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