add embassy sync channel example for message passing between interrupt and task

This commit is contained in:
Robin Mueller 2025-07-09 14:02:20 +02:00
parent ca667f124f
commit e4aa539708

View File

@ -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<CriticalSectionRawMutex, u32, 8> = 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;