aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorEmil Fresk <emil.fresk@gmail.com>2021-02-23 19:35:26 +0100
committerEmil Fresk <emil.fresk@gmail.com>2021-02-23 21:03:51 +0100
commitcd3484cbab3c4cd7e483e8de19bcdd9498443412 (patch)
treebf7639d1d1b3b20c34c00847030f4d84e5f8b8e7 /examples
parent670cdb92d3a22f1e41c9a69912dbfca885fa5de4 (diff)
GHA update
Fmt fixes Spawn_after did not work with parameters Examples working again Revert "GHA update" This reverts commit e0a71d4859966a6c5cf2629d3cb27e88acada9c0. Readd flags Only add DWT based dep with __v7 flag
Diffstat (limited to 'examples')
-rw-r--r--examples/double_schedule.rs23
-rw-r--r--examples/periodic.rs28
-rw-r--r--examples/schedule.rs40
-rw-r--r--examples/t-schedule.rs51
-rw-r--r--examples/types.rs20
5 files changed, 95 insertions, 67 deletions
diff --git a/examples/double_schedule.rs b/examples/double_schedule.rs
index 77a8e38..403f358 100644
--- a/examples/double_schedule.rs
+++ b/examples/double_schedule.rs
@@ -9,20 +9,35 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
+ use dwt_systick_monotonic::{
+ consts::{U0, U8},
+ DwtSystick,
+ };
+ use rtic::time::duration::Seconds;
+
+ #[monotonic(binds = SysTick, default = true)]
+ type MyMono = DwtSystick<U8, U0, U0>; // 8 MHz
+
#[init]
- fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
+ fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
task1::spawn().ok();
- (init::LateResources {}, init::Monotonics())
+ let mut dcb = cx.core.DCB;
+ let dwt = cx.core.DWT;
+ let systick = cx.core.SYST;
+
+ let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
+
+ (init::LateResources {}, init::Monotonics(mono))
}
#[task]
fn task1(_cx: task1::Context) {
- task2::schedule(_cx.scheduled + 100.cycles()).ok();
+ task2::spawn_after(Seconds(1_u32)).ok();
}
#[task]
fn task2(_cx: task2::Context) {
- task1::schedule(_cx.scheduled + 100.cycles()).ok();
+ task1::spawn_after(Seconds(1_u32)).ok();
}
}
diff --git a/examples/periodic.rs b/examples/periodic.rs
index 29fa6bd..82c2128 100644
--- a/examples/periodic.rs
+++ b/examples/periodic.rs
@@ -10,25 +10,31 @@ use panic_semihosting as _;
// NOTE: does NOT work on QEMU!
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
- use cortex_m_semihosting::hprintln;
- use rtic::cyccnt::{Instant, U32Ext};
+ use dwt_systick_monotonic::{
+ consts::{U0, U8},
+ DwtSystick,
+ };
+ use rtic::time::duration::Seconds;
- const PERIOD: u32 = 8_000_000;
+ #[monotonic(binds = SysTick, default = true)]
+ type MyMono = DwtSystick<U8, U0, U0>; // 8 MHz
#[init]
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
- // omitted: initialization of `CYCCNT`
+ let mut dcb = cx.core.DCB;
+ let dwt = cx.core.DWT;
+ let systick = cx.core.SYST;
- foo::schedule(cx.start + PERIOD.cycles()).unwrap();
+ let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
- (init::LateResources {}, init::Monotonics())
+ foo::spawn_after(Seconds(1_u32)).unwrap();
+
+ (init::LateResources {}, init::Monotonics(mono))
}
#[task]
- fn foo(cx: foo::Context) {
- let now = Instant::now();
- hprintln!("foo(scheduled = {:?}, now = {:?})", cx.scheduled, now).unwrap();
-
- foo::schedule(cx.scheduled + PERIOD.cycles()).unwrap();
+ fn foo(_cx: foo::Context) {
+ // Periodic
+ foo::spawn_after(Seconds(1_u32)).unwrap();
}
}
diff --git a/examples/schedule.rs b/examples/schedule.rs
index 6f6f8cb..cdbdc0d 100644
--- a/examples/schedule.rs
+++ b/examples/schedule.rs
@@ -10,40 +10,42 @@ use panic_halt as _;
// NOTE: does NOT work on QEMU!
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
- use cortex_m::peripheral::DWT;
use cortex_m_semihosting::hprintln;
- use rtic::cyccnt::{Instant, U32Ext as _};
+ use dwt_systick_monotonic::{
+ consts::{U0, U8},
+ DwtSystick,
+ };
+ use rtic::time::duration::Seconds;
+
+ #[monotonic(binds = SysTick, default = true)]
+ type MyMono = DwtSystick<U8, U0, U0>; // 8 MHz
#[init()]
- fn init(mut cx: init::Context) -> (init::LateResources, init::Monotonics) {
- // Initialize (enable) the monotonic timer (CYCCNT)
- cx.core.DCB.enable_trace();
- // required on Cortex-M7 devices that software lock the DWT (e.g. STM32F7)
- DWT::unlock();
- cx.core.DWT.enable_cycle_counter();
+ fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
+ let mut dcb = cx.core.DCB;
+ let dwt = cx.core.DWT;
+ let systick = cx.core.SYST;
- // semantically, the monotonic timer is frozen at time "zero" during `init`
- // NOTE do *not* call `Instant::now` in this context; it will return a nonsense value
- let now = cx.start; // the start time of the system
+ let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
- hprintln!("init @ {:?}", now).unwrap();
+ hprintln!("init").unwrap();
- // Schedule `foo` to run 8e6 cycles (clock cycles) in the future
- foo::schedule(now + 8_000_000.cycles()).unwrap();
+ // Schedule `foo` to run 1 second in the future
+ foo::spawn_after(Seconds(1_u32)).unwrap();
- // Schedule `bar` to run 4e6 cycles in the future
- bar::schedule(now + 4_000_000.cycles()).unwrap();
+ // Schedule `bar` to run 2 seconds in the future
+ bar::spawn_after(Seconds(2_u32)).unwrap();
- (init::LateResources {}, init::Monotonics())
+ (init::LateResources {}, init::Monotonics(mono))
}
#[task]
fn foo(_: foo::Context) {
- hprintln!("foo @ {:?}", Instant::now()).unwrap();
+ hprintln!("foo").unwrap();
}
#[task]
fn bar(_: bar::Context) {
- hprintln!("bar @ {:?}", Instant::now()).unwrap();
+ hprintln!("bar").unwrap();
}
}
diff --git a/examples/t-schedule.rs b/examples/t-schedule.rs
index 1771d41..259b226 100644
--- a/examples/t-schedule.rs
+++ b/examples/t-schedule.rs
@@ -9,48 +9,43 @@ use panic_halt as _;
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
- use rtic::cyccnt::{Instant, U32Ext as _};
+ use dwt_systick_monotonic::{
+ consts::{U0, U8},
+ DwtSystick,
+ };
+ use rtic::time::duration::Seconds;
+
+ #[monotonic(binds = SysTick, default = true)]
+ type MyMono = DwtSystick<U8, U0, U0>; // 8 MHz
#[init]
- fn init(c: init::Context) -> (init::LateResources, init::Monotonics) {
- let _: Result<(), ()> = foo::schedule(c.start + 10.cycles());
- let _: Result<(), u32> = bar::schedule(c.start + 20.cycles(), 0);
- let _: Result<(), (u32, u32)> = baz::schedule(c.start + 30.cycles(), 0, 1);
+ fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
+ let mut dcb = cx.core.DCB;
+ let dwt = cx.core.DWT;
+ let systick = cx.core.SYST;
+
+ let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
- (init::LateResources {}, init::Monotonics())
+ let _: Result<(), ()> = foo::spawn_after(Seconds(1_u32));
+ let _: Result<(), u32> = bar::spawn_after(Seconds(2_u32), 0);
+ let _: Result<(), (u32, u32)> = baz::spawn_after(Seconds(3_u32), 0, 1);
+
+ (init::LateResources {}, init::Monotonics(mono))
}
#[idle]
fn idle(_: idle::Context) -> ! {
- let _: Result<(), ()> = foo::schedule(Instant::now() + 40.cycles());
- let _: Result<(), u32> = bar::schedule(Instant::now() + 50.cycles(), 0);
- let _: Result<(), (u32, u32)> = baz::schedule(Instant::now() + 60.cycles(), 0, 1);
+ let _: Result<(), ()> = foo::spawn_at(MyMono::now() + Seconds(3_u32));
+ let _: Result<(), u32> = bar::spawn_at(MyMono::now() + Seconds(4_u32), 0);
+ let _: Result<(), (u32, u32)> = baz::spawn_at(MyMono::now() + Seconds(5_u32), 0, 1);
loop {
cortex_m::asm::nop();
}
}
- #[task(binds = SVCall)]
- fn svcall(c: svcall::Context) {
- let _: Result<(), ()> = foo::schedule(c.start + 70.cycles());
- let _: Result<(), u32> = bar::schedule(c.start + 80.cycles(), 0);
- let _: Result<(), (u32, u32)> = baz::schedule(c.start + 90.cycles(), 0, 1);
- }
-
- #[task(binds = UART0)]
- fn uart0(c: uart0::Context) {
- let _: Result<(), ()> = foo::schedule(c.start + 100.cycles());
- let _: Result<(), u32> = bar::schedule(c.start + 110.cycles(), 0);
- let _: Result<(), (u32, u32)> = baz::schedule(c.start + 120.cycles(), 0, 1);
- }
-
#[task]
- fn foo(c: foo::Context) {
- let _: Result<(), ()> = foo::schedule(c.scheduled + 130.cycles());
- let _: Result<(), u32> = bar::schedule(c.scheduled + 140.cycles(), 0);
- let _: Result<(), (u32, u32)> = baz::schedule(c.scheduled + 150.cycles(), 0, 1);
- }
+ fn foo(_: foo::Context) {}
#[task]
fn bar(_: bar::Context, _x: u32) {}
diff --git a/examples/types.rs b/examples/types.rs
index 8411eec..ff7deb8 100644
--- a/examples/types.rs
+++ b/examples/types.rs
@@ -10,6 +10,13 @@ use panic_semihosting as _;
#[rtic::app(device = lm3s6965, peripherals = true, dispatchers = [SSI0])]
mod app {
use cortex_m_semihosting::debug;
+ use dwt_systick_monotonic::{
+ consts::{U0, U8},
+ DwtSystick,
+ };
+
+ #[monotonic(binds = SysTick, default = true)]
+ type MyMono = DwtSystick<U8, U0, U0>; // 8 MHz
#[resources]
struct Resources {
@@ -19,13 +26,18 @@ mod app {
#[init]
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
- let _: cyccnt::Instant = cx.start;
- let _: rtic::Peripherals = cx.core;
+ let _: cortex_m::Peripherals = cx.core;
let _: lm3s6965::Peripherals = cx.device;
debug::exit(debug::EXIT_SUCCESS);
- (init::LateResources {}, init::Monotonics())
+ let mut dcb = cx.core.DCB;
+ let dwt = cx.core.DWT;
+ let systick = cx.core.SYST;
+
+ let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
+
+ (init::LateResources {}, init::Monotonics(mono))
}
#[idle]
@@ -37,13 +49,11 @@ mod app {
#[task(binds = UART0, resources = [shared])]
fn uart0(cx: uart0::Context) {
- let _: cyccnt::Instant = cx.start;
let _: resources::shared = cx.resources.shared;
}
#[task(priority = 2, resources = [shared])]
fn foo(cx: foo::Context) {
- let _: cyccnt::Instant = cx.scheduled;
let _: resources::shared = cx.resources.shared;
let _: foo::Resources = cx.resources;
}