📄 sl811.lst
字号:
531 {
532 1 unsigned char i; // always reset USB transfer address
533 1 unsigned char uAddr = 0; // for enumeration to Address #0
534 1 unsigned char epLen;
535 1 //unsigned short strLang;
536 1
537 1 pDevDesc pDev;
538 1 pCfgDesc pCfg;
539 1 pIntfDesc pIfc;
540 1 pEPDesc pEnp;
541 1 //------------------------------------------------
542 1 // Reset only Slave device attached directly
543 1 //------------------------------------------------
544 1 uDev.wPayLoad[0] = 8; // default 64-byte payload of Endpoint 0, address #0
545 1 if(usbaddr == 1) // bus reset for the device attached to SL811HS only
546 1 USBReset(); // that will always have the USB address = 0x01 (for a hub)
547 1
548 1 DelayMs(25);
549 1
550 1 //------------------------------------------------
C51 COMPILER V6.20c SL811 04/07/2005 10:50:50 PAGE 10
551 1 // Get USB Device Descriptors on EP0 & Addr 0
552 1 // with default 64-byte payload
553 1 //------------------------------------------------
554 1 pDev =(pDevDesc)DBUF; // ask for 64 bytes on Addr #0
555 1
556 1 usbstack.usbaddr=uAddr;
557 1 usbstack.setup.wValue=DEVICE;
558 1 usbstack.setup.wIndex=0;
559 1 usbstack.setup.wLength=18;
560 1 //usbstack.setup.wLength=sbstack.setup.wLength);
561 1 usbstack.buffer=DBUF;
562 1
563 1 if (!GetDesc()) // and determine the wPayload size
564 1 return FALSE; // get correct wPayload of Endpoint 0
565 1 uDev.wPayLoad[0]=pDev->bMaxPacketSize0;// on current non-zero USB address
566 1
567 1 //------------------------------------------------
568 1 // Set Slave USB Device Address
569 1 //------------------------------------------------
570 1 if (!SetAddress(usbaddr)) // set to specific USB address
571 1 return FALSE; //
572 1 uAddr = usbaddr; // transfer using this new address
573 1 //------------------------------------------------
574 1 // Get USB Device Descriptors on EP0 & Addr X
575 1 //------------------------------------------------
576 1 pDev =(pDevDesc)DBUF;
577 1 usbstack.usbaddr=uAddr;
578 1
579 1 usbstack.setup.wLength=pDev->bLength;
580 1 usbstack.setup.wValue=DEVICE;
581 1 usbstack.setup.wIndex=0;
582 1
583 1 //usbstack.setup.wLength=0x12;//(unsigned short)DBUF[0];//pDev->bLength;
584 1 usbstack.buffer=DBUF;
585 1
586 1 if (!GetDesc())
587 1 return FALSE; // For this current device:
588 1 uDev.wVID = pDev->idVendor; // save VID
589 1 uDev.wPID = pDev->idProduct; // save PID
590 1 uDev.iMfg = pDev->iManufacturer; // save Mfg Index
591 1 uDev.iPdt = pDev->iProduct; // save Product Index
592 1
593 1 //------------------------------------------------
594 1 // Get String Descriptors
595 1 //------------------------------------------------
596 1 //------------------------------------------------
597 1 // Get Slave USB Configuration Descriptors
598 1 //------------------------------------------------
599 1
600 1 pCfg = (pCfgDesc)DBUF;
601 1
602 1 usbstack.usbaddr=uAddr;
603 1 usbstack.setup.wValue=CONFIGURATION;
604 1 usbstack.setup.wIndex=0;
605 1 usbstack.setup.wLength=64;
606 1 usbstack.buffer=DBUF;
607 1 if (!GetDesc())
608 1 return FALSE;
609 1
610 1 pIfc = (pIntfDesc)(DBUF + 9); // point to Interface Descp
611 1 uDev.bClass = pIfc->iClass; // update to class type
612 1 uDev.bNumOfEPs = (pIfc->bEndPoints <= MAX_EP) ? pIfc->bEndPoints : MAX_EP;
C51 COMPILER V6.20c SL811 04/07/2005 10:50:50 PAGE 11
613 1
614 1 if(uDev.bClass==8) //mass storage device
615 1 bXXGFlags.bMassDevice=TRUE;
616 1 else
617 1 return FALSE;
618 1 //------------------------------------------------
619 1 // Set configuration (except for HUB device)
620 1 //------------------------------------------------
621 1 usbstack.usbaddr=uAddr;
622 1 //if (uDev[usbaddr].bClass!=HUBCLASS) // enumerating a FS/LS non-hub device
623 1 if (!Set_Configuration()) // connected directly to SL811HS
624 1 return FALSE;
625 1 if (!Set_Interface())
626 1 return FALSE;
627 1 //------------------------------------------------
628 1 // For each slave endpoints, get its attributes
629 1 // Excluding endpoint0, only data endpoints
630 1 //------------------------------------------------
631 1
632 1 epLen = 0;
633 1 for (i=1; i<=uDev.bNumOfEPs; i++) // For each data endpoint
634 1 {
635 2 pEnp = (pEPDesc)(DBUF + 9 + 9 + epLen); // point to Endpoint Descp(non-HID)
636 2 //if(pIfc->iClass == HIDCLASS)
637 2 // pEnp = (pEPDesc)(DBUF + 9 + 9 + 9 + epLen); // update pointer to Endpoint(HID)
638 2 uDev.bEPAddr[i] = pEnp->bEPAdd; // Ep address and direction
639 2 uDev.bAttr[i] = pEnp->bAttr; // Attribute of Endpoint
640 2 uDev.wPayLoad[i] = WordSwap(pEnp->wPayLoad); // Payload of Endpoint
641 2 uDev.bInterval[i] = pEnp->bInterval; // Polling interval
642 2 uDev.bData1[i] = 0; // init data toggle
643 2 epLen += 7;
644 2 uDev.bData1[i]=0;
645 2 bXXGFlags.bData1=0;
646 2 //////////////////////////////
647 2 if(uDev.bAttr[i]==0x2)
648 2 {
649 3 if(uDev.bEPAddr[i]&0x80)
650 3 usbstack.epbulkin=uDev.bEPAddr[i];
651 3 else
652 3 usbstack.epbulkout=uDev.bEPAddr[i];
653 3 }
654 2 //////////////////////////////
655 2 }
656 1 /////////////////////////
657 1 usbstack.buffer=DBUF;
658 1 if(!GetMaxLUN())
659 1 return FALSE;
660 1 opLun=DBUF[0]&0x03;
661 1 ////////////////////////
662 1 return TRUE;
663 1 }
664
665 ///////////////////////////////////////////////////////////////////////////////////////////
666 void SL811_Init(void)
667 {
668 1
669 1 SL811_CS=0;
670 1 ///////////////////////////////////////////////////////
671 1 SL811Write(cDATASet,0xe0);
672 1 SL811Write(cSOFcnt,0xae);
673 1 SL811Write(CtrlReg,0x5);
674 1
C51 COMPILER V6.20c SL811 04/07/2005 10:50:50 PAGE 12
675 1 SL811Write(EP0Status,0x50);
676 1 SL811Write(EP0Counter,0);
677 1 SL811Write(EP0Control,0x01);
678 1
679 1 SL811Write(IntEna,0x20); // USB-A, Insert/Remove, USB_Resume.
680 1 SL811Write(IntStatus,INT_CLEAR); // Clear Interrupt enable status
681 1 }
682
683 void check_key_LED(void)
684 {
685 1 /* static unsigned char last_key=0x7;
686 1 unsigned char *pBuf;//=(unsigned char *)&UartCmdBlock;
687 1 unsigned int *wpBuf;
688 1 unsigned char intr;
689 1 unsigned int i,len,j;
690 1 //SL811Write(IntStatus,INSERT_REMOVE);
691 1 /////// for test only /////////////////////
692 1 intr=SWM0;
693 1 intr&=0x1;
694 1 if(intr!=last_key)
695 1 {
696 1 if(intr==0)
697 1 {
698 1 pBuf=(unsigned char *)&UartCmdBlock;
699 1 for(i=0;i<64;i++)
700 1 *(pBuf+i)=*(cmd_test_createfile+i);
701 1 UartHandler(1);
702 1 //bXXGFlags.bits.bUartInDone=1;
703 1 last_key=0;
704 1 }
705 1 else
706 1 last_key=1;
707 1 }
708 1 ////////////////////////////////////////////
709 1 intr=SWM1;
710 1 intr&=0x1;
711 1 if(intr!=last_key)
712 1 {
713 1 if(intr==0)
714 1 {
715 1 pBuf=(unsigned char *)&UartCmdBlock;
716 1 for(i=0;i<64;i++)
717 1 *(pBuf+i)=*(cmd_test_writefile+i);
718 1
719 1 wpBuf=(unsigned int *)UARTBUF;
720 1 len=SwapINT16(UartCmdBlock.CmdBlock.Cmd_WriteFile.writeLength)/2;
721 1 for(i=0;i<len;i++)
722 1 *(wpBuf+i)=i;
723 1
724 1 UartHandler(1);
725 1 //bXXGFlags.bits.bUartInDone=1;
726 1 last_key=0;
727 1 }
728 1 else
729 1 last_key=1;
730 1 }
731 1 */
732 1 }
733
734 void check_usbdevice(void)
735 {
736 1 unsigned char intr;
C51 COMPILER V6.20c SL811 04/07/2005 10:50:50 PAGE 13
737 1 //SL811Write(IntStatus,INSERT_REMOVE);
738 1 intr=SL811Read(IntStatus);
739 1 SL811Write(IntStatus,INT_CLEAR);
740 1 SL811Write(IntStatus,INSERT_REMOVE);
741 1
742 1 if(intr & 0x40) // This bit is "1" -> Device not present
743 1 {
744 2 if(bXXGFlags.SLAVE_ONLINE ==1)
745 2 {
746 3 MCU_LED0=1;
747 3 MCU_LED1=1;
748 3 bXXGFlags.UDiskOK = FALSE;
749 3 bXXGFlags.SLAVE_ONLINE =0;
750 3 USBReset();
751 3
752 3 }
753 2 }
754 1 else // This bit is "0" -> Device is present
755 1 {
756 2 if(bXXGFlags.SLAVE_ONLINE == 0)
757 2 {
758 3 DelayMs(250);
759 3 if(!EnumUsbDev(1)) //step 1: enumerate USB device, assign USB address = #1
760 3 {
761 4 USBReset();
762 4 return;
763 4 }
764 3 MCU_LED0=0;
765 3 if(EnumMassDev()) //step 2: emumerate U-Disk
*** WARNING C206 IN LINE 765 OF SL811.C: 'EnumMassDev': missing function-prototype
766 3 {
767 4 bXXGFlags.UDiskOK = TRUE;
768 4 MCU_LED1=0;
769 4 }
770 3 else
771 3 {
772 4 MCU_LED1=1;
773 4 bXXGFlags.UDiskOK = FALSE;
774 4 USBReset();
775 4 }
776 3
777 3 bXXGFlags.SLAVE_ONLINE =1;
778 3 return;
779 3
780 3 }
781 2 }
782 1 return;
783 1
784 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1825 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 4096 ----
PDATA SIZE = ---- ----
DATA SIZE = 20 20
IDATA SIZE = 47 8
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -