void hd64465_gpio_register_irq(int portpin, int mode, void (*handler)(int portpin, void *dev), void *dev) { unsigned long flags; unsigned short icr, mask; if (handler == 0) return; local_irq_save(flags); handlers[portpin].func = handler; handlers[portpin].dev = dev; /* * Configure Interrupt Control Register */ icr = inw(GPIO_ICR(_PORTOF(portpin))); mask = (1<<_PINOF(portpin)); /* unmask interrupt */ icr &= ~mask; /* set TS bit */ mask <<= 8; icr &= ~mask; if (mode == HD64465_GPIO_RISING) icr |= mask; outw(icr, GPIO_ICR(_PORTOF(portpin))); local_irq_restore(flags); }
void gpiof_isr(void) { if (GPIO_RIS(GPIOF) & USR_SW1) { /* SW1 was just depressed */ bypass = !bypass; if (bypass) { rcc_pll_bypass_enable(); /* * The divisor is still applied to the raw clock. * Disable the divisor, or we'll divide the raw clock. */ SYSCTL_RCC &= ~SYSCTL_RCC_USESYSDIV; } else { rcc_change_pll_divisor(plldiv[ipll]); } /* Clear interrupt source */ GPIO_ICR(GPIOF) = USR_SW1; } if (GPIO_RIS(GPIOF) & USR_SW2) { /* SW2 was just depressed */ if (!bypass) { if (plldiv[++ipll] == 0) ipll = 0; rcc_change_pll_divisor(plldiv[ipll]); } /* Clear interrupt source */ GPIO_ICR(GPIOF) = USR_SW2; } }
void hd64465_gpio_unregister_irq(int portpin) { unsigned long flags; unsigned short icr; local_irq_save(flags); /* * Configure Interrupt Control Register */ icr = inw(GPIO_ICR(_PORTOF(portpin))); icr |= (1<<_PINOF(portpin)); /* mask interrupt */ outw(icr, GPIO_ICR(_PORTOF(portpin))); handlers[portpin].func = 0; handlers[portpin].dev = 0; local_irq_restore(flags); }
int imxrt_gpioirq_configure(gpio_pinset_t pinset) { unsigned int port; unsigned int pin; uintptr_t regaddr; uint32_t regval; uint32_t icr; /* Decode information in the pin configuration */ port = ((unsigned int)pinset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT; pin = ((unsigned int)pinset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT; icr = ((uint32_t)pinset & GPIO_INTCFG_MASK) >> GPIO_INTCFG_SHIFT; /* Set the right field in the right ICR register */ regaddr = pin < 16 ? IMXRT_GPIO_ICR1(port) : IMXRT_GPIO_ICR2(port); regval = getreg32(regaddr); regval &= ~GPIO_ICR_MASK(pin); regval |= GPIO_ICR(icr, pin); putreg32(regval, regaddr); return OK; }