2018-12-16 20:56:57 +01:00
|
|
|
//! examples/cfg.rs
|
|
|
|
|
|
|
|
#![deny(unsafe_code)]
|
|
|
|
#![deny(warnings)]
|
|
|
|
#![no_main]
|
|
|
|
#![no_std]
|
|
|
|
|
|
|
|
extern crate panic_semihosting;
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
use cortex_m_semihosting::hprintln;
|
|
|
|
|
2019-04-21 20:10:40 +02:00
|
|
|
#[rtfm::app(device = lm3s6965)]
|
2018-12-16 20:56:57 +01:00
|
|
|
const APP: () = {
|
|
|
|
#[cfg(debug_assertions)] // <- `true` when using the `dev` profile
|
|
|
|
static mut COUNT: u32 = 0;
|
|
|
|
|
|
|
|
#[init]
|
2019-04-21 20:10:40 +02:00
|
|
|
fn init(_: init::Context) {
|
2018-12-16 20:56:57 +01:00
|
|
|
// ..
|
|
|
|
}
|
|
|
|
|
|
|
|
#[task(priority = 3, resources = [COUNT], spawn = [log])]
|
2019-04-21 20:10:40 +02:00
|
|
|
fn foo(c: foo::Context) {
|
2018-12-16 20:56:57 +01:00
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
{
|
2019-04-21 20:10:40 +02:00
|
|
|
*c.resources.COUNT += 1;
|
2018-12-16 20:56:57 +01:00
|
|
|
|
2019-04-21 20:10:40 +02:00
|
|
|
c.spawn.log(*c.resources.COUNT).ok();
|
2018-12-16 20:56:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// this wouldn't compile in `release` mode
|
|
|
|
// *resources.COUNT += 1;
|
|
|
|
|
|
|
|
// ..
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
#[task]
|
2019-04-21 20:10:40 +02:00
|
|
|
fn log(_: log::Context, n: u32) {
|
2018-12-16 20:56:57 +01:00
|
|
|
hprintln!(
|
|
|
|
"foo has been called {} time{}",
|
|
|
|
n,
|
|
|
|
if n == 1 { "" } else { "s" }
|
|
|
|
)
|
|
|
|
.ok();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
fn UART0();
|
|
|
|
fn UART1();
|
|
|
|
}
|
|
|
|
};
|