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 <peter.bigot@nordicsemi.no>
This commit is contained in:
parent
dc1edb946f
commit
47cf5d295f
1 changed files with 16 additions and 4 deletions
|
@ -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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue