xcpt_t sam_setup_overcurrent(xcpt_t handler) { #if defined(CONFIG_SAMA5_PIOD_IRQ) && (defined(CONFIG_SAMA5_UHPHS_RHPORT2) || \ defined(CONFIG_SAMA5_UHPHS_RHPORT3)) xcpt_t oldhandler; irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the * following operations are atomic. */ flags = enter_critical_section(); /* Get the old interrupt handler and save the new one */ oldhandler = g_ochandler; g_ochandler = handler; /* Configure the interrupt */ sam_pioirq(PIO_USBBC_VBUS_OVERCURRENT); (void)irq_attach(IRQ_USBBC_VBUS_OVERCURRENT, handler); sam_pioirqenable(IRQ_USBBC_VBUS_OVERCURRENT); /* Return the old handler (so that it can be restored) */ leave_critical_section(flags); return oldhandler; #else return NULL; #endif }
xcpt_t up_irqbutton(int id, xcpt_t irqhandler) { xcpt_t oldhandler = NULL; if (id == BUTTON_USER1) { irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the * following operations are atomic. */ flags = irqsave(); /* Get the old button interrupt handler and save the new one */ oldhandler = *g_irquser1; *g_irquser1 = irqhandler; /* Configure the interrupt */ sam_pioirq(IRQ_USER1); (void)irq_attach(IRQ_USER1, irqhandler); sam_pioirqenable(IRQ_USER1); } /* Return the old button handler (so that it can be restored) */ return oldhandler; }
int sam_ajoy_initialization(void) { int ret; int fd; int i; /* NOTE: The ADC driver was initialized earlier in the bring-up sequence. */ /* Open the ADC driver for reading. */ fd = open("/dev/adc0", O_RDONLY); if (fd < 0) { int errcode = get_errno(); ierr("ERROR: Failed to open /dev/adc0: %d\n", errcode); return -errcode; } /* Detach the file structure from the file descriptor so that it can be * used on any thread. */ ret = file_detach(fd, &g_adcfile); if (ret < 0) { ierr("ERROR: Failed to detach from file descriptor: %d\n", ret); (void)close(fd); return ret; } /* Configure the GPIO pins as interrupting inputs. */ for (i = 0; i < AJOY_NGPIOS; i++) { /* Configure the PIO as an input */ sam_configpio(g_joypio[i]); /* Configure PIO interrupts, attach the interrupt handler, but leave * the interrupt disabled. */ sam_pioirq(g_joypio[i]); (void)irq_attach(g_joyirq[i], ajoy_interrupt); sam_pioirqdisable(g_joyirq[i]); } /* Register the joystick device as /dev/ajoy0 */ ret = ajoy_register("/dev/ajoy0", &g_ajoylower); if (ret < 0) { ierr("ERROR: ajoy_register failed: %d\n", ret); file_close_detached(&g_adcfile); } return ret; }
xcpt_t board_button_irq(int id, xcpt_t irqhandler) { xcpt_t oldhandler = NULL; if (id == BUTTON_USER) { irqstate_t flags; /* Disable interrupts until we are done. This guarantees that the * following operations are atomic. */ flags = irqsave(); /* Get the old button interrupt handler and save the new one */ oldhandler = g_irquser1; g_irquser1 = irqhandler; /* Are we attaching or detaching? */ if (irqhandler != NULL) { /* Configure the interrupt */ sam_pioirq(PIO_BTN_USER); (void)irq_attach(IRQ_BTN_USER, irqhandler); sam_pioirqenable(IRQ_BTN_USER); } else { /* Disable and detach the interrupt */ sam_pioirqdisable(IRQ_BTN_USER); (void)irq_detach(IRQ_BTN_USER); } irqrestore(flags); } /* Return the old button handler (so that it can be restored) */ return oldhandler; }
xcpt_t arch_phy_irq(FAR const char *intf, xcpt_t handler, phy_enable_t *enable) { irqstate_t flags; xcpt_t *phandler; xcpt_t oldhandler; pio_pinset_t pinset; phy_enable_t enabler; int irq; DEBUGASSERT(intf); nvdbg("%s: handler=%p\n", intf, handler); #ifdef CONFIG_SAMA5_EMACA phydbg("EMAC: devname=%s\n", SAMA5_EMAC_DEVNAME); #endif #ifdef CONFIG_SAMA5_GMAC phydbg("GMAC: devname=%s\n", SAMA5_GMAC_DEVNAME); #endif #ifdef CONFIG_SAMA5_EMACA if (strcmp(intf, SAMA5_EMAC_DEVNAME) == 0) { phydbg("Select EMAC\n"); phandler = &g_emac_handler; pinset = PIO_INT_ETH1; irq = IRQ_INT_ETH1; enabler = sam_emac_phy_enable; } else #endif #ifdef CONFIG_SAMA5_GMAC if (strcmp(intf, SAMA5_GMAC_DEVNAME) == 0) { phydbg("Select GMAC\n"); phandler = &g_gmac_handler; pinset = PIO_INT_ETH0; irq = IRQ_INT_ETH0; enabler = sam_gmac_phy_enable; } else #endif { ndbg("Unsupported interface: %s\n", intf); return NULL; } /* Disable interrupts until we are done. This guarantees that the * following operations are atomic. */ flags = irqsave(); /* Get the old interrupt handler and save the new one */ oldhandler = *phandler; *phandler = handler; /* Configure the interrupt */ if (handler) { phydbg("Configure pin: %08x\n", pinset); sam_pioirq(pinset); phydbg("Attach IRQ%d\n", irq); (void)irq_attach(irq, handler); } else { phydbg("Detach IRQ%d\n", irq); (void)irq_detach(irq); enabler = NULL; } /* Return with the interrupt disabled in either case */ sam_pioirqdisable(irq); /* Return the enabling function pointer */ if (enable) { *enable = enabler; } /* Return the old handler (so that it can be restored) */ irqrestore(flags); return oldhandler; }