While trying that two tasks to write on two different receiver task indexes, my system crashes (it resets itself continuosly):
TaskR[1] ← TaskA
TaskR[2] ← TaskB
In isolation both approaches work as expected, but whenever I activate both, then the system crashes. Before moving on let me show you my code:
#include <FreeRTOS.h>
#include <task.h>
TaskHandle_t consumidor_h;
void Productor1_task( void* pvParameters )
{
uint16_t time_to_sleep = (uint16_t) pvParameters;
TickType_t last_wake_time = xTaskGetTickCount();
while( 1 )
{
vTaskDelayUntil( &last_wake_time, pdMS_TO_TICKS( time_to_sleep ) );
xTaskNotifyIndexed( consumidor_h, 1, (uint32_t) time_to_sleep, eSetValueWithOverwrite );
}
}
void Productor2_task( void* pvParameters )
{
uint16_t time_to_sleep = (uint16_t) pvParameters;
while( 1 )
{
vTaskDelay( pdMS_TO_TICKS( time_to_sleep ) );
xTaskNotifyIndexed( consumidor_h, 2, (uint32_t) time_to_sleep, eSetValueWithOverwrite );
}
}
void Consumidor_task( void* pvParameters )
{
pinMode( 13, OUTPUT );
uint32_t value;
while( 1 )
{
#if 1
xTaskNotifyWaitIndexed( 1, 0x00, 0x00, &value, portMAX_DELAY );
Serial.println( value );
#endif
#if 1
xTaskNotifyWaitIndexed( 2, 0x00, 0x00, &value, portMAX_DELAY );
Serial.println( value );
#endif
}
}
void setup()
{
Serial.begin( 115200 );
xTaskCreate( Productor1_task, "PROD1", 256, (void*) 997, tskIDLE_PRIORITY + 1, NULL );
xTaskCreate( Productor2_task, "PROD2", 256, (void*) 1747, tskIDLE_PRIORITY + 1, NULL );
xTaskCreate( Consumidor_task, "CONS", 256, NULL, tskIDLE_PRIORITY, &consumidor_h );
vTaskStartScheduler();
}
void loop()
{
}
In my FreeRTOSConfig.h file I’ve set it up:
#define configUSE_TASK_NOTIFICATIONS 1
#define configTASK_NOTIFICATION_ARRAY_ENTRIES 5
What am I missing? What am I not understanding on the xTaskNotifyIndexed() and xTaskNotifyWaitIndexed() functions?
Maybe I’m not understanding the official documentation on xTaskNotifyWaitIndexed():
Note: Each notification within the array operates independently – a task can only block on one notification within the array at a time and will not be unblocked by a notification sent to any other array index.
If this is my case, would you point me out to a scenario or example where these two functions are used for passing a single value?
Note aside, an intriguing fact is that there are no information on the Internet! Google only found 10 entries on “xTaskNotifyIndexed()” and most of them are mirror of the official documentation.
Thank you!