boot_uart.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /* Copyright (C) 2017 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_UART_H_
  13. #define _BOOT_UART_H_
  14. #include "osi_compiler.h"
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /**
  19. * \brief opaque data structure for uart
  20. */
  21. typedef struct bootUart bootUart_t;
  22. /**
  23. * \brief open uart
  24. *
  25. * When \p reconfig is false, the UART won't be re-configured, such as
  26. * iomux, uart config and baud rate. This is useful that it is known
  27. * that the uart is already configured. For example, when ROM jumps to
  28. * FDL, the uart is already configured, and the configured baud rate
  29. * should be used.
  30. *
  31. * When \p reconfig is false, \p baud will be ignored.
  32. *
  33. * \param name uart device name
  34. * \param baud baud rate
  35. * \param reconfig false to ignore re-configuration
  36. * \return
  37. * - the uart instance
  38. * - NULL for failed
  39. */
  40. bootUart_t *bootUartOpen(uint32_t name, uint32_t baud, bool reconfig);
  41. /**
  42. * \brief whether baud rate is supported
  43. *
  44. * \param uart uart instance
  45. * \param baud baud rate to be checked
  46. * \return
  47. * - true on supported
  48. * - false on unsupported
  49. */
  50. bool bootUartBaudSupported(bootUart_t *uart, uint32_t baud);
  51. /**
  52. * \brief set baud rate
  53. *
  54. * \param uart uart instance
  55. * \param baud baud rate to be set
  56. * \return
  57. * - true on success
  58. * - false on failed
  59. */
  60. bool bootUartSetBaud(bootUart_t *uart, uint32_t baud);
  61. /**
  62. * \brief get available size for read
  63. *
  64. * \param uart uart instance
  65. * \return
  66. * - available size for read
  67. */
  68. int bootUartAvail(bootUart_t *uart);
  69. /**
  70. * \brief read from the uart
  71. *
  72. * \param uart uart instance
  73. * \param data memory for read data
  74. * \param size maximum read size
  75. * \return
  76. * - actual read size
  77. */
  78. int bootUartRead(bootUart_t *uart, void *data, size_t size);
  79. /**
  80. * \brief write to the uart
  81. *
  82. * \param uart uart instance
  83. * \param data pointer of data to be written
  84. * \param size maximum write size
  85. * \return
  86. * - actual written size
  87. */
  88. int bootUartWrite(bootUart_t *uart, const void *data, size_t size);
  89. /**
  90. * \brief flush output
  91. *
  92. * This will wait all data will be sent out, and the peer is able to
  93. * receive all data.
  94. *
  95. * \param uart uart instance
  96. */
  97. void bootUartFlush(bootUart_t *uart);
  98. /**
  99. * \brief write all data to the uart
  100. *
  101. * Comparing to \p bootUartWrite, it will loop and wait there are space
  102. * in uart tx fifo.
  103. *
  104. * \param uart uart instance
  105. * \param data pointer of data to be written
  106. * \param size write size
  107. * \return
  108. * - true on success
  109. * - false on error, invalid parameter
  110. */
  111. bool bootUartWriteAll(bootUart_t *uart, const void *data, size_t size);
  112. /**
  113. * \brief write all data to the uart with hdlc encoding
  114. *
  115. * \param uart uart instance
  116. * \param data pointer of data to be written
  117. * \param size write size
  118. * \return
  119. * - true on success
  120. * - false on error, invalid parameter
  121. */
  122. bool bootUartWriteHdlc(bootUart_t *uart, const void *data, size_t size);
  123. /**
  124. * \brief write all data of multiple buffers to the uart with hdlc encoding
  125. *
  126. * \param uart uart instance
  127. * \param bufs buffers
  128. * \param count buffer count
  129. * \return
  130. * - true on success
  131. * - false on error, invalid parameter
  132. */
  133. bool bootUartWriteMultiHdlc(bootUart_t *uart, const osiBuffer_t *bufs, unsigned count);
  134. #ifdef __cplusplus
  135. }
  136. #endif
  137. #endif