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

first task is replaced by second task

Posted by vincent on August 27, 2012
Hi:

I create two task with xTaskCreate(channel_task ...... ) and void channel_task(void *pvparam);

the two task share same task function, but with different input parameters. I found that the first
task 's input parameters is replayed by second task input parameters after I create second task.

how to solve it ?


vincent

RE: first task is replaced by second task

Posted by Dave on August 27, 2012
What is the parameter? A constant, or a pointer? If it is a pointer, are you passing a pointer to the same structure into both tasks?

Please post the code that creates the tasks, and the code that uses the parameter in the task.

RE: first task is replaced by second task

Posted by vincent on August 27, 2012
hi ,
the parameter is pointer
if (strcmp(tmp, "on") == 0)
{
struct relay_outlet_param outletparam;

outletparam.outletidx = channel;
outletparam.outletsts = OUTLET_ON;

xTaskCreate(outlet_task,"OUTLETON", configMINIMAL_STACK_SIZE*2,&outletparam, RS485_TASK_PRIO, NULL);

sprintf(consolemsg, "\r\n%4X", ERROR_SUCCESS);
}
else if (strcmp(tmp, "off") == 0)
{
struct relay_outlet_param outletparam;

outletparam.outletidx = channel;
outletparam.outletsts = OUTLET_OFF;

xTaskCreate(outlet_task,"OUTLETOFF", configMINIMAL_STACK_SIZE*2,&outletparam, RS485_TASK_PRIO, NULL);
sprintf(consolemsg, "\r\n%4X", ERROR_SUCCESS);
}
else if (strcmp(tmp, "reboot") == 0)
{
struct relay_outlet_param outletparam;

outletparam.outletidx = channel;
outletparam.outletsts = OUTLET_REBOOT;

xTaskCreate(outlet_task,"OUTLETRBT", configMINIMAL_STACK_SIZE*2,&outletparam, RS485_TASK_PRIO, NULL);
sprintf(consolemsg, "\r\n%4X", ERROR_SUCCESS);
}

RE: first task is replaced by second task

Posted by Dave on August 27, 2012
if (strcmp(tmp, "on") == 0)
{
struct relay_outlet_param outletparam;


In the code above you are declaring a structure on the stack with block scope.

xTaskCreate(outlet_task,"OUTLETON", configMINIMAL_STACK_SIZE*2,&outletparam, RS485_TASK_PRIO, NULL);


In the code above you are passing into a task a pointer to a structure that only has block scope.

}
else if (strcmp(tmp, "off") == 0)


When you leave the block the structure becomes invalid, so when the task runs it is accessing something on a stack frame that no longer exists. The memory might not be corrupted for a while, how long depends on when the stack frame reaches that level again. If you call the function again it will create a new stack frame and probably allocate the structure in the same stack memory again so it might be that both tasks are accessing the same area of invalid memory.

You need to allocate the structures from global memory. It can be malloced from the heap, or be two separate structures defined with file or global (instead of block) scope.

RE: first task is replaced by second task

Posted by vincent on August 27, 2012
i guess the xTaskCreate function copy the parameter in own task stack...i will have a try

RE: first task is replaced by second task

Posted by Richard Damon on August 28, 2012
xTaskCreate does copy the parameter to the tasks stack. The parameter is of course the void pointer value. FreeRTOS does not (and can not) copy the structure the pointer points to, for the very good reason that it doesn't know what it points to, if in fact it actually points to anything. If you pass pointers to data when creating tasks, that data needs to live until the task no longer needs it.


[ 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