Tool/software: TI-RTOS
Hi there, I am facing issues working with 2 tasks. The function that starts the 2 task is as follow:
void rxTaskInit(PIN_Handle ledPinHandle) { pinHandle = ledPinHandle; Task_Params_init(&rxWakeTaskParams); rxWakeTaskParams.stackSize = RFEASYLINKRX_TASK_STACK_SIZE; rxWakeTaskParams.priority = 2; rxWakeTaskParams.stack = &rxWakeTaskStack; rxWakeTaskParams.arg0 = (UInt)1000000; Task_Params_init(&rxDataTaskParams); rxDataTaskParams.stackSize = RFEASYLINKRX_TASK_STACK_SIZE; rxDataTaskParams.priority = 1; rxDataTaskParams.stack = &rxDataTaskStack; rxDataTaskParams.arg0 = (UInt)1000000; Task_construct(&rxWakeTask, rfSlaveRXWakeTask, &rxWakeTaskParams, NULL); Task_construct(&rxDataTask, rfSlaveRXDataTask, &rxDataTaskParams, NULL); }
rfSlaveRXWakeTask and rfSlaveRXDataTask :
static void rfSlaveRXDataTask(UArg arg0, UArg arg1){ while(1) { Semaphore_pend(rxInterchangeSem, BIOS_WAIT_FOREVER); // Do stuff, then semaphore_post to let higher priority task (rfSlaveRXWakeTask) to continue Semaphore_post(rxInterchangeSem); } } static void rfSlaveRXWakeTask(UArg arg0, UArg arg1){ while(1) { Semaphore_pend(rxInterchangeSem, BIOS_WAIT_FOREVER); // Do RX stuff, then sleep for 5 seconds before semaphore_post Task_sleep(5000 * 1000 / Clock_tickPeriod); Semaphore_post(rxInterchangeSem); // if a "Wake" packet is received, pause this higher priority task and allow the lower priority task (rfSlaveRXDataTask) to start if(isWakeReceived){ isWakeReceived = FALSE; Task_sleep(5); } } }
The expected behavior is to have "rfSlaveRXWakeTask" to run indefinitely, RF RX for 500ms every 5 seconds.
"isWakeReceived" will be changed to TRUE when a "Wake" packet is received.
Then "rfSlaveRXWakeTask" will sleep for 5 ticks to allow "rfSlaveRXDataTask" to continue.
When "rfSlaveRXDataTask" has done executing, it will semaphoire_post to let "rfSlaveRXWakeTask" to continue.
However, the actual behavior is:
"rfSlaveRXWakeTask" runs once, then "rfSlaveRXDataTask" runs once, sleep for 5 seconds, repeat.
What did I miss here...
Please advise.
Thanks.
Edit:
I realize that if I remove Task_sleep(5000 * 1000 / Clock_tickPeriod); line 14 from "rfSlaveRXWakeTask", "rfSlaveRXDataTask" will not be executed.
But "rfSlaveRXWakeTask" has to stop for a few seconds before the next loop, removing it is not an option.
Why is Task_sleep affecting the flow of the whole program?