BDT_transfer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef _BBT_TRANSFER_H
  2. #define _BBT_TRANSFER_H
  3. #include "USB/usb.h"
  4. #include "USB/usb_function_generic.h"
  5. #include "HardwareProfile.h"
  6. // Externs from usb_device.c
  7. extern volatile BDT_ENTRY* pBDTEntryOut[USB_MAX_EP_NUMBER+1];
  8. extern volatile BDT_ENTRY* pBDTEntryIn[USB_MAX_EP_NUMBER+1];
  9. /////////////////////////
  10. // BDT transfer macros //
  11. /////////////////////////
  12. //Toggle the DTS bit if required
  13. #if ((USB_PING_PONG_MODE==USB_PING_PONG__FULL_PING_PONG) || (USB_PING_PONG_MODE==USB_PING_PONG__ALL_BUT_EP0))
  14. #define PP_COUNT (2)
  15. // Copied from usb_device.h ///////////////
  16. #if defined (__18CXX) || defined(__C30__)
  17. #define USB_NEXT_PING_PONG 0x0004
  18. #elif defined(__C32__)
  19. #define USB_NEXT_PING_PONG 0x0008
  20. #else
  21. #error "Not defined for this compiler"
  22. #endif
  23. ///////////////////////////////////////////
  24. #define mBDT_MaskAndToggleDTS(BdtPtr) (BdtPtr->STAT.Val & _DTSMASK)
  25. #define mBDT_IsOdd(BdtPtr) ((((BYTE_VAL*)&BdtPtr)->Val & USB_NEXT_PING_PONG)?1:0)
  26. #define mBDT_TogglePP(BdtPtr) ((BYTE_VAL*)&BdtPtr)->Val ^= USB_NEXT_PING_PONG
  27. #else
  28. #define PP_COUNT (1)
  29. #define mBDT_MaskAndToggleDTS(BdtPtr) ((BdtPtr->STAT.Val & _DTSMASK) ^ _DTSMASK)
  30. #define mBDT_IsOdd(BdtPtr) (0)
  31. #define mBDT_TogglePP(BdtPtr)
  32. #endif
  33. #if defined(__C32__)
  34. #define mBDT_FillTransfer(BdtPtr, BufferPtr, BufferLength) \
  35. { \
  36. BdtPtr->ADR = ConvertToPhysicalAddress(BufferPtr); \
  37. BdtPtr->CNT = BufferLength; \
  38. }
  39. #define mBDT_GetLength(BdtPtr) (BdtPtr->CNT)
  40. #else
  41. #define mBDT_FillTransfer(BdtPtr, BufferPtr, BufferLength) \
  42. { \
  43. BdtPtr->ADR = ConvertToPhysicalAddress(BufferPtr); \
  44. BdtPtr->CNT = (BYTE)BufferLength; \
  45. }
  46. #define mBDT_GetLength(BdtPtr) (BdtPtr->CNT + ((BdtPtr->STAT.Val << 8) & 0x300))
  47. #endif
  48. // Masks STAT with DTS, Set _USIE, _DTSEN
  49. #define mBDT_SubmitTransfer(BdtPtr) BdtPtr->STAT.Val = (mBDT_MaskAndToggleDTS(BdtPtr)) | _USIE | _DTSEN
  50. #if defined (__18CXX) || defined(__C30__)
  51. // Sets BC8 & BC9 with high transfer length bits, _USIE
  52. #define mBDT_SubmitIsoTransfer(BdtPtr, BufferLength) BdtPtr->STAT.Val = (((BufferLength >> 8) & 0x3) | _USIE)
  53. #elif defined(__C32__)
  54. // Sets _USIE (CNT is 16bit for PIC32)
  55. #define mBDT_SubmitIsoTransfer(BdtPtr, BufferLength) BdtPtr->STAT.Val = _USIE
  56. #else
  57. #error "Not defined for this compiler"
  58. #endif
  59. #if USB_MAX_EP_NUMBER > 0
  60. #define pBdtRxEp1 pBDTEntryOut[1]
  61. #define pBdtOutEp1 pBDTEntryOut[1]
  62. #define pBdtTxEp1 pBDTEntryIn[1]
  63. #define pBdtInEp1 pBDTEntryIn[1]
  64. #endif
  65. #if USB_MAX_EP_NUMBER > 1
  66. #define pBdtRxEp2 pBDTEntryOut[2]
  67. #define pBdtOutEp2 pBDTEntryOut[2]
  68. #define pBdtTxEp2 pBDTEntryIn[2]
  69. #define pBdtInEp2 pBDTEntryIn[2]
  70. #endif
  71. #if USB_MAX_EP_NUMBER > 2
  72. #define pBdtRxEp3 pBDTEntryOut[3]
  73. #define pBdtOutEp3 pBDTEntryOut[3]
  74. #define pBdtTxEp3 pBDTEntryIn[3]
  75. #define pBdtInEp3 pBDTEntryIn[3]
  76. #endif
  77. #if USB_MAX_EP_NUMBER > 3
  78. #define pBdtRxEp4 pBDTEntryOut[4]
  79. #define pBdtOutEp4 pBDTEntryOut[4]
  80. #define pBdtTxEp4 pBDTEntryIn[4]
  81. #define pBdtInEp4 pBDTEntryIn[4]
  82. #endif
  83. #if USB_MAX_EP_NUMBER > 4
  84. #define pBdtRxEp5 pBDTEntryOut[5]
  85. #define pBdtOutEp5 pBDTEntryOut[5]
  86. #define pBdtTxEp5 pBDTEntryIn[5]
  87. #define pBdtInEp5 pBDTEntryIn[5]
  88. #endif
  89. #if USB_MAX_EP_NUMBER > 5
  90. #define pBdtRxEp6 pBDTEntryOut[6]
  91. #define pBdtOutEp6 pBDTEntryOut[6]
  92. #define pBdtTxEp6 pBDTEntryIn[6]
  93. #define pBdtInEp6 pBDTEntryIn[6]
  94. #endif
  95. #if USB_MAX_EP_NUMBER > 6
  96. #define pBdtRxEp7 pBDTEntryOut[7]
  97. #define pBdtOutEp7 pBDTEntryOut[7]
  98. #define pBdtTxEp7 pBDTEntryIn[7]
  99. #define pBdtInEp7 pBDTEntryIn[7]
  100. #endif
  101. #if USB_MAX_EP_NUMBER > 7
  102. #define pBdtRxEp8 pBDTEntryOut[8]
  103. #define pBdtOutEp8 pBDTEntryOut[8]
  104. #define pBdtTxEp8 pBDTEntryIn[8]
  105. #define pBdtInEp8 pBDTEntryIn[8]
  106. #endif
  107. #if USB_MAX_EP_NUMBER > 8
  108. #define pBdtRxEp9 pBDTEntryOut[9]
  109. #define pBdtOutEp9 pBDTEntryOut[9]
  110. #define pBdtTxEp9 pBDTEntryIn[9]
  111. #define pBdtInEp9 pBDTEntryIn[9]
  112. #endif
  113. #if USB_MAX_EP_NUMBER > 9
  114. #define pBdtRxEp10 pBDTEntryOut[10]
  115. #define pBdtOutEp10 pBDTEntryOut[10]
  116. #define pBdtTxEp10 pBDTEntryIn[10]
  117. #define pBdtInEp10 pBDTEntryIn[10]
  118. #endif
  119. #if USB_MAX_EP_NUMBER > 10
  120. #define pBdtRxEp11 pBDTEntryOut[11]
  121. #define pBdtOutEp11 pBDTEntryOut[11]
  122. #define pBdtTxEp11 pBDTEntryIn[11]
  123. #define pBdtInEp11 pBDTEntryIn[11]
  124. #endif
  125. #if USB_MAX_EP_NUMBER > 11
  126. #define pBdtRxEp12 pBDTEntryOut[12]
  127. #define pBdtOutEp12 pBDTEntryOut[12]
  128. #define pBdtTxEp12 pBDTEntryIn[12]
  129. #define pBdtInEp12 pBDTEntryIn[12]
  130. #endif
  131. #if USB_MAX_EP_NUMBER > 12
  132. #define pBdtRxEp13 pBDTEntryOut[13]
  133. #define pBdtOutEp13 pBDTEntryOut[13]
  134. #define pBdtTxEp13 pBDTEntryIn[13]
  135. #define pBdtInEp13 pBDTEntryIn[13]
  136. #endif
  137. #if USB_MAX_EP_NUMBER > 13
  138. #define pBdtRxEp14 pBDTEntryOut[14]
  139. #define pBdtOutEp14 pBDTEntryOut[14]
  140. #define pBdtTxEp14 pBDTEntryIn[14]
  141. #define pBdtInEp14 pBDTEntryIn[14]
  142. #endif
  143. #if USB_MAX_EP_NUMBER > 14
  144. #define pBdtRxEp15 pBDTEntryOut[15]
  145. #define pBdtOutEp15 pBDTEntryOut[15]
  146. #define pBdtTxEp15 pBDTEntryIn[15]
  147. #define pBdtInEp15 pBDTEntryIn[15]
  148. #endif
  149. #endif