Benchmark.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  1. /// Benchmark.c
  2. /// Single interface ping-pong buffering enabled.
  3. /* USB Benchmark for libusb-win32
  4. Copyright © 2010 Travis Robinson. <libusbdotnet@gmail.com>
  5. website: http://sourceforge.net/projects/libusb-win32
  6. Software License Agreement:
  7. The software supplied herewith is intended for use solely and
  8. exclusively on Microchip PIC Microcontroller products. This
  9. software is owned by Travis Robinson, and is protected under
  10. applicable copyright laws. All rights are reserved. Any use in
  11. violation of the foregoing restrictions may subject the user to
  12. criminal sanctions under applicable laws, as well as to civil
  13. liability for the breach of the terms and conditions of this
  14. license.
  15. You may redistribute and/or modify this file under the terms
  16. described above.
  17. THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
  18. WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
  19. TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  20. PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE OWNER SHALL NOT,
  21. IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
  22. CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  23. */
  24. /** INCLUDES *******************************************************/
  25. #include "USB/usb.h"
  26. #include "USB/usb_function_generic.h"
  27. #include "HardwareProfile.h"
  28. #include "Benchmark.h"
  29. #include "PicFWCommands.h"
  30. #include "BDT_transfer.h"
  31. /** VARIABLES ******************************************************/
  32. //NOTE: The below endpoint buffers need to be located in a section of
  33. //system SRAM that is accessible by the USB module. The USB module on all
  34. //currently existing Microchip USB microcontrollers use a dedicated DMA
  35. //interface for reading/writing USB data into/out of main system SRAM.
  36. //On some USB PIC microcontrollers, all of the microcontroller SRAM is dual
  37. //access, and therefore all of it can be accessed by either the USB
  38. //module or the microcontroller core. On other devices, only a certain
  39. //portion of the SRAM is accessible by the USB module. Therefore, on some
  40. //devices, it is important to place USB data buffers in certain sections of
  41. //SRAM, while on other devices, the buffers can be placed anywhere.
  42. //For all PIC18F87J50 family and PIC18F46J50 family devices: all SRAM is USB accessible.
  43. //For PIC18F1xK50 devices: 0x200-0x2FF is USB accessible.
  44. //For PIC18F4450/2450 devices: 0x400-0x4FF is USB accessible.
  45. //For PIC18F4550/4553/4455/4458/2550/2553/2455/2458: 0x400-0x7FF is USB accessible.
  46. #if defined(__18F14K50) || defined(__18F13K50) || defined(__18LF14K50) || defined(__18LF13K50)
  47. #pragma udata USB_VARIABLES=0x240
  48. #elif defined(__18F2455) || defined(__18F2550) || defined(__18F4455) || defined(__18F4550) || defined(__18F2458) || defined(__18F2453) || defined(__18F4558) || defined(__18F4553)
  49. #pragma udata USB_VARIABLES=0x450
  50. #elif defined(__18F4450) || defined(__18F2450)
  51. #pragma udata USB_VARIABLES=0x450
  52. #else
  53. #pragma udata
  54. #endif
  55. // Data buffers
  56. BYTE BenchmarkBuffers_INTF0_1[2][PP_COUNT][USBGEN_EP_SIZE_INTF0];
  57. BYTE BenchmarkBuffers_INTF0_2[2][PP_COUNT][USBGEN_EP_SIZE_INTF0];
  58. BYTE BenchmarkBuffer_CTRL[USB_EP0_BUFF_SIZE];
  59. #ifdef DUAL_INTERFACE
  60. BYTE BenchmarkBuffers_INTF1[2][PP_COUNT][USBGEN_EP_SIZE_INTF1];
  61. #endif
  62. // The below variables are only accessed by the CPU and can be placed anywhere in RAM.
  63. #pragma udata
  64. WORD Ctrl_BufferCount = 0;
  65. // Temporary variables
  66. WORD counter;
  67. // Internal test variables
  68. volatile BYTE TestType_INTF0;
  69. volatile BYTE PrevTestType_INTF0;
  70. volatile BYTE FillCount_INTF0_1;
  71. volatile BYTE NextPacketKey_INTF0_1;
  72. volatile BYTE FillCount_INTF0_2;
  73. volatile BYTE NextPacketKey_INTF0_2;
  74. #ifdef DUAL_INTERFACE
  75. volatile BYTE TestType_INTF1;
  76. volatile BYTE PrevTestType_INTF1;
  77. volatile BYTE FillCount_INTF1;
  78. volatile BYTE NextPacketKey_INTF1;
  79. #endif
  80. /** EXTERNS ********************************************************/
  81. extern void BlinkUSBStatus(void);
  82. /** BMARK FUNCTIONS ************************************************/
  83. void doBenchmarkLoop_INTF0(void);
  84. void doBenchmarkWrite_INTF0(void);
  85. void doBenchmarkRead_INTF0(void);
  86. #ifdef DUAL_INTERFACE
  87. void doBenchmarkLoop_INTF1(void);
  88. void doBenchmarkWrite_INTF1(void);
  89. void doBenchmarkRead_INTF1(void);
  90. #endif
  91. void fillBuffer(BYTE* pBuffer, WORD size);
  92. /** BMARK MACROS ****************************************************/
  93. #define mBenchMarkInit_INTF0() \
  94. { \
  95. TestType_INTF0=TEST_LOOP; \
  96. PrevTestType_INTF0=TEST_LOOP; \
  97. FillCount_INTF0_1=0; \
  98. NextPacketKey_INTF0_1=0; \
  99. FillCount_INTF0_2=0; \
  100. NextPacketKey_INTF0_2=0; \
  101. }
  102. #define mBenchMarkInit_INTF1() \
  103. { \
  104. TestType_INTF1=TEST_LOOP; \
  105. PrevTestType_INTF1=TEST_LOOP; \
  106. FillCount_INTF1_1=0; \
  107. NextPacketKey_INTF1_1=0; \
  108. FillCount_INTF1_2=0; \
  109. NextPacketKey_INTF1_2=0; \
  110. }
  111. #define mSetWritePacketID(BufferPtr, BufferSize, FillCount, NextPacketKey) \
  112. { \
  113. if (FillCount < 3) \
  114. { \
  115. FillCount++; \
  116. fillBuffer((BYTE*)BufferPtr,BufferSize); \
  117. } \
  118. BufferPtr[1]=NextPacketKey++; \
  119. }
  120. // If interface #0 is iso, use an iso specific submit macro
  121. #if (INTF0==EP_ISO)
  122. #define mSubmitTransfer_INTF0(BdtPtr, BufferLength) mBDT_SubmitIsoTransfer(BdtPtr, BufferLength)
  123. #else
  124. #define mSubmitTransfer_INTF0(BdtPtr, BufferLength) mBDT_SubmitTransfer(BdtPtr)
  125. #endif
  126. // If interface #1 is iso, use an iso specific submit macro
  127. #if (INTF1==EP_ISO)
  128. #define mSubmitTransfer_INTF1(BdtPtr, BufferLength) mBDT_SubmitIsoTransfer(BdtPtr, BufferLength)
  129. #else
  130. #define mSubmitTransfer_INTF1(BdtPtr, BufferLength) mBDT_SubmitTransfer(BdtPtr)
  131. #endif
  132. #define GetBenchmarkBuffer(IntfSuffix, Direction, IsOdd) BenchmarkBuffers_##IntfSuffix[Direction][IsOdd]
  133. // Swaps byte pointers
  134. #define Swap(r1,r2) { pSwapBufferTemp = r1; r1 = r2; r2 = pSwapBufferTemp; }
  135. /** BMARK DECLARATIONS *********************************************/
  136. #pragma code
  137. // The Benchmark firmware "overrides" the USBCBInitEP to initialize
  138. // the OUT (MCU Rx) endpoint with the first BenchmarkBuffer.
  139. void USBCBInitEP(void)
  140. {
  141. USBEnableEndpoint(USBGEN_EP_NUM_INTF0_1,USB_OUT_ENABLED|USB_IN_ENABLED|USBGEN_EP_HANDSHAKE_INTF0_1|USB_DISALLOW_SETUP);
  142. USBEnableEndpoint(USBGEN_EP_NUM_INTF0_2,USB_OUT_ENABLED|USB_IN_ENABLED|USBGEN_EP_HANDSHAKE_INTF0_1|USB_DISALLOW_SETUP);
  143. //Prepare the OUT endpoints to receive the first packets from the host.
  144. pBdtRxEp1->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_1, OUT_FROM_HOST, mBDT_IsOdd(pBdtRxEp1)));
  145. #if (PP_COUNT==(2))
  146. mBDT_TogglePP(pBdtRxEp1);
  147. pBdtRxEp1->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_1, OUT_FROM_HOST, mBDT_IsOdd(pBdtRxEp1)));
  148. mBDT_TogglePP(pBdtRxEp1);
  149. #endif
  150. pBdtRxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_2, OUT_FROM_HOST, mBDT_IsOdd(pBdtRxEp2)));
  151. #if (PP_COUNT==(2))
  152. mBDT_TogglePP(pBdtRxEp2);
  153. pBdtRxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_2, OUT_FROM_HOST, mBDT_IsOdd(pBdtRxEp2)));
  154. mBDT_TogglePP(pBdtRxEp2);
  155. #endif
  156. doBenchmarkRead_INTF0();
  157. doBenchmarkRead_INTF0();
  158. pBdtTxEp1->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_1, IN_TO_HOST, mBDT_IsOdd(pBdtTxEp1)));
  159. #if (PP_COUNT==(2))
  160. mBDT_TogglePP(pBdtTxEp1);
  161. pBdtTxEp1->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_1, IN_TO_HOST, mBDT_IsOdd(pBdtTxEp1)));
  162. mBDT_TogglePP(pBdtTxEp1);
  163. #endif
  164. pBdtTxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_2, IN_TO_HOST, mBDT_IsOdd(pBdtTxEp2)));
  165. #if (PP_COUNT==(2))
  166. mBDT_TogglePP(pBdtTxEp2);
  167. pBdtTxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF0_2, IN_TO_HOST, mBDT_IsOdd(pBdtTxEp2)));
  168. mBDT_TogglePP(pBdtTxEp2);
  169. #endif
  170. Ctrl_BufferCount = 0;
  171. #ifdef DUAL_INTERFACE
  172. USBEnableEndpoint(USBGEN_EP_NUM_INTF1,USB_OUT_ENABLED|USB_IN_ENABLED|USBGEN_EP_HANDSHAKE_INTF1|USB_DISALLOW_SETUP);
  173. //Prepare the OUT endpoints to receive the first packets from the host.
  174. pBdtRxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF1, OUT_FROM_HOST, mBDT_IsOdd(pBdtRxEp2)));
  175. #if (PP_COUNT==(2))
  176. mBDT_TogglePP(pBdtRxEp2);
  177. pBdtRxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF1, OUT_FROM_HOST, mBDT_IsOdd(pBdtRxEp2)));
  178. mBDT_TogglePP(pBdtRxEp2);
  179. #endif
  180. doBenchmarkRead_INTF1();
  181. doBenchmarkRead_INTF1();
  182. pBdtTxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF1, IN_TO_HOST, mBDT_IsOdd(pBdtTxEp2)));
  183. #if (PP_COUNT==(2))
  184. mBDT_TogglePP(pBdtTxEp2);
  185. pBdtTxEp2->ADR = ConvertToPhysicalAddress(GetBenchmarkBuffer(INTF1, IN_TO_HOST, mBDT_IsOdd(pBdtTxEp2)));
  186. mBDT_TogglePP(pBdtTxEp2);
  187. #endif
  188. #endif
  189. }
  190. void USBCBCheckOtherReq(void)
  191. {
  192. if (SetupPkt.RequestType != USB_SETUP_TYPE_VENDOR_BITFIELD) return;
  193. switch (SetupPkt.bRequest)
  194. {
  195. case PICFW_SET_TEST:
  196. #ifdef DUAL_INTERFACE
  197. if ((SetupPkt.wIndex & 0xff) == 1)
  198. {
  199. TestType_INTF1=SetupPkt.wValue & 0xff;
  200. inPipes[0].pSrc.bRam = (BYTE*)&TestType_INTF1; // Set Source
  201. inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type
  202. inPipes[0].wCount.v[0] = 1; // Set data count
  203. inPipes[0].info.bits.busy = 1;
  204. }
  205. else
  206. #endif
  207. {
  208. TestType_INTF0=SetupPkt.wValue & 0xff;
  209. inPipes[0].pSrc.bRam = (BYTE*)&TestType_INTF0; // Set Source
  210. inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type
  211. inPipes[0].wCount.v[0] = 1; // Set data count
  212. inPipes[0].info.bits.busy = 1;
  213. }
  214. break;
  215. case PICFW_GET_TEST:
  216. #ifdef DUAL_INTERFACE
  217. if ((SetupPkt.wIndex & 0xff) == 1)
  218. {
  219. inPipes[0].pSrc.bRam = (BYTE*)&TestType_INTF1; // Set Source
  220. inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type
  221. inPipes[0].wCount.v[0] = 1; // Set data count
  222. inPipes[0].info.bits.busy = 1;
  223. }
  224. else
  225. #endif
  226. {
  227. inPipes[0].pSrc.bRam = (BYTE*)&TestType_INTF0; // Set Source
  228. inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type
  229. inPipes[0].wCount.v[0] = 1; // Set data count
  230. inPipes[0].info.bits.busy = 1;
  231. }
  232. break;
  233. case PICFW_GET_EEDATA:
  234. break;
  235. case PICFW_SET_EEDATA:
  236. break;
  237. case CTRL_LOOPBACK_WRITE:
  238. Ctrl_BufferCount = SetupPkt.wLength;
  239. outPipes[0].pDst.bRam = BenchmarkBuffer_CTRL;
  240. outPipes[0].info.bits.busy = 1;
  241. outPipes[0].wCount.Val = Ctrl_BufferCount;
  242. break;
  243. case CTRL_LOOPBACK_READ:
  244. inPipes[0].pSrc.bRam = BenchmarkBuffer_CTRL; // Set Source
  245. inPipes[0].info.bits.ctrl_trf_mem = USB_EP0_RAM; // Set memory type
  246. inPipes[0].wCount.Val = SetupPkt.wLength > Ctrl_BufferCount ? Ctrl_BufferCount : SetupPkt.wLength; // Set data count
  247. inPipes[0].info.bits.busy = 1;
  248. break;
  249. default:
  250. break;
  251. }//end switch
  252. }//end
  253. void Benchmark_Init(void)
  254. {
  255. mBenchMarkInit_INTF0();
  256. #ifdef DUAL_INTERFACE
  257. mBenchMarkInit(INTF1);
  258. #endif
  259. }//end UserInit
  260. void fillBuffer(BYTE* pBuffer, WORD size)
  261. {
  262. BYTE dataByte = 0;
  263. for (counter=0; counter < size; counter++)
  264. {
  265. pBuffer[counter] = dataByte++;
  266. if (dataByte == 0) dataByte++;
  267. }
  268. }
  269. void Benchmark_ProcessIO(void)
  270. {
  271. //Blink the LEDs according to the USB device status, but only do so if the PC application isn't connected and controlling the LEDs.
  272. BlinkUSBStatus();
  273. //Don't attempt to read/write over the USB until after the device has been fully enumerated.
  274. if((USBDeviceState < CONFIGURED_STATE)||(USBSuspendControl==1))
  275. {
  276. Benchmark_Init();
  277. return;
  278. }
  279. if (TestType_INTF0!=PrevTestType_INTF0)
  280. {
  281. FillCount_INTF0_1=0;
  282. NextPacketKey_INTF0_1=0;
  283. FillCount_INTF0_2=0;
  284. NextPacketKey_INTF0_2=0;
  285. PrevTestType_INTF0=TestType_INTF0;
  286. }
  287. switch(TestType_INTF0)
  288. {
  289. case TEST_PCREAD:
  290. doBenchmarkWrite_INTF0();
  291. break;
  292. case TEST_PCWRITE:
  293. doBenchmarkRead_INTF0();
  294. break;
  295. case TEST_LOOP:
  296. doBenchmarkLoop_INTF0();
  297. break;
  298. default:
  299. doBenchmarkRead_INTF0();
  300. break;
  301. }
  302. #ifdef DUAL_INTERFACE
  303. if (TestType_INTF1!=PrevTestType_INTF1)
  304. {
  305. FillCount_INTF1=0;
  306. NextPacketKey_INTF1=0;
  307. PrevTestType_INTF1=TestType_INTF1;
  308. }
  309. switch(TestType_INTF1)
  310. {
  311. case TEST_PCREAD:
  312. doBenchmarkWrite_INTF1();
  313. break;
  314. case TEST_PCWRITE:
  315. doBenchmarkRead_INTF1();
  316. break;
  317. case TEST_LOOP:
  318. doBenchmarkLoop_INTF1();
  319. break;
  320. default:
  321. doBenchmarkRead_INTF1();
  322. break;
  323. }
  324. #endif
  325. }//end Benchmark_ProcessIO
  326. void doBenchmarkWrite_INTF0(void)
  327. {
  328. BYTE* pBufferTx;
  329. if (!USBHandleBusy(pBdtTxEp1))
  330. {
  331. pBufferTx = USBHandleGetAddr(pBdtTxEp1);
  332. mSetWritePacketID(pBufferTx, USBGEN_EP_SIZE_INTF0, FillCount_INTF0_1, NextPacketKey_INTF0_1);
  333. mBDT_FillTransfer(pBdtTxEp1, pBufferTx, USBGEN_EP_SIZE_INTF0);
  334. mSubmitTransfer_INTF0(pBdtTxEp1, USBGEN_EP_SIZE_INTF0);
  335. mBDT_TogglePP(pBdtTxEp1);
  336. }
  337. if (!USBHandleBusy(pBdtTxEp2))
  338. {
  339. pBufferTx = USBHandleGetAddr(pBdtTxEp2);
  340. mSetWritePacketID(pBufferTx, USBGEN_EP_SIZE_INTF0, FillCount_INTF0_2, NextPacketKey_INTF0_2);
  341. mBDT_FillTransfer(pBdtTxEp2, pBufferTx, USBGEN_EP_SIZE_INTF0);
  342. mSubmitTransfer_INTF0(pBdtTxEp2, USBGEN_EP_SIZE_INTF0);
  343. mBDT_TogglePP(pBdtTxEp2);
  344. }
  345. }
  346. void doBenchmarkLoop_INTF0(void)
  347. {
  348. WORD Length;
  349. BYTE* pBufferRx;
  350. BYTE* pBufferTx;
  351. if (!USBHandleBusy(pBdtRxEp1) && !USBHandleBusy(pBdtTxEp1))
  352. {
  353. pBufferTx = USBHandleGetAddr(pBdtRxEp1);
  354. pBufferRx = USBHandleGetAddr(pBdtTxEp1);
  355. #if INTF0_1==EP_ISO
  356. Length = USBGEN_EP_SIZE_INTF0;
  357. #else
  358. Length = mBDT_GetLength(pBdtRxEp1);
  359. #endif
  360. mBDT_FillTransfer(pBdtTxEp1, pBufferTx, Length);
  361. mSubmitTransfer_INTF0(pBdtTxEp1, Length);
  362. mBDT_TogglePP(pBdtTxEp1);
  363. mBDT_FillTransfer(pBdtRxEp1, pBufferRx, USBGEN_EP_SIZE_INTF0);
  364. mSubmitTransfer_INTF0(pBdtRxEp1, USBGEN_EP_SIZE_INTF0);
  365. mBDT_TogglePP(pBdtRxEp1);
  366. }
  367. if (!USBHandleBusy(pBdtRxEp2) && !USBHandleBusy(pBdtTxEp2))
  368. {
  369. pBufferTx = USBHandleGetAddr(pBdtRxEp2);
  370. pBufferRx = USBHandleGetAddr(pBdtTxEp2);
  371. #if INTF0_2==EP_ISO
  372. Length = USBGEN_EP_SIZE_INTF0;
  373. #else
  374. Length = mBDT_GetLength(pBdtRxEp2);
  375. #endif
  376. mBDT_FillTransfer(pBdtTxEp2, pBufferTx, Length);
  377. mSubmitTransfer_INTF0(pBdtTxEp2, Length);
  378. mBDT_TogglePP(pBdtTxEp2);
  379. mBDT_FillTransfer(pBdtRxEp2, pBufferRx, USBGEN_EP_SIZE_INTF0);
  380. mSubmitTransfer_INTF0(pBdtRxEp2, USBGEN_EP_SIZE_INTF0);
  381. mBDT_TogglePP(pBdtRxEp2);
  382. }
  383. }
  384. void doBenchmarkRead_INTF0(void)
  385. {
  386. BYTE* pBufferRx;
  387. if (!USBHandleBusy(pBdtRxEp1))
  388. {
  389. pBufferRx = USBHandleGetAddr(pBdtRxEp1);
  390. mBDT_FillTransfer(pBdtRxEp1, pBufferRx, USBGEN_EP_SIZE_INTF0);
  391. mSubmitTransfer_INTF0(pBdtRxEp1, USBGEN_EP_SIZE_INTF0);
  392. mBDT_TogglePP(pBdtRxEp1);
  393. }
  394. if (!USBHandleBusy(pBdtRxEp2))
  395. {
  396. pBufferRx = USBHandleGetAddr(pBdtRxEp2);
  397. mBDT_FillTransfer(pBdtRxEp2, pBufferRx, USBGEN_EP_SIZE_INTF0);
  398. mSubmitTransfer_INTF0(pBdtRxEp2, USBGEN_EP_SIZE_INTF0);
  399. mBDT_TogglePP(pBdtRxEp2);
  400. }
  401. }
  402. #ifdef DUAL_INTERFACE
  403. void doBenchmarkWrite_INTF1(void)
  404. {
  405. BYTE* pBufferTx;
  406. if (!USBHandleBusy(pBdtTxEp2))
  407. {
  408. pBufferTx = USBHandleGetAddr(pBdtTxEp2);
  409. mSetWritePacketID(pBufferTx, USBGEN_EP_SIZE_INTF1, FillCount_INTF1, NextPacketKey_INTF1);
  410. mBDT_FillTransfer(pBdtTxEp2, pBufferTx, USBGEN_EP_SIZE_INTF1);
  411. mSubmitTransfer_INTF1(pBdtTxEp2, USBGEN_EP_SIZE_INTF1);
  412. mBDT_TogglePP(pBdtTxEp2);
  413. }
  414. }
  415. void doBenchmarkLoop_INTF1(void)
  416. {
  417. WORD Length;
  418. BYTE* pBufferRx;
  419. BYTE* pBufferTx;
  420. if (!USBHandleBusy(pBdtRxEp2) && !USBHandleBusy(pBdtTxEp2))
  421. {
  422. pBufferTx = USBHandleGetAddr(pBdtRxEp2);
  423. pBufferRx = USBHandleGetAddr(pBdtTxEp2);
  424. #if INTF1==EP_ISO
  425. Length = USBGEN_EP_SIZE_INTF1;
  426. #else
  427. Length = mBDT_GetLength(pBdtRxEp2);
  428. #endif
  429. mBDT_FillTransfer(pBdtTxEp2, pBufferTx, Length);
  430. mSubmitTransfer_INTF1(pBdtTxEp2, Length);
  431. mBDT_TogglePP(pBdtTxEp2);
  432. mBDT_FillTransfer(pBdtRxEp2, pBufferRx, USBGEN_EP_SIZE_INTF1);
  433. mSubmitTransfer_INTF1(pBdtRxEp2, USBGEN_EP_SIZE_INTF1);
  434. mBDT_TogglePP(pBdtRxEp2);
  435. }
  436. }
  437. void doBenchmarkRead_INTF1(void)
  438. {
  439. BYTE* pBufferRx;
  440. if (!USBHandleBusy(pBdtRxEp2))
  441. {
  442. pBufferRx = USBHandleGetAddr(pBdtRxEp2);
  443. mBDT_FillTransfer(pBdtRxEp2, pBufferRx, USBGEN_EP_SIZE_INTF1);
  444. mSubmitTransfer_INTF1(pBdtRxEp2, USBGEN_EP_SIZE_INTF1);
  445. mBDT_TogglePP(pBdtRxEp2);
  446. }
  447. }
  448. #endif