Usage of xTaskNotify/xTaskNotifyWait.

andy-pevy wrote on Wednesday, March 29, 2017:

Hi, I am using xTaskNotify and xTaskNotifyWait to signal interrupt status between an int handler and the
supporting task.

Very occasionally I am loosing indications and I’d just like to clarify my understanding of how
the pair work together.

I receive data and therefore interrupts asynchronously and it is possible that I am
still procesing a previous message and I get another indication informing me of new data
being received.

So, my question is that if a new indication arrives while I am ‘Busy’, when I enter the
xTaskNotifyWait routine, will it return immediately because of the existing indication,
or will it wait until the next indication arrives thus ignoring the one that it already has ?.

Thanks,
Andy Pevy

rtel wrote on Wednesday, March 29, 2017:

If you call a function to wait for a notification, but a notification is
already pending, then you won’t wait at all, but just return immediately.

xTaskNotify() is not an ISR safe function - is this just an error in
your post, or are you actually using that function in an ISR?

Also, if you are using notifications from an interrupt, be sure to use
them in their ‘counting’ form, rather than binary form. See the chapter
on task notifications in the following book for more information:
http://www.freertos.org/Documentation/RTOS_book.html

andy-pevy wrote on Thursday, March 30, 2017:

Hi, I am using the HAL callback code so the interrupt domain appears to be lost, so I am really using xTaskNotify.

I am however passing 2 bits of information in the notification, I.E. Which H/W interrupt has triggered the event and an ID of a buffer that is currently being processed. If I have to use the counting notification I loose the ability to do this.

It looks like I am going to have to use a normal quere mechanism to achieve what I need.

Unless there is another way…

Andy

rtel wrote on Thursday, March 30, 2017:

Hi, I am using the HAL callback code so the interrupt domain appears to
be lost, so I am really using xTaskNotify.

Are you 100% sure the callback is not being called by an interrupt? Do
you have configASSERT() defined?

I am however passing 2 bits of information in the notification, I.E.
Which H/W interrupt has triggered the event and an ID of a buffer that
is currently being processed. If I have to use the counting notification
I loose the ability to do this.

It looks like I am going to have to use a normal quere mechanism to
achieve what I need.

Unless there is another way…

We often use a thread safe circular buffer to ‘push’ information about
an interrupt into a buffer, then use the task notification to wake a
task…which then reads the information from the buffer. This will
become part of the FreeRTOS feature set as soon as we get time to tidy
it up and fully test it - but you could rig up something similar easily
enough.