mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-27 14:04:56 +01:00
wip, problem with static Context
This commit is contained in:
parent
99a45ff28e
commit
06e6e9dc9d
5 changed files with 66 additions and 41 deletions
|
@ -14,6 +14,9 @@ readme = "README.md"
|
||||||
repository = "https://github.com/rtfm-rs/cortex-m-rtfm"
|
repository = "https://github.com/rtfm-rs/cortex-m-rtfm"
|
||||||
version = "0.5.0-beta.1"
|
version = "0.5.0-beta.1"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
rtfm-syntax = { path = '../rtfm-syntax' }
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "rtfm"
|
name = "rtfm"
|
||||||
|
|
||||||
|
|
|
@ -7,34 +7,18 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
use core::ops::Generator;
|
use core::ops::Generator;
|
||||||
// use core::mem::MaybeUninit;
|
|
||||||
|
|
||||||
// // #[task(binds = EXTI0, resources = [x])]
|
|
||||||
// // fn bar(cx: bar::Context) {
|
|
||||||
// // let x = cx.resources.x;
|
|
||||||
// // }
|
|
||||||
|
|
||||||
// // expansion
|
|
||||||
// type Foo = impl Generator<Yield = (), Return = !>;
|
|
||||||
|
|
||||||
// static mut X: MaybeUninit<Foo> = MaybeUninit::uninit();
|
|
||||||
|
|
||||||
// fn main() {
|
|
||||||
// // init();
|
|
||||||
// unsafe {
|
|
||||||
// X.as_mut_ptr().write(foo());
|
|
||||||
// }
|
|
||||||
// // idle();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #![deny(unsafe_code)]
|
|
||||||
|
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
use panic_semihosting as _;
|
use panic_semihosting as _;
|
||||||
|
use rtfm::{Exclusive, Mutex};
|
||||||
|
|
||||||
#[rtfm::app(device = lm3s6965)]
|
#[rtfm::app(device = lm3s6965)]
|
||||||
const APP: () = {
|
const APP: () = {
|
||||||
|
struct Resources {
|
||||||
|
#[init(0)]
|
||||||
|
shared: u32,
|
||||||
|
}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) {
|
fn init(_: init::Context) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
@ -43,28 +27,35 @@ const APP: () = {
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
fn idle(_: idle::Context) -> ! {
|
fn idle(_: idle::Context) -> ! {
|
||||||
static mut X: u32 = 0;
|
|
||||||
|
|
||||||
// Safe access to local `static mut` variable
|
|
||||||
let _x: &'static mut u32 = X;
|
|
||||||
|
|
||||||
hprintln!("idle").unwrap();
|
hprintln!("idle").unwrap();
|
||||||
|
rtfm::pend(Interrupt::GPIOA);
|
||||||
|
rtfm::pend(Interrupt::GPIOA);
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[task(binds = GPIOA, resources = [x])]
|
#[task(binds = GPIOA, resources = [shared])]
|
||||||
// in user code the return type will be `impl Generator<..>`
|
// fn foo1(ctx: &'static mut foo1::Context) -> impl Generator<Yield = (), Return = !> {
|
||||||
#[task(binds = GPIOA)]
|
|
||||||
fn foo1(ctx: foo1::Context) -> impl Generator<Yield = (), Return = !> {
|
fn foo1(ctx: foo1::Context) -> impl Generator<Yield = (), Return = !> {
|
||||||
|
let mut local = 0;
|
||||||
|
//let shared_res = Exclusive(ctx.resources.shared);
|
||||||
|
// static shared_res : &mut u32 = ctx.resources.shared;
|
||||||
move || loop {
|
move || loop {
|
||||||
// x.lock(|_| {});
|
hprintln!("foo1_1 {}", local).unwrap();
|
||||||
hprintln!("foo1_1").unwrap();
|
local += 1;
|
||||||
|
// shared_res.lock(|s| hprintln!("s {}", s));
|
||||||
|
// *shared_res += 1;
|
||||||
|
// *ctx.resources.shared += 1;
|
||||||
yield;
|
yield;
|
||||||
hprintln!("foo1_2").unwrap();
|
hprintln!("foo1_2 {}", local).unwrap();
|
||||||
|
local += 1;
|
||||||
yield;
|
yield;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #[task(binds = GPIOB, resources = [shared], priority = 2)]
|
||||||
|
// fn foo2(ctx: foo2::Context) {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,10 +74,12 @@ pub fn codegen(
|
||||||
#let_instant
|
#let_instant
|
||||||
|
|
||||||
rtfm::export::run(PRIORITY, || {
|
rtfm::export::run(PRIORITY, || {
|
||||||
hprintln!("here").unwrap();
|
// TODO: Remove trace
|
||||||
// core::pin::Pin::new(crate::#gen_static.assume_init()).resume();
|
hprintln!("interrupt dispatch").unwrap();
|
||||||
// let stat = &mut core::mem::transmute::<_,#gen_type>(crate::#gen_static);
|
// TODO: possible compiler bug
|
||||||
core::pin::Pin::new(#gen_static.as_mut_ptr()).resume();
|
// core::pin::Pin::new(#gen_static.as_mut_ptr()).resume();
|
||||||
|
let mut g: &mut dyn Generator<Yield = (), Return = !> = &mut *#gen_static.as_mut_ptr();
|
||||||
|
core::pin::Pin::new_unchecked(&mut *g).resume();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
@ -129,8 +131,12 @@ pub fn codegen(
|
||||||
// `${task}Locals`
|
// `${task}Locals`
|
||||||
let mut locals_pat = None;
|
let mut locals_pat = None;
|
||||||
if !task.locals.is_empty() {
|
if !task.locals.is_empty() {
|
||||||
let (struct_, pat) =
|
let (struct_, pat) = locals::codegen(
|
||||||
locals::codegen(Context::HardwareTask(name), &task.locals, core, app);
|
Context::HardwareTask(name),
|
||||||
|
&task.locals,
|
||||||
|
core,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
root.push(struct_);
|
root.push(struct_);
|
||||||
locals_pat = Some(pat);
|
locals_pat = Some(pat);
|
||||||
|
|
|
@ -4,7 +4,12 @@ use rtfm_syntax::{ast::App, Context};
|
||||||
|
|
||||||
use crate::{check::Extra, codegen::util};
|
use crate::{check::Extra, codegen::util};
|
||||||
|
|
||||||
pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> TokenStream2 {
|
pub fn codegen(
|
||||||
|
ctxt: Context,
|
||||||
|
resources_tick: bool,
|
||||||
|
app: &App,
|
||||||
|
extra: &Extra,
|
||||||
|
) -> TokenStream2 {
|
||||||
let mut items = vec![];
|
let mut items = vec![];
|
||||||
let mut fields = vec![];
|
let mut fields = vec![];
|
||||||
let mut values = vec![];
|
let mut values = vec![];
|
||||||
|
@ -184,7 +189,9 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) ->
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
values.push(quote!(spawn: Spawn { _not_send: core::marker::PhantomData }));
|
values.push(
|
||||||
|
quote!(spawn: Spawn { _not_send: core::marker::PhantomData }),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
lt = Some(quote!('a));
|
lt = Some(quote!('a));
|
||||||
|
|
||||||
|
@ -319,6 +326,7 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) ->
|
||||||
#[doc = #doc]
|
#[doc = #doc]
|
||||||
#cfg_core
|
#cfg_core
|
||||||
pub mod #name {
|
pub mod #name {
|
||||||
|
fn plepps() {}
|
||||||
#(#items)*
|
#(#items)*
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -161,10 +161,27 @@ pub fn codegen(
|
||||||
let gen_static = util::gen_static_ident(&name);
|
let gen_static = util::gen_static_ident(&name);
|
||||||
let priority = task.args.priority;
|
let priority = task.args.priority;
|
||||||
|
|
||||||
|
// #[doc(inline)]
|
||||||
|
// pub use super::foo1Resources as Resources;
|
||||||
|
// #[doc = r" Execution context"]
|
||||||
|
// pub struct Context<'a> {
|
||||||
|
// #[doc = r" Resources this task has access to"]
|
||||||
|
// pub resources: Resources<'a>,
|
||||||
|
// }
|
||||||
|
// impl<'a> Context<'a> {
|
||||||
|
// #[inline(always)]
|
||||||
|
// pub unsafe fn new(
|
||||||
|
// priority: &'a rtfm::export::Priority,
|
||||||
|
// ) -> Self {
|
||||||
|
// Context {
|
||||||
|
// resources: Resources::new(priority),
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
stmts.push(quote!(
|
stmts.push(quote!(
|
||||||
const PRIORITY: u8 = #priority;
|
const PRIORITY: u8 = #priority;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
static CTX: #name::Context = #name::Context::new(&rtfm::export::Priority::new(PRIORITY));
|
||||||
#gen_static.as_mut_ptr().write(
|
#gen_static.as_mut_ptr().write(
|
||||||
#name(#name::Context::new(&rtfm::export::Priority::new(PRIORITY)))
|
#name(#name::Context::new(&rtfm::export::Priority::new(PRIORITY)))
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue