hal_spi_lld.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  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_spi_lld.c
  15. * @brief PLATFORM SPI subsystem low level driver source.
  16. *
  17. * @addtogroup SPI
  18. * @{
  19. */
  20. #include "hal.h"
  21. #if (HAL_USE_SPI == TRUE) || defined(__DOXYGEN__)
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver exported variables. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief SPI1 driver identifier.
  30. */
  31. #if (PLATFORM_SPI_USE_SPI1 == TRUE) || defined(__DOXYGEN__)
  32. SPIDriver SPID1;
  33. #endif
  34. /*===========================================================================*/
  35. /* Driver local variables and types. */
  36. /*===========================================================================*/
  37. /*===========================================================================*/
  38. /* Driver local functions. */
  39. /*===========================================================================*/
  40. /*===========================================================================*/
  41. /* Driver interrupt handlers. */
  42. /*===========================================================================*/
  43. /*===========================================================================*/
  44. /* Driver exported functions. */
  45. /*===========================================================================*/
  46. /**
  47. * @brief Low level SPI driver initialization.
  48. *
  49. * @notapi
  50. */
  51. void spi_lld_init(void) {
  52. #if PLATFORM_SPI_USE_SPI1 == TRUE
  53. /* Driver initialization.*/
  54. spiObjectInit(&SPID1);
  55. #endif
  56. }
  57. /**
  58. * @brief Configures and activates the SPI peripheral.
  59. *
  60. * @param[in] spip pointer to the @p SPIDriver object
  61. *
  62. * @notapi
  63. */
  64. void spi_lld_start(SPIDriver *spip) {
  65. if (spip->state == SPI_STOP) {
  66. /* Enables the peripheral.*/
  67. #if PLATFORM_SPI_USE_SPI1 == TRUE
  68. if (&SPID1 == spip) {
  69. }
  70. #endif
  71. }
  72. /* Configures the peripheral.*/
  73. }
  74. /**
  75. * @brief Deactivates the SPI peripheral.
  76. *
  77. * @param[in] spip pointer to the @p SPIDriver object
  78. *
  79. * @notapi
  80. */
  81. void spi_lld_stop(SPIDriver *spip) {
  82. if (spip->state == SPI_READY) {
  83. /* Disables the peripheral.*/
  84. #if PLATFORM_SPI_USE_SPI1 == TRUE
  85. if (&SPID1 == spip) {
  86. }
  87. #endif
  88. }
  89. }
  90. /**
  91. * @brief Asserts the slave select signal and prepares for transfers.
  92. *
  93. * @param[in] spip pointer to the @p SPIDriver object
  94. *
  95. * @notapi
  96. */
  97. void spi_lld_select(SPIDriver *spip) {
  98. (void)spip;
  99. }
  100. /**
  101. * @brief Deasserts the slave select signal.
  102. * @details The previously selected peripheral is unselected.
  103. *
  104. * @param[in] spip pointer to the @p SPIDriver object
  105. *
  106. * @notapi
  107. */
  108. void spi_lld_unselect(SPIDriver *spip) {
  109. (void)spip;
  110. }
  111. /**
  112. * @brief Ignores data on the SPI bus.
  113. * @details This asynchronous function starts the transmission of a series of
  114. * idle words on the SPI bus and ignores the received data.
  115. * @post At the end of the operation the configured callback is invoked.
  116. *
  117. * @param[in] spip pointer to the @p SPIDriver object
  118. * @param[in] n number of words to be ignored
  119. *
  120. * @notapi
  121. */
  122. void spi_lld_ignore(SPIDriver *spip, size_t n) {
  123. (void)spip;
  124. (void)n;
  125. }
  126. /**
  127. * @brief Exchanges data on the SPI bus.
  128. * @details This asynchronous function starts a simultaneous transmit/receive
  129. * operation.
  130. * @post At the end of the operation the configured callback is invoked.
  131. * @note The buffers are organized as uint8_t arrays for data sizes below or
  132. * equal to 8 bits else it is organized as uint16_t arrays.
  133. *
  134. * @param[in] spip pointer to the @p SPIDriver object
  135. * @param[in] n number of words to be exchanged
  136. * @param[in] txbuf the pointer to the transmit buffer
  137. * @param[out] rxbuf the pointer to the receive buffer
  138. *
  139. * @notapi
  140. */
  141. void spi_lld_exchange(SPIDriver *spip, size_t n,
  142. const void *txbuf, void *rxbuf) {
  143. (void)spip;
  144. (void)n;
  145. (void)txbuf;
  146. (void)rxbuf;
  147. }
  148. /**
  149. * @brief Sends data over the SPI bus.
  150. * @details This asynchronous function starts a transmit operation.
  151. * @post At the end of the operation the configured callback is invoked.
  152. * @note The buffers are organized as uint8_t arrays for data sizes below or
  153. * equal to 8 bits else it is organized as uint16_t arrays.
  154. *
  155. * @param[in] spip pointer to the @p SPIDriver object
  156. * @param[in] n number of words to send
  157. * @param[in] txbuf the pointer to the transmit buffer
  158. *
  159. * @notapi
  160. */
  161. void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) {
  162. (void)spip;
  163. (void)n;
  164. (void)txbuf;
  165. }
  166. /**
  167. * @brief Receives data from the SPI bus.
  168. * @details This asynchronous function starts a receive operation.
  169. * @post At the end of the operation the configured callback is invoked.
  170. * @note The buffers are organized as uint8_t arrays for data sizes below or
  171. * equal to 8 bits else it is organized as uint16_t arrays.
  172. *
  173. * @param[in] spip pointer to the @p SPIDriver object
  174. * @param[in] n number of words to receive
  175. * @param[out] rxbuf the pointer to the receive buffer
  176. *
  177. * @notapi
  178. */
  179. void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
  180. (void)spip;
  181. (void)n;
  182. (void)rxbuf;
  183. }
  184. #if (SPI_SUPPORTS_CIRCULAR == TRUE) || defined(__DOXYGEN__)
  185. /**
  186. * @brief Aborts the ongoing SPI operation, if any.
  187. *
  188. * @param[in] spip pointer to the @p SPIDriver object
  189. *
  190. * @notapi
  191. */
  192. void spi_lld_abort(SPIDriver *spip) {
  193. (void)spip;
  194. }
  195. #endif /* SPI_SUPPORTS_CIRCULAR == TRUE */
  196. /**
  197. * @brief Exchanges one frame using a polled wait.
  198. * @details This synchronous function exchanges one frame using a polled
  199. * synchronization method. This function is useful when exchanging
  200. * small amount of data on high speed channels, usually in this
  201. * situation is much more efficient just wait for completion using
  202. * polling than suspending the thread waiting for an interrupt.
  203. *
  204. * @param[in] spip pointer to the @p SPIDriver object
  205. * @param[in] frame the data frame to send over the SPI bus
  206. * @return The received data frame from the SPI bus.
  207. *
  208. * @notapi
  209. */
  210. uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
  211. (void)spip;
  212. (void)frame;
  213. return 0;
  214. }
  215. #endif /* HAL_USE_SPI == TRUE */
  216. /** @} */