📄 sl811.lst
字号:
184 4 // not overwrite data in previous buffer.
185 4 //------------------------------------------------
186 4 if(remainder==xferLen) // empty data detected
187 4 bufLen = 0; // do not overwriten previous data
188 4 else // reset bufLen to zero
189 4 bufLen = xferLen; // update previous buffer length
190 4
191 4 //------------------------------------------------
192 4 // Arm for next data transfer when requested data
193 4 // length have not reach zero, i.e. wLen!=0, and
194 4 // last xferlen of data was completed, i.e.
195 4 // remainder is equal to zero, not a short pkt
196 4 //------------------------------------------------
197 4 if(!remainder && usbstack.wLen) // remainder==0 when last xferLen
198 4 { // was all completed or wLen!=0
199 5 addr = (dataX & 1) ? data1:data0; // select next address for data
200 5 xferLen = (BYTE)(usbstack.wLen>=usbstack.wPayload) ? usbstack.wPayload:usbstack.wLen; // get data len
-gth required
201 5 //if (FULL_SPEED) // sync with SOF transfer
202 5 cmd |= 0x20; // always sync SOF when FS, regardless
203 5 SL811Write(EP0XferLen, xferLen); // select next xfer length
204 5 SL811Write(EP0Address, addr); // data buffer addr
205 5 SL811Write(IntStatus,INT_CLEAR); // is a LS is on Hub.
206 5 SL811Write(EP0Control,cmd); // Enable USB transfer and re-arm
207 5 }
208 4
209 4 //------------------------------------------------
210 4 // Copy last IN token data pkt from prev transfer
211 4 // Check if there was data available during the
212 4 // last data transfer
213 4 //------------------------------------------------
214 4 if(bufLen)
215 4 {
216 5 SL811BufRead(((dataX&1)?data0:data1), usbstack.buffer, bufLen);
217 5 usbstack.buffer += bufLen;
218 5 }
219 4
220 4 //------------------------------------------------
221 4 // Terminate on short packets, i.e. remainder!=0
222 4 // a short packet or empty data packet OR when
223 4 // requested data len have completed, i.e.wLen=0
224 4 // For a LOWSPEED device, the 1st device descp,
225 4 // wPayload is default to 64-byte, LS device will
226 4 // only send back a max of 8-byte device descp,
227 4 // and host detect this as a short packet, and
228 4 // terminate with OUT status stage
229 4 //------------------------------------------------
230 4 if(remainder || !usbstack.wLen)
231 4 break;
232 4 }// PID IN
233 3 }
234 2
235 2 //-------------------------NAK----------------------------
236 2 if (result & EP0_NAK) // NAK Detected
237 2 {
238 3 if(usbstack.endpoint==0) // on ep0 during enumeration of LS device
239 3 { // happen when slave is not fast enough,
C51 COMPILER V7.06 SL811 04/30/2005 15:12:27 PAGE 5
240 4 SL811Write(IntStatus,INT_CLEAR); // clear interrupt status, need to
241 4 SL811Write(EP0Control,cmd); // re-arm and request for last cmd, IN token
242 4 result = 0; // respond to NAK status only
243 4 }
244 3 else // normal data endpoint, exit now !!! , non-zero ep
245 3 break; // main loop control the interval polling
246 3 }
247 2
248 2 //-----------------------TIMEOUT--------------------------
249 2 if (result & EP0_TIMEOUT) // TIMEOUT Detected
250 2 {
251 3 if(usbstack.endpoint==0) // happens when hub enumeration
252 3 {
253 4 if(++timeout >= TIMEOUT_RETRY)
254 4 {
255 5 timeout--;
256 5 break; // exit on the timeout detected
257 5 }
258 4 SL811Write(IntStatus,INT_CLEAR); // clear interrupt status, need to
259 4 SL811Write(EP0Control,cmd); // re-arm and request for last cmd again
260 4 }
261 3 else
262 3 { // all other data endpoint, data transfer
263 4 bXXGFlags.bits.TIMEOUT_ERR = TRUE; // failed, set flag to terminate transfer
264 4 break; // happens when data transfer on a device
265 4 } // through the hub
266 3 }
267 2
268 2 //-----------------------STALL----------------------------
269 2 if (result & EP0_STALL) // STALL detected
270 2 return TRUE; // for unsupported request.
271 2
272 2 //----------------------OVEFLOW---------------------------
273 2 if (result & EP0_OVERFLOW) // OVERFLOW detected
274 2 //result=result;
275 2 break;
276 2 //-----------------------ERROR----------------------------
277 2 if (result & EP0_ERROR) // ERROR detected
278 2 //result=result;
279 2 break;
280 2 } // end of While(1)
281 1
282 1 if (result & EP0_ACK) // on ACK transmission
283 1 return TRUE; // return OK
284 1
285 1 return FALSE; // fail transmission
286 1
287 1 }
288 //*****************************************************************************************
289 // Control Endpoint 0's USB Data Xfer
290 // ep0Xfer, endpoint 0 data transfer
291 //*****************************************************************************************
292 unsigned char ep0Xfer(void)
293 {
294 1 //unsigned char wLen;
295 1
296 1 //wLen=usbstack.wLen;
297 1 usbstack.endpoint=0;
298 1 //----------------------------------------------------
299 1 // SETUP token with 8-byte request on endpoint 0
300 1 //----------------------------------------------------
301 1 usbstack.pid=PID_SETUP;
C51 COMPILER V7.06 SL811 04/30/2005 15:12:27 PAGE 6
302 1 usbstack.wLen=8;
303 1 //usbstack.buffer=&usbstack.setup;
304 1 if (!usbXfer())
305 1 return FALSE;
306 1 DelayMs(10);
307 1 usbstack.pid = PID_IN;
308 1 //----------------------------------------------------
309 1 // IN or OUT data stage on endpoint 0
310 1 //----------------------------------------------------
311 1 usbstack.wLen=usbstack.setup.wLength;
312 1 if (usbstack.wLen) // if there are data for transfer
313 1 {
314 2 if (usbstack.setup.bmRequest & 0x80) // host-to-device : IN token
315 2 {
316 3 usbstack.pid = PID_IN;
317 3
318 3 if(!usbXfer())
319 3 return FALSE;
320 3 //usbstack.wPayload = 0;
321 3 usbstack.pid = PID_OUT;
322 3 }
323 2 else // device-to-host : OUT token
324 2 {
325 3 usbstack.pid = PID_OUT;
326 3
327 3 if(!usbXfer())
328 3 return FALSE;
329 3 usbstack.pid = PID_IN;
330 3 }
331 2 }
332 1 DelayMs(10);
333 1 //----------------------------------------------------
334 1 // Status stage IN or OUT zero-length data packet
335 1 //----------------------------------------------------
336 1 usbstack.wLen=0;
337 1 if(!usbXfer())
338 1 return FALSE;
339 1
340 1 return TRUE;
341 1
342 1 }
343
344
345 unsigned char epBulkSend(unsigned char *pBuffer,unsigned int len)
346 {
347 1 usbstack.usbaddr=0x1;
348 1 usbstack.endpoint=usbstack.epbulkout;
349 1 usbstack.pid=PID_OUT;
350 1 usbstack.wPayload=64;
351 1 usbstack.wLen=len;
352 1 usbstack.buffer=pBuffer;
353 1 while(len>0)
354 1 {
355 2 if (len > usbstack.wPayload)
356 2 usbstack.wLen = usbstack.wPayload;
357 2 else
358 2 usbstack.wLen = len;
359 2 if(!usbXfer())
360 2 return FALSE;
361 2 len-=usbstack.wLen;
362 2 usbstack.buffer=usbstack.buffer+usbstack.wLen;
363 2 DelayUs(10);
C51 COMPILER V7.06 SL811 04/30/2005 15:12:27 PAGE 7
364 2 }
365 1 return TRUE;
366 1 }
367
368 unsigned char epBulkRcv(unsigned char *pBuffer,unsigned int len)
369 {
370 1 usbstack.usbaddr=0x1;
371 1 usbstack.endpoint=usbstack.epbulkin;
372 1 usbstack.pid=PID_IN;
373 1 usbstack.wPayload=64;
374 1 usbstack.wLen=len;
375 1 usbstack.buffer=pBuffer;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -