📄 host_811.lst
字号:
352 1 BYTE ep0 = 0; // always endpoint zero
353 1 ////////////////////////////////////////////////////////////////////////
354 1 //----------------------------------------------------
355 1 // SETUP token with 8-byte request on endpoint 0
356 1 //----------------------------------------------------
357 1 if (!usbXfer(usbaddr, ep0, PID_SETUP,payload, 8, (BYTE*)setup))
358 1 return FALSE;
359 1
360 1 //----------------------------------------------------
361 1 // IN or OUT data stage on endpoint 0
362 1 //----------------------------------------------------
363 1 if (wLen) // if there are data for transfer
364 1 {
365 2 if (setup->bmRequest & 0x80) // host-to-device : IN token
C51 COMPILER V7.06 HOST_811 07/30/2008 08:56:14 PAGE 7
366 2 {
367 3 pid = PID_OUT;
368 3 if(!usbXfer(usbaddr, ep0, PID_IN,payload, wLen, pData))
369 3 return FALSE;
370 3 payload = 0;
371 3 }
372 2 else // device-to-host : OUT token
373 2 {
374 3 if(!usbXfer(usbaddr, ep0, PID_OUT,payload, wLen, pData))
375 3 return FALSE;
376 3 }
377 2 }
378 1
379 1 //----------------------------------------------------
380 1 // Status stage IN or OUT zero-length data packet
381 1 //----------------------------------------------------
382 1 if(!usbXfer(usbaddr, ep0, pid,payload, 0, NULL))
383 1 return FALSE;
384 1
385 1 return TRUE;
386 1 }
387
388 //*****************************************************************************************
389 // Control endpoint
390 //*****************************************************************************************
391 BYTE VendorCmd(BYTE usbaddr,BYTE bReq,BYTE bCmd,WORD wValue,WORD wIndex,WORD wLen,BYTE *pData)
392 {
393 1 SetupPKG setup;
394 1 setup.bmRequest = bReq;
395 1 setup.bRequest = bCmd;
396 1 setup.wValue = wValue;
397 1 setup.wIndex = wIndex;
398 1 setup.wLength = WordSwap(wLen);
399 1 return ep0Xfer(usbaddr, uDev.wPayLoad[0], &setup, pData);
400 1 }
401
402 //*****************************************************************************************
403 // Set Device Address :
404 //*****************************************************************************************
405 BYTE SetAddress(WORD addr)
406 {
407 1 return VendorCmd(0,0,SET_ADDRESS, WordSwap(addr), 0, 0, NULL);
408 1 }
409
410 //*****************************************************************************************
411 // Set Device Configuration :
412 //*****************************************************************************************
413 BYTE SetConfiguration(BYTE usbaddr, WORD wVal)
414 {
415 1 return VendorCmd(usbaddr, 0, SET_CONFIG, WordSwap(wVal), 0, 0, NULL);
416 1 }
417
418 //*****************************************************************************************
419 // Get Device Descriptor : Device, Configuration, String
420 //*****************************************************************************************
421 BYTE GetDesc(BYTE usbaddr, WORD wValue, WORD wIndex, WORD wLen, BYTE *desc)
422 {
423 1 return VendorCmd(usbaddr, 0x80, GET_DESCRIPTOR, wValue, wIndex, wLen, desc);
424 1 }
425 //*****************************************************************************************
426 // USB Device Enumeration Process
427 // Support 1 confguration and interface #0 and alternate setting #0 only
C51 COMPILER V7.06 HOST_811 07/30/2008 08:56:14 PAGE 8
428 // Support up to 1 control endpoint + 4 data endpoint only
429 //*****************************************************************************************
430 BYTE EnumUsbDev(BYTE usbaddr)
431 {
432 1 BYTE i; // always reset USB transfer address
433 1 BYTE uAddr = 0; // for enumeration to Address #0
434 1 BYTE epLen;
435 1 pDevDesc pDev;
436 1 pCfgDesc pCfg;
437 1 pIntfDesc pIfc;
438 1 pEPDesc pEnp;
439 1 ////////////////////////////////////////////////////////////////////////
440 1 uDev.wPayLoad[0] = 64; // default 64-byte payload of Endpoint 0, address #0
441 1 if(usbaddr == 1) // bus reset for the device attached to SL811HS only
442 1 USBReset(); // that will always have the USB address = 0x01 (for a hub)
443 1 pDev =(pDevDesc)bBUF; // ask for 64 bytes on Addr #0
444 1 if (!GetDesc(uAddr,DEVICE,0,18,bBUF)) // and determine the wPayload size
445 1 return FALSE; // get correct wPayload of Endpoint 0
446 1 uDev.wPayLoad[0]=pDev->bMaxPacketSize0; // on current non-zero USB address
447 1 if (!SetAddress(usbaddr)) // set to specific USB address
448 1 return FALSE; //
449 1 uAddr = usbaddr; // transfer using this new address
450 1 if (!GetDesc(uAddr,DEVICE,0,(pDev->bLength),bBUF))
451 1 return FALSE; // For this current device:
452 1 uDev.wVID = pDev->idVendor; // save VID
453 1 uDev.wPID = pDev->idProduct; // save PID
454 1 uDev.iMfg = pDev->iManufacturer; // save Mfg Index
455 1 uDev.iPdt = pDev->iProduct; // save Product Index
456 1 pCfg = (pCfgDesc)bBUF;
457 1 if (!GetDesc(uAddr,CONFIGURATION,0,8,bBUF))
458 1 return FALSE;
459 1 if (!GetDesc(uAddr,CONFIGURATION,0,WordSwap(pCfg->wLength),bBUF))
460 1 return FALSE;
461 1
462 1 pIfc = (pIntfDesc)(bBUF + 9); // point to Interface Descp
463 1 uDev.bClass = pIfc->iClass; // update to class type
464 1 uDev.bNumOfEPs = (pIfc->bEndPoints<=MAX_EP) ? pIfc->bEndPoints : MAX_EP;
465 1 if (!SetConfiguration(uAddr,DEVICE)) // connected directly to SL811HS
466 1 return FALSE;
467 1 if(uDev.bClass==8)
468 1 {
469 2 USB_Control.bMassDevice=TRUE;
470 2 }
471 1 epLen = 0;
472 1 for (i=1; i<=uDev.bNumOfEPs; i++) // For each data endpoint
473 1 {
474 2 pEnp = (pEPDesc)(bBUF + 9 + 9 + epLen); // point to Endpoint Descp(non-HID)
475 2 uDev.bEPAddr[i] = pEnp->bEPAdd; // Ep address and direction
476 2 uDev.bAttr[i] = pEnp->bAttr; // Attribute of Endpoint
477 2 uDev.wPayLoad[i] = pEnp->wPayLoad; // Payload of Endpoint
478 2 uDev.bInterval[i] = pEnp->bInterval; // Polling interval
479 2 uDev.bData1[i] = 0; // init data toggleu
480 2 epLen += 7;
481 2 if(uDev.bAttr[i]==0x2)
482 2 {
483 3 if(uDev.bEPAddr[i]&0x80)
484 3 uDev.bEpin=uDev.bEPAddr[i];
485 3 else
486 3 uDev.bEpOut=uDev.bEPAddr[i];
487 3 }
488 2 }
489 1 return TRUE;
C51 COMPILER V7.06 HOST_811 07/30/2008 08:56:14 PAGE 9
490 1 }
491 //--------------------------------------------------------------------------
492 //SL811H variables initialization
493 //--------------------------------------------------------------------------
494 void sl811h_init(void)
495 {
496 1 SL811Write(IntEna,0x20);
497 1 SL811Write(IntStatus,INT_CLEAR);
498 1 SL811Write(cSOFcnt,0xae);
499 1 DelayMs(10);
500 1 SL811Write(IntStatus,INT_CLEAR);
501 1 USB_Control.SLAVE_FOUND = FALSE;
502 1 USB_Control.SLAVE_ENUMERATED = FALSE;
503 1 USB_Control.SLAVE_ONLINE = FALSE;
504 1 USB_Control.SLAVE_REMOVED=FALSE;
505 1 USB_Control.DATA_STOP=FALSE;
506 1 USB_Control.TIMEOUT_ERR=FALSE;
507 1 USB_Control.bMassDevice = FALSE;
508 1 }
509 //************************************************************************
510 //author:dragon
511 //web:8dragon.com
512 //2004.2.5完成于桃龙源
513 //*************************************************************************
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2314 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 259 84
PDATA SIZE = ---- ----
DATA SIZE = 1 ----
IDATA SIZE = 45 1
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -