Beispiel #1
0
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_gpioirq(IRQ_USER1);
      (void)irq_attach(IRQ_USER1, irqhandler);
      sam_gpioirqenable(IRQ_USER1);
    }

  /* Return the old button handler (so that it can be restored) */

  return oldhandler;
}
Beispiel #2
0
static xcpt_t board_button_irqx(int irq, xcpt_t irqhandler, xcpt_t *store)
{
  xcpt_t oldhandler;
  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 = *store;
  *store = irqhandler;

  /* Configure the interrupt */

  sam_gpioirq(irq);
  (void)irq_attach(irq, irqhandler);
  sam_gpioirqenable(irq);
  irqrestore(flags);

  /* Return the old button handler (so that it can be restored) */

  return oldhandler;
}
Beispiel #3
0
int sam_hsmci_initialize(void)
{
  int ret;
  fdbg("Initializing SDIO\n");

  /* Have we already initialized? */

  if (!g_hsmci.initialized)
    {
      /* Mount the SDIO-based MMC/SD block driver */
      /* First, get an instance of the SDIO interface */

      g_hsmci.hsmci = sdio_initialize(CONFIG_NSH_MMCSDSLOTNO);
      if (!g_hsmci.hsmci)
        {
          fdbg("Failed to initialize SDIO\n");
          return -ENODEV;
        }

      /* Now bind the SDIO interface to the MMC/SD driver */

      ret = mmcsd_slotinitialize(CONFIG_NSH_MMCSDMINOR, g_hsmci.hsmci);
      if (ret != OK)
        {
          fdbg("Failed to bind SDIO to the MMC/SD driver: %d\n", ret);
          return ret;
        }

#ifdef CONFIG_MMCSD_HAVECARDDETECT
      /* Initialize card-detect GPIO.  There is no write-protection GPIO. */

      sam_configgpio(GPIO_MCI_CD);

      /* Configure card detect interrupts */

      sam_gpioirq(GPIO_MCI_CD);
      (void)irq_attach(MCI_CD_IRQ, sam_hsmci_cardetect_int);
      g_hsmci.inserted = sam_cardinserted(0);
#else
      g_hsmci.inserted = true; /* An assumption? */
#endif
      /* Then inform the HSMCI driver if there is or is not a card in the slot. */

      sdio_mediachange(g_hsmci.hsmci, g_hsmci.inserted);

      /* Now we are initialized */

      g_hsmci.initialized = true;

      /* Enable card detect interrupts */

#ifdef CONFIG_MMCSD_HAVECARDDETECT
      sam_gpioirqenable(MCI_CD_IRQ);
#endif
    }

  return OK;
}
Beispiel #4
0
int board_tsc_setup(int minor)
{
    FAR struct spi_dev_s *dev;
    static bool initialized = false;
    int ret;

    idbg("minor %d\n", minor);
    DEBUGASSERT(minor == 0);

    /* Have we already initialized?  Since we never uninitialize we must prevent
     * multiple initializations.  This is necessary, for example, when the
     * touchscreen example is used as a built-in application in NSH and can be
     * called numerous time.  It will attempt to initialize each time.
     */

    if (!initialized)
    {
        /* Configure and enable the XPT2046 interrupt pin as an input */

        (void)sam_configgpio(GPIO_TSC_IRQ);

        /* Configure the PIO interrupt */

        sam_gpioirq(SAM_TSC_IRQ);

        /* Get an instance of the SPI interface for the touchscreen chip select */

        dev = sam_tsc_spiinitialize();
        if (!dev)
        {
            idbg("Failed to initialize bit bang SPI\n");
            return -ENODEV;
        }

        /* Initialize and register the SPI touschscreen device */

        ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR);
        if (ret < 0)
        {
            idbg("Failed to register touchscreen device\n");
            /* up_spiuninitialize(dev); */
            return -ENODEV;
        }

        /* Now we are initialized */

        initialized = true;
    }

    return OK;
}
Beispiel #5
0
xcpt_t board_button_irq(int id, xcpt_t irqhandler)
{
  xcpt_t oldhandler = NULL;

  if (id == BUTTON_SW0)
    {
      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_irqsw0;
      g_irqsw0 = irqhandler;

      /* Are we attaching or detaching? */

      if (irqhandler != NULL)
        {
          /* Configure the interrupt */

          sam_gpioirq(GPIO_SW0);
          (void)irq_attach(IRQ_SW0, irqhandler);
          sam_gpioirqenable(IRQ_SW0);
        }
      else
        {
          /* Detach and disable the interrupt */

          (void)irq_detach(IRQ_SW0);
          sam_gpioirqdisable(IRQ_SW0);
        }

      irqrestore(flags);
    }

  /* Return the old button handler (so that it can be restored) */

  return oldhandler;
}
Beispiel #6
0
static xcpt_t board_button_irqx(gpio_pinset_t pinset, int irq,
                                xcpt_t irqhandler, xcpt_t *store)
{
  xcpt_t oldhandler;
  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 = *store;
  *store = irqhandler;

  /* Are we attaching or detaching? */

  if (irqhandler != NULL)
    {
      /* Configure the interrupt */

      sam_gpioirq(pinset);
      (void)irq_attach(irq, irqhandler);
      sam_gpioirqenable(irq);
    }
  else
    {
      /* Detach and disable the interrupt */

      (void)irq_detach(irq);
      sam_gpioirqdisable(irq);
    }

  irqrestore(flags);

  /* Return the old button handler (so that it can be restored) */

  return oldhandler;
}
Beispiel #7
0
int arch_tcinitialize(int minor)
{
  FAR struct spi_dev_s *dev;
  int ret;

  idbg("minor %d\n", minor);
  DEBUGASSERT(minor == 0);

  /* Configure and enable the ADS7843E interrupt pin as an input */

  (void)sam_configgpio(GPIO_TCS_BUSY);
  (void)sam_configgpio(GPIO_TCS_IRQ);

  /* Configure the PIO interrupt */

  sam_gpioirq(GPIO_TCS_IRQ);

  /* Get an instance of the SPI interface for the touchscreen chip select */

  dev = up_spiinitialize(TSC_CSNUM);
  if (!dev)
    {
      idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM);
      return -ENODEV;
    }

  /* Initialize and register the SPI touschscreen device */

  ret = ads7843e_register(dev, &g_tscinfo, CONFIG_ADS7843E_DEVMINOR);
  if (ret < 0)
    {
      idbg("Failed to initialize SPI chip select %d\n", TSC_CSNUM);
      /* up_spiuninitialize(dev); */
      return -ENODEV;
    }

  return OK;
}
Beispiel #8
0
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;
  gpio_pinset_t pinset;
  phy_enable_t enabler;
  int irq;

  DEBUGASSERT(intf);

  ninfo("%s: handler=%p\n", intf, handler);
  phyinfo("EMAC0: devname=%s\n", SAMV7_EMAC0_DEVNAME);

  if (strcmp(intf, SAMV7_EMAC0_DEVNAME) == 0)
    {
      phyinfo("Select EMAC0\n");

      phandler = &g_emac0_handler;
      pinset   = GPIO_EMAC0_INT;
      irq      = IRQ_EMAC0_INT;
      enabler  = sam_emac0_phy_enable;
    }
  else
    {
      nerr("ERROR: Unsupported interface: %s\n", intf);
      return NULL;
    }

  /* 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 = *phandler;
  *phandler  = handler;

  /* Configure the interrupt */

  if (handler)
    {
      phyinfo("Configure pin: %08x\n", pinset);
      sam_gpioirq(pinset);

      phyinfo("Attach IRQ%d\n", irq);
      (void)irq_attach(irq, handler);
    }
  else
    {
      phyinfo("Detach IRQ%d\n", irq);
      (void)irq_detach(irq);
      enabler = NULL;
    }

  /* Return with the interrupt disabled in either case */

  sam_gpioirqdisable(irq);

  /* Return the enabling function pointer */

  if (enable)
    {
      *enable = enabler;
    }

  /* Return the old handler (so that it can be restored) */

  leave_critical_section(flags);
  return oldhandler;
}