Skip to content

Commit 76c6264

Browse files
committed
zephyrCommon: Immediately terminate pulseIn if gpio not ready
If gpio is not initialized, the pulseIn function will terminate without running the timer. Signed-off-by: TOKITA Hiroshi <tokita.hiroshi@gmail.com>
1 parent 3683c77 commit 76c6264

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -439,13 +439,13 @@ unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout
439439
int64_t start, end, delta = 0;
440440
const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
441441

442-
k_timer_init(&timer, NULL, NULL);
443-
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
444-
445442
if (!gpio_is_ready_dt(spec)) {
446-
goto cleanup;
443+
return 0;
447444
}
448445

446+
k_timer_init(&timer, NULL, NULL);
447+
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
448+
449449
while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0);
450450
if (k_timer_status_get(&timer) > 0) {
451451
goto cleanup;

0 commit comments

Comments
 (0)