Skip to content

Commit b7a7e1b

Browse files
committed
Removed core and device from init context in preparation for their disapearance
1 parent 064cf19 commit b7a7e1b

File tree

15 files changed

+26
-98
lines changed

15 files changed

+26
-98
lines changed

rtic-macros/src/codegen/bindings/cortex.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
195195
let nvic_prio_bits = quote!(#device::NVIC_PRIO_BITS);
196196
let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));
197197

198+
stmts.push(quote!(
199+
let mut _nvic = unsafe { core::mem::transmute::<_, rtic::export::NVIC>(()) };
200+
let mut _scb = unsafe { core::mem::transmute::<_, rtic::export::SCB>(()) };
201+
));
202+
198203
// Unmask interrupts and set their priorities
199204
for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| {
200205
if is_exception(&task.args.binds) {
@@ -213,7 +218,7 @@ pub fn pre_init_enable_interrupts(app: &App, analysis: &CodegenAnalysis) -> Vec<
213218
));
214219

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

243-
stmts.push(quote!(core.SCB.set_priority(
248+
stmts.push(quote!(_scb.set_priority(
244249
rtic::export::SystemHandler::#name,
245250
rtic::export::cortex_logical2hw(#priority, #nvic_prio_bits),
246251
);));

rtic-macros/src/codegen/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
4141

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

4646
#(#post_init_stmts)*
4747
});

rtic-macros/src/codegen/module.rs

+1-25
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,12 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
1616

1717
match ctxt {
1818
Context::Init => {
19-
fields.push(quote!(
20-
/// Core peripherals
21-
pub core: rtic::export::Peripherals
22-
));
23-
24-
if app.args.peripherals {
25-
let device = &app.args.device;
26-
27-
fields.push(quote!(
28-
/// Device peripherals (PAC)
29-
pub device: #device::Peripherals
30-
));
31-
32-
values.push(quote!(device: #device::Peripherals::steal()));
33-
}
34-
3519
fields.push(quote!(
3620
/// Critical section token for init
3721
pub cs: rtic::export::CriticalSection<'a>
3822
));
3923

4024
values.push(quote!(cs: rtic::export::CriticalSection::new()));
41-
42-
values.push(quote!(core));
4325
}
4426

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

94-
let core = if ctxt.is_init() {
95-
Some(quote!(core: rtic::export::Peripherals,))
96-
} else {
97-
None
98-
};
99-
10076
let internal_context_name = util::internal_task_ident(name, "Context");
10177
let exec_name = util::internal_task_ident(name, "EXEC");
10278

@@ -115,7 +91,7 @@ pub fn codegen(ctxt: Context, app: &App, analysis: &Analysis) -> TokenStream2 {
11591
impl<'a> #internal_context_name<'a> {
11692
#[inline(always)]
11793
#[allow(missing_docs)]
118-
pub unsafe fn new(#core) -> Self {
94+
pub unsafe fn new() -> Self {
11995
#internal_context_name {
12096
__rtic_internal_p: ::core::marker::PhantomData,
12197
#(#values,)*

rtic-macros/src/codegen/pre_init.rs

-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
1111
// Disable interrupts -- `init` must run with interrupts disabled
1212
stmts.push(quote!(rtic::export::interrupt::disable();));
1313

14-
stmts.push(quote!(
15-
// To set the variable in cortex_m so the peripherals cannot be taken multiple times
16-
let mut core: rtic::export::Peripherals = rtic::export::Peripherals::steal().into();
17-
));
18-
1914
stmts.append(&mut pre_init_checks(app, analysis));
2015

2116
stmts.append(&mut pre_init_enable_interrupts(app, analysis));

rtic-macros/src/syntax/ast.rs

-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ pub struct AppArgs {
5656
/// Device
5757
pub device: Path,
5858

59-
/// Peripherals
60-
pub peripherals: bool,
61-
6259
/// Interrupts used to dispatch software tasks
6360
pub dispatchers: Dispatchers,
6461
}

rtic-macros/src/syntax/parse/app.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use proc_macro2::TokenStream as TokenStream2;
55
use syn::{
66
parse::{self, ParseStream, Parser},
77
spanned::Spanned,
8-
Expr, ExprArray, Fields, ForeignItem, Ident, Item, LitBool, Path, Token, Visibility,
8+
Expr, ExprArray, Fields, ForeignItem, Ident, Item, Path, Token, Visibility,
99
};
1010

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

2928
loop {
@@ -58,17 +57,6 @@ impl AppArgs {
5857
}
5958
}
6059

61-
"peripherals" => {
62-
if let Ok(p) = input.parse::<LitBool>() {
63-
peripherals = p.value;
64-
} else {
65-
return Err(parse::Error::new(
66-
ident.span(),
67-
"unexpected argument value; this should be a boolean",
68-
));
69-
}
70-
}
71-
7260
"dispatchers" => {
7361
if let Ok(p) = input.parse::<ExprArray>() {
7462
for e in p.elems {
@@ -133,7 +121,6 @@ impl AppArgs {
133121

134122
Ok(AppArgs {
135123
device,
136-
peripherals,
137124
dispatchers,
138125
})
139126
})

rtic/CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ For each category, *Added*, *Changed*, *Fixed* add new entries at the top!
1313

1414
### Changed
1515

16+
- `peripherals = ...` is removed
17+
- The context in init has removed `cx.core` and `cx.device`
1618
- `cortex-m` set as an optional dependency
1719
- Moved `cortex-m`-related utilities from `rtic/lib.rs` to `rtic/export.rs`
1820
- Make async task priorities start at 0, instead of 1, to always start at the lowest priority

rtic/ci/expected/peripherals-taken.run

Whitespace-only changes.

rtic/examples/async-delay.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use panic_semihosting as _;
1111

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

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

27+
let core = cortex_m::Peripherals::take().unwrap();
28+
2729
let systick_token = rtic_monotonics::create_systick_token!();
28-
Systick::start(cx.core.SYST, 12_000_000, systick_token);
30+
Systick::start(core.SYST, 12_000_000, systick_token);
2931

3032
foo::spawn().ok();
3133
bar::spawn().ok();

rtic/examples/async-task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use panic_semihosting as _;
1515
// task can have a mutable reference stored.
1616
// - Spawning an async task equates to it being polled once.
1717

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

rtic/examples/async-timeout.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use cortex_m_semihosting::{debug, hprintln};
1111
use panic_semihosting as _;
1212
use rtic_monotonics::systick::*;
1313

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

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

30+
let core = cortex_m::Peripherals::take().unwrap();
31+
3032
let systick_token = rtic_monotonics::create_systick_token!();
31-
Systick::start(cx.core.SYST, 12_000_000, systick_token);
33+
Systick::start(core.SYST, 12_000_000, systick_token);
3234

3335
foo::spawn().ok();
3436

rtic/examples/idle-wfi.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,9 @@ mod app {
1919
struct Local {}
2020

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

25-
// Set the ARM SLEEPONEXIT bit to go to sleep after handling interrupts
26-
// See https://developer.arm.com/docs/100737/0100/power-management/sleep-mode/sleep-on-exit-bit
27-
cx.core.SCB.set_sleepdeep();
28-
2925
(Shared {}, Local {})
3026
}
3127

rtic/examples/init.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
use panic_semihosting as _;
1010

11-
#[rtic::app(device = lm3s6965, peripherals = true)]
11+
#[rtic::app(device = lm3s6965)]
1212
mod app {
1313
use cortex_m_semihosting::{debug, hprintln};
1414

@@ -20,12 +20,6 @@ mod app {
2020

2121
#[init(local = [x: u32 = 0])]
2222
fn init(cx: init::Context) -> (Shared, Local) {
23-
// Cortex-M peripherals
24-
let _core: cortex_m::Peripherals = cx.core;
25-
26-
// Device specific peripherals
27-
let _device: lm3s6965::Peripherals = cx.device;
28-
2923
// Locals in `init` have 'static lifetime
3024
let _x: &'static mut u32 = cx.local.x;
3125

rtic/examples/peripherals-taken.rs

-28
This file was deleted.

rtic/examples/zero-prio-task.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct NotSend {
1515
_0: PhantomData<*const ()>,
1616
}
1717

18-
#[rtic::app(device = lm3s6965, peripherals = true)]
18+
#[rtic::app(device = lm3s6965)]
1919
mod app {
2020
use super::NotSend;
2121
use core::marker::PhantomData;

0 commit comments

Comments
 (0)