Hi,
I have three tasks, P1, P2 (‘P’ is from “Producer”), and C (from “Consumer”). P1 and P2 have higher priority than C.
P1 produces the values: 1, 3, 5, …; while P2 produces the values: 2, 4, 6, … .
P1 notifies on task’s C slot 1, while P2 notifies on task’s C slot 2. Task C does something with the value sent by P1, and does other thing with the value sent by P2.
However, while experimenting I noticed that, as my C’s setup, C task is missing data. My C task is as follows:
void Consumer_task( void* pvParameters )
{
uint32_t p1_value;
uint32_t p2_value;
while( 1 )
{
if( xTaskNotifyWaitIndexed( 1, 0xffffffff, 0x00, &p1_value, pdMS_TO_TICKS( 2000 ) ) != pdPASS ){
DEBUGOUT( "Error on P1\n\r" );
} else{
DEBUGOUT( "In slot 1 I received the value: %d\n\r", p1_value );
}
if( xTaskNotifyWaitIndexed( 2, 0xffffffff, 0x00, &p2_value, pdMS_TO_TICKS( 2000 ) ) != pdPASS ){
DEBUGOUT( "Error on P2\n\r" );
} else{
DEBUGOUT( "In slot 2 I received the value: %d\n\r", p2_value );
}
}
}
An output from this program is:
P1 is about to notify: 7…
P1 is about to notify: 9…
P2 is about to notify: 6…
In slot 2 I received the value: 6
In slot 1 I received the value: 9
P1 is about to notify: 11…
P1 is about to notify: 13…
P2 is about to notify: 8…
In slot 2 I received the value: 8
In slot 1 I received the value: 13
P1 is about to notify: 15…
P2 is about to notify: 10…
In slot 2 I received the value: 10
In slot 1 I received the value: 15
In this excerpt values 7 and 11 are never received by the task C. In this experiment the tasks P1 and P2 are almost identical:
TaskHandle_t consumer_h;
void Producer1_task( void* pvParameters )
{
pvParameters = pvParameters;
TickType_t last_wake_time = xTaskGetTickCount();
uint32_t cont = 1;
while( 1 )
{
vTaskDelay( pdMS_TO_TICKS( 997 ) );
DEBUGOUT( "P1 is about to notify: %d...\n\r", cont );
xTaskNotifyIndexed( consumer_h, 1, (uint32_t) cont, eSetValueWithOverwrite );
cont += 2;
}
}
I’m pretty sure that I’m doing something wrong in the way the consumer task is sitting waiting for the notifications due to the fact that it blocks twice. That’s way I’m asking you:
What is the best way for a task to wait for notifications from two or more slots from two or more tasks? Is that posible? Is that the intention of indexed notifications?
Thank you in advanced !