uart small ping pong receive, update of register functions
[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
20 /* void * systick_handler() {
21
22 //      *RANDOM_ADDR = (volatile uint32_t) 0x10101010 ;
23 //      uart_puts("TEST");
24 } */
25
26 __attribute__ ((interrupt))
27 void * systick_handler(struct interrupt_frame * frame) {
28
29         uart_puts("TICKING\n");
30 //      addrtohex((uint32_t) 0x12345678);
31         //      for(;;);
32 }
33
34
35 void systick_init() {
36
37         /* Enable the counter and enable the interrupt
38          * associated with it */
39         *STK_CTRL = (volatile uint32_t) 0x00000003;
40
41         /* The counter reload register here holds 
42          * 0x1000 -- that's 4096 clock cycles -- if 
43          * it is down to zero it is restores the value */
44         *STK_RELOAD = (volatile uint32_t) 0x00000400; 
45
46         /* Every time the counter counts down to zero
47          * a systick exception is asserted. Systick has
48          * exception number 15. in the vector table  */
49         ivt_set_gate(15, systick_handler, 0); 
50 }