aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Per Lindgren <per.lindgren@ltu.se> 2021-03-12 01:30:20 +0100
committerGravatar Per Lindgren <per.lindgren@ltu.se> 2021-03-12 01:30:20 +0100
commit37530fd687cad35a66eab75a36e660743ba9c4f9 (patch)
treecbc0fe2edadbb8c77ea3263d9b0dc8c7d963bd4d
parent4b370c3d602a1e43d0bc4f1c8deff629e838c784 (diff)
downloadrtic-37530fd687cad35a66eab75a36e660743ba9c4f9.tar.gz
rtic-37530fd687cad35a66eab75a36e660743ba9c4f9.tar.zst
rtic-37530fd687cad35a66eab75a36e660743ba9c4f9.zip
task local early now with RacyCell
Diffstat (limited to '')
-rw-r--r--examples/binds.rs58
-rw-r--r--examples/task-local-minimal.rs34
-rw-r--r--macros/src/codegen/resources.rs4
-rw-r--r--macros/src/codegen/resources_struct.rs2
4 files changed, 62 insertions, 36 deletions
diff --git a/examples/binds.rs b/examples/binds.rs
new file mode 100644
index 00000000..fbdf86c7
--- /dev/null
+++ b/examples/binds.rs
@@ -0,0 +1,58 @@
+//! examples/binds.rs
+
+#![deny(unsafe_code)]
+#![deny(warnings)]
+#![no_main]
+#![no_std]
+
+use panic_semihosting as _;
+
+// `examples/interrupt.rs` rewritten to use `binds`
+#[rtic::app(device = lm3s6965)]
+mod app {
+ use cortex_m_semihosting::{debug, hprintln};
+ use lm3s6965::Interrupt;
+
+ #[resources]
+ struct Resources {
+ // A local (move), late resource
+ #[task_local]
+ #[init(0)]
+ times: u32,
+ }
+
+ #[init]
+ fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
+ rtic::pend(Interrupt::UART0);
+
+ hprintln!("init").unwrap();
+
+ (init::LateResources {}, init::Monotonics())
+ }
+
+ #[idle]
+ fn idle(_: idle::Context) -> ! {
+ hprintln!("idle").unwrap();
+
+ rtic::pend(Interrupt::UART0);
+
+ debug::exit(debug::EXIT_SUCCESS);
+
+ loop {
+ cortex_m::asm::nop();
+ }
+ }
+
+ #[task(binds = UART0, resources = [times])]
+ fn foo(cx: foo::Context) {
+ let times = cx.resources.times;
+ *times += 1;
+
+ hprintln!(
+ "foo called {} time{}",
+ *times,
+ if *times > 1 { "s" } else { "" }
+ )
+ .unwrap();
+ }
+}
diff --git a/examples/task-local-minimal.rs b/examples/task-local-minimal.rs
deleted file mode 100644
index 29132f00..00000000
--- a/examples/task-local-minimal.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-//! examples/task-local_minimal.rs
-#![deny(unsafe_code)]
-//#![deny(warnings)]
-#![no_main]
-#![no_std]
-
-use panic_semihosting as _;
-
-#[rtic::app(device = lm3s6965)]
-mod app {
- use cortex_m_semihosting::{debug, hprintln};
-
- #[resources]
- struct Resources {
- // A local (move), late resource
- #[task_local]
- task_local: u32,
- }
-
- #[init]
- fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
- (init::LateResources { task_local: 42 }, init::Monotonics())
- }
-
- // task_local is task_local
- #[idle(resources =[task_local])]
- fn idle(cx: idle::Context) -> ! {
- hprintln!("IDLE:l = {}", cx.resources.task_local).unwrap();
- debug::exit(debug::EXIT_SUCCESS);
- loop {
- cortex_m::asm::nop();
- }
- }
-}
diff --git a/macros/src/codegen/resources.rs b/macros/src/codegen/resources.rs
index 68eea4d2..ad01ccbf 100644
--- a/macros/src/codegen/resources.rs
+++ b/macros/src/codegen/resources.rs
@@ -55,9 +55,11 @@ pub fn codegen(
};
let attrs = &res.attrs;
+
+ let doc = format!(" RTIC internal: {}:{}", file!(), line!());
mod_app.push(quote!(
#[allow(non_upper_case_globals)]
- #[doc(hidden)]
+ #[doc = #doc]
#(#attrs)*
#(#cfgs)*
#section
diff --git a/macros/src/codegen/resources_struct.rs b/macros/src/codegen/resources_struct.rs
index 6a21c319..036a34da 100644
--- a/macros/src/codegen/resources_struct.rs
+++ b/macros/src/codegen/resources_struct.rs
@@ -91,7 +91,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
} else {
values.push(quote!(
#(#cfgs)*
- #name: &#mut_ #mangled_name
+ #name: #mangled_name.get_mut_unchecked()
));
}
}