.. include:: Message Queues ============== .. topic:: Documentation * :doc:`../why-os/communication` * `Zephyr: Message Queues `__ Basic Usage ----------- * Fixed size data items * ``get()`` *blocks* when no items available * ``put()`` *blocks* when full * ``_nowait()`` variants .. literalinclude:: code/basic.cpp :caption: :download:`code/basic.cpp` :language: c++ Communicating From An ISR Into Thread Context --------------------------------------------- .. topic:: Trainer's note * Copy over spinlock example from :doc:`../spinlocks/index`: :download:`../spinlocks/code/sensor-enqueue-list-spinlock.cpp` * Common pattern: in the ISR, quickly transfer work into an easier - schedulable - context * Producer is an ISR: *cannot* wait |longrightarrow| ``put_noblock()`` * Consumer is a thread: *can* wait |longrightarrow| ``get()`` * Main: not a busy loop anymore * *OS does powermanagement when nothing else happens* .. literalinclude:: code/sensor-messagequeue.cpp :caption: :download:`code/sensor-messagequeue.cpp` :language: c++ .. code-block:: console $ while true; do echo irq 2; done | \ why-shell code/why-mq-sensor-messagequeue