From 06c1e2f9b47b5bc9de049e1e1edfed27d8dd2c58 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 16 Dec 2018 19:34:16 +0100 Subject: note that the timer queue is not supported on ARMv6-M --- ci/script.sh | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'ci') diff --git a/ci/script.sh b/ci/script.sh index 20394d5..0244c58 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -12,11 +12,17 @@ main() { esac cargo check --target $T - cargo check --features timer-queue --target $T + if [ $TARGET != thumbv6m-none-eabi ]; then + cargo check --features timer-queue --target $T + fi - if [ $TRAVIS_RUST_VERSION = beta ]; then + if [ $TRAVIS_RUST_VERSION != nightly ]; then rm -f .cargo/config - cargo doc --features timer-queue + if [ $TARGET != thumbv6m-none-eabi ]; then + cargo doc --features timer-queue + else + cargo doc + fi ( cd book && mdbook build ) local td=$(mktemp -d) @@ -33,7 +39,9 @@ main() { fi cargo check --target $T --examples - cargo check --features timer-queue --target $T --examples + if [ $TARGET != thumbv6m-none-eabi ]; then + cargo check --features timer-queue --target $T --examples + fi # run-pass tests case $T in @@ -76,11 +84,13 @@ main() { diff -u ci/expected/$ex.run - fi - cargo run --features timer-queue --example $ex --target $T | \ - diff -u ci/expected/$ex.run - + if [ $TARGET != thumbv6m-none-eabi ]; then + cargo run --features timer-queue --example $ex --target $T | \ + diff -u ci/expected/$ex.run - - cargo run --features timer-queue --example $ex --target $T --release | \ - diff -u ci/expected/$ex.run - + cargo run --features timer-queue --example $ex --target $T --release | \ + diff -u ci/expected/$ex.run - + fi done esac } -- cgit v1.2.3 From 34e74f4bb36b0866be94c9bfdb41c11270b448a7 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 16 Dec 2018 20:56:57 +0100 Subject: book: add an example of conditional compilation of resources and tasks --- book/src/by-example/tips.md | 14 ++++++++++++ ci/script.sh | 2 ++ examples/cfg.rs | 54 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 examples/cfg.rs (limited to 'ci') diff --git a/book/src/by-example/tips.md b/book/src/by-example/tips.md index c163328..5057c80 100644 --- a/book/src/by-example/tips.md +++ b/book/src/by-example/tips.md @@ -20,6 +20,20 @@ rewrite code. If you consistently use `lock`s to access the data behind shared resources then your code will continue to compile when you change the priority of tasks. +## Conditional compilation + +You can use conditional compilation (`#[cfg]`) on resources (`static [mut]` +items) and tasks (`fn` items). The effect of using `#[cfg]` attributes is that +the resource / task will *not* be injected into the prelude of tasks that use +them (see `resources`, `spawn` and `schedule`) if the condition doesn't hold. + +The example below logs a message whenever the `foo` task is spawned, but only if +the program has been compiled using the `dev` profile. + +``` rust +{{#include ../../../examples/cfg.rs}} +``` + ## Running tasks from RAM The main goal of moving the specification of RTFM applications to attributes in diff --git a/ci/script.sh b/ci/script.sh index 0244c58..27229a5 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -68,6 +68,8 @@ main() { generics ramfunc + + cfg ) for ex in ${exs[@]}; do diff --git a/examples/cfg.rs b/examples/cfg.rs new file mode 100644 index 0000000..3f4ca90 --- /dev/null +++ b/examples/cfg.rs @@ -0,0 +1,54 @@ +//! examples/cfg.rs + +#![deny(unsafe_code)] +#![deny(warnings)] +#![no_main] +#![no_std] + +extern crate panic_semihosting; + +#[cfg(debug_assertions)] +use cortex_m_semihosting::hprintln; +use rtfm::app; + +#[app(device = lm3s6965)] +const APP: () = { + #[cfg(debug_assertions)] // <- `true` when using the `dev` profile + static mut COUNT: u32 = 0; + + #[init] + fn init() { + // .. + } + + #[task(priority = 3, resources = [COUNT], spawn = [log])] + fn foo() { + #[cfg(debug_assertions)] + { + *resources.COUNT += 1; + + spawn.log(*resources.COUNT).ok(); + } + + // this wouldn't compile in `release` mode + // *resources.COUNT += 1; + + // .. + } + + #[cfg(debug_assertions)] + #[task] + fn log(n: u32) { + hprintln!( + "foo has been called {} time{}", + n, + if n == 1 { "" } else { "s" } + ) + .ok(); + } + + extern "C" { + fn UART0(); + fn UART1(); + } +}; -- cgit v1.2.3 From 1643dd0a57bb4c813da8e79916621ae59ad3d19b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 16 Dec 2018 22:02:06 +0100 Subject: actually, don't check the output of the cfg example --- ci/script.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'ci') diff --git a/ci/script.sh b/ci/script.sh index 27229a5..0244c58 100644 --- a/ci/script.sh +++ b/ci/script.sh @@ -68,8 +68,6 @@ main() { generics ramfunc - - cfg ) for ex in ${exs[@]}; do -- cgit v1.2.3