Re: designing a message "bus"


Jason Bens
 

I’m sure you’ll get a slew of possible implementations, but have you considered implementing the observer pattern?  https://en.wikipedia.org/wiki/Observer_pattern .  If I were to implement this, I’d give each module an event queue to receive messages on, and a list containing pointers to the event queues of other interested modules (the observers).  Observers are notified by iterating over the list and sending the event to each one.  Unfortunately, the granularity of this approach is only to the module level, and so may not meet your needs as described.

 

  • Jason

 

From: users@... <users@...> On Behalf Of yshragai.firmware@...
Sent: May 3, 2022 11:20 PM
To: users@...
Subject: [Zephyr-users] designing a message "bus"

 

External Email:

Hi,

I'm wanting to design a firmware, for a small low-power embedded system, with an architecture that features a "bus" over which the firmware modules communicate. I'm wondering how to design this "bus".

 

Basically what I'm envisioning is modules sending messages over this bus that contain an address or module ID of some sort or another; the module that matches this address or ID would pick up the message off the bus.

 

One brute-force way to design this is a queue (such as a FIFO) per target module. This is not the most elegant or scalable solution, but it'll work... Is there a way to design this that's more scalable, and maybe even elegant?

 

I wish there were a mechanism in Zephyr by which a thread could subscribe to messages in a given queue not by sender ID (as is possible with a mailbox) but by some identifying characteristic of the message (e.g., by the value in the "info" field).

 

Thanks!

Join users@lists.zephyrproject.org to automatically receive all group messages.