Ejemplo n.º 1
0
/*************************************************************************
 * Function Name: UsbSetDevState
 * Parameters:  UsbT9DevState_t DevState
 *
 * Return: none
 *
 * Description: Set device state
 *
 *************************************************************************/
void UsbSetDevState (UsbT9DevState_t DevState)
{
pUsbStandardInterfaceDescriptor_t pInterface;
  if(UsbDevCtrl.State.DS == UsbDevStatusConfigured)
  {
    // deconfigure device
    for (Int32U i = 0; i < UsbDevCtrl.Interfaces; ++i)
    {
      pInterface = UsbFindInterface(UsbDevCtrl.pCnfg,i,UsbDevCtrl.AlternateSetting[i]);
      UsbEpInterfaceCnfg(pInterface,FALSE);
    }
  }
  switch (DevState)
  {
  case UsbDevStatusAttached:
  case UsbDevStatusPowered:
  case UsbDevStatusDefault:
    USB_Configure(FALSE);
    USB_SetDefAdd();  // Set address 0
    USB_CONFIGURE_HOOK(NULL);
    UsbDevCtrl.DevAdd = UsbDevCtrl.Configuration = 0;
    break;
  case UsbDevStatusAddress:
    USB_Configure(FALSE);
    UsbDevCtrl.Configuration = 0;
    break;
  case UsbDevStatusConfigured:
    // configure device
    for (Int32U i = 0; i < UsbDevCtrl.Interfaces; ++i)
    {
      pInterface = UsbFindInterface(UsbDevCtrl.pCnfg,i,UsbDevCtrl.AlternateSetting[i]);
      UsbEpInterfaceCnfg(pInterface,TRUE);
    }
    USB_Configure(TRUE);
    break;
  default:  // unknown state - disconnected or in process of a connection
    USB_Configure(FALSE);
    USB_CONFIGURE_HOOK(NULL);
    UsbDevCtrl.DevAdd = UsbDevCtrl.Configuration = 0;
  }
  UsbDevCtrl.State.DS = DevState;
}
Ejemplo n.º 2
0
/*************************************************************************
 * Function Name: USB_HwReset
 * Parameters: none
 *
 * Return: none
 *
 * Description: Reset USB engine
 *
 *************************************************************************/
void USB_HwReset (void)
{
Int32U Count;

  // Clear realized EP flag
  for(Count = 0; Count < ENP_MAX_NUMB; Count++)
  {
    EpCnfg[Count].pEpCtrl = NULL;
  }

  // Free entire USB packet memory
  for (Count = 0; Count < EP_MAX_SLOTS*2; Count++)
  {
    PacketMemBuff[Count].Size = 0;
  }

  // Resume delay counter
  DlyCnt = 0;

  // USB_Configure
  USB_Configure(FALSE);
  // Set Buffer table address
  USB_BTABLE = USB_OffsetOfDBT;
  // Init Packet memory table
  pPacketMemUse = NULL;
  // Control EP Init
  USB_RealizeEp(&USB_CtrlEpDescr0,&USB_CtrlEpExt0,TRUE);
  USB_RealizeEp(&USB_CtrlEpDescr1,&USB_CtrlEpExt1,TRUE);

  // Set address 0
  USB_SetDefAdd();

  // Enable Device interrupts
  USB_CNTR = bmCTRM | bmRESETM | bmSUSPM | bmWKUPM |
            (USB_SOF_EVENT    ? bmSOFM    : 0) |
            (USB_ERROR_EVENT  ? bmERRM    : 0) |
            (USB_PMAOVR_EVENT ? bmPMAOVRM : 0) ;
}