diff --git a/hardware.c b/hardware.c index 37cc1b6..ef962bb 100644 --- a/hardware.c +++ b/hardware.c @@ -315,4 +315,9 @@ char mmc_write_protected() { void MCUReset() { *AT91C_RSTC_RCR = 0xA5 << 24 | AT91C_RSTC_PERRST | AT91C_RSTC_PROCRST | AT91C_RSTC_EXTRST; } + +void InitRTTC() { + // reprogram the realtime timer to run at 1Khz + AT91C_BASE_RTTC->RTTC_RTMR = 0x8000 / 1000; +} \ No newline at end of file diff --git a/hardware.h b/hardware.h index b54ba3b..c646ec4 100644 --- a/hardware.h +++ b/hardware.h @@ -76,6 +76,10 @@ void USART_Poll(void); void MCUReset(); +void InitRTTC(); + +int inline GetRTTC() {return (int)(AT91C_BASE_RTTC->RTTC_RTVR);} + #ifdef FPGA3 // the MiST has the user inout on the arm controller void EnableIO(void); diff --git a/osd.c b/osd.c index 97b42ae..336023f 100644 --- a/osd.c +++ b/osd.c @@ -89,7 +89,7 @@ static int quickrand() #ifndef MIST int r=*(volatile unsigned long *)0x80000c; #else - int r = (int)(AT91C_BASE_RTTC->RTTC_RTVR); + int r = GetRTTC(); #endif r^=(prev&0xc75a)<<4; r^=(prev&0x5a7c)>>(prev&7); diff --git a/usb/timer.c b/usb/timer.c index 32f6fa1..a67d1d4 100644 --- a/usb/timer.c +++ b/usb/timer.c @@ -1,20 +1,20 @@ #include "timer.h" -#include "AT91SAM7S256.h" +#include "hardware.h" // this is a 32 bit counter which overflows after 2^32 milliseconds // -> after 46 days void timer_init() { // reprogram the realtime timer to run at 1Khz - AT91C_BASE_RTTC->RTTC_RTMR = 0x8000 / 1000; + InitRTTC(); } msec_t timer_get_msec() { - return AT91C_BASE_RTTC->RTTC_RTVR; + return GetRTTC(); } void timer_delay_msec(msec_t t) { - msec_t now = AT91C_BASE_RTTC->RTTC_RTVR; + msec_t now = GetRTTC(); - while(AT91C_BASE_RTTC->RTTC_RTVR - now < t); + while(GetRTTC() - now < t); }