added a ticks delta function, handles overflow situations much better

This commit is contained in:
iceman1001 2024-02-20 06:51:29 +01:00
parent 392c251c81
commit 6edd1b9de2
2 changed files with 10 additions and 0 deletions

View file

@ -309,6 +309,14 @@ uint32_t GetTicks(void) {
return (hi << 16) | lo;
}
uint32_t RAMFUNC GetTicksDelta(uint32_t start) {
uint32_t stop = GetTicks();
if (stop >= start) {
return stop - start;
}
return (UINT32_MAX - start) + stop;
}
// Wait - Spindelay in ticks.
// if called with a high number, this will trigger the WDT...
void WaitTicks(uint32_t ticks) {
@ -328,3 +336,4 @@ void StopTicks(void) {
AT91C_BASE_TC0->TC_CCR = AT91C_TC_CLKDIS;
AT91C_BASE_TC1->TC_CCR = AT91C_TC_CLKDIS;
}

View file

@ -28,6 +28,7 @@
void StartTicks(void);
uint32_t GetTicks(void);
uint32_t RAMFUNC GetTicksDelta(uint32_t start);
void WaitUS(uint32_t us);
void WaitTicks(uint32_t ticks);
void StartCountUS(void);