test_usb_device.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2022 OpenLuat & AirM2M
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  5. * this software and associated documentation files (the "Software"), to deal in
  6. * the Software without restriction, including without limitation the rights to
  7. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  8. * the Software, and to permit persons to whom the Software is furnished to do so,
  9. * subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in all
  12. * copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  16. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  17. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  18. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  19. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  20. */
  21. #include "user.h"
  22. static uint8_t TestBuf[4096];
  23. static int32_t prvTest_USBCB(void *pData, void *pParam)
  24. {
  25. uint32_t UartID = (uint32_t)pData;
  26. uint32_t State = (uint32_t)pParam;
  27. uint16_t ReadLen;
  28. switch (State)
  29. {
  30. case UART_CB_TX_BUFFER_DONE:
  31. case UART_CB_TX_ALL_DONE:
  32. // DBG("usb send ok");
  33. // Core_PrintMemInfo();
  34. break;
  35. case UART_CB_RX_BUFFER_FULL:
  36. case UART_CB_RX_TIMEOUT:
  37. case UART_CB_RX_NEW:
  38. ReadLen = Core_VUartRxBufferRead(UartID, TestBuf, sizeof(TestBuf));
  39. Core_VUartBufferTx(UartID, TestBuf, ReadLen);
  40. break;
  41. case UART_CB_ERROR:
  42. DBG("usb disconnect");
  43. Core_VUartBufferTxStop(UartID); //也可以选择不清除,USB连上后,会自动重发,但是会有重复发送的情况,需要用户去处理
  44. break;
  45. case UART_CB_CONNECTED:
  46. Core_VUartBufferTx(UartID, "hello\r\n", 7);
  47. break;
  48. }
  49. }
  50. void Test_USBStart(void)
  51. {
  52. Core_VUartInit(VIRTUAL_UART0, 0, 1, 0, 0, 0, prvTest_USBCB);
  53. // Core_VUartSetRxTimeout(VIRTUAL_UART0, 200);
  54. }