NonArduino: Tock: Don't read the frequency every time

To speed up the operation of obtaining the current time in milliseconds
let's cache the frequency.

Signed-off-by: Alistair Francis <alistair@alistair23.me>
This commit is contained in:
Alistair Francis 2024-07-02 20:18:13 +10:00
parent 416df1c50d
commit 1c429228d5

View file

@ -56,6 +56,7 @@
typedef void (*gpioIrqFn)(void);
gpioIrqFn gpio_funcs[4] = { NULL, NULL, NULL, NULL};
uint32_t frequency = 0;
/*
* Get the the timer frequency in Hz.
@ -164,12 +165,18 @@ class TockHal : public RadioLibHal {
}
unsigned long millis() override {
uint32_t frequency, now;
uint32_t now;
unsigned long ms;
if (frequency == 0) {
alarm_internal_frequency(&frequency);
}
alarm_internal_frequency(&frequency);
alarm_internal_read(&now);
return (now / frequency) / 1000;
ms = now / (frequency / 1000);
return ms;
}
unsigned long micros() override {