mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
async_util
This commit is contained in:
parent
5df1f59f47
commit
5b1c0dbb0a
3 changed files with 15 additions and 4 deletions
|
@ -82,6 +82,8 @@ version = "0.5.2"
|
||||||
trybuild = "1"
|
trybuild = "1"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
# experimental support for async/await
|
||||||
|
async = []
|
||||||
# used for testing this crate; do not use in applications
|
# used for testing this crate; do not use in applications
|
||||||
__v7 =[]
|
__v7 =[]
|
||||||
__min_r1_43 =[]
|
__min_r1_43 =[]
|
||||||
|
|
|
@ -91,8 +91,10 @@ mod app {
|
||||||
async fn task(mut cx: foo::Context<'static>) {
|
async fn task(mut cx: foo::Context<'static>) {
|
||||||
hprintln!("foo task").ok();
|
hprintln!("foo task").ok();
|
||||||
|
|
||||||
hprintln!("delay long time").ok();
|
hprintln!("prepare two futures").ok();
|
||||||
timer_delay(&mut cx.resources.systick, 5000000).await;
|
let d1 = timer_delay(&mut cx.resources.systick, 5000000);
|
||||||
|
let d2 = timer_delay(&mut cx.resources.systick, 1000000);
|
||||||
|
|
||||||
hprintln!("foo task resumed").ok();
|
hprintln!("foo task resumed").ok();
|
||||||
|
|
||||||
hprintln!("delay short time").ok();
|
hprintln!("delay short time").ok();
|
||||||
|
@ -182,6 +184,7 @@ impl<F: Future + 'static> Task<F> {
|
||||||
use core::cmp::Ordering;
|
use core::cmp::Ordering;
|
||||||
use heapless::binary_heap::{BinaryHeap, Max};
|
use heapless::binary_heap::{BinaryHeap, Max};
|
||||||
use heapless::consts::U8;
|
use heapless::consts::U8;
|
||||||
|
use heapless::Vec;
|
||||||
|
|
||||||
pub enum State {
|
pub enum State {
|
||||||
Started,
|
Started,
|
||||||
|
@ -217,7 +220,6 @@ pub struct Systick {
|
||||||
syst: cortex_m::peripheral::SYST,
|
syst: cortex_m::peripheral::SYST,
|
||||||
state: State,
|
state: State,
|
||||||
queue: BinaryHeap<Timeout, U8, Max>,
|
queue: BinaryHeap<Timeout, U8, Max>,
|
||||||
// waker: Option<Waker>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=============
|
//=============
|
||||||
|
@ -260,7 +262,7 @@ impl<'a, T: Mutex<T = Systick>> Future for Timer<'a, T> {
|
||||||
fn timer_delay<'a, T: Mutex<T = Systick>>(systick: &'a mut T, t: u32) -> Timer<'a, T> {
|
fn timer_delay<'a, T: Mutex<T = Systick>>(systick: &'a mut T, t: u32) -> Timer<'a, T> {
|
||||||
hprintln!("timer_delay {}", t);
|
hprintln!("timer_delay {}", t);
|
||||||
Timer {
|
Timer {
|
||||||
request: Some(t),
|
request: heapless,
|
||||||
systick,
|
systick,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,16 @@
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
// async currently requires nightly
|
||||||
|
#![cfg_attr(feature = "async", feature(const_fn))]
|
||||||
|
#![cfg_attr(feature = "async", feature(type_alias_impl_trait))]
|
||||||
|
|
||||||
use core::ops::Sub;
|
use core::ops::Sub;
|
||||||
|
|
||||||
|
// currently requires nightly
|
||||||
|
#[cfg(feature = "async")]
|
||||||
|
pub mod async_util;
|
||||||
|
|
||||||
use cortex_m::{
|
use cortex_m::{
|
||||||
interrupt::Nr,
|
interrupt::Nr,
|
||||||
peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},
|
peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},
|
||||||
|
|
Loading…
Reference in a new issue