mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-16 21:05:35 +01:00
rtfm-syntax refactor + heterogeneous multi-core support
This commit is contained in:
parent
fafeeb2727
commit
81275bfa4f
127 changed files with 4072 additions and 5848 deletions
|
|
@ -5,13 +5,12 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
// NOTE: does NOT properly work on QEMU
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo])]
|
||||
fn init(c: init::Context) {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
// `examples/interrupt.rs` rewritten to use `binds`
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
@ -21,12 +20,12 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[task(priority = 3, resources = [COUNT], spawn = [log])]
|
||||
fn foo(c: foo::Context) {
|
||||
fn foo(_c: foo::Context) {
|
||||
#[cfg(debug_assertions)]
|
||||
{
|
||||
*c.resources.COUNT += 1;
|
||||
*_c.resources.COUNT += 1;
|
||||
|
||||
c.spawn.log(*c.resources.COUNT).ok();
|
||||
_c.spawn.log(*_c.resources.COUNT).ok();
|
||||
}
|
||||
|
||||
// this wouldn't compile in `release` mode
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use rtfm::Mutex;
|
||||
use panic_semihosting as _;
|
||||
use rtfm::{Exclusive, Mutex};
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
@ -35,17 +34,15 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(priority = 2, resources = [SHARED])]
|
||||
fn UART1(mut c: UART1::Context) {
|
||||
fn UART1(c: UART1::Context) {
|
||||
static mut STATE: u32 = 0;
|
||||
|
||||
hprintln!("UART1(STATE = {})", *STATE).unwrap();
|
||||
|
||||
// just to show that `SHARED` can be accessed directly and ..
|
||||
// just to show that `SHARED` can be accessed directly
|
||||
*c.resources.SHARED += 0;
|
||||
// .. also through a (no-op) `lock`
|
||||
c.resources.SHARED.lock(|shared| *shared += 0);
|
||||
|
||||
advance(STATE, c.resources.SHARED);
|
||||
advance(STATE, Exclusive(c.resources.SHARED));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
|
|||
|
|
@ -5,18 +5,17 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965, peripherals = true)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(c: init::Context) {
|
||||
static mut X: u32 = 0;
|
||||
|
||||
// Cortex-M peripherals
|
||||
let _core: rtfm::Peripherals = c.core;
|
||||
let _core: cortex_m::Peripherals = c.core;
|
||||
|
||||
// Device specific peripherals
|
||||
let _device: lm3s6965::Peripherals = c.device;
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
|
|||
|
|
@ -5,20 +5,21 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use heapless::{
|
||||
consts::*,
|
||||
spsc::{Consumer, Producer, Queue},
|
||||
};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
// Late resources
|
||||
static mut P: Producer<'static, u32, U4> = ();
|
||||
static mut C: Consumer<'static, u32, U4> = ();
|
||||
extern "C" {
|
||||
static mut P: Producer<'static, u32, U4>;
|
||||
static mut C: Consumer<'static, u32, U4>;
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
@ -46,7 +45,7 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[interrupt(priority = 2, resources = [SHARED])]
|
||||
fn GPIOB(mut c: GPIOB::Context) {
|
||||
fn GPIOB(c: GPIOB::Context) {
|
||||
// the higher priority task does *not* need a critical section
|
||||
*c.resources.SHARED += 1;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use cortex_m_semihosting::debug;
|
||||
use panic_halt as _;
|
||||
use rtfm::app;
|
||||
|
||||
pub struct NotSend {
|
||||
|
|
@ -38,13 +37,13 @@ const APP: () = {
|
|||
}
|
||||
|
||||
#[task(priority = 2, resources = [SHARED])]
|
||||
fn baz(mut c: baz::Context) {
|
||||
fn baz(c: baz::Context) {
|
||||
// scenario 2: resource shared between tasks that run at the same priority
|
||||
*c.resources.SHARED = Some(NotSend { _0: PhantomData });
|
||||
}
|
||||
|
||||
#[task(priority = 2, resources = [SHARED])]
|
||||
fn quux(mut c: quux::Context) {
|
||||
fn quux(c: quux::Context) {
|
||||
// scenario 2
|
||||
let _not_send = c.resources.SHARED.take().unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use cortex_m_semihosting::debug;
|
||||
use panic_halt as _;
|
||||
|
||||
pub struct NotSync {
|
||||
_0: PhantomData<*const ()>,
|
||||
|
|
|
|||
|
|
@ -5,15 +5,14 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use rtfm::Instant;
|
||||
use panic_semihosting as _;
|
||||
use rtfm::cyccnt::{Instant, U32Ext};
|
||||
|
||||
const PERIOD: u32 = 8_000_000;
|
||||
|
||||
// NOTE: does NOT work on QEMU!
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo])]
|
||||
fn init(c: init::Context) {
|
||||
|
|
|
|||
|
|
@ -5,14 +5,13 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use heapless::{
|
||||
pool,
|
||||
pool::singleton::{Box, Pool},
|
||||
};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
use rtfm::app;
|
||||
|
||||
// Declare a pool of 128-byte memory blocks
|
||||
|
|
|
|||
|
|
@ -5,9 +5,8 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
@ -33,7 +32,7 @@ const APP: () = {
|
|||
|
||||
// `SHARED` can be access from this context
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn UART0(mut c: UART0::Context) {
|
||||
fn UART0(c: UART0::Context) {
|
||||
*c.resources.SHARED += 1;
|
||||
|
||||
hprintln!("UART0: SHARED = {}", c.resources.SHARED).unwrap();
|
||||
|
|
@ -41,7 +40,7 @@ const APP: () = {
|
|||
|
||||
// `SHARED` can be access from this context
|
||||
#[interrupt(resources = [SHARED])]
|
||||
fn UART1(mut c: UART1::Context) {
|
||||
fn UART1(c: UART1::Context) {
|
||||
*c.resources.SHARED += 1;
|
||||
|
||||
hprintln!("UART1: SHARED = {}", c.resources.SHARED).unwrap();
|
||||
|
|
|
|||
|
|
@ -5,13 +5,12 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::hprintln;
|
||||
use rtfm::Instant;
|
||||
use panic_halt as _;
|
||||
use rtfm::cyccnt::{Instant, U32Ext as _};
|
||||
|
||||
// NOTE: does NOT work on QEMU!
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo, bar])]
|
||||
fn init(c: init::Context) {
|
||||
|
|
|
|||
|
|
@ -5,10 +5,9 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_halt;
|
||||
|
||||
use cortex_m_semihosting::debug;
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_halt as _;
|
||||
use rtfm::app;
|
||||
|
||||
pub struct MustBeSend;
|
||||
|
|
|
|||
|
|
@ -5,13 +5,8 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
// panic-handler crate
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use panic_semihosting as _; // panic handler
|
||||
use rtfm::app;
|
||||
|
||||
#[app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {}
|
||||
};
|
||||
const APP: () = {};
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use lm3s6965::Interrupt;
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static KEY: u32 = ();
|
||||
extern "C" {
|
||||
static KEY: u32;
|
||||
}
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) -> init::LateResources {
|
||||
|
|
|
|||
30
examples/t-binds.rs
Normal file
30
examples/t-binds.rs
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
//! [compile-pass] Check that `binds` works as advertised
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_halt as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init]
|
||||
fn init(_: init::Context) {}
|
||||
|
||||
#[exception(binds = SVCall)]
|
||||
fn foo(c: foo::Context) {
|
||||
foo_trampoline(c)
|
||||
}
|
||||
|
||||
#[interrupt(binds = UART0)]
|
||||
fn bar(c: bar::Context) {
|
||||
bar_trampoline(c)
|
||||
}
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn foo_trampoline(_: foo::Context) {}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn bar_trampoline(_: bar::Context) {}
|
||||
47
examples/t-cfg.rs
Normal file
47
examples/t-cfg.rs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
//! [compile-pass] check that `#[cfg]` attributes are respected
|
||||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_halt as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[cfg(never)]
|
||||
static mut FOO: u32 = 0;
|
||||
|
||||
#[init]
|
||||
fn init(_: init::Context) {
|
||||
#[cfg(never)]
|
||||
static mut BAR: u32 = 0;
|
||||
}
|
||||
|
||||
#[idle]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
#[cfg(never)]
|
||||
static mut BAR: u32 = 0;
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[task(resources = [FOO], schedule = [quux], spawn = [quux])]
|
||||
fn foo(_: foo::Context) {
|
||||
#[cfg(never)]
|
||||
static mut BAR: u32 = 0;
|
||||
}
|
||||
|
||||
#[task(priority = 3, resources = [FOO], schedule = [quux], spawn = [quux])]
|
||||
fn bar(_: bar::Context) {
|
||||
#[cfg(never)]
|
||||
static mut BAR: u32 = 0;
|
||||
}
|
||||
|
||||
#[cfg(never)]
|
||||
#[task]
|
||||
fn quux(_: quux::Context) {}
|
||||
|
||||
extern "C" {
|
||||
fn UART0();
|
||||
fn UART1();
|
||||
}
|
||||
};
|
||||
36
examples/t-late-not-send.rs
Normal file
36
examples/t-late-not-send.rs
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
//! [compile-pass] late resources don't need to be `Send` if they are owned by `idle`
|
||||
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use panic_halt as _;
|
||||
|
||||
pub struct NotSend {
|
||||
_0: PhantomData<*const ()>,
|
||||
}
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
extern "C" {
|
||||
static mut X: NotSend;
|
||||
}
|
||||
|
||||
static mut Y: Option<NotSend> = None;
|
||||
|
||||
#[init(resources = [Y])]
|
||||
fn init(c: init::Context) -> init::LateResources {
|
||||
// equivalent to late resource initialization
|
||||
*c.resources.Y = Some(NotSend { _0: PhantomData });
|
||||
|
||||
init::LateResources {
|
||||
X: NotSend { _0: PhantomData },
|
||||
}
|
||||
}
|
||||
|
||||
#[idle(resources = [X, Y])]
|
||||
fn idle(_: idle::Context) -> ! {
|
||||
loop {}
|
||||
}
|
||||
};
|
||||
77
examples/t-resource.rs
Normal file
77
examples/t-resource.rs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
//! [compile-pass] Check code generation of resources
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_halt as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
static mut O1: u32 = 0; // init
|
||||
static mut O2: u32 = 0; // idle
|
||||
static mut O3: u32 = 0; // EXTI0
|
||||
static O4: u32 = 0; // idle
|
||||
static O5: u32 = 0; // EXTI1
|
||||
static O6: u32 = 0; // init
|
||||
|
||||
static mut S1: u32 = 0; // idle & EXTI0
|
||||
static mut S2: u32 = 0; // EXTI0 & EXTI1
|
||||
static S3: u32 = 0;
|
||||
|
||||
#[init(resources = [O1, O4, O5, O6, S3])]
|
||||
fn init(c: init::Context) {
|
||||
// owned by `init` == `&'static mut`
|
||||
let _: &'static mut u32 = c.resources.O1;
|
||||
|
||||
// owned by `init` == `&'static` if read-only
|
||||
let _: &'static u32 = c.resources.O6;
|
||||
|
||||
// `init` has exclusive access to all resources
|
||||
let _: &mut u32 = c.resources.O4;
|
||||
let _: &mut u32 = c.resources.O5;
|
||||
let _: &mut u32 = c.resources.S3;
|
||||
}
|
||||
|
||||
#[idle(resources = [O2, O4, S1, S3])]
|
||||
fn idle(mut c: idle::Context) -> ! {
|
||||
// owned by `idle` == `&'static mut`
|
||||
let _: &'static mut u32 = c.resources.O2;
|
||||
|
||||
// owned by `idle` == `&'static` if read-only
|
||||
let _: &'static u32 = c.resources.O4;
|
||||
|
||||
// shared with `idle` == `Mutex`
|
||||
c.resources.S1.lock(|_| {});
|
||||
|
||||
// `&` if read-only
|
||||
let _: &u32 = c.resources.S3;
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[interrupt(resources = [O3, S1, S2, S3])]
|
||||
fn UART0(c: UART0::Context) {
|
||||
// owned by interrupt == `&mut`
|
||||
let _: &mut u32 = c.resources.O3;
|
||||
|
||||
// no `Mutex` proxy when access from highest priority task
|
||||
let _: &mut u32 = c.resources.S1;
|
||||
|
||||
// no `Mutex` proxy when co-owned by cooperative (same priority) tasks
|
||||
let _: &mut u32 = c.resources.S2;
|
||||
|
||||
// `&` if read-only
|
||||
let _: &u32 = c.resources.S3;
|
||||
}
|
||||
|
||||
#[interrupt(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 _: &mut u32 = c.resources.S2;
|
||||
}
|
||||
};
|
||||
59
examples/t-schedule.rs
Normal file
59
examples/t-schedule.rs
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
//! [compile-pass] Check `schedule` code generation
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_halt as _;
|
||||
use rtfm::cyccnt::{Instant, U32Ext as _};
|
||||
|
||||
#[rtfm::app(device = lm3s6965, monotonic = rtfm::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
#[init(schedule = [foo, bar, baz])]
|
||||
fn init(c: init::Context) {
|
||||
let _: Result<(), ()> = c.schedule.foo(c.start + 10.cycles());
|
||||
let _: Result<(), u32> = c.schedule.bar(c.start + 20.cycles(), 0);
|
||||
let _: Result<(), (u32, u32)> = c.schedule.baz(c.start + 30.cycles(), 0, 1);
|
||||
}
|
||||
|
||||
#[idle(schedule = [foo, bar, baz])]
|
||||
fn idle(c: idle::Context) -> ! {
|
||||
let _: Result<(), ()> = c.schedule.foo(Instant::now() + 40.cycles());
|
||||
let _: Result<(), u32> = c.schedule.bar(Instant::now() + 50.cycles(), 0);
|
||||
let _: Result<(), (u32, u32)> = c.schedule.baz(Instant::now() + 60.cycles(), 0, 1);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[exception(schedule = [foo, bar, baz])]
|
||||
fn SVCall(c: SVCall::Context) {
|
||||
let _: Result<(), ()> = c.schedule.foo(c.start + 70.cycles());
|
||||
let _: Result<(), u32> = c.schedule.bar(c.start + 80.cycles(), 0);
|
||||
let _: Result<(), (u32, u32)> = c.schedule.baz(c.start + 90.cycles(), 0, 1);
|
||||
}
|
||||
|
||||
#[interrupt(schedule = [foo, bar, baz])]
|
||||
fn UART0(c: UART0::Context) {
|
||||
let _: Result<(), ()> = c.schedule.foo(c.start + 100.cycles());
|
||||
let _: Result<(), u32> = c.schedule.bar(c.start + 110.cycles(), 0);
|
||||
let _: Result<(), (u32, u32)> = c.schedule.baz(c.start + 120.cycles(), 0, 1);
|
||||
}
|
||||
|
||||
#[task(schedule = [foo, bar, baz])]
|
||||
fn foo(c: foo::Context) {
|
||||
let _: Result<(), ()> = c.schedule.foo(c.scheduled + 130.cycles());
|
||||
let _: Result<(), u32> = c.schedule.bar(c.scheduled + 140.cycles(), 0);
|
||||
let _: Result<(), (u32, u32)> = c.schedule.baz(c.scheduled + 150.cycles(), 0, 1);
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context, _x: u32) {}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context, _x: u32, _y: u32) {}
|
||||
|
||||
extern "C" {
|
||||
fn UART1();
|
||||
}
|
||||
};
|
||||
58
examples/t-spawn.rs
Normal file
58
examples/t-spawn.rs
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
//! [compile-pass] Check code generation of `spawn`
|
||||
|
||||
#![deny(unsafe_code)]
|
||||
#![deny(warnings)]
|
||||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
use panic_halt as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
#[init(spawn = [foo, bar, baz])]
|
||||
fn init(c: init::Context) {
|
||||
let _: Result<(), ()> = c.spawn.foo();
|
||||
let _: Result<(), u32> = c.spawn.bar(0);
|
||||
let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1);
|
||||
}
|
||||
|
||||
#[idle(spawn = [foo, bar, baz])]
|
||||
fn idle(c: idle::Context) -> ! {
|
||||
let _: Result<(), ()> = c.spawn.foo();
|
||||
let _: Result<(), u32> = c.spawn.bar(0);
|
||||
let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1);
|
||||
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[exception(spawn = [foo, bar, baz])]
|
||||
fn SVCall(c: SVCall::Context) {
|
||||
let _: Result<(), ()> = c.spawn.foo();
|
||||
let _: Result<(), u32> = c.spawn.bar(0);
|
||||
let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1);
|
||||
}
|
||||
|
||||
#[interrupt(spawn = [foo, bar, baz])]
|
||||
fn UART0(c: UART0::Context) {
|
||||
let _: Result<(), ()> = c.spawn.foo();
|
||||
let _: Result<(), u32> = c.spawn.bar(0);
|
||||
let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1);
|
||||
}
|
||||
|
||||
#[task(spawn = [foo, bar, baz])]
|
||||
fn foo(c: foo::Context) {
|
||||
let _: Result<(), ()> = c.spawn.foo();
|
||||
let _: Result<(), u32> = c.spawn.bar(0);
|
||||
let _: Result<(), (u32, u32)> = c.spawn.baz(0, 1);
|
||||
}
|
||||
|
||||
#[task]
|
||||
fn bar(_: bar::Context, _x: u32) {}
|
||||
|
||||
#[task]
|
||||
fn baz(_: baz::Context, _x: u32, _y: u32) {}
|
||||
|
||||
extern "C" {
|
||||
fn UART1();
|
||||
}
|
||||
};
|
||||
|
|
@ -5,9 +5,8 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::{debug, hprintln};
|
||||
use panic_semihosting as _;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
const APP: () = {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,11 @@
|
|||
#![no_main]
|
||||
#![no_std]
|
||||
|
||||
extern crate panic_semihosting;
|
||||
|
||||
use cortex_m_semihosting::debug;
|
||||
use rtfm::{Exclusive, Instant};
|
||||
use panic_semihosting as _;
|
||||
use rtfm::cyccnt::Instant;
|
||||
|
||||
#[rtfm::app(device = lm3s6965)]
|
||||
#[rtfm::app(device = lm3s6965, peripherals = true, monotonic = rtfm::cyccnt::CYCCNT)]
|
||||
const APP: () = {
|
||||
static mut SHARED: u32 = 0;
|
||||
|
||||
|
|
@ -43,7 +42,7 @@ const APP: () = {
|
|||
#[task(priority = 2, resources = [SHARED], schedule = [foo], spawn = [foo])]
|
||||
fn foo(c: foo::Context) {
|
||||
let _: Instant = c.scheduled;
|
||||
let _: Exclusive<u32> = c.resources.SHARED;
|
||||
let _: &mut u32 = c.resources.SHARED;
|
||||
let _: foo::Resources = c.resources;
|
||||
let _: foo::Schedule = c.schedule;
|
||||
let _: foo::Spawn = c.spawn;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue