Skip to content

Commit 12c0e7f

Browse files
facchinmsoburi
authored andcommitted
zephyrCommon: improve delay* accurancy
experimental results here arduino#332 (comment) On boards with different clock speed, function call overhead etc. the results may vary but will likely be consistent, given that all the boards share CONFIG_SYS_CLOCK_TICKS_PER_SEC Co-authored-by: Martino Facchin <m.facchin@arduino.cc> Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 4dd64c6 commit 12c0e7f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

cores/arduino/zephyrCommon.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,15 @@ void noTone(pin_size_t pinNumber) {
343343
gpio_pin_set_dt(&arduino_pins[pinNumber], 0);
344344
}
345345

346-
void delay(unsigned long ms) {
346+
__attribute__((always_inline)) void delay(unsigned long ms) {
347347
k_sleep(K_MSEC(ms));
348348
}
349349

350-
void delayMicroseconds(unsigned int us) {
351-
k_busy_wait(us);
350+
__attribute__((always_inline)) void delayMicroseconds(unsigned int us) {
351+
if (us == 0) {
352+
return;
353+
}
354+
k_busy_wait(us - 1);
352355
}
353356

354357
unsigned long micros(void) {

0 commit comments

Comments
 (0)