diff options
Diffstat (limited to 'src/examples/_4_nested.rs')
-rw-r--r-- | src/examples/_4_nested.rs | 61 |
1 files changed, 29 insertions, 32 deletions
diff --git a/src/examples/_4_nested.rs b/src/examples/_4_nested.rs index 6be68d8e..d0306210 100644 --- a/src/examples/_4_nested.rs +++ b/src/examples/_4_nested.rs @@ -4,13 +4,11 @@ //! letters in the comments: A, then B, then C, etc. //! //! ``` -//! //! #![deny(unsafe_code)] //! #![feature(const_fn)] //! #![feature(proc_macro)] //! #![no_std] //! -//! #[macro_use(task)] //! extern crate cortex_m_rtfm as rtfm; //! extern crate stm32f103xx; //! @@ -27,19 +25,19 @@ //! //! tasks: { //! EXTI0: { -//! enabled: true, +//! path: exti0, //! priority: 1, //! resources: [LOW, HIGH], //! }, //! //! EXTI1: { -//! enabled: true, +//! path: exti1, //! priority: 2, //! resources: [LOW], //! }, //! //! EXTI2: { -//! enabled: true, +//! path: exti2, //! priority: 3, //! resources: [HIGH], //! }, @@ -49,9 +47,12 @@ //! fn init(_p: init::Peripherals, _r: init::Resources) {} //! //! fn idle() -> ! { -//! // sets task `exti0` as pending +//! // A +//! rtfm::bkpt(); +//! +//! // Sets task `exti0` as pending //! // -//! // because `exti0` has higher priority than `idle` it will be executed +//! // Because `exti0` has higher priority than `idle` it will be executed //! // immediately //! rtfm::set_pending(Interrupt::EXTI0); // ~> exti0 //! @@ -60,72 +61,68 @@ //! } //! } //! -//! task!(EXTI0, exti0); -//! //! fn exti0(t: &mut Threshold, r: EXTI0::Resources) { -//! // because this task has a priority of 1 the preemption threshold is also 1 +//! // Because this task has a priority of 1 the preemption threshold `t` also +//! // starts at 1 //! //! let mut low = r.LOW; //! let mut high = r.HIGH; //! -//! // A +//! // B //! rtfm::bkpt(); //! -//! // because `exti1` has higher priority than `exti0` it can preempt it +//! // Because `exti1` has higher priority than `exti0` it can preempt it //! rtfm::set_pending(Interrupt::EXTI1); // ~> exti1 //! -//! // a claim creates a critical section +//! // A claim creates a critical section //! low.claim_mut(t, |_low, t| { -//! // this claim increases the preemption threshold to 2 -//! // just high enough to not race with task `exti1` for access to the +//! // This claim increases the preemption threshold to 2 +//! // +//! // 2 is just high enough to not race with task `exti1` for access to the //! // `LOW` resource //! -//! // C +//! // D //! rtfm::bkpt(); //! -//! // now `exti1` can't preempt this task because its priority is equal to +//! // Now `exti1` can't preempt this task because its priority is equal to //! // the current preemption threshold //! rtfm::set_pending(Interrupt::EXTI1); //! -//! // but `exti2` can, because its priority is higher than the current +//! // But `exti2` can, because its priority is higher than the current //! // preemption threshold //! rtfm::set_pending(Interrupt::EXTI2); // ~> exti2 //! -//! // E +//! // F //! rtfm::bkpt(); //! -//! // claims can be nested +//! // Claims can be nested //! high.claim_mut(t, |_high, _| { //! // This claim increases the preemption threshold to 3 //! -//! // now `exti2` can't preempt this task +//! // Now `exti2` can't preempt this task //! rtfm::set_pending(Interrupt::EXTI2); //! -//! // F +//! // G //! rtfm::bkpt(); //! }); //! -//! // upon leaving the critical section the preemption threshold drops to 2 -//! // and `exti2` immediately preempts this task +//! // Upon leaving the critical section the preemption threshold drops back +//! // to 2 and `exti2` immediately preempts this task //! // ~> exti2 //! }); //! -//! // once again the preemption threshold drops to 1 -//! // now the pending `exti1` can preempt this task +//! // Once again the preemption threshold drops but this time to 1. Now the +//! // pending `exti1` task can preempt this task //! // ~> exti1 //! } //! -//! task!(EXTI1, exti1); -//! //! fn exti1(_t: &mut Threshold, _r: EXTI1::Resources) { -//! // B, H +//! // C, I //! rtfm::bkpt(); //! } //! -//! task!(EXTI2, exti2); -//! //! fn exti2(_t: &mut Threshold, _r: EXTI2::Resources) { -//! // D, G +//! // E, H //! rtfm::bkpt(); //! } //! ``` |