hal_mac_lld.c 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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_mac_lld.c
  15. * @brief PLATFORM MAC subsystem low level driver source.
  16. *
  17. * @addtogroup MAC
  18. * @{
  19. */
  20. #include <string.h>
  21. #include "hal.h"
  22. #if (HAL_USE_MAC == TRUE) || defined(__DOXYGEN__)
  23. #include "hal_mii.h"
  24. /*===========================================================================*/
  25. /* Driver local definitions. */
  26. /*===========================================================================*/
  27. /*===========================================================================*/
  28. /* Driver exported variables. */
  29. /*===========================================================================*/
  30. /**
  31. * @brief MAC1 driver identifier.
  32. */
  33. #if (PLATFORM_MAC_USE_MAC1 == TRUE) || defined(__DOXYGEN__)
  34. MACDriver ETHD1;
  35. #endif
  36. /*===========================================================================*/
  37. /* Driver local variables and types. */
  38. /*===========================================================================*/
  39. /*===========================================================================*/
  40. /* Driver local functions. */
  41. /*===========================================================================*/
  42. /*===========================================================================*/
  43. /* Driver interrupt handlers. */
  44. /*===========================================================================*/
  45. /*===========================================================================*/
  46. /* Driver exported functions. */
  47. /*===========================================================================*/
  48. /**
  49. * @brief Low level MAC initialization.
  50. *
  51. * @notapi
  52. */
  53. void mac_lld_init(void) {
  54. #if PLATFORM_MAC_USE_MAC1 == TRUE
  55. /* Driver initialization.*/
  56. macObjectInit(&MACD1);
  57. #endif
  58. }
  59. /**
  60. * @brief Configures and activates the MAC peripheral.
  61. *
  62. * @param[in] macp pointer to the @p MACDriver object
  63. *
  64. * @notapi
  65. */
  66. void mac_lld_start(MACDriver *macp) {
  67. if (macp->state == MAC_STOP) {
  68. /* Enables the peripheral.*/
  69. #if PLATFORM_MAC_USE_MAC1 == TRUE
  70. if (&MACD1 == macp) {
  71. }
  72. #endif
  73. }
  74. /* Configures the peripheral.*/
  75. }
  76. /**
  77. * @brief Deactivates the MAC peripheral.
  78. *
  79. * @param[in] macp pointer to the @p MACDriver object
  80. *
  81. * @notapi
  82. */
  83. void mac_lld_stop(MACDriver *macp) {
  84. if (macp->state != MAC_STOP) {
  85. /* Resets the peripheral.*/
  86. /* Disables the peripheral.*/
  87. #if PLATFORM_MAC_USE_MAC1 == TRUE
  88. if (&MACD1 == macp) {
  89. }
  90. #endif
  91. }
  92. }
  93. /**
  94. * @brief Returns a transmission descriptor.
  95. * @details One of the available transmission descriptors is locked and
  96. * returned.
  97. *
  98. * @param[in] macp pointer to the @p MACDriver object
  99. * @param[out] tdp pointer to a @p MACTransmitDescriptor structure
  100. * @return The operation status.
  101. * @retval MSG_OK the descriptor has been obtained.
  102. * @retval MSG_TIMEOUT descriptor not available.
  103. *
  104. * @notapi
  105. */
  106. msg_t mac_lld_get_transmit_descriptor(MACDriver *macp,
  107. MACTransmitDescriptor *tdp) {
  108. (void)macp;
  109. (void)tdp;
  110. return MSG_OK;
  111. }
  112. /**
  113. * @brief Releases a transmit descriptor and starts the transmission of the
  114. * enqueued data as a single frame.
  115. *
  116. * @param[in] tdp the pointer to the @p MACTransmitDescriptor structure
  117. *
  118. * @notapi
  119. */
  120. void mac_lld_release_transmit_descriptor(MACTransmitDescriptor *tdp) {
  121. (void)tdp;
  122. }
  123. /**
  124. * @brief Returns a receive descriptor.
  125. *
  126. * @param[in] macp pointer to the @p MACDriver object
  127. * @param[out] rdp pointer to a @p MACReceiveDescriptor structure
  128. * @return The operation status.
  129. * @retval MSG_OK the descriptor has been obtained.
  130. * @retval MSG_TIMEOUT descriptor not available.
  131. *
  132. * @notapi
  133. */
  134. msg_t mac_lld_get_receive_descriptor(MACDriver *macp,
  135. MACReceiveDescriptor *rdp) {
  136. (void)macp;
  137. (void)rdp;
  138. return MSG_OK;
  139. }
  140. /**
  141. * @brief Releases a receive descriptor.
  142. * @details The descriptor and its buffer are made available for more incoming
  143. * frames.
  144. *
  145. * @param[in] rdp the pointer to the @p MACReceiveDescriptor structure
  146. *
  147. * @notapi
  148. */
  149. void mac_lld_release_receive_descriptor(MACReceiveDescriptor *rdp) {
  150. (void)rdp;
  151. }
  152. /**
  153. * @brief Updates and returns the link status.
  154. *
  155. * @param[in] macp pointer to the @p MACDriver object
  156. * @return The link status.
  157. * @retval true if the link is active.
  158. * @retval false if the link is down.
  159. *
  160. * @notapi
  161. */
  162. bool mac_lld_poll_link_status(MACDriver *macp) {
  163. (void)macp;
  164. return false;
  165. }
  166. /**
  167. * @brief Writes to a transmit descriptor's stream.
  168. *
  169. * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
  170. * @param[in] buf pointer to the buffer containing the data to be
  171. * written
  172. * @param[in] size number of bytes to be written
  173. * @return The number of bytes written into the descriptor's
  174. * stream, this value can be less than the amount
  175. * specified in the parameter @p size if the maximum
  176. * frame size is reached.
  177. *
  178. * @notapi
  179. */
  180. size_t mac_lld_write_transmit_descriptor(MACTransmitDescriptor *tdp,
  181. uint8_t *buf,
  182. size_t size) {
  183. (void)tdp;
  184. (void)buf;
  185. return size;
  186. }
  187. /**
  188. * @brief Reads from a receive descriptor's stream.
  189. *
  190. * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
  191. * @param[in] buf pointer to the buffer that will receive the read data
  192. * @param[in] size number of bytes to be read
  193. * @return The number of bytes read from the descriptor's
  194. * stream, this value can be less than the amount
  195. * specified in the parameter @p size if there are
  196. * no more bytes to read.
  197. *
  198. * @notapi
  199. */
  200. size_t mac_lld_read_receive_descriptor(MACReceiveDescriptor *rdp,
  201. uint8_t *buf,
  202. size_t size) {
  203. (void)rdp;
  204. (void)buf;
  205. return size;
  206. }
  207. #if (MAC_USE_ZERO_COPY == TRUE) || defined(__DOXYGEN__)
  208. /**
  209. * @brief Returns a pointer to the next transmit buffer in the descriptor
  210. * chain.
  211. * @note The API guarantees that enough buffers can be requested to fill
  212. * a whole frame.
  213. *
  214. * @param[in] tdp pointer to a @p MACTransmitDescriptor structure
  215. * @param[in] size size of the requested buffer. Specify the frame size
  216. * on the first call then scale the value down subtracting
  217. * the amount of data already copied into the previous
  218. * buffers.
  219. * @param[out] sizep pointer to variable receiving the buffer size, it is
  220. * zero when the last buffer has already been returned.
  221. * Note that a returned size lower than the amount
  222. * requested means that more buffers must be requested
  223. * in order to fill the frame data entirely.
  224. * @return Pointer to the returned buffer.
  225. * @retval NULL if the buffer chain has been entirely scanned.
  226. *
  227. * @notapi
  228. */
  229. uint8_t *mac_lld_get_next_transmit_buffer(MACTransmitDescriptor *tdp,
  230. size_t size,
  231. size_t *sizep) {
  232. (void)tdp;
  233. (void)size;
  234. (void)sizep;
  235. return NULL;
  236. }
  237. /**
  238. * @brief Returns a pointer to the next receive buffer in the descriptor
  239. * chain.
  240. * @note The API guarantees that the descriptor chain contains a whole
  241. * frame.
  242. *
  243. * @param[in] rdp pointer to a @p MACReceiveDescriptor structure
  244. * @param[out] sizep pointer to variable receiving the buffer size, it is
  245. * zero when the last buffer has already been returned.
  246. * @return Pointer to the returned buffer.
  247. * @retval NULL if the buffer chain has been entirely scanned.
  248. *
  249. * @notapi
  250. */
  251. const uint8_t *mac_lld_get_next_receive_buffer(MACReceiveDescriptor *rdp,
  252. size_t *sizep) {
  253. (void)rdp;
  254. (void)sizep;
  255. return NULL;
  256. }
  257. #endif /* MAC_USE_ZERO_COPY == TRUE */
  258. #endif /* HAL_USE_MAC == TRUE */
  259. /** @} */