aboutsummaryrefslogtreecommitdiff
path: root/examples/zero-tasks.rs
diff options
context:
space:
mode:
authorGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-20 22:53:44 -0500
committerGravatar Jorge Aparicio <jorge@japaric.io> 2017-07-20 22:53:44 -0500
commitc7b9507a57f2ba28c18b15dd2719a1c56f74a302 (patch)
tree1fed754475cdbe4baf0d2f1445ce2777b437de31 /examples/zero-tasks.rs
parent23425f2f0645cdfbf78135848fe87f733072ade3 (diff)
downloadrtic-c7b9507a57f2ba28c18b15dd2719a1c56f74a302.tar.gz
rtic-c7b9507a57f2ba28c18b15dd2719a1c56f74a302.tar.zst
rtic-c7b9507a57f2ba28c18b15dd2719a1c56f74a302.zip
`Resource` trait, docs, examples and rtfm-syntax related changes
Diffstat (limited to 'examples/zero-tasks.rs')
-rw-r--r--examples/zero-tasks.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/examples/zero-tasks.rs b/examples/zero-tasks.rs
new file mode 100644
index 00000000..13201677
--- /dev/null
+++ b/examples/zero-tasks.rs
@@ -0,0 +1,49 @@
+//! Minimal example with zero tasks
+
+#![deny(unsafe_code)]
+#![feature(proc_macro)] // IMPORTANT always include this feature gate
+#![no_std]
+
+extern crate cortex_m_rtfm as rtfm; // IMPORTANT always do this rename
+extern crate stm32f103xx; // the device crate
+
+// import the procedural macro
+use rtfm::app;
+
+// This macro call indicates that this is a RTFM application
+//
+// This macro will expand to a `main` function so you don't need to supply
+// `main` yourself.
+app! {
+ // this is a path to the device crate
+ device: stm32f103xx,
+}
+
+// The initialization phase.
+//
+// This runs first and within a *global* critical section. Nothing can preempt
+// this function.
+fn init(p: init::Peripherals) {
+ // This function has access to all the peripherals of the device
+ p.GPIOA;
+ p.RCC;
+ // ..
+
+ // You'll hit this breakpoint first
+ rtfm::bkpt();
+}
+
+// The idle loop.
+//
+// This runs afterwards and has a priority of 0. All tasks can preempt this
+// function. This function can never return so it must contain some sort of
+// endless loop.
+fn idle() -> ! {
+ // And then this breakpoint
+ rtfm::bkpt();
+
+ loop {
+ // This puts the processor to sleep until there's a task to service
+ rtfm::wfi();
+ }
+}