1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-14 20:10:18 +03:00

Implement Stopwatch (#12623)

* Implement stopwatch to measure time periods

* Add float version of stopwatchGetMicros()
This commit is contained in:
Jan Post 2023-04-07 02:16:43 +02:00 committed by GitHub
parent 29ef811fa2
commit 2792d518d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 128 additions and 0 deletions

View file

@ -46,6 +46,7 @@
// cycles per microsecond
static uint32_t usTicks = 0;
static float usTicksInv = 0.0f;
// current uptime for 1kHz systick timer. will rollover after 49 days. hopefully we won't care.
static volatile uint32_t sysTickUptime = 0;
static volatile uint32_t sysTickValStamp = 0;
@ -67,6 +68,7 @@ void cycleCounterInit(void)
cpuClockFrequency = clocks.SYSCLK_Frequency;
#endif
usTicks = cpuClockFrequency / 1000000;
usTicksInv = 1e6f / cpuClockFrequency;
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
@ -162,6 +164,11 @@ int32_t clockCyclesToMicros(int32_t clockCycles)
return clockCycles / usTicks;
}
float clockCyclesToMicrosf(int32_t clockCycles)
{
return clockCycles * usTicksInv;
}
// Note that this conversion is signed as this is used for periods rather than absolute timestamps
int32_t clockCyclesTo10thMicros(int32_t clockCycles)
{