mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-11-25 21:19:35 +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"
|
||||
version = "0.5.0-beta.1"
|
||||
|
||||
[patch.crates-io]
|
||||
rtfm-syntax = { path = '../rtfm-syntax' }
|
||||
|
||||
[lib]
|
||||
name = "rtfm"
|
||||
|
||||
|
|
|
@ -7,34 +7,18 @@
|
|||
#![no_std]
|
||||
|
||||
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 lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
use rtfm::{Exclusive, Mutex};
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
struct Resources {
|
||||
#[init(0)]
|
||||
shared: u32,
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
hprintln!("init").unwrap();
|
||||
|
@ -43,28 +27,35 @@ const APP: () = {
|
|||
|
||||
#[idle]
|
||||
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();
|
||||
rtfm::pend(Interrupt::GPIOA);
|
||||
rtfm::pend(Interrupt::GPIOA);
|
||||
|
||||
debug::exit(debug::EXIT_SUCCESS);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
// #[task(binds = GPIOA, resources = [x])]
|
||||
// in user code the return type will be `impl Generator<..>`
|
||||
#[task(binds = GPIOA)]
|
||||
#[task(binds = GPIOA, resources = [shared])]
|
||||
// fn foo1(ctx: &'static mut 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 {
|
||||
// x.lock(|_| {});
|
||||
hprintln!("foo1_1").unwrap();
|
||||
hprintln!("foo1_1 {}", local).unwrap();
|
||||
local += 1;
|
||||
// shared_res.lock(|s| hprintln!("s {}", s));
|
||||
// *shared_res += 1;
|
||||
// *ctx.resources.shared += 1;
|
||||
yield;
|
||||
hprintln!("foo1_2").unwrap();
|
||||
hprintln!("foo1_2 {}", local).unwrap();
|
||||
local += 1;
|
||||
yield;
|
||||
}
|
||||
}
|
||||
|
||||
// #[task(binds = GPIOB, resources = [shared], priority = 2)]
|
||||
// fn foo2(ctx: foo2::Context) {}
|
||||
};
|
||||
|
|
|
@ -74,10 +74,12 @@ pub fn codegen(
|
|||
#let_instant
|
||||
|
||||
rtfm::export::run(PRIORITY, || {
|
||||
hprintln!("here").unwrap();
|
||||
// core::pin::Pin::new(crate::#gen_static.assume_init()).resume();
|
||||
// let stat = &mut core::mem::transmute::<_,#gen_type>(crate::#gen_static);
|
||||
core::pin::Pin::new(#gen_static.as_mut_ptr()).resume();
|
||||
// TODO: Remove trace
|
||||
hprintln!("interrupt dispatch").unwrap();
|
||||
// TODO: possible compiler bug
|
||||
// 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`
|
||||
let mut locals_pat = None;
|
||||
if !task.locals.is_empty() {
|
||||
let (struct_, pat) =
|
||||
locals::codegen(Context::HardwareTask(name), &task.locals, core, app);
|
||||
let (struct_, pat) = locals::codegen(
|
||||
Context::HardwareTask(name),
|
||||
&task.locals,
|
||||
core,
|
||||
app,
|
||||
);
|
||||
|
||||
root.push(struct_);
|
||||
locals_pat = Some(pat);
|
||||
|
|
|
@ -4,7 +4,12 @@ use rtfm_syntax::{ast::App, Context};
|
|||
|
||||
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 fields = 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 {
|
||||
lt = Some(quote!('a));
|
||||
|
||||
|
@ -319,6 +326,7 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) ->
|
|||
#[doc = #doc]
|
||||
#cfg_core
|
||||
pub mod #name {
|
||||
fn plepps() {}
|
||||
#(#items)*
|
||||
}
|
||||
)
|
||||
|
|
|
@ -161,10 +161,27 @@ pub fn codegen(
|
|||
let gen_static = util::gen_static_ident(&name);
|
||||
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!(
|
||||
const PRIORITY: u8 = #priority;
|
||||
|
||||
unsafe {
|
||||
static CTX: #name::Context = #name::Context::new(&rtfm::export::Priority::new(PRIORITY));
|
||||
#gen_static.as_mut_ptr().write(
|
||||
#name(#name::Context::new(&rtfm::export::Priority::new(PRIORITY)))
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue