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