FreeRTOS Communication/Eventing Mechanism

hirohiro wrote on Thursday, August 01, 2019:

Hi all,

I’m trying to come up with an appropriate, and abstracted architecture for my next project and am leaning towards using and event bus of some sort throughout all my tasks/modules to signal/receive events. I don’t have much experience with FreeROTS, so I’m hoping someone can point me in the right direction or ideally tell me what what I’m looking for is already part of the OS :slight_smile:

Example: Events would be flags with or without associated data that need to be passed around the application. I want to define a list of these events that can be signaled and received globally across the application. For example, a task monitoring reading & processing thermometer data could detect that a certain temperature has been reached (the event). At this point it would need to notify a number of modules aboout this, however, it shouldn’t be concerned about what those modules or tasks are. It should just signal the event and the other tasks (logger, UI, networking, state machine, etc…) would be notified about the event if they are interested and take action.

Details: This would have to be a many-to-many publish-subscribe type of model. Events should be publishable from critical sections (ie. interrupts), but should not result in being handled directly from that context (ie. direct callback wouldn’t work). Events should be disseminated to all interested parties before being cleared.

My Questions:

  1. Is there something that accomplishes this already available in FreeRTOS
  2. Is there something similar available that accomplishes this outside of FreeRTOS
  3. Is there a better/simpler mechanism/architecture to achieve IPC handling multiple tasks/modules that I may have overlooked?

Looking forward to hearing some thoughts! :slight_smile:

richard_damon wrote on Thursday, August 01, 2019:

Event groups look to do a lot of what you want. One task or interrupt sets the event, then every task that is waiting on the event gets released.

hirohiro wrote on Thursday, August 01, 2019:

Is there someway to also attach data? As far as I know events don’t support that

hirohiro wrote on Thursday, August 01, 2019:

Is there someway to also attach data? As far as I know events don’t support that

hirohiro wrote on Thursday, August 01, 2019:

Is there someway to also attach data? As far as I know events don’t support that

richard_damon wrote on Friday, August 02, 2019:

No (unless you can encode the data in a few bits and use bits in the event for the data). You might just be able to use a global and the flag that the data is there, it really depends a lot on exactly what you are trying to do.

One other thing to point out, is that if some task wants the notification, but isn’t waiting, the (if you clear the event in the wait) it won’t see that event.

If you really need the full functionaity describe, the solution I can think of would be a full signal and slots system, where every task that wants to be notified puts itself on a list, and to signal you walk that list and signal every task that was registered.