aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Emil Fresk <emil.fresk@gmail.com> 2020-10-08 17:33:16 +0200
committerGravatar Emil Fresk <emil.fresk@gmail.com> 2020-10-08 17:33:16 +0200
commite8b4fa7b32cf044428971f22e01428ff9cccff3c (patch)
tree6ba42a637d3f08bfbf10cfaaf4727cafd46f1d3c
parent0bc2168cd689f996ab3d7557fd4626bccbd3b954 (diff)
downloadrtic-e8b4fa7b32cf044428971f22e01428ff9cccff3c.tar.gz
rtic-e8b4fa7b32cf044428971f22e01428ff9cccff3c.tar.zst
rtic-e8b4fa7b32cf044428971f22e01428ff9cccff3c.zip
Added critical sections
-rw-r--r--macros/src/codegen/module.rs28
1 files changed, 11 insertions, 17 deletions
diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs
index bba64bb9..1fd3cd42 100644
--- a/macros/src/codegen/module.rs
+++ b/macros/src/codegen/module.rs
@@ -350,13 +350,6 @@ pub fn codegen(
let device = extra.device;
let enum_ = util::interrupt_ident();
let interrupt = &analysis.interrupts.get(&priority);
- let pend = {
- quote!(
- rtic::pend(#device::#enum_::#interrupt);
- )
- };
-
- eprintln!("pend {}", &pend);
items.push(quote!(
#(#cfgs)*
@@ -365,25 +358,26 @@ pub fn codegen(
use rtic::Mutex as _;
let input = #tupled;
- // TODO: use critical section, now we are unsafe
- unsafe {
- if let Some(index) = #app_path::#fq.dequeue() {
+
+ if let Some(index) = rtic::export::interrupt::free(|_| #app_path::#fq.dequeue()) {
+ unsafe {
#app_path::#inputs
.get_unchecked_mut(usize::from(index))
.as_mut_ptr()
.write(input);
+ }
- // #write_instant, do we need?
-
+ rtic::export::interrupt::free(|_| {
#app_path::#rq.enqueue_unchecked((#app_path::#t::#name, index));
+ });
- #pend
+ rtic::pend(#device::#enum_::#interrupt);
- Ok(())
- } else {
- Err(input)
- }
+ Ok(())
+ } else {
+ Err(input)
}
+
}));
}