📄 usbd_udphs.lst
字号:
651
652 pTransfer->transferred = pTransfer->buffered
653 - ((status & AT91C_UDPHS_BUFF_COUNT) >> 16);
654 pTransfer->remaining = 0;
655 trace_LOG(trace_DEBUG, "\n\rR:%d ", pTransfer->remaining );
656 trace_LOG(trace_DEBUG, "B:%d ", pTransfer->buffered );
657 trace_LOG(trace_DEBUG, "T:%d ", pTransfer->transferred );
658 }
659 else {
660
661 trace_LOG(trace_ERROR, "UDPHS_DmaHandler: Error (0x%08X)\n\r", status);
662 result = USBD_STATUS_ABORTED;
663 }
664
665 // Invoke callback
666 if( pTransfer->remaining == 0 ) {
667
668 trace_LOG(trace_DEBUG, "EOT ");
669 UDPHS_EndOfTransfer(bEndpoint, result);
670 }
671 }
672 #endif
673
674
675 //------------------------------------------------------------------------------
676 // Exported functions
677 //------------------------------------------------------------------------------
678
679 //------------------------------------------------------------------------------
680 // UDP interrupt handler
681 // Manages device resume, suspend, end of bus reset. Forwards endpoint
682 // interrupts to the appropriate handler.
683 //------------------------------------------------------------------------------
684 void USBD_InterruptHandler(void)
685 {
686 unsigned int status;
687 unsigned char numIT;
688
689 if (deviceState >= USBD_STATE_POWERED) {
690
691 LED_Set(USBD_LEDUSB);
692 }
693
694 // Get interrupts status
695 status = AT91C_BASE_UDPHS->UDPHS_INTSTA & AT91C_BASE_UDPHS->UDPHS_IEN;
696
697 // Handle all UDPHS interrupts
698 trace_LOG(trace_DEBUG, "H");
699 while (status != 0) {
700
701 // Start Of Frame (SOF)
702 if ((status & AT91C_UDPHS_IEN_SOF) != 0) {
703
704 trace_LOG(trace_DEBUG, "SOF ");
705
706 // Invoke the SOF callback
707 //USB_StartOfFrameCallback(pUsb);
708
709 // Acknowledge interrupt
710 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_IEN_SOF;
711 status &= ~AT91C_UDPHS_IEN_SOF;
712 }
713 // Suspend
714 // This interrupt is always treated last (hence the '==')
715 else if (status == AT91C_UDPHS_DET_SUSPD) {
716
717 trace_LOG(trace_DEBUG, "S");
718
719 // The device enters the Suspended state
720 // MCK + UDPCK must be off
721 // Pull-Up must be connected
722 // Transceiver must be disabled
723
724 LED_Clear(USBD_LEDUSB);
725
726 UDPHS_DisableBIAS();
727
728 // Enable wakeup
729 AT91C_BASE_UDPHS->UDPHS_IEN |= AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_ENDOFRSM;
730 AT91C_BASE_UDPHS->UDPHS_IEN &= ~AT91C_UDPHS_DET_SUSPD;
731
732 // Acknowledge interrupt
733 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_DET_SUSPD | AT91C_UDPHS_WAKE_UP;
734 previousDeviceState = deviceState;
735 deviceState = USBD_STATE_SUSPENDED;
736 UDPHS_DisableUsbClock();
737
738 // Invoke the Suspend callback
739 USBDCallbacks_Suspended();
740 }
741 // Resume
742 else if( ((status & AT91C_UDPHS_WAKE_UP) != 0) // line activity
743 || ((status & AT91C_UDPHS_ENDOFRSM) != 0)) { // pc wakeup
744
745 //JCB
746 #ifdef NOT_DEFINED
747 #if !defined(PIN_USB_VBUS)
748 // Configure PIO
749 PIO_Configure(&pinVbus, 1);
750
751 // Check current level on VBus
752 if (PIO_Get(&pinVbus) == 1) // Protection
753 #endif
754 #endif
755 {
756 // Invoke the Resume callback
757 USBDCallbacks_Resumed();
758
759 trace_LOG(trace_DEBUG, "R");
760
761 UDPHS_EnableUsbClock();
762 UDPHS_EnableBIAS();
763
764 // The device enters Configured state
765 // MCK + UDPCK must be on
766 // Pull-Up must be connected
767 // Transceiver must be enabled
768
769 deviceState = previousDeviceState;
770
771 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_ENDOFRSM | AT91C_UDPHS_DET_SUSPD;
772
773 AT91C_BASE_UDPHS->UDPHS_IEN |= AT91C_UDPHS_ENDOFRSM | AT91C_UDPHS_DET_SUSPD;
774 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_ENDOFRSM;
775 AT91C_BASE_UDPHS->UDPHS_IEN &= ~AT91C_UDPHS_WAKE_UP;
776 }
777 // jcb !!!
778 #ifdef NOT_DEFINED
779 #if !defined(PIN_USB_VBUS)
780 else {
781
782 // No VBUS
783 // Disconnect the pull-up
784 USBD_Disconnect();
785 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_WAKE_UP;
786 }
787 #endif
788 #endif
789 }
790 // End of bus reset
791 else if ((status & AT91C_UDPHS_ENDRESET) == AT91C_UDPHS_ENDRESET) {
792
793 // trace_LOG(trace_DEBUG, "EoB ");
794
795 // The device enters the Default state
796 deviceState = USBD_STATE_DEFAULT;
797 // MCK + UDPCK are already enabled
798 // Pull-Up is already connected
799 // Transceiver must be enabled
800 // Endpoint 0 must be enabled
801
802 UDPHS_ResetEndpoints();
803 UDPHS_DisableEndpoints();
804 USBD_ConfigureEndpoint(0);
805
806 // Flush and enable the Suspend interrupt
807 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_WAKE_UP | AT91C_UDPHS_DET_SUSPD;
808
809 //// Enable the Start Of Frame (SOF) interrupt if needed
810 //if (pCallbacks->startOfFrame != 0)
811 //{
812 // AT91C_BASE_UDPHS->UDPHS_IEN |= AT91C_UDPHS_IEN_SOF;
813 //}
814
815 // Invoke the Reset callback
816 USBDCallbacks_Reset();
817
818 // Acknowledge end of bus reset interrupt
819 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_ENDRESET;
820
821 AT91C_BASE_UDPHS->UDPHS_IEN |= AT91C_UDPHS_DET_SUSPD;
822 }
823 // Handle upstream resume interrupt
824 else if (status & AT91C_UDPHS_UPSTR_RES) {
825
826 trace_LOG(trace_DEBUG, "ExtRes ");
827
828 // - Acknowledge the IT
829 AT91C_BASE_UDPHS->UDPHS_CLRINT = AT91C_UDPHS_UPSTR_RES;
830 }
831 // Endpoint interrupts
832 else {
833 #ifndef DMA
834 // Handle endpoint interrupts
835 for (numIT = 0; numIT < NUM_IT_MAX; numIT++) {
836
837 if ((status & (1 << SHIFT_INTERUPT << numIT)) != 0) {
838
839 UDPHS_EndpointHandler(numIT);
840 }
841 }
842 #else
843 // Handle endpoint control interrupt
844 if ((status & (1 << SHIFT_INTERUPT << 0)) != 0) {
845
846 UDPHS_EndpointHandler( 0 );
847 }
848 else {
849
850 numIT = 1;
851 while((status&(0x7E<<SHIFT_DMA)) != 0) {
852
853 // Check if endpoint has a pending interrupt
854 if ((status & (1 << SHIFT_DMA << numIT)) != 0) {
855
856 UDPHS_DmaHandler(numIT);
857 status &= ~(1 << SHIFT_DMA << numIT);
858 if (status != 0) {
859
860 trace_LOG(trace_INFO, "\n\r - ");
861 }
862 }
863 numIT++;
864 }
865 }
866 #endif
867 }
868
869 // Retrieve new interrupt status
870 status = AT91C_BASE_UDPHS->UDPHS_INTSTA & AT91C_BASE_UDPHS->UDPHS_IEN;
871
872 trace_LOG(trace_DEBUG, "\n\r");
873 if (status != 0) {
874
875 trace_LOG(trace_DEBUG, " - ");
876 }
877 }
878
879 if (deviceState >= USBD_STATE_POWERED) {
880
881 LED_Clear(USBD_LEDUSB);
882 }
883 }
884
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -