hpm_enet_drv.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. /*
  2. * Copyright (c) 2021 hpmicro
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. *
  6. */
  7. #ifndef HPM_ENET_DRV_H
  8. #define HPM_ENET_DRV_H
  9. /*---------------------------------------------------------------------*
  10. * Includes
  11. *---------------------------------------------------------------------*/
  12. #include "hpm_common.h"
  13. #include "hpm_enet_regs.h"
  14. #include "hpm_soc_feature.h"
  15. #include "hpm_enet_soc_drv.h"
  16. /**
  17. * @brief Enet driver APIs
  18. * @defgroup enet_interface Enet driver APIs
  19. * @ingroup communication_interfaces
  20. * @{
  21. */
  22. /*---------------------------------------------------------------------*
  23. * Macro Constant Declarations
  24. *---------------------------------------------------------------------*/
  25. #define ENET_HEADER (14U) /**< 6-byte Dest addr, 6-byte Src addr, 2-byte type */
  26. #define ENET_EXTRA (2U) /**< Extra bytes in some cases */
  27. #define ENET_VLAN_TAG (4U) /**< optional 802.1q VLAN Tag */
  28. #define ENET_CRC (4U) /**< Ethernet CRC */
  29. #define ENET_MIN_PAYLOAD (46U) /**< Minimum Ethernet payload size */
  30. #define ENET_MAX_PAYLOAD (1500U) /**< Maximum Ethernet payload size */
  31. #define ENET_MAX_FRAME_SIZE (1524U) /**< ENET_HEADER + ENET_EXTRA + VLAN_TAG + MAX_ENET_PAYLOAD + ENET_CRC */
  32. #define ENET_JUMBO_FRAME_PAYLOAD (9000U) /**< Jumbo frame payload size */
  33. #define ENET_ERROR (0) /**< ENET error */
  34. #define ENET_SUCCESS (1) /**< ENET success */
  35. #define ENET_ADJ_FREQ_BASE_ADDEND (0x7fffffffUL) /**< PTP base adjustment addend */
  36. #define ENET_ONE_SEC_IN_NANOSEC (1000000000UL) /**< one second in nanoseconds */
  37. /*---------------------------------------------------------------------*
  38. * Typedef Enum Declarations
  39. *---------------------------------------------------------------------*/
  40. /** @brief Programmable burst length selections */
  41. typedef enum {
  42. enet_pbl_1 = 1,
  43. enet_pbl_2 = 2,
  44. enet_pbl_4 = 4,
  45. enet_pbl_8 = 8,
  46. enet_pbl_16 = 16,
  47. enet_pbl_32 = 32
  48. } enet_pbl_t;
  49. /** @brief Checksum insertion control selections */
  50. typedef enum {
  51. enet_cic_bypass = 0,
  52. enet_cic_insert_ipv4_header,
  53. enet_cic_insert_tcp_udp_icmp,
  54. enet_cic_insert_tcp_upd_icmp,
  55. } enet_insert_t;
  56. /** @brief PHY opeartion selections */
  57. typedef enum {
  58. enet_phy_op_read = 0,
  59. enet_phy_op_write
  60. } enet_phy_op_t;
  61. /** @brief PHY status */
  62. typedef enum {
  63. enet_phy_idle = 0,
  64. enet_phy_busy
  65. } enet_phy_status_t;
  66. /** @brief CSR clock range and MDC clock selections */
  67. /** @note The suggested range of CSR clock is approximately
  68. * between the frequency range 1.0MHz-2.5MHz.
  69. * You can achieve higher frequency of the MDC clock than the frequency limit of 2.5MHz(specified in the IEEE Std 802.3)
  70. * and program a clock divider of lower value. Program the value which is no less than enet_csr_60m_to_100m_mdc_csr_div_4
  71. * only if the interfacing chips support faster MDC clocks.
  72. */
  73. typedef enum {
  74. enet_csr_60m_to_100m_mdc_csr_div_42 = 0, /**< CSR clock range: 60-100MHz <==> MDC clock: CSR clock / 42 */
  75. enet_csr_100m_to_150m_mdc_csr_div_62, /**< CSR clock range: 100-150MHz <==> MDC clock: CSR clock / 62 */
  76. enet_csr_20m_to_35m_mdc_csr_div_16, /**< CSR clock range: 20-35MHz <==> MDC clock: CSR clock / 16 */
  77. enet_csr_35m_to_60m_mdc_csr_div_26, /**< CSR clock range: 35-60MHz <==> MDC clock: CSR clock / 26 */
  78. enet_csr_150m_to_250m_mdc_csr_div_102, /**< CSR clock range: 150-250MHz <==> MDC clock: CSR clock / 102 */
  79. enet_csr_250m_to_300m_mdc_csr_div_124, /**< CSR clock range: 250-300MHz <==> MDC clock: CSR clock / 124 */
  80. enet_csr_60m_to_100m_mdc_csr_div_4 = 8, /**< CSR clock / 4 */
  81. enet_csr_60m_to_100m_mdc_csr_div_6, /**< CSR clock / 6 */
  82. enet_csr_60m_to_100m_mdc_csr_div_8, /**< CSR clock / 8 */
  83. enet_csr_60m_to_100m_mdc_csr_div_10, /**< CSR clock / 10 */
  84. enet_csr_60m_to_100m_mdc_csr_div_12, /**< CSR clock / 12 */
  85. enet_csr_60m_to_100m_mdc_csr_div_14, /**< CSR clock / 14 */
  86. enet_csr_60m_to_100m_mdc_csr_div_16, /**< CSR clock / 16 */
  87. enet_csr_60m_to_100m_mdc_csr_div_18 /**< CSR clock / 18 */
  88. } enet_csr_clk_range_t;
  89. /** @brief enet interface selections */
  90. typedef enum {
  91. enet_inf_rmii = 4,
  92. enet_inf_rgmii = 1
  93. } enet_inf_type_t;
  94. /** @brief enet timestamp update methods */
  95. typedef enum {
  96. enet_ptp_time_coarse_update = 0,
  97. enet_ptp_time_fine_update
  98. } enet_ptp_time_update_method_t;
  99. /** @brief PTP versions */
  100. typedef enum {
  101. enet_ptp_v1 = 0,
  102. enet_ptp_v2
  103. } enet_ptp_version_t;
  104. /** @brief PTP frame types */
  105. typedef enum {
  106. enet_ptp_frame_ipv4 = 0,
  107. enet_ptp_frame_ipv6,
  108. enet_ptp_frame_ethernet
  109. } enet_ptp_frame_type_t;
  110. /** @brief PTP message type for snapshots */
  111. typedef enum {
  112. enet_ts_ss_ptp_msg_0 = 0, /* SYNC, Follow_Up, Delay_Req, Delay_Resp */
  113. enet_ts_ss_ptp_msg_1 = 1, /* SYNC */
  114. enet_ts_ss_ptp_msg_2 = 3, /* Delay_Req */
  115. enet_ts_ss_ptp_msg_3 = 4, /* SYNC, Follow_Up, Delay_Req, Delay_Resp, Pdelay_Req, Pdelay_Resp, Pdelay_Resp_Follow_Up */
  116. enet_ts_ss_ptp_msg_4 = 5, /* SYNC, Pdelay_Req, Pdelay_Resp */
  117. enet_ts_ss_ptp_msg_5 = 7, /* Delay_Req, Pdelay_Req, Pdelay_Resp */
  118. enet_ts_ss_ptp_msg_6 = 8, /* SYNC, Delay_Req */
  119. enet_ts_ss_ptp_msg_7 = 12 /* Pdelay_Req, Pdelay_Resp */
  120. } enet_ts_ss_ptp_msg_t;
  121. typedef enum {
  122. enet_ptp_count_res_high = 0, /* ptp sub-second count resolution at 0.465 ns */
  123. enet_ptp_count_res_low /* ptp su-second count resolution at 1 ns */
  124. } enet_ptp_count_res_t;
  125. /*---------------------------------------------------------------------*
  126. * Typedef Struct Declarations
  127. *---------------------------------------------------------------------*/
  128. /** @brief enet buffer config struct */
  129. typedef struct {
  130. uint32_t buffer;
  131. uint32_t count;
  132. uint16_t size;
  133. } enet_buff_config_t;
  134. /** @brief enet mac config struct */
  135. typedef struct {
  136. uint32_t mac_addr_high[ENET_SOC_ADDR_MAX_COUNT];
  137. uint32_t mac_addr_low[ENET_SOC_ADDR_MAX_COUNT];
  138. uint8_t valid_max_count;
  139. } enet_mac_config_t;
  140. /** @brief transmission descriptor struct */
  141. typedef struct {
  142. union {
  143. uint32_t tdes0;
  144. struct {
  145. uint32_t db: 1; /**< * Deferred Bit*/
  146. uint32_t uf: 1; /**< * Underflow Error */
  147. uint32_t ed: 1; /**< * Excessive Deferral */
  148. uint32_t cc: 4; /**< * Collision Count */
  149. uint32_t vf: 1; /**< * VLAN Frame */
  150. uint32_t ec: 1; /**< * Excessive Collision */
  151. uint32_t lc: 1; /**< * Late Collision */
  152. uint32_t nc: 1; /**< * No Carrier */
  153. uint32_t loc: 1; /**< * Loss of Carrier */
  154. uint32_t ipe: 1; /**< * IP Payload Error */
  155. uint32_t ff: 1; /**< * Frame Flushed */
  156. uint32_t jt: 1; /**< * Jabber Timeout */
  157. uint32_t es: 1; /**< * Error Summary */
  158. uint32_t ihe: 1; /**< * IP Header Error */
  159. uint32_t ttss: 1; /**< * Transmit Timestamp Status */
  160. uint32_t vlic: 2; /**< * VLAN Insertion Control */
  161. uint32_t tch: 1; /**< * Second Address Chained */
  162. uint32_t ter: 1; /**< * Transmit End of Ring */
  163. uint32_t cic: 2; /**< * Checksum Insertion Control */
  164. uint32_t crcr: 1; /**< * CRC Replacement Control */
  165. uint32_t ttse: 1; /**< * Transmit Timestamp Enable */
  166. uint32_t dp: 1; /**< * Disable Pad */
  167. uint32_t dc: 1; /**< * Disable CRC */
  168. uint32_t fs: 1; /**< * First Segment */
  169. uint32_t ls: 1; /**< * Last Segment */
  170. uint32_t ic: 1; /**< * Interrupt on Completion */
  171. uint32_t own: 1; /**< * Own Bit */
  172. } tdes0_bm;
  173. };
  174. union {
  175. uint32_t tdes1;
  176. struct {
  177. uint32_t tbs1 : 13; /**< Transmit Buffer 1 Size */
  178. uint32_t reserved: 3; /**< Reserved */
  179. uint32_t tbs2 : 13; /**< Transmit Buffer 2 Size */
  180. uint32_t saic : 3; /**< SA Inertion Control */
  181. } tdes1_bm;
  182. };
  183. union {
  184. uint32_t tdes2;
  185. struct {
  186. uint32_t buffer1; /**< Buffer 1 Address */
  187. } tdes2_bm;
  188. };
  189. union {
  190. uint32_t tdes3;
  191. union {
  192. uint32_t buffer2; /**< Buffer 2 Address */
  193. uint32_t next_desc; /**< Next Descriptor Address */
  194. } tdes3_bm;
  195. };
  196. #if ENET_SOC_ALT_EHD_DES_LEN == ENET_SOC_ALT_EHD_DES_MAX_LEN
  197. struct {
  198. uint32_t reserved;
  199. } tdes4_bm;
  200. struct {
  201. uint32_t reserved;
  202. } tdes5_bm;
  203. struct {
  204. uint32_t ttsl; /**< Transmit Frame Timestamp Low */
  205. } tdes6_bm;
  206. struct {
  207. uint32_t ttsh; /**< Transmit Frame Timestamp High */
  208. } tdes7_bm;
  209. #endif
  210. } enet_tx_desc_t;
  211. /** @brief reception descriptor struct */
  212. typedef struct
  213. {
  214. union {
  215. uint32_t rdes0;
  216. struct {
  217. uint32_t ex_sta_rx_addr : 1; /**< Extended Status Available or Rx MAC Address*/
  218. uint32_t ce : 1; /**< CRC Error */
  219. uint32_t dbe : 1; /**< Dribble Bit Error */
  220. uint32_t re : 1; /**< Receive Error */
  221. uint32_t rwt : 1; /**< Receive Watchdog Timeout */
  222. uint32_t ft : 1; /**< Frame Type */
  223. uint32_t lc : 1; /**< Late Collision */
  224. uint32_t ts_ip_gf : 1; /**< Timestamp Available, IP Checksum Error or Giant Frame*/
  225. uint32_t ls : 1; /**< Last Descriptor */
  226. uint32_t fs : 1; /**< First Descriptor */
  227. uint32_t vlan : 1; /**< VLAN Tag */
  228. uint32_t oe : 1; /**< Overflow Error */
  229. uint32_t le : 1; /**< Length Error */
  230. uint32_t saf : 1; /**< Source Address Filter Fail */
  231. uint32_t dse : 1; /**< Descriptor Error */
  232. uint32_t es : 1; /**< Error Summary */
  233. uint32_t fl : 14; /**< Frame Length */
  234. uint32_t afm : 1; /**< Destination Address Filter Fail */
  235. uint32_t own : 1; /**< Own Bit */
  236. } rdes0_bm;
  237. };
  238. union {
  239. uint32_t rdes1;
  240. struct {
  241. uint32_t rbs1 : 13; /**< Receive Buffer 1 Size */
  242. uint32_t reserved0: 1; /**< Reserved */
  243. uint32_t rch : 1; /**< Second Address Chained */
  244. uint32_t rer : 1; /**< Receive End of Ring */
  245. uint32_t rbs2 : 13; /**< Receive Buffer 2 Size */
  246. uint32_t reserved1: 2; /**< Reserved */
  247. uint32_t dic : 1; /**< Disable Interrupt on Completion */
  248. } rdes1_bm;
  249. };
  250. union {
  251. uint32_t rdes2;
  252. struct {
  253. uint32_t buffer1; /**< Buffer 1 Address */
  254. } rdes2_bm;
  255. };
  256. union {
  257. uint32_t rdes3;
  258. union {
  259. uint32_t buffer2; /**< Buffer 2 Address */
  260. uint32_t next_desc; /**< Next Descriptor Address */
  261. } rdes3_bm;
  262. };
  263. #if ENET_SOC_ALT_EHD_DES_LEN == ENET_SOC_ALT_EHD_DES_MAX_LEN
  264. union {
  265. uint32_t rdes4;
  266. struct {
  267. uint32_t ip_payload_type : 3; /**< IP Payload Type */
  268. uint32_t ip_header_err : 1; /**< IP Header Error */
  269. uint32_t ip_payload_err : 1; /**< IP Payload Error */
  270. uint32_t ip_chksum_bypassed : 1; /**< IP Checksum Bypassed */
  271. uint32_t ipv4_pkt_received : 1; /**< IPv4 Packet Received */
  272. uint32_t ipv6_pkt_received : 1; /**< IPv6 Packet Received */
  273. uint32_t msg_type : 4; /**< Message Type */
  274. uint32_t ptp_frame_type : 1; /**< PTP Frame Type */
  275. uint32_t ptp_version : 1; /**< PTP Version */
  276. uint32_t ts_dp : 1; /**< Timestamp Dropped */
  277. uint32_t reserved0 : 1; /**< Reserved */
  278. uint32_t av_pkt_recv : 1; /**< AV Packet Received */
  279. uint32_t av_tagged_pkt_recv : 1; /**< AV Tagged Packet Received */
  280. uint32_t vlan_tag_pri_value : 3; /**< VLAN Tag Priority Value */
  281. uint32_t reserved1 : 3; /**< Reserved */
  282. uint32_t l3_fm : 1; /**< Layer 3 Filter Matched */
  283. uint32_t l4_fm : 1; /**< Layer 4 Filter Matched */
  284. uint32_t l3_l4_fnl : 2; /**< Layer 3 and Layer 4 Filter Number Matched */
  285. uint32_t reserved2 : 4; /**< Reserved */
  286. } rdes4_bm;
  287. };
  288. struct {
  289. uint32_t reserved;
  290. } rdes5_bm;
  291. struct {
  292. uint32_t rtsl; /**< Receive Frame Timestamp Low */
  293. }rdes6_bm;
  294. struct {
  295. uint32_t rtsh; /**< Receive Frame Timestamp High */
  296. } rdes7_bm;
  297. #endif
  298. } enet_rx_desc_t;
  299. /** @brief enet frame struct */
  300. typedef struct{
  301. uint32_t length;
  302. uint32_t buffer;
  303. enet_rx_desc_t *rx_desc;
  304. } enet_frame_t;
  305. /** @brief enet reception frame info struct */
  306. typedef struct {
  307. enet_rx_desc_t *fs_rx_desc;
  308. enet_rx_desc_t *ls_rx_desc;
  309. uint32_t seg_count;
  310. } enet_rx_frame_info_t;
  311. /** @brief enet description struct */
  312. typedef struct {
  313. enet_tx_desc_t *tx_desc_list_head;
  314. enet_rx_desc_t *rx_desc_list_head;
  315. enet_tx_desc_t *tx_desc_list_cur;
  316. enet_rx_desc_t *rx_desc_list_cur;
  317. enet_buff_config_t tx_buff_cfg;
  318. enet_buff_config_t rx_buff_cfg;
  319. enet_rx_frame_info_t rx_frame_info;
  320. } enet_desc_t;
  321. /** @brief PTP timestamp struct */
  322. typedef struct {
  323. uint32_t sec;
  324. uint32_t nsec;
  325. uint8_t sign;
  326. } enet_ptp_time_t;
  327. /* PTP config strcut */
  328. typedef struct {
  329. uint8_t ssinc;
  330. uint8_t sub_sec_count_res;
  331. uint8_t update_method;
  332. uint32_t addend;
  333. } enet_ptp_config_t;
  334. /*
  335. * @brief Bit definition of TDES1
  336. */
  337. #define ENET_DMATxDesc_TBS2 ((uint32_t)0x1FFF0000) /**< Transmit Buffer2 Size */
  338. #define ENET_DMATxDesc_TBS1 ((uint32_t)0x00001FFF) /**< Transmit Buffer1 Size */
  339. #if defined __cplusplus
  340. extern "C" {
  341. #endif /* __cplusplus */
  342. /*---------------------------------------------------------------------*
  343. * Exported Functions
  344. *---------------------------------------------------------------------*/
  345. /**
  346. * @brief Initialize controller
  347. *
  348. * @param[in] ptr An Ethernet peripheral base address
  349. * @param[in] inf_type the specified interface
  350. * @param[in] desc A pointer to descriptor config
  351. * @param[in] config A pointer to mac config
  352. * @param[in] intr A mask of all required interrupts
  353. * @pramm[in] mask_intr A mask of all not required interrupts
  354. */
  355. int enet_controller_init(ENET_Type *ptr, enet_inf_type_t inf_type, enet_desc_t *desc, enet_mac_config_t *config, uint32_t intr, uint32_t mask_intr);
  356. /**
  357. * @brief Read phy
  358. *
  359. * @param[in] ptr An Ethernet peripheral base address
  360. * @param[in] phy_addr the specified address of phy
  361. * @param[in] addr the specified address of register
  362. * @retval A value corresponding to the specifeid register address
  363. */
  364. uint16_t enet_read_phy(ENET_Type *ptr, uint32_t phy_addr, uint32_t addr);
  365. /**
  366. * @brief Write phy
  367. *
  368. * @param[in] ptr An Ethernet peripheral base address
  369. * @param[in] phy_addr a specified address of phy
  370. * @param[in] addr a specified address of the register
  371. * @param[in] data a specified data to be written
  372. */
  373. void enet_write_phy(ENET_Type *ptr, uint32_t phy_addr, uint32_t addr, uint32_t data);
  374. /**
  375. * @brief Check if there is a received frame
  376. *
  377. * @param[out] parent_rx_desc_list_cur a parrent pointer to the current reception descritpion list
  378. * @param[in] rx_frame_info A pointer to the information of the reception frames
  379. * @retval A result of reception frame.
  380. * 1 means that a reception of frame is successful.
  381. * 0 means that a reception of frame is unsuccessful.
  382. */
  383. uint32_t enet_check_received_frame(enet_rx_desc_t **parent_rx_desc_list_cur, enet_rx_frame_info_t *rx_frame_info);
  384. /**
  385. * @brief get a received frame
  386. *
  387. * @param[out] parent_rx_desc_list_cur A parrent pointer to the current reception descritpion list
  388. * @param[in] rx_frame_info A pointer to the information of the reception frames
  389. * @retval A struct of the current reception frame
  390. */
  391. enet_frame_t enet_get_received_frame(enet_rx_desc_t **parent_rx_desc_list_cur, enet_rx_frame_info_t *rx_frame_info);
  392. /**
  393. * @brief get a received frame from interrupt
  394. *
  395. * @param[out] parent_rx_desc_list_cur the parrent pointer to the current reception descritpion list
  396. * @param[in] rx_frame_info A pointer to the information of the reception frames
  397. * @param[in] rx_desc_count A total count of the reception descriptors
  398. * @retval A struct of the current reception frame
  399. */
  400. enet_frame_t enet_get_received_frame_interrupt(enet_rx_desc_t **parent_rx_desc_list_cur, enet_rx_frame_info_t *rx_frame_info, uint32_t rx_desc_count);
  401. /**
  402. * @brief prepare for the transmission descriptors
  403. *
  404. * @param[in] ptr An Ethernet peripheral base address
  405. * @param[out] parent_tx_desc_list_cur a pointer to the information of the reception frames
  406. * @param[in] frame_length the length of the transmission
  407. * @param[in] tx_buff_size the size of the transmission buffer
  408. * @retval a result of the transmission preparation.
  409. * 1 means that the preparation is successful.
  410. * 0 means that the prepartion is unsuccessful.
  411. */
  412. uint32_t enet_prepare_transmission_descriptors(ENET_Type *ptr, enet_tx_desc_t **parent_tx_desc_list_cur, uint16_t frame_length, uint16_t tx_buff_size);
  413. /**
  414. * @brief Initialize DMA transmission descriptors in chain mode
  415. *
  416. * @param[in] ptr An Ethernet peripheral base address
  417. * @param[in] desc A pointer to transmission descriptors
  418. */
  419. void enet_dma_tx_desc_chain_init(ENET_Type *ptr, enet_desc_t *desc);
  420. /**
  421. * @brief Initialize DMA reception descriptors in chain mode
  422. *
  423. * @param[in] ptr An Ethernet peripheral base address
  424. * @param[in] desc A pointer to reception descriptors
  425. */
  426. void enet_dma_rx_desc_chain_init(ENET_Type *ptr, enet_desc_t *desc);
  427. /**
  428. * @brief Flush DMA
  429. *
  430. * @param[in] ptr An Ethernet peripheral base address
  431. */
  432. void enet_dma_flush(ENET_Type *ptr);
  433. /**
  434. * @brief Initialize a PTP timer
  435. *
  436. * @param[in] ptr An Ethernet peripheral base address
  437. * @param[in] config A pointer to an enet_ptp_config struct instance
  438. */
  439. void enet_init_ptp(ENET_Type *ptr, enet_ptp_config_t *config);
  440. /**
  441. * @brief Set a timestamp to the PTP timer
  442. *
  443. * @param[in] ptr An Ethernet peripheral base address
  444. * @param[in] timestamp A pointer to a timestamp structure instance
  445. */
  446. void enet_set_ptp_timestamp(ENET_Type *ptr, enet_ptp_time_t *timestamp);
  447. /**
  448. * @brief Get a timestamp from the PTP timer
  449. *
  450. * @param[in] ptr An Ethernet peripheral base address
  451. * @param[out] timestamp A pointer to a timestamp structure instance
  452. */
  453. void enet_get_ptp_timestamp(ENET_Type *ptr, enet_ptp_time_t *timestamp);
  454. /**
  455. * @brief Update a timestamp to the PTP timer
  456. *
  457. * @param[in] ptr An Ethernet peripheral base address
  458. * @param[in] timeoffset A pointer to a timestamp structure instance
  459. */
  460. void enet_update_ptp_timeoffset(ENET_Type *ptr, enet_ptp_time_t *timeoffset);
  461. /**
  462. * @brief Adjust the count frequency of the PTP timer
  463. *
  464. * @param[in] ptr An Ethernet peripheral base address
  465. * @param[in] adj An adjustment value for the count frequency of the PTP timer
  466. */
  467. void enet_adjust_ptp_time_freq(ENET_Type *ptr, int32_t adj);
  468. /**
  469. * @brief Set the PTP version
  470. *
  471. * @param[in] ptr An Ethernet peripheral base address
  472. * @param[in] ptp_ver An enum value indicating the PTP protocol
  473. */
  474. void enet_set_ptp_version(ENET_Type *ptr, enet_ptp_version_t ptp_ver);
  475. /**
  476. * @brief Enable the specified ptp frame type for MAC process
  477. *
  478. * @param[in] ptr An Ethernet peripheral base address
  479. * @param[in] ptp_frame_type An enum value indicating the transport protocol of PTP frames
  480. * @param[in] enable A value to enable or disable the transport protocol of PTP frames which is specified by ptp_frame_type parameter
  481. * @retval hpm_stat_t @ref status_invalid_argument or @ref status_success
  482. */
  483. hpm_stat_t enet_enable_ptp_frame_type(ENET_Type *ptr, enet_ptp_frame_type_t ptp_frame_type, bool enable);
  484. /**
  485. * @brief Set the ptp message type for snapshots
  486. *
  487. * @param[in] ptr An Ethernet peripheral base address
  488. * @param[in] ts_ss_ptp_msg An enum value indicating the specified ptp message type for snapshots
  489. */
  490. void enet_set_snapshot_ptp_message_type(ENET_Type *ptr, enet_ts_ss_ptp_msg_t ts_ss_ptp_msg);
  491. #if defined __cplusplus
  492. }
  493. #endif /* __cplusplus */
  494. /** @} */
  495. #endif /* HPM_ENET_DRV_H */