FreeRTOS Support Archive
The FreeRTOS support forum is used to obtain active support directly from Real
Time Engineers Ltd. In return for using our top quality software and services for
free, we request you play fair and do your bit to help others too! Sign up
to receive notifications of new support topics then help where you can.
This is a read only archive of threads posted to the FreeRTOS support forum.
The archive is updated every week, so will not always contain the very latest posts.
Use these archive pages to search previous posts. Use the Live FreeRTOS Forum
link to reply to a post, or start a new support thread.
[FreeRTOS Home] [Live FreeRTOS Forum] [FAQ] [Archive Top] [August 2012 Threads] first task is replaced by second taskPosted 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 taskPosted 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 taskPosted 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 taskPosted 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 taskPosted 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 taskPosted 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.
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.
|