mirror of
https://github.com/rtic-rs/rtic.git
synced 2024-12-25 03:19:34 +01:00
8e636f0d12
Some beginners are confused about the "extern" section, so I added an explanation comment to all examples. Furthermore, using the UARTx interrupts when UART is actually being used in the same example may be confusing, so I changed them all to SSI0/QEI0.
61 lines
1.7 KiB
Rust
61 lines
1.7 KiB
Rust
//! examples/types.rs
|
|
|
|
#![deny(unsafe_code)]
|
|
#![deny(warnings)]
|
|
#![no_main]
|
|
#![no_std]
|
|
|
|
use cortex_m_semihosting::debug;
|
|
use panic_semihosting as _;
|
|
use rtic::cyccnt;
|
|
|
|
#[rtic::app(device = lm3s6965, peripherals = true, monotonic = rtic::cyccnt::CYCCNT)]
|
|
const APP: () = {
|
|
struct Resources {
|
|
#[init(0)]
|
|
shared: u32,
|
|
}
|
|
|
|
#[init(schedule = [foo], spawn = [foo])]
|
|
fn init(cx: init::Context) {
|
|
let _: cyccnt::Instant = cx.start;
|
|
let _: rtic::Peripherals = cx.core;
|
|
let _: lm3s6965::Peripherals = cx.device;
|
|
let _: init::Schedule = cx.schedule;
|
|
let _: init::Spawn = cx.spawn;
|
|
|
|
debug::exit(debug::EXIT_SUCCESS);
|
|
}
|
|
|
|
#[idle(schedule = [foo], spawn = [foo])]
|
|
fn idle(cx: idle::Context) -> ! {
|
|
let _: idle::Schedule = cx.schedule;
|
|
let _: idle::Spawn = cx.spawn;
|
|
|
|
loop {}
|
|
}
|
|
|
|
#[task(binds = UART0, resources = [shared], schedule = [foo], spawn = [foo])]
|
|
fn uart0(cx: uart0::Context) {
|
|
let _: cyccnt::Instant = cx.start;
|
|
let _: resources::shared = cx.resources.shared;
|
|
let _: uart0::Schedule = cx.schedule;
|
|
let _: uart0::Spawn = cx.spawn;
|
|
}
|
|
|
|
#[task(priority = 2, resources = [shared], schedule = [foo], spawn = [foo])]
|
|
fn foo(cx: foo::Context) {
|
|
let _: cyccnt::Instant = cx.scheduled;
|
|
let _: &mut u32 = cx.resources.shared;
|
|
let _: foo::Resources = cx.resources;
|
|
let _: foo::Schedule = cx.schedule;
|
|
let _: foo::Spawn = cx.spawn;
|
|
}
|
|
|
|
// RTIC requires that unused interrupts are declared in an extern block when
|
|
// using software tasks; these free interrupts will be used to dispatch the
|
|
// software tasks.
|
|
extern "C" {
|
|
fn SSI0();
|
|
}
|
|
};
|