📄 subp.lst
字号:
162 if(sof_cnt==TIME_OUT) //5 reset counter on specify
163 { // time out.
164 sof_cnt = 0;
165 timeout = 1; // set timeout flag
166 }
167
168 return;
169 }
170 */
171 //*****************************************************************************************
172 // EP0 interrupt service routine
173 //*****************************************************************************************
174 //int ep0_isr(void)
175 void ep0_isr(void)
176 {
177 1 BYTE status, byte_rx, len_xfr;
178 1 BYTE req_type,data_seq;
179 1
C51 COMPILER V7.20 SUBP 07/05/2004 23:23:35 PAGE 4
180 1 SL811Write(IntStatus,EP0_DONE); // clear EP0 interrupt
181 1 status = SL811Read(EP0AStatus); // get packet status
182 1 byte_rx = SL811Read(EP0AXferLen) - SL811Read(EP0ACounter); // get no. of BYTEs received
183 1 // for OUT data from host
184 1 //----------------------------------------------------------------------------------------
185 1 // ACK received
186 1 //----------------------------------------------------------------------------------------
187 1 if(status & EP_ACK)
188 1 {
189 2 //----------------------------------------------------------------
190 2 // Set newly assigned USB address
191 2 //----------------------------------------------------------------
192 2 if(Slave_USBaddr)
193 2 { // if new USB address was assigned,
194 3 SL811Write(USBAddress,Slave_USBaddr); // communicate all USB transaction
195 3 Slave_USBaddr = 0; // using this new address.
196 3 }
197 2
198 2 //================================================================
199 2 // SETUP's ACKed
200 2 //================================================================
201 2 //status = SL811Read(EP0AStatus);
202 2 if(status & EP_SETUP)
203 2 {
204 3
205 3 SL811BufRead(EP0A_Slave_Buf, ( BYTE*)&dReq, byte_rx); // capture SETUP data request
206 3 len_req = WordSwap(dReq.wLength); // len_req = actual requested length
207 3 in_buffer_idx = 0; // reset buffer locatio indexing
208 3 IN_NULL = FALSE; // these are for IN-NULL packet
209 3 IN_EXACT = FALSE; // transfer condition
210 3 req_type = (dReq.bmRequest&0x60)>>5; // decode for Std,Class,Vendor type
211 3
212 3 switch (req_type) // Parse bmRequest Type
213 3 {
214 4 //---------------------------------------------------------------------
215 4 // Standard USB Requests
216 4 //---------------------------------------------------------------------
217 4 case STD_REQUEST:
218 4 switch (dReq.bRequest) // Parse bRequest
219 4 {
220 5 case GET_DESCRIPTOR:
221 5 switch (( BYTE)dReq.wValue) // Parse wValue
222 5 {
223 6 case DEVICE:
224 6 SL811BufWrite(EP0A_Slave_Buf,( BYTE*)Dev_Descp,DEV_LEN); // load Device Descp
225 6 len_req = (len_req>=DEV_LEN) ? DEV_LEN:len_req; // get exact data length
226 6
227 6 break;
228 6
229 6 case CONFIGURATION:
230 6 SL811BufWrite(EP0A_Slave_Buf,( BYTE*)Cfg_Descp,CFG_LEN); // load Config Descp
231 6 len_req = (len_req>=CFG_LEN) ? CFG_LEN:len_req; // get exact data length
232 6
233 6 break;
234 6
235 6 case HID_DEV:
236 6 SL811BufWrite(EP0A_Slave_Buf,( BYTE*)Cfg_Descp+18,HID_LEN);// load HID Class Descp
237 6 len_req = (len_req>=HID_LEN) ? HID_LEN:len_req; // get exact data length
238 6 break;
239 6
240 6 case HID_REPORT:
241 6 SL811BufWrite(EP0A_Slave_Buf,( BYTE*)Rep_Descp,REP_LEN); // load Report Descp
C51 COMPILER V7.20 SUBP 07/05/2004 23:23:35 PAGE 5
242 6 len_req = (len_req>=REP_LEN) ? REP_LEN:len_req; // get exact data length
243 6 break;
244 6
245 6 case STRING:
246 6 switch(dReq.wValue>>8) // get string index
247 6 {
248 7 case 0x00: SL811BufWrite(EP0A_Slave_Buf,( BYTE*)LangString,LangString[0]);
249 7 len_req = (len_req>=LangString[0]) ? LangString[0]:len_req;
250 7
251 7 break;
252 7 case 0x01: SL811BufWrite(EP0A_Slave_Buf,( BYTE*)MfgString,MfgString[0]);
253 7 len_req = (len_req>=MfgString[0]) ? MfgString[0]:len_req;
254 7 break;
255 7 case 0x02: SL811BufWrite(EP0A_Slave_Buf,( BYTE*)ProdString,ProdString[0]);
256 7 len_req = (len_req>=ProdString[0]) ? ProdString[0]:len_req;
257 7 break;
258 7 }
259 6 break;
260 6 }
261 5
262 5 if (len_req == WordSwap(dReq.wLength)) // if requested length is equal to the
263 5 IN_EXACT = TRUE; // exact length of descriptor, set IN_EXACT
264 5 // is use during IN-NULL pkt trasnmission
265 5 len_xfr = (len_req>=EP0_LEN) ? EP0_LEN:( BYTE)len_req; // get current IN transfer length
266 5 EP0A_IN_Arm(EP0A_Slave_Buf,len_xfr,1); // Arm IN response, start with DATA1 seq
267 5 in_buffer_idx += len_xfr; // update to next muliple buffer location
268 5 len_req -= len_xfr; // update data length for current transfer
269 5
270 5 break;
271 5
272 5 case GET_CONFIG:
273 5 SL811Write(EP0A_Slave_Buf,Slave_ConfigVal); // load current configuration value
274 5 EP0A_IN_Arm(EP0A_Slave_Buf,1,1); // send 1 BYTE data back to host
275 5 len_req = 0;
276 5 break;
277 5
278 5 case GET_INTERFACE:
279 5 SL811Write(EP0A_Slave_Buf,Slave_IfcAlt[dReq.wIndex>>8]);// load current alternate setting
280 5 EP0A_IN_Arm(EP0A_Slave_Buf,1,1); // send 1 BYTE data back to host
281 5 len_req = 0;
282 5 break;
283 5
284 5 case GET_STATUS:
285 5 switch(dReq.bmRequest&0x03) // check for recipients
286 5 {
287 6 case RECIPIENT_DEV: // load current device status
288 6 SL811Write(EP0A_Slave_Buf,(Slave_RemoteWU<<1)|BUS_POWERED);
289 6 break;
290 6 case RECIPIENT_IFC:
291 6 SL811Write(EP0A_Slave_Buf,0); // first BYTE = 0
292 6 break;
293 6 case RECIPIENT_ENP:
294 6 if((dReq.wIndex>>8) & 0x80) // for IN direction endpoint
295 6 {
296 7 if(Slave_inEPstall & (0x01<<((dReq.wIndex>>8)&0x0F)))
297 7 SL811Write(EP0A_Slave_Buf,1); // first BYTE = 1 (IN endpoint stall)
298 7 else
299 7 SL811Write(EP0A_Slave_Buf,0); // first BYTE = 0 (IN endpoint not stall)
300 7 }
301 6 else // for OUT direction endpoint
302 6 {
303 7 if(Slave_outEPstall & (0x01<<((dReq.wIndex>>8)&0x0F)))
C51 COMPILER V7.20 SUBP 07/05/2004 23:23:35 PAGE 6
304 7 SL811Write(EP0A_Slave_Buf,1); // first BYTE = 1 (OUT endpoint stall)
305 7 else
306 7 SL811Write(EP0A_Slave_Buf,0); // first BYTE = 0 (OUT endpoint not stall)
307 7 }
308 6 break;
309 6 }
310 5 SL811Write(EP0A_Slave_Buf+1,0); // second BYTE = 0
311 5 EP0A_IN_Arm(EP0A_Slave_Buf,2,1); // send 2 BYTEs data back to host
312 5 len_req = 0; // reset request length to zero
313 5 break;
314 5
315 5 case SET_FEATURE:
316 5 case CLEAR_FEATURE:
317 5 switch(dReq.bmRequest&0x03) // check for recipients
318 5 {
319 6 case RECIPIENT_DEV:
320 6 if((dReq.wValue>>8) == 1) // feature selector = 1 (remote wakeup)
321 6 {
322 7 if(dReq.bRequest==SET_FEATURE) // set remote wake up status
323 7 Slave_RemoteWU = 1;
324 7 if(dReq.bRequest==CLEAR_FEATURE) // clear remote wake up status
325 7 Slave_RemoteWU = 0;
326 7 EP0A_IN_Arm(0,0,1); // IN status stage
327 7 }
328 6 else
329 6 SL811Write(EP0AControl,SEND_STALL); // Stall unsupported requests
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -