some pseudo code:
Code: Select all
if(ble_command == 1){
xTaskCreate(task1,"task1",10000,&global_message,1,&task1_handle);
}
elseif(ble_command == 2){
xTaskCreate(task2,"task2",10000,&global_message,1,&task2_handle);
}
else{
xTaskCreate(task3,"task3",10000,&global_message,1,&task3_handle);
}
I have decided to use semaphore for that.
Code: Select all
spi_long_task_mutex = xSemaphoreCreateBinary();
Inside each task at the beggining, I check if this semaphore is free. If it is free, I do some stuff inside a task and it deletes itself. If I detect that the semaphore is already taken by someone else, I delete the task immediately.
Code: Select all
void task1(void* param){
if(xSemaphoreTake(spi_long_task_mutex,100)==pdTRUE){
for(;;)
{
printf("hello world \n");
xSemaphoreGive(spi_long_task_mutex);
vTaskDelete(0);
}
}
else{
printf("semaphore is taken by someone else \n");
vTaskDelete(0);
}
}
Is there something I am misunderstanding about the semaphores? According to how I understand it, this should just simply work