1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
//! [compile-pass] Check `schedule` code generation
#![deny(unsafe_code)]
#![deny(warnings)]
#![deny(missing_docs)]
#![no_main]
#![no_std]
use panic_semihosting as _;
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
mod app {
use cortex_m_semihosting::debug;
use systick_monotonic::*;
#[monotonic(binds = SysTick, default = true)]
type MyMono = Systick<100>; // 100 Hz / 10 ms granularity
#[shared]
struct Shared {}
#[local]
struct Local {}
#[init]
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
let systick = cx.core.SYST;
// Initialize the monotonic (SysTick rate in QEMU is 12 MHz)
let mono = Systick::new(systick, 12_000_000);
debug::exit(debug::EXIT_SUCCESS); // Exit QEMU simulator
(Shared {}, Local {}, init::Monotonics(mono))
}
#[idle]
fn idle(_: idle::Context) -> ! {
// Task without message passing
// Not default
let _: Result<foo::MyMono::SpawnHandle, ()> =
foo::MyMono::spawn_at(monotonics::MyMono::now());
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs());
let _: Result<foo::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs());
let _: Result<foo::MyMono::SpawnHandle, ()> =
handle.unwrap().reschedule_at(monotonics::MyMono::now());
let handle: Result<foo::MyMono::SpawnHandle, ()> = foo::MyMono::spawn_after(1.secs());
let _: Result<(), ()> = handle.unwrap().cancel();
// Using default
let _: Result<foo::SpawnHandle, ()> = foo::spawn_at(monotonics::now());
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs());
let _: Result<foo::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs());
let _: Result<foo::SpawnHandle, ()> =
handle.unwrap().reschedule_at(monotonics::MyMono::now());
let handle: Result<foo::SpawnHandle, ()> = foo::spawn_after(1.secs());
let _: Result<(), ()> = handle.unwrap().cancel();
// Task with single message passing
// Not default
let _: Result<bar::MyMono::SpawnHandle, u32> =
bar::MyMono::spawn_at(monotonics::MyMono::now(), 0);
let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1);
let _: Result<bar::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1);
let _: Result<bar::MyMono::SpawnHandle, ()> =
handle.unwrap().reschedule_at(monotonics::MyMono::now());
let handle: Result<bar::MyMono::SpawnHandle, u32> = bar::MyMono::spawn_after(1.secs(), 1);
let _: Result<u32, ()> = handle.unwrap().cancel();
// Using default
let _: Result<bar::SpawnHandle, u32> = bar::spawn_at(monotonics::MyMono::now(), 0);
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1);
let _: Result<bar::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1);
let _: Result<bar::SpawnHandle, ()> =
handle.unwrap().reschedule_at(monotonics::MyMono::now());
let handle: Result<bar::SpawnHandle, u32> = bar::spawn_after(1.secs(), 1);
let _: Result<u32, ()> = handle.unwrap().cancel();
// Task with multiple message passing
// Not default
let _: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_at(monotonics::MyMono::now(), 0, 1);
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_after(1.secs(), 1, 2);
let _: Result<baz::MyMono::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_after(1.secs(), 1, 2);
let _: Result<baz::MyMono::SpawnHandle, ()> =
handle.unwrap().reschedule_at(monotonics::MyMono::now());
let handle: Result<baz::MyMono::SpawnHandle, (u32, u32)> =
baz::MyMono::spawn_after(1.secs(), 1, 2);
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
// Using default
let _: Result<baz::SpawnHandle, (u32, u32)> =
baz::spawn_at(monotonics::MyMono::now(), 0, 1);
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2);
let _: Result<baz::SpawnHandle, ()> = handle.unwrap().reschedule_after(1.secs());
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2);
let _: Result<baz::SpawnHandle, ()> =
handle.unwrap().reschedule_at(monotonics::MyMono::now());
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(1.secs(), 1, 2);
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
loop {
cortex_m::asm::nop();
}
}
#[task]
fn foo(_: foo::Context) {}
#[task]
fn bar(_: bar::Context, _x: u32) {}
#[task]
fn baz(_: baz::Context, _x: u32, _y: u32) {}
}
|