aboutsummaryrefslogtreecommitdiff
path: root/src/examples/_1_one_task.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/examples/_1_one_task.rs')
-rw-r--r--src/examples/_1_one_task.rs58
1 files changed, 32 insertions, 26 deletions
diff --git a/src/examples/_1_one_task.rs b/src/examples/_1_one_task.rs
index 33e8bf7f..1bccc219 100644
--- a/src/examples/_1_one_task.rs
+++ b/src/examples/_1_one_task.rs
@@ -1,14 +1,12 @@
//! An application with one task
//!
//! ```
-//!
//! #![deny(unsafe_code)]
//! #![feature(const_fn)]
//! #![feature(proc_macro)]
//! #![no_std]
//!
//! extern crate cortex_m;
-//! #[macro_use(task)]
//! extern crate cortex_m_rtfm as rtfm;
//! extern crate stm32f103xx;
//!
@@ -18,6 +16,15 @@
//! app! {
//! device: stm32f103xx,
//!
+//! // Here data resources are declared
+//! //
+//! // Data resources are static variables that are safe to share across tasks
+//! resources: {
+//! // Declaration of resources looks exactly like declaration of static
+//! // variables
+//! static ON: bool = false;
+//! },
+//!
//! // Here tasks are declared
//! //
//! // Each task corresponds to an interrupt or an exception. Every time the
@@ -26,22 +33,30 @@
//! tasks: {
//! // Here we declare that we'll use the SYS_TICK exception as a task
//! SYS_TICK: {
+//! // Path to the task handler
+//! path: sys_tick,
+//!
//! // This is the priority of the task.
-//! // 1 is the lowest priority a task can have.
-//! // The maximum priority is determined by the number of priority bits
-//! // the device has. This device has 4 priority bits so 16 is the
-//! // maximum value.
+//! //
+//! // 1 is the lowest priority a task can have, and the maximum
+//! // priority is determined by the number of priority bits the device
+//! // has. `stm32f103xx` has 4 priority bits so 16 is the maximum valid
+//! // value.
+//! //
+//! // You can omit this field. If you do the priority is assumed to be
+//! // 1.
//! priority: 1,
//!
-//! // These are the *resources* associated with this task
+//! // These are the resources this task has access to.
//! //
-//! // The peripherals that the task needs can be listed here
-//! resources: [GPIOC],
+//! // A resource can be a peripheral like `GPIOC` or a static variable
+//! // like `ON`
+//! resources: [GPIOC, ON],
//! },
//! }
//! }
//!
-//! fn init(p: init::Peripherals) {
+//! fn init(p: init::Peripherals, _r: init::Resources) {
//! // power on GPIOC
//! p.RCC.apb2enr.modify(|_, w| w.iopcen().enabled());
//!
@@ -64,26 +79,17 @@
//! }
//! }
//!
-//! // This binds the `sys_tick` handler to the `SYS_TICK` task
-//! //
-//! // This particular handler has local state associated to it. The value of the
-//! // `STATE` variable will be preserved across invocations of this handler
-//! task!(SYS_TICK, sys_tick, Locals {
-//! static STATE: bool = false;
-//! });
-//!
//! // This is the task handler of the SYS_TICK exception
//! //
-//! // `t` is the preemption threshold token. We won't use it this time.
-//! // `l` is the data local to this task. The type here must match the one declared
-//! // in `task!`.
-//! // `r` is the resources this task has access to. `SYS_TICK::Resources` has one
-//! // field per resource declared in `app!`.
-//! fn sys_tick(_t: &mut Threshold, l: &mut Locals, r: SYS_TICK::Resources) {
+//! // `_t` is the preemption threshold token. We won't use it in this program.
+//! //
+//! // `r` is the set of resources this task has access to. `TIMER0_A1::Resources`
+//! // has one field per resource declared in `app!`.
+//! fn sys_tick(_t: &mut Threshold, r: SYS_TICK::Resources) {
//! // toggle state
-//! *l.STATE = !*l.STATE;
+//! **r.ON = !**r.ON;
//!
-//! if *l.STATE {
+//! if **r.ON {
//! // set the pin PC13 high
//! r.GPIOC.bsrr.write(|w| w.bs13().set());
//! } else {