777d04daccbe4065de61a893b9034b623811c862
[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
8 void * systick_handler() {
9
10 //      *RANDOM_ADDR = (volatile uint32_t) 0x10101010 ;
11 //      uart_puts("TEST");
12 }
13
14 void systick_init() {
15
16         /* Enable the counter and enable the interrupt
17          * associated with it */
18         *STK_CTRL = (volatile uint32_t) 0x00000003;
19
20         /* The counter reload register here holds 
21          * 0x1000 -- that's 4096 clock cycles -- if 
22          * it is down to zero it is restores the value */
23         *STK_RELOAD = (volatile uint32_t) 0x00000400; 
24
25         /* Every time the counter counts down to zero
26          * a systick exception is asserted. Systick has
27          * exception number 15. in the vector table  */
28         ivt_set_gate(15, systick_handler, 0); 
29 }