📄 f34x_usb_isr.lst
字号:
570 1 gEp2OutStatus.bEpState = EP_HALTED; // Reset state
571 1 gEp2OutStatus.uNumBytes = 0; // Reset byte counter
572 1
573 1 // Get Suspend enable/disable status. If enabled, prepare temporary
574 1 // variable bPower.
575 1 if (SUSPEND_ENABLE)
576 1 {
577 2 bPower = 0x01; // Set bit0 (Suspend Enable)
578 2 }
579 1
580 1 // Get ISO Update enable/disable status. If enabled, prepare temporary
581 1 // variable bPower.
582 1 if (ISO_UPDATE_ENABLE)
583 1 {
584 2 bPower |= 0x80; // Set bit7 (ISO Update Enable)
585 2 }
586 1
587 1 UWRITE_BYTE(POWER, bPower);
588 1 }
589
590
591 //-----------------------------------------------------------------------------
592 // Page_Erase
593 //-----------------------------------------------------------------------------
594 //
595 // Return Value : None
596 // Parameters :
597 // 1) BYTE* Page_Address
598 //
599 // Erases the page of FLASH located at Page_Address
600 //-----------------------------------------------------------------------------
601 void Page_Erase (BYTE* Page_Address) small
602 {
603 1 BYTE EA_Save; // Used to save state of global
604 1 // interrupt enable
605 1 BYTE xdata *pwrite; // xdata pointer used to generate movx
606 1
607 1 EA_Save = EA; // Save current EA
608 1 EA = 0; // Turn off interrupts
609 1 pwrite = (BYTE xdata *)(Page_Address); // Set write pointer to Page_Address
610 1 PSCTL = 0x03; // Enable flash erase and writes
611 1
612 1 FLKEY = 0xA5; // Write flash key sequence to FLKEY
613 1 FLKEY = 0xF1;
C51 COMPILER V8.08 F34X_USB_ISR 06/23/2008 15:53:52 PAGE 11
614 1 *pwrite = 0x00; // Erase flash page using a
615 1 // write command
616 1
617 1 PSCTL = 0x00; // Disable flash erase and writes
618 1 EA = EA_Save; // Restore state of EA
619 1 }
620
621 //-----------------------------------------------------------------------------
622 // USBReset
623 //-----------------------------------------------------------------------------
624 //
625 // Return Value : None
626 // Parameters :
627 // 1) BYTE* PageAddress
628 //
629 // Writes data to the page of FLASH located at PageAddress
630 //-----------------------------------------------------------------------------
631 void Page_Write (BYTE* PageAddress) small
632 {
633 1 BYTE EA_Save; // Used to save state of global
634 1 // interrupt enable
635 1 BYTE xdata *pwrite; // Write Pointer
636 1 BYTE xdata *pread; // Read Pointer
637 1 UINT x; // Counter for 0-512 bytes
638 1
639 1 pread = (BYTE xdata *)(TempStorage);
640 1 EA_Save = EA; // Save EA
641 1 EA = 0; // Turn off interrupts
642 1 pwrite = (BYTE xdata *)(PageAddress);
643 1 PSCTL = 0x01; // Enable flash writes
644 1 for(x = 0; x<FLASH_PAGE_SIZE; x++) // Write 512 bytes
645 1 {
646 2 FLKEY = 0xA5; // Write flash key sequence
647 2 FLKEY = 0xF1;
648 2 *pwrite = *pread; // Write data byte to flash
649 2
650 2 pread++; // Increment pointers
651 2 pwrite++;
652 2 }
653 1 PSCTL = 0x00; // Disable flash writes
654 1 EA = EA_Save; // Restore EA
655 1 }
656
657 //-----------------------------------------------------------------------------
658 // State_Machine
659 //-----------------------------------------------------------------------------
660 //
661 // Return Value : None
662 // Parameters : None
663 //
664 // Determine new state and act on current state
665 //-----------------------------------------------------------------------------
666 void State_Machine(void)
667 {
668 1 switch (M_State)
669 1 {
670 2
671 2 case
672 2 ST_WAIT_DEV: // Stay in Wait State
673 2 break;
674 2
675 2 case
C51 COMPILER V8.08 F34X_USB_ISR 06/23/2008 15:53:52 PAGE 12
676 2 ST_IDLE_DEV: // Stay in Idle State
677 2 break;
678 2
679 2 case ST_RX_SETUP:
680 2 Receive_Setup(); // Decode host Setup Message
681 2 break;
682 2
683 2 case ST_RX_FILE:
684 2 Receive_File(); // Receive File data from host
685 2 break;
686 2
687 2 case ST_TX_ACK:
688 2 M_State = ST_RX_FILE; // Ack complete, continue RX data
689 2 break;
690 2
691 2 case ST_TX_FILE: // Send file data to host
692 2 if(BytesToWrite > MAX_BLOCK_SIZE)
693 2 {
694 3 BulkOrInterruptIn(&gEp1InStatus, (BYTE*)(ReadIndex),MAX_BLOCK_SIZE);
695 3 //BytesToWrite -= MAX_BLOCK_SIZE;
696 3 //ReadIndex += MAX_BLOCK_SIZE;
697 3
698 3 // Try to write a second packet to the fifo here
699 3 if(BytesToWrite > MAX_BLOCK_SIZE)
700 3 {
701 4 BulkOrInterruptIn(&gEp1InStatus,
702 4 (BYTE*)(ReadIndex),MAX_BLOCK_SIZE);
703 4 }
704 3 else
705 3 {
706 4 BulkOrInterruptIn(&gEp1InStatus,
707 4 (BYTE*)(ReadIndex),BytesToWrite);
708 4 }
709 3 }
710 2 else
711 2 {
712 3 BulkOrInterruptIn(&gEp1InStatus, (BYTE*)(ReadIndex),BytesToWrite);
713 3 //BytesToWrite = 0;
714 3 //ReadIndex += BytesToWrite;
715 3 }
716 2 //BlocksWrote++;
717 2 if ((BlocksWrote%8) == 0)
718 2 {
719 3 Led2 = ~Led2;
720 3 }
721 2 if (BlocksWrote == NumBlocks)
722 2 {
723 3 Led2 = 0;
724 3 }
725 2 break;
726 2
727 2 default:
728 2 M_State = ST_ERROR; // Unknown State, stay in Error State
729 2 break;
730 2 }
731 1 }
732
733 //-----------------------------------------------------------------------------
734 // Receive_Setup
735 //-----------------------------------------------------------------------------
736 //
737 // Return Value : None
C51 COMPILER V8.08 F34X_USB_ISR 06/23/2008 15:53:52 PAGE 13
738 // Parameters : None
739 //
740 // Determines whether a read or write request has been received
741 // Initializes variables for either a read or write operation
742 //
743 //-----------------------------------------------------------------------------
744
745 void Receive_Setup(void)
746 {
747 1
748 1 if (Buffer[0] == READ_MSG) // Check See if Read File Setup
749 1 {
750 2 PageIndex = 0; // Reset Index
751 2 NumBlocks = LengthFile[2]; // Read NumBlocks from flash stg
752 2 NumBlocks = (NumBlocks > MAX_NUM_BLOCKS)? MAX_NUM_BLOCKS: NumBlocks;
753 2 Buffer[0] = SIZE_MSG; // Send host size of transfer message
754 2 Buffer[1] = LengthFile[1];
755 2 Buffer[2] = LengthFile[0];
756 2 BulkOrInterruptIn(&gEp1InStatus, &Buffer, 3);
757 2 M_State = ST_TX_FILE; // Go to TX data state
758 2 BlocksWrote = 0;
759 2 BytesToWrite = BytesToRead;
760 2 ReadIndex = PageIndices[0];
761 2 Led2 = 1;
762 2 }
763 1 else // Otherwise assume Write Setup Packet
764 1 {
765 2 BytesToRead = Buffer[1] + 256*Buffer[2];
766 2 NumBlocks = (BYTE)(BytesToRead/MAX_BLOCK_SIZE); // Find NumBlocks
767 2
768 2 if (NumBlocks > MAX_NUM_BLOCKS) // State Error if transfer too big
769 2 {
770 3 M_State = ST_ERROR;
771 3 }
772 2 else
773 2 {
774 3
775 3 if (BytesToRead % MAX_BLOCK_SIZE)
776 3 {
777 4 NumBlocks++; // Increment NumBlocks
778 4 // for last partial block
779 4 }
780 3
781 3 TempStorage[0].Piece[0] = Buffer[2];
782 3 TempStorage[0].Piece[1] = Buffer[1];
783 3 TempStorage[0].Piece[2] = NumBlocks;
784 3
785 3 // Write Values to Flash
786 3 Page_Erase(LengthFile); // Store file data to flash
787 3 Page_Write(LengthFile);
788 3
789 3 PageIndex = 0; // Reset Index
790 3 BlockIndex = 0;
791 3 BlocksRead = 0;
792 3 Led1 = 1;
793 3 M_State = ST_RX_FILE; // Go to RX data state
794 3 }
795 2 }
796 1 }
797
798 //-----------------------------------------------------------------------------
799 // Receive_Setup
C51 COMPILER V8.08 F34X_USB_ISR 06/23/2008 15:53:52 PAGE 14
800 //-----------------------------------------------------------------------------
801 //
802 // Return Value : None
803 // Parameters : None
804 //
805 // Increments BlockRead and BlockIndex
806 // After every 8 packets or at the end of the transfer, sends a handshake
807 // signal to the host (0xFF)
808 // Sets the state of the device
809 //
810 //-----------------------------------------------------------------------------
811
812 void Receive_File(void)
813 {
814 1 BlocksRead++; // Increment
815 1 BlockIndex++;
816 1 // If multiple of 8 or last packet, disable interrupts,
817 1 // write page to flash, reset packet index, enable interrupts
818 1 // Send handshake packet 0xFF to host after FLASH write
819 1 if ((BlockIndex == (BLOCKS_PR_PAGE)) || (BlocksRead == NumBlocks))
820 1 {
821 2 Page_Erase((BYTE*)(PageIndices[PageIndex]));
822 2 Page_Write((BYTE*)(PageIndices[PageIndex]));
823 2 PageIndex++;
824 2 Led1 = ~Led1;
825 2 BlockIndex = 0;
826 2 Buffer[0] = 0xFF;
827 2
828 2 // Place Handshake packet (0xFF) on the OUT FIFO
829 2 BulkOrInterruptIn (&gEp1InStatus, (BYTE*)&Buffer, 1);
830 2 }
831 1
832 1 // Go to Idle state if last packet has been received
833 1 if (BlocksRead == NumBlocks)
834 1 {
835 2 M_State = ST_IDLE_DEV;
836 2 Led1 = 0;
837 2 }
838 1 }
839
840 //-----------------------------------------------------------------------------
841 // End Of File
842 //-----------------------------------------------------------------------------
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1483 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 512 ----
PDATA SIZE = ---- ----
DATA SIZE = 16 25
IDATA SIZE = 60 ----
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 + -