Ejemplo n.º 1
0
/*
 * USB_IRQHandler() is the first level handler for the USB peripheral interrupt.
 */
void USB_IRQHandler( void )
{
  uint32_t status;
  bool servedVbusInterrupt = false;

  INT_Disable();

#if ( USB_PWRSAVE_MODE )
  if ( USBD_poweredDown )
  {
    /* Switch USBC clock from 32kHz to a 48MHz clock to be able to  */
    /* read USB peripheral registers.                               */
    /* If we woke up from EM2, HFCLK is now HFRCO.                  */

    /* Restore clock oscillators.*/
#if defined( CMU_OSCENCMD_USHFRCOEN )
    if ( ( CMU->STATUS & CMU_STATUS_USHFRCOENS ) == 0 )/*Wakeup from EM2 ?*/
    {
      CMU->OSCENCMD = ( cmuStatus
                        & ( CMU_STATUS_AUXHFRCOENS | CMU_STATUS_HFXOENS ) )
                      | CMU_OSCENCMD_USHFRCOEN;
    }
#else
    if ( ( CMU->STATUS & CMU_STATUS_HFXOENS ) == 0 ) /* Wakeup from EM2 ? */
    {
      CMU->OSCENCMD = cmuStatus
                      & ( CMU_STATUS_AUXHFRCOENS | CMU_STATUS_HFXOENS );
    }
#endif

    /* Select correct USBC clock.*/
#if defined( CMU_OSCENCMD_USHFRCOEN )
    CMU->CMD = CMU_CMD_USBCCLKSEL_USHFRCO;
    while ( ( CMU->STATUS & CMU_STATUS_USBCUSHFRCOSEL ) == 0 ){}
#else
    CMU->CMD = CMU_CMD_USBCCLKSEL_HFCLKNODIV;
    while ( ( CMU->STATUS & CMU_STATUS_USBCHFCLKSEL ) == 0 ){}
#endif
  }
#endif /* if ( USB_PWRSAVE_MODE ) */

  if ( USB->IF && ( USB->CTRL & USB_CTRL_VREGOSEN ) )
  {
    if ( USB->IF & USB_IF_VREGOSH )
    {
      USB->IFC = USB_IFC_VREGOSH;

      if ( USB->STATUS & USB_STATUS_VREGOS )
      {
        servedVbusInterrupt = true;
        DEBUG_USB_INT_LO_PUTS( "\nVboN" );

#if ( USB_PWRSAVE_MODE )
        if ( UsbPowerUp() )
        {
          USBDHAL_EnableUsbResetAndSuspendInt();
        }
        USBD_SetUsbState( USBD_STATE_POWERED );
#endif
      }
    }

    if ( USB->IF & USB_IF_VREGOSL )
    {
      USB->IFC = USB_IFC_VREGOSL;

      if ( ( USB->STATUS & USB_STATUS_VREGOS ) == 0 )
      {
        servedVbusInterrupt = true;
        DEBUG_USB_INT_LO_PUTS( "\nVboF" );

#if ( USB_PWRSAVE_MODE )
#if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
        if ( !USBD_poweredDown )
        {
          USB->GINTMSK = 0;
          USB->GINTSTS = 0xFFFFFFFF;
        }

        UsbPowerDown();
#endif
        USBD_SetUsbState( USBD_STATE_NONE );
#endif
      }
    }
  }

  status = USBHAL_GetCoreInts();
  if ( status == 0 )
  {
    INT_Enable();
    if ( !servedVbusInterrupt )
    {
      DEBUG_USB_INT_LO_PUTS( "\nSinT" );
    }
    return;
  }

  HANDLE_INT( USB_GINTSTS_RESETDET   )
  HANDLE_INT( USB_GINTSTS_WKUPINT    )
  HANDLE_INT( USB_GINTSTS_USBSUSP    )
  HANDLE_INT( USB_GINTSTS_SOF        )
  HANDLE_INT( USB_GINTSTS_ENUMDONE   )
  HANDLE_INT( USB_GINTSTS_USBRST     )
  HANDLE_INT( USB_GINTSTS_IEPINT     )
  HANDLE_INT( USB_GINTSTS_OEPINT     )

  INT_Enable();

  if ( status != 0 )
  {
    DEBUG_USB_INT_LO_PUTS( "\nUinT" );
  }
}
Ejemplo n.º 2
0
/*
 * USB_IRQHandler() is the first level handler for the USB peripheral interrupt.
 */
void USB_IRQHandler( void )
{
	uint32_t status;
	bool servedVbusInterrupt = false;

	INT_Disable();

#if ( USB_PWRSAVE_MODE )
	if ( USBD_poweredDown )
	{
		/* Switch USBC clock from 32kHz to HFCLK to be able to read USB */
		/* peripheral registers.                                        */
		/* If we woke up from EM2, HFCLK is now HFRCO.                  */

		CMU_OscillatorEnable( cmuOsc_HFXO, true, false);  /* Prepare HFXO. */
		CMU->CMD = CMU_CMD_USBCCLKSEL_HFCLKNODIV;
		while ( !( CMU->STATUS & CMU_STATUS_USBCHFCLKSEL ) ) { }
	}
#endif /* if ( USB_PWRSAVE_MODE ) */

	if ( USB->IF && ( USB->CTRL & USB_CTRL_VREGOSEN ) )
	{
		if ( USB->IF & USB_IF_VREGOSH )
		{
			USB->IFC = USB_IFC_VREGOSH;

			if ( USB->STATUS & USB_STATUS_VREGOS )
			{
				servedVbusInterrupt = true;
				DEBUG_USB_INT_LO_PUTS( "\nVboN" );

#if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
				if ( UsbPowerUp() )
#endif
				{
					USBDHAL_EnableUsbResetInt();
				}

				USBD_SetUsbState( USBD_STATE_POWERED );
			}
		}

		if ( USB->IF & USB_IF_VREGOSL )
		{
			USB->IFC = USB_IFC_VREGOSL;

			if ( !( USB->STATUS & USB_STATUS_VREGOS ) )
			{
				servedVbusInterrupt = true;
				DEBUG_USB_INT_LO_PUTS( "\nVboF" );

				USB->GINTMSK = 0;
				USB->GINTSTS = 0xFFFFFFFF;

#if ( USB_PWRSAVE_MODE & USB_PWRSAVE_MODE_ONVBUSOFF )
				UsbPowerDown();
#endif
				USBD_SetUsbState( USBD_STATE_NONE );
			}
		}
	}

	status = USBHAL_GetCoreInts();
	if ( status == 0 )
	{
		INT_Enable();
		if ( !servedVbusInterrupt )
		{
			DEBUG_USB_INT_LO_PUTS( "\nSinT" );
		}
		return;
	}

	HANDLE_INT( USB_GINTSTS_RESETDET   )
	HANDLE_INT( USB_GINTSTS_WKUPINT    )
	HANDLE_INT( USB_GINTSTS_USBSUSP    )
	HANDLE_INT( USB_GINTSTS_SOF        )
	HANDLE_INT( USB_GINTSTS_ENUMDONE   )
	HANDLE_INT( USB_GINTSTS_USBRST     )
	HANDLE_INT( USB_GINTSTS_IEPINT     )
	HANDLE_INT( USB_GINTSTS_OEPINT     )

	INT_Enable();

	if ( status != 0 )
	{
		DEBUG_USB_INT_LO_PUTS( "\nUinT" );
	}
}