hal_uart_lld.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_uart_lld.h
  15. * @brief PLATFORM UART subsystem low level driver header.
  16. *
  17. * @addtogroup UART
  18. * @{
  19. */
  20. #ifndef HAL_UART_LLD_H
  21. #define HAL_UART_LLD_H
  22. #if (HAL_USE_UART == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /*===========================================================================*/
  27. /* Driver pre-compile time settings. */
  28. /*===========================================================================*/
  29. /**
  30. * @name PLATFORM configuration options
  31. * @{
  32. */
  33. /**
  34. * @brief UART driver enable switch.
  35. * @details If set to @p TRUE the support for UART1 is included.
  36. * @note The default is @p FALSE.
  37. */
  38. #if !defined(PLATFORM_UART_USE_UART1) || defined(__DOXYGEN__)
  39. #define PLATFORM_UART_USE_UART1 FALSE
  40. #endif
  41. /** @} */
  42. /*===========================================================================*/
  43. /* Derived constants and error checks. */
  44. /*===========================================================================*/
  45. /*===========================================================================*/
  46. /* Driver data structures and types. */
  47. /*===========================================================================*/
  48. /**
  49. * @brief UART driver condition flags type.
  50. */
  51. typedef uint32_t uartflags_t;
  52. /**
  53. * @brief Type of structure representing an UART driver.
  54. */
  55. typedef struct UARTDriver UARTDriver;
  56. /**
  57. * @brief Generic UART notification callback type.
  58. *
  59. * @param[in] uartp pointer to the @p UARTDriver object
  60. */
  61. typedef void (*uartcb_t)(UARTDriver *uartp);
  62. /**
  63. * @brief Character received UART notification callback type.
  64. *
  65. * @param[in] uartp pointer to the @p UARTDriver object triggering the
  66. * callback
  67. * @param[in] c received character
  68. */
  69. typedef void (*uartccb_t)(UARTDriver *uartp, uint16_t c);
  70. /**
  71. * @brief Receive error UART notification callback type.
  72. *
  73. * @param[in] uartp pointer to the @p UARTDriver object triggering the
  74. * callback
  75. * @param[in] e receive error mask
  76. */
  77. typedef void (*uartecb_t)(UARTDriver *uartp, uartflags_t e);
  78. /**
  79. * @brief Driver configuration structure.
  80. * @note Implementations may extend this structure to contain more,
  81. * architecture dependent, fields.
  82. */
  83. typedef struct {
  84. /**
  85. * @brief End of transmission buffer callback.
  86. */
  87. uartcb_t txend1_cb;
  88. /**
  89. * @brief Physical end of transmission callback.
  90. */
  91. uartcb_t txend2_cb;
  92. /**
  93. * @brief Receive buffer filled callback.
  94. */
  95. uartcb_t rxend_cb;
  96. /**
  97. * @brief Character received while out if the @p UART_RECEIVE state.
  98. */
  99. uartccb_t rxchar_cb;
  100. /**
  101. * @brief Receive error callback.
  102. */
  103. uartecb_t rxerr_cb;
  104. /* End of the mandatory fields.*/
  105. } UARTConfig;
  106. /**
  107. * @brief Structure representing an UART driver.
  108. * @note Implementations may extend this structure to contain more,
  109. * architecture dependent, fields.
  110. */
  111. struct UARTDriver {
  112. /**
  113. * @brief Driver state.
  114. */
  115. uartstate_t state;
  116. /**
  117. * @brief Transmitter state.
  118. */
  119. uarttxstate_t txstate;
  120. /**
  121. * @brief Receiver state.
  122. */
  123. uartrxstate_t rxstate;
  124. /**
  125. * @brief Current configuration data.
  126. */
  127. const UARTConfig *config;
  128. #if (UART_USE_WAIT == TRUE) || defined(__DOXYGEN__)
  129. /**
  130. * @brief Synchronization flag for transmit operations.
  131. */
  132. bool early;
  133. /**
  134. * @brief Waiting thread on RX.
  135. */
  136. thread_reference_t threadrx;
  137. /**
  138. * @brief Waiting thread on TX.
  139. */
  140. thread_reference_t threadtx;
  141. #endif /* UART_USE_WAIT */
  142. #if (UART_USE_MUTUAL_EXCLUSION == TRUE) || defined(__DOXYGEN__)
  143. /**
  144. * @brief Mutex protecting the peripheral.
  145. */
  146. mutex_t mutex;
  147. #endif /* UART_USE_MUTUAL_EXCLUSION */
  148. #if defined(UART_DRIVER_EXT_FIELDS)
  149. UART_DRIVER_EXT_FIELDS
  150. #endif
  151. /* End of the mandatory fields.*/
  152. };
  153. /*===========================================================================*/
  154. /* Driver macros. */
  155. /*===========================================================================*/
  156. /*===========================================================================*/
  157. /* External declarations. */
  158. /*===========================================================================*/
  159. #if (PLATFORM_UART_USE_UART1 == TRUE) && !defined(__DOXYGEN__)
  160. extern UARTDriver UARTD1;
  161. #endif
  162. #ifdef __cplusplus
  163. extern "C" {
  164. #endif
  165. void uart_lld_init(void);
  166. void uart_lld_start(UARTDriver *uartp);
  167. void uart_lld_stop(UARTDriver *uartp);
  168. void uart_lld_start_send(UARTDriver *uartp, size_t n, const void *txbuf);
  169. size_t uart_lld_stop_send(UARTDriver *uartp);
  170. void uart_lld_start_receive(UARTDriver *uartp, size_t n, void *rxbuf);
  171. size_t uart_lld_stop_receive(UARTDriver *uartp);
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif /* HAL_USE_UART == TRUE */
  176. #endif /* HAL_UART_LLD_H */
  177. /** @} */