From 5b1c0dbb0aa0f4a3cb0f21ee7531c21558f4a7c3 Mon Sep 17 00:00:00 2001 From: Per Lindgren Date: Mon, 26 Oct 2020 17:16:51 +0100 Subject: [PATCH] async_util --- Cargo.toml | 2 ++ examples/async_systick2.rs | 10 ++++++---- src/lib.rs | 7 +++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6fe5fce38f..9521998397 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -82,6 +82,8 @@ version = "0.5.2" trybuild = "1" [features] +# experimental support for async/await +async = [] # used for testing this crate; do not use in applications __v7 =[] __min_r1_43 =[] diff --git a/examples/async_systick2.rs b/examples/async_systick2.rs index 3f1245332a..618baf61c6 100644 --- a/examples/async_systick2.rs +++ b/examples/async_systick2.rs @@ -91,8 +91,10 @@ mod app { async fn task(mut cx: foo::Context<'static>) { hprintln!("foo task").ok(); - hprintln!("delay long time").ok(); - timer_delay(&mut cx.resources.systick, 5000000).await; + hprintln!("prepare two futures").ok(); + let d1 = timer_delay(&mut cx.resources.systick, 5000000); + let d2 = timer_delay(&mut cx.resources.systick, 1000000); + hprintln!("foo task resumed").ok(); hprintln!("delay short time").ok(); @@ -182,6 +184,7 @@ impl Task { use core::cmp::Ordering; use heapless::binary_heap::{BinaryHeap, Max}; use heapless::consts::U8; +use heapless::Vec; pub enum State { Started, @@ -217,7 +220,6 @@ pub struct Systick { syst: cortex_m::peripheral::SYST, state: State, queue: BinaryHeap, - // waker: Option, } //============= @@ -260,7 +262,7 @@ impl<'a, T: Mutex> Future for Timer<'a, T> { fn timer_delay<'a, T: Mutex>(systick: &'a mut T, t: u32) -> Timer<'a, T> { hprintln!("timer_delay {}", t); Timer { - request: Some(t), + request: heapless, systick, } } diff --git a/src/lib.rs b/src/lib.rs index a7d399cd45..5a17c9c50a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -34,9 +34,16 @@ #![deny(rust_2018_idioms)] #![deny(warnings)] #![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; +// currently requires nightly +#[cfg(feature = "async")] +pub mod async_util; + use cortex_m::{ interrupt::Nr, peripheral::{CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, TPIU},