Skip to content

Commit a807227

Browse files
soburiDhruvaG2000
authored andcommitted
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 <[email protected]>
1 parent f5dbe52 commit a807227

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
@@ -418,13 +418,13 @@ unsigned long pulseIn(pin_size_t pinNumber, uint8_t state, unsigned long timeout
418418
int64_t start, end, delta = 0;
419419
const struct gpio_dt_spec *spec = &arduino_pins[pinNumber];
420420

421-
k_timer_init(&timer, NULL, NULL);
422-
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
423-
424421
if (!gpio_is_ready_dt(spec)) {
425-
goto cleanup;
422+
return 0;
426423
}
427424

425+
k_timer_init(&timer, NULL, NULL);
426+
k_timer_start(&timer, K_MSEC(timeout), K_NO_WAIT);
427+
428428
while(gpio_pin_get_dt(spec) == state && k_timer_status_get(&timer) == 0);
429429
if (k_timer_status_get(&timer) > 0) {
430430
goto cleanup;

0 commit comments

Comments
 (0)