📄 f3xx_usb0_interruptserviceroutine.lst
字号:
432 2 // packet was a stall
433 2 {
434 3 POLL_WRITE_BYTE (EOUTCSR1, rbOutCLRDT);
435 3 }
436 2
437 2 Setup_OUT_BUFFER (); // configure buffer to save
438 2 // received data
439 2 Fifo_Read(FIFO_EP1, OUT_BUFFER.Length, OUT_BUFFER.Ptr);
440 2
441 2 // process data according to received Report ID.
442 2 // In systems with Report Descriptors that do not define report IDs,
443 2 // the host will still format OUT packets with a prefix byte
444 2 // of '0x00'.
445 2
446 2 ReportHandler_OUT (OUT_BUFFER.Ptr[0]);
447 2
448 2 POLL_WRITE_BYTE (EOUTCSR1, 0); // Clear Out Packet ready bit
449 2 }
450 1 }
451
452 //-----------------------------------------------------------------------------
453 // Usb_Suspend
454 //-----------------------------------------------------------------------------
455 // Enter suspend mode after suspend signalling is present on the bus
456 //
457 void Usb_Suspend (void)
458 {
459 1 volatile int k;
460 1 k++;
461 1 }
462
463 //-----------------------------------------------------------------------------
464 // Fifo_Read
465 //-----------------------------------------------------------------------------
466 //
467 // Return Value : None
468 // Parameters :
469 // 1) BYTE addr : target address
470 // 2) unsigned int uNumBytes : number of bytes to unload
471 // 3) BYTE * pData : read data destination
472 //
473 // Read from the selected endpoint FIFO
474 //
475 //-----------------------------------------------------------------------------
476 void Fifo_Read (unsigned char addr, unsigned int uNumBytes,
477 unsigned char * pData)
478 {
479 1 int i;
480 1
481 1 if (uNumBytes) // Check if >0 bytes requested,
482 1 {
483 2 USB0ADR = (addr); // Set address
484 2 USB0ADR |= 0xC0; // Set auto-read and initiate
485 2 // first read
486 2
487 2 // Unload <NumBytes> from the selected FIFO
488 2 for(i=0;i< (uNumBytes);i++)
489 2 {
C51 COMPILER V8.05a F3XX_USB0_INTERRUPTSERVICEROUTINE 10/16/2008 16:50:25 PAGE 9
490 3 while (USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
491 3 pData[i] = USB0DAT; // Copy data byte
492 3 }
493 2
494 2 //while(USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
495 2 USB0ADR = 0; // Clear auto-read
496 2 }
497 1 }
498
499 //-----------------------------------------------------------------------------
500 // Fifo_Write
501 //-----------------------------------------------------------------------------
502 //
503 // Return Value : None
504 // Parameters :
505 // 1) BYTE addr : target address
506 // 2) unsigned int uNumBytes : number of bytes to unload
507 // 3) BYTE * pData : location of source data
508 //
509 // Write to the selected endpoint FIFO
510 //
511 // Fifo_Write_Foreground is used for function calls made in the foreground routines,
512 // and Fifo_Write_InterruptServiceRoutine is used for calls made in an ISR.
513
514 //-----------------------------------------------------------------------------
515
516 void Fifo_Write_Foreground (unsigned char addr, unsigned int uNumBytes,
517 unsigned char * pData)
518 {
519 1 int i;
520 1
521 1 // If >0 bytes requested,
522 1 if (uNumBytes)
523 1 {
524 2 while (USB0ADR & 0x80); // Wait for BUSY->'0'
525 2 // (register available)
526 2 USB0ADR = (addr); // Set address (mask out bits7-6)
527 2
528 2 // Write <NumBytes> to the selected FIFO
529 2 for(i=0;i<uNumBytes;i++)
530 2 {
531 3 USB0DAT = pData[i];
532 3 while (USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
533 3 }
534 2 }
535 1 }
536
537 void Fifo_Write_InterruptServiceRoutine (unsigned char addr,
538 unsigned int uNumBytes,
539 unsigned char * pData)
540 {
541 1 int i;
542 1
543 1 // If >0 bytes requested,
544 1 if (uNumBytes)
545 1 {
546 2 while (USB0ADR & 0x80); // Wait for BUSY->'0'
547 2 // (register available)
548 2 USB0ADR = (addr); // Set address (mask out bits7-6)
549 2
550 2 // Write <NumBytes> to the selected FIFO
551 2 for (i=0; i<uNumBytes; i++)
C51 COMPILER V8.05a F3XX_USB0_INTERRUPTSERVICEROUTINE 10/16/2008 16:50:25 PAGE 10
552 2 {
553 3 USB0DAT = pData[i];
554 3 while (USB0ADR & 0x80); // Wait for BUSY->'0' (data ready)
555 3 }
556 2 }
557 1 }
558
559 //-----------------------------------------------------------------------------
560 // Force_Stall
561 //-----------------------------------------------------------------------------
562 //
563 // Return Value : None
564 // Parameters : None
565 //
566 // Force a procedural stall to be sent to the host
567 //
568 //-----------------------------------------------------------------------------
569
570 void Force_Stall (void)
571 {
572 1 POLL_WRITE_BYTE (INDEX, 0);
573 1 POLL_WRITE_BYTE (E0CSR, rbSDSTL); // Set the send stall bit
574 1 EP_STATUS[0] = EP_STALL; // Put the endpoint in stall status
575 1 }
576
577
578 //-----------------------------------------------------------------------------
579 // SendPacket
580 //-----------------------------------------------------------------------------
581 //
582 // Return Value - None
583 // Parameters - Report ID that's used to call the appropriate IN handler
584 //
585 // This function can be called by other routines to force an IN packet
586 // transmit. It takes as an input the Report ID of the packet to be
587 // transmitted.
588 //-----------------------------------------------------------------------------
589
590 void SendPacket (unsigned char ReportID)
591 {
592 1 bit EAState;
593 1 unsigned char ControlReg;
594 1
595 1 EAState = EA;
596 1 EA = 0;
597 1
598 1 POLL_WRITE_BYTE (INDEX, 1); // Set index to endpoint 1 registers
599 1
600 1 // Read contol register for EP 1
601 1 POLL_READ_BYTE (EINCSR1, ControlReg);
602 1
603 1 if (EP_STATUS[1] == EP_HALT) // If endpoint is currently halted,
604 1 // send a stall
605 1 {
606 2 POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
607 2 }
608 1
609 1 else if(EP_STATUS[1] == EP_IDLE)
610 1 {
611 2 // the state will be updated inside the ISR handler
612 2 EP_STATUS[1] = EP_TX;
613 2
C51 COMPILER V8.05a F3XX_USB0_INTERRUPTSERVICEROUTINE 10/16/2008 16:50:25 PAGE 11
614 2 if (ControlReg & rbInSTSTL) // Clear sent stall if last
615 2 // packet returned a stall
616 2 {
617 3 POLL_WRITE_BYTE (EINCSR1, rbInCLRDT);
618 3 }
619 2
620 2 if (ControlReg & rbInUNDRUN) // Clear underrun bit if it was set
621 2 {
622 3 POLL_WRITE_BYTE (EINCSR1, 0x00);
623 3 }
624 2
625 2 ReportHandler_IN_Foreground (ReportID);
626 2
627 2 // Put new data on Fifo
628 2 Fifo_Write_Foreground (FIFO_EP1, IN_BUFFER.Length,
629 2 (unsigned char *)IN_BUFFER.Ptr);
630 2 POLL_WRITE_BYTE (EINCSR1, rbInINPRDY);
631 2 // Set In Packet ready bit,
632 2 } // indicating fresh data on FIFO 1
633 1
634 1 EA = EAState;
635 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1273 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 19 22
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -