📄 usb_isr.lst
字号:
C51 COMPILER V6.12 USB_ISR 06/09/2004 15:44:26 PAGE 1
C51 COMPILER V6.12, COMPILATION OF MODULE USB_ISR
OBJECT MODULE PLACED IN USB_ISR.OBJ
COMPILER INVOKED BY: c:\Keil\C51\BIN\C51.EXE USB_ISR.c DB OE
stmt level source
1 /*
2 File: usb_top_isr.c
3 Author: DM
4 Created: 11/8/02
5
6 Target Device: C8051F320
7
8 Source file for USB firmware. Includes top level isr with Setup,
9 and Endpoint data handlers. Also includes routine for USB suspend,
10 reset, and procedural stall.
11 */
12
13 //#include "c8051F320.h"
14 #include "USB_REGISTER.h"
15 #include "USB_MAIN.h"
16 #include "USB_DESCRIPTOR.h"
17
18 #define c_cISR
19 #include "USB_ISR.h"
20 #undef USB_USER
21 #include "USB_USER.h"
22
23 extern BYTE OUT_PACKET[];
24 extern BYTE IN_PACKET[];
25
26 BYTE USB_State; // Holds the current USB State def. in USB_MAIN.h
27
28 setup_buffer Setup; // Buffer for current device request information
29
30 unsigned int DataSize; // Size of data to return
31 unsigned int DataSent; // Amount of data sent so far
32 BYTE* DataPtr; // Pointer to data to return
33
34 BYTE Ep_Status[3] = {EP_IDLE, EP_IDLE, EP_IDLE};
35 // Holds the status for each endpoint
36
37 //-------------------------
38 // Usb_ISR
39 //-------------------------
40 // Called after any USB type interrupt, this handler determines which type
41 // of interrupt occurred, and calls the specific routine to handle it.
42 //
43 void Usb_ISR(void) interrupt 8 // Top-level USB ISR
44 {
45 1 BYTE bCommon, bIn, bOut;
46 1 POLL_READ_BYTE(CMINT, bCommon); // Read all interrupt registers
47 1 POLL_READ_BYTE(IN1INT, bIn); // this read also clears the register
48 1 POLL_READ_BYTE(OUT1INT, bOut);
49 1 {
50 2 if (bCommon & rbRSUINT) // Handle Resume interrupt
51 2 {
52 3 Usb_Resume();
53 3 }
54 2 if (bCommon & rbRSTINT) // Handle Reset interrupt
55 2 {
C51 COMPILER V6.12 USB_ISR 06/09/2004 15:44:26 PAGE 2
56 3 Usb_Reset();
57 3 }
58 2 if (bIn & rbEP0) // Handle Setup packet received
59 2 { // or packet transmitted if Endpoint 0 is
60 3 Handle_Setup(); // transmit mode
61 3 }
62 2 if (bIn & rbIN1) // Handle In Packet sent, put new data on
63 2 { // endpoint 1 fifo
64 3 Handle_In1();
65 3 }
66 2 if (bOut & rbOUT2) // Handle Out packet received, take data off
67 2 { // endpoint 2 fifo
68 3 Handle_Out2();
69 3 }
70 2 if (bCommon & rbSUSINT) // Handle Suspend interrupt
71 2 {
72 3 Usb_Suspend();
73 3 }
74 2 }
75 1 }
76
77 //-------------------------
78 // Usb_Resume
79 //-------------------------
80 // Resume normal USB operation
81 //
82 void Usb_Resume(void) // Add code to turn on anything turned off when
83 { // entering suspend mode
84 1 volatile int k;
85 1 k++;
86 1 }
87
88 //-------------------------
89 // Usb_Reset
90 //-------------------------
91 // - Set state to default
92 // - Clear Usb Inhibit bit
93 //
94 void Usb_Reset(void)
95 {
96 1 USB_State = DEV_DEFAULT; // Set device state to default
97 1
98 1 POLL_WRITE_BYTE(POWER, 0x01); // Clear usb inhibit bit to enable USB
99 1 // suspend detection
100 1
101 1 Ep_Status[0] = EP_IDLE; // Set default Endpoint Status
102 1 Ep_Status[1] = EP_HALT;
103 1 Ep_Status[2] = EP_HALT;
104 1 }
105
106 //-------------------------
107 // Handle_Setup
108 //-------------------------
109 // - Decode Incoming Setup requests
110 // - Load data packets on fifo while in transmit mode
111 //
112 void Handle_Setup(void)
113 {
114 1 BYTE ControlReg,TempReg; // Temporary storage for EP control register
115 1
116 1 POLL_WRITE_BYTE(INDEX, 0); // Set Index to Endpoint Zero
117 1 POLL_READ_BYTE(E0CSR, ControlReg); // Read control register
C51 COMPILER V6.12 USB_ISR 06/09/2004 15:44:26 PAGE 3
118 1
119 1 if (Ep_Status[0] == EP_ADDRESS) // Handle Status Phase of Set Address command
120 1 {
121 2 POLL_WRITE_BYTE(FADDR, Setup.wValue.c[LSB]);
122 2 Ep_Status[0] = EP_IDLE;
123 2 }
124 1
125 1 if (ControlReg & rbSTSTL) // If last packet was a sent stall, reset STSTL
126 1 { // bit and return EP0 to idle state
127 2 POLL_WRITE_BYTE(E0CSR, 0);
128 2 Ep_Status[0] = EP_IDLE;
129 2 return;
130 2 }
131 1
132 1 if (ControlReg & rbSUEND) // If last setup transaction was ended prematurely
133 1 { // then set
134 2 POLL_WRITE_BYTE(E0CSR, rbDATAEND);
135 2 POLL_WRITE_BYTE(E0CSR, rbSSUEND); // Serviced Setup End bit and return EP0
136 2 Ep_Status[0] = EP_IDLE; // to idle state
137 2 }
138 1
139 1 if (Ep_Status[0] == EP_IDLE) // If Endpoint 0 is in idle mode
140 1 {
141 2 if (ControlReg & rbOPRDY) // Make sure that EP 0 has an Out Packet ready from host
142 2 { // although if EP0 is idle, this should always be the case
143 3 Fifo_Read(FIFO_EP0, 8, (BYTE *)&Setup);
144 3 // Get Setup Packet off of Fifo, it is currently Big-Endian
145 3
146 3 // Compiler Specific - these next three statements swap the
147 3 // bytes of the setup packet words to Big Endian so they
148 3 // can be compared to other 16-bit values elsewhere properly
149 3 Setup.wValue.i = Setup.wValue.c[MSB] + 256*Setup.wValue.c[LSB];
150 3 Setup.wIndex.i = Setup.wIndex.c[MSB] + 256*Setup.wIndex.c[LSB];
151 3 Setup.wLength.i = Setup.wLength.c[MSB] + 256*Setup.wLength.c[LSB];
152 3
153 3
154 3 switch(Setup.bRequest) // Call correct subroutine to handle each kind of
155 3 { // standard request
156 4 case GET_STATUS:
157 4 Get_Status();
158 4 break;
159 4 case CLEAR_FEATURE:
160 4 Clear_Feature();
161 4 break;
162 4 case SET_FEATURE:
163 4 Set_Feature();
164 4 break;
165 4 case SET_ADDRESS:
166 4 Set_Address();
167 4 break;
168 4 case GET_DESCRIPTOR:
169 4 Get_Descriptor();
170 4 break;
171 4 case GET_CONFIGURATION:
172 4 Get_Configuration();
173 4 break;
174 4 case SET_CONFIGURATION:
175 4 Set_Configuration();
176 4 break;
177 4 case GET_INTERFACE:
178 4 Get_Interface();
179 4 break;
C51 COMPILER V6.12 USB_ISR 06/09/2004 15:44:26 PAGE 4
180 4 case SET_INTERFACE:
181 4 Set_Interface();
182 4 break;
183 4 default:
184 4 Force_Stall(); // Send stall to host if invalid request
185 4 break;
186 4 }
187 3 }
188 2 }
189 1
190 1 if (Ep_Status[0] == EP_TX) // See if the endpoint has data to transmit to host
191 1 {
192 2 if (!(ControlReg & rbINPRDY)) // Make sure you don't overwrite last packet
193 2 {
194 3 // Endpoint 0 transmit mode
195 3 //Delay();
196 3 POLL_READ_BYTE(E0CSR, ControlReg);
197 3 // Read control register
198 3
199 3 if ((!(ControlReg & rbSUEND)) || (!(ControlReg & rbOPRDY)))
200 3 // Check to see if Setup End or Out Packet received, if so
-
201 3 // do not put any new data on FIFO
202 3 {
203 4 TempReg = rbINPRDY; // Add In Packet ready flag to E0CSR bitmask
204 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -