Skip to content

Commit

Permalink
drivers: gpio_mcux_igpio: fix code disabling the interrupt
Browse files Browse the repository at this point in the history
When disabling the interrupt current implementation of the
gpio_pin_interrupt_configure function will first reconfigure the
interrupt to be active on gpio low level.
Since the pin interrupt is enabled if the gpio pin level happens
to be low at the time the interrupt will trigger immediately.
Rewrite the function to disable the interrupt in a safe manner.

Signed-off-by: Frank Li <lgl88911@163.com>
  • Loading branch information
lgl88911 authored and MaureenHelm committed Apr 3, 2020
1 parent 71eb56a commit 007aa03
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions drivers/gpio/gpio_mcux_igpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ static int mcux_igpio_pin_interrupt_configure(struct device *dev,
u8_t icr;
int shift;

if (mode == GPIO_INT_MODE_DISABLED) {
key = irq_lock();

WRITE_BIT(base->IMR, pin, 0);
WRITE_BIT(data->pin_callback_enables, pin, 0);

irq_unlock(key);

return 0;
}

if ((mode == GPIO_INT_MODE_EDGE) && (trig == GPIO_INT_TRIG_LOW)) {
icr = 3;
} else if ((mode == GPIO_INT_MODE_EDGE) &&
Expand All @@ -148,10 +159,9 @@ static int mcux_igpio_pin_interrupt_configure(struct device *dev,
key = irq_lock();

WRITE_BIT(base->EDGE_SEL, pin, trig == GPIO_INT_TRIG_BOTH);
WRITE_BIT(base->ISR, pin, mode != GPIO_INT_MODE_DISABLED);
WRITE_BIT(base->IMR, pin, mode != GPIO_INT_MODE_DISABLED);
WRITE_BIT(data->pin_callback_enables, pin,
mode != GPIO_INT_MODE_DISABLED);
WRITE_BIT(base->ISR, pin, 1);
WRITE_BIT(base->IMR, pin, 1);
WRITE_BIT(data->pin_callback_enables, pin, 1);

irq_unlock(key);

Expand Down

0 comments on commit 007aa03

Please sign in to comment.