i.MX8MM M4 core - Is it safe to use GPIO_PinSetInterruptConfig() inside ISR to change Rising/Falling

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

i.MX8MM M4 core - Is it safe to use GPIO_PinSetInterruptConfig() inside ISR to change Rising/Falling

294 次查看
paulw2
Contributor II

Hi,

Is it safe to use GPIO_PinSetInterruptConfig() inside GPIO4_Combined_0_15_IRQHandler()  to change Rising/Falling state of GPIO's already configured for interrupts ?

The idea is that a GPIO pin is initially configured to trigger an interrupt on a rising edge, then inside the ISR it is reconfigured to trigger an interrupt on a falling edge.

The following (incomplete) code snippet illustrates the intent, the GPIO pins are configured elsewhere.

Is there a better and/or more complete way to do this ?

static volatile bool gpio_one_FallingEdge = true;
static volatile bool gpio_two_FallingEdge = true;

void GPIO4_Combined_0_15_IRQHandler(void){
    uint32_t interruptFlags;
    interruptFlags = GPIO_PortGetInterruptFlags(GPIO4);

	if (interruptFlags & GPIO4_IO01_GPIO_PIN_MASK)
	{
		invertFallingRisingEdge(1);
		GPIO_PortClearInterruptFlags(GPIO4, 1U << 1U);
	}

	if (interruptFlags & GPIO4_IO02_GPIO_PIN_MASK)
	{
		invertFallingRisingEdge(2);
		GPIO_PortClearInterruptFlags(GPIO4, 1U << 2U);
	}

/*
 * Add for ARM errata 838869, affects Cortex-M4, Cortex-M4F Store immediate overlapping
 * exception return operation might vector to incorrect interrupt.
 *
 * defined in core_cm4.h:71
 */
#if defined __CORTEX_M && (__CORTEX_M == 4U || __CORTEX_M == 7U)
    __DSB();
#endif
}


void invertFallingRisingEdge(uint32_t gpio_pin)
{
     /*
      * Invert the direction of signal required to generate an interrupt
      * gpio_pin is the GPIO pin that caused the interrupt.
      */
     if (gpio_pin == 1)
     {
    	 if (gpio_one_FallingEdge)
    	 {
    		 GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntRisingEdge);
    		 gpio_one_FallingEdge = false;
    	 }
    	 else
		 {
    		 GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntFallingEdge);

    		 gpio_one_FallingEdge = true;
		 }
     }

     if (gpio_pin == 2)
     {
    	 if (gpio_two_FallingEdge)
    	 {
			GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntRisingEdge);
			gpio_two_FallingEdge = false;
    	 }
    	 else
		 {
			GPIO_PinSetInterruptConfig(GPIO4, gpio_pin, kGPIO_IntFallingEdge);
			gpio_two_FallingEdge = true;
		 }
     }

}

Thanks.

标签 (1)
0 项奖励
0 回复数