hal_mac_async.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /**
  2. * \file
  3. *
  4. * \brief MAC functionality declaration.
  5. *
  6. * Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Subject to your compliance with these terms, you may use Microchip
  13. * software and any derivatives exclusively with Microchip products.
  14. * It is your responsibility to comply with third party license terms applicable
  15. * to your use of third party software (including open source software) that
  16. * may accompany Microchip software.
  17. *
  18. * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES,
  19. * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE,
  20. * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY,
  21. * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE
  22. * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL
  23. * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE
  24. * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE
  25. * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT
  26. * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY
  27. * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
  28. * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
  29. *
  30. * \asf_license_stop
  31. *
  32. */
  33. #ifndef HAL_MAC_ASYNC_H_INCLUDED
  34. #define HAL_MAC_ASYNC_H_INCLUDED
  35. #include <hpl_mac_async.h>
  36. #ifdef __cplusplus
  37. extern "C" {
  38. #endif
  39. /**
  40. * \addtogroup doc_driver_hal_mac_async
  41. *
  42. *@{
  43. */
  44. /**
  45. * \brief MAC descriptor
  46. *
  47. * The MAC descriptor forward declaration.
  48. */
  49. struct mac_async_descriptor;
  50. /**
  51. * \brief MAC callback type
  52. *
  53. * \param[in] descr A MAC descriptor
  54. */
  55. typedef void (*mac_async_cb_t)(struct mac_async_descriptor *const descr);
  56. /**
  57. * \brief MAC callbacks
  58. */
  59. struct mac_async_callbacks {
  60. mac_async_cb_t receive;
  61. mac_async_cb_t transmit;
  62. };
  63. /**
  64. * \brief MAC descriptor
  65. */
  66. struct mac_async_descriptor {
  67. struct _mac_async_device dev; /*!< MAC HPL device descriptor */
  68. struct mac_async_callbacks cb; /*!< MAC Callback handlers */
  69. };
  70. /**
  71. * Callback for MAC interrupt
  72. */
  73. typedef void (*mac_cb)(struct mac_async_descriptor *const descr);
  74. /**
  75. * \brief Initialize the MAC driver
  76. *
  77. * \param[in] descr A MAC descriptor to init.
  78. * \param[in] hw Hardware instance pointer.
  79. *
  80. * \return Operation status.
  81. * \retval ERR_NONE Success.
  82. */
  83. int32_t mac_async_init(struct mac_async_descriptor *const descr, void *const dev);
  84. /**
  85. * \brief Deinitialize the MAC driver
  86. *
  87. * \param[in] descr A MAC descriptor to deinitialize.
  88. *
  89. * \return Operation status.
  90. * \retval ERR_NONE Success.
  91. */
  92. int32_t mac_async_deinit(struct mac_async_descriptor *const descr);
  93. /** \brief Enable the MAC
  94. *
  95. * \param[in] descr Pointer to the HAL MAC descriptor.
  96. *
  97. * \return Operation status.
  98. * \retval ERR_NONE Success.
  99. */
  100. int32_t mac_async_enable(struct mac_async_descriptor *const descr);
  101. /**
  102. * \brief Disable the MAC
  103. *
  104. * \param[in] descr Pointer to the HAL MAC descriptor
  105. *
  106. * \return Operation status.
  107. * \retval ERR_NONE Success.
  108. */
  109. int32_t mac_async_disable(struct mac_async_descriptor *const descr);
  110. /**
  111. * \brief Write raw data to MAC
  112. *
  113. * Write the raw data to the MAC that will be transmitted
  114. *
  115. * \param[in] descr Pointer to the HAL MAC descriptor.
  116. * \param[in] buf Pointer to the data buffer.
  117. * \param[in] len Length of the data buffer.
  118. *
  119. * \return Operation status.
  120. * \retval ERR_NONE Success.
  121. */
  122. int32_t mac_async_write(struct mac_async_descriptor *const descr, uint8_t *buf, uint32_t len);
  123. /**
  124. * \brief Read raw data from MAC
  125. *
  126. * Read received raw data from MAC
  127. *
  128. * \param[in] descr Pointer to the HAL MAC descriptor.
  129. * \param[in] buffer Pointer to the data buffer. If the pointer is NULL, then the
  130. * frame will be discarded.
  131. * \param[in] length The max. length of the data buffer to be read. If the length is zero,
  132. * then the frame will be discard
  133. *
  134. * \return Number of bytes that received
  135. */
  136. uint32_t mac_async_read(struct mac_async_descriptor *const descr, uint8_t *buf, uint32_t len);
  137. /**
  138. * \brief Get next valid package length
  139. *
  140. * Get next valid package length from the MAC. The application can use this function
  141. * to fetch the length of the next package, malloc a buffer with this
  142. * length, and then invoke mac_async_read to read out the package data.
  143. *
  144. * \param[in] descr Pointer to the HAL MAC descriptor.
  145. *
  146. * \return The number of bytes in the next package that can be read.
  147. */
  148. uint32_t mac_async_read_len(struct mac_async_descriptor *const descr);
  149. /**
  150. * \brief Enable the MAC IRQ
  151. *
  152. * \param[in] descr Pointer to the HAL MAC descriptor
  153. */
  154. void mac_async_enable_irq(struct mac_async_descriptor *const descr);
  155. /**
  156. * \brief Disable the MAC IRQ
  157. *
  158. * \param[in] descr Pointer to the HAL MAC descriptor
  159. */
  160. void mac_async_disable_irq(struct mac_async_descriptor *const descr);
  161. /**
  162. * \brief Register the MAC callback function
  163. *
  164. * \param[in] descr Pointer to the HAL MAC descriptor.
  165. * \param[in] type Callback function type.
  166. * \param[in] func A callback function. Passing NULL will de-register any
  167. * registered callback.
  168. *
  169. * \return Operation status.
  170. * \retval ERR_NONE Success.
  171. */
  172. int32_t mac_async_register_callback(struct mac_async_descriptor *const descr, const enum mac_async_cb_type type,
  173. const FUNC_PTR func);
  174. /**
  175. * \brief Set MAC filter
  176. *
  177. * Set MAC filter. Ethernet frames matching the filter, will be received.
  178. *
  179. * \param[in] descr Pointer to the HAL MAC descriptor.
  180. * \param[in] index MAC filter index. Start from 0. The maximum value depends on
  181. * the hardware specifications.
  182. * \param[in] filter Pointer to the filter descriptor.
  183. *
  184. * \return Operation status.
  185. * \retval ERR_NONE Success.
  186. */
  187. int32_t mac_async_set_filter(struct mac_async_descriptor *const descr, uint8_t index, struct mac_async_filter *filter);
  188. /**
  189. * \brief Set MAC filter (expanded).
  190. *
  191. * Set MAC filter. The Ethernet frames matching the filter, will be received.
  192. *
  193. * \param[in] descr Pointer to the HAL MAC descriptor
  194. * \param[in] mac MAC address
  195. *
  196. * \return Operation status.
  197. * \retval ERR_NONE Success.
  198. */
  199. int32_t mac_async_set_filter_ex(struct mac_async_descriptor *const descr, uint8_t mac[6]);
  200. /**
  201. * \brief Write PHY register
  202. *
  203. * \param[in] descr Pointer to the HAL MAC descriptor.
  204. * \param[in] addr PHY address.
  205. * \param[in] reg Register address.
  206. * \param[in] val Register value.
  207. *
  208. * \return Operation status.
  209. * \retval ERR_NONE Success.
  210. */
  211. int32_t mac_async_write_phy_reg(struct mac_async_descriptor *const descr, uint16_t addr, uint16_t reg, uint16_t val);
  212. /**
  213. * \brief Read PHY register
  214. *
  215. * \param[in] descr Pointer to the HAL MAC descriptor.
  216. * \param[in] addr PHY address.
  217. * \param[in] reg Register address.
  218. * \param[in] val Register value.
  219. *
  220. * \return Operation status.
  221. * \retval ERR_NONE Success.
  222. */
  223. int32_t mac_async_read_phy_reg(struct mac_async_descriptor *const descr, uint16_t addr, uint16_t reg, uint16_t *val);
  224. /**
  225. * \brief Get the MAC driver version
  226. */
  227. uint32_t mac_async_get_version(void);
  228. /**@}*/
  229. #ifdef __cplusplus
  230. }
  231. #endif
  232. #endif /* HAL_MAC_ASYNC_H_INCLUDED */