aboutsummaryrefslogtreecommitdiffstats
path: root/examples/test-systick.cpp
blob: c7b55298c99efe80650d7e47cf6cac543253cdfc (plain)
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
// Tests the SysTick enable/disable functions
//
#include "wirish.h"
#include "systick.h"

#define LED_PIN BOARD_LED_PIN
#define PWM_PIN 2
#define BUT     BOARD_BUTTON_PIN

void setup() {
    /* Set up the LED to blink  */
    pinMode(LED_PIN, OUTPUT);
    pinMode(BUT, INPUT);
}

bool disable = true;
long time = 0;

void loop() {
    volatile int i = 0;
    toggleLED();

    // An artificial delay
    for(i = 0; i < 150000; i++)
        ;

    if(isButtonPressed()) {
        if (disable) {
            systick_disable();
            SerialUSB.println("Disabling SysTick");
        } else {
            SerialUSB.println("Re-enabling SysTick");
            systick_resume();
        }
        disable = !disable;
    }

    SerialUSB.println(millis());
}

// Force init to be called *first*, i.e. before static object allocation.
// Otherwise, statically allocated object that need libmaple may fail.
__attribute__((constructor)) void premain() {
    init();
}

int main(void) {
    setup();

    while (1) {
        loop();
    }
    return 0;
}