Skip to content

Commit

Permalink
tests: drivers: gpio_basic_api: fix deprecated API level test
Browse files Browse the repository at this point in the history
Some boards don't support level interrupts; respect their rejection of
the configuration.

Also correct the code intended to disable the interrupt from within
the callback when level triggers are tested.  Note that the legacy
call emulation does not work: it's necessary to add a flag that causes
the interrupt to be disabled.

Also improve a diagnostic and fix the exit path for a failure detected
before the callback was installed.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
  • Loading branch information
pabigot authored and jhedberg committed Feb 12, 2020
1 parent dc1edb9 commit 47cf5d2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions tests/drivers/gpio/gpio_basic_api/src/test_deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ static void callback(struct device *dev,
}
if (cb_cnt >= MAX_INT_CNT) {
gpio_pin_write(dev, PIN_OUT, dd->aux);
gpio_pin_enable_callback(dev, PIN_IN);

/* NB: The legacy idiom for disabling interrupts is to
* pass GPIO_DIR_IN without any interrupt-related
* flags. In the new API this leaves the interrupt
* configuration of the pin unchanged, which causes
* level interrupts to repeat forever. To prevent hangs
* it's necessary to explicitly disable the interrupt.
*/
gpio_pin_configure(dev, PIN_IN, GPIO_DIR_IN
| GPIO_INT_DISABLE);
}
}

Expand Down Expand Up @@ -67,9 +76,12 @@ static int test_callback(gpio_flags_t int_flags)
GPIO_DIR_IN | GPIO_INT
| GPIO_INT_DEBOUNCE
| int_flags);
if (rc != 0) {
if (rc == -ENOTSUP) {
TC_PRINT("interrupt configuration not supported\n");
return TC_PASS;
} else if (rc != 0) {
TC_ERROR("config PIN_IN fail: %d\n", rc);
goto err_exit;
return TC_FAIL;
}

drv_data->mode = int_flags;
Expand All @@ -90,7 +102,7 @@ static int test_callback(gpio_flags_t int_flags)
TC_PRINT("Mode %x not supported\n", int_flags);
goto pass_exit;
} else if (rc != 0) {
TC_ERROR("config PIN_IN interrupt fail: %d\n", rc);
TC_ERROR("enable PIN_IN interrupt fail: %d\n", rc);
goto err_exit;
}
k_sleep(K_MSEC(100));
Expand Down

0 comments on commit 47cf5d2

Please sign in to comment.