1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-01-13 15:17:43 +00:00

hardware.c: add InitRTTC() and GetRTTC() functions

This commit is contained in:
Gyorgy Szombathelyi 2021-07-10 23:09:46 +02:00
parent 8efbe7034b
commit e400ed30df
4 changed files with 15 additions and 6 deletions

View File

@ -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;
}

View File

@ -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);

2
osd.c
View File

@ -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);

View File

@ -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);
}