1
0
mirror of https://github.com/mist-devel/mist-firmware.git synced 2026-04-25 20:11:42 +00:00

Add separate timer functions to RAM/Flash, so the previous broken fw might be upgraded with this hack

This commit is contained in:
Gyorgy Szombathelyi
2023-12-14 16:05:05 +01:00
parent 2f1f42e6db
commit d8874d24a5
3 changed files with 20 additions and 4 deletions

View File

@@ -281,14 +281,28 @@ void Timer_Init(void) {
}
// 12 bits accuracy at 1ms = 4096 ms
RAMFUNC unsigned long GetTimer(unsigned long offset)
unsigned long GetTimer(unsigned long offset)
{
unsigned long systimer = (*AT91C_PITC_PIIR & AT91C_PITC_PICNT);
systimer += offset << 20;
return (systimer); // valid bits [31:20]
}
RAMFUNC unsigned long CheckTimer(unsigned long time)
unsigned long CheckTimer(unsigned long time)
{
unsigned long systimer = (*AT91C_PITC_PIIR & AT91C_PITC_PICNT);
time -= systimer;
return(time > (1UL << 31));
}
RAMFUNC unsigned long RAMGetTimer(unsigned long offset)
{
unsigned long systimer = (*AT91C_PITC_PIIR & AT91C_PITC_PICNT);
systimer += offset << 20;
return (systimer); // valid bits [31:20]
}
RAMFUNC unsigned long RAMCheckTimer(unsigned long time)
{
unsigned long systimer = (*AT91C_PITC_PIIR & AT91C_PITC_PICNT);
time -= systimer;

View File

@@ -109,6 +109,8 @@ unsigned long CheckButton(void);
void Timer_Init(void);
unsigned long GetTimer(unsigned long offset);
unsigned long CheckTimer(unsigned long t);
unsigned long RAMGetTimer(unsigned long offset);
unsigned long RAMCheckTimer(unsigned long t);
void WaitTimer(unsigned long time);
void TIMER_wait(unsigned long ms);

View File

@@ -284,10 +284,10 @@ unsigned long MMC_GetCapacity()
RAMFUNC static unsigned char MMC_WaitBusy(unsigned long timeout)
{
unsigned long timer = GetTimer(timeout);
unsigned long timer = RAMGetTimer(timeout);
while (1) {
if (SPI(0xFF) == 0xFF) return 1; // OK
if (CheckTimer(timer)) return 0; // timeout
if (RAMCheckTimer(timer)) return 0; // timeout
}
}