From c542a4c56faf5d3d3926a6832393cad7d70a8c8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20G=C5=82=C4=85bek?= Date: Tue, 13 Aug 2019 11:55:28 +0200 Subject: [PATCH] drivers: gpio_nrfx: Correct the way the callbacks are fired MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add additional masking of the pins with fired callback triggers against the currently enabled callbacks, in order to not call handlers for callbacks that got disabled in some other callback handlers that were called in the same ISR execution. Signed-off-by: Andrzej Głąbek --- drivers/gpio/gpio_nrfx.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpio_nrfx.c b/drivers/gpio/gpio_nrfx.c index f2ceb2e7534..5050ee9c284 100644 --- a/drivers/gpio/gpio_nrfx.c +++ b/drivers/gpio/gpio_nrfx.c @@ -400,7 +400,25 @@ static u32_t check_level_trigger_pins(struct device *port) static inline void fire_callbacks(struct device *port, u32_t pins) { - gpio_fire_callbacks(&get_port_data(port)->callbacks, port, pins); + struct gpio_nrfx_data *data = get_port_data(port); + sys_slist_t *list = &data->callbacks; + struct gpio_callback *cb, *tmp; + + /* Instead of calling the common gpio_fire_callbacks() function, + * iterate the list of callbacks locally, to be able to perform + * additional masking of the pins and to call handlers only for + * the currently enabled callbacks. + */ + SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cb, tmp, node) { + /* Check currently enabled callbacks (data->int_en) in each + * iteration, as some callbacks may get disabled also in any + * of the handlers called here. + */ + if ((cb->pin_mask & pins) & data->int_en) { + __ASSERT(cb->handler, "No callback handler!"); + cb->handler(port, cb, pins); + } + } } #ifdef CONFIG_GPIO_NRF_P0