Task waiting for either one of two events or both

Hi,
I am using freeRTOS with Microchip Harmony V3.
I posted asking about serving an interrupt from an I2C port expander here: I2C port expander with interrupt

And this is related to that…

I have to have a task in wait/block until I receive a notification from either:

  • vTaskNotifyGiveFromISR() because the interrupt from the I2C port expander
    or
  • a regular timeout from a timer

Two questions:

  1. the code in the task stops and waits right at the line of ulTaskNotifyTake(). And all I need to do is use that function, i.e. no other separate function (before or after that one) to put the task into wait state. Are both statements correct?

  2. can I that single ulTaskNotifyTake() function to put the task to wait and for it to be resumed again by EITHER the timer interrupt AND / OR the port expander pin interrupt?

  3. what if they both occur at the same time or overlap each other in time somehow? When I receive either one of the notifications I carry out both port expander operations (check if the input changed and also update any outputs - reason for having the timer) so it doesn’t matter if I loose either one of the notifications. But I was wondering if I need to cater for it somehow.

Being a beginner with freeRTOS, I would appreciate very much simple solutions because have to deliver the software on a very tight timeline. :slight_smile:

Thank you very much :slight_smile:

What’s the purpose of the timer/timeout ?
Maybe it’s possible to simply use the xTicksToWait argument of ulTaskNotifyTake to implement the timer/timeout functionality. That would be the most simple solution.

There are very good books to get more familiar with the basics of FreeRTOS besides the very good online documentation definitely worth reading.

Thank you Hartmut,
the timer function is to update the Expander output regularly for the Expander’s output which are mainly LEDs that need to regularly be either flashing or updating their status relatively quickly (some LEDs are used for UI and others are of optocoupling for relatively fast signalling at 200Hz).

Thank you :slight_smile:

And thank you for the books link.

If you want to do the complete I/O expander control in 1 task supporting 2 (or more) independent events (input change and timer based output update) you could use task notifications As Light Weight Event Group (including example).
Using the ulTaskNotifyTake timeout is probably not appropriate to simulate required timer etc.

A Task can only block on ONE thing, and generally that block can have a timeout set on it in the call.

If you want two interrupts to be able to wake up the task, then both need to signal the task with the same sort of thing.