I have a task A create a task B. Task B starts a measurement, an ISR wakes it up.
It seems like the ISR calling xTaskNotifyfromISR and portYIELD_FROM_ISR with the handle of task B, actually wakes up task A.
Is this expected? If yes, what terms should I have search for, to find info about this? If no, any idea what might be going on? Task B is not waiting for anything from A.
Possibly, the ISR finishes and tries to wake B up when it is no longer in its vTaskDelay. Still, in that case, B should go on and run its stuff after the loop, and notify A with the new value.
Instead, A wakes up with its notified value at 0, before B has the time to process value and notify A with it.
You are correct. I suppose the original plan was to have a wait instead of a vTaskdelay in the B task, and to terminate it early in case the ISR executed.
I removed the notify from the ISR, unfortunately that made no difference.
sensor_find_task notifies a task, only after the ISR has set a flag to true
I expect:
ISR set the flag
B notices it, exits the while loop, notifies A
A wakes up and prints the value sent together with the notification from B
I observe, in that order:
ISR sets the flag (I have a short printf in there)
A wakes up with notification value 0
B comes out of the while loop, has correct value before trying to notify A
Is there a way I can see, in A, where the waking notification origins from?
EDIT:
In this case, since you made me notice I don’t need the notification from ISR, I don’t need the ISR at all, I can just read the GPIO level in the task. Still, I would like to understand what is causing the ISR to wake task A. I also have a global gpio ISR, set with gpio_set_irq_enabled_with_callback, but this ISR I set raw with gpio_add_raw_irq_handler.
Calling printf from ISR is not a good idea. Please remove that.
It may be a memory corruption. One way to debug is to put a databreakpoint on the notification state variable of the A’s TCB and see who is updating it.
Calling printf from ISR is not a good idea. Please remove that.
You’re right. In this case, this is a single character without a flush, and was added solely for debugging. The behavior does not change with or without the print, and it will go away once I understand what is going on.
databreakpoint on the notification state variable of the A’s TCB and see who is updating it.
Good suggestion. Unfortunately, my gdb and rp2040 does not seem to support watchpoints. I don’t know if that is fixable, or if the HW just isn’t there.
Anyway, I just found out that another ISR notifies the same task. I didn’t expect this ISR to trigger, so I have more digging to do for that, but it’s another issue.
Thanks for your help, not least confirming that what I was seeing was unexpected (I have been working with Contiki in the past, where waking a thread up had to go through a possible parent thread. This is why I found this suspicious, maybe it’s some light PTSD ).