boot_udc.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* Copyright (C) 2019 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef __BOOT_UDC_H_
  13. #define __BOOT_UDC_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. struct boot_udc;
  20. typedef struct boot_udc bootUdc_t;
  21. typedef struct
  22. {
  23. uint16_t mps;
  24. union {
  25. struct
  26. {
  27. uint8_t num : 7;
  28. uint8_t dirin : 1;
  29. };
  30. uint8_t address;
  31. };
  32. } bootUsbEp_t;
  33. struct boot_usb_xfer;
  34. typedef void (*bootUsbXferComp_t)(bootUsbEp_t *ep, struct boot_usb_xfer *xfer);
  35. typedef struct boot_usb_xfer
  36. {
  37. void *buf;
  38. uint32_t length;
  39. uint32_t actual;
  40. int status;
  41. uint8_t zlp;
  42. void *param;
  43. bootUsbXferComp_t complete;
  44. } bootUsbXfer_t;
  45. /**
  46. * \brief udc xfer enqueue
  47. *
  48. * \param udc the udc
  49. * \param ep the endpoint
  50. * \param xfer the usb transfer
  51. * \return true on success else false
  52. */
  53. bool bootUdcXferEnqueue(bootUdc_t *udc, bootUsbEp_t *ep, bootUsbXfer_t *xfer);
  54. /**
  55. * \brief udc xfer dequeue
  56. *
  57. * \param udc the udc
  58. * \param ep the endpoint
  59. * \param xfer the usb transfer
  60. */
  61. void bootUdcXferDequeue(bootUdc_t *udc, bootUsbEp_t *ep, bootUsbXfer_t *xfer);
  62. /**
  63. * \brief open the usb controller and got the controller instance
  64. *
  65. * \param name the controller device name
  66. * \param continue_rom do not restart the controller and keep connection from rom code or not
  67. * \return NULL if fail else the pointer of controller instance
  68. */
  69. bootUdc_t *bootUdcOpen(uint32_t name, bool continue_rom);
  70. /**
  71. * \brief close the usb controller and release the instance
  72. *
  73. * \param udc the udc
  74. */
  75. void bootUdcClose(bootUdc_t *udc);
  76. /**
  77. * \breif polling the usb controller interrupt and process them
  78. * (can only poll 'cause there is no INTERRUPT in bootloader codes)
  79. * \param udc the udc
  80. */
  81. bool bootUdcIsrPoll(bootUdc_t *udc);
  82. /**
  83. * \brief allocate and init an usb transfer from usb controller
  84. *
  85. * \param udc the udc
  86. * \param ep the endpoint
  87. * \return NULL if fail else the pointer of transfer
  88. */
  89. bootUsbXfer_t *bootUdcXferAlloc(bootUdc_t *udc, bootUsbEp_t *ep);
  90. /**
  91. * \brief free an usb transfer
  92. *
  93. * \param udc the udc
  94. * \param xfer the usb transfer
  95. */
  96. void bootUdcXferFree(bootUdc_t *udc, bootUsbXfer_t *xfer);
  97. /**
  98. * \brief check if the usb controller connected to a host
  99. *
  100. * \return true if connected
  101. */
  102. bool bootUdcConnected(bootUdc_t *udc);
  103. /**
  104. * \brief rom usb serial in endpoint
  105. *
  106. * \param udc the udc
  107. * \return NULL if not exist else usb endpoint
  108. */
  109. bootUsbEp_t *bootUdcRomSerialInEp(bootUdc_t *udc);
  110. /**
  111. * \brief rom usb serial out endpoint
  112. *
  113. * \param udc the udc
  114. * \return NULL if not exist else usb endpoint
  115. */
  116. bootUsbEp_t *bootUdcRomSerialOutEp(bootUdc_t *udc);
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120. #endif