hal_sio_lld.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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_lld.h
  15. * @brief PLATFORM SIO subsystem low level driver header.
  16. *
  17. * @addtogroup SIO
  18. * @{
  19. */
  20. #ifndef HAL_SIO_LLD_H
  21. #define HAL_SIO_LLD_H
  22. #if (HAL_USE_SIO == 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 SIO driver enable switch.
  35. * @details If set to @p TRUE the support for SIO1 is included.
  36. * @note The default is @p FALSE.
  37. */
  38. #if !defined(PLATFORM_SIO_USE_SIO1) || defined(__DOXYGEN__)
  39. #define PLATFORM_SIO_USE_SIO1 FALSE
  40. #endif
  41. /** @} */
  42. /*===========================================================================*/
  43. /* Derived constants and error checks. */
  44. /*===========================================================================*/
  45. /*===========================================================================*/
  46. /* Driver data structures and types. */
  47. /*===========================================================================*/
  48. /**
  49. * @brief SIO driver condition flags type.
  50. */
  51. typedef uint32_t sioflags_t;
  52. /**
  53. * @brief Generic SIO notification callback type.
  54. *
  55. * @param[in] siop pointer to the @p SIODriver object
  56. */
  57. typedef void (*siocb_t)(SIODriver *siop);
  58. /**
  59. * @brief Receive error SIO notification callback type.
  60. *
  61. * @param[in] siop pointer to the @p SIODriver object triggering the
  62. * callback
  63. * @param[in] e receive error mask
  64. */
  65. typedef void (*sioecb_t)(SIODriver *siop, sioflags_t e);
  66. /**
  67. * @brief Driver configuration structure.
  68. * @note Implementations may extend this structure to contain more,
  69. * architecture dependent, fields.
  70. */
  71. struct hal_sio_config {
  72. /**
  73. * @brief Receive buffer filled callback.
  74. * @note Can be @p NULL.
  75. */
  76. siocb_t rxne_cb;
  77. /**
  78. * @brief End of transmission buffer callback.
  79. * @note Can be @p NULL.
  80. */
  81. siocb_t txnf_cb;
  82. /**
  83. * @brief Physical end of transmission callback.
  84. * @note Can be @p NULL.
  85. */
  86. siocb_t txend_cb;
  87. /**
  88. * @brief Receive event callback.
  89. * @note Can be @p NULL.
  90. */
  91. sioecb_t rxevt_cb;
  92. /* End of the mandatory fields.*/
  93. };
  94. /**
  95. * @brief Structure representing a SIO driver.
  96. * @note Implementations may extend this structure to contain more,
  97. * architecture dependent, fields.
  98. */
  99. struct hal_sio_driver {
  100. /**
  101. * @brief Driver state.
  102. */
  103. siostate_t state;
  104. /**
  105. * @brief Current configuration data.
  106. */
  107. const SIOConfig *config;
  108. #if defined(SIO_DRIVER_EXT_FIELDS)
  109. SIO_DRIVER_EXT_FIELDS
  110. #endif
  111. /* End of the mandatory fields.*/
  112. };
  113. /*===========================================================================*/
  114. /* Driver macros. */
  115. /*===========================================================================*/
  116. /**
  117. * @brief Determines the state of the RX FIFO.
  118. *
  119. * @param[in] siop pointer to the @p SIODriver object
  120. * @return The RX FIFO state.
  121. * @retval false if RX FIFO is not empty
  122. * @retval true if RX FIFO is empty
  123. *
  124. * @notapi
  125. */
  126. #define sio_lld_rx_is_empty(siop) true
  127. /**
  128. * @brief Determines the state of the TX FIFO.
  129. *
  130. * @param[in] siop pointer to the @p SIODriver object
  131. * @return The TX FIFO state.
  132. * @retval false if TX FIFO is not full
  133. * @retval true if TX FIFO is full
  134. *
  135. * @notapi
  136. */
  137. #define sio_lld_tx_is_full(siop) true
  138. /**
  139. * @brief Returns one frame from the RX FIFO.
  140. * @note If the FIFO is empty then the returned value is unpredictable.
  141. *
  142. * @param[in] siop pointer to the @p SIODriver object
  143. * @return The frame from RX FIFO.
  144. *
  145. * @notapi
  146. */
  147. #define sio_lld_rx_get(siop)
  148. /**
  149. * @brief Pushes one frame into the TX FIFO.
  150. * @note If the FIFO is full then the behavior is unpredictable.
  151. *
  152. * @param[in] siop pointer to the @p SIODriver object
  153. * @param[in] data frame to be written
  154. *
  155. * @notapi
  156. */
  157. #define sio_lld_tx_put(siop, data)
  158. /*===========================================================================*/
  159. /* External declarations. */
  160. /*===========================================================================*/
  161. #if (PLATFORM_SIO_USE_SIO1 == TRUE) && !defined(__DOXYGEN__)
  162. extern SIODriver SIOD1;
  163. #endif
  164. #ifdef __cplusplus
  165. extern "C" {
  166. #endif
  167. void sio_lld_init(void);
  168. void sio_lld_start(SIODriver *siop);
  169. void sio_lld_stop(SIODriver *siop);
  170. size_t sio_lld_read(SIODriver *siop, void *buffer, size_t size);
  171. size_t sio_lld_write(SIODriver *siop, const void *buffer, size_t size);
  172. msg_t sio_lld_control(SIODriver *siop, unsigned int operation, void *arg);
  173. #ifdef __cplusplus
  174. }
  175. #endif
  176. #endif /* HAL_USE_SIO == TRUE */
  177. #endif /* HAL_SIO_LLD_H */
  178. /** @} */