📄 sl811.lst
字号:
499 if(epaddr & 0x80) // get direction of transfer
500 usbstack.pid = PID_IN;
501
502 if(usbXfer())
503 return TRUE;
504
505 return FALSE;
506 }
507 */
508
509 //*****************************************************************************************
510 // USB Device Enumeration Process
511 // Support 1 confguration and interface #0 and alternate setting #0 only
512 // Support up to 1 control endpoint + 4 data endpoint only
513 //*****************************************************************************************
514 unsigned char EnumUsbDev(BYTE usbaddr)
515 {
516 1 unsigned char i; // always reset USB transfer address
517 1 unsigned char uAddr = 0; // for enumeration to Address #0
518 1 unsigned char epLen;
519 1 //unsigned short strLang;
520 1
521 1 pDevDesc pDev;
522 1 pCfgDesc pCfg;
523 1 pIntfDesc pIfc;
524 1 pEPDesc pEnp;
525 1 //------------------------------------------------
526 1 // Reset only Slave device attached directly
527 1 //------------------------------------------------
528 1 uDev.wPayLoad[0] = 64; // default 64-byte payload of Endpoint 0, address #0
529 1 if(usbaddr == 1) // bus reset for the device attached to SL811HS only
530 1 USBReset(); // that will always have the USB address = 0x01 (for a hub)
531 1
532 1 DelayMs(25);
533 1
534 1 //i = SL811Read(EP0Status);
535 1 //i=SL811Read(IntStatus);
536 1 //------------------------------------------------
537 1 // Get USB Device Descriptors on EP0 & Addr 0
538 1 // with default 64-byte payload
539 1 //------------------------------------------------
540 1 pDev =(pDevDesc)DBUF; // ask for 64 bytes on Addr #0
541 1
542 1 usbstack.usbaddr=uAddr;
543 1 usbstack.setup.wValue=DEVICE;
544 1 usbstack.setup.wIndex=0;
545 1 usbstack.setup.wLength=18;
546 1 //usbstack.setup.wLength=sbstack.setup.wLength);
547 1 usbstack.buffer=DBUF;
548 1
549 1 if (!GetDesc()) // and determine the wPayload size
550 1 return FALSE; // get correct wPayload of Endpoint 0
C51 COMPILER V6.20c SL811 08/21/2003 22:51:04 PAGE 10
551 1 uDev.wPayLoad[0]=pDev->bMaxPacketSize0;// on current non-zero USB address
552 1
553 1 //------------------------------------------------
554 1 // Set Slave USB Device Address
555 1 //------------------------------------------------
556 1 if (!SetAddress(usbaddr)) // set to specific USB address
557 1 return FALSE; //
558 1 uAddr = usbaddr; // transfer using this new address
559 1
560 1 //------------------------------------------------
561 1 // Get USB Device Descriptors on EP0 & Addr X
562 1 //------------------------------------------------
563 1 pDev =(pDevDesc)DBUF;
564 1 usbstack.usbaddr=uAddr;
565 1
566 1 usbstack.setup.wLength=pDev->bLength;
567 1 usbstack.setup.wValue=DEVICE;
568 1 usbstack.setup.wIndex=0;
569 1
570 1 //usbstack.setup.wLength=0x12;//(unsigned short)DBUF[0];//pDev->bLength;
571 1 usbstack.buffer=DBUF;
572 1
573 1 if (!GetDesc())
574 1 return FALSE; // For this current device:
575 1 uDev.wVID = pDev->idVendor; // save VID
576 1 uDev.wPID = pDev->idProduct; // save PID
577 1 uDev.iMfg = pDev->iManufacturer; // save Mfg Index
578 1 uDev.iPdt = pDev->iProduct; // save Product Index
579 1
580 1 //------------------------------------------------
581 1 // Get String Descriptors
582 1 //------------------------------------------------
583 1 //------------------------------------------------
584 1 // Get Slave USB Configuration Descriptors
585 1 //------------------------------------------------
586 1
587 1 pCfg = (pCfgDesc)DBUF;
588 1
589 1 usbstack.usbaddr=uAddr;
590 1 usbstack.setup.wValue=CONFIGURATION;
591 1 usbstack.setup.wIndex=0;
592 1 usbstack.setup.wLength=64;
593 1 usbstack.buffer=DBUF;
594 1 if (!GetDesc())
595 1 return FALSE;
596 1
597 1 pIfc = (pIntfDesc)(DBUF + 9); // point to Interface Descp
598 1 uDev.bClass = pIfc->iClass; // update to class type
599 1 uDev.bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;
600 1
601 1 if(uDev.bClass==8) //mass storage device
602 1 bXXGFlags.bits.bMassDevice=TRUE;
603 1 //------------------------------------------------
604 1 // Set configuration (except for HUB device)
605 1 //------------------------------------------------
606 1 usbstack.usbaddr=uAddr;
607 1 usbstack.setup.wValue=DEVICE;
608 1 //if (uDev[usbaddr].bClass!=HUBCLASS) // enumerating a FS/LS non-hub device
609 1 if (!Set_Configuration()) // connected directly to SL811HS
610 1 return FALSE;
611 1
612 1 //------------------------------------------------
C51 COMPILER V6.20c SL811 08/21/2003 22:51:04 PAGE 11
613 1 // For each slave endpoints, get its attributes
614 1 // Excluding endpoint0, only data endpoints
615 1 //------------------------------------------------
616 1
617 1 epLen = 0;
618 1 for (i=1; i<=uDev.bNumOfEPs; i++) // For each data endpoint
619 1 {
620 2 pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen); // point to Endpoint Descp(non-HID)
621 2 //if(pIfc->iClass == HIDCLASS)
622 2 // pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen); // update pointer to Endpoint(HID)
623 2 uDev.bEPAddr[i] = pEnp->bEPAdd; // Ep address and direction
624 2 uDev.bAttr[i] = pEnp->bAttr; // Attribute of Endpoint
625 2 uDev.wPayLoad[i] = WordSwap(pEnp->wPayLoad); // Payload of Endpoint
626 2 uDev.bInterval[i] = pEnp->bInterval; // Polling interval
627 2 uDev.bData1[i] = 0; // init data toggle
628 2 epLen += 7;
629 2 //////////////////////////////
630 2 if(uDev.bAttr[i]==0x2)
631 2 {
632 3 if(uDev.bEPAddr[i]&0x80)
633 3 usbstack.epbulkin=uDev.bEPAddr[i];
634 3 else
635 3 usbstack.epbulkout=uDev.bEPAddr[i];
636 3 }
637 2 //////////////////////////////
638 2 }
639 1
640 1 return TRUE;
641 1 }
642
643 ///////////////////////////////////////////////////////////////////////////////////////////
644 void SL811_Init(void)
645 {
646 1 bXXGFlags.bits.SLAVE_ONLINE = FALSE;
647 1 bXXGFlags.bits.SLAVE_FOUND = FALSE;
648 1 bXXGFlags.bits.SLAVE_REMOVED=FALSE;
649 1
650 1 bXXGFlags.bits.SLAVE_ENUMERATED = FALSE;
651 1 bXXGFlags.bits.SLAVE_IS_ATTACHED = FALSE;
652 1
653 1 SL811_CS=0;
654 1 ///////////////////////////////////////////////////////
655 1
656 1 SL811Write(cDATASet,0xe0);
657 1 SL811Write(cSOFcnt,0xae);
658 1 SL811Write(CtrlReg,0x5);
659 1
660 1 SL811Write(EP0Status,0x50);
661 1 SL811Write(EP0Counter,0);
662 1 SL811Write(EP0Control,0x01);
663 1
664 1
665 1 SL811Write(IntEna,0x20); // USB-A, Insert/Remove, USB_Resume.
666 1 SL811Write(IntStatus,INT_CLEAR); // Clear Interrupt enable status
667 1 }
668
669 void check_key_LED(void)
670 {
671 1 static unsigned char last_key=0x7;
672 1 unsigned char *pBuf;//=(unsigned char *)&UartCmdBlock;
673 1 unsigned int *wpBuf;
674 1 unsigned char intr;
C51 COMPILER V6.20c SL811 08/21/2003 22:51:04 PAGE 12
675 1 unsigned int i,len;
676 1 //SL811Write(IntStatus,INSERT_REMOVE);
677 1 intr=SL811Read(IntStatus);
678 1 if(intr & USB_RESET)
679 1 {
680 2 //bXXGFlags.bits.SLAVE_IS_ATTACHED = FALSE; // Set USB device found flag
681 2 if(bXXGFlags.bits.SLAVE_ONLINE ==TRUE)
682 2 {bXXGFlags.bits.SLAVE_REMOVED=TRUE;
683 3 bXXGFlags.bits.SLAVE_ONLINE =FALSE;}
684 2 }
685 1 else {
686 2 //bXXGFlags.bits.SLAVE_IS_ATTACHED = TRUE;
687 2 if(bXXGFlags.bits.SLAVE_ONLINE == FALSE)
688 2 {bXXGFlags.bits.SLAVE_FOUND=TRUE;
689 3 bXXGFlags.bits.SLAVE_ONLINE =TRUE;}
690 2 }
691 1 //bXXGFlags.bits.SLAVE_FOUND;
692 1
693 1 //bXXGFlags.bits.SLAVE_REMOVED=0;
694 1 SL811Write(IntStatus,INT_CLEAR);
695 1 SL811Write(IntStatus,INSERT_REMOVE);
696 1
697 1 /////// for test only /////////////////////
698 1 intr=SWM0;
699 1 intr&=0x1;
700 1 if(intr!=last_key)
701 1 {
702 2 if(intr==0)
703 2 {
704 3 pBuf=(unsigned char *)&UartCmdBlock;
705 3 for(i=0;i<64;i++)
706 3 *(pBuf+i)=*(cmd_test_createfile+i);
707 3 bXXGFlags.bits.bUartInDone=1;
708 3 last_key=0;
709 3 }
710 2 else
711 2 last_key=1;
712 2 }
713 1 ////////////////////////////////////////////
714 1 intr=SWM1;
715 1 intr&=0x1;
716 1 if(intr!=last_key)
717 1 {
718 2 if(intr==0)
719 2 {
720 3 pBuf=(unsigned char *)&UartCmdBlock;
721 3 for(i=0;i<64;i++)
722 3 *(pBuf+i)=*(cmd_test_writefile+i);
723 3 wpBuf=(unsigned int *)UARTBUF;
724 3 len=SwapINT16(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)/2;
725 3 for(i=0;i<len;i++)
726 3 *(wpBuf+i)=i;
727 3 bXXGFlags.bits.bUartInDone=1;
728 3 last_key=0;
729 3 }
730 2 else
731 2 last_key=1;
732 2 }
733 1
734 1 /////////////////////////////////////////////
735 1 }
C51 COMPILER V6.20c SL811 08/21/2003 22:51:04 PAGE 13
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1894 ----
CONSTANT SIZE = 124 ----
XDATA SIZE = 512 ----
PDATA SIZE = ---- ----
DATA SIZE = 21 33
IDATA SIZE = 45 ----
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 + -