📄 protocol.lst
字号:
571 // Out: None
572 // Function:
573 // In order to tell firmware that host application now is started,we use
574 // vendor defined request NotifyAppStart() to notify our firmware;when received
575 // this request,firmware refresh LED initial status and return current switch
576 // status to host,thus device's LED and switch has the same status with host
577 // application software .
578 void NotifyAppStart(void)
579 {
580 1 unsigned char data bSwitchStatus;
581 1
582 1 //refresh LED status
583 1 mEp1OutBuffer[0] = (unsigned char)(sSysInformation.sUsbDeviceRequest.wValue);
584 1 LED_ADDRESS = mEp1OutBuffer[0];
585 1 //return switch status
586 1 bSwitchStatus = SWITCH_ADDRESS;
587 1 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN,0x01,&bSwitchStatus);
588 1 sSysInformation.sUsbSetUpDealwith.wRemaindLength = 0;
589 1
590 1 }
591
592 /////////////////////////////////////////////////////////////////////////////////
593 ///////////////////////////////other routine/////////////////////////////////////
594
595 //
596 //*************************************************************************
597 // Parameter:
598 // In : None
599 // Out: None
600 // Function:
601 // After control-out transfer will finish,we set correspoding flag and
602 // return zero length data packet as status stage to complete this
603 // transfer.
604 void ControlOutComplete(void)
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 11
605 {
606 1 unsigned char data bNone = 0; //it is only used to provid a address needed by funcion D12WriteBuffer(),
607 1 //and it has no meaning when return zero length data packet to Host
608 1 //When control-out transfer will be finished,we set bControOutCommandIsPending
609 1 //flag,and return zero length data packet as status stage to complete this control-out
610 1 //transfer.
611 1 //see 8.5.3.1"
612 1 sSysInformation.sUsbSetUpDealwith.bControOutCommandIsPending = FALSE;
613 1 D12WriteBuffer(D12_SELECT_ENDPOINT_CONTROL_IN, 0x00, &bNone);
614 1 }
615
616 //
617 //*************************************************************************
618 // Parameter:
619 // In : None
620 // Out: None
621 // Function:
622 // This firmware implement SetDescriptor() and SetDeviceSerialNumber()
623 // request which all are control-out transfer with a data stage.Deal with
624 // them has some different from other contro-out transfer that without
625 // data stage.We should wait until all data are received and then deal
626 // with it.
627 void ControlOutDealWith(void)
628 {
629 1 if (sSysInformation.sUsbSetUpDealwith.bControlOutDataComplete == TRUE)
630 1 {
631 2 if (sSysInformation.sUsbDeviceRequest.bRequest == USB_REQUEST_SET_DESCRIPTOR)
632 2 SetDescriptor();
633 2 else if (sSysInformation.sUsbDeviceRequest.bRequest == SET_DEVICE_SERIAL_NUMBER)
634 2 SetDeviceSerialNumber();
635 2
636 2 //because UsbSetUpDeal() has already checked whether bRequest is valid,
637 2 //so here no necessary to check bRequest again.
638 2 }
639 1 }
640 //
641 //*************************************************************************
642 // Parameter:
643 // In : None
644 // Out: None
645 // Function:
646 // When received a setup packet,this function dispatch routine according to
647 // different request.
648 void UsbSetUpDeal(void)
649 {
650 1 //This routine complete contro-in, and control-out that without data stage.
651 1 //For control-out with data stage,when data receice is finished,deal with them
652 1 //at ControlOutDealWith().
653 1
654 1 //if setup packet is USB standard request.
655 1 if ((sSysInformation.sUsbDeviceRequest.bmRequestType & USB_REQUEST_BMREQUESTTYPE_TPYE_MASK)\
656 1 == USB_REQUEST_BMREQUESTTYPE_TPYE_STANDARD)
657 1 {
658 2 switch(sSysInformation.sUsbDeviceRequest.bRequest )
659 2 {
660 3 case USB_REQUEST_GET_STATUS :
661 3 GetStatus();
662 3 break;
663 3 case USB_REQUEST_CLEAR_FEATURE :
664 3 ClearFeature();
665 3 break;
666 3 case USB_REQUEST_SET_FEATURE :
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 12
667 3 SetFeature();
668 3 break;
669 3 case USB_REQUEST_SET_ADDRESS :
670 3 SetAddress();
671 3 break;
672 3 case USB_REQUEST_GET_DESCRIPTOR :
673 3 GetDescriptor();
674 3 break;
675 3 case USB_REQUEST_SET_DESCRIPTOR:
676 3 //because SetDescriptor request has data stage,
677 3 //so here we have nothing to do. When data is received,
678 3 //deal with it in ControlOutDealWith() routine
679 3 break;
680 3 case USB_REQUEST_GET_CONFIGURATION :
681 3 GetConfiguration();
682 3 break;
683 3 case USB_REQUEST_SET_CONFIGURATION :
684 3 SetConfiguration();
685 3 break;
686 3 case USB_REQUEST_GET_INTERFACE:
687 3 GetInterface();
688 3 break;
689 3 case USB_REQUEST_SET_INTERFACE:
690 3 SetInterface();
691 3 break;
692 3 case USB_REQUEST_SYNC_FRAME:
693 3 ReadSynFrameNumber();
694 3 break;
695 3 case 2 :
696 3 case 4 :
697 3 default:
698 3 CONTROL_ENDPOINT_STALL //set control endpoint stall
699 3 break;
700 3 }
701 2 }
702 1 //else if USB request is Vendor request
703 1 else if ((sSysInformation.sUsbDeviceRequest.bmRequestType & USB_REQUEST_BMREQUESTTYPE_TPYE_MASK)\
704 1 == USB_REQUEST_BMREQUESTTYPE_TPYE_VENDOR)
705 1 {
706 2 switch(sSysInformation.sUsbDeviceRequest.bRequest )
707 2 {
708 3 //set looptest command
709 3 case RAM_COMMAND_LOOPBACK :
710 3 //set read ram command
711 3 case RAM_COMMAND_READ :
712 3 //set write ram command
713 3 case RAM_COMMAND_WRITE :
714 3 //for this firmware,RamControl is refered as ram control;
715 3 //include ram read ,ram write and loopback test
716 3 //sSysInformation.sUsbSetUpDealwith.bControOutCommandIsPending = TRUE;
717 3 RamControl();
718 3 break;
719 3 //get firmware version command,it is a control-in transfer with data stage
720 3 case GET_FIRMWARE_VERSION:
721 3 GetFirmWareVersion();
722 3 break;
723 3 //set device serial number command is a control-out transfer with data stage
724 3 //note this only is an example to demenstrate how to deal with control-out
725 3 //transfer with data stage;serial number will be saved to mSerialNumber,and lost
726 3 //when powered off.
727 3 case SET_DEVICE_SERIAL_NUMBER:
728 3 //because SetDeviceSerialNumber() request has data stage,
C51 COMPILER V7.01 PROTOCOL 02/17/2006 15:09:24 PAGE 13
729 3 //so here we have nothing to do. When data is received,
730 3 //deal with it in ControlOutDealWith() routine
731 3 break;
732 3 case NOTIFY_APP_START:
733 3 NotifyAppStart();
734 3 break;
735 3 //all other vendor request will be dealwith by user
736 3 default:
737 3 CONTROL_ENDPOINT_STALL //set control endpoint stall
738 3 break;
739 3 }
740 2
741 2 }
742 1 else
743 1 {
744 2 //this firmware does not support other request type,so stall endpoint0 here.
745 2 //If needed,user can implement other request type here.
746 2 CONTROL_ENDPOINT_STALL //set control endpoint stall
747 2 }
748 1
749 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1165 ----
CONSTANT SIZE = 291 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 13
IDATA SIZE = ---- ----
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 + -