mirror of
https://github.com/embassy-rs/embassy.git
synced 2025-09-27 04:10:25 +00:00
add embassy sync channel example for message passing between interrupt and task
This commit is contained in:
parent
ca667f124f
commit
e4aa539708
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user