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