Basic functionality for TM1637
[cortex-from-scratch] / systick.c
1 #include <stdbool.h>
2 #include <stddef.h>
3 #include <stdint.h>
4
5 #include <sys/robsys.h>
6 #include <sys/mmap.h>
7
8 #include <lib/regfunc.h> // TODO
9
10 struct interrupt_frame {
11
12         uint32_t r0; // N-32
13         uint32_t r1;
14         uint32_t r2;
15         uint32_t r3;
16         uint32_t r12;
17         uint32_t lr;
18         uint32_t pc;
19         uint32_t psr; // N-4
20 };
21
22 //__attribute__ ((interrupt))
23 void * systick_handler(/* struct interrupt_frame * frame */) {
24
25 //      uint32_t volatile status;
26         //uart_puts("TICKING\n");
27 //      for(;;);
28 }
29
30
31 void systick_init() {
32
33         /* Enable the counter and enable the interrupt
34          * associated with it */
35         *STK_CTRL = (volatile uint32_t) 0x00000003;
36
37         /* The counter reload register here holds 
38          * 0x1000 -- that's 4096 clock cycles -- if 
39          * it is down to zero it is restores the value */
40         *STK_RELOAD = (volatile uint32_t) 0x00400000; 
41
42         /* Every time the counter counts down to zero
43          * a systick exception is asserted. Systick has
44          * exception number 15. in the vector table  */
45         ivt_set_gate(15, systick_handler, 0); 
46 }