mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-01-24 01:59:03 +01:00
Merge #494
494: Resoures take 2 r=korken89 a=korken89 Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
This commit is contained in:
commit
e1a4d001f8
85 changed files with 1094 additions and 1779 deletions
5
.github/workflows/build.yml
vendored
5
.github/workflows/build.yml
vendored
|
@ -138,7 +138,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
use-cross: false
|
use-cross: false
|
||||||
command: check
|
command: check
|
||||||
args: --examples --target=${{ matrix.target }} --features __min_r1_43,${{ env.V7 }}
|
args: --examples --target=${{ matrix.target }} --features ${{ env.V7 }}
|
||||||
|
|
||||||
# Verify the example output with run-pass tests
|
# Verify the example output with run-pass tests
|
||||||
testexamples:
|
testexamples:
|
||||||
|
@ -244,18 +244,15 @@ jobs:
|
||||||
resource
|
resource
|
||||||
lock
|
lock
|
||||||
multilock
|
multilock
|
||||||
late
|
|
||||||
only-shared-access
|
only-shared-access
|
||||||
|
|
||||||
task
|
task
|
||||||
message
|
message
|
||||||
capacity
|
capacity
|
||||||
|
|
||||||
types
|
|
||||||
not-sync
|
not-sync
|
||||||
|
|
||||||
generics
|
generics
|
||||||
cfg
|
|
||||||
pool
|
pool
|
||||||
ramfunc
|
ramfunc
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,12 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
## [v0.6.0-alpha.5] - 2021-07-09
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The new resources syntax is implemented.
|
||||||
|
|
||||||
## [v0.6.0-alpha.4] - 2021-05-27
|
## [v0.6.0-alpha.4] - 2021-05-27
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
19
Cargo.toml
19
Cargo.toml
|
@ -14,7 +14,7 @@ name = "cortex-m-rtic"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
repository = "https://github.com/rtic-rs/cortex-m-rtic"
|
repository = "https://github.com/rtic-rs/cortex-m-rtic"
|
||||||
|
|
||||||
version = "0.6.0-alpha.4"
|
version = "0.6.0-alpha.5"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "rtic"
|
name = "rtic"
|
||||||
|
@ -31,22 +31,10 @@ required-features = ["__v7"]
|
||||||
name = "schedule"
|
name = "schedule"
|
||||||
required-features = ["__v7"]
|
required-features = ["__v7"]
|
||||||
|
|
||||||
[[example]]
|
|
||||||
name = "t-cfg"
|
|
||||||
required-features = ["__v7"]
|
|
||||||
|
|
||||||
[[example]]
|
|
||||||
name = "t-cfg-resources"
|
|
||||||
required-features = ["__min_r1_43"]
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "t-schedule"
|
name = "t-schedule"
|
||||||
required-features = ["__v7"]
|
required-features = ["__v7"]
|
||||||
|
|
||||||
[[example]]
|
|
||||||
name = "types"
|
|
||||||
required-features = ["__v7"]
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "double_schedule"
|
name = "double_schedule"
|
||||||
required-features = ["__v7"]
|
required-features = ["__v7"]
|
||||||
|
@ -54,14 +42,14 @@ required-features = ["__v7"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = "0.7.0"
|
cortex-m = "0.7.0"
|
||||||
cortex-m-rtic-macros = { path = "macros", version = "0.6.0-alpha.4" }
|
cortex-m-rtic-macros = { path = "macros", version = "0.6.0-alpha.4" }
|
||||||
rtic-monotonic = "0.1.0-alpha.1"
|
rtic-monotonic = "0.1.0-alpha.2"
|
||||||
rtic-core = "0.3.1"
|
rtic-core = "0.3.1"
|
||||||
heapless = "0.6.1"
|
heapless = "0.6.1"
|
||||||
bare-metal = "1.0.0"
|
bare-metal = "1.0.0"
|
||||||
generic-array = "0.14"
|
generic-array = "0.14"
|
||||||
|
|
||||||
[dependencies.dwt-systick-monotonic]
|
[dependencies.dwt-systick-monotonic]
|
||||||
version = "0.1.0-alpha.2"
|
version = "0.1.0-alpha.3"
|
||||||
optional = true
|
optional = true
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
@ -81,7 +69,6 @@ trybuild = "1"
|
||||||
[features]
|
[features]
|
||||||
# used for testing this crate; do not use in applications
|
# used for testing this crate; do not use in applications
|
||||||
__v7 = ["dwt-systick-monotonic"]
|
__v7 = ["dwt-systick-monotonic"]
|
||||||
__min_r1_43 = []
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
codegen-units = 1
|
codegen-units = 1
|
||||||
|
|
|
@ -25,27 +25,32 @@ mod app {
|
||||||
use super::BigStruct;
|
use super::BigStruct;
|
||||||
use core::mem::MaybeUninit;
|
use core::mem::MaybeUninit;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
big_struct: &'static mut BigStruct,
|
big_struct: &'static mut BigStruct,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[local]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
struct Local {}
|
||||||
let big_struct = unsafe {
|
|
||||||
static mut BIG_STRUCT: MaybeUninit<BigStruct> = MaybeUninit::uninit();
|
|
||||||
|
|
||||||
|
#[init(local = [bs: MaybeUninit<BigStruct> = MaybeUninit::uninit()])]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
let big_struct = unsafe {
|
||||||
// write directly into the static storage
|
// write directly into the static storage
|
||||||
BIG_STRUCT.as_mut_ptr().write(BigStruct::new());
|
cx.local.bs.as_mut_ptr().write(BigStruct::new());
|
||||||
&mut *BIG_STRUCT.as_mut_ptr()
|
&mut *cx.local.bs.as_mut_ptr()
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
init::LateResources {
|
Shared {
|
||||||
// assign the reference so we can use the resource
|
// assign the reference so we can use the resource
|
||||||
big_struct,
|
big_struct,
|
||||||
},
|
},
|
||||||
|
Local {},
|
||||||
init::Monotonics(),
|
init::Monotonics(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[task(binds = UART0, shared = [big_struct])]
|
||||||
|
fn task(_: task::Context) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,19 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
|
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
@ -35,16 +41,14 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
#[task(binds = UART0, local = [times: u32 = 0])]
|
||||||
fn foo(_: foo::Context) {
|
fn foo(cx: foo::Context) {
|
||||||
static mut TIMES: u32 = 0;
|
*cx.local.times += 1;
|
||||||
|
|
||||||
*TIMES += 1;
|
|
||||||
|
|
||||||
hprintln!(
|
hprintln!(
|
||||||
"foo called {} time{}",
|
"foo called {} time{}",
|
||||||
*TIMES,
|
*cx.local.times,
|
||||||
if *TIMES > 1 { "s" } else { "" }
|
if *cx.local.times > 1 { "s" } else { "" }
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,11 +12,17 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
#[task(binds = UART0)]
|
||||||
|
|
|
@ -13,22 +13,32 @@ mod app {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
use cortex_m_semihosting::hprintln;
|
use cortex_m_semihosting::hprintln;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
#[cfg(debug_assertions)] // <- `true` when using the `dev` profile
|
#[cfg(debug_assertions)] // <- `true` when using the `dev` profile
|
||||||
#[init(0)]
|
|
||||||
count: u32,
|
count: u32,
|
||||||
#[cfg(never)]
|
#[cfg(never)]
|
||||||
#[init(0)]
|
|
||||||
unused: u32,
|
unused: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(
|
||||||
|
Shared {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
count: 0,
|
||||||
|
#[cfg(never)]
|
||||||
|
unused: 1,
|
||||||
|
},
|
||||||
|
Local {},
|
||||||
|
init::Monotonics(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
@ -40,17 +50,17 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(capacity = 2, resources = [count])]
|
#[task(capacity = 2, shared = [count])]
|
||||||
fn foo(mut _cx: foo::Context) {
|
fn foo(mut _cx: foo::Context) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
_cx.resources.count.lock(|count| *count += 1);
|
_cx.shared.count.lock(|count| *count += 1);
|
||||||
|
|
||||||
log::spawn(_cx.resources.count.lock(|count| *count)).unwrap();
|
log::spawn(_cx.shared.count.lock(|count| *count)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this wouldn't compile in `release` mode
|
// this wouldn't compile in `release` mode
|
||||||
// *_cx.resources.count += 1;
|
// *_cx.shared.count += 1;
|
||||||
|
|
||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
@ -58,17 +68,17 @@ mod app {
|
||||||
// The whole task should disappear,
|
// The whole task should disappear,
|
||||||
// currently still present in the Tasks enum
|
// currently still present in the Tasks enum
|
||||||
#[cfg(never)]
|
#[cfg(never)]
|
||||||
#[task(capacity = 2, resources = [count])]
|
#[task(capacity = 2, shared = [count])]
|
||||||
fn foo2(mut _cx: foo2::Context) {
|
fn foo2(mut _cx: foo2::Context) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
_cx.resources.count.lock(|count| *count += 10);
|
_cx.shared.count.lock(|count| *count += 10);
|
||||||
|
|
||||||
log::spawn(_cx.resources.count.lock(|count| *count)).unwrap();
|
log::spawn(_cx.shared.count.lock(|count| *count)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// this wouldn't compile in `release` mode
|
// this wouldn't compile in `release` mode
|
||||||
// *_cx.resources.count += 1;
|
// *_cx.shared.count += 1;
|
||||||
|
|
||||||
// ..
|
// ..
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,65 +0,0 @@
|
||||||
//! examples/cfg.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::debug;
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
use cortex_m_semihosting::hprintln;
|
|
||||||
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
#[cfg(debug_assertions)] // <- `true` when using the `dev` profile
|
|
||||||
#[init(0)]
|
|
||||||
count: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
foo::spawn().unwrap();
|
|
||||||
foo::spawn().unwrap();
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[idle]
|
|
||||||
fn idle(_: idle::Context) -> ! {
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
|
|
||||||
loop {
|
|
||||||
cortex_m::asm::nop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(capacity = 2, resources = [count])]
|
|
||||||
fn foo(mut _cx: foo::Context) {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
{
|
|
||||||
_cx.resources.count.lock(|count| *count += 1);
|
|
||||||
|
|
||||||
log::spawn(_cx.resources.count.lock(|count| *count)).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// this wouldn't compile in `release` mode
|
|
||||||
// *_cx.resources.count += 1;
|
|
||||||
|
|
||||||
// ..
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
#[task(capacity = 2)]
|
|
||||||
fn log(_: log::Context, n: u32) {
|
|
||||||
hprintln!(
|
|
||||||
"foo has been called {} time{}",
|
|
||||||
n,
|
|
||||||
if n == 1 { "" } else { "s" }
|
|
||||||
)
|
|
||||||
.ok();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,39 +12,39 @@ mod app {
|
||||||
use cortex_m_semihosting::hprintln;
|
use cortex_m_semihosting::hprintln;
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
// Some resources to work with
|
// Some resources to work with
|
||||||
#[init(0)]
|
|
||||||
a: u32,
|
a: u32,
|
||||||
#[init(0)]
|
|
||||||
b: u32,
|
b: u32,
|
||||||
#[init(0)]
|
|
||||||
c: u32,
|
c: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared { a: 0, b: 0, c: 0 }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Direct destructure
|
// Direct destructure
|
||||||
#[task(binds = UART0, resources = [&a, &b, &c])]
|
#[task(binds = UART0, shared = [&a, &b, &c])]
|
||||||
fn uart0(cx: uart0::Context) {
|
fn uart0(cx: uart0::Context) {
|
||||||
let a = cx.resources.a;
|
let a = cx.shared.a;
|
||||||
let b = cx.resources.b;
|
let b = cx.shared.b;
|
||||||
let c = cx.resources.c;
|
let c = cx.shared.c;
|
||||||
|
|
||||||
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// De-structure-ing syntax
|
// De-structure-ing syntax
|
||||||
#[task(binds = UART1, resources = [&a, &b, &c])]
|
#[task(binds = UART1, shared = [&a, &b, &c])]
|
||||||
fn uart1(cx: uart1::Context) {
|
fn uart1(cx: uart1::Context) {
|
||||||
let uart1::Resources { a, b, c } = cx.resources;
|
let uart1::SharedResources { a, b, c } = cx.shared;
|
||||||
|
|
||||||
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
hprintln!("UART0: a = {}, b = {}, c = {}", a, b, c).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,8 +15,14 @@ mod app {
|
||||||
#[monotonic(binds = SysTick, default = true)]
|
#[monotonic(binds = SysTick, default = true)]
|
||||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
task1::spawn().ok();
|
task1::spawn().ok();
|
||||||
|
|
||||||
let mut dcb = cx.core.DCB;
|
let mut dcb = cx.core.DCB;
|
||||||
|
@ -25,7 +31,7 @@ mod app {
|
||||||
|
|
||||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics(mono))
|
(Shared {}, Local {}, init::Monotonics(mono))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
|
|
@ -19,13 +19,19 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
|
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -21,11 +21,17 @@ fn foo(_c: app::foo::Context, x: i32, y: u32) {
|
||||||
mod app {
|
mod app {
|
||||||
use crate::foo;
|
use crate::foo;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_c: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn(1, 2).unwrap();
|
foo::spawn(1, 2).unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "Rust" {
|
extern "Rust" {
|
||||||
|
|
|
@ -14,42 +14,40 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
shared: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [shared])]
|
#[task(binds = UART0, shared = [shared], local = [state: u32 = 0])]
|
||||||
fn uart0(c: uart0::Context) {
|
fn uart0(c: uart0::Context) {
|
||||||
static mut STATE: u32 = 0;
|
hprintln!("UART0(STATE = {})", *c.local.state).unwrap();
|
||||||
|
|
||||||
hprintln!("UART0(STATE = {})", *STATE).unwrap();
|
// second argument has type `shared::shared`
|
||||||
|
super::advance(c.local.state, c.shared.shared);
|
||||||
// second argument has type `resources::shared`
|
|
||||||
super::advance(STATE, c.resources.shared);
|
|
||||||
|
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART1, priority = 2, resources = [shared])]
|
#[task(binds = UART1, priority = 2, shared = [shared], local = [state: u32 = 0])]
|
||||||
fn uart1(c: uart1::Context) {
|
fn uart1(c: uart1::Context) {
|
||||||
static mut STATE: u32 = 0;
|
hprintln!("UART1(STATE = {})", *c.local.state).unwrap();
|
||||||
|
|
||||||
hprintln!("UART1(STATE = {})", *STATE).unwrap();
|
// second argument has type `shared::shared`
|
||||||
|
super::advance(c.local.state, c.shared.shared);
|
||||||
// second argument has type `resources::shared`
|
|
||||||
super::advance(STATE, c.resources.shared);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,15 +12,21 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
// Pends the UART0 interrupt but its handler won't run until *after*
|
// Pends the UART0 interrupt but its handler won't run until *after*
|
||||||
// `init` returns because interrupts are disabled
|
// `init` returns because interrupts are disabled
|
||||||
rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
|
rtic::pend(Interrupt::UART0); // equivalent to NVIC::pend
|
||||||
|
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
@ -38,17 +44,15 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
#[task(binds = UART0, local = [times: u32 = 0])]
|
||||||
fn uart0(_: uart0::Context) {
|
fn uart0(cx: uart0::Context) {
|
||||||
static mut TIMES: u32 = 0;
|
|
||||||
|
|
||||||
// Safe access to local `static mut` variable
|
// Safe access to local `static mut` variable
|
||||||
*TIMES += 1;
|
*cx.local.times += 1;
|
||||||
|
|
||||||
hprintln!(
|
hprintln!(
|
||||||
"UART0 called {} time{}",
|
"UART0 called {} time{}",
|
||||||
*TIMES,
|
*cx.local.times,
|
||||||
if *TIMES > 1 { "s" } else { "" }
|
if *cx.local.times > 1 { "s" } else { "" }
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,19 +11,23 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
hprintln!("init").unwrap();
|
hprintln!("init").unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle(local = [x: u32 = 0])]
|
||||||
fn idle(_: idle::Context) -> ! {
|
fn idle(cx: idle::Context) -> ! {
|
||||||
static mut X: u32 = 0;
|
// Locals in idle have lifetime 'static
|
||||||
|
let _x: &'static mut u32 = cx.local.x;
|
||||||
// Safe access to local `static mut` variable
|
|
||||||
let _x: &'static mut u32 = X;
|
|
||||||
|
|
||||||
hprintln!("idle").unwrap();
|
hprintln!("idle").unwrap();
|
||||||
|
|
||||||
|
|
|
@ -11,18 +11,22 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
#[init]
|
#[shared]
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
struct Shared {}
|
||||||
static mut X: u32 = 0;
|
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init(local = [x: u32 = 0])]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
// Cortex-M peripherals
|
// Cortex-M peripherals
|
||||||
let _core: cortex_m::Peripherals = cx.core;
|
let _core: cortex_m::Peripherals = cx.core;
|
||||||
|
|
||||||
// Device specific peripherals
|
// Device specific peripherals
|
||||||
let _device: lm3s6965::Peripherals = cx.device;
|
let _device: lm3s6965::Peripherals = cx.device;
|
||||||
|
|
||||||
// Safe access to local `static mut` variable
|
// Locals in `init` have 'static lifetime
|
||||||
let _x: &'static mut u32 = X;
|
let _x: &'static mut u32 = cx.local.x;
|
||||||
|
|
||||||
// Access to the critical section token,
|
// Access to the critical section token,
|
||||||
// to indicate that this is a critical seciton
|
// to indicate that this is a critical seciton
|
||||||
|
@ -32,6 +36,6 @@ mod app {
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,26 +12,28 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
shared: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::GPIOA);
|
rtic::pend(Interrupt::GPIOA);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
// when omitted priority is assumed to be `1`
|
// when omitted priority is assumed to be `1`
|
||||||
#[task(binds = GPIOA, resources = [shared])]
|
#[task(binds = GPIOA, shared = [shared])]
|
||||||
fn gpioa(mut c: gpioa::Context) {
|
fn gpioa(mut c: gpioa::Context) {
|
||||||
hprintln!("A").unwrap();
|
hprintln!("A").unwrap();
|
||||||
|
|
||||||
// the lower priority task requires a critical section to access the data
|
// the lower priority task requires a critical section to access the data
|
||||||
c.resources.shared.lock(|shared| {
|
c.shared.shared.lock(|shared| {
|
||||||
// data can only be modified within this critical section (closure)
|
// data can only be modified within this critical section (closure)
|
||||||
*shared += 1;
|
*shared += 1;
|
||||||
|
|
||||||
|
@ -51,10 +53,10 @@ mod app {
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = GPIOB, priority = 2, resources = [shared])]
|
#[task(binds = GPIOB, priority = 2, shared = [shared])]
|
||||||
fn gpiob(mut c: gpiob::Context) {
|
fn gpiob(mut c: gpiob::Context) {
|
||||||
// the higher priority task does still need a critical section
|
// the higher priority task does still need a critical section
|
||||||
let shared = c.resources.shared.lock(|shared| {
|
let shared = c.shared.shared.lock(|shared| {
|
||||||
*shared += 1;
|
*shared += 1;
|
||||||
|
|
||||||
*shared
|
*shared
|
||||||
|
|
|
@ -11,21 +11,25 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn(/* no message */).unwrap();
|
foo::spawn(/* no message */).unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task(local = [count: u32 = 0])]
|
||||||
fn foo(_: foo::Context) {
|
fn foo(cx: foo::Context) {
|
||||||
static mut COUNT: u32 = 0;
|
|
||||||
|
|
||||||
hprintln!("foo").unwrap();
|
hprintln!("foo").unwrap();
|
||||||
|
|
||||||
bar::spawn(*COUNT).unwrap();
|
bar::spawn(*cx.local.count).unwrap();
|
||||||
*COUNT += 1;
|
*cx.local.count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
|
|
@ -14,29 +14,37 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
#[init(0)]
|
|
||||||
shared1: u32,
|
shared1: u32,
|
||||||
#[init(0)]
|
|
||||||
shared2: u32,
|
shared2: u32,
|
||||||
#[init(0)]
|
|
||||||
shared3: u32,
|
shared3: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::GPIOA);
|
rtic::pend(Interrupt::GPIOA);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(
|
||||||
|
Shared {
|
||||||
|
shared1: 0,
|
||||||
|
shared2: 0,
|
||||||
|
shared3: 0,
|
||||||
|
},
|
||||||
|
Local {},
|
||||||
|
init::Monotonics(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// when omitted priority is assumed to be `1`
|
// when omitted priority is assumed to be `1`
|
||||||
#[task(binds = GPIOA, resources = [shared1, shared2, shared3])]
|
#[task(binds = GPIOA, shared = [shared1, shared2, shared3])]
|
||||||
fn locks(c: locks::Context) {
|
fn locks(c: locks::Context) {
|
||||||
let mut s1 = c.resources.shared1;
|
let mut s1 = c.shared.shared1;
|
||||||
let mut s2 = c.resources.shared2;
|
let mut s2 = c.shared.shared2;
|
||||||
let mut s3 = c.resources.shared3;
|
let mut s3 = c.shared.shared3;
|
||||||
|
|
||||||
hprintln!("Multiple single locks").unwrap();
|
hprintln!("Multiple single locks").unwrap();
|
||||||
s1.lock(|s1| {
|
s1.lock(|s1| {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! `examples/not-sync.rs`
|
//! `examples/not-sync.rs`
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
// #![deny(unsafe_code)]
|
||||||
#![deny(warnings)]
|
#![deny(warnings)]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
@ -12,32 +12,42 @@ pub struct NotSync {
|
||||||
_0: PhantomData<*const ()>,
|
_0: PhantomData<*const ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsafe impl Send for NotSync {}
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||||
mod app {
|
mod app {
|
||||||
use super::NotSync;
|
use super::NotSync;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::debug;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
#[init(NotSync { _0: PhantomData })]
|
|
||||||
shared: NotSync,
|
shared: NotSync,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(
|
||||||
|
Shared {
|
||||||
|
shared: NotSync { _0: PhantomData },
|
||||||
|
},
|
||||||
|
Local {},
|
||||||
|
init::Monotonics(),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(resources = [&shared])]
|
#[task(shared = [&shared])]
|
||||||
fn foo(c: foo::Context) {
|
fn foo(c: foo::Context) {
|
||||||
let _: &NotSync = c.resources.shared;
|
let _: &NotSync = c.shared.shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(resources = [&shared])]
|
#[task(shared = [&shared])]
|
||||||
fn bar(c: bar::Context) {
|
fn bar(c: bar::Context) {
|
||||||
let _: &NotSync = c.resources.shared;
|
let _: &NotSync = c.shared.shared;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,29 +12,32 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
key: u32,
|
key: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(init::LateResources { key: 0xdeadbeef }, init::Monotonics())
|
(Shared { key: 0xdeadbeef }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [&key])]
|
#[task(binds = UART0, shared = [&key])]
|
||||||
fn uart0(cx: uart0::Context) {
|
fn uart0(cx: uart0::Context) {
|
||||||
let key: &u32 = cx.resources.key;
|
let key: &u32 = cx.shared.key;
|
||||||
hprintln!("UART0(key = {:#x})", key).unwrap();
|
hprintln!("UART0(key = {:#x})", key).unwrap();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART1, priority = 2, resources = [&key])]
|
#[task(binds = UART1, priority = 2, shared = [&key])]
|
||||||
fn uart1(cx: uart1::Context) {
|
fn uart1(cx: uart1::Context) {
|
||||||
hprintln!("UART1(key = {:#x})", cx.resources.key).unwrap();
|
hprintln!("UART1(key = {:#x})", cx.shared.key).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,14 @@ mod app {
|
||||||
#[monotonic(binds = SysTick, default = true)]
|
#[monotonic(binds = SysTick, default = true)]
|
||||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
let mut dcb = cx.core.DCB;
|
let mut dcb = cx.core.DCB;
|
||||||
let dwt = cx.core.DWT;
|
let dwt = cx.core.DWT;
|
||||||
let systick = cx.core.SYST;
|
let systick = cx.core.SYST;
|
||||||
|
@ -26,7 +32,7 @@ mod app {
|
||||||
|
|
||||||
foo::spawn_after(Seconds(1_u32)).unwrap();
|
foo::spawn_after(Seconds(1_u32)).unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics(mono))
|
(Shared {}, Local {}, init::Monotonics(mono))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
|
|
@ -9,11 +9,17 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::debug;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
assert!(cortex_m::Peripherals::take().is_none());
|
assert!(cortex_m::Peripherals::take().is_none());
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,16 +24,20 @@ mod app {
|
||||||
// Import the memory pool into scope
|
// Import the memory pool into scope
|
||||||
use super::P;
|
use super::P;
|
||||||
|
|
||||||
#[init]
|
#[shared]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
struct Shared {}
|
||||||
static mut MEMORY: [u8; 512] = [0; 512];
|
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init(local = [memory: [u8; 512] = [0; 512]])]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
// Increase the capacity of the memory pool by ~4
|
// Increase the capacity of the memory pool by ~4
|
||||||
P::grow(MEMORY);
|
P::grow(cx.local.memory);
|
||||||
|
|
||||||
rtic::pend(Interrupt::I2C0);
|
rtic::pend(Interrupt::I2C0);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = I2C0, priority = 2)]
|
#[task(binds = I2C0, priority = 2)]
|
||||||
|
|
|
@ -11,11 +11,17 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::GPIOA);
|
rtic::pend(Interrupt::GPIOA);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = GPIOA, priority = 1)]
|
#[task(binds = GPIOA, priority = 1)]
|
||||||
|
|
|
@ -18,11 +18,17 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(never)]
|
#[inline(never)]
|
||||||
|
|
|
@ -12,26 +12,28 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
// A resource
|
// A resource
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
shared: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should not collide with the struct above
|
// Should not collide with the struct above
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
struct Resources2 {
|
struct Shared2 {
|
||||||
// A resource
|
// A resource
|
||||||
shared: u32,
|
shared: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
// `shared` cannot be accessed from this context
|
// `shared` cannot be accessed from this context
|
||||||
|
@ -39,16 +41,16 @@ mod app {
|
||||||
fn idle(_cx: idle::Context) -> ! {
|
fn idle(_cx: idle::Context) -> ! {
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
|
||||||
// error: no `resources` field in `idle::Context`
|
// error: no `shared` field in `idle::Context`
|
||||||
// _cx.resources.shared += 1;
|
// _cx.shared.shared += 1;
|
||||||
|
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
// `shared` can be accessed from this context
|
||||||
#[task(binds = UART0, resources = [shared])]
|
#[task(binds = UART0, shared = [shared])]
|
||||||
fn uart0(mut cx: uart0::Context) {
|
fn uart0(mut cx: uart0::Context) {
|
||||||
let shared = cx.resources.shared.lock(|shared| {
|
let shared = cx.shared.shared.lock(|shared| {
|
||||||
*shared += 1;
|
*shared += 1;
|
||||||
*shared
|
*shared
|
||||||
});
|
});
|
||||||
|
@ -57,9 +59,9 @@ mod app {
|
||||||
}
|
}
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
// `shared` can be accessed from this context
|
||||||
#[task(binds = UART1, resources = [shared])]
|
#[task(binds = UART1, shared = [shared])]
|
||||||
fn uart1(mut cx: uart1::Context) {
|
fn uart1(mut cx: uart1::Context) {
|
||||||
let shared = cx.resources.shared.lock(|shared| {
|
let shared = cx.shared.shared.lock(|shared| {
|
||||||
*shared += 1;
|
*shared += 1;
|
||||||
*shared
|
*shared
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,19 +12,20 @@ mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
// A resource
|
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
shared: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(Interrupt::UART0);
|
rtic::pend(Interrupt::UART0);
|
||||||
rtic::pend(Interrupt::UART1);
|
rtic::pend(Interrupt::UART1);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared { shared: 0 }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
// `shared` cannot be accessed from this context
|
// `shared` cannot be accessed from this context
|
||||||
|
@ -32,8 +33,8 @@ mod app {
|
||||||
fn idle(_cx: idle::Context) -> ! {
|
fn idle(_cx: idle::Context) -> ! {
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
|
||||||
// error: no `resources` field in `idle::Context`
|
// error: no `shared` field in `idle::Context`
|
||||||
// _cx.resources.shared += 1;
|
// _cx.shared.shared += 1;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
cortex_m::asm::nop();
|
cortex_m::asm::nop();
|
||||||
|
@ -42,9 +43,9 @@ mod app {
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
// `shared` can be accessed from this context
|
||||||
// defaults to priority 1
|
// defaults to priority 1
|
||||||
#[task(binds = UART0, resources = [shared])]
|
#[task(binds = UART0, shared = [shared])]
|
||||||
fn uart0(mut cx: uart0::Context) {
|
fn uart0(mut cx: uart0::Context) {
|
||||||
let shared = cx.resources.shared.lock(|shared| {
|
let shared = cx.shared.shared.lock(|shared| {
|
||||||
*shared += 1;
|
*shared += 1;
|
||||||
*shared
|
*shared
|
||||||
});
|
});
|
||||||
|
@ -54,9 +55,9 @@ mod app {
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
// `shared` can be accessed from this context
|
||||||
// explicitly set to priority 2
|
// explicitly set to priority 2
|
||||||
#[task(binds = UART1, resources = [shared], priority = 2)]
|
#[task(binds = UART1, shared = [shared], priority = 2)]
|
||||||
fn uart1(mut cx: uart1::Context) {
|
fn uart1(mut cx: uart1::Context) {
|
||||||
let shared = cx.resources.shared.lock(|shared| {
|
let shared = cx.shared.shared.lock(|shared| {
|
||||||
*shared += 1;
|
*shared += 1;
|
||||||
*shared
|
*shared
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,8 +19,14 @@ mod app {
|
||||||
#[monotonic(binds = SysTick, default = true)]
|
#[monotonic(binds = SysTick, default = true)]
|
||||||
type MyMono = DwtSystick<MONO_HZ>;
|
type MyMono = DwtSystick<MONO_HZ>;
|
||||||
|
|
||||||
#[init()]
|
#[shared]
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
let mut dcb = cx.core.DCB;
|
let mut dcb = cx.core.DCB;
|
||||||
let dwt = cx.core.DWT;
|
let dwt = cx.core.DWT;
|
||||||
let systick = cx.core.SYST;
|
let systick = cx.core.SYST;
|
||||||
|
@ -35,7 +41,7 @@ mod app {
|
||||||
// Schedule `bar` to run 2 seconds in the future
|
// Schedule `bar` to run 2 seconds in the future
|
||||||
bar::spawn_after(Seconds(2_u32)).ok();
|
bar::spawn_after(Seconds(2_u32)).ok();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics(mono))
|
(Shared {}, Local {}, init::Monotonics(mono))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
|
|
@ -17,27 +17,27 @@ mod app {
|
||||||
};
|
};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
// Late resources
|
#[shared]
|
||||||
#[resources]
|
struct Shared {
|
||||||
struct Resources {
|
|
||||||
p: Producer<'static, u32, U4>,
|
p: Producer<'static, u32, U4>,
|
||||||
c: Consumer<'static, u32, U4>,
|
c: Consumer<'static, u32, U4>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[local]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
struct Local {}
|
||||||
static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
|
|
||||||
|
|
||||||
let (p, c) = Q.split();
|
#[init(local = [q: Queue<u32, U4> = Queue(i::Queue::new())])]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
let (p, c) = cx.local.q.split();
|
||||||
|
|
||||||
// Initialization of late resources
|
// Initialization of shared resources
|
||||||
(init::LateResources { p, c }, init::Monotonics())
|
(Shared { p, c }, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(resources = [c])]
|
#[idle(shared = [c])]
|
||||||
fn idle(mut c: idle::Context) -> ! {
|
fn idle(mut c: idle::Context) -> ! {
|
||||||
loop {
|
loop {
|
||||||
if let Some(byte) = c.resources.c.lock(|c| c.dequeue()) {
|
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
|
||||||
hprintln!("received message: {}", byte).unwrap();
|
hprintln!("received message: {}", byte).unwrap();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
@ -47,8 +47,8 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [p])]
|
#[task(binds = UART0, shared = [p])]
|
||||||
fn uart0(mut c: uart0::Context) {
|
fn uart0(mut c: uart0::Context) {
|
||||||
c.resources.p.lock(|p| p.enqueue(42).unwrap());
|
c.shared.p.lock(|p| p.enqueue(42).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -7,4 +7,15 @@ use panic_semihosting as _; // panic handler
|
||||||
use rtic::app;
|
use rtic::app;
|
||||||
|
|
||||||
#[app(device = lm3s6965)]
|
#[app(device = lm3s6965)]
|
||||||
mod app {}
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,11 +11,17 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_c: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn(1, 2).unwrap();
|
foo::spawn(1, 2).unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task()]
|
#[task()]
|
||||||
|
|
|
@ -11,11 +11,17 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_c: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn(1, 2).unwrap();
|
foo::spawn(1, 2).unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
|
|
@ -18,27 +18,26 @@ mod app {
|
||||||
};
|
};
|
||||||
use lm3s6965::Interrupt;
|
use lm3s6965::Interrupt;
|
||||||
|
|
||||||
// Late resources
|
#[shared]
|
||||||
#[resources]
|
struct Shared {
|
||||||
struct Resources {
|
|
||||||
p: Producer<'static, u32, U4>,
|
p: Producer<'static, u32, U4>,
|
||||||
c: Consumer<'static, u32, U4>,
|
c: Consumer<'static, u32, U4>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[init]
|
#[local]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
struct Local {}
|
||||||
static mut Q: Queue<u32, U4> = Queue(i::Queue::new());
|
|
||||||
|
|
||||||
let (p, c) = Q.split();
|
#[init(local = [q: Queue<u32, U4> = Queue(i::Queue::new())])]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
let (p, c) = cx.local.q.split();
|
||||||
|
|
||||||
// Initialization of late resources
|
(Shared { p, c }, Local {}, init::Monotonics())
|
||||||
(init::LateResources { p, c }, init::Monotonics())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(resources = [c])]
|
#[idle(shared = [c])]
|
||||||
fn idle(mut c: idle::Context) -> ! {
|
fn idle(mut c: idle::Context) -> ! {
|
||||||
loop {
|
loop {
|
||||||
if let Some(byte) = c.resources.c.lock(|c| c.dequeue()) {
|
if let Some(byte) = c.shared.c.lock(|c| c.dequeue()) {
|
||||||
hprintln!("received message: {}", byte).unwrap();
|
hprintln!("received message: {}", byte).unwrap();
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
debug::exit(debug::EXIT_SUCCESS);
|
||||||
|
@ -48,10 +47,9 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [p])]
|
#[task(binds = UART0, shared = [p], local = [kalle: u32 = 0])]
|
||||||
fn uart0(mut c: uart0::Context) {
|
fn uart0(mut c: uart0::Context) {
|
||||||
static mut KALLE: u32 = 0;
|
*c.local.kalle += 1;
|
||||||
*KALLE += 1;
|
c.shared.p.lock(|p| p.enqueue(42).unwrap());
|
||||||
c.resources.p.lock(|p| p.enqueue(42).unwrap());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,9 +9,15 @@ use panic_semihosting as _;
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
#[rtic::app(device = lm3s6965)]
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cortex-M exception
|
// Cortex-M exception
|
||||||
|
|
|
@ -7,25 +7,24 @@ use panic_semihosting as _;
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
#[rtic::app(device = lm3s6965)]
|
||||||
mod app {
|
mod app {
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
// A resource
|
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
|
||||||
// A conditionally compiled resource behind feature_x
|
// A conditionally compiled resource behind feature_x
|
||||||
#[cfg(feature = "feature_x")]
|
#[cfg(feature = "feature_x")]
|
||||||
x: u32,
|
x: u32,
|
||||||
dummy: (), // dummy such that we have at least one late resource
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
(
|
(
|
||||||
init::LateResources {
|
Shared {
|
||||||
// The feature needs to be applied everywhere x is defined or used
|
|
||||||
#[cfg(feature = "feature_x")]
|
#[cfg(feature = "feature_x")]
|
||||||
x: 0,
|
x: 0,
|
||||||
dummy: (), // dummy such that we have at least one late resource
|
|
||||||
},
|
},
|
||||||
|
Local {},
|
||||||
init::Monotonics(),
|
init::Monotonics(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,50 +0,0 @@
|
||||||
//! [compile-pass] check that `#[cfg]` attributes are respected
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0, QEI0])]
|
|
||||||
mod app {
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
foo: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut BAR: u32 = 0;
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[idle]
|
|
||||||
fn idle(_: idle::Context) -> ! {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut BAR: u32 = 0;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
cortex_m::asm::nop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(resources = [foo])]
|
|
||||||
fn foo(_: foo::Context) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut BAR: u32 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(priority = 3, resources = [foo])]
|
|
||||||
fn bar(_: bar::Context) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut BAR: u32 = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[task]
|
|
||||||
fn quux(_: quux::Context) {}
|
|
||||||
}
|
|
|
@ -9,11 +9,17 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::debug;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
rtic::pend(lm3s6965::Interrupt::UART0);
|
rtic::pend(lm3s6965::Interrupt::UART0);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
#[task(binds = UART0)]
|
||||||
|
|
|
@ -9,9 +9,15 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::debug;
|
use cortex_m_semihosting::debug;
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -1,18 +0,0 @@
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::debug;
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
//! [compile-pass] late resources don't need to be `Send` if they are owned by `idle`
|
//! [compile-pass] shared resources don't need to be `Send` if they are owned by `idle`
|
||||||
|
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
@ -16,24 +16,28 @@ mod app {
|
||||||
use super::NotSend;
|
use super::NotSend;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
#[resources]
|
#[shared]
|
||||||
struct Resources {
|
struct Shared {
|
||||||
x: NotSend,
|
x: NotSend,
|
||||||
#[init(None)]
|
|
||||||
y: Option<NotSend>,
|
y: Option<NotSend>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
(
|
(
|
||||||
init::LateResources {
|
Shared {
|
||||||
x: NotSend { _0: PhantomData },
|
x: NotSend { _0: PhantomData },
|
||||||
|
y: None,
|
||||||
},
|
},
|
||||||
|
Local {},
|
||||||
init::Monotonics(),
|
init::Monotonics(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle(resources = [x, y])]
|
#[idle(shared = [x, y])]
|
||||||
fn idle(_: idle::Context) -> ! {
|
fn idle(_: idle::Context) -> ! {
|
||||||
loop {
|
loop {
|
||||||
cortex_m::asm::nop();
|
cortex_m::asm::nop();
|
||||||
|
|
|
@ -1,81 +0,0 @@
|
||||||
//! [compile-pass] Check code generation of resources
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
#[init(0)]
|
|
||||||
o1: u32, // init
|
|
||||||
#[init(0)]
|
|
||||||
o2: u32, // idle
|
|
||||||
#[init(0)]
|
|
||||||
o3: u32, // EXTI0
|
|
||||||
#[init(0)]
|
|
||||||
o4: u32, // idle
|
|
||||||
#[init(0)]
|
|
||||||
o5: u32, // EXTI1
|
|
||||||
#[init(0)]
|
|
||||||
o6: u32, // init
|
|
||||||
#[init(0)]
|
|
||||||
s1: u32, // idle & uart0
|
|
||||||
#[init(0)]
|
|
||||||
s2: u32, // uart0 & uart1
|
|
||||||
#[init(0)]
|
|
||||||
s3: u32, // idle & uart0
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[idle(resources = [o2, &o4, s1, &s3])]
|
|
||||||
fn idle(mut c: idle::Context) -> ! {
|
|
||||||
// owned by `idle` == `&'static mut`
|
|
||||||
let _: resources::o2 = c.resources.o2;
|
|
||||||
|
|
||||||
// owned by `idle` == `&'static` if read-only
|
|
||||||
let _: &u32 = c.resources.o4;
|
|
||||||
|
|
||||||
// shared with `idle` == `Mutex`
|
|
||||||
c.resources.s1.lock(|_| {});
|
|
||||||
|
|
||||||
// `&` if read-only
|
|
||||||
let _: &u32 = c.resources.s3;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
cortex_m::asm::nop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [o3, s1, s2, &s3])]
|
|
||||||
fn uart0(c: uart0::Context) {
|
|
||||||
// owned by interrupt == `&mut`
|
|
||||||
let _: resources::o3 = c.resources.o3;
|
|
||||||
|
|
||||||
// no `Mutex` proxy when access from highest priority task
|
|
||||||
let _: resources::s1 = c.resources.s1;
|
|
||||||
|
|
||||||
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
|
||||||
let _: resources::s2 = c.resources.s2;
|
|
||||||
|
|
||||||
// `&` if read-only
|
|
||||||
let _: &u32 = c.resources.s3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = UART1, resources = [s2, &o5])]
|
|
||||||
fn uart1(c: uart1::Context) {
|
|
||||||
// owned by interrupt == `&` if read-only
|
|
||||||
let _: &u32 = c.resources.o5;
|
|
||||||
|
|
||||||
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
|
||||||
let _: resources::s2 = c.resources.s2;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
//! [compile-pass] Check `schedule` code generation
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
|
||||||
mod app {
|
|
||||||
#[init]
|
|
||||||
fn init(c: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
let _c: cortex_m::Peripherals = c.core;
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task]
|
|
||||||
fn some_task(_: some_task::Context) {}
|
|
||||||
}
|
|
|
@ -15,8 +15,14 @@ mod app {
|
||||||
#[monotonic(binds = SysTick, default = true)]
|
#[monotonic(binds = SysTick, default = true)]
|
||||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
let mut dcb = cx.core.DCB;
|
let mut dcb = cx.core.DCB;
|
||||||
let dwt = cx.core.DWT;
|
let dwt = cx.core.DWT;
|
||||||
let systick = cx.core.SYST;
|
let systick = cx.core.SYST;
|
||||||
|
@ -114,7 +120,7 @@ mod app {
|
||||||
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(Seconds(1_u32), 0, 1);
|
let handle: Result<baz::SpawnHandle, (u32, u32)> = baz::spawn_after(Seconds(1_u32), 0, 1);
|
||||||
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
|
let _: Result<(u32, u32), ()> = handle.unwrap().cancel();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics(mono))
|
(Shared {}, Local {}, init::Monotonics(mono))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -9,13 +9,19 @@ use panic_semihosting as _;
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
let _: Result<(), ()> = foo::spawn();
|
let _: Result<(), ()> = foo::spawn();
|
||||||
let _: Result<(), u32> = bar::spawn(0);
|
let _: Result<(), u32> = bar::spawn(0);
|
||||||
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
let _: Result<(), (u32, u32)> = baz::spawn(0, 1);
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[idle]
|
#[idle]
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::debug;
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
taskmain::spawn().ok();
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task]
|
|
||||||
fn taskmain(_: taskmain::Context) {
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
//! examples/task-local_minimal.rs
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
|
||||||
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
// A local (move), late resource
|
|
||||||
#[task_local]
|
|
||||||
l: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
(init::LateResources { l: 42 }, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
// l is task_local
|
|
||||||
#[idle(resources =[l])]
|
|
||||||
fn idle(cx: idle::Context) -> ! {
|
|
||||||
hprintln!("IDLE:l = {}", cx.resources.l).unwrap();
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
loop {
|
|
||||||
cortex_m::asm::nop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,87 +0,0 @@
|
||||||
//! examples/task-local.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
|
||||||
use lm3s6965::Interrupt;
|
|
||||||
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
// An early resource
|
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
|
||||||
|
|
||||||
// A local (move), early resource
|
|
||||||
#[task_local]
|
|
||||||
#[init(1)]
|
|
||||||
l1: u32,
|
|
||||||
|
|
||||||
// An exclusive, early resource
|
|
||||||
#[lock_free]
|
|
||||||
#[init(1)]
|
|
||||||
e1: u32,
|
|
||||||
|
|
||||||
// A local (move), late resource
|
|
||||||
#[task_local]
|
|
||||||
l2: u32,
|
|
||||||
|
|
||||||
// An exclusive, late resource
|
|
||||||
#[lock_free]
|
|
||||||
e2: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
rtic::pend(Interrupt::UART0);
|
|
||||||
rtic::pend(Interrupt::UART1);
|
|
||||||
(init::LateResources { e2: 2, l2: 2 }, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
// `shared` cannot be accessed from this context
|
|
||||||
// l1 ok (task_local)
|
|
||||||
// e2 ok (lock_free)
|
|
||||||
#[idle(resources =[l1, e2])]
|
|
||||||
fn idle(cx: idle::Context) -> ! {
|
|
||||||
hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap();
|
|
||||||
hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap();
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
loop {
|
|
||||||
cortex_m::asm::nop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
|
||||||
// l2 ok (task_local)
|
|
||||||
// e1 ok (lock_free)
|
|
||||||
#[task(priority = 1, binds = UART0, resources = [shared, l2, e1])]
|
|
||||||
fn uart0(mut cx: uart0::Context) {
|
|
||||||
let shared = cx.resources.shared.lock(|shared| {
|
|
||||||
*shared += 1;
|
|
||||||
*shared
|
|
||||||
});
|
|
||||||
*cx.resources.e1 += 10;
|
|
||||||
hprintln!("UART0: shared = {}", shared).unwrap();
|
|
||||||
hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap();
|
|
||||||
hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
|
||||||
// e1 ok (lock_free)
|
|
||||||
#[task(priority = 1, binds = UART1, resources = [shared, e1])]
|
|
||||||
fn uart1(mut cx: uart1::Context) {
|
|
||||||
let shared = cx.resources.shared.lock(|shared| {
|
|
||||||
*shared += 1;
|
|
||||||
*shared
|
|
||||||
});
|
|
||||||
|
|
||||||
hprintln!("UART1: shared = {}", shared).unwrap();
|
|
||||||
hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,11 +11,17 @@ use panic_semihosting as _;
|
||||||
mod app {
|
mod app {
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
use cortex_m_semihosting::{debug, hprintln};
|
||||||
|
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
foo::spawn().unwrap();
|
foo::spawn().unwrap();
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
//! examples/task_named_main.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
main::spawn().unwrap();
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task]
|
|
||||||
fn main(_: main::Context) {
|
|
||||||
hprintln!("This task is named main, useful for rust-analyzer").unwrap();
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,15 +0,0 @@
|
||||||
//! examples/type-usage.rs
|
|
||||||
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _; // panic handler
|
|
||||||
use rtic::app;
|
|
||||||
|
|
||||||
#[app(device = lm3s6965, dispatchers = [SSI0])]
|
|
||||||
mod app {
|
|
||||||
type Test = u32;
|
|
||||||
|
|
||||||
#[task]
|
|
||||||
fn t1(_: t1::Context, _val: Test) {}
|
|
||||||
}
|
|
|
@ -1,57 +0,0 @@
|
||||||
//! examples/types.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, peripherals = true, dispatchers = [SSI0])]
|
|
||||||
mod app {
|
|
||||||
use cortex_m_semihosting::debug;
|
|
||||||
use dwt_systick_monotonic::DwtSystick;
|
|
||||||
|
|
||||||
#[monotonic(binds = SysTick, default = true)]
|
|
||||||
type MyMono = DwtSystick<8_000_000>; // 8 MHz
|
|
||||||
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(cx: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
let _: cortex_m::Peripherals = cx.core;
|
|
||||||
let _: lm3s6965::Peripherals = cx.device;
|
|
||||||
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
|
|
||||||
let mut dcb = cx.core.DCB;
|
|
||||||
let dwt = cx.core.DWT;
|
|
||||||
let systick = cx.core.SYST;
|
|
||||||
|
|
||||||
let mono = DwtSystick::new(&mut dcb, dwt, systick, 8_000_000);
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics(mono))
|
|
||||||
}
|
|
||||||
|
|
||||||
#[idle]
|
|
||||||
fn idle(_: idle::Context) -> ! {
|
|
||||||
loop {
|
|
||||||
cortex_m::asm::nop();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [shared])]
|
|
||||||
fn uart0(cx: uart0::Context) {
|
|
||||||
let _: resources::shared = cx.resources.shared;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(priority = 2, resources = [shared])]
|
|
||||||
fn foo(cx: foo::Context) {
|
|
||||||
let _: resources::shared = cx.resources.shared;
|
|
||||||
let _: foo::Resources = cx.resources;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
|
||||||
name = "cortex-m-rtic-macros"
|
name = "cortex-m-rtic-macros"
|
||||||
readme = "../README.md"
|
readme = "../README.md"
|
||||||
repository = "https://github.com/rtic-rs/cortex-m-rtic"
|
repository = "https://github.com/rtic-rs/cortex-m-rtic"
|
||||||
version = "0.6.0-alpha.4"
|
version = "0.6.0-alpha.5"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
@ -22,4 +22,4 @@ proc-macro2 = "1"
|
||||||
proc-macro-error = "1"
|
proc-macro-error = "1"
|
||||||
quote = "1"
|
quote = "1"
|
||||||
syn = "1"
|
syn = "1"
|
||||||
rtic-syntax = "0.5.0-alpha.3"
|
rtic-syntax = "0.5.0-alpha.4"
|
||||||
|
|
|
@ -9,17 +9,17 @@ mod dispatchers;
|
||||||
mod hardware_tasks;
|
mod hardware_tasks;
|
||||||
mod idle;
|
mod idle;
|
||||||
mod init;
|
mod init;
|
||||||
mod locals;
|
mod local_resources;
|
||||||
|
mod local_resources_struct;
|
||||||
mod module;
|
mod module;
|
||||||
mod post_init;
|
mod post_init;
|
||||||
mod pre_init;
|
mod pre_init;
|
||||||
mod resources;
|
mod shared_resources;
|
||||||
mod resources_struct;
|
mod shared_resources_struct;
|
||||||
mod software_tasks;
|
mod software_tasks;
|
||||||
mod timer_queue;
|
mod timer_queue;
|
||||||
mod util;
|
mod util;
|
||||||
|
|
||||||
// TODO document the syntax here or in `rtic-syntax`
|
|
||||||
pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
||||||
let mut mod_app = vec![];
|
let mut mod_app = vec![];
|
||||||
let mut mains = vec![];
|
let mut mains = vec![];
|
||||||
|
@ -52,7 +52,7 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
||||||
mod_app.push(quote!(
|
mod_app.push(quote!(
|
||||||
#mod_app_init
|
#mod_app_init
|
||||||
|
|
||||||
#mod_app_idle
|
#(#mod_app_idle)*
|
||||||
));
|
));
|
||||||
|
|
||||||
let main = util::suffixed("main");
|
let main = util::suffixed("main");
|
||||||
|
@ -83,7 +83,10 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
let (mod_app_resources, mod_resources) = resources::codegen(app, analysis, extra);
|
let (mod_app_shared_resources, mod_shared_resources) =
|
||||||
|
shared_resources::codegen(app, analysis, extra);
|
||||||
|
let (mod_app_local_resources, mod_local_resources) =
|
||||||
|
local_resources::codegen(app, analysis, extra);
|
||||||
|
|
||||||
let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
|
let (mod_app_hardware_tasks, root_hardware_tasks, user_hardware_tasks) =
|
||||||
hardware_tasks::codegen(app, analysis, extra);
|
hardware_tasks::codegen(app, analysis, extra);
|
||||||
|
@ -185,7 +188,9 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
||||||
|
|
||||||
#(#root)*
|
#(#root)*
|
||||||
|
|
||||||
#mod_resources
|
#mod_shared_resources
|
||||||
|
|
||||||
|
#mod_local_resources
|
||||||
|
|
||||||
#(#root_hardware_tasks)*
|
#(#root_hardware_tasks)*
|
||||||
|
|
||||||
|
@ -194,7 +199,9 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
|
||||||
/// app module
|
/// app module
|
||||||
#(#mod_app)*
|
#(#mod_app)*
|
||||||
|
|
||||||
#(#mod_app_resources)*
|
#(#mod_app_shared_resources)*
|
||||||
|
|
||||||
|
#(#mod_app_local_resources)*
|
||||||
|
|
||||||
#(#mod_app_hardware_tasks)*
|
#(#mod_app_hardware_tasks)*
|
||||||
|
|
||||||
|
|
|
@ -76,12 +76,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
|
||||||
let inputs = util::mark_internal_ident(&inputs);
|
let inputs = util::mark_internal_ident(&inputs);
|
||||||
let (_, tupled, pats, _) = util::regroup_inputs(&task.inputs);
|
let (_, tupled, pats, _) = util::regroup_inputs(&task.inputs);
|
||||||
|
|
||||||
let locals_new = if task.locals.is_empty() {
|
|
||||||
quote!()
|
|
||||||
} else {
|
|
||||||
quote!(#name::Locals::new(),)
|
|
||||||
};
|
|
||||||
|
|
||||||
quote!(
|
quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#t::#name => {
|
#t::#name => {
|
||||||
|
@ -94,7 +88,6 @@ pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStrea
|
||||||
#fq.get_mut_unchecked().split().0.enqueue_unchecked(index);
|
#fq.get_mut_unchecked().split().0.enqueue_unchecked(index);
|
||||||
let priority = &rtic::export::Priority::new(PRIORITY);
|
let priority = &rtic::export::Priority::new(PRIORITY);
|
||||||
#name(
|
#name(
|
||||||
#locals_new
|
|
||||||
#name::Context::new(priority)
|
#name::Context::new(priority)
|
||||||
#(,#pats)*
|
#(,#pats)*
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rtic_syntax::{ast::App, Context};
|
||||||
use crate::{
|
use crate::{
|
||||||
analyze::Analysis,
|
analyze::Analysis,
|
||||||
check::Extra,
|
check::Extra,
|
||||||
codegen::{locals, module, resources_struct},
|
codegen::{local_resources_struct, module, shared_resources_struct},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s)
|
/// Generate support code for hardware tasks (`#[exception]`s and `#[interrupt]`s)
|
||||||
|
@ -29,12 +29,6 @@ pub fn codegen(
|
||||||
let mut user_tasks = vec![];
|
let mut user_tasks = vec![];
|
||||||
|
|
||||||
for (name, task) in &app.hardware_tasks {
|
for (name, task) in &app.hardware_tasks {
|
||||||
let locals_new = if task.locals.is_empty() {
|
|
||||||
quote!()
|
|
||||||
} else {
|
|
||||||
quote!(#name::Locals::new(),)
|
|
||||||
};
|
|
||||||
|
|
||||||
let symbol = task.args.binds.clone();
|
let symbol = task.args.binds.clone();
|
||||||
let priority = task.args.priority;
|
let priority = task.args.priority;
|
||||||
let cfgs = &task.cfgs;
|
let cfgs = &task.cfgs;
|
||||||
|
@ -50,19 +44,35 @@ pub fn codegen(
|
||||||
|
|
||||||
rtic::export::run(PRIORITY, || {
|
rtic::export::run(PRIORITY, || {
|
||||||
#name(
|
#name(
|
||||||
#locals_new
|
|
||||||
#name::Context::new(&rtic::export::Priority::new(PRIORITY))
|
#name::Context::new(&rtic::export::Priority::new(PRIORITY))
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
let mut needs_lt = false;
|
let mut shared_needs_lt = false;
|
||||||
|
let mut local_needs_lt = false;
|
||||||
|
|
||||||
|
// `${task}Locals`
|
||||||
|
if !task.args.local_resources.is_empty() {
|
||||||
|
let (item, constructor) = local_resources_struct::codegen(
|
||||||
|
Context::HardwareTask(name),
|
||||||
|
&mut local_needs_lt,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
|
root.push(item);
|
||||||
|
|
||||||
|
mod_app.push(constructor);
|
||||||
|
}
|
||||||
|
|
||||||
// `${task}Resources`
|
// `${task}Resources`
|
||||||
if !task.args.resources.is_empty() {
|
if !task.args.shared_resources.is_empty() {
|
||||||
let (item, constructor) =
|
let (item, constructor) = shared_resources_struct::codegen(
|
||||||
resources_struct::codegen(Context::HardwareTask(name), &mut needs_lt, app);
|
Context::HardwareTask(name),
|
||||||
|
&mut shared_needs_lt,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
root.push(item);
|
root.push(item);
|
||||||
|
|
||||||
|
@ -71,30 +81,21 @@ pub fn codegen(
|
||||||
|
|
||||||
root.push(module::codegen(
|
root.push(module::codegen(
|
||||||
Context::HardwareTask(name),
|
Context::HardwareTask(name),
|
||||||
needs_lt,
|
shared_needs_lt,
|
||||||
|
local_needs_lt,
|
||||||
app,
|
app,
|
||||||
analysis,
|
analysis,
|
||||||
extra,
|
extra,
|
||||||
));
|
));
|
||||||
|
|
||||||
// `${task}Locals`
|
if !task.is_extern {
|
||||||
let mut locals_pat = None;
|
|
||||||
if !task.locals.is_empty() {
|
|
||||||
let (struct_, pat) = locals::codegen(Context::HardwareTask(name), &task.locals, app);
|
|
||||||
|
|
||||||
root.push(struct_);
|
|
||||||
locals_pat = Some(pat);
|
|
||||||
}
|
|
||||||
|
|
||||||
if !&task.is_extern {
|
|
||||||
let attrs = &task.attrs;
|
let attrs = &task.attrs;
|
||||||
let context = &task.context;
|
let context = &task.context;
|
||||||
let stmts = &task.stmts;
|
let stmts = &task.stmts;
|
||||||
let locals_pat = locals_pat.iter();
|
|
||||||
user_tasks.push(quote!(
|
user_tasks.push(quote!(
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn #name(#(#locals_pat,)* #context: #name::Context) {
|
fn #name(#context: #name::Context) {
|
||||||
use rtic::Mutex as _;
|
use rtic::Mutex as _;
|
||||||
use rtic::mutex_prelude::*;
|
use rtic::mutex_prelude::*;
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rtic_syntax::{ast::App, Context};
|
||||||
use crate::{
|
use crate::{
|
||||||
analyze::Analysis,
|
analyze::Analysis,
|
||||||
check::Extra,
|
check::Extra,
|
||||||
codegen::{locals, module, resources_struct},
|
codegen::{local_resources_struct, module, shared_resources_struct},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Generates support code for `#[idle]` functions
|
/// Generates support code for `#[idle]` functions
|
||||||
|
@ -15,7 +15,7 @@ pub fn codegen(
|
||||||
extra: &Extra,
|
extra: &Extra,
|
||||||
) -> (
|
) -> (
|
||||||
// mod_app_idle -- the `${idle}Resources` constructor
|
// mod_app_idle -- the `${idle}Resources` constructor
|
||||||
Option<TokenStream2>,
|
Vec<TokenStream2>,
|
||||||
// root_idle -- items that must be placed in the root of the crate:
|
// root_idle -- items that must be placed in the root of the crate:
|
||||||
// - the `${idle}Locals` struct
|
// - the `${idle}Locals` struct
|
||||||
// - the `${idle}Resources` struct
|
// - the `${idle}Resources` struct
|
||||||
|
@ -26,34 +26,35 @@ pub fn codegen(
|
||||||
// call_idle
|
// call_idle
|
||||||
TokenStream2,
|
TokenStream2,
|
||||||
) {
|
) {
|
||||||
if !app.idles.is_empty() {
|
if let Some(idle) = &app.idle {
|
||||||
let idle = &app.idles.first().unwrap();
|
let mut shared_needs_lt = false;
|
||||||
let mut needs_lt = false;
|
let mut local_needs_lt = false;
|
||||||
let mut mod_app = None;
|
let mut mod_app = vec![];
|
||||||
let mut root_idle = vec![];
|
let mut root_idle = vec![];
|
||||||
let mut locals_pat = None;
|
|
||||||
let mut locals_new = None;
|
|
||||||
|
|
||||||
let name = &idle.name;
|
let name = &idle.name;
|
||||||
|
|
||||||
if !idle.args.resources.is_empty() {
|
if !idle.args.shared_resources.is_empty() {
|
||||||
let (item, constructor) = resources_struct::codegen(Context::Idle, &mut needs_lt, app);
|
let (item, constructor) =
|
||||||
|
shared_resources_struct::codegen(Context::Idle, &mut shared_needs_lt, app);
|
||||||
|
|
||||||
root_idle.push(item);
|
root_idle.push(item);
|
||||||
mod_app = Some(constructor);
|
mod_app.push(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !idle.locals.is_empty() {
|
if !idle.args.local_resources.is_empty() {
|
||||||
let (locals, pat) = locals::codegen(Context::Idle, &idle.locals, app);
|
let (item, constructor) =
|
||||||
|
local_resources_struct::codegen(Context::Idle, &mut local_needs_lt, app);
|
||||||
|
|
||||||
locals_new = Some(quote!(#name::Locals::new()));
|
root_idle.push(item);
|
||||||
locals_pat = Some(pat);
|
|
||||||
root_idle.push(locals);
|
mod_app.push(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
root_idle.push(module::codegen(
|
root_idle.push(module::codegen(
|
||||||
Context::Idle,
|
Context::Idle,
|
||||||
needs_lt,
|
shared_needs_lt,
|
||||||
|
local_needs_lt,
|
||||||
app,
|
app,
|
||||||
analysis,
|
analysis,
|
||||||
extra,
|
extra,
|
||||||
|
@ -62,11 +63,10 @@ pub fn codegen(
|
||||||
let attrs = &idle.attrs;
|
let attrs = &idle.attrs;
|
||||||
let context = &idle.context;
|
let context = &idle.context;
|
||||||
let stmts = &idle.stmts;
|
let stmts = &idle.stmts;
|
||||||
let locals_pat = locals_pat.iter();
|
|
||||||
let user_idle = Some(quote!(
|
let user_idle = Some(quote!(
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn #name(#(#locals_pat,)* #context: #name::Context) -> ! {
|
fn #name(#context: #name::Context) -> ! {
|
||||||
use rtic::Mutex as _;
|
use rtic::Mutex as _;
|
||||||
use rtic::mutex_prelude::*;
|
use rtic::mutex_prelude::*;
|
||||||
|
|
||||||
|
@ -74,16 +74,14 @@ pub fn codegen(
|
||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
let locals_new = locals_new.iter();
|
|
||||||
let call_idle = quote!(#name(
|
let call_idle = quote!(#name(
|
||||||
#(#locals_new,)*
|
|
||||||
#name::Context::new(&rtic::export::Priority::new(0))
|
#name::Context::new(&rtic::export::Priority::new(0))
|
||||||
));
|
));
|
||||||
|
|
||||||
(mod_app, root_idle, user_idle, call_idle)
|
(mod_app, root_idle, user_idle, call_idle)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
None,
|
vec![],
|
||||||
vec![],
|
vec![],
|
||||||
None,
|
None,
|
||||||
quote!(loop {
|
quote!(loop {
|
||||||
|
|
|
@ -5,7 +5,7 @@ use rtic_syntax::{ast::App, Context};
|
||||||
use crate::{
|
use crate::{
|
||||||
analyze::Analysis,
|
analyze::Analysis,
|
||||||
check::Extra,
|
check::Extra,
|
||||||
codegen::{locals, module, resources_struct},
|
codegen::{local_resources_struct, module},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CodegenResult = (
|
type CodegenResult = (
|
||||||
|
@ -18,68 +18,96 @@ type CodegenResult = (
|
||||||
// - the `${init}` module, which contains types like `${init}::Context`
|
// - the `${init}` module, which contains types like `${init}::Context`
|
||||||
Vec<TokenStream2>,
|
Vec<TokenStream2>,
|
||||||
// user_init -- the `#[init]` function written by the user
|
// user_init -- the `#[init]` function written by the user
|
||||||
Option<TokenStream2>,
|
TokenStream2,
|
||||||
// call_init -- the call to the user `#[init]` if there's one
|
// call_init -- the call to the user `#[init]`
|
||||||
Option<TokenStream2>,
|
TokenStream2,
|
||||||
);
|
);
|
||||||
|
|
||||||
/// Generates support code for `#[init]` functions
|
/// Generates support code for `#[init]` functions
|
||||||
pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
|
pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
|
||||||
if !app.inits.is_empty() {
|
let init = &app.init;
|
||||||
let init = &app.inits.first().unwrap();
|
let mut local_needs_lt = false;
|
||||||
let mut needs_lt = false;
|
let name = &init.name;
|
||||||
let name = &init.name;
|
|
||||||
|
|
||||||
let mut root_init = vec![];
|
let mut root_init = vec![];
|
||||||
|
|
||||||
let mut locals_pat = None;
|
let context = &init.context;
|
||||||
let mut locals_new = None;
|
let attrs = &init.attrs;
|
||||||
if !init.locals.is_empty() {
|
let stmts = &init.stmts;
|
||||||
let (struct_, pat) = locals::codegen(Context::Init, &init.locals, app);
|
let shared = &init.user_shared_struct;
|
||||||
|
let local = &init.user_local_struct;
|
||||||
|
|
||||||
locals_new = Some(quote!(#name::Locals::new()));
|
let shared_resources: Vec<_> = app
|
||||||
locals_pat = Some(pat);
|
.shared_resources
|
||||||
root_init.push(struct_);
|
.iter()
|
||||||
|
.map(|(k, v)| {
|
||||||
|
let ty = &v.ty;
|
||||||
|
let cfgs = &v.cfgs;
|
||||||
|
quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
#k: #ty,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
let local_resources: Vec<_> = app
|
||||||
|
.local_resources
|
||||||
|
.iter()
|
||||||
|
.map(|(k, v)| {
|
||||||
|
let ty = &v.ty;
|
||||||
|
let cfgs = &v.cfgs;
|
||||||
|
quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
#k: #ty,
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
root_init.push(quote! {
|
||||||
|
struct #shared {
|
||||||
|
#(#shared_resources)*
|
||||||
}
|
}
|
||||||
|
|
||||||
let context = &init.context;
|
struct #local {
|
||||||
let attrs = &init.attrs;
|
#(#local_resources)*
|
||||||
let stmts = &init.stmts;
|
|
||||||
let locals_pat = locals_pat.iter();
|
|
||||||
|
|
||||||
let user_init_return = quote! {#name::LateResources, #name::Monotonics};
|
|
||||||
|
|
||||||
let user_init = Some(quote!(
|
|
||||||
#(#attrs)*
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
fn #name(#(#locals_pat,)* #context: #name::Context) -> (#user_init_return) {
|
|
||||||
#(#stmts)*
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
let mut mod_app = None;
|
|
||||||
if !init.args.resources.is_empty() {
|
|
||||||
let (item, constructor) = resources_struct::codegen(Context::Init, &mut needs_lt, app);
|
|
||||||
|
|
||||||
root_init.push(item);
|
|
||||||
mod_app = Some(constructor);
|
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
let locals_new = locals_new.iter();
|
// let locals_pat = locals_pat.iter();
|
||||||
let call_init = Some(
|
|
||||||
quote!(let (late, mut monotonics) = #name(#(#locals_new,)* #name::Context::new(core.into()));),
|
|
||||||
);
|
|
||||||
|
|
||||||
root_init.push(module::codegen(
|
let user_init_return = quote! {#shared, #local, #name::Monotonics};
|
||||||
Context::Init,
|
|
||||||
needs_lt,
|
|
||||||
app,
|
|
||||||
analysis,
|
|
||||||
extra,
|
|
||||||
));
|
|
||||||
|
|
||||||
(mod_app, root_init, user_init, call_init)
|
let user_init = quote!(
|
||||||
} else {
|
#(#attrs)*
|
||||||
(None, vec![], None, None)
|
#[allow(non_snake_case)]
|
||||||
|
fn #name(#context: #name::Context) -> (#user_init_return) {
|
||||||
|
#(#stmts)*
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut mod_app = None;
|
||||||
|
|
||||||
|
// `${task}Locals`
|
||||||
|
if !init.args.local_resources.is_empty() {
|
||||||
|
let (item, constructor) =
|
||||||
|
local_resources_struct::codegen(Context::Init, &mut local_needs_lt, app);
|
||||||
|
|
||||||
|
root_init.push(item);
|
||||||
|
|
||||||
|
mod_app = Some(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// let locals_new = locals_new.iter();
|
||||||
|
let call_init = quote! {
|
||||||
|
let (shared_resources, local_resources, mut monotonics) = #name(#name::Context::new(core.into()));
|
||||||
|
};
|
||||||
|
|
||||||
|
root_init.push(module::codegen(
|
||||||
|
Context::Init,
|
||||||
|
false,
|
||||||
|
local_needs_lt,
|
||||||
|
app,
|
||||||
|
analysis,
|
||||||
|
extra,
|
||||||
|
));
|
||||||
|
|
||||||
|
(mod_app, root_init, user_init, call_init)
|
||||||
}
|
}
|
||||||
|
|
71
macros/src/codegen/local_resources.rs
Normal file
71
macros/src/codegen/local_resources.rs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
use quote::quote;
|
||||||
|
use rtic_syntax::ast::App;
|
||||||
|
|
||||||
|
use crate::{analyze::Analysis, check::Extra, codegen::util};
|
||||||
|
|
||||||
|
/// Generates `local` variables and local resource proxies
|
||||||
|
///
|
||||||
|
/// I.e. the `static` variables and theirs proxies.
|
||||||
|
pub fn codegen(
|
||||||
|
app: &App,
|
||||||
|
_analysis: &Analysis,
|
||||||
|
_extra: &Extra,
|
||||||
|
) -> (
|
||||||
|
// mod_app -- the `static` variables behind the proxies
|
||||||
|
Vec<TokenStream2>,
|
||||||
|
// mod_resources -- the `resources` module
|
||||||
|
TokenStream2,
|
||||||
|
) {
|
||||||
|
let mut mod_app = vec![];
|
||||||
|
// let mut mod_resources: _ = vec![];
|
||||||
|
|
||||||
|
// All local resources declared in the `#[local]' struct
|
||||||
|
for (name, res) in &app.local_resources {
|
||||||
|
let cfgs = &res.cfgs;
|
||||||
|
let ty = &res.ty;
|
||||||
|
let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name));
|
||||||
|
|
||||||
|
let attrs = &res.attrs;
|
||||||
|
// late resources in `util::link_section_uninit`
|
||||||
|
let section = util::link_section_uninit();
|
||||||
|
|
||||||
|
// For future use
|
||||||
|
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
||||||
|
mod_app.push(quote!(
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
// #[doc = #doc]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#(#attrs)*
|
||||||
|
#(#cfgs)*
|
||||||
|
#section
|
||||||
|
static #mangled_name: rtic::RacyCell<core::mem::MaybeUninit<#ty>> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit());
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
// All declared `local = [NAME: TY = EXPR]` local resources
|
||||||
|
for (task_name, resource_name, task_local) in app.declared_local_resources() {
|
||||||
|
let cfgs = &task_local.cfgs;
|
||||||
|
let ty = &task_local.ty;
|
||||||
|
let expr = &task_local.expr;
|
||||||
|
let attrs = &task_local.attrs;
|
||||||
|
|
||||||
|
let mangled_name = util::mark_internal_ident(&util::declared_static_local_resource_ident(
|
||||||
|
resource_name,
|
||||||
|
&task_name,
|
||||||
|
));
|
||||||
|
|
||||||
|
// For future use
|
||||||
|
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
||||||
|
mod_app.push(quote!(
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
// #[doc = #doc]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#(#attrs)*
|
||||||
|
#(#cfgs)*
|
||||||
|
static #mangled_name: rtic::RacyCell<#ty> = rtic::RacyCell::new(#expr);
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
(mod_app, TokenStream2::new())
|
||||||
|
}
|
110
macros/src/codegen/local_resources_struct.rs
Normal file
110
macros/src/codegen/local_resources_struct.rs
Normal file
|
@ -0,0 +1,110 @@
|
||||||
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
use quote::quote;
|
||||||
|
use rtic_syntax::{
|
||||||
|
ast::{App, TaskLocal},
|
||||||
|
Context,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::codegen::util;
|
||||||
|
|
||||||
|
/// Generates local resources structs
|
||||||
|
pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
|
let mut lt = None;
|
||||||
|
|
||||||
|
let resources = match ctxt {
|
||||||
|
Context::Init => &app.init.args.local_resources,
|
||||||
|
Context::Idle => &app.idle.as_ref().unwrap().args.local_resources,
|
||||||
|
Context::HardwareTask(name) => &app.hardware_tasks[name].args.local_resources,
|
||||||
|
Context::SoftwareTask(name) => &app.software_tasks[name].args.local_resources,
|
||||||
|
};
|
||||||
|
|
||||||
|
let task_name = util::get_task_name(ctxt, app);
|
||||||
|
|
||||||
|
let mut fields = vec![];
|
||||||
|
let mut values = vec![];
|
||||||
|
let mut has_cfgs = false;
|
||||||
|
|
||||||
|
for (name, task_local) in resources {
|
||||||
|
let (cfgs, ty, is_declared) = match task_local {
|
||||||
|
TaskLocal::External => {
|
||||||
|
let r = app.local_resources.get(name).expect("UNREACHABLE");
|
||||||
|
(&r.cfgs, &r.ty, false)
|
||||||
|
}
|
||||||
|
TaskLocal::Declared(r) => (&r.cfgs, &r.ty, true),
|
||||||
|
_ => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
has_cfgs |= !cfgs.is_empty();
|
||||||
|
|
||||||
|
let lt = if ctxt.runs_once() {
|
||||||
|
quote!('static)
|
||||||
|
} else {
|
||||||
|
lt = Some(quote!('a));
|
||||||
|
quote!('a)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mangled_name = if matches!(task_local, TaskLocal::External) {
|
||||||
|
util::mark_internal_ident(&util::static_local_resource_ident(name))
|
||||||
|
} else {
|
||||||
|
util::mark_internal_ident(&util::declared_static_local_resource_ident(
|
||||||
|
name, &task_name,
|
||||||
|
))
|
||||||
|
};
|
||||||
|
|
||||||
|
fields.push(quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
pub #name: &#lt mut #ty
|
||||||
|
));
|
||||||
|
|
||||||
|
let expr = if is_declared {
|
||||||
|
// If the local resources is already initialized, we only need to access its value and
|
||||||
|
// not go through an `MaybeUninit`
|
||||||
|
quote!(#mangled_name.get_mut_unchecked())
|
||||||
|
} else {
|
||||||
|
quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr())
|
||||||
|
};
|
||||||
|
|
||||||
|
values.push(quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
#name: #expr
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
if lt.is_some() {
|
||||||
|
*needs_lt = true;
|
||||||
|
|
||||||
|
// The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused
|
||||||
|
if has_cfgs {
|
||||||
|
fields.push(quote!(
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub __marker__: core::marker::PhantomData<&'a ()>
|
||||||
|
));
|
||||||
|
|
||||||
|
values.push(quote!(__marker__: core::marker::PhantomData))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let doc = format!("Local resources `{}` has access to", ctxt.ident(app));
|
||||||
|
let ident = util::local_resources_ident(ctxt, app);
|
||||||
|
let ident = util::mark_internal_ident(&ident);
|
||||||
|
let item = quote!(
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
#[doc = #doc]
|
||||||
|
pub struct #ident<#lt> {
|
||||||
|
#(#fields,)*
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
let constructor = quote!(
|
||||||
|
impl<#lt> #ident<#lt> {
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn new() -> Self {
|
||||||
|
#ident {
|
||||||
|
#(#values,)*
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
(item, constructor)
|
||||||
|
}
|
|
@ -1,95 +0,0 @@
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
|
||||||
use quote::quote;
|
|
||||||
use rtic_syntax::{
|
|
||||||
ast::{App, Local},
|
|
||||||
Context, Map,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::codegen::util;
|
|
||||||
|
|
||||||
pub fn codegen(
|
|
||||||
ctxt: Context,
|
|
||||||
locals: &Map<Local>,
|
|
||||||
app: &App,
|
|
||||||
) -> (
|
|
||||||
// locals
|
|
||||||
TokenStream2,
|
|
||||||
// pat
|
|
||||||
TokenStream2,
|
|
||||||
) {
|
|
||||||
assert!(!locals.is_empty());
|
|
||||||
|
|
||||||
let runs_once = ctxt.runs_once();
|
|
||||||
let ident = util::locals_ident(ctxt, app);
|
|
||||||
|
|
||||||
let mut lt = None;
|
|
||||||
let mut fields = vec![];
|
|
||||||
let mut items = vec![];
|
|
||||||
let mut names = vec![];
|
|
||||||
let mut values = vec![];
|
|
||||||
let mut pats = vec![];
|
|
||||||
let mut has_cfgs = false;
|
|
||||||
|
|
||||||
for (name, local) in locals {
|
|
||||||
let lt = if runs_once {
|
|
||||||
quote!('static)
|
|
||||||
} else {
|
|
||||||
lt = Some(quote!('a));
|
|
||||||
quote!('a)
|
|
||||||
};
|
|
||||||
|
|
||||||
let cfgs = &local.cfgs;
|
|
||||||
has_cfgs |= !cfgs.is_empty();
|
|
||||||
|
|
||||||
let expr = &local.expr;
|
|
||||||
let ty = &local.ty;
|
|
||||||
fields.push(quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#name: &#lt mut #ty
|
|
||||||
));
|
|
||||||
items.push(quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#[doc(hidden)]
|
|
||||||
static #name: rtic::RacyCell<#ty> = rtic::RacyCell::new(#expr)
|
|
||||||
));
|
|
||||||
values.push(quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#name: #name.get_mut_unchecked()
|
|
||||||
));
|
|
||||||
names.push(name);
|
|
||||||
pats.push(quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#name
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
if lt.is_some() && has_cfgs {
|
|
||||||
fields.push(quote!(__marker__: core::marker::PhantomData<&'a ()>));
|
|
||||||
values.push(quote!(__marker__: core::marker::PhantomData));
|
|
||||||
}
|
|
||||||
|
|
||||||
let locals = quote!(
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
#[doc(hidden)]
|
|
||||||
pub struct #ident<#lt> {
|
|
||||||
#(#fields),*
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<#lt> #ident<#lt> {
|
|
||||||
#[inline(always)]
|
|
||||||
unsafe fn new() -> Self {
|
|
||||||
#(#items;)*
|
|
||||||
|
|
||||||
#ident {
|
|
||||||
#(#values),*
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let ident = ctxt.ident(app);
|
|
||||||
(
|
|
||||||
locals,
|
|
||||||
quote!(#ident::Locals { #(#pats,)* .. }: #ident::Locals),
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -5,7 +5,8 @@ use rtic_syntax::{ast::App, Context};
|
||||||
|
|
||||||
pub fn codegen(
|
pub fn codegen(
|
||||||
ctxt: Context,
|
ctxt: Context,
|
||||||
resources_tick: bool,
|
shared_resources_tick: bool,
|
||||||
|
local_resources_tick: bool,
|
||||||
app: &App,
|
app: &App,
|
||||||
analysis: &Analysis,
|
analysis: &Analysis,
|
||||||
extra: &Extra,
|
extra: &Extra,
|
||||||
|
@ -56,18 +57,18 @@ pub fn codegen(
|
||||||
Context::SoftwareTask(_) => {}
|
Context::SoftwareTask(_) => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctxt.has_locals(app) {
|
// if ctxt.has_locals(app) {
|
||||||
let ident = util::locals_ident(ctxt, app);
|
// let ident = util::locals_ident(ctxt, app);
|
||||||
module_items.push(quote!(
|
// module_items.push(quote!(
|
||||||
#[doc(inline)]
|
// #[doc(inline)]
|
||||||
pub use super::#ident as Locals;
|
// pub use super::#ident as Locals;
|
||||||
));
|
// ));
|
||||||
}
|
// }
|
||||||
|
|
||||||
if ctxt.has_resources(app) {
|
if ctxt.has_local_resources(app) {
|
||||||
let ident = util::resources_ident(ctxt, app);
|
let ident = util::local_resources_ident(ctxt, app);
|
||||||
let ident = util::mark_internal_ident(&ident);
|
let ident = util::mark_internal_ident(&ident);
|
||||||
let lt = if resources_tick {
|
let lt = if local_resources_tick {
|
||||||
lt = Some(quote!('a));
|
lt = Some(quote!('a));
|
||||||
Some(quote!('a))
|
Some(quote!('a))
|
||||||
} else {
|
} else {
|
||||||
|
@ -76,12 +77,35 @@ pub fn codegen(
|
||||||
|
|
||||||
module_items.push(quote!(
|
module_items.push(quote!(
|
||||||
#[doc(inline)]
|
#[doc(inline)]
|
||||||
pub use super::#ident as Resources;
|
pub use super::#ident as LocalResources;
|
||||||
));
|
));
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
/// Resources this task has access to
|
/// Local Resources this task has access to
|
||||||
pub resources: #name::Resources<#lt>
|
pub local: #name::LocalResources<#lt>
|
||||||
|
));
|
||||||
|
|
||||||
|
values.push(quote!(local: #name::LocalResources::new()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if ctxt.has_shared_resources(app) {
|
||||||
|
let ident = util::shared_resources_ident(ctxt, app);
|
||||||
|
let ident = util::mark_internal_ident(&ident);
|
||||||
|
let lt = if shared_resources_tick {
|
||||||
|
lt = Some(quote!('a));
|
||||||
|
Some(quote!('a))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
module_items.push(quote!(
|
||||||
|
#[doc(inline)]
|
||||||
|
pub use super::#ident as SharedResources;
|
||||||
|
));
|
||||||
|
|
||||||
|
fields.push(quote!(
|
||||||
|
/// Shared Resources this task has access to
|
||||||
|
pub shared: #name::SharedResources<#lt>
|
||||||
));
|
));
|
||||||
|
|
||||||
let priority = if ctxt.is_init() {
|
let priority = if ctxt.is_init() {
|
||||||
|
@ -89,38 +113,10 @@ pub fn codegen(
|
||||||
} else {
|
} else {
|
||||||
Some(quote!(priority))
|
Some(quote!(priority))
|
||||||
};
|
};
|
||||||
values.push(quote!(resources: #name::Resources::new(#priority)));
|
values.push(quote!(shared: #name::SharedResources::new(#priority)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Context::Init = ctxt {
|
if let Context::Init = ctxt {
|
||||||
let late_fields = analysis
|
|
||||||
.late_resources
|
|
||||||
.iter()
|
|
||||||
.flat_map(|resources| {
|
|
||||||
resources.iter().map(|name| {
|
|
||||||
let ty = &app.late_resources[name].ty;
|
|
||||||
let cfgs = &app.late_resources[name].cfgs;
|
|
||||||
|
|
||||||
quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
pub #name: #ty
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let internal_late_ident = util::mark_internal_name("LateResources");
|
|
||||||
items.push(quote!(
|
|
||||||
/// Resources initialized at runtime
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub struct #internal_late_ident {
|
|
||||||
#(#late_fields),*
|
|
||||||
}
|
|
||||||
));
|
|
||||||
module_items.push(quote!(
|
|
||||||
pub use super::#internal_late_ident as LateResources;
|
|
||||||
));
|
|
||||||
|
|
||||||
let monotonic_types: Vec<_> = app
|
let monotonic_types: Vec<_> = app
|
||||||
.monotonics
|
.monotonics
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -202,9 +198,6 @@ pub fn codegen(
|
||||||
pub use super::#internal_context_name as Context;
|
pub use super::#internal_context_name as Context;
|
||||||
));
|
));
|
||||||
|
|
||||||
// not sure if this is the right way, maybe its backwards,
|
|
||||||
// that spawn_module should put in in root
|
|
||||||
|
|
||||||
if let Context::SoftwareTask(..) = ctxt {
|
if let Context::SoftwareTask(..) = ctxt {
|
||||||
let spawnee = &app.software_tasks[name];
|
let spawnee = &app.software_tasks[name];
|
||||||
let priority = spawnee.args.priority;
|
let priority = spawnee.args.priority;
|
||||||
|
|
|
@ -9,24 +9,39 @@ use crate::{analyze::Analysis, codegen::util};
|
||||||
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
|
||||||
let mut stmts = vec![];
|
let mut stmts = vec![];
|
||||||
|
|
||||||
// Initialize late resources
|
// Initialize shared resources
|
||||||
if !analysis.late_resources.is_empty() {
|
for (name, res) in &app.shared_resources {
|
||||||
// BTreeSet wrapped in a vector
|
let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(name));
|
||||||
for name in analysis.late_resources.first().unwrap() {
|
// If it's live
|
||||||
let mangled_name = util::mark_internal_ident(&name);
|
let cfgs = res.cfgs.clone();
|
||||||
// If it's live
|
if analysis.shared_resource_locations.get(name).is_some() {
|
||||||
let cfgs = app.late_resources[name].cfgs.clone();
|
stmts.push(quote!(
|
||||||
if analysis.locations.get(name).is_some() {
|
// We include the cfgs
|
||||||
stmts.push(quote!(
|
#(#cfgs)*
|
||||||
// We include the cfgs
|
// Resource is a RacyCell<MaybeUninit<T>>
|
||||||
#(#cfgs)*
|
// - `get_mut_unchecked` to obtain `MaybeUninit<T>`
|
||||||
// Late resource is a RacyCell<MaybeUninit<T>>
|
// - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
|
||||||
// - `get_mut_unchecked` to obtain `MaybeUninit<T>`
|
// - `write` the defined value for the late resource T
|
||||||
// - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
|
#mangled_name.get_mut_unchecked().as_mut_ptr().write(shared_resources.#name);
|
||||||
// - `write` the defined value for the late resource T
|
));
|
||||||
#mangled_name.get_mut_unchecked().as_mut_ptr().write(late.#name);
|
}
|
||||||
));
|
}
|
||||||
}
|
|
||||||
|
// Initialize local resources
|
||||||
|
for (name, res) in &app.local_resources {
|
||||||
|
let mangled_name = util::mark_internal_ident(&util::static_local_resource_ident(name));
|
||||||
|
// If it's live
|
||||||
|
let cfgs = res.cfgs.clone();
|
||||||
|
if analysis.local_resource_locations.get(name).is_some() {
|
||||||
|
stmts.push(quote!(
|
||||||
|
// We include the cfgs
|
||||||
|
#(#cfgs)*
|
||||||
|
// Resource is a RacyCell<MaybeUninit<T>>
|
||||||
|
// - `get_mut_unchecked` to obtain `MaybeUninit<T>`
|
||||||
|
// - `as_mut_ptr` to obtain a raw pointer to `MaybeUninit<T>`
|
||||||
|
// - `write` the defined value for the late resource T
|
||||||
|
#mangled_name.get_mut_unchecked().as_mut_ptr().write(local_resources.#name);
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there's no user `#[idle]` then optimize returning from interrupt handlers
|
// If there's no user `#[idle]` then optimize returning from interrupt handlers
|
||||||
if app.idles.is_empty() {
|
if app.idle.is_none() {
|
||||||
// Set SLEEPONEXIT bit to enter sleep mode when returning from ISR
|
// Set SLEEPONEXIT bit to enter sleep mode when returning from ISR
|
||||||
stmts.push(quote!(core.SCB.scr.modify(|r| r | 1 << 1);));
|
stmts.push(quote!(core.SCB.scr.modify(|r| r | 1 << 1);));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,152 +0,0 @@
|
||||||
use proc_macro2::TokenStream as TokenStream2;
|
|
||||||
use quote::quote;
|
|
||||||
use rtic_syntax::{analyze::Ownership, ast::App};
|
|
||||||
|
|
||||||
use crate::{analyze::Analysis, check::Extra, codegen::util};
|
|
||||||
|
|
||||||
/// Generates `static` variables and resource proxies
|
|
||||||
/// Early resources are stored in `RacyCell<T>`
|
|
||||||
/// Late resource are stored in `RacyCell<MaybeUninit<T>>`
|
|
||||||
///
|
|
||||||
/// Safety:
|
|
||||||
/// - RacyCell<T> access is `unsafe`.
|
|
||||||
/// - RacyCell<MaybeUninit> is always written to before user access, thus
|
|
||||||
// the generated code for user access can safely `assume_init`.
|
|
||||||
pub fn codegen(
|
|
||||||
app: &App,
|
|
||||||
analysis: &Analysis,
|
|
||||||
extra: &Extra,
|
|
||||||
) -> (
|
|
||||||
// mod_app -- the `static` variables behind the proxies
|
|
||||||
Vec<TokenStream2>,
|
|
||||||
// mod_resources -- the `resources` module
|
|
||||||
TokenStream2,
|
|
||||||
) {
|
|
||||||
let mut mod_app = vec![];
|
|
||||||
let mut mod_resources = vec![];
|
|
||||||
|
|
||||||
for (name, res, expr, _) in app.resources(analysis) {
|
|
||||||
let cfgs = &res.cfgs;
|
|
||||||
let ty = &res.ty;
|
|
||||||
let mangled_name = util::mark_internal_ident(&name);
|
|
||||||
|
|
||||||
{
|
|
||||||
// late resources in `util::link_section_uninit`
|
|
||||||
let section = if expr.is_none() {
|
|
||||||
util::link_section_uninit(true)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
// resource type and assigned value
|
|
||||||
let (ty, expr) = if let Some(expr) = expr {
|
|
||||||
// early resource
|
|
||||||
(
|
|
||||||
quote!(rtic::RacyCell<#ty>),
|
|
||||||
quote!(rtic::RacyCell::new(#expr)),
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// late resource
|
|
||||||
(
|
|
||||||
quote!(rtic::RacyCell<core::mem::MaybeUninit<#ty>>),
|
|
||||||
quote!(rtic::RacyCell::new(core::mem::MaybeUninit::uninit())),
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
let attrs = &res.attrs;
|
|
||||||
|
|
||||||
// For future use
|
|
||||||
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
|
||||||
mod_app.push(quote!(
|
|
||||||
#[allow(non_upper_case_globals)]
|
|
||||||
// #[doc = #doc]
|
|
||||||
#[doc(hidden)]
|
|
||||||
#(#attrs)*
|
|
||||||
#(#cfgs)*
|
|
||||||
#section
|
|
||||||
static #mangled_name: #ty = #expr;
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
let r_prop = &res.properties;
|
|
||||||
// For future use
|
|
||||||
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
|
||||||
|
|
||||||
if !r_prop.task_local && !r_prop.lock_free {
|
|
||||||
mod_resources.push(quote!(
|
|
||||||
// #[doc = #doc]
|
|
||||||
#[doc(hidden)]
|
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
#(#cfgs)*
|
|
||||||
pub struct #name<'a> {
|
|
||||||
priority: &'a Priority,
|
|
||||||
}
|
|
||||||
|
|
||||||
#(#cfgs)*
|
|
||||||
impl<'a> #name<'a> {
|
|
||||||
#[inline(always)]
|
|
||||||
pub unsafe fn new(priority: &'a Priority) -> Self {
|
|
||||||
#name { priority }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline(always)]
|
|
||||||
pub unsafe fn priority(&self) -> &Priority {
|
|
||||||
self.priority
|
|
||||||
}
|
|
||||||
}
|
|
||||||
));
|
|
||||||
|
|
||||||
let (ptr, _doc) = if expr.is_none() {
|
|
||||||
// late resource
|
|
||||||
(
|
|
||||||
quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#mangled_name.get_mut_unchecked().as_mut_ptr()
|
|
||||||
),
|
|
||||||
"late",
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// early resource
|
|
||||||
(
|
|
||||||
quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#mangled_name.get_mut_unchecked()
|
|
||||||
),
|
|
||||||
"early",
|
|
||||||
)
|
|
||||||
};
|
|
||||||
|
|
||||||
let ceiling = match analysis.ownerships.get(name) {
|
|
||||||
Some(Ownership::Owned { priority }) => *priority,
|
|
||||||
Some(Ownership::CoOwned { priority }) => *priority,
|
|
||||||
Some(Ownership::Contended { ceiling }) => *ceiling,
|
|
||||||
None => 0,
|
|
||||||
};
|
|
||||||
|
|
||||||
// For future use
|
|
||||||
// let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!());
|
|
||||||
|
|
||||||
mod_app.push(util::impl_mutex(
|
|
||||||
extra,
|
|
||||||
cfgs,
|
|
||||||
true,
|
|
||||||
name,
|
|
||||||
quote!(#ty),
|
|
||||||
ceiling,
|
|
||||||
ptr,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mod_resources = if mod_resources.is_empty() {
|
|
||||||
quote!()
|
|
||||||
} else {
|
|
||||||
quote!(mod resources {
|
|
||||||
use rtic::export::Priority;
|
|
||||||
|
|
||||||
#(#mod_resources)*
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
(mod_app, mod_resources)
|
|
||||||
}
|
|
107
macros/src/codegen/shared_resources.rs
Normal file
107
macros/src/codegen/shared_resources.rs
Normal file
|
@ -0,0 +1,107 @@
|
||||||
|
use proc_macro2::TokenStream as TokenStream2;
|
||||||
|
use quote::quote;
|
||||||
|
use rtic_syntax::{analyze::Ownership, ast::App};
|
||||||
|
|
||||||
|
use crate::{analyze::Analysis, check::Extra, codegen::util};
|
||||||
|
|
||||||
|
/// Generates `static` variables and shared resource proxies
|
||||||
|
pub fn codegen(
|
||||||
|
app: &App,
|
||||||
|
analysis: &Analysis,
|
||||||
|
extra: &Extra,
|
||||||
|
) -> (
|
||||||
|
// mod_app -- the `static` variables behind the proxies
|
||||||
|
Vec<TokenStream2>,
|
||||||
|
// mod_resources -- the `resources` module
|
||||||
|
TokenStream2,
|
||||||
|
) {
|
||||||
|
let mut mod_app = vec![];
|
||||||
|
let mut mod_resources = vec![];
|
||||||
|
|
||||||
|
for (name, res) in &app.shared_resources {
|
||||||
|
let cfgs = &res.cfgs;
|
||||||
|
let ty = &res.ty;
|
||||||
|
let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(&name));
|
||||||
|
|
||||||
|
// late resources in `util::link_section_uninit`
|
||||||
|
let section = util::link_section_uninit();
|
||||||
|
let attrs = &res.attrs;
|
||||||
|
|
||||||
|
// For future use
|
||||||
|
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
||||||
|
mod_app.push(quote!(
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
// #[doc = #doc]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#(#attrs)*
|
||||||
|
#(#cfgs)*
|
||||||
|
#section
|
||||||
|
static #mangled_name: rtic::RacyCell<core::mem::MaybeUninit<#ty>> = rtic::RacyCell::new(core::mem::MaybeUninit::uninit());
|
||||||
|
));
|
||||||
|
|
||||||
|
// For future use
|
||||||
|
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
|
||||||
|
|
||||||
|
if !res.properties.lock_free {
|
||||||
|
mod_resources.push(quote!(
|
||||||
|
// #[doc = #doc]
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#(#cfgs)*
|
||||||
|
pub struct #name<'a> {
|
||||||
|
priority: &'a Priority,
|
||||||
|
}
|
||||||
|
|
||||||
|
#(#cfgs)*
|
||||||
|
impl<'a> #name<'a> {
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn new(priority: &'a Priority) -> Self {
|
||||||
|
#name { priority }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)]
|
||||||
|
pub unsafe fn priority(&self) -> &Priority {
|
||||||
|
self.priority
|
||||||
|
}
|
||||||
|
}
|
||||||
|
));
|
||||||
|
|
||||||
|
let ptr = quote!(
|
||||||
|
#(#cfgs)*
|
||||||
|
#mangled_name.get_mut_unchecked().as_mut_ptr()
|
||||||
|
);
|
||||||
|
|
||||||
|
let ceiling = match analysis.ownerships.get(name) {
|
||||||
|
Some(Ownership::Owned { priority }) => *priority,
|
||||||
|
Some(Ownership::CoOwned { priority }) => *priority,
|
||||||
|
Some(Ownership::Contended { ceiling }) => *ceiling,
|
||||||
|
None => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
// For future use
|
||||||
|
// let doc = format!(" RTIC internal ({} resource): {}:{}", doc, file!(), line!());
|
||||||
|
|
||||||
|
mod_app.push(util::impl_mutex(
|
||||||
|
extra,
|
||||||
|
cfgs,
|
||||||
|
true,
|
||||||
|
&name,
|
||||||
|
quote!(#ty),
|
||||||
|
ceiling,
|
||||||
|
ptr,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let mod_resources = if mod_resources.is_empty() {
|
||||||
|
quote!()
|
||||||
|
} else {
|
||||||
|
quote!(mod shared_resources {
|
||||||
|
use rtic::export::Priority;
|
||||||
|
|
||||||
|
#(#mod_resources)*
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
(mod_app, mod_resources)
|
||||||
|
}
|
|
@ -4,14 +4,15 @@ use rtic_syntax::{ast::App, Context};
|
||||||
|
|
||||||
use crate::codegen::util;
|
use crate::codegen::util;
|
||||||
|
|
||||||
|
/// Generate shared resources structs
|
||||||
pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) {
|
pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2, TokenStream2) {
|
||||||
let mut lt = None;
|
let mut lt = None;
|
||||||
|
|
||||||
let resources = match ctxt {
|
let resources = match ctxt {
|
||||||
Context::Init => &app.inits.first().unwrap().args.resources,
|
Context::Init => unreachable!("Tried to generate shared resources struct for init"),
|
||||||
Context::Idle => &app.idles.first().unwrap().args.resources,
|
Context::Idle => &app.idle.as_ref().unwrap().args.shared_resources,
|
||||||
Context::HardwareTask(name) => &app.hardware_tasks[name].args.resources,
|
Context::HardwareTask(name) => &app.hardware_tasks[name].args.shared_resources,
|
||||||
Context::SoftwareTask(name) => &app.software_tasks[name].args.resources,
|
Context::SoftwareTask(name) => &app.software_tasks[name].args.shared_resources,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut fields = vec![];
|
let mut fields = vec![];
|
||||||
|
@ -19,7 +20,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
let mut has_cfgs = false;
|
let mut has_cfgs = false;
|
||||||
|
|
||||||
for (name, access) in resources {
|
for (name, access) in resources {
|
||||||
let (res, expr) = app.resource(name).expect("UNREACHABLE");
|
let res = app.shared_resources.get(name).expect("UNREACHABLE");
|
||||||
|
|
||||||
let cfgs = &res.cfgs;
|
let cfgs = &res.cfgs;
|
||||||
has_cfgs |= !cfgs.is_empty();
|
has_cfgs |= !cfgs.is_empty();
|
||||||
|
@ -31,12 +32,9 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
let ty = &res.ty;
|
let ty = &res.ty;
|
||||||
let mangled_name = util::mark_internal_ident(&name);
|
let mangled_name = util::mark_internal_ident(&util::static_shared_resource_ident(&name));
|
||||||
|
|
||||||
// let ownership = &analysis.ownerships[name];
|
if !res.properties.lock_free {
|
||||||
let r_prop = &res.properties;
|
|
||||||
|
|
||||||
if !r_prop.task_local && !r_prop.lock_free {
|
|
||||||
if access.is_shared() {
|
if access.is_shared() {
|
||||||
lt = Some(quote!('a));
|
lt = Some(quote!('a));
|
||||||
|
|
||||||
|
@ -50,12 +48,12 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
|
|
||||||
fields.push(quote!(
|
fields.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
pub #name: resources::#name<'a>
|
pub #name: shared_resources::#name<'a>
|
||||||
));
|
));
|
||||||
|
|
||||||
values.push(quote!(
|
values.push(quote!(
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#name: resources::#name::new(priority)
|
#name: shared_resources::#name::new(priority)
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
@ -76,24 +74,16 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_late = expr.is_none();
|
let expr = if access.is_exclusive() {
|
||||||
if is_late {
|
quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr())
|
||||||
let expr = if access.is_exclusive() {
|
|
||||||
quote!(&mut *#mangled_name.get_mut_unchecked().as_mut_ptr())
|
|
||||||
} else {
|
|
||||||
quote!(&*#mangled_name.get_unchecked().as_ptr())
|
|
||||||
};
|
|
||||||
|
|
||||||
values.push(quote!(
|
|
||||||
#(#cfgs)*
|
|
||||||
#name: #expr
|
|
||||||
));
|
|
||||||
} else {
|
} else {
|
||||||
values.push(quote!(
|
quote!(&*#mangled_name.get_unchecked().as_ptr())
|
||||||
#(#cfgs)*
|
};
|
||||||
#name: #mangled_name.get_mut_unchecked()
|
|
||||||
));
|
values.push(quote!(
|
||||||
}
|
#(#cfgs)*
|
||||||
|
#name: #expr
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if lt.is_some() {
|
if lt.is_some() {
|
||||||
|
@ -110,8 +100,8 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let doc = format!("Resources `{}` has access to", ctxt.ident(app));
|
let doc = format!("Shared resources `{}` has access to", ctxt.ident(app));
|
||||||
let ident = util::resources_ident(ctxt, app);
|
let ident = util::shared_resources_ident(ctxt, app);
|
||||||
let ident = util::mark_internal_ident(&ident);
|
let ident = util::mark_internal_ident(&ident);
|
||||||
let item = quote!(
|
let item = quote!(
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
|
@ -5,7 +5,7 @@ use rtic_syntax::{ast::App, Context};
|
||||||
use crate::{
|
use crate::{
|
||||||
analyze::Analysis,
|
analyze::Analysis,
|
||||||
check::Extra,
|
check::Extra,
|
||||||
codegen::{locals, module, resources_struct, util},
|
codegen::{local_resources_struct, module, shared_resources_struct, util},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn codegen(
|
pub fn codegen(
|
||||||
|
@ -45,7 +45,7 @@ pub fn codegen(
|
||||||
quote!(rtic::export::Queue(unsafe {
|
quote!(rtic::export::Queue(unsafe {
|
||||||
rtic::export::iQueue::u8_sc()
|
rtic::export::iQueue::u8_sc()
|
||||||
})),
|
})),
|
||||||
Box::new(|| util::link_section_uninit(true)),
|
Box::new(|| util::link_section_uninit()),
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
mod_app.push(quote!(
|
mod_app.push(quote!(
|
||||||
|
@ -90,23 +90,32 @@ pub fn codegen(
|
||||||
));
|
));
|
||||||
|
|
||||||
// `${task}Resources`
|
// `${task}Resources`
|
||||||
let mut needs_lt = false;
|
let mut shared_needs_lt = false;
|
||||||
if !task.args.resources.is_empty() {
|
let mut local_needs_lt = false;
|
||||||
let (item, constructor) =
|
|
||||||
resources_struct::codegen(Context::SoftwareTask(name), &mut needs_lt, app);
|
// `${task}Locals`
|
||||||
|
if !task.args.local_resources.is_empty() {
|
||||||
|
let (item, constructor) = local_resources_struct::codegen(
|
||||||
|
Context::SoftwareTask(name),
|
||||||
|
&mut local_needs_lt,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
root.push(item);
|
root.push(item);
|
||||||
|
|
||||||
mod_app.push(constructor);
|
mod_app.push(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
// `${task}Locals`
|
if !task.args.shared_resources.is_empty() {
|
||||||
let mut locals_pat = None;
|
let (item, constructor) = shared_resources_struct::codegen(
|
||||||
if !task.locals.is_empty() {
|
Context::SoftwareTask(name),
|
||||||
let (struct_, pat) = locals::codegen(Context::SoftwareTask(name), &task.locals, app);
|
&mut shared_needs_lt,
|
||||||
|
app,
|
||||||
|
);
|
||||||
|
|
||||||
locals_pat = Some(pat);
|
root.push(item);
|
||||||
root.push(struct_);
|
|
||||||
|
mod_app.push(constructor);
|
||||||
}
|
}
|
||||||
|
|
||||||
if !&task.is_extern {
|
if !&task.is_extern {
|
||||||
|
@ -114,12 +123,11 @@ pub fn codegen(
|
||||||
let attrs = &task.attrs;
|
let attrs = &task.attrs;
|
||||||
let cfgs = &task.cfgs;
|
let cfgs = &task.cfgs;
|
||||||
let stmts = &task.stmts;
|
let stmts = &task.stmts;
|
||||||
let locals_pat = locals_pat.iter();
|
|
||||||
user_tasks.push(quote!(
|
user_tasks.push(quote!(
|
||||||
#(#attrs)*
|
#(#attrs)*
|
||||||
#(#cfgs)*
|
#(#cfgs)*
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn #name(#(#locals_pat,)* #context: #name::Context #(,#inputs)*) {
|
fn #name(#context: #name::Context #(,#inputs)*) {
|
||||||
use rtic::Mutex as _;
|
use rtic::Mutex as _;
|
||||||
use rtic::mutex_prelude::*;
|
use rtic::mutex_prelude::*;
|
||||||
|
|
||||||
|
@ -130,7 +138,8 @@ pub fn codegen(
|
||||||
|
|
||||||
root.push(module::codegen(
|
root.push(module::codegen(
|
||||||
Context::SoftwareTask(name),
|
Context::SoftwareTask(name),
|
||||||
needs_lt,
|
shared_needs_lt,
|
||||||
|
local_needs_lt,
|
||||||
app,
|
app,
|
||||||
analysis,
|
analysis,
|
||||||
extra,
|
extra,
|
||||||
|
|
|
@ -41,7 +41,7 @@ pub fn impl_mutex(
|
||||||
ptr: TokenStream2,
|
ptr: TokenStream2,
|
||||||
) -> TokenStream2 {
|
) -> TokenStream2 {
|
||||||
let (path, priority) = if resources_prefix {
|
let (path, priority) = if resources_prefix {
|
||||||
(quote!(resources::#name), quote!(self.priority()))
|
(quote!(shared_resources::#name), quote!(self.priority()))
|
||||||
} else {
|
} else {
|
||||||
(quote!(#name), quote!(self.priority))
|
(quote!(#name), quote!(self.priority))
|
||||||
};
|
};
|
||||||
|
@ -152,30 +152,12 @@ fn link_section_index() -> usize {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE `None` means in shared memory
|
// NOTE `None` means in shared memory
|
||||||
pub fn link_section_uninit(empty_expr: bool) -> Option<TokenStream2> {
|
pub fn link_section_uninit() -> Option<TokenStream2> {
|
||||||
let section = if empty_expr {
|
let section = format!(".uninit.rtic{}", link_section_index());
|
||||||
let index = link_section_index();
|
|
||||||
format!(".uninit.rtic{}", index)
|
|
||||||
} else {
|
|
||||||
format!(".uninit.rtic{}", link_section_index())
|
|
||||||
};
|
|
||||||
|
|
||||||
Some(quote!(#[link_section = #section]))
|
Some(quote!(#[link_section = #section]))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a pre-reexport identifier for the "locals" struct
|
|
||||||
pub fn locals_ident(ctxt: Context, app: &App) -> Ident {
|
|
||||||
let mut s = match ctxt {
|
|
||||||
Context::Init => app.inits.first().unwrap().name.to_string(),
|
|
||||||
Context::Idle => app.idles.first().unwrap().name.to_string(),
|
|
||||||
Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
s.push_str("Locals");
|
|
||||||
|
|
||||||
Ident::new(&s, Span::call_site())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Regroups the inputs of a task
|
// Regroups the inputs of a task
|
||||||
//
|
//
|
||||||
// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`]
|
// `inputs` could be &[`input: Foo`] OR &[`mut x: i32`, `ref y: i64`]
|
||||||
|
@ -225,15 +207,39 @@ pub fn regroup_inputs(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generates a pre-reexport identifier for the "resources" struct
|
/// Get the ident for the name of the task
|
||||||
pub fn resources_ident(ctxt: Context, app: &App) -> Ident {
|
pub fn get_task_name(ctxt: Context, app: &App) -> Ident {
|
||||||
let mut s = match ctxt {
|
let s = match ctxt {
|
||||||
Context::Init => app.inits.first().unwrap().name.to_string(),
|
Context::Init => app.init.name.to_string(),
|
||||||
Context::Idle => app.idles.first().unwrap().name.to_string(),
|
Context::Idle => app.idle.as_ref().unwrap().name.to_string(),
|
||||||
Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(),
|
Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
s.push_str("Resources");
|
Ident::new(&s, Span::call_site())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates a pre-reexport identifier for the "shared resources" struct
|
||||||
|
pub fn shared_resources_ident(ctxt: Context, app: &App) -> Ident {
|
||||||
|
let mut s = match ctxt {
|
||||||
|
Context::Init => app.init.name.to_string(),
|
||||||
|
Context::Idle => app.idle.as_ref().unwrap().name.to_string(),
|
||||||
|
Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
s.push_str("SharedResources");
|
||||||
|
|
||||||
|
Ident::new(&s, Span::call_site())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Generates a pre-reexport identifier for the "local resources" struct
|
||||||
|
pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident {
|
||||||
|
let mut s = match ctxt {
|
||||||
|
Context::Init => app.init.name.to_string(),
|
||||||
|
Context::Idle => app.idle.as_ref().unwrap().name.to_string(),
|
||||||
|
Context::HardwareTask(ident) | Context::SoftwareTask(ident) => ident.to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
s.push_str("LocalResources");
|
||||||
|
|
||||||
Ident::new(&s, Span::call_site())
|
Ident::new(&s, Span::call_site())
|
||||||
}
|
}
|
||||||
|
@ -275,6 +281,27 @@ pub fn monotonic_ident(name: &str) -> Ident {
|
||||||
Ident::new(&format!("MONOTONIC_STORAGE_{}", name), Span::call_site())
|
Ident::new(&format!("MONOTONIC_STORAGE_{}", name), Span::call_site())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn static_shared_resource_ident(name: &Ident) -> Ident {
|
||||||
|
Ident::new(
|
||||||
|
&format!("shared_resource_{}", name.to_string()),
|
||||||
|
Span::call_site(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn static_local_resource_ident(name: &Ident) -> Ident {
|
||||||
|
Ident::new(
|
||||||
|
&format!("local_resource_{}", name.to_string()),
|
||||||
|
Span::call_site(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident {
|
||||||
|
Ident::new(
|
||||||
|
&format!("local_{}_{}", task_name.to_string(), name.to_string()),
|
||||||
|
Span::call_site(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// The name to get better RT flag errors
|
/// The name to get better RT flag errors
|
||||||
pub fn rt_err_ident() -> Ident {
|
pub fn rt_err_ident() -> Ident {
|
||||||
Ident::new(
|
Ident::new(
|
||||||
|
|
|
@ -10,6 +10,17 @@ fn analyze() {
|
||||||
quote!(device = pac, dispatchers = [B, A]),
|
quote!(device = pac, dispatchers = [B, A]),
|
||||||
quote!(
|
quote!(
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(_: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
|
}
|
||||||
|
|
||||||
#[task(priority = 1)]
|
#[task(priority = 1)]
|
||||||
fn a(_: a::Context) {}
|
fn a(_: a::Context) {}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,17 @@
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
#[rtic::app(device = lm3s6965)]
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
|
}
|
||||||
|
|
||||||
#[task(binds = NonMaskableInt)]
|
#[task(binds = NonMaskableInt)]
|
||||||
fn nmi(_: nmi::Context) {}
|
fn nmi(_: nmi::Context) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: only exceptions with configurable priority can be used as hardware tasks
|
error: only exceptions with configurable priority can be used as hardware tasks
|
||||||
--> $DIR/exception-invalid.rs:6:8
|
--> $DIR/exception-invalid.rs:17:8
|
||||||
|
|
|
|
||||||
6 | fn nmi(_: nmi::Context) {}
|
17 | fn nmi(_: nmi::Context) {}
|
||||||
| ^^^
|
| ^^^
|
||||||
|
|
|
@ -2,6 +2,17 @@
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
#[rtic::app(device = lm3s6965)]
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
|
}
|
||||||
|
|
||||||
#[task]
|
#[task]
|
||||||
fn a(_: a::Context) {}
|
fn a(_: a::Context) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: not enough interrupts to dispatch all software tasks (need: 1; given: 0)
|
error: not enough interrupts to dispatch all software tasks (need: 1; given: 0)
|
||||||
--> $DIR/extern-interrupt-not-enough.rs:6:8
|
--> $DIR/extern-interrupt-not-enough.rs:17:8
|
||||||
|
|
|
|
||||||
6 | fn a(_: a::Context) {}
|
17 | fn a(_: a::Context) {}
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -2,6 +2,17 @@
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [UART0])]
|
#[rtic::app(device = lm3s6965, dispatchers = [UART0])]
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
|
#[init]
|
||||||
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
|
}
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
#[task(binds = UART0)]
|
||||||
fn a(_: a::Context) {}
|
fn a(_: a::Context) {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error: dispatcher interrupts can't be used as hardware tasks
|
error: dispatcher interrupts can't be used as hardware tasks
|
||||||
--> $DIR/extern-interrupt-used.rs:5:20
|
--> $DIR/extern-interrupt-used.rs:16:20
|
||||||
|
|
|
|
||||||
5 | #[task(binds = UART0)]
|
16 | #[task(binds = UART0)]
|
||||||
| ^^^^^
|
| ^^^^^
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
//! examples/local-cfg-task-local.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
//#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
use cortex_m_semihosting::debug;
|
|
||||||
use cortex_m_semihosting::hprintln;
|
|
||||||
use lm3s6965::Interrupt;
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
// A local (move), early resource
|
|
||||||
#[cfg(feature = "feature_l1")]
|
|
||||||
#[task_local]
|
|
||||||
#[init(1)]
|
|
||||||
l1: u32,
|
|
||||||
|
|
||||||
// A local (move), late resource
|
|
||||||
#[task_local]
|
|
||||||
l2: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
rtic::pend(Interrupt::UART0);
|
|
||||||
rtic::pend(Interrupt::UART1);
|
|
||||||
(
|
|
||||||
init::LateResources {
|
|
||||||
#[cfg(feature = "feature_l2")]
|
|
||||||
l2: 2,
|
|
||||||
#[cfg(not(feature = "feature_l2"))]
|
|
||||||
l2: 5,
|
|
||||||
},
|
|
||||||
init::Monotonics(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// l1 ok (task_local)
|
|
||||||
#[idle(resources =[#[cfg(feature = "feature_l1")]l1])]
|
|
||||||
fn idle(_cx: idle::Context) -> ! {
|
|
||||||
#[cfg(feature = "feature_l1")]
|
|
||||||
hprintln!("IDLE:l1 = {}", _cx.resources.l1).unwrap();
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// l2 ok (task_local)
|
|
||||||
#[task(priority = 1, binds = UART0, resources = [
|
|
||||||
#[cfg(feature = "feature_l2")]l2,
|
|
||||||
])]
|
|
||||||
fn uart0(_cx: uart0::Context) {
|
|
||||||
#[cfg(feature = "feature_l2")]
|
|
||||||
hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// l2 error, conflicting with uart0 for l2 (task_local)
|
|
||||||
#[task(priority = 1, binds = UART1, resources = [
|
|
||||||
#[cfg(not(feature = "feature_l2"))]l2
|
|
||||||
])]
|
|
||||||
fn uart1(_cx: uart1::Context) {
|
|
||||||
#[cfg(not(feature = "feature_l2"))]
|
|
||||||
hprintln!("UART0:l2 = {}", _cx.resources.l2).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,37 +0,0 @@
|
||||||
error: task local resource "l2" is used by multiple tasks
|
|
||||||
--> $DIR/local-cfg-task-local-err.rs:25:9
|
|
||||||
|
|
|
||||||
25 | l2: u32,
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: task local resource "l2" is used by task "uart0" with priority 1
|
|
||||||
--> $DIR/local-cfg-task-local-err.rs:54:39
|
|
||||||
|
|
|
||||||
54 | #[cfg(feature = "feature_l2")]l2,
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: task local resource "l2" is used by task "uart1" with priority 1
|
|
||||||
--> $DIR/local-cfg-task-local-err.rs:63:44
|
|
||||||
|
|
|
||||||
63 | #[cfg(not(feature = "feature_l2"))]l2
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
warning: unused import: `cortex_m_semihosting::debug`
|
|
||||||
--> $DIR/local-cfg-task-local-err.rs:8:5
|
|
||||||
|
|
|
||||||
8 | use cortex_m_semihosting::debug;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: `#[warn(unused_imports)]` on by default
|
|
||||||
|
|
||||||
warning: unused import: `cortex_m_semihosting::hprintln`
|
|
||||||
--> $DIR/local-cfg-task-local-err.rs:9:5
|
|
||||||
|
|
|
||||||
9 | use cortex_m_semihosting::hprintln;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: unused import: `lm3s6965::Interrupt`
|
|
||||||
--> $DIR/local-cfg-task-local-err.rs:10:5
|
|
||||||
|
|
|
||||||
10 | use lm3s6965::Interrupt;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
|
|
@ -1,83 +0,0 @@
|
||||||
//! examples/local_err.rs
|
|
||||||
|
|
||||||
#![deny(unsafe_code)]
|
|
||||||
#![deny(warnings)]
|
|
||||||
#![no_main]
|
|
||||||
#![no_std]
|
|
||||||
|
|
||||||
// errors here, since we cannot bail compilation or generate stubs
|
|
||||||
// run cargo expand, then you see the root of the problem...
|
|
||||||
use cortex_m_semihosting::{debug, hprintln};
|
|
||||||
use lm3s6965::Interrupt;
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
// An early resource
|
|
||||||
#[init(0)]
|
|
||||||
shared: u32,
|
|
||||||
|
|
||||||
// A local (move), early resource
|
|
||||||
#[task_local]
|
|
||||||
#[init(1)]
|
|
||||||
l1: u32,
|
|
||||||
|
|
||||||
// An exclusive, early resource
|
|
||||||
#[lock_free]
|
|
||||||
#[init(1)]
|
|
||||||
e1: u32,
|
|
||||||
|
|
||||||
// A local (move), late resource
|
|
||||||
#[task_local]
|
|
||||||
l2: u32,
|
|
||||||
|
|
||||||
// An exclusive, late resource
|
|
||||||
#[lock_free]
|
|
||||||
e2: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
rtic::pend(Interrupt::UART0);
|
|
||||||
rtic::pend(Interrupt::UART1);
|
|
||||||
(init::LateResources { e2: 2, l2: 2 }, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
// `shared` cannot be accessed from this context
|
|
||||||
// l1 ok
|
|
||||||
// l2 rejeceted (not task_local)
|
|
||||||
// e2 ok
|
|
||||||
#[idle(resources =[l1, l2, e2])]
|
|
||||||
fn idle(cx: idle::Context) -> ! {
|
|
||||||
hprintln!("IDLE:l1 = {}", cx.resources.l1).unwrap();
|
|
||||||
hprintln!("IDLE:e2 = {}", cx.resources.e2).unwrap();
|
|
||||||
debug::exit(debug::EXIT_SUCCESS);
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
// `shared` can be accessed from this context
|
|
||||||
// l2 rejected (not task_local)
|
|
||||||
// e1 rejected (not lock_free)
|
|
||||||
#[task(priority = 1, binds = UART0, resources = [shared, l2, e1])]
|
|
||||||
fn uart0(cx: uart0::Context) {
|
|
||||||
let shared: &mut u32 = cx.resources.shared;
|
|
||||||
*shared += 1;
|
|
||||||
*cx.resources.e1 += 10;
|
|
||||||
hprintln!("UART0: shared = {}", shared).unwrap();
|
|
||||||
hprintln!("UART0:l2 = {}", cx.resources.l2).unwrap();
|
|
||||||
hprintln!("UART0:e1 = {}", cx.resources.e1).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
// l2 rejected (not task_local)
|
|
||||||
#[task(priority = 2, binds = UART1, resources = [shared, l2, e1])]
|
|
||||||
fn uart1(cx: uart1::Context) {
|
|
||||||
let shared: &mut u32 = cx.resources.shared;
|
|
||||||
*shared += 1;
|
|
||||||
|
|
||||||
hprintln!("UART1: shared = {}", shared).unwrap();
|
|
||||||
hprintln!("UART1:l2 = {}", cx.resources.l2).unwrap();
|
|
||||||
hprintln!("UART1:e1 = {}", cx.resources.e1).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,60 +0,0 @@
|
||||||
error: task local resource "l2" is used by multiple tasks
|
|
||||||
--> $DIR/local-err.rs:34:9
|
|
||||||
|
|
|
||||||
34 | l2: u32,
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: task local resource "l2" is used by task "idle" with priority 0
|
|
||||||
--> $DIR/local-err.rs:52:28
|
|
||||||
|
|
|
||||||
52 | #[idle(resources =[l1, l2, e2])]
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: task local resource "l2" is used by task "uart0" with priority 1
|
|
||||||
--> $DIR/local-err.rs:63:62
|
|
||||||
|
|
|
||||||
63 | #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])]
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: task local resource "l2" is used by task "uart1" with priority 2
|
|
||||||
--> $DIR/local-err.rs:74:62
|
|
||||||
|
|
|
||||||
74 | #[task(priority = 2, binds = UART1, resources = [shared, l2, e1])]
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: Lock free resource "e1" is used by tasks at different priorities
|
|
||||||
--> $DIR/local-err.rs:30:9
|
|
||||||
|
|
|
||||||
30 | e1: u32,
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: Resource "e1" is declared lock free but used by tasks at different priorities
|
|
||||||
--> $DIR/local-err.rs:63:66
|
|
||||||
|
|
|
||||||
63 | #[task(priority = 1, binds = UART0, resources = [shared, l2, e1])]
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: Resource "e1" is declared lock free but used by tasks at different priorities
|
|
||||||
--> $DIR/local-err.rs:74:66
|
|
||||||
|
|
|
||||||
74 | #[task(priority = 2, binds = UART1, resources = [shared, l2, e1])]
|
|
||||||
| ^^
|
|
||||||
|
|
||||||
error: unused imports: `debug`, `hprintln`
|
|
||||||
--> $DIR/local-err.rs:10:28
|
|
||||||
|
|
|
||||||
10 | use cortex_m_semihosting::{debug, hprintln};
|
|
||||||
| ^^^^^ ^^^^^^^^
|
|
||||||
|
|
|
||||||
note: the lint level is defined here
|
|
||||||
--> $DIR/local-err.rs:4:9
|
|
||||||
|
|
|
||||||
4 | #![deny(warnings)]
|
|
||||||
| ^^^^^^^^
|
|
||||||
= note: `#[deny(unused_imports)]` implied by `#[deny(warnings)]`
|
|
||||||
|
|
||||||
error: unused import: `lm3s6965::Interrupt`
|
|
||||||
--> $DIR/local-err.rs:11:5
|
|
||||||
|
|
|
||||||
11 | use lm3s6965::Interrupt;
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
|
|
@ -1,50 +0,0 @@
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965, dispatchers = [SSI0])]
|
|
||||||
mod app {
|
|
||||||
#[init]
|
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut FOO: u32 = 0;
|
|
||||||
|
|
||||||
FOO;
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[idle]
|
|
||||||
fn idle(_: idle::Context) -> ! {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut FOO: u32 = 0;
|
|
||||||
|
|
||||||
FOO;
|
|
||||||
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = SVCall)]
|
|
||||||
fn svcall(_: svcall::Context) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut FOO: u32 = 0;
|
|
||||||
|
|
||||||
FOO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = UART0)]
|
|
||||||
fn uart0(_: uart0::Context) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut FOO: u32 = 0;
|
|
||||||
|
|
||||||
FOO;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task]
|
|
||||||
fn foo(_: foo::Context) {
|
|
||||||
#[cfg(never)]
|
|
||||||
static mut FOO: u32 = 0;
|
|
||||||
|
|
||||||
FOO;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,29 +0,0 @@
|
||||||
error[E0425]: cannot find value `FOO` in this scope
|
|
||||||
--> $DIR/locals-cfg.rs:12:9
|
|
||||||
|
|
|
||||||
12 | FOO;
|
|
||||||
| ^^^ not found in this scope
|
|
||||||
|
|
||||||
error[E0425]: cannot find value `FOO` in this scope
|
|
||||||
--> $DIR/locals-cfg.rs:22:9
|
|
||||||
|
|
|
||||||
22 | FOO;
|
|
||||||
| ^^^ not found in this scope
|
|
||||||
|
|
||||||
error[E0425]: cannot find value `FOO` in this scope
|
|
||||||
--> $DIR/locals-cfg.rs:32:9
|
|
||||||
|
|
|
||||||
32 | FOO;
|
|
||||||
| ^^^ not found in this scope
|
|
||||||
|
|
||||||
error[E0425]: cannot find value `FOO` in this scope
|
|
||||||
--> $DIR/locals-cfg.rs:40:9
|
|
||||||
|
|
|
||||||
40 | FOO;
|
|
||||||
| ^^^ not found in this scope
|
|
||||||
|
|
||||||
error[E0425]: cannot find value `FOO` in this scope
|
|
||||||
--> $DIR/locals-cfg.rs:48:9
|
|
||||||
|
|
|
||||||
48 | FOO;
|
|
||||||
| ^^^ not found in this scope
|
|
|
@ -1,80 +0,0 @@
|
||||||
#![no_main]
|
|
||||||
|
|
||||||
use panic_semihosting as _;
|
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
|
||||||
mod app {
|
|
||||||
#[resources]
|
|
||||||
struct Resources {
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
o1: u32, // init
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
o2: u32, // idle
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
o3: u32, // EXTI0
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
o4: u32, // idle
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
o5: u32, // EXTI1
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
o6: u32, // init
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
s1: u32, // idle & EXTI0
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
s2: u32, // EXTI0 & EXTI1
|
|
||||||
|
|
||||||
#[cfg(never)]
|
|
||||||
#[init(0)]
|
|
||||||
s3: u32,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[init(resources = [o1, o4, o5, o6, s3])]
|
|
||||||
fn init(c: init::Context) -> (init::LateResources, init::Monotonics) {
|
|
||||||
c.resources.o1;
|
|
||||||
c.resources.o4;
|
|
||||||
c.resources.o5;
|
|
||||||
c.resources.o6;
|
|
||||||
c.resources.s3;
|
|
||||||
|
|
||||||
(init::LateResources {}, init::Monotonics())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[idle(resources = [o2, &o4, s1, &s3])]
|
|
||||||
fn idle(c: idle::Context) -> ! {
|
|
||||||
c.resources.o2;
|
|
||||||
c.resources.o4;
|
|
||||||
c.resources.s1;
|
|
||||||
c.resources.s3;
|
|
||||||
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = UART0, resources = [o3, s1, s2, &s3])]
|
|
||||||
fn uart0(c: uart0::Context) {
|
|
||||||
c.resources.o3;
|
|
||||||
c.resources.s1;
|
|
||||||
c.resources.s2;
|
|
||||||
c.resources.s3;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds = UART1, resources = [s2, &o5])]
|
|
||||||
fn uart1(c: uart1::Context) {
|
|
||||||
c.resources.s2;
|
|
||||||
c.resources.o5;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,119 +0,0 @@
|
||||||
error[E0609]: no field `o1` on type `__rtic_internal_initResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:48:21
|
|
||||||
|
|
|
||||||
48 | c.resources.o1;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o4` on type `__rtic_internal_initResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:49:21
|
|
||||||
|
|
|
||||||
49 | c.resources.o4;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o5` on type `__rtic_internal_initResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:50:21
|
|
||||||
|
|
|
||||||
50 | c.resources.o5;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o6` on type `__rtic_internal_initResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:51:21
|
|
||||||
|
|
|
||||||
51 | c.resources.o6;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s3` on type `__rtic_internal_initResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:52:21
|
|
||||||
|
|
|
||||||
52 | c.resources.s3;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o2` on type `__rtic_internal_idleResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:59:21
|
|
||||||
|
|
|
||||||
59 | c.resources.o2;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o4` on type `__rtic_internal_idleResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:60:21
|
|
||||||
|
|
|
||||||
60 | c.resources.o4;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s1` on type `__rtic_internal_idleResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:61:21
|
|
||||||
|
|
|
||||||
61 | c.resources.s1;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s3` on type `__rtic_internal_idleResources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:62:21
|
|
||||||
|
|
|
||||||
62 | c.resources.s3;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o3` on type `__rtic_internal_uart0Resources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:69:21
|
|
||||||
|
|
|
||||||
69 | c.resources.o3;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s1` on type `__rtic_internal_uart0Resources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:70:21
|
|
||||||
|
|
|
||||||
70 | c.resources.s1;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s2` on type `__rtic_internal_uart0Resources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:71:21
|
|
||||||
|
|
|
||||||
71 | c.resources.s2;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s3` on type `__rtic_internal_uart0Resources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:72:21
|
|
||||||
|
|
|
||||||
72 | c.resources.s3;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `s2` on type `__rtic_internal_uart1Resources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:77:21
|
|
||||||
|
|
|
||||||
77 | c.resources.s2;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
||||||
|
|
||||||
error[E0609]: no field `o5` on type `__rtic_internal_uart1Resources<'_>`
|
|
||||||
--> $DIR/resources-cfg.rs:78:21
|
|
||||||
|
|
|
||||||
78 | c.resources.o5;
|
|
||||||
| ^^ unknown field
|
|
||||||
|
|
|
||||||
= note: available fields are: `__marker__`
|
|
|
@ -2,9 +2,15 @@
|
||||||
|
|
||||||
#[rtic::app(device = lm3s6965)]
|
#[rtic::app(device = lm3s6965)]
|
||||||
mod app {
|
mod app {
|
||||||
|
#[shared]
|
||||||
|
struct Shared {}
|
||||||
|
|
||||||
|
#[local]
|
||||||
|
struct Local {}
|
||||||
|
|
||||||
#[init]
|
#[init]
|
||||||
fn init(_: init::Context) -> (init::LateResources, init::Monotonics) {
|
fn init(cx: init::Context) -> (Shared, Local, init::Monotonics) {
|
||||||
(init::LateResources {}, init::Monotonics())
|
(Shared {}, Local {}, init::Monotonics {})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(binds = GPIOA, priority = 1)]
|
#[task(binds = GPIOA, priority = 1)]
|
||||||
|
|
Loading…
Reference in a new issue