first task is replaced by second task

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

first task is replaced by second task

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.

first task is replaced by second task

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, “rn%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, “rn%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, “rn%4X”, ERROR_SUCCESS);
}

first task is replaced by second task

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.

first task is replaced by second task

i guess  the xTaskCreate function copy the parameter in own task stack…i will have a try

first task is replaced by second task

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.