Esempio n. 1
0
void USB_ResetInterface(void)
{
	uint8_t PrescalerNeeded;

	#if defined(USB_DEVICE_OPT_FULLSPEED)
	if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
	  PrescalerNeeded = F_USB / 6000000;
	else
	  PrescalerNeeded = F_USB / 48000000;
	#else
	PrescalerNeeded = F_USB / 6000000;
	#endif

	uint8_t DividerIndex = 0;
	while (PrescalerNeeded > 0)
	{
		DividerIndex++;
		PrescalerNeeded >>= 1;
	}

	CLK.USBCTRL = (DividerIndex - 1) << CLK_USBPSDIV_gp;

	if (USB_Options & USB_OPT_PLLCLKSRC)
	  CLK.USBCTRL |= (CLK_USBSRC_PLL_gc   | CLK_USBSEN_bm);
	else
	  CLK.USBCTRL |= (CLK_USBSRC_RC32M_gc | CLK_USBSEN_bm);

	USB_Device_SetDeviceAddress(0);

	USB_INT_DisableAllInterrupts();
	USB_INT_ClearAllInterrupts();

	USB_Controller_Reset();
	USB_Init_Device();
}
void USB_ResetInterface(void)
{
	if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
	  CLK.USBCTRL = ((((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp) | CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
	else
	  CLK.USBCTRL = ((((F_USB / 48000000) - 1) << CLK_USBPSDIV_gp) | CLK_USBSRC_PLL_gc | CLK_USBSEN_bm);
	
	USB_Device_SetDeviceAddress(0);
	
	USB_INT_DisableAllInterrupts();
	USB_INT_ClearAllInterrupts();

	USB_Controller_Reset();
	USB_Init_Device();
}
static void USB_Device_SetAddress(void)
{
	uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F);

	USB_Device_SetDeviceAddress(DeviceAddress);

	Endpoint_ClearSETUP();

	Endpoint_ClearStatusStage();

	while (!(Endpoint_IsINReady()));

	USB_Device_EnableDeviceAddress(DeviceAddress);

	USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
}
static void USB_Device_SetAddress(void)
{
	uint8_t    DeviceAddress    = (USB_ControlRequest.wValue & 0x7F);
	uint_reg_t CurrentGlobalInt = GetGlobalInterruptMask();
	GlobalInterruptDisable();
				
	Endpoint_ClearSETUP();

	Endpoint_ClearStatusStage();

	while (!(Endpoint_IsINReady()));

	USB_Device_SetDeviceAddress(DeviceAddress);
	USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;
	
	SetGlobalInterruptMask(CurrentGlobalInt);
}
Esempio n. 5
0
/********************************************************************//**
 * @brief
 * @param
 * @return
 *********************************************************************/
void HAL_Reset (void)
{
  uint32_t i;

  /* disable all EPs */
  USB_REG(USBPortNum)->ENDPTCTRL0 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);
  USB_REG(USBPortNum)->ENDPTCTRL1 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);
  USB_REG(USBPortNum)->ENDPTCTRL2 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);
  USB_REG(USBPortNum)->ENDPTCTRL3 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);
  if(USB_REG(USBPortNum) == LPC_USB0)
  {
	  USB_REG(USBPortNum)->ENDPTCTRL4 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);
	  USB_REG(USBPortNum)->ENDPTCTRL5 &= ~(ENDPTCTRL_RxEnable | ENDPTCTRL_TxEnable);
  }

  /* Clear all pending interrupts */
  USB_REG(USBPortNum)->ENDPTNAK		= 0xFFFFFFFF;
  USB_REG(USBPortNum)->ENDPTNAKEN		= 0;
  USB_REG(USBPortNum)->USBSTS_D		= 0xFFFFFFFF;
  USB_REG(USBPortNum)->ENDPTSETUPSTAT	= USB_REG(USBPortNum)->ENDPTSETUPSTAT;
  USB_REG(USBPortNum)->ENDPTCOMPLETE	= USB_REG(USBPortNum)->ENDPTCOMPLETE;
  while (USB_REG(USBPortNum)->ENDPTPRIME);                  /* Wait until all bits are 0 */
  USB_REG(USBPortNum)->ENDPTFLUSH = 0xFFFFFFFF;
  while (USB_REG(USBPortNum)->ENDPTFLUSH); /* Wait until all bits are 0 */

  /* Set the interrupt Threshold control interval to 0 */
  USB_REG(USBPortNum)->USBCMD_D &= ~0x00FF0000;

  /* Configure the Endpoint List Address */
  /* make sure it in on 64 byte boundary !!! */
  /* init list address */
  USB_REG(USBPortNum)->ENDPOINTLISTADDR = (uint32_t)dQueueHead;
  
  /* Enable interrupts: USB interrupt, error, port change, reset, suspend, NAK interrupt */
  USB_REG(USBPortNum)->USBINTR_D =  USBINTR_D_UsbIntEnable | USBINTR_D_UsbErrorIntEnable |
						USBINTR_D_PortChangeIntEnable | USBINTR_D_UsbResetEnable |
						USBINTR_D_SuspendEnable | USBINTR_D_NAKEnable | USBINTR_D_SofReceivedEnable;

  USB_Device_SetDeviceAddress(0);
  
  endpointselected = 0;
  for(i=0;i<ENDPOINT_TOTAL_ENDPOINTS;i++)
	  endpointhandle[i] = 0;

  return;
}
static void USB_Device_SetAddress(void)
{
	uint8_t DeviceAddress = (USB_ControlRequest.wValue & 0x7F);

	Endpoint_ClearSETUP();
	
	Endpoint_ClearStatusStage();
	
	while (!(Endpoint_IsINReady()))
	{
		if (USB_DeviceState == DEVICE_STATE_Unattached)
		  return;
	}

	USB_DeviceState = (DeviceAddress) ? DEVICE_STATE_Addressed : DEVICE_STATE_Default;

	USB_Device_SetDeviceAddress(DeviceAddress);

	return;
}
Esempio n. 7
0
void USB_ResetInterface(void)
{
	#if defined(USB_DEVICE_OPT_FULLSPEED)
	if (USB_Options & USB_DEVICE_OPT_LOWSPEED)
	  CLK.USBCTRL = (((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp);
	else
	  CLK.USBCTRL = (((F_USB / 48000000) - 1) << CLK_USBPSDIV_gp);
	#else
	CLK.USBCTRL = (((F_USB / 6000000) - 1) << CLK_USBPSDIV_gp);
	#endif
	
	if (USB_Options & USB_OPT_PLLCLKSRC)
	  CLK.USBCTRL |= (CLK_USBSRC_PLL_gc   | CLK_USBSEN_bm);
	else
	  CLK.USBCTRL |= (CLK_USBSRC_RC32M_gc | CLK_USBSEN_bm);

	USB_Device_SetDeviceAddress(0);

	USB_INT_DisableAllInterrupts();
	USB_INT_ClearAllInterrupts();

	USB_Controller_Reset();
	USB_Init_Device();
}