📄 usb_task.lst
字号:
234 1 {
235 2 cbw_error = TRUE;
236 2 }
237 1 if (0x42 != Usb_read_byte())
238 1 {
239 2 cbw_error = TRUE;
240 2 }
C51 COMPILER V7.02a USB_TASK 09/13/2007 11:53:05 PAGE 5
241 1 if (0x43 != Usb_read_byte()) /* check if dCBWSignature is correct */
242 1 {
243 2 cbw_error = TRUE;
244 2 }
245 1
246 1 dCBWTag[0] = Usb_read_byte(); /* Store Tag to be repeated in CSW */
247 1 dCBWTag[1] = Usb_read_byte();
248 1 dCBWTag[2] = Usb_read_byte();
249 1 dCBWTag[3] = Usb_read_byte();
250 1 ((Byte*)&dCBWDataTransferLength)[3] = Usb_read_byte();
251 1 ((Byte*)&dCBWDataTransferLength)[2] = Usb_read_byte();
252 1 ((Byte*)&dCBWDataTransferLength)[1] = Usb_read_byte();
253 1 ((Byte*)&dCBWDataTransferLength)[0] = Usb_read_byte();
254 1 if (Usb_read_byte() != 0x00) /* store bmCBWFlags.bit7 */
255 1 {
256 2 Usb_CBWFlag_in();
257 2 if (cbw_error)
258 2 {
259 3 Usb_clear_RXOUT_PP();
260 3 Usb_select_ep(EP_IN);
261 3 Usb_set_STALLRQ();
262 3 return;
263 3 }
264 2 }
265 1 else
266 1 {
267 2 Usb_CBWFlag_out();
268 2 if (cbw_error)
269 2 {
270 3 Usb_clear_RXOUT_PP();
271 3 Usb_set_STALLRQ();
272 3 return;
273 3 }
274 2 }
275 1
276 1 if (ms_multiple_drive)
277 1 { /* multiple drive supported */
278 2 if (Usb_read_byte() == 0)
279 2 { /* LUN = 0 */
280 3 ACC = Usb_read_byte(); /* dummy CBWCBLength read */
281 3 Usb_clear_no_data_phase();
282 3 Sbc_command_chip();
283 3 }
284 2 else
285 2 { /* LUN = 1 */
286 3 ACC = Usb_read_byte(); /* dummy CBWCBLength read */
287 3 Usb_clear_no_data_phase();
288 3 Sbc_command_card();
289 3 }
290 2 }
291 1 else
292 1 { /* only 1 drive supported */
293 2 ACC = Usb_read_byte(); /* dummy LUN read */
294 2 ACC = Usb_read_byte(); /* dummy CBWCBLength read */
295 2 Usb_clear_no_data_phase();
296 2
297 2 if (gl_memory == MEM_CHIP)
298 2 { /* on-board memory */
299 3 Sbc_command_chip();
300 3 }
301 2 else
302 2 { /* memory card */
C51 COMPILER V7.02a USB_TASK 09/13/2007 11:53:05 PAGE 6
303 3 Sbc_command_card();
304 3 }
305 2 }
306 1 }
307
308
309 /*F**************************************************************************
310 * NAME: usb_mass_storage_csw
311 *----------------------------------------------------------------------------
312 * PARAMS:
313 *
314 * return:
315 *----------------------------------------------------------------------------
316 * PURPOSE:
317 * Command Status Wrapper management
318 *----------------------------------------------------------------------------
319 * EXAMPLE:
320 *----------------------------------------------------------------------------
321 * NOTE:
322 *
323 * REQUIREMENTS:
324 *****************************************************************************/
325 void usb_mass_storage_csw (void)
326 {
327 1 Usb_select_ep(EP_IN);
328 1 while (Usb_STALL_requested())
329 1 {
330 2 Usb_select_ep(EP_CONTROL);
331 2 if (Usb_setup_received())
332 2 {
333 3 usb_enumeration_process();
334 3 }
335 2 Usb_select_ep(EP_IN);
336 2 }
337 1
338 1 Usb_select_ep(EP_OUT);
339 1 while (Usb_STALL_requested())
340 1 {
341 2 Usb_select_ep(EP_CONTROL);
342 2 if (Usb_setup_received())
343 2 {
344 3 usb_enumeration_process();
345 3 }
346 2 Usb_select_ep(EP_OUT);
347 2 }
348 1
349 1 Usb_clear_no_data_phase();
350 1 Usb_clear_status_ready();
351 1 Usb_select_ep(EP_IN);
352 1 Usb_write_byte(0x55);
353 1 Usb_write_byte(0x53);
354 1 Usb_write_byte(0x42);
355 1 Usb_write_byte(0x53);
356 1
357 1 Usb_write_byte(dCBWTag[0]);
358 1 Usb_write_byte(dCBWTag[1]);
359 1 Usb_write_byte(dCBWTag[2]);
360 1 Usb_write_byte(dCBWTag[3]);
361 1 Usb_write_byte(((Byte*)&dCBWDataTransferLength)[3]);
362 1 Usb_write_byte(((Byte*)&dCBWDataTransferLength)[2]);
363 1 Usb_write_byte(((Byte*)&dCBWDataTransferLength)[1]);
364 1 Usb_write_byte(((Byte*)&dCBWDataTransferLength)[0]);
C51 COMPILER V7.02a USB_TASK 09/13/2007 11:53:05 PAGE 7
365 1 Usb_write_byte(status);
366 1 Usb_set_TXRDY();
367 1
368 1 Usb_select_ep(EP_IN);
369 1 while (!Usb_tx_complete());
370 1 Usb_clear_TXCMPL();
371 1 }
372
373
374 /*F**************************************************************************
375 * NAME: usb_mass_storage_reset
376 *----------------------------------------------------------------------------
377 * PARAMS:
378 *
379 * return:
380 *----------------------------------------------------------------------------
381 * PURPOSE:
382 * This function handles the mass storage reset command
383 *----------------------------------------------------------------------------
384 * EXAMPLE:
385 *----------------------------------------------------------------------------
386 * NOTE:
387 *----------------------------------------------------------------------------
388 * REQUIREMENTS:
389 *****************************************************************************/
390 void usb_mass_storage_reset (void)
391 {
392 1 Usb_clear_RXSETUP();
393 1 Usb_set_TXRDY();
394 1 while (!(Usb_tx_complete()));
395 1 Usb_clear_TXCMPL();
396 1 }
397
398
399 /*F**************************************************************************
400 * NAME: usb_mass_storage_get_lun
401 *----------------------------------------------------------------------------
402 * PARAMS:
403 *
404 * return:
405 *----------------------------------------------------------------------------
406 * PURPOSE:
407 * This function returns the mass storage class specific Logical Unit Number.
408 *----------------------------------------------------------------------------
409 * EXAMPLE:
410 *----------------------------------------------------------------------------
411 * NOTE:
412 *----------------------------------------------------------------------------
413 * REQUIREMENTS:
414 *****************************************************************************/
415 void usb_mass_storage_get_lun (void)
416 {
417 1 Usb_clear_RXSETUP();
418 1 Usb_set_DIR();
419 1 Usb_write_byte(MS_MAX_LUN);
420 1 Usb_set_TXRDY();
421 1 while (!(Usb_tx_complete()));
422 1 Usb_clear_TXCMPL();
423 1 while (!(Usb_rx_complete()));
424 1 Usb_clear_RXOUT();
425 1 Usb_clear_DIR();
426 1 #if (MS_MAX_LUN != 0)
C51 COMPILER V7.02a USB_TASK 09/13/2007 11:53:05 PAGE 8
ms_multiple_drive = TRUE; /* multiple disk support */
print_screen(MASS_SCREEN_NO_MEM); /* memory icon off */
#endif
430 1 }
431
432
433 /*F**************************************************************************
434 * NAME: usb_it_suspend
435 *----------------------------------------------------------------------------
436 * PARAMS:
437 *
438 * return:
439 *----------------------------------------------------------------------------
440 * PURPOSE:
441 * USB suspend interrupt function -> reset
442 *----------------------------------------------------------------------------
443 * EXAMPLE:
444 *----------------------------------------------------------------------------
445 * NOTE:
446 * IRQ_USB defined in extsnd1.h
447 *----------------------------------------------------------------------------
448 * REQUIREMENTS:
449 *****************************************************************************/
450 Interrupt (usb_it_suspend(void), IRQ_USB)
451 {
452 1 if (Usb_suspend())
453 1 {
454 2 Wdt_enable(0);
455 2 while (1);
456 2 }
457 1 }
458
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 466 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 5 ----
IDATA SIZE = 5 ----
BIT SIZE = 6 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -