hpm_enet_drv.h 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /*
  2. * Copyright (c) 2021-2024 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. */
  13. #include "hpm_common.h"
  14. #include "hpm_enet_regs.h"
  15. #include "hpm_soc_feature.h"
  16. #include "hpm_enet_soc_drv.h"
  17. /**
  18. * @brief Enet driver APIs
  19. * @defgroup enet_interface Enet driver APIs
  20. * @ingroup communication_interfaces
  21. * @{
  22. */
  23. /*---------------------------------------------------------------------
  24. * Macro Constant Declarations
  25. *---------------------------------------------------------------------
  26. */
  27. #define ENET_HEADER (14U) /**< 6-byte Dest addr, 6-byte Src addr, 2-byte type */
  28. #define ENET_EXTRA (2U) /**< Extra bytes in some cases */
  29. #define ENET_VLAN_TAG (4U) /**< optional 802.1q VLAN Tag */
  30. #define ENET_CRC (4U) /**< Ethernet CRC */
  31. #define ENET_MIN_PAYLOAD (46U) /**< Minimum Ethernet payload size */
  32. #define ENET_MAX_PAYLOAD (1500U) /**< Maximum Ethernet payload size */
  33. #define ENET_MAX_FRAME_SIZE (1524U) /**< ENET_HEADER + ENET_EXTRA + VLAN_TAG + MAX_ENET_PAYLOAD + ENET_CRC */
  34. #define ENET_JUMBO_FRAME_PAYLOAD (9000U) /**< Jumbo frame payload size */
  35. #define ENET_MAC (6) /**< Ethernet MAC size */
  36. #define ENET_ERROR (0) /**< ENET error */
  37. #define ENET_SUCCESS (1) /**< ENET success */
  38. #define ENET_ADJ_FREQ_BASE_ADDEND (0x80000000UL) /**< PTP base adjustment addend */
  39. #define ENET_ONE_SEC_IN_NANOSEC (1000000000UL) /**< one second in nanoseconds */
  40. #define ENET_PPS_CMD_MASK (0x07UL) /**< Enet PPS CMD Mask */
  41. #define ENET_PPS_CMD_OFS_FAC (3U) /**< Enet PPS CMD OFS Factor */
  42. #ifndef ENET_RETRY_CNT
  43. #define ENET_RETRY_CNT (10000UL) /**< Enet retry count for PTP */
  44. #endif
  45. /*---------------------------------------------------------------------
  46. * Typedef Enum Declarations
  47. *---------------------------------------------------------------------
  48. */
  49. /** @brief interrupt enable type */
  50. typedef enum {
  51. enet_normal_int_sum_en = ENET_DMA_INTR_EN_NIE_MASK,
  52. enet_aboarmal_int_sum_en = ENET_DMA_INTR_EN_AIE_MASK,
  53. enet_receive_int_en = ENET_DMA_INTR_EN_RIE_MASK,
  54. enet_transmit_int_en = ENET_DMA_INTR_EN_TIE_MASK
  55. } enet_interrupt_enable_t;
  56. /** @brief interrupt mask type */
  57. typedef enum {
  58. enet_lpi_int_mask = ENET_INTR_MASK_LPIIM_MASK,
  59. enet_rgsmii_int_mask = ENET_INTR_MASK_RGSMIIIM_MASK
  60. } enet_interrupt_mask_t;
  61. /** @brief Programmable burst length selections */
  62. typedef enum {
  63. enet_pbl_1 = 1,
  64. enet_pbl_2 = 2,
  65. enet_pbl_4 = 4,
  66. enet_pbl_8 = 8,
  67. enet_pbl_16 = 16,
  68. enet_pbl_32 = 32
  69. } enet_pbl_t;
  70. /** @brief Checksum insertion control selections */
  71. typedef enum {
  72. enet_cic_disable = 0,
  73. enet_cic_ip = 1,
  74. enet_cic_ip_no_pseudoheader = 2,
  75. enet_cic_ip_pseudoheader = 3
  76. } enet_cic_insertion_control_t;
  77. /** @brief VLAN insertion control selections */
  78. typedef enum {
  79. enet_vlic_disable = 0,
  80. enet_vlic_remove_vlan_tag = 1,
  81. enet_vlic_insert_vlan_tag = 2,
  82. enet_vlic_replace_vlan_tag = 3
  83. } enet_vlan_insertion_control_t;
  84. /** @brief SA insertion or replacement control selections for any selective frames */
  85. typedef enum {
  86. enet_saic_disable = 0,
  87. enet_saic_insert_mac0 = 1,
  88. enet_saic_replace_mac0 = 2,
  89. enet_saic_insert_mac1 = 5,
  90. enet_saic_replace_mac1 = 6
  91. } enet_saic_insertion_replacement_control_t;
  92. /** @brief SA insertion or replacement control selections for all transmit frames */
  93. typedef enum {
  94. enet_sarc_disable = 0,
  95. enet_sarc_insert_mac0 = 2,
  96. enet_sarc_replace_mac0 = 3,
  97. enet_sarc_insert_mac1 = 6,
  98. enet_sarc_replace_mac1 = 7
  99. } enet_sarc_insertion_replacement_control_t;
  100. /** @brief PHY operation selections */
  101. typedef enum {
  102. enet_phy_op_read = 0,
  103. enet_phy_op_write
  104. } enet_phy_op_t;
  105. /** @brief PHY status */
  106. typedef enum {
  107. enet_gmii_idle = 0,
  108. enet_gmii_busy
  109. } enet_gmii_status_t;
  110. /** @brief CSR clock range and MDC clock selections */
  111. /** @note The suggested range of CSR clock is approximately
  112. * between the frequency range 1.0MHz-2.5MHz.
  113. * You can achieve higher frequency of the MDC clock than the frequency limit of 2.5MHz(specified in the IEEE Std 802.3)
  114. * 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
  115. * only if the interfacing chips support faster MDC clocks.
  116. */
  117. typedef enum {
  118. enet_csr_60m_to_100m_mdc_csr_div_42 = 0, /**< CSR clock range: 60-100MHz <==> MDC clock: CSR clock / 42 */
  119. enet_csr_100m_to_150m_mdc_csr_div_62, /**< CSR clock range: 100-150MHz <==> MDC clock: CSR clock / 62 */
  120. enet_csr_20m_to_35m_mdc_csr_div_16, /**< CSR clock range: 20-35MHz <==> MDC clock: CSR clock / 16 */
  121. enet_csr_35m_to_60m_mdc_csr_div_26, /**< CSR clock range: 35-60MHz <==> MDC clock: CSR clock / 26 */
  122. enet_csr_150m_to_250m_mdc_csr_div_102, /**< CSR clock range: 150-250MHz <==> MDC clock: CSR clock / 102 */
  123. enet_csr_250m_to_300m_mdc_csr_div_124, /**< CSR clock range: 250-300MHz <==> MDC clock: CSR clock / 124 */
  124. enet_csr_60m_to_100m_mdc_csr_div_4 = 8, /**< CSR clock / 4 */
  125. enet_csr_60m_to_100m_mdc_csr_div_6, /**< CSR clock / 6 */
  126. enet_csr_60m_to_100m_mdc_csr_div_8, /**< CSR clock / 8 */
  127. enet_csr_60m_to_100m_mdc_csr_div_10, /**< CSR clock / 10 */
  128. enet_csr_60m_to_100m_mdc_csr_div_12, /**< CSR clock / 12 */
  129. enet_csr_60m_to_100m_mdc_csr_div_14, /**< CSR clock / 14 */
  130. enet_csr_60m_to_100m_mdc_csr_div_16, /**< CSR clock / 16 */
  131. enet_csr_60m_to_100m_mdc_csr_div_18 /**< CSR clock / 18 */
  132. } enet_csr_clk_range_t;
  133. /** @brief enet interface selections */
  134. typedef enum {
  135. enet_inf_mii = 0,
  136. enet_inf_rmii = 4,
  137. enet_inf_rgmii = 1
  138. } enet_inf_type_t;
  139. /** @brief enet line speed */
  140. typedef enum {
  141. enet_line_speed_1000mbps = 0,
  142. enet_line_speed_10mbps = 2,
  143. enet_line_speed_100mbps = 3
  144. } enet_line_speed_t;
  145. /** @brief enet duplex mode */
  146. typedef enum {
  147. enet_half_duplex = 0,
  148. enet_full_duplex
  149. } enet_duplex_mode_t;
  150. /** @brief enet timestamp update methods */
  151. typedef enum {
  152. enet_ptp_time_coarse_update = 0,
  153. enet_ptp_time_fine_update
  154. } enet_ptp_time_update_method_t;
  155. /** @brief PTP versions */
  156. typedef enum {
  157. enet_ptp_v1 = 0,
  158. enet_ptp_v2
  159. } enet_ptp_version_t;
  160. /** @brief PTP frame types */
  161. typedef enum {
  162. enet_ptp_frame_ipv4 = 0,
  163. enet_ptp_frame_ipv6,
  164. enet_ptp_frame_ethernet
  165. } enet_ptp_frame_type_t;
  166. /** @brief PTP message type for snapshots */
  167. typedef enum {
  168. enet_ts_ss_ptp_msg_0 = 0, /* SYNC, Follow_Up, Delay_Req, Delay_Resp */
  169. enet_ts_ss_ptp_msg_1 = 1, /* SYNC */
  170. enet_ts_ss_ptp_msg_2 = 3, /* Delay_Req */
  171. enet_ts_ss_ptp_msg_3 = 4, /* SYNC, Follow_Up, Delay_Req, Delay_Resp, Pdelay_Req, Pdelay_Resp, Pdelay_Resp_Follow_Up */
  172. enet_ts_ss_ptp_msg_4 = 5, /* SYNC, Pdelay_Req, Pdelay_Resp */
  173. enet_ts_ss_ptp_msg_5 = 7, /* Delay_Req, Pdelay_Req, Pdelay_Resp */
  174. enet_ts_ss_ptp_msg_6 = 8, /* SYNC, Delay_Req */
  175. enet_ts_ss_ptp_msg_7 = 12 /* Pdelay_Req, Pdelay_Resp */
  176. } enet_ts_ss_ptp_msg_t;
  177. /** @brief PTP timer rollover modes */
  178. typedef enum {
  179. enet_ts_bin_rollover_control = 0, /* timestamp rolls over after 0x7fffffff */
  180. enet_ts_dig_rollover_control /* timestamp rolls over after 0x3b9ac9ff */
  181. } enet_ts_rollover_control_t;
  182. /** @brief PPS indexes */
  183. typedef enum {
  184. enet_pps_0 = -1,
  185. enet_pps_1 = 0,
  186. enet_pps_2 = 1,
  187. enet_pps_3 = 2
  188. } enet_pps_idx_t;
  189. /** @brief PPS0 control for output frequency selections */
  190. typedef enum {
  191. enet_pps_ctrl_pps = 0,
  192. enet_pps_ctrl_bin_2hz_digital_1hz,
  193. enet_pps_ctrl_bin_4hz_digital_2hz,
  194. enet_pps_ctrl_bin_8hz_digital_4hz,
  195. enet_pps_ctrl_bin_16hz_digital_8hz,
  196. enet_pps_ctrl_bin_32hz_digital_16hz,
  197. enet_pps_ctrl_bin_64hz_digital_32hz,
  198. enet_pps_ctrl_bin_128hz_digital_64hz,
  199. enet_pps_ctrl_bin_256hz_digital_128hz,
  200. enet_pps_ctrl_bin_512hz_digital_256hz,
  201. enet_pps_ctrl_bin_1024hz_digital_512hz,
  202. enet_pps_ctrl_bin_2048hz_digital_1024hz,
  203. enet_pps_ctrl_bin_4096hz_digital_2048hz,
  204. enet_pps_ctrl_bin_8192hz_digital_4096hz,
  205. enet_pps_ctrl_bin_16384hz_digital_8192hz,
  206. enet_pps_ctrl_bin_32768hz_digital_16384hz
  207. } enet_pps_ctrl_t;
  208. /** @brief PPS0 commands */
  209. typedef enum {
  210. enet_pps_cmd_no_command = 0,
  211. enet_pps_cmd_start_single_pulse,
  212. enet_pps_cmd_start_pulse_train,
  213. enet_pps_cmd_cancel_start,
  214. enet_pps_cmd_stop_pulse_train_at_time,
  215. enet_pps_cmd_stop_pulse_train_immediately,
  216. enet_pps_cmd_cancel_stop_pulse_train
  217. } enet_pps_cmd_t;
  218. /*---------------------------------------------------------------------
  219. * Typedef Struct Declarations
  220. *---------------------------------------------------------------------
  221. */
  222. /** @brief enet buffer config struct */
  223. typedef struct {
  224. uint32_t buffer;
  225. uint32_t count;
  226. uint16_t size;
  227. } enet_buff_config_t;
  228. /** @brief enet mac config struct */
  229. typedef struct {
  230. uint32_t mac_addr_high[ENET_SOC_ADDR_MAX_COUNT];
  231. uint32_t mac_addr_low[ENET_SOC_ADDR_MAX_COUNT];
  232. uint8_t valid_max_count;
  233. uint8_t dma_pbl;
  234. uint8_t sarc;
  235. } enet_mac_config_t;
  236. /** @brief transmission descriptor struct */
  237. typedef struct {
  238. union {
  239. uint32_t tdes0;
  240. struct {
  241. uint32_t db: 1; /**< * Deferred Bit*/
  242. uint32_t uf: 1; /**< * Underflow Error */
  243. uint32_t ed: 1; /**< * Excessive Deferral */
  244. uint32_t cc: 4; /**< * Collision Count */
  245. uint32_t vf: 1; /**< * VLAN Frame */
  246. uint32_t ec: 1; /**< * Excessive Collision */
  247. uint32_t lc: 1; /**< * Late Collision */
  248. uint32_t nc: 1; /**< * No Carrier */
  249. uint32_t loc: 1; /**< * Loss of Carrier */
  250. uint32_t ipe: 1; /**< * IP Payload Error */
  251. uint32_t ff: 1; /**< * Frame Flushed */
  252. uint32_t jt: 1; /**< * Jabber Timeout */
  253. uint32_t es: 1; /**< * Error Summary */
  254. uint32_t ihe: 1; /**< * IP Header Error */
  255. uint32_t ttss: 1; /**< * Transmit Timestamp Status */
  256. uint32_t vlic: 2; /**< * VLAN Insertion Control */
  257. uint32_t tch: 1; /**< * Second Address Chained */
  258. uint32_t ter: 1; /**< * Transmit End of Ring */
  259. uint32_t cic: 2; /**< * Checksum Insertion Control */
  260. uint32_t crcr: 1; /**< * CRC Replacement Control */
  261. uint32_t ttse: 1; /**< * Transmit Timestamp Enable */
  262. uint32_t dp: 1; /**< * Disable Pad */
  263. uint32_t dc: 1; /**< * Disable CRC */
  264. uint32_t fs: 1; /**< * First Segment */
  265. uint32_t ls: 1; /**< * Last Segment */
  266. uint32_t ic: 1; /**< * Interrupt on Completion */
  267. uint32_t own: 1; /**< * Own Bit */
  268. } tdes0_bm;
  269. };
  270. union {
  271. uint32_t tdes1;
  272. struct {
  273. uint32_t tbs1 : 13; /**< Transmit Buffer 1 Size */
  274. uint32_t reserved: 3; /**< Reserved */
  275. uint32_t tbs2 : 13; /**< Transmit Buffer 2 Size */
  276. uint32_t saic : 3; /**< SA Insertion Control */
  277. } tdes1_bm;
  278. };
  279. union {
  280. uint32_t tdes2;
  281. struct {
  282. uint32_t buffer1; /**< Buffer 1 Address */
  283. } tdes2_bm;
  284. };
  285. union {
  286. uint32_t tdes3;
  287. union {
  288. uint32_t buffer2; /**< Buffer 2 Address */
  289. uint32_t next_desc; /**< Next Descriptor Address */
  290. } tdes3_bm;
  291. };
  292. #if ENET_SOC_ALT_EHD_DES_LEN == ENET_SOC_ALT_EHD_DES_MAX_LEN
  293. struct {
  294. uint32_t reserved;
  295. } tdes4_bm;
  296. struct {
  297. uint32_t reserved;
  298. } tdes5_bm;
  299. struct {
  300. uint32_t ttsl; /**< Transmit Frame Timestamp Low */
  301. } tdes6_bm;
  302. struct {
  303. uint32_t ttsh; /**< Transmit Frame Timestamp High */
  304. } tdes7_bm;
  305. #endif
  306. } enet_tx_desc_t;
  307. /** @brief reception descriptor struct */
  308. typedef struct {
  309. union {
  310. uint32_t rdes0;
  311. struct {
  312. uint32_t ex_sta_rx_addr : 1; /**< Extended Status Available or Rx MAC Address*/
  313. uint32_t ce : 1; /**< CRC Error */
  314. uint32_t dbe : 1; /**< Dribble Bit Error */
  315. uint32_t re : 1; /**< Receive Error */
  316. uint32_t rwt : 1; /**< Receive Watchdog Timeout */
  317. uint32_t ft : 1; /**< Frame Type */
  318. uint32_t lc : 1; /**< Late Collision */
  319. uint32_t ts_ip_gf : 1; /**< Timestamp Available, IP Checksum Error or Giant Frame*/
  320. uint32_t ls : 1; /**< Last Descriptor */
  321. uint32_t fs : 1; /**< First Descriptor */
  322. uint32_t vlan : 1; /**< VLAN Tag */
  323. uint32_t oe : 1; /**< Overflow Error */
  324. uint32_t le : 1; /**< Length Error */
  325. uint32_t saf : 1; /**< Source Address Filter Fail */
  326. uint32_t dse : 1; /**< Descriptor Error */
  327. uint32_t es : 1; /**< Error Summary */
  328. uint32_t fl : 14; /**< Frame Length */
  329. uint32_t afm : 1; /**< Destination Address Filter Fail */
  330. uint32_t own : 1; /**< Own Bit */
  331. } rdes0_bm;
  332. };
  333. union {
  334. uint32_t rdes1;
  335. struct {
  336. uint32_t rbs1 : 13; /**< Receive Buffer 1 Size */
  337. uint32_t reserved0: 1; /**< Reserved */
  338. uint32_t rch : 1; /**< Second Address Chained */
  339. uint32_t rer : 1; /**< Receive End of Ring */
  340. uint32_t rbs2 : 13; /**< Receive Buffer 2 Size */
  341. uint32_t reserved1: 2; /**< Reserved */
  342. uint32_t dic : 1; /**< Disable Interrupt on Completion */
  343. } rdes1_bm;
  344. };
  345. union {
  346. uint32_t rdes2;
  347. struct {
  348. uint32_t buffer1; /**< Buffer 1 Address */
  349. } rdes2_bm;
  350. };
  351. union {
  352. uint32_t rdes3;
  353. union {
  354. uint32_t buffer2; /**< Buffer 2 Address */
  355. uint32_t next_desc; /**< Next Descriptor Address */
  356. } rdes3_bm;
  357. };
  358. #if ENET_SOC_ALT_EHD_DES_LEN == ENET_SOC_ALT_EHD_DES_MAX_LEN
  359. union {
  360. uint32_t rdes4;
  361. struct {
  362. uint32_t ip_payload_type : 3; /**< IP Payload Type */
  363. uint32_t ip_header_err : 1; /**< IP Header Error */
  364. uint32_t ip_payload_err : 1; /**< IP Payload Error */
  365. uint32_t ip_chksum_bypassed : 1; /**< IP Checksum Bypassed */
  366. uint32_t ipv4_pkt_received : 1; /**< IPv4 Packet Received */
  367. uint32_t ipv6_pkt_received : 1; /**< IPv6 Packet Received */
  368. uint32_t msg_type : 4; /**< Message Type */
  369. uint32_t ptp_frame_type : 1; /**< PTP Frame Type */
  370. uint32_t ptp_version : 1; /**< PTP Version */
  371. uint32_t ts_dp : 1; /**< Timestamp Dropped */
  372. uint32_t reserved0 : 1; /**< Reserved */
  373. uint32_t av_pkt_recv : 1; /**< AV Packet Received */
  374. uint32_t av_tagged_pkt_recv : 1; /**< AV Tagged Packet Received */
  375. uint32_t vlan_tag_pri_value : 3; /**< VLAN Tag Priority Value */
  376. uint32_t reserved1 : 3; /**< Reserved */
  377. uint32_t l3_fm : 1; /**< Layer 3 Filter Matched */
  378. uint32_t l4_fm : 1; /**< Layer 4 Filter Matched */
  379. uint32_t l3_l4_fnl : 2; /**< Layer 3 and Layer 4 Filter Number Matched */
  380. uint32_t reserved2 : 4; /**< Reserved */
  381. } rdes4_bm;
  382. };
  383. struct {
  384. uint32_t reserved;
  385. } rdes5_bm;
  386. struct {
  387. uint32_t rtsl; /**< Receive Frame Timestamp Low */
  388. } rdes6_bm;
  389. struct {
  390. uint32_t rtsh; /**< Receive Frame Timestamp High */
  391. } rdes7_bm;
  392. #endif
  393. } enet_rx_desc_t;
  394. /** @brief enet frame struct */
  395. typedef struct{
  396. uint32_t length;
  397. uint32_t buffer;
  398. enet_rx_desc_t *rx_desc;
  399. } enet_frame_t;
  400. /** @brief enet reception frame info struct */
  401. typedef struct {
  402. enet_rx_desc_t *fs_rx_desc;
  403. enet_rx_desc_t *ls_rx_desc;
  404. uint32_t seg_count;
  405. } enet_rx_frame_info_t;
  406. /** @brief enet control config struct for transmission */
  407. typedef struct {
  408. bool enable_ioc; /* interrupt on completion */
  409. bool disable_crc; /* disable CRC */
  410. bool disable_pad; /* disable Pad */
  411. bool enable_ttse; /* enable transmit timestamp */
  412. bool enable_crcr; /* CRC replacement control */
  413. uint8_t cic; /* checksum insertion control */
  414. uint8_t vlic; /* VLAN insertion control */
  415. uint8_t saic; /* SA insertion control */
  416. } enet_tx_control_config_t;
  417. /** @brief enet description struct */
  418. typedef struct {
  419. enet_tx_desc_t *tx_desc_list_head;
  420. enet_rx_desc_t *rx_desc_list_head;
  421. enet_tx_desc_t *tx_desc_list_cur;
  422. enet_rx_desc_t *rx_desc_list_cur;
  423. enet_buff_config_t tx_buff_cfg;
  424. enet_buff_config_t rx_buff_cfg;
  425. enet_rx_frame_info_t rx_frame_info;
  426. enet_tx_control_config_t tx_control_config;
  427. } enet_desc_t;
  428. /** @brief PTP system timestamp struct */
  429. typedef struct {
  430. uint32_t sec;
  431. uint32_t nsec;
  432. } enet_ptp_ts_system_t;
  433. /** @brief PTP update timestamp struct */
  434. typedef struct {
  435. uint32_t sec;
  436. uint32_t nsec;
  437. uint8_t sign;
  438. } enet_ptp_ts_update_t;
  439. /** @brief PTP target timestamp struct */
  440. typedef struct {
  441. uint32_t sec;
  442. uint32_t nsec;
  443. } enet_ptp_ts_target_t;
  444. /** @brief PTP config strcut */
  445. typedef struct {
  446. uint8_t ssinc;
  447. uint8_t timestamp_rollover_mode;
  448. uint8_t update_method;
  449. uint32_t addend;
  450. } enet_ptp_config_t;
  451. /** @brief PTP PPS command output config strcut */
  452. typedef struct {
  453. uint32_t pps_interval;
  454. uint32_t pps_width;
  455. uint32_t target_sec;
  456. uint32_t target_nsec;
  457. } enet_pps_cmd_config_t;
  458. /** @brief Enet interrupt config struct */
  459. typedef struct {
  460. uint32_t int_enable; /* DMA_INTR_EN */
  461. uint32_t int_mask; /* INTR MASK */
  462. uint32_t mmc_intr_rx;
  463. uint32_t mmc_intr_mask_rx;
  464. uint32_t mmc_intr_tx;
  465. uint32_t mmc_intr_mask_tx;
  466. } enet_int_config_t;
  467. /*
  468. * @brief Bit definition of TDES1
  469. */
  470. #define ENET_DMATxDesc_TBS2 ((uint32_t)0x1FFF0000) /**< Transmit Buffer2 Size */
  471. #define ENET_DMATxDesc_TBS1 ((uint32_t)0x00001FFF) /**< Transmit Buffer1 Size */
  472. #if defined __cplusplus
  473. extern "C" {
  474. #endif /* __cplusplus */
  475. /*---------------------------------------------------------------------
  476. * Exported Functions
  477. *---------------------------------------------------------------------
  478. */
  479. /**
  480. * @brief Get a default control config for tranmission
  481. *
  482. * @param[in] ptr An Ethernet peripheral base address
  483. * @param[in] config A pointer to a control config structure for tranmission
  484. */
  485. void enet_get_default_tx_control_config(ENET_Type *ptr, enet_tx_control_config_t *config);
  486. /**
  487. * @brief Get a default interrupt config
  488. *
  489. * @param[in] ptr An Ethernet peripheral base address
  490. * @param[in] config A pointer to a interrupt config structure
  491. */
  492. void enet_get_default_interrupt_config(ENET_Type *ptr, enet_int_config_t *config);
  493. /**
  494. * @brief Get interrupt status
  495. *
  496. * @param[in] ptr An Ethernet peripheral base address
  497. * @return A result of interrupt status
  498. */
  499. uint32_t enet_get_interrupt_status(ENET_Type *ptr);
  500. /**
  501. * @brief Mask the specified mmc interrupt evenets of received frames
  502. *
  503. * @param[in] ptr An Ethernet peripheral base address
  504. * @param[in] mask A mask of the specified evenets
  505. */
  506. void enet_mask_mmc_rx_interrupt_event(ENET_Type *ptr, uint32_t mask);
  507. /**
  508. * @brief Mask the specified mmc interrupt evenets of transmitted frames
  509. *
  510. * @param[in] ptr An Ethernet peripheral base address
  511. * @param[in] mask A mask of the specified evenets
  512. */
  513. void enet_mask_mmc_tx_interrupt_event(ENET_Type *ptr, uint32_t mask);
  514. /**
  515. * @brief Get a staus of mmc receive interrupt events
  516. *
  517. * @param[in] ptr An Ethernet peripheral base address
  518. * @return A result of interrupt status
  519. */
  520. uint32_t enet_get_mmc_rx_interrupt_status(ENET_Type *ptr);
  521. /**
  522. * @brief et a staus of mmc transmission interrupt events
  523. *
  524. * @param[in] ptr An Ethernet peripheral base address
  525. * @return A result of interrupt status
  526. */
  527. uint32_t enet_get_mmc_tx_interrupt_status(ENET_Type *ptr);
  528. /**
  529. * @brief Initialize controller
  530. *
  531. * @param[in] ptr An Ethernet peripheral base address
  532. * @param[in] inf_type the specified interface
  533. * @param[in] desc A pointer to descriptor config
  534. * @param[in] cfg A pointer to mac config
  535. * @param[in] int_config A pointer to the masks of the specified enabled interrupts and the specified masked interrupts
  536. * @return A result of the specified controller initialization
  537. */
  538. hpm_stat_t enet_controller_init(ENET_Type *ptr, enet_inf_type_t inf_type, enet_desc_t *desc, enet_mac_config_t *cfg, enet_int_config_t *int_config);
  539. /**
  540. * @brief Set port line speed
  541. *
  542. * @param[in] ptr An Ethernet peripheral base address
  543. * @param[in] speed An enum variable of @ref enet_line_speed_t
  544. */
  545. void enet_set_line_speed(ENET_Type *ptr, enet_line_speed_t speed);
  546. /**
  547. * @brief Set duplex mode
  548. *
  549. * @param[in] ptr An Ethernet peripheral base address
  550. * @param[in] mode An enum variable of @ref enet_duplex_mode_t
  551. */
  552. void enet_set_duplex_mode(ENET_Type *ptr, enet_duplex_mode_t mode);
  553. /**
  554. * @brief Read phy
  555. *
  556. * @param[in] ptr An Ethernet peripheral base address
  557. * @param[in] phy_addr the specified address of phy
  558. * @param[in] addr the specified address of register
  559. * @retval A value corresponding to the specified register address
  560. */
  561. uint16_t enet_read_phy(ENET_Type *ptr, uint32_t phy_addr, uint32_t addr);
  562. /**
  563. * @brief Write phy
  564. *
  565. * @param[in] ptr An Ethernet peripheral base address
  566. * @param[in] phy_addr a specified address of phy
  567. * @param[in] addr a specified address of the register
  568. * @param[in] data a specified data to be written
  569. */
  570. void enet_write_phy(ENET_Type *ptr, uint32_t phy_addr, uint32_t addr, uint32_t data);
  571. /**
  572. * @brief Resume reception process
  573. *
  574. * @param[in] ptr An Ethernet peripheral base address
  575. *
  576. */
  577. void enet_rx_resume(ENET_Type *ptr);
  578. /**
  579. * @brief Check if there is a received frame
  580. *
  581. * @param[out] parent_rx_desc_list_cur a parent pointer to the current reception description list
  582. * @param[in] rx_frame_info A pointer to the information of the reception frames
  583. * @retval A result of reception frame.
  584. * 1 means that a reception of frame is successful.
  585. * 0 means that a reception of frame is unsuccessful.
  586. */
  587. uint32_t enet_check_received_frame(enet_rx_desc_t **parent_rx_desc_list_cur, enet_rx_frame_info_t *rx_frame_info);
  588. /**
  589. * @brief get a received frame
  590. *
  591. * @param[out] parent_rx_desc_list_cur A parent pointer to the current reception description list
  592. * @param[in] rx_frame_info A pointer to the information of the reception frames
  593. * @retval A struct of the current reception frame
  594. */
  595. enet_frame_t enet_get_received_frame(enet_rx_desc_t **parent_rx_desc_list_cur, enet_rx_frame_info_t *rx_frame_info);
  596. /**
  597. * @brief get a received frame from interrupt
  598. *
  599. * @param[out] parent_rx_desc_list_cur the parent pointer to the current reception description list
  600. * @param[in] rx_frame_info A pointer to the information of the reception frames
  601. * @param[in] rx_desc_count A total count of the reception descriptors
  602. * @retval A struct of the current reception frame
  603. */
  604. 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);
  605. /**
  606. * @brief prepare for the transmission descriptors (It will be deprecated.)
  607. *
  608. * @param[in] ptr An Ethernet peripheral base address
  609. * @param[out] parent_tx_desc_list_cur a pointer to the information of the reception frames
  610. * @param[in] frame_length the length of the transmission
  611. * @param[in] tx_buff_size the size of the transmission buffer
  612. * @retval a result of the transmission preparation.
  613. * 1 means that the preparation is successful.
  614. * 0 means that the preparation is unsuccessful.
  615. */
  616. 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);
  617. /**
  618. * @brief prepare for the transmission descriptors
  619. *
  620. * @param[in] ptr An Ethernet peripheral base address
  621. * @param[out] parent_tx_desc_list_cur a pointer to the information of the reception frames
  622. * @param[in] config a pointer to the control configuration for the transmission frames
  623. * @param[in] frame_length the length of the transmission
  624. * @param[in] tx_buff_size the size of the transmission buffer
  625. * @retval a result of the transmission preparation.
  626. * 1 means that the preparation is successful.
  627. * 0 means that the preparation is unsuccessful.
  628. */
  629. uint32_t enet_prepare_tx_desc(ENET_Type *ptr, enet_tx_desc_t **parent_tx_desc_list_cur, enet_tx_control_config_t *config, uint16_t frame_length, uint16_t tx_buff_size);
  630. /**
  631. * @brief prepare for the transmission descriptors with a timestamp record
  632. *
  633. * @param[in] ptr An Ethernet peripheral base address
  634. * @param[out] parent_tx_desc_list_cur a pointer to the information of the reception frames
  635. * @param[in] config a pointer to the control configuration for the transmission frames
  636. * @param[in] frame_length the length of the transmission
  637. * @param[in] tx_buff_size the size of the transmission buffer
  638. * @param[out] timestamp a pointer to the timestamp record of a transmitted frame
  639. * @retval a result of the transmission preparation.
  640. * 1 means that the preparation is successful.
  641. * 0 means that the preparation is unsuccessful.
  642. */
  643. uint32_t enet_prepare_tx_desc_with_ts_record(ENET_Type *ptr,
  644. enet_tx_desc_t **parent_tx_desc_list_cur,
  645. enet_tx_control_config_t *config,
  646. uint16_t frame_length, uint16_t tx_buff_size,
  647. enet_ptp_ts_system_t *timestamp);
  648. /**
  649. * @brief Initialize DMA transmission descriptors in chain mode
  650. *
  651. * @param[in] ptr An Ethernet peripheral base address
  652. * @param[in] desc A pointer to transmission descriptors
  653. */
  654. void enet_dma_tx_desc_chain_init(ENET_Type *ptr, enet_desc_t *desc);
  655. /**
  656. * @brief Initialize DMA reception descriptors in chain mode
  657. *
  658. * @param[in] ptr An Ethernet peripheral base address
  659. * @param[in] desc A pointer to reception descriptors
  660. */
  661. void enet_dma_rx_desc_chain_init(ENET_Type *ptr, enet_desc_t *desc);
  662. /**
  663. * @brief Flush DMA
  664. *
  665. * @param[in] ptr An Ethernet peripheral base address
  666. */
  667. void enet_dma_flush(ENET_Type *ptr);
  668. /**
  669. * @brief Initialize a PTP timer
  670. *
  671. * @param[in] ptr An Ethernet peripheral base address
  672. * @param[in] config A pointer to an enet_ptp_config struct instance
  673. */
  674. void enet_init_ptp(ENET_Type *ptr, enet_ptp_config_t *config);
  675. /**
  676. * @brief Set a timestamp to the PTP timer
  677. *
  678. * @param[in] ptr An Ethernet peripheral base address
  679. * @param[in] timestamp A pointer to a update timestamp structure instance
  680. */
  681. void enet_set_ptp_timestamp(ENET_Type *ptr, enet_ptp_ts_update_t *timestamp);
  682. /**
  683. * @brief Get a timestamp from the PTP timer
  684. *
  685. * @param[in] ptr An Ethernet peripheral base address
  686. * @param[out] timestamp A pointer to a system timestamp structure instance
  687. */
  688. void enet_get_ptp_timestamp(ENET_Type *ptr, enet_ptp_ts_system_t *timestamp);
  689. /**
  690. * @brief Update a timestamp to the PTP timer
  691. *
  692. * @param[in] ptr An Ethernet peripheral base address
  693. * @param[in] timeoffset A pointer to a update timestamp structure instance
  694. */
  695. void enet_update_ptp_timeoffset(ENET_Type *ptr, enet_ptp_ts_update_t *timeoffset);
  696. /**
  697. * @brief Adjust the count frequency of the PTP timer
  698. *
  699. * @param[in] ptr An Ethernet peripheral base address
  700. * @param[in] adj An adjustment value for the count frequency of the PTP timer
  701. */
  702. void enet_adjust_ptp_time_freq(ENET_Type *ptr, int32_t adj);
  703. /**
  704. * @brief Set the PTP version
  705. *
  706. * @param[in] ptr An Ethernet peripheral base address
  707. * @param[in] ptp_ver An enum value indicating the PTP protocol
  708. */
  709. void enet_set_ptp_version(ENET_Type *ptr, enet_ptp_version_t ptp_ver);
  710. /**
  711. * @brief Enable the specified ptp frame type for MAC process
  712. *
  713. * @param[in] ptr An Ethernet peripheral base address
  714. * @param[in] ptp_frame_type An enum value indicating the transport protocol of PTP frames
  715. * @param[in] enable A value to enable or disable the transport protocol of PTP frames which is specified by ptp_frame_type parameter
  716. * @retval hpm_stat_t @ref status_invalid_argument or @ref status_success
  717. */
  718. hpm_stat_t enet_enable_ptp_frame_type(ENET_Type *ptr, enet_ptp_frame_type_t ptp_frame_type, bool enable);
  719. /**
  720. * @brief Set the ptp message type for snapshots
  721. *
  722. * @param[in] ptr An Ethernet peripheral base address
  723. * @param[in] ts_ss_ptp_msg An enum value indicating the specified ptp message type for snapshots
  724. */
  725. void enet_set_snapshot_ptp_message_type(ENET_Type *ptr, enet_ts_ss_ptp_msg_t ts_ss_ptp_msg);
  726. /**
  727. * @brief Set the pps0 control output
  728. *
  729. * @param[in] ptr An Ethernet peripheral base address
  730. * @param[in] freq An enum value indicating the specified pps frequency
  731. */
  732. void enet_set_pps0_control_output(ENET_Type *ptr, enet_pps_ctrl_t freq);
  733. /**
  734. * @brief Set a pps command for ppsx
  735. *
  736. * @param[in] ptr An Ethernet peripheral base address
  737. * @param[in] cmd An enum value indicating the specified pps command
  738. * @param[in] idx An enum value indicating the index of pps instance
  739. * @retval hpm_stat_t @ref status_invalid_argument or @ref status_success
  740. */
  741. hpm_stat_t enet_set_ppsx_command(ENET_Type *ptr, enet_pps_cmd_t cmd, enet_pps_idx_t idx);
  742. /**
  743. * @brief Set a pps config for ppsx
  744. *
  745. * @param[in] ptr An Ethernet peripheral base address
  746. * @param[in] cmd_cfg An enum value indicating the specified pps config
  747. * @param[in] idx An enum value indicating the index of pps instance
  748. * @retval hpm_stat_t @ref status_invalid_argument or @ref status_success
  749. */
  750. hpm_stat_t enet_set_ppsx_config(ENET_Type *ptr, enet_pps_cmd_config_t *cmd_cfg, enet_pps_idx_t idx);
  751. #if defined __cplusplus
  752. }
  753. #endif /* __cplusplus */
  754. /** @} */
  755. #endif /* HPM_ENET_DRV_H */