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:
parent
416df1c50d
commit
1c429228d5
1 changed files with 10 additions and 3 deletions
|
@ -56,6 +56,7 @@
|
||||||
typedef void (*gpioIrqFn)(void);
|
typedef void (*gpioIrqFn)(void);
|
||||||
|
|
||||||
gpioIrqFn gpio_funcs[4] = { NULL, NULL, NULL, NULL};
|
gpioIrqFn gpio_funcs[4] = { NULL, NULL, NULL, NULL};
|
||||||
|
uint32_t frequency = 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the the timer frequency in Hz.
|
* Get the the timer frequency in Hz.
|
||||||
|
@ -164,12 +165,18 @@ class TockHal : public RadioLibHal {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long millis() override {
|
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);
|
alarm_internal_read(&now);
|
||||||
|
|
||||||
return (now / frequency) / 1000;
|
ms = now / (frequency / 1000);
|
||||||
|
|
||||||
|
return ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long micros() override {
|
unsigned long micros() override {
|
||||||
|
|
Loading…
Add table
Reference in a new issue