hal_can_lld.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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_can_lld.c
  15. * @brief PLATFORM CAN subsystem low level driver source.
  16. *
  17. * @addtogroup CAN
  18. * @{
  19. */
  20. #include "hal.h"
  21. #if (HAL_USE_CAN == TRUE) || defined(__DOXYGEN__)
  22. /*===========================================================================*/
  23. /* Driver local definitions. */
  24. /*===========================================================================*/
  25. /*===========================================================================*/
  26. /* Driver exported variables. */
  27. /*===========================================================================*/
  28. /**
  29. * @brief CAN1 driver identifier.
  30. */
  31. #if (PLATFORM_CAN_USE_CAN1 == TRUE) || defined(__DOXYGEN__)
  32. CANDriver CAND1;
  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 CAN driver initialization.
  48. *
  49. * @notapi
  50. */
  51. void can_lld_init(void) {
  52. #if PLATFORM_CAN_USE_CAN1 == TRUE
  53. /* Driver initialization.*/
  54. canObjectInit(&CAND1);
  55. #endif
  56. }
  57. /**
  58. * @brief Configures and activates the CAN peripheral.
  59. *
  60. * @param[in] canp pointer to the @p CANDriver object
  61. *
  62. * @notapi
  63. */
  64. void can_lld_start(CANDriver *canp) {
  65. if (canp->state == CAN_STOP) {
  66. /* Enables the peripheral.*/
  67. #if PLATFORM_CAN_USE_CAN1 == TRUE
  68. if (&CAND1 == canp) {
  69. }
  70. #endif
  71. }
  72. /* Configures the peripheral.*/
  73. }
  74. /**
  75. * @brief Deactivates the CAN peripheral.
  76. *
  77. * @param[in] canp pointer to the @p CANDriver object
  78. *
  79. * @notapi
  80. */
  81. void can_lld_stop(CANDriver *canp) {
  82. if (canp->state == CAN_READY) {
  83. /* Resets the peripheral.*/
  84. /* Disables the peripheral.*/
  85. #if PLATFORM_CAN_USE_CAN1 == TRUE
  86. if (&CAND1 == canp) {
  87. }
  88. #endif
  89. }
  90. }
  91. /**
  92. * @brief Determines whether a frame can be transmitted.
  93. *
  94. * @param[in] canp pointer to the @p CANDriver object
  95. * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
  96. *
  97. * @return The queue space availability.
  98. * @retval false no space in the transmit queue.
  99. * @retval true transmit slot available.
  100. *
  101. * @notapi
  102. */
  103. bool can_lld_is_tx_empty(CANDriver *canp, canmbx_t mailbox) {
  104. (void)canp;
  105. switch (mailbox) {
  106. case CAN_ANY_MAILBOX:
  107. return false;
  108. case 1:
  109. return false;
  110. case 2:
  111. return false;
  112. case 3:
  113. return false;
  114. default:
  115. return false;
  116. }
  117. }
  118. /**
  119. * @brief Inserts a frame into the transmit queue.
  120. *
  121. * @param[in] canp pointer to the @p CANDriver object
  122. * @param[in] ctfp pointer to the CAN frame to be transmitted
  123. * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
  124. *
  125. * @notapi
  126. */
  127. void can_lld_transmit(CANDriver *canp,
  128. canmbx_t mailbox,
  129. const CANTxFrame *ctfp) {
  130. (void)canp;
  131. (void)mailbox;
  132. (void)ctfp;
  133. }
  134. /**
  135. * @brief Determines whether a frame has been received.
  136. *
  137. * @param[in] canp pointer to the @p CANDriver object
  138. * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
  139. *
  140. * @return The queue space availability.
  141. * @retval false no space in the transmit queue.
  142. * @retval true transmit slot available.
  143. *
  144. * @notapi
  145. */
  146. bool can_lld_is_rx_nonempty(CANDriver *canp, canmbx_t mailbox) {
  147. (void)canp;
  148. (void)mailbox;
  149. switch (mailbox) {
  150. case CAN_ANY_MAILBOX:
  151. return false;
  152. case 1:
  153. return false;
  154. case 2:
  155. return false;
  156. default:
  157. return false;
  158. }
  159. }
  160. /**
  161. * @brief Receives a frame from the input queue.
  162. *
  163. * @param[in] canp pointer to the @p CANDriver object
  164. * @param[in] mailbox mailbox number, @p CAN_ANY_MAILBOX for any mailbox
  165. * @param[out] crfp pointer to the buffer where the CAN frame is copied
  166. *
  167. * @notapi
  168. */
  169. void can_lld_receive(CANDriver *canp,
  170. canmbx_t mailbox,
  171. CANRxFrame *crfp) {
  172. (void)canp;
  173. (void)mailbox;
  174. (void)crfp;
  175. }
  176. #if (CAN_USE_SLEEP_MODE == TRUE) || defined(__DOXYGEN__)
  177. /**
  178. * @brief Enters the sleep mode.
  179. *
  180. * @param[in] canp pointer to the @p CANDriver object
  181. *
  182. * @notapi
  183. */
  184. void can_lld_sleep(CANDriver *canp) {
  185. (void)canp;
  186. }
  187. /**
  188. * @brief Enforces leaving the sleep mode.
  189. *
  190. * @param[in] canp pointer to the @p CANDriver object
  191. *
  192. * @notapi
  193. */
  194. void can_lld_wakeup(CANDriver *canp) {
  195. (void)canp;
  196. }
  197. #endif /* CAN_USE_SLEEP_MOD == TRUEE */
  198. #endif /* HAL_USE_CAN == TRUE */
  199. /** @} */