Event-driven architecture in Zephyr


Jeff Langballe <Jeff.langballe@...>
 

Hi all,

 

I’m trying to implement an event driven architecture within Zephyr. My goal is to have multiple event handlers trigger on each event. ex. power monitor emits a “low battery” event -> UI thread receives this and sets an LED pattern, cloud thread receives and pushes a warning, another subscriber shuts down some outputs, another subscriber does logging, etc.

 

Zephyr doesn’t seem to have any explicit mechanisms built in for this. I’ve tried working with message queues and poll signals but they lend themselves more to “one-to-one” communication instead of “one-to-many”. I’ve also used Nordic’s Event Manager library which has the exact interface I’m looking for but gave me trouble with lack of event priority and lack of concurrency for event handlers. For example, if I have a lengthy event handler running for a less-important task, it will block other event handlers which may be of higher importance.

 

What I’d like to know is if there are existing samples that achieve this or a set of recommendations for implementing this within Zephyr. Specifically, what data passing objects (FIFOs, message queues, mailboxes, etc.) from Zephyr are most appropriate for this kind of IPC and do these objects lend themselves nicely to any specific topology (event broker, event mediator, or others). I could also work around the shortcomings of the Nordic library but it would be nice to have a good framework to use as a starting point instead.

 

Thanks,

Jeff

 


pawel.dunaj@...
 

Hi Jeff,

As far as I know Zephyr does not have any such mechanism. This is why we have created the Event Manger. The aim was to keep it universal but since it was done to satisfy needs of a certain project it has its limitations. We tried to keep overhead low and remove concurrency issues. Anyway I am glad that people try to use it.

In nrf_desktop we use separate low-priority thread for long running operations. We were also thinking about splitting long operations into sub-tasks each triggered separately (you can have a look in the optical sensor drivers).

I would like to hear what people find missing in the Event Manager as there is a plan to improve it in the future. I would like to move towards creating an application framework but that is a much bigger task and first we need to see what is really needed.

Thanks,
Pawel


yshragai.firmware@...
 

I suppose the Event Manager has been discontinued as of rev 1.7 of the Nordic SDK?
Is there another library you would suggest for developing event-driven embedded applications?
Thanks!
Yaron


Carles Cufi
 

Hi there,

 

It’s not discontinued, it’s still part of the nRF Connect SDK.

 

There was an attempt to upstream it but there was no agreement on several technical details so it ended up being kept downstream:

https://github.com/zephyrproject-rtos/zephyr/pull/38611

 

Thanks,

 

Carles

 

 

 

From: devel@... <devel@...> On Behalf Of yshragai.firmware via lists.zephyrproject.org
Sent: 21 April 2022 20:38
To: devel@...
Subject: Re: [Zephyr-devel] Event-driven architecture in Zephyr

 

I suppose the Event Manager has been discontinued as of rev 1.7 of the Nordic SDK?
Is there another library you would suggest for developing event-driven embedded applications?
Thanks!
Yaron


yshragai.firmware@...
 

Hi Carles,

Re:
It’s not discontinued, it’s still part of the nRF Connect SDK.
I have nRF Connect SDK v1.9.1. I can't find it. Where should I look?

Thanks,
Yaron


Carles Cufi
 

Hi there,

 

Here:

https://github.com/nrfconnect/sdk-nrf/tree/main/subsys/app_event_manager

 

Thanks,

 

Carles

 

From: devel@... <devel@...> On Behalf Of yshragai.firmware via lists.zephyrproject.org
Sent: 27 April 2022 20:44
To: devel@...
Subject: Re: [Zephyr-devel] Event-driven architecture in Zephyr

 

Hi Carles,

Re:

It’s not discontinued, it’s still part of the nRF Connect SDK.

I have nRF Connect SDK v1.9.1. I can't find it. Where should I look?

Thanks,
Yaron