aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Per Lindgren <per.lindgren@ltu.se> 2020-06-15 18:56:10 +0200
committerGravatar Per Lindgren <per.lindgren@ltu.se> 2020-06-15 18:56:10 +0200
commit2d4a960c8bff347bb821c7e6c9a13710b80e7259 (patch)
treed49e3b33f1005cde4d6dded54b689cffff982b71
parent245f4f9b6e32006e0be8f4751aaf10efd3a68d26 (diff)
downloadrtic-2d4a960c8bff347bb821c7e6c9a13710b80e7259.tar.gz
rtic-2d4a960c8bff347bb821c7e6c9a13710b80e7259.tar.zst
rtic-2d4a960c8bff347bb821c7e6c9a13710b80e7259.zip
first attemtp to support Exclusive
-rw-r--r--Cargo.toml2
-rw-r--r--examples/lock5.rs83
-rw-r--r--examples/lock6.rs85
-rw-r--r--examples/lock7.rs82
4 files changed, 252 insertions, 0 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 395501f1..8978f006 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -56,6 +56,8 @@ version = '0.5.3'
[lib]
name = 'rtic'
+
+# path = "../rtic-core"
[patch.crates-io.rtic-core]
git = 'https://github.com/rtic-rs/rtic-core.git'
branch = 'immutable_resource_proxies'
diff --git a/examples/lock5.rs b/examples/lock5.rs
new file mode 100644
index 00000000..36534191
--- /dev/null
+++ b/examples/lock5.rs
@@ -0,0 +1,83 @@
+//! examples/lock.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use cortex_m_semihosting::{debug, hprintln};
+use lm3s6965::Interrupt;
+use panic_semihosting as _;
+use rtic::Mutex;
+use rtic_core::Exclusive;
+
+#[rtic::app(device = lm3s6965)]
+const APP: () = {
+ struct Resources {
+ #[init(0)]
+ shared: u32,
+ }
+
+ #[init]
+ fn init(_: init::Context) {
+ rtic::pend(Interrupt::GPIOA);
+ }
+
+ // when omitted priority is assumed to be `1`
+ #[task(binds = GPIOA, resources = [shared])]
+ fn gpioa(c: gpioa::Context) {
+ hprintln!("A").unwrap();
+
+ // the lower priority task requires a critical section to access the data
+ c.resources.shared.lock(|shared| {
+ // data can only be modified within this critical section (closure)
+ *shared += 1;
+
+ // GPIOB will *not* run right now due to the critical section
+ rtic::pend(Interrupt::GPIOB);
+
+ hprintln!("B - shared = {}", *shared).unwrap();
+
+ // GPIOC does not contend for `shared` so it's allowed to run now
+ rtic::pend(Interrupt::GPIOC);
+ });
+
+ // critical section is over: GPIOB can now start
+
+ hprintln!("E").unwrap();
+
+ debug::exit(debug::EXIT_SUCCESS);
+ }
+
+ #[task(binds = GPIOB, priority = 2, resources = [shared])]
+ fn gpiob(c: gpiob::Context) {
+ c.resources.shared.lock(|shared| {
+ *shared += 1;
+ hprintln!("D - shared = {}", shared).unwrap();
+ });
+ }
+
+ #[task(binds = GPIOC, priority = 3, resources = [shared])]
+ fn gpioc(c: gpioc::Context) {
+ static mut STATE: u32 = 0;
+ hprintln!("GPIOC(STATE = {})", *STATE).unwrap();
+ *c.resources.shared += 2;
+ let ex_shared = Exclusive(c.resources.shared);
+ advance(STATE, ex_shared); // try swap order of (1)
+ *c.resources.shared += 3; // and (2), will fail
+ hprintln!("GPIOC(STATE = {})", *STATE).unwrap();
+ }
+};
+
+// the second parameter is generic: it can be any type that implements the `Mutex` trait
+fn advance(state: &mut u32, shared: impl Mutex<T = u32>) {
+ *state += 1;
+
+ let (old, new) = shared.lock(|shared: &mut u32| {
+ let old = *shared;
+ *shared += *state;
+ (old, *shared)
+ });
+
+ hprintln!("shared: {} -> {}", old, new).unwrap();
+}
diff --git a/examples/lock6.rs b/examples/lock6.rs
new file mode 100644
index 00000000..6cff0dd1
--- /dev/null
+++ b/examples/lock6.rs
@@ -0,0 +1,85 @@
+//! examples/lock.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use cortex_m_semihosting::{debug, hprintln};
+use lm3s6965::Interrupt;
+use panic_semihosting as _;
+use rtic::Mutex;
+use rtic_core::Exclusive;
+
+#[rtic::app(device = lm3s6965)]
+const APP: () = {
+ struct Resources {
+ #[init(0)]
+ shared: u32,
+ }
+
+ #[init]
+ fn init(_: init::Context) {
+ rtic::pend(Interrupt::GPIOA);
+ }
+
+ // when omitted priority is assumed to be `1`
+ #[task(binds = GPIOA, resources = [shared])]
+ fn gpioa(c: gpioa::Context) {
+ hprintln!("A").unwrap();
+
+ // the lower priority task requires a critical section to access the data
+ c.resources.shared.lock(|shared| {
+ // data can only be modified within this critical section (closure)
+ *shared += 1;
+
+ // GPIOB will *not* run right now due to the critical section
+ rtic::pend(Interrupt::GPIOB);
+
+ hprintln!("B - shared = {}", *shared).unwrap();
+
+ // GPIOC does not contend for `shared` so it's allowed to run now
+ rtic::pend(Interrupt::GPIOC);
+ });
+
+ // critical section is over: GPIOB can now start
+
+ hprintln!("E").unwrap();
+
+ debug::exit(debug::EXIT_SUCCESS);
+ }
+
+ #[task(binds = GPIOB, priority = 2, resources = [shared])]
+ fn gpiob(c: gpiob::Context) {
+ c.resources.shared.lock(|shared| {
+ *shared += 1;
+ hprintln!("D - shared = {}", shared).unwrap();
+ });
+ }
+
+ #[task(binds = GPIOC, priority = 3, resources = [shared])]
+ fn gpioc(c: gpioc::Context) {
+ static mut STATE: u32 = 0;
+ hprintln!("GPIOC(STATE = {})", *STATE).unwrap();
+ *c.resources.shared += 2;
+ let mut ex_shared = Exclusive(c.resources.shared);
+ // a mutable exclusive is still possible to DerefMut
+ *ex_shared += 1;
+ advance(STATE, ex_shared); // try swap order of (1)
+ *c.resources.shared += 3; // and (2), will fail
+ hprintln!("GPIOC(STATE = {})", *STATE).unwrap();
+ }
+};
+
+// the second parameter is generic: it can be any type that implements the `Mutex` trait
+fn advance(state: &mut u32, shared: impl Mutex<T = u32>) {
+ *state += 1;
+
+ let (old, new) = shared.lock(|shared: &mut u32| {
+ let old = *shared;
+ *shared += *state;
+ (old, *shared)
+ });
+
+ hprintln!("shared: {} -> {}", old, new).unwrap();
+}
diff --git a/examples/lock7.rs b/examples/lock7.rs
new file mode 100644
index 00000000..cdb950b8
--- /dev/null
+++ b/examples/lock7.rs
@@ -0,0 +1,82 @@
+//! examples/lock.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use cortex_m_semihosting::{debug, hprintln};
+use lm3s6965::Interrupt;
+use panic_semihosting as _;
+use rtic::Mutex;
+use rtic_core::Exclusive;
+
+#[rtic::app(device = lm3s6965)]
+const APP: () = {
+ struct Resources {
+ #[init(0)]
+ shared: u32,
+ }
+
+ #[init]
+ fn init(_: init::Context) {
+ rtic::pend(Interrupt::GPIOA);
+ }
+
+ // when omitted priority is assumed to be `1`
+ #[task(binds = GPIOA, resources = [shared])]
+ fn gpioa(c: gpioa::Context) {
+ hprintln!("A").unwrap();
+
+ // the lower priority task requires a critical section to access the data
+ c.resources.shared.lock(|shared| {
+ // data can only be modified within this critical section (closure)
+ *shared += 1;
+
+ // GPIOB will *not* run right now due to the critical section
+ rtic::pend(Interrupt::GPIOB);
+
+ hprintln!("B - shared = {}", *shared).unwrap();
+
+ // GPIOC does not contend for `shared` so it's allowed to run now
+ rtic::pend(Interrupt::GPIOC);
+ });
+
+ // critical section is over: GPIOB can now start
+
+ hprintln!("E").unwrap();
+
+ debug::exit(debug::EXIT_SUCCESS);
+ }
+
+ #[task(binds = GPIOB, priority = 2, resources = [shared])]
+ fn gpiob(c: gpiob::Context) {
+ c.resources.shared.lock(|shared| {
+ *shared += 1;
+ hprintln!("D - shared = {}", shared).unwrap();
+ });
+ }
+
+ #[task(binds = GPIOC, priority = 3, resources = [shared])]
+ fn gpioc(c: gpioc::Context) {
+ static mut STATE: u32 = 0;
+ hprintln!("GPIOC(STATE = {})", *STATE).unwrap();
+ *c.resources.shared += 2;
+ advance(STATE, *c.resources.shared); // try swap order of (1)
+ *c.resources.shared += 3; // and (2), will fail
+ hprintln!("GPIOC(STATE = {})", *STATE).unwrap();
+ }
+};
+
+// the second parameter is generic: it can be any type that implements the `Mutex` trait
+fn advance(state: &mut u32, shared: impl Mutex<T = u32>) {
+ *state += 1;
+
+ let (old, new) = shared.lock(|shared: &mut u32| {
+ let old = *shared;
+ *shared += *state;
+ (old, *shared)
+ });
+
+ hprintln!("shared: {} -> {}", old, new).unwrap();
+}
26:49 -0700'>2023-09-04fix(HTMLRewriter) buffer response before transform (#4418)Gravatar Ciro Spaciari 18-5941/+6655 2023-09-03initialize JSC for macros from cliGravatar Dylan Conway 1-0/+4 2023-09-03fix(syscall): fix handling syscall errno (#4461)Gravatar Ai Hoshino 2-1/+22 2023-09-02workaround a zig bug (#4440)Gravatar dave caruso 1-3/+4 2023-09-01docs: fix http simple example log statement (#4320)Gravatar Karl Böhlmark 1-1/+1 2023-09-01Fix typo (#4445)Gravatar Jorge Jiménez 1-1/+1 2023-09-01keep export star as (#4451)Gravatar Dylan Conway 1-14/+0 2023-09-01bun-vscode 0.0.8Gravatar Colin McDonnell 3-41/+39 2023-09-01Update commandsGravatar Colin McDonnell 3-4/+6 2023-09-01fix `Bun.serve` with tls and `Bun.file` (#4450)Gravatar Dylan Conway 3-14/+40 2023-09-01exclusive maxGravatar Dylan Conway 1-1/+1 2023-09-01Fix debug console from appears on startGravatar Ashcon Partovi 2-2/+5 2023-09-01Add configuration options to extensionGravatar Ashcon Partovi 5-5/+137 2023-09-01Fix run button starting cwd at /Gravatar Ashcon Partovi 1-0/+2 2023-09-01fix(runtime): fix dns_resolver crash (#4435)Gravatar dave caruso 3-17/+19 2023-09-01Fix background colorGravatar Ashcon Partovi 1-2/+3 2023-09-01Allow older versions of VSCodeGravatar Ashcon Partovi 2-6/+5 2023-09-01Fix README for extensionGravatar Ashcon Partovi 2-7/+12 2023-09-01Update VSCode extensionGravatar Ashcon Partovi 1-3/+4 2023-09-01Fix breakpoint on entry for extensionGravatar Ashcon Partovi 5-18/+15 2023-09-01Add Bun.canReload event to inspectorGravatar Ashcon Partovi 2-0/+17 2023-08-31JavaScript Debug Terminal == Bun TerminalGravatar Ashcon Partovi 1-0/+32 2023-08-31fix(runtime): `fs.cp` edge cases (#4439)Gravatar dave caruso 2-8/+44 2023-08-31only set initial debugger breakpoint once (#4441)Gravatar Dylan Conway 1-2/+11 2023-08-31Make breakpoints faster in VSCode extensionGravatar Ashcon Partovi 1-241/+327 2023-08-31`bun install` correctly join dependency URLs (#4421)Gravatar Julian 6-64/+243 2023-08-31get name if not provided in `FormData.append` (#4434)Gravatar Dylan Conway 4-5/+45 2023-08-31Fix vscode debug terminalGravatar Ashcon Partovi 1-21/+0