Skip to content

Commit f5b6505

Browse files
KurtEsoburi
authored andcommitted
Fix micros() for nano without breaking giga
The rollover fix for the giga used the 64 bit timer instead of 32 bits. The nano does not have a 64 bit timer, so you need to use the 32 bit instead. So I know check to see if the processor supports 64 bits if so use it else fall back to 32 bit. Note: This branch doesn't include support for Arduino Giga, but we'll include it as it's a reasonable solution for preventing timer overflows. Co-Authored-by: Kurt Eckhardt <kurte@rockisland.com> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 78bcf6a commit f5b6505

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,11 @@ void delayMicroseconds(unsigned int us) {
347347
}
348348

349349
unsigned long micros(void) {
350+
#ifdef CONFIG_TIMER_HAS_64BIT_CYCLE_COUNTER
351+
return k_cyc_to_us_floor32(k_cycle_get_64());
352+
#else
350353
return k_cyc_to_us_floor32(k_cycle_get_32());
354+
#endif
351355
}
352356

353357
unsigned long millis(void) {

0 commit comments

Comments
 (0)