📄 f34x_usb_standard_requests.lst
字号:
C51 COMPILER V7.50 F34X_USB_STANDARD_REQUESTS 08/01/2007 13:13:23 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE F34X_USB_STANDARD_REQUESTS
OBJECT MODULE PLACED IN F34x_USB_Standard_Requests.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\c51.exe F34x_USB_Standard_Requests.c DB OE
line level source
1 //-----------------------------------------------------------------------------
2 // F34x_USB_Standard_Requests.c
3 //-----------------------------------------------------------------------------
4 // Copyright 2005 Silicon Laboratories, Inc.
5 // http://www.silabs.com
6 //
7 // Program Description:
8 //
9 // This source file contains the subroutines used to handle incoming
10 // setup packets. These are called by Handle_Setup in USB_ISR.c and used for
11 // USB chapter 9 compliance.
12 //
13
14 // How To Test: See Readme.txt
15 //
16 //
17 // FID: 34X000022
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 // Externs
42 //-----------------------------------------------------------------------------
43
44 // These are created in USB_DESCRIPTOR.h
45
46 extern device_descriptor DeviceDesc;
47 extern configuration_descriptor ConfigDesc;
48 extern interface_descriptor InterfaceDesc;
49 extern endpoint_descriptor Endpoint1Desc;
50 extern endpoint_descriptor Endpoint2Desc;
51 extern BYTE* StringDescTable[];
52
53 extern setup_buffer Setup; // Buffer for current device request
54 extern unsigned int DataSize;
55 extern unsigned int DataSent;
C51 COMPILER V7.50 F34X_USB_STANDARD_REQUESTS 08/01/2007 13:13:23 PAGE 2
56 extern BYTE* DataPtr;
57
58 extern BYTE Ep_Status[]; // Contains status bytes for EP 0-2
59
60 extern BYTE USB_State; // Determines current usb device state
61
62 //-----------------------------------------------------------------------------
63 // Global Variables
64 //-----------------------------------------------------------------------------
65
66 // These are response packets used for communication with host
67 code BYTE ONES_PACKET[2] = {0x01, 0x00};
68 code BYTE ZERO_PACKET[2] = {0x00, 0x00};
69
70 //-----------------------------------------------------------------------------
71 // Support Subroutines
72 //-----------------------------------------------------------------------------
73
74 //-----------------------------------------------------------------------------
75 // Get_Status
76 //-----------------------------------------------------------------------------
77 //
78 // Return Value : None
79 // Parameters : None
80 //
81 // This routine returns a two byte status packet to the host
82 //
83 //-----------------------------------------------------------------------------
84
85 void Get_Status(void)
86 {
87 1
88 1 if (Setup.wValue.c[MSB] || Setup.wValue.c[LSB] ||
89 1
90 1 // If non-zero return length or data length not equal to 2 then send a stall
91 1 // indicating invalid request
92 1 Setup.wLength.c[MSB] || (Setup.wLength.c[LSB] != 2))
93 1 {
94 2 Force_Stall();
95 2 }
96 1
97 1 // Determine if recipient was device, interface, or EP
98 1 switch(Setup.bmRequestType)
99 1 {
100 2 // If recipient was device
101 2 case OUT_DEVICE:
102 2 if (Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])
103 2 {
104 3 // Send stall if request is invalid
105 3 Force_Stall();
106 3 }
107 2 else
108 2 {
109 3 // Otherwise send 0x00, indicating bus power and no
110 3 // remote wake-up supported
111 3 DataPtr = (BYTE*)&ZERO_PACKET;
112 3 DataSize = 2;
113 3 }
114 2 break;
115 2
116 2 // See if recipient was interface
117 2 case OUT_INTERFACE:
C51 COMPILER V7.50 F34X_USB_STANDARD_REQUESTS 08/01/2007 13:13:23 PAGE 3
118 2 // Only valid if device is configured and non-zero index
119 2 if ((USB_State != DEV_CONFIGURED) ||
120 2 Setup.wIndex.c[MSB] || Setup.wIndex.c[LSB])
121 2 {
122 3 // Otherwise send stall to host
123 3 Force_Stall();
124 3 }
125 2 else
126 2 {
127 3 // Status packet always returns 0x00
128 3 DataPtr = (BYTE*)&ZERO_PACKET;
129 3 DataSize = 2;
130 3 }
131 2 break;
132 2
133 2 // See if recipient was an endpoint
134 2 case OUT_ENDPOINT:
135 2 // Make sure device is configured and index msb = 0x00
136 2 if ((USB_State != DEV_CONFIGURED) || Setup.wIndex.c[MSB])
137 2 {
138 3 Force_Stall(); // otherwise return stall to host
139 3 }
140 2 else
141 2 {
142 3 // Handle case if request is directed to EP 1
143 3 if (Setup.wIndex.c[LSB] == IN_EP1)
144 3 {
145 4 if (Ep_Status[1] == EP_HALT)
146 4 {
147 5 // If endpoint is halted, return 0x01,0x00
148 5 DataPtr = (BYTE*)&ONES_PACKET;
149 5 DataSize = 2;
150 5 }
151 4 else
152 4 {
153 5 // Otherwise return 0x00,0x00 to indicate endpoint active
154 5 DataPtr = (BYTE*)&ZERO_PACKET;
155 5 DataSize = 2;
156 5 }
157 4 }
158 3 else
159 3 {
160 4 // If request is directed to endpoint 2, send either
161 4 // 0x01,0x00 if endpoint halted or 0x00,0x00 if endpoint is active
162 4 if (Setup.wIndex.c[LSB] == OUT_EP2)
163 4
164 4 {
165 5 if (Ep_Status[2] == EP_HALT)
166 5 {
167 6 DataPtr = (BYTE*)&ONES_PACKET;
168 6 DataSize = 2;
169 6 }
170 5 else
171 5 {
172 6 DataPtr = (BYTE*)&ZERO_PACKET;
173 6 DataSize = 2;
174 6 }
175 5 }
176 4 else
177 4 {
178 5 Force_Stall(); // Send stall if unexpected data
179 5 }
C51 COMPILER V7.50 F34X_USB_STANDARD_REQUESTS 08/01/2007 13:13:23 PAGE 4
180 4 }
181 3 }
182 2 break;
183 2
184 2 default:
185 2 Force_Stall();
186 2 break;
187 2 }
188 1 if (Ep_Status[0] != EP_STALL)
189 1 {
190 2 // Set serviced Setup Packet, Endpoint 0 intransmit mode,
191 2 // and reset DataSent counter
192 2 POLL_WRITE_BYTE(E0CSR, rbSOPRDY);
193 2 Ep_Status[0] = EP_TX;
194 2 DataSent = 0;
195 2 }
196 1 }
197
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -