aboutsummaryrefslogtreecommitdiff
path: root/examples/systic.rs
blob: f9aff30b762824a646774745a265c1536ddedae5 (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
//! examples/systic.rs

#![deny(unsafe_code)]
#![deny(warnings)]
#![no_main]
#![no_std]

use panic_semihosting as _;

#[rtic::app(device = lm3s6965)]
mod app {
    use cortex_m_semihosting::{debug, hprintln};

    #[resources]
    struct Resources {
        #[init(0)]
        #[task_local]
        counter: i32,
    }

    #[init]
    fn init(cx: init::Context) -> init::LateResources {
        let mut syst = cx.core.SYST;
        syst.set_reload(100000);
        syst.enable_interrupt();
        syst.enable_counter();

        hprintln!("init").unwrap();
        init::LateResources {}
    }

    #[idle]
    fn idle(_: idle::Context) -> ! {
        hprintln!("idle").unwrap();
        loop {
            cortex_m::asm::nop();
        }
    }

    #[task(binds = SysTick, resources = [counter])]
    fn systic(cx: systic::Context) {
        let counter = cx.resources.counter;

        *counter += 1;
        hprintln!("SysTick #{}", counter).unwrap();
        if *counter == 10 {
            debug::exit(debug::EXIT_SUCCESS);
        }
    }
}