hal_sio.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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_sio.h
  15. * @brief SIO Driver macros and structures.
  16. *
  17. * @addtogroup SIO
  18. * @{
  19. */
  20. #ifndef HAL_SIO_H
  21. #define HAL_SIO_H
  22. #if (HAL_USE_SIO == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Driver constants. */
  25. /*===========================================================================*/
  26. /**
  27. * @name SIO status flags
  28. * @{
  29. */
  30. #define SIO_NO_ERROR 0 /**< @brief No pending conditions. */
  31. #define SIO_PARITY_ERROR 4 /**< @brief Parity error happened. */
  32. #define SIO_FRAMING_ERROR 8 /**< @brief Framing error happened. */
  33. #define SIO_OVERRUN_ERROR 16 /**< @brief Overflow happened. */
  34. #define SIO_NOISE_ERROR 32 /**< @brief Noise on the line. */
  35. #define SIO_BREAK_DETECTED 64 /**< @brief Break detected. */
  36. /** @} */
  37. /*===========================================================================*/
  38. /* Driver pre-compile time settings. */
  39. /*===========================================================================*/
  40. /**
  41. * @name SIO configuration options
  42. * @{
  43. */
  44. /** @} */
  45. /*===========================================================================*/
  46. /* Derived constants and error checks. */
  47. /*===========================================================================*/
  48. /*===========================================================================*/
  49. /* Driver data structures and types. */
  50. /*===========================================================================*/
  51. /**
  52. * @brief Type of structure representing a SIO driver.
  53. */
  54. typedef struct hal_sio_driver SIODriver;
  55. /**
  56. * @brief Type of structure representing a SIO configuration.
  57. */
  58. typedef struct hal_sio_config SIOConfig;
  59. /**
  60. * @brief Driver state machine possible states.
  61. */
  62. typedef enum {
  63. SIO_UNINIT = 0, /**< Not initialized. */
  64. SIO_STOP = 1, /**< Stopped. */
  65. SIO_READY = 2 /**< Ready. */
  66. } siostate_t;
  67. #include "hal_sio_lld.h"
  68. /*===========================================================================*/
  69. /* Driver macros. */
  70. /*===========================================================================*/
  71. /**
  72. * @brief Returns the current set of flags and clears it.
  73. */
  74. #define sioGetFlagsX(siop) sio_lld_get_flags(siop)
  75. /**
  76. * @brief Determines the state of the RX FIFO.
  77. *
  78. * @param[in] siop pointer to the @p SIODriver object
  79. * @return The RX FIFO state.
  80. * @retval false if RX FIFO is not empty
  81. * @retval true if RX FIFO is empty
  82. *
  83. * @xclass
  84. */
  85. #define sioRXIsEmptyX(siop) sio_lld_rx_is_empty(siop)
  86. /**
  87. * @brief Determines the state of the TX FIFO.
  88. *
  89. * @param[in] siop pointer to the @p SIODriver object
  90. * @return The TX FIFO state.
  91. * @retval false if TX FIFO is not full
  92. * @retval true if TX FIFO is full
  93. *
  94. * @xclass
  95. */
  96. #define sioTXIsFullX(siop) sio_lld_tx_is_full(siop)
  97. /**
  98. * @brief Returns one frame from the RX FIFO.
  99. * @note If the FIFO is empty then the returned value is unpredictable.
  100. *
  101. * @param[in] siop pointer to the @p SIODriver object
  102. * @return The frame from RX FIFO.
  103. *
  104. * @xclass
  105. */
  106. #define sioRXGetX(siop) sio_lld_rx_get(siop)
  107. /**
  108. * @brief Pushes one frame into the TX FIFO.
  109. * @note If the FIFO is full then the behavior is unpredictable.
  110. *
  111. * @param[in] siop pointer to the @p SIODriver object
  112. * @param[in] data frame to be written
  113. *
  114. * @xclass
  115. */
  116. #define sioTXPutX(siop, data) sio_lld_tx_put(siop, data)
  117. /**
  118. * @brief Reads data from the RX FIFO.
  119. * @details This function is non-blocking, data is read if present and the
  120. * effective amount is returned.
  121. * @note This function can be called from any context but it is meant to
  122. * be called from the @p rxne_cb callback handler.
  123. *
  124. * @param[in] siop pointer to the @p SIODriver object
  125. * @param[in] buffer buffer for the received data
  126. * @param[in] size maximum number of frames to read
  127. * @return The number of received frames.
  128. *
  129. * @xclass
  130. */
  131. #define sioReadX(siop, buffer, size) sio_lld_read(siop, buffer, size)
  132. /**
  133. * @brief Writes data into the TX FIFO.
  134. * @details This function is non-blocking, data is written if there is space
  135. * in the FIFO and the effective amount is returned.
  136. * @note This function can be called from any context but it is meant to
  137. * be called from the @p txnf_cb callback handler.
  138. *
  139. * @param[in] siop pointer to the @p SIODriver object
  140. * @param[out] buffer buffer containing the data to be transmitted
  141. * @param[in] size maximum number of frames to read
  142. * @return The number of transmitted frames.
  143. *
  144. * @xclass
  145. */
  146. #define sioWriteX(siop, buffer, size) sio_lld_write(siop, buffer, size)
  147. /**
  148. * @brief Control operation on a serial port.
  149. *
  150. * @param[in] siop pointer to the @p SIODriver object
  151. * @param[in] operation control operation code
  152. * @param[in,out] arg operation argument
  153. *
  154. * @return The control operation status.
  155. * @retval MSG_OK in case of success.
  156. * @retval MSG_TIMEOUT in case of operation timeout.
  157. * @retval MSG_RESET in case of operation reset.
  158. *
  159. * @xclass
  160. */
  161. #define sioControlX(siop, operation, arg) sio_lld_control(siop, operation, arg)
  162. /*===========================================================================*/
  163. /* External declarations. */
  164. /*===========================================================================*/
  165. #ifdef __cplusplus
  166. extern "C" {
  167. #endif
  168. void sioInit(void);
  169. void sioObjectInit(SIODriver *siop);
  170. void sioStart(SIODriver *siop, const SIOConfig *config);
  171. void sioStop(SIODriver *siop);
  172. #ifdef __cplusplus
  173. }
  174. #endif
  175. #endif /* HAL_USE_SIO == TRUE */
  176. #endif /* HAL_SIO_H */
  177. /** @} */