X-Git-Url: https://robinkrens.nl/gitweb/?a=blobdiff_plain;f=systick.c;h=05f515fde9be2b0f00ae4964ccc0319fc330095e;hb=d98e5505c9433565ebb71fa6a843997ea0e0cda6;hp=b9c87568f62f9a3563d6a6f5f6be491875ec3f58;hpb=2ad654f037bae2ec8f0223179c4b96c23308c34d;p=cortex-from-scratch diff --git a/systick.c b/systick.c index b9c8756..05f515f 100644 --- a/systick.c +++ b/systick.c @@ -1,28 +1,53 @@ #include #include #include -#include -#include +#include +#include -void * systick_handler() { +#include +#include - *RANDOM_ADDR = (volatile uint32_t) 0x10101010 ; -} +struct interrupt_frame { -void systick_init() { + uint32_t r0; // N-32 + uint32_t r1; + uint32_t r2; + uint32_t r3; + uint32_t r12; + uint32_t lr; + uint32_t pc; + uint32_t psr; // N-4 +}; + +//__attribute__ ((interrupt)) +void * systick_handler(/* struct interrupt_frame * frame */) { + +// cputs("TICKING\n"); +// for(;;); +} - /* Enable the counter and enable the interrupt - * associated with it */ - *STK_CTRL = (volatile uint32_t) 0x00000003; - /* The counter reload register here holds - * 0x1000 -- that's 4096 clock cycles -- if - * it is down to zero it is restores the value */ - *STK_RELOAD = (volatile uint32_t) 0x00000400; +void systick_init() { /* Every time the counter counts down to zero * a systick exception is asserted. Systick has * exception number 15. in the vector table */ ivt_set_gate(15, systick_handler, 0); + + /* Get calibration and set this to 1 sec + * !Most boards have a 1 ms or 10 ms + * calibration value */ + int calib = (*STK_CALIB << 0) * 500; + + /* The counter reload registers counts down to zero + * and then it is restores the value */ + rwrite(STK_RELOAD, calib); + + /* Enable the counter and enable the interrupt + * associated with it */ + rsetbit(STK_CTRL, 0); + rsetbit(STK_CTRL, 1); + + }