aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Mueller <[email protected]>2025-07-09 14:02:20 +0200
committerRobin Mueller <[email protected]>2025-07-09 14:10:24 +0200
commite4aa539708781af2474240c5c16456ffe554754b (patch)
treede29ef3ee2c9fbcb89848c72323218f816ca7cce
parentca667f124f20825a0624ae3d6ef3de9def033d90 (diff)
add embassy sync channel example for message passing between interrupt and task
-rw-r--r--embassy-sync/src/channel.rs25
1 files changed, 25 insertions, 0 deletions
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 @@
17//! messages that it can store, and if this limit is reached, trying to send 17//! messages that it can store, and if this limit is reached, trying to send
18//! another message will result in an error being returned. 18//! another message will result in an error being returned.
19//! 19//!
20//! # Example: Message passing between task and interrupt handler
21//!
22//! ```rust
23//! use embassy_sync::channel::Channel;
24//! use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
25//!
26//! static SHARED_CHANNEL: Channel<CriticalSectionRawMutex, u32, 8> = Channel::new();
27//!
28//! fn my_interrupt_handler() {
29//! // Do some work..
30//! // ...
31//! if let Err(e) = SHARED_CHANNEL.sender().try_send(42) {
32//! // Channel is full..
33//! }
34//! }
35//!
36//! async fn my_async_task() {
37//! // ...
38//! let receiver = SHARED_CHANNEL.receiver();
39//! loop {
40//! let data_from_interrupt = receiver.receive().await;
41//! // Do something with the data.
42//! }
43//! }
44//! ```
20 45
21use core::cell::RefCell; 46use core::cell::RefCell;
22use core::future::Future; 47use core::future::Future;