From e4aa539708781af2474240c5c16456ffe554754b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Jul 2025 14:02:20 +0200 Subject: add embassy sync channel example for message passing between interrupt and task --- embassy-sync/src/channel.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index dda91c651..a0e39fcb5 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs @@ -17,6 +17,31 @@ //! messages that it can store, and if this limit is reached, trying to send //! another message will result in an error being returned. //! +//! # Example: Message passing between task and interrupt handler +//! +//! ```rust +//! use embassy_sync::channel::Channel; +//! use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; +//! +//! static SHARED_CHANNEL: Channel = Channel::new(); +//! +//! fn my_interrupt_handler() { +//! // Do some work.. +//! // ... +//! if let Err(e) = SHARED_CHANNEL.sender().try_send(42) { +//! // Channel is full.. +//! } +//! } +//! +//! async fn my_async_task() { +//! // ... +//! let receiver = SHARED_CHANNEL.receiver(); +//! loop { +//! let data_from_interrupt = receiver.receive().await; +//! // Do something with the data. +//! } +//! } +//! ``` use core::cell::RefCell; use core::future::Future; -- cgit