Quality RTOS & Embedded Software

 Real time embedded FreeRTOS RSS feed 
Real time embedded FreeRTOS mailing list 
Quick Start Supported MCUs PDF Books Trace Tools Ecosystem TCP & FAT Training




Loading

xQueueCreate

Posted by koor1200 on February 23, 2016

Hello, I'm relatively new to FREERTOS so bear with me please.

My target is the NXP Kinitic K64 series (formerly Freescale) bord.I created a FREERTOS project with the Kernel and libraraies and build it Created 2 priodic taske and evrything seems to be running well. For the next step I'm trying to create a QUE for passing messeges between tasks so I created a task (this is taken from the freertos example):

void vATask( void *pvParameters ) { struct AMessage *pxMessage; uint32t * testptr;

// Create a queue capable of containing 10 pointers to AMessage structures.
// These should be passed by pointer as they contain a lot of data.
xQueue = xQueueCreate( 10, sizeof( unsigned int*  ) );
if( xQueue == 0 )
{
    // Failed to create the queue.
}



// ...



// Send a pointer to a struct AMessage object.  Don't block if the
// queue is already full.
pxMessage = & xMessage;
test_ptr= &test_var;
xQueueSend( xQueue, ( void * )/* &pxMessage*/&test_ptr, ( TickType_t ) 0 );



// ... Rest of task code.

} When I step through the code ,It hangs in xQueueCreate(). It hits configASSERT( xReturn ); and just hangs there. Don't know what is going on.

I appriciate your help.

Thanks, Koorosh Hajiani


xQueueCreate

Posted by xz8987f on February 23, 2016

Hi Koorosh, it means that xReturn is NULL. And this means that xQueueCreate() was not able to allocte the queue. Step with your debugger through xQueueCreate() and you should see what is failing.

I think your problem is /* Allocate the new queue structure and storage area. */ pxNewQueue = ( Queuet * ) pvPortMalloc( sizeof( Queuet ) + xQueueSizeInBytes ); and that pvPortMalloc() returns NULL because you don't have enough heap allocated.

I suggest you allocate more heap with increasing configTOTALHEAPSIZE in FreeRTOSConfig.h

I hope this helps, Erich


xQueueCreate

Posted by koor1200 on February 23, 2016

Hi Erich, Many thanks you for your response. You're correct, It does crash here: pxNewQueue = ( Queuet * ) pvPortMalloc( sizeof( Queuet ) ); if( pxNewQueue != NULL )

Which is part of xQueueGenericCreate( const UBaseTypet uxQueueLength, const UBaseTypet uxItemSize, const uint8_t ucQueueType ) ** function which is the macro definition of ** xQueueCreate.

I tried to change the heap size from 0x8000 to 0xA000

define configTOTALHEAPSIZE ((size_t)(/0x8000/ 0xA000)) /* size of heap in bytes */

It is not helping. I looked at the linker file and there is 0x4000 bytes allocated on the heap. I am not sure if the freertos definition of the heap size override the linker one but I changed the configTOTALHEAPSIZE to 0x4000 to match that in the linker file and it did not help either. I'm allocating only 10 bytes and 0x8000 seems sufficient for this. Something is not right. Any ideas?

Thanks, Koorosh Hajiani


xQueueCreate

Posted by rtel on February 23, 2016

The FreeRTOS heap is separate to the heap allocated by the linker - and FreeRTOS doesn't touch the heap allocated by the linker unless you are using heap_3 (see http://www.freertos.org/a00111.html for an explanation of the different heap options). Unless you code is calling malloc() somewhere then you can set the size of the heap allocated by the linker to 0 (or 4 as 0 is not always a valid value) as it is not needed. You application code can always call pvPortMalloc() instead of malloc() too - which will also allow you to set the linker allocated heap to 0.

If you are interested there is a V9 release candidate on SourceForge currently that allows you to allocate this memory statically too http://www.freertos.org/FreeRTOS-V9.html

Regards.


xQueueCreate

Posted by koor1200 on February 23, 2016

Hi Thank you for thr response. I changed heap3 to heap1 and it seems to have done the trick. However no my code is generating a trap. As I said I'm kind of new to freertos and I'm certain there are lots of mistake in the code. My code is trying to creat 4 tasks : void taskone(taskparamt param); void tasktwo(taskparamt param); void vATask(taskparamt param); void vADifferentTask(taskparamt param);

taskone and tasktwo are periodic:

void taskone(taskparam_t param) { int i = 0; PRINTF("This is Task Onennr"); PRINTF("Press SW2 to Toggle Blue LED...nnr"); while(1) {

	vTaskDelay( 500 );
	// Poll (sw2) if GPIO_INTERRUPT is not set
	if(/*GPIO_DRV_ReadPinInput(kGpioSW2) == 0*/1)
	{
		//OSA_TimeDelay(200);
		GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_GREEN);
	}
	PRINTF("%x\r\n",*test_rx_ptr);
}

} void tasktwo(taskparam_t param) { //int i = 0; PRINTF("This is Task Twonnr"); PRINTF("Press SW2 to Toggle Blue LED...nnr"); while(1) {

	vTaskDelay( 700 );
	// Poll (sw2) if GPIO_INTERRUPT is not set
	if(GPIO_DRV_ReadPinInput(kGpioSW2) == 0)
	{
		//OSA_TimeDelay(200);
		GPIO_DRV_TogglePinOutput(BOARD_GPIO_LED_GREEN);
	}

	test_var++;
}

} vATask is a task that creates a queue and post a value to it

void vATask( void *pvParameters ) { struct AMessage *pxMessage; uint32t * testptr;

// Create a queue capable of containing 10 pointers to AMessage structures.
// These should be passed by pointer as they contain a lot of data.
xQueue = xQueueCreate( 16, sizeof( unsigned int  ) );
if( xQueue == 0 )
{
    // Failed to create the queue.
}



// ...



// Send a pointer to a struct AMessage object.  Don't block if the
// queue is already full.
pxMessage = & xMessage;
test_ptr= &test_var;
xQueueSend( xQueue, ( void * )/* &pxMessage*/&test_ptr, ( TickType_t ) 0 );



// ... Rest of task code.

} vADifferentTask is a task that read the queue:

void vADifferentTask( void *pvParameters ) { struct AMessage *pxRxedMessage; //uint32t testrx_ptr;

 if( xQueue != 0 )
 {
     // Receive a message on the created queue.  Block for 10 ticks if a
     // message is not immediately available.
     if( xQueueReceive( xQueue,/* &( pxRxedMessage )*/&test_rx_ptr, ( TickType_t ) 10 ) )
     {
         // pcRxedMessage now points to the struct AMessage variable posted
         // by vATask.
     }
 }

and here are the tasks creation

OSATaskCreate(tasktwo,"tasktwo",TASKONESTACKSIZE,NULL,6u,NULL,false,&tasktwotaskhandler); OSATaskCreate(vATask,"vATask",TASKONESTACKSIZE,NULL,5u,NULL,false,&vATasktaskhandler); OSATaskCreate(vADifferentTask,"vADifferentTask",TASKONESTACKSIZE,NULL,5u,NULL,false,&vADifferentTasktask_handler);

//create task
 OSA_TaskCreate(task_one,
		(uint8_t *)"task_one",
		TASK_ONE_STACK_SIZE,
		NULL,
		TASK_ONE_PRIO,
		(task_param_t)0,
		false,
		&task_one_task_handler);

what happens is it goes through thevATask and as soon as it returns it hits an eception which I believe is the HARD FAULT eception as my targer is an ARM CORTEX M4.

Sorry about the long post , but I need help.In the mean time I try to figure what I'm doing wrong.

Thanks, Koorosh Hajiani


xQueueCreate

Posted by koor1200 on February 24, 2016

Futther debugging ,reveals the following: HEAP1 is selected. From OSSTART() leads to xPortStartScheduler(void) and that calls **vPortStartFirstTask() ** and that is shown below:

~~~~

if (configCOMPILER==configCOMPILERARMGCC)

void vPortStartFirstTask(void) { __asm volatile ( " ldr r0, =0xE000ED08 n" /* Use the NVIC offset register to locate the stack. / " ldr r0, [r0] n" / load address of vector table / " ldr r0, [r0] n" / load first entry of vector table which is the reset stack pointer / " msr msp, r0 n" / Set the msp back to the start of the stack. / " cpsie i n" / Globally enable interrupts. / " svc 0 n" / System call to start first task. */ " nop n" ); }

endif

~~~~ now at this point the stack points to a portion of RAM which is not allocated for the stack by the linker .eventhough the first task that creats a Queue and post a variable to it is called and correctly does what is supposed to do , however the return address is corrupted and the Arm triggeres a trap(Hard Fault) in this case.

Why is Stack pointer changing by vPortStartFirstTas?

Thanks, Koorosh Hajiani


xQueueCreate

Posted by edwards3 on February 24, 2016

Every task has a unique stack allocated from the heap so the stack pointer is changed each time the running task is changed.


[ Back to the top ]    [ About FreeRTOS ]    [ Sitemap ]    [ ]




Copyright (C) 2004-2010 Richard Barry. Copyright (C) 2010-2016 Real Time Engineers Ltd.
Any and all data, files, source code, html content and documentation included in the FreeRTOSTM distribution or available on this site are the exclusive property of Real Time Engineers Ltd.. See the files license.txt (included in the distribution) and this copyright notice for more information. FreeRTOSTM and FreeRTOS.orgTM are trade marks of Real Time Engineers Ltd.

Latest News:

FreeRTOS V9.0.0 is now available for download.


Free TCP/IP and file system demos for the RTOS


Sponsored Links

⇓ Now With No Code Size Limit! ⇓
⇑ Free Download Without Registering ⇑


FreeRTOS Partners

ARM Connected RTOS partner for all ARM microcontroller cores

Renesas Electronics Gold Alliance RTOS Partner.jpg

Microchip Premier RTOS Partner

RTOS partner of NXP for all NXP ARM microcontrollers

Atmel RTOS partner supporting ARM Cortex-M3 and AVR32 microcontrollers

STMicro RTOS partner supporting ARM7, ARM Cortex-M3, ARM Cortex-M4 and ARM Cortex-M0

Xilinx Microblaze and Zynq partner

Silicon Labs low power RTOS partner

Altera RTOS partner for Nios II and Cortex-A9 SoC

Freescale Alliance RTOS Member supporting ARM and ColdFire microcontrollers

Infineon ARM Cortex-M microcontrollers

Texas Instruments MCU Developer Network RTOS partner for ARM and MSP430 microcontrollers

Cypress RTOS partner supporting ARM Cortex-M3

Fujitsu RTOS partner supporting ARM Cortex-M3 and FM3

Microsemi (previously Actel) RTOS partner supporting ARM Cortex-M3

Atollic Partner

IAR Partner

Keil ARM Partner

Embedded Artists