?? f34x_usb_isr.lst
字號:
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE F34X_USB_ISR
OBJECT MODULE PLACED IN F34x_USB_ISR.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F34x_USB_ISR.c DB OE
stmt level source
1 //-----------------------------------------------------------------------------
2 // F34x_USB_ISR.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2005 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // Source file for USB firmware. Includes top level ISR with Setup,
10 // and Endpoint data handlers. Also includes routine for USB suspend,
11 // reset, and procedural stall.
12 //
13 //
14 // How To Test: See Readme.txt
15 //
16 //
17 // FID: 34X000018
18 // Target: C8051F34x
19 // Tool chain: Keil C51 7.50 / Keil EVAL C51
20 // Silicon Laboratories IDE version 2.6
21 // Command Line: See Readme.txt
22 // Project Name: F34x_USB_Interrupt
23 //
24 //
25 // Release 1.0
26 // -Initial Revision (GP)
27 // -22 NOV 2005
28 // -Ported from 'F320_USB_Bulk
29 //
30
31 //-----------------------------------------------------------------------------
32 // Includes
33 //-----------------------------------------------------------------------------
34
35 #include "c8051F340.h"
36 #include "F34x_USB_Register.h"
37 #include "F34x_USB_Main.h"
38 #include "F34x_USB_Descriptor.h"
39
40 //-----------------------------------------------------------------------------
41 // Global Externs
42 //-----------------------------------------------------------------------------
43
44 extern idata BYTE OUT_PACKET[];
45 extern idata BYTE IN_PACKET[];
46
47 //-----------------------------------------------------------------------------
48 // Global Variables
49 //-----------------------------------------------------------------------------
50
51 BYTE USB_State; // Holds the current USB State
52 // def. in F32x_USB_Main.h
53
54 setup_buffer Setup; // Buffer for current device request
55
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 2
56 unsigned int DataSize; // Size of data to return
57 unsigned int DataSent; // Amount of data sent so far
58 BYTE* DataPtr; // Pointer to data to return
59
60 // Holds the status for each endpoint
61 BYTE Ep_Status[3] = {EP_IDLE, EP_IDLE, EP_IDLE};
62
63
64 //-----------------------------------------------------------------------------
65 // Interrupt Service Routines
66 //-----------------------------------------------------------------------------
67
68 //-----------------------------------------------------------------------------
69 // USB0_ISR
70 //-----------------------------------------------------------------------------
71 //
72 // Called after any USB type interrupt, this handler determines which type
73 // of interrupt occurred, and calls the specific routine to handle it.
74 //
75 //-----------------------------------------------------------------------------
76 void USB0_ISR(void) interrupt 8 // Top-level USB ISR
77 {
78 1 BYTE bCommon, bIn, bOut;
79 1 POLL_READ_BYTE(CMINT, bCommon); // Read all interrupt registers
80 1 POLL_READ_BYTE(IN1INT, bIn); // this read also clears the register
81 1 POLL_READ_BYTE(OUT1INT, bOut);
82 1 {
83 2 if (bCommon & rbRSUINT) // Handle Resume interrupt
84 2 {
85 3 Usb_Resume();
86 3 }
87 2 if (bCommon & rbRSTINT) // Handle Reset interrupt
88 2 {
89 3 Usb_Reset();
90 3 }
91 2 if (bIn & rbEP0) // Handle Setup packet received
92 2 { // or packet transmitted if Endpoint 0
93 3 Handle_Setup(); // is transmit mode
94 3 }
95 2 if (bIn & rbIN1) // Handle In Packet sent, put new data
96 2 { // on endpoint 1 fifo
97 3 Handle_In1();
98 3 }
99 2 if (bOut & rbOUT2) // Handle Out packet received, take data
100 2 { // off endpoint 2 fifo
101 3 Handle_Out2();
102 3 }
103 2 if (bCommon & rbSUSINT) // Handle Suspend interrupt
104 2 {
105 3 Usb_Suspend();
106 3 }
107 2 }
108 1 }
109
110 //-----------------------------------------------------------------------------
111 // Support Routines for ISR
112 //-----------------------------------------------------------------------------
113
114 //-----------------------------------------------------------------------------
115 // Usb_Reset
116 //-----------------------------------------------------------------------------
117 //
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 3
118 // Return Value : None
119 // Parameters : None
120 //
121 // - Set state to default
122 // - Clear Usb Inhibit bit
123 //
124 //-----------------------------------------------------------------------------
125
126 void Usb_Reset(void)
127 {
128 1 USB_State = DEV_DEFAULT; // Set device state to default
129 1
130 1 POLL_WRITE_BYTE(POWER, 0x01); // Clear usb inhibit bit to enable USB
131 1 // suspend detection
132 1
133 1 Ep_Status[0] = EP_IDLE; // Set default Endpoint Status
134 1 Ep_Status[1] = EP_HALT;
135 1 Ep_Status[2] = EP_HALT;
136 1 }
137
138 //-----------------------------------------------------------------------------
139 // Handle_Setup
140 //-----------------------------------------------------------------------------
141 //
142 // Return Value : None
143 // Parameters : None
144 //
145 // - Decode Incoming Setup requests
146 // - Load data packets on fifo while in transmit mode
147 //
148 //-----------------------------------------------------------------------------
149
150 void Handle_Setup(void)
151 {
152 1 BYTE ControlReg,TempReg; // Temporary storage for EP control
153 1 // register
154 1
155 1 POLL_WRITE_BYTE(INDEX, 0); // Set Index to Endpoint Zero
156 1 POLL_READ_BYTE(E0CSR, ControlReg); // Read control register
157 1
158 1 if (Ep_Status[0] == EP_ADDRESS) // Handle Status Phase of Set Address
159 1 // command
160 1 {
161 2 POLL_WRITE_BYTE(FADDR, Setup.wValue.c[LSB]);
162 2 Ep_Status[0] = EP_IDLE;
163 2 }
164 1
165 1 if (ControlReg & rbSTSTL) // If last packet was a sent stall, reset
166 1 { // STSTL bit and return EP0 to idle state
167 2 POLL_WRITE_BYTE(E0CSR, 0);
168 2 Ep_Status[0] = EP_IDLE;
169 2 return;
170 2 }
171 1
172 1 if (ControlReg & rbSUEND) // If last setup transaction was ended
173 1 { // prematurely then set
174 2 POLL_WRITE_BYTE(E0CSR, rbDATAEND);
175 2 POLL_WRITE_BYTE(E0CSR, rbSSUEND); // Serviced Setup End bit and return EP0
176 2 Ep_Status[0] = EP_IDLE; // to idle state
177 2 }
178 1
179 1 if (Ep_Status[0] == EP_IDLE) // If Endpoint 0 is in idle mode
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 4
180 1 {
181 2 if (ControlReg & rbOPRDY) // Make sure that EP 0 has an Out Packet ready from host
182 2 { // although if EP0 is idle, this should always be the case
183 3 Fifo_Read(FIFO_EP0, 8, (BYTE *)&Setup);
184 3 // Get Setup Packet off of Fifo, it is currently Big-Endian
185 3
186 3 // Compiler Specific - these next three statements swap the
187 3 // bytes of the setup packet words to Big Endian so they
188 3 // can be compared to other 16-bit values elsewhere properly
189 3 Setup.wValue.i = Setup.wValue.c[MSB] + 256*Setup.wValue.c[LSB];
190 3 Setup.wIndex.i = Setup.wIndex.c[MSB] + 256*Setup.wIndex.c[LSB];
191 3 Setup.wLength.i = Setup.wLength.c[MSB] + 256*Setup.wLength.c[LSB];
192 3
193 3
194 3 switch(Setup.bRequest) // Call correct subroutine to handle each kind of
195 3 { // standard request
196 4 case GET_STATUS:
197 4 Get_Status();
198 4 break;
199 4 case CLEAR_FEATURE:
200 4 Clear_Feature();
201 4 break;
202 4 case SET_FEATURE:
203 4 Set_Feature();
204 4 break;
205 4 case SET_ADDRESS:
206 4 Set_Address();
207 4 break;
208 4 case GET_DESCRIPTOR:
209 4 Get_Descriptor();
210 4 break;
211 4 case GET_CONFIGURATION:
212 4 Get_Configuration();
213 4 break;
214 4 case SET_CONFIGURATION:
215 4 Set_Configuration();
216 4 break;
217 4 case GET_INTERFACE:
218 4 Get_Interface();
219 4 break;
220 4 case SET_INTERFACE:
221 4 Set_Interface();
222 4 break;
223 4 default:
224 4 Force_Stall(); // Send stall to host if invalid request
225 4 break;
226 4 }
227 3 }
228 2 }
229 1
230 1 if (Ep_Status[0] == EP_TX) // See if the endpoint has data to transmit to host
231 1 {
232 2 if (!(ControlReg & rbINPRDY)) // Make sure you don't overwrite last packet
233 2 {
234 3 // Endpoint 0 transmit mode
235 3
236 3 POLL_READ_BYTE(E0CSR, ControlReg);
237 3 // Read control register
238 3
239 3 if ((!(ControlReg & rbSUEND)) || (!(ControlReg & rbOPRDY)))
240 3 // Check to see if Setup End or Out Packet received, if so
241 3 // do not put any new data on FIFO
C51 COMPILER V7.06 F34X_USB_ISR 09/10/2008 08:42:46 PAGE 5
242 3 {
243 4 TempReg = rbINPRDY; // Add In Packet ready flag to E0CSR bitmask
244 4
245 4 // Break Data into multiple packets if larger than Max Packet
246 4 if (DataSize >= EP0_PACKET_SIZE)
247 4 {
248 5 Fifo_Write(FIFO_EP0, EP0_PACKET_SIZE, (BYTE *)DataPtr);// Put Data on Fifo
249 5 DataPtr += EP0_PACKET_SIZE; // Advance data pointer
250 5 DataSize -= EP0_PACKET_SIZE; // Decrement data size
251 5 DataSent += EP0_PACKET_SIZE; // Increment data sent counter
252 5 }
253 4 else // If data is less than Max Packet size or zero
254 4 {
255 5 Fifo_Write(FIFO_EP0, DataSize, (BYTE *)DataPtr); // Put Data on Fifo
256 5 TempReg |= rbDATAEND; // Add Data End bit to bitmask
257 5 Ep_Status[0] = EP_IDLE; // Return EP 0 to idle state
258 5 }
259 4 if (DataSent == Setup.wLength.i)
260 4 // This case exists when the host requests an even multiple of
261 4 // your endpoint zero max packet size, and you need to exit
262 4 // transmit mode without sending a zero length packet
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -