Wait for multiple notifications before continuing Task

I have 3 tasks - taskA, taskB and taskC.

I need taskA to waits for both taskB and taskC to finish before continuing.

I am trying to use FreeRTOS’ notifications for this but unsure how to use xTaskNotifyWait to wait for not one notification but two before reseting notifications and carrying on with taskA.

My current idea is this:

    //Task B
    xTaskNotify(taskA, (1<<0), eSetBits);  // set 0th bit HIGH
    // Task C
    xTaskNotify(taskB, (1<<1), eSetBits); // set 1st bit HIGH

    // Task A
    while(ulNotifiedValue != 5)
    {
      xTaskNotifyWait(0, 0,  &ulNotifiedValue, (TickType_t)portMAX_DELAY);
    }
    // reset notification value
    ulNotifiedValue = 0
    // contiunue with taskA...

However, this seems to block at xTaskNotifyWait indefinitely.

Any help much appreciated,
Will

b1|b0 = 1|1 == 3 right :wink:
Could be easily found by yourself watching ulNotifiedValue with a debugger or some log output.

Ah dear it’s been a long week.
Unsure how clean this method is but it seems to work now.
Thanks

:smile: … The method is just fine.
You surely have a ulTaskNotifyValueClear somewhere for the next signaling sequence.

Ah I thought ulNotifiedValue = 0 would do the trick but I think you’re right.
Sadly ulTaskNotifyValueClear is not available on ESP32 currently, so will have to try and update library.

Alternatively you could assemble/collect the bits in a local variable and set the ulBitsToClearOnExit argument of xTaskNotifyWait to the complete bitmask (3).

static uint32_t const BitMask = 3;
uint32_t ulNotifiedBits = 0, ulNotifiedValue = 0;
while( ulNotifiedBits != BitMask )
{
    xTaskNotifyWait(0, BitMask,  &ulNotifiedValue, (TickType_t)portMAX_DELAY);
    ulNotifiedBits |= ulNotifiedValue;
}