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:
parent
29ef811fa2
commit
2792d518d1
5 changed files with 128 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue