From 47cf5d295f4360870574c0468ee5c57e10bfcf9a Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Sun, 9 Feb 2020 07:03:28 -0600 Subject: [PATCH] tests: drivers: gpio_basic_api: fix deprecated API level test 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 --- .../gpio/gpio_basic_api/src/test_deprecated.c | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/drivers/gpio/gpio_basic_api/src/test_deprecated.c b/tests/drivers/gpio/gpio_basic_api/src/test_deprecated.c index e10f025ef32886..c237dbd7f09ed6 100644 --- a/tests/drivers/gpio/gpio_basic_api/src/test_deprecated.c +++ b/tests/drivers/gpio/gpio_basic_api/src/test_deprecated.c @@ -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); } } @@ -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; @@ -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));