Small chrono function refactoring

This commit is contained in:
Aurora 2016-05-13 05:01:32 +02:00
parent ffee64c67f
commit 050f433046
3 changed files with 22 additions and 19 deletions

View File

@ -32,9 +32,8 @@ void main(void)
updatedSys, updatedSys,
needConfig, needConfig,
newConfig, newConfig,
emuHeader; emuHeader,
chronoStarted = 0;
u64 chronoStarted = 0;
//Detect the console being used //Detect the console being used
console = PDN_MPCORE_CFG == 7; console = PDN_MPCORE_CFG == 7;
@ -75,9 +74,9 @@ void main(void)
//Zero the last booted FIRM flag //Zero the last booted FIRM flag
CFG_BOOTENV = 0; CFG_BOOTENV = 0;
chronoStarted = chrono();
while(chrono() - chronoStarted < 2 * TICKS_PER_SEC); //Wait for 2s
chronoStarted = 1; chronoStarted = 1;
chrono(0);
chrono(2);
//Update pressed buttons //Update pressed buttons
pressed = HID_PAD; pressed = HID_PAD;
@ -152,7 +151,10 @@ void main(void)
//If screens are inited or the corresponding option is set, load splash screen //If screens are inited or the corresponding option is set, load splash screen
if((PDN_GPU_CNT != 1 || CONFIG(7)) && loadSplash()) if((PDN_GPU_CNT != 1 || CONFIG(7)) && loadSplash())
chronoStarted = chrono(); {
chronoStarted = 2;
chrono(0);
}
//If R is pressed, boot the non-updated NAND with the FIRM of the opposite one //If R is pressed, boot the non-updated NAND with the FIRM of the opposite one
if(pressed & BUTTON_R1) if(pressed & BUTTON_R1)
@ -218,7 +220,7 @@ void main(void)
if(chronoStarted) if(chronoStarted)
{ {
while(chronoStarted > 1 && chrono() - chronoStarted < 3 * TICKS_PER_SEC); if(chronoStarted == 2) chrono(3);
stopChrono(); stopChrono();
} }

View File

@ -40,7 +40,7 @@ void mcuReboot(void)
} }
//TODO: add support for TIMER IRQ //TODO: add support for TIMER IRQ
static void startChrono(u64 initialTicks) static inline void startChrono(u64 initialTicks)
{ {
//Based on a NATIVE_FIRM disassembly //Based on a NATIVE_FIRM disassembly
@ -53,21 +53,22 @@ static void startChrono(u64 initialTicks)
for(u32 i = 1; i < 4; i++) *(vu16 *)(0x10003002 + 4 * i) = 0x84; //Count-up; enabled for(u32 i = 1; i < 4; i++) *(vu16 *)(0x10003002 + 4 * i) = 0x84; //Count-up; enabled
} }
u64 chrono(void) void chrono(u32 seconds)
{ {
static u32 chronoStarted = 0; static u64 startingTicks = 0;
if(!chronoStarted) if(!startingTicks) startChrono(0);
u64 res;
do
{ {
startChrono(0); res = 0;
chronoStarted++;
}
u64 res = 0;
for(u32 i = 0; i < 4; i++) res |= *(vu16 *)(0x10003000 + 4 * i) << (16 * i); for(u32 i = 0; i < 4; i++) res |= *(vu16 *)(0x10003000 + 4 * i) << (16 * i);
}
while(res - startingTicks < seconds * TICKS_PER_SEC);
return res; if(!seconds) startingTicks = res;
} }
void stopChrono(void) void stopChrono(void)

View File

@ -11,5 +11,5 @@ void mcuReboot(void);
#define TICKS_PER_SEC 67027964ULL #define TICKS_PER_SEC 67027964ULL
u64 chrono(void); void chrono(u32 seconds);
void stopChrono(void); void stopChrono(void);