aboutsummaryrefslogtreecommitdiff
path: root/ui/local-cfg-task-local-err.rs
blob: d4752edf5d2847b326b866fb01f529cd2a6a4836 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//! 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();
    }
}