summaryrefslogtreecommitdiff
path: root/tests/qemu/main.c
blob: 863ce9eebbdc55865bf267ef5ddc02c80383a32f (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
55
56
57
58
#include <libopencm3/cm3/nvic.h>
#include <libopencm3/cm3/systick.h>


/* LM3S Specifics, usart and RCC */
#include <libopencm3/lm3s/rcc.h>
#include <libopencm3/lm3s/usart.h>

static volatile uint32_t jiffies = 0u;

static void printbanner(void)
{
    char msg[] = "One second elapsed!\r\n";
    char *c = msg;
    while (*c != 0) {
        usart_send(USART0_BASE, (uint16_t )*c);
        c++;
    }
}

void sys_tick_handler(void)
{
    jiffies++;
}

static inline uint32_t systick_app_config(uint32_t n_ticks)
{
    /* constant from systick_set_reload -- as this returns something that's
     *      * not void, this is the only possible error condition */
    if (n_ticks & ~0x00FFFFFF) {
        return 1;
    }

    systick_set_reload(n_ticks);
    systick_set_clocksource(1);
    systick_interrupt_enable();
    systick_counter_enable();

    return 0;
}

#define HZ 1000

int main(void)
{
    uint32_t last_time = 0;
    rcc_clock_setup_in_xtal_8mhz_out_50mhz();
    systick_app_config(HZ);

    nvic_set_priority(NVIC_SYSTICK_IRQ, 0);
    jiffies = 0;
    while(1) {
        if (jiffies > HZ) {
            printbanner();
            jiffies = 0;
        }
    }
}