Can't replace Binary Semaphore with Task Notification

Good day

I used a binary semaphore to start a task.
I wanted to switch to using a task notification, because I know that they can give performance benefits and they use less RAM.

I’ve replaced xSemaphoreGiveFromISR(binSem, &xHigherPriorityTaskWoken); in the ISR that starts the task with vTaskNotifyGiveFromISR(taskHndl, &xHigherPriorityTaskWoken);.
I also have portYIELD_FROM_ISR(xHigherPriorityTaskWoken); after this in the ISR.
I have also replaced the xSemaphoreTake(binSem, (TickType_t) 100); with if(ulTaskNotifyTake(pdTRUE, (TickType_t) 100)) inside the for(;;) of the task.

The task executes when I use the semaphore (so the ISR isn’t the problem), but not when I use the task notification instead.

Am I missing something?

This probably should be &xHigherPriorityTaskWoken depending on how you declared xHigherPriorityTaskWoken.

Can you elaborate this a bit more? Is the task not running at all?

Can you share actual code snippet showing the problem?


Hi @aggarg

Thanks for your reply.
I see I made a typo in my original post, it should indeed be &xHigherPriorityTaskWoken, as I have it in my code:

The above code is the ISR for CAN interrupts on a certain CAN interface.
Here is the relevant part of the task’s code (echoed in the CAN_TX_Extra_Task):
The task handles are declared as follows:

The task handles are initialised when the tasks are created:

I believe that neither the CAN_RX_Extra_Task nor the CAN_Tx_Extra_Task is being started by the task notifications, but for now I’ve just been testing the CAN_RX_Extra_Task.
Also, I checked again, and using a semaphore with no other changes works as expected.

Finally, I’ll show some side-by-side screenshots so that you can see the changes I made to convert from using semaphores to using task notifications (left = task notifications, right = semaphores, yellow highlights = changes made):

(Note that the above change was repeated for both tasks)

To answer your second question, the task is definitely running (hits the breakpoint at the task notification take) but it doesn’t ever seem to go past this line (never hits the breakpoint just below this line).
I’m not even sure how this is possible, since the timeout is specified as 1 tick.

Thank you for your help!

Could your system be hitting an assert? And thus just halting? Or getting stuck in some ISR?

Have you enabled config assert, stack overflow checking and malloc failed checking -

As pointed by others on your different post, the fact that adding a delay before the loop fixed your issue, is probably just an indication of a problem elsewhere.

The next step of debugging will be to step through the function vTaskNotifyGiveFromISR and see if it correctly updates the ready task (the value of pxCurrentTCB). What is the value of xHigherPriorityTaskWoken?