twofishes
驱动牛犊
驱动牛犊
  • 注册日期2003-12-25
  • 最后登录2005-10-27
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:908回复:1

固件开发

楼主#
更多 发布于:2004-07-29 19:41
能否详细讲述枚举的概念,怎样在固件开发中体现?谢谢!
OpenCore
驱动牛犊
驱动牛犊
  • 注册日期2003-03-31
  • 最后登录2004-10-01
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2004-07-29 23:41
//*****************************************************************************************
// USB Device Enumeration Process
// Support 1 confguration and interface #0 and alternate setting #0 only
// Support up to 1 control endpoint + 4 data endpoint only
//*****************************************************************************************
int EnumUsbDev(BYTE usbaddr)
{  
int i; // always reset USB transfer address
xdata BYTE uAddr = 0; // for enumeration to Address #0
xdata BYTE epLen;
xdata WORD strLang;

//------------------------------------------------
// Reset only Slave device attached directly
//------------------------------------------------
uDev[0].wPayLoad[0] = 64; // default 64-byte payload of Endpoint 0, address #0
if(usbaddr == 1) // bus reset for the device attached to SL811HS only
USBReset(); // that will always have the USB address = 0x01 (for a hub)
    EZUSB_Delay(25);

//------------------------------------------------
// Get USB Device Descriptors on EP0 & Addr 0
// with default 64-byte payload
//------------------------------------------------
pDev =(pDevDesc)DBUF; // ask for 64 bytes on Addr #0
if (!GetDesc(uAddr,DEVICE,0,18,DBUF)) // and determine the wPayload size
return FALSE; // get correct wPayload of Endpoint 0
uDev[usbaddr].wPayLoad[0]=pDev->bMaxPacketSize0;// on current non-zero USB address

//------------------------------------------------
// Set Slave USB Device Address
//------------------------------------------------
if (!SetAddress(usbaddr)) // set to specific USB address
return FALSE; //
uAddr = usbaddr; // transfer using this new address

//------------------------------------------------
// Get USB Device Descriptors on EP0 & Addr X
//------------------------------------------------
if (!GetDesc(uAddr,DEVICE,0,(pDev->bLength),DBUF))
return FALSE; // For this current device:
uDev[usbaddr].wVID = pDev->idVendor; // save VID
uDev[usbaddr].wPID = pDev->idProduct; // save PID
uDev[usbaddr].iMfg = pDev->iManufacturer; // save Mfg Index
uDev[usbaddr].iPdt = pDev->iProduct; // save Product Index

//------------------------------------------------
// Get String Descriptors
//------------------------------------------------
pStr = (pStrDesc)DBUF;
if (!GetDesc(uAddr,STRING,0,4,DBUF)) // Get string language
return FALSE;
strLang = pStr->wLang; // get iManufacturer String length
if (!GetDesc(uAddr,(WORD)(uDev[usbaddr].iMfg<<8)|STRING,strLang,4,DBUF))
return FALSE; // get iManufacturer String descriptors
if (!GetDesc(uAddr,(WORD)(uDev[usbaddr].iMfg<<8)|STRING,strLang,pStr->bLength,DBUF))
return FALSE;

//------------------------------------------------
// Get Slave USB Configuration Descriptors
//------------------------------------------------
pCfg = (pCfgDesc)DBUF;
if (!GetDesc(uAddr,CONFIGURATION,0,8,DBUF))
return FALSE;
if (!GetDesc(uAddr,CONFIGURATION,0,WordSwap(pCfg->wLength),DBUF))
return FALSE;

pIfc = (pIntfDesc)(DBUF + 9); // point to Interface Descp
uDev[usbaddr].bClass = pIfc->iClass; // update to class type
uDev[usbaddr].bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;

//------------------------------------------------
// Set configuration (except for HUB device)
//------------------------------------------------
if (uDev[usbaddr].bClass!=HUBCLASS) // enumerating a FS/LS non-hub device
if (!Set_Configuration(uAddr,DEVICE)) // connected directly to SL811HS
return FALSE;

//------------------------------------------------
// For each slave endpoints, get its attributes
// Excluding endpoint0, only data endpoints
//------------------------------------------------
epLen = 0;
for (i=1; i<=uDev[usbaddr].bNumOfEPs; i++) // For each data endpoint
{
pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen);   // point to Endpoint Descp(non-HID)
if(pIfc->iClass == HIDCLASS)
pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen); // update pointer to Endpoint(HID)
uDev[usbaddr].bEPAddr   = pEnp->bEPAdd; // Ep address and direction
uDev[usbaddr].bAttr = pEnp->bAttr; // Attribute of Endpoint
uDev[usbaddr].wPayLoad = pEnp->wPayLoad; // Payload of Endpoint
uDev[usbaddr].bInterval = pEnp->bInterval; // Polling interval
   uDev[usbaddr].bData1 = 0;            // init data toggle
epLen += 7;
}

//------------------------------------------------
// Get Hid Report Descriptors
//------------------------------------------------
if(pIfc->iClass == HIDCLASS)
{
pHid = (pHidDesc)(DBUF + 9 + 9);   // point to HID-CLASS descp
if (!GetHid_Desc(uAddr,HID_REPORT,pHid->wItemLength,DBUF))
return FALSE;
}

//------------------------------------------------
// Get HUB Class Specific Descriptor (per port switching)
//------------------------------------------------
if(uDev[usbaddr].bClass==HUBCLASS)
    { // enumerating a HUB device
   pHub =(pHubDesc)DBUF; // Ask for 71 bytes ???
   if (!GetHubDesc(uAddr,0x00,0x47,DBUF))
return FALSE; // Get Hub Desriptor
if (!GetStatus(uAddr,STATUS))
return FALSE;     // Get Status
if (!Set_Configuration(uAddr,DEVICE))
return FALSE;   // Set configuration

pNumPort = pHub->bNbrPort; // save no. of ports available
for(i=1; i<=pNumPort; i++) // ClearPortFeature: C_PORT_CONNECTION off
   if(!PortFeature(uAddr,CLEAR_FEATURE, C_PORT_CONNECTION,i))
return FALSE;

for(i=1; i<=pNumPort; i++) // SetPortFeature: PORT_POWER on
{
   if(!PortFeature(uAddr,SET_FEATURE, PORT_POWER, i))
return FALSE;
}

for(i=1; i<=pHub->bNbrPort; i++) // GetPortStatus(wHubStatus,wHubChange)
  if( !GetPortStatus(uAddr,i,STATUS) ) //
return FALSE; //

for(i=2;i<=pNumPort+1;i++) // clear port present status
{ // address #2..#5 only
uHub.bPortPresent = 0; // clear status
uHub.bPortNumber = 0; //
}
HUB_DEVICE = TRUE; // Set Hub flag, as long as a hub is attached
} // directly to the HUB_DEVICE will be set

return TRUE;
}

EZ里的一个枚举过程,没试过,不过原理上估计也就这么体现……
游客

返回顶部