Skip to content

Commit

Permalink
Removed core and device from init context in preparation for their di…
Browse files Browse the repository at this point in the history
…sapearance
  • Loading branch information
korken89 committed Mar 31, 2023
1 parent 064cf19 commit b7a7e1b
Show file tree
Hide file tree
Showing 15 changed files with 26 additions and 98 deletions.
9 changes: 7 additions & 2 deletions rtic-macros/src/codegen/bindings/cortex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));

stmts.push(quote!(
let mut _nvic = unsafe { core::mem::transmute::<_, rtic::export::NVIC>(()) };
let mut _scb = unsafe { core::mem::transmute::<_, rtic::export::SCB>(()) };
));

// Unmask interrupts and set their priorities
for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| {
if is_exception(&task.args.binds) {
Expand All @@ -213,7 +218,7 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
));

stmts.push(quote!(
core.NVIC.set_priority(
_nvic.set_priority(
#rt_err::#interrupt::#name,
rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits),
);
Expand All @@ -240,7 +245,7 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
const _: () = if (1 << #nvic_prio_bits) < #priority as usize { ::core::panic!(#es); };
));

stmts.push(quote!(core.SCB.set_priority(
stmts.push(quote!(_scb.set_priority(
rtic::export::SystemHandler::#name,
rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits),
);));
Expand Down
2 changes: 1 addition & 1 deletion rtic-macros/src/codegen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {

// Wrap late_init_stmts in a function to ensure that stack space is reclaimed.
__rtic_init_resources(||{
let (shared_resources, local_resources) = #init_name(#init_name::Context::new(core.into()));
let (shared_resources, local_resources) = #init_name(#init_name::Context::new());

#(#post_init_stmts)*
});
Expand Down
26 changes: 1 addition & 25 deletions rtic-macros/src/codegen/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,12 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {

match ctxt {
Context::Init => {
fields.push(quote!(
/// Core peripherals
pub core: rtic::export::Peripherals
));

if app.args.peripherals {
let device = &app.args.device;

fields.push(quote!(
/// Device peripherals (PAC)
pub device: #device::Peripherals
));

values.push(quote!(device: #device::Peripherals::steal()));
}

fields.push(quote!(
/// Critical section token for init
pub cs: rtic::export::CriticalSection<'a>
));

values.push(quote!(cs: rtic::export::CriticalSection::new()));

values.push(quote!(core));
}

Context::Idle | Context::HardwareTask(_) | Context::SoftwareTask(_) => {}
Expand Down Expand Up @@ -91,12 +73,6 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
_ => &v,
};

let core = if ctxt.is_init() {
Some(quote!(core: rtic::export::Peripherals,))
} else {
None
};

let internal_context_name = util::internal_task_ident(name, "Context");
let exec_name = util::internal_task_ident(name, "EXEC");

Expand All @@ -115,7 +91,7 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
impl<'a> #internal_context_name<'a> {
#[inline(always)]
#[allow(missing_docs)]
pub unsafe fn new(#core) -> Self {
pub unsafe fn new() -> Self {
#internal_context_name {
__rtic_internal_p: ::core::marker::PhantomData,
#(#values,)*
Expand Down
5 changes: 0 additions & 5 deletions rtic-macros/src/codegen/pre_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
// Disable interrupts -- `init` must run with interrupts disabled
stmts.push(quote!(rtic::export::interrupt::disable();));

stmts.push(quote!(
// To set the variable in cortex_m so the peripherals cannot be taken multiple times
let mut core: rtic::export::Peripherals = rtic::export::Peripherals::steal().into();
));

stmts.append(&mut pre_init_checks(app, analysis));

stmts.append(&mut pre_init_enable_interrupts(app, analysis));
Expand Down
3 changes: 0 additions & 3 deletions rtic-macros/src/syntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ pub struct AppArgs {
/// Device
pub device: Path,

/// Peripherals
pub peripherals: bool,

/// Interrupts used to dispatch software tasks
pub dispatchers: Dispatchers,
}
Expand Down
15 changes: 1 addition & 14 deletions rtic-macros/src/syntax/parse/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use proc_macro2::TokenStream as TokenStream2;
use syn::{
parse::{self, ParseStream, Parser},
spanned::Spanned,
Expr, ExprArray, Fields, ForeignItem, Ident, Item, LitBool, Path, Token, Visibility,
Expr, ExprArray, Fields, ForeignItem, Ident, Item, Path, Token, Visibility,
};

use super::Input;
Expand All @@ -23,7 +23,6 @@ impl AppArgs {
(|input: ParseStream<'_>| -> parse::Result<Self> {
let mut custom = Set::new();
let mut device = None;
let mut peripherals = true;
let mut dispatchers = Dispatchers::new();

loop {
Expand Down Expand Up @@ -58,17 +57,6 @@ impl AppArgs {
}
}

"peripherals" => {
if let Ok(p) = input.parse::<LitBool>() {
peripherals = p.value;
} else {
return Err(parse::Error::new(
ident.span(),
"unexpected argument value; this should be a boolean",
));
}
}

"dispatchers" => {
if let Ok(p) = input.parse::<ExprArray>() {
for e in p.elems {
Expand Down Expand Up @@ -133,7 +121,6 @@ impl AppArgs {

Ok(AppArgs {
device,
peripherals,
dispatchers,
})
})
Expand Down
2 changes: 2 additions & 0 deletions rtic/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!

### Changed

- `peripherals = ...` is removed
- The context in init has removed `cx.core` and `cx.device`
- `cortex-m` set as an optional dependency
- Moved `cortex-m`-related utilities from `rtic/lib.rs` to `rtic/export.rs`
- Make async task priorities start at 0, instead of 1, to always start at the lowest priority
Expand Down
Empty file.
8 changes: 5 additions & 3 deletions rtic/examples/async-delay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use panic_semihosting as _;

#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)]
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0])]
mod app {
use cortex_m_semihosting::{debug, hprintln};
use rtic_monotonics::systick::*;
Expand All @@ -21,11 +21,13 @@ mod app {
struct Local {}

#[init]
fn init(cx: init::Context) -> (Shared, Local) {
fn init(_cx: init::Context) -> (Shared, Local) {
hprintln!("init");

let core = cortex_m::Peripherals::take().unwrap();

let systick_token = rtic_monotonics::create_systick_token!();
Systick::start(cx.core.SYST, 12_000_000, systick_token);
Systick::start(core.SYST, 12_000_000, systick_token);

foo::spawn().ok();
bar::spawn().ok();
Expand Down
2 changes: 1 addition & 1 deletion rtic/examples/async-task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use panic_semihosting as _;
// task can have a mutable reference stored.
// - Spawning an async task equates to it being polled once.

#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)]
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0])]
mod app {
use cortex_m_semihosting::{debug, hprintln};

Expand Down
8 changes: 5 additions & 3 deletions rtic/examples/async-timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use cortex_m_semihosting::{debug, hprintln};
use panic_semihosting as _;
use rtic_monotonics::systick::*;

#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0], peripherals = true)]
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, UART0])]
mod app {
use super::*;
use futures::{future::FutureExt, select_biased};
Expand All @@ -24,11 +24,13 @@ mod app {
struct Local {}

#[init]
fn init(cx: init::Context) -> (Shared, Local) {
fn init(_cx: init::Context) -> (Shared, Local) {
hprintln!("init");

let core = cortex_m::Peripherals::take().unwrap();

let systick_token = rtic_monotonics::create_systick_token!();
Systick::start(cx.core.SYST, 12_000_000, systick_token);
Systick::start(core.SYST, 12_000_000, systick_token);

foo::spawn().ok();

Expand Down
6 changes: 1 addition & 5 deletions rtic/examples/idle-wfi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,9 @@ mod app {
struct Local {}

#[init]
fn init(mut cx: init::Context) -> (Shared, Local) {
fn init(_cx: init::Context) -> (Shared, Local) {
hprintln!("init");

// Set the ARM SLEEPONEXIT bit to go to sleep after handling interrupts
// See https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit
cx.core.SCB.set_sleepdeep();

(Shared {}, Local {})
}

Expand Down
8 changes: 1 addition & 7 deletions rtic/examples/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

use panic_semihosting as _;

#[rtic::app(device = lm3s6965, peripherals = true)]
#[rtic::app(device = lm3s6965)]
mod app {
use cortex_m_semihosting::{debug, hprintln};

Expand All @@ -20,12 +20,6 @@ mod app {

#[init(local = [x: u32 = 0])]
fn init(cx: init::Context) -> (Shared, Local) {
// Cortex-M peripherals
let _core: cortex_m::Peripherals = cx.core;

// Device specific peripherals
let _device: lm3s6965::Peripherals = cx.device;

// Locals in `init` have 'static lifetime
let _x: &'static mut u32 = cx.local.x;

Expand Down
28 changes: 0 additions & 28 deletions rtic/examples/peripherals-taken.rs

This file was deleted.

2 changes: 1 addition & 1 deletion rtic/examples/zero-prio-task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct NotSend {
_0: PhantomData<*const ()>,
}

#[rtic::app(device = lm3s6965, peripherals = true)]
#[rtic::app(device = lm3s6965)]
mod app {
use super::NotSend;
use core::marker::PhantomData;
Expand Down

0 comments on commit b7a7e1b

Please sign in to comment.