1 
2 /**
3  * @file xmc_eth_mac.h
4  * @date 2018-08-08
5  *
6  * @cond
7  *********************************************************************************************************************
8  * XMClib v2.1.24 - XMC Peripheral Driver Library
9  *
10  * Copyright (c) 2015-2019, Infineon Technologies AG
11  * All rights reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without modification,are permitted provided that the
14  * following conditions are met:
15  *
16  * Redistributions of source code must retain the above copyright notice, this list of conditions and the following
17  * disclaimer.
18  *
19  * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
20  * disclaimer in the documentation and/or other materials provided with the distribution.
21  *
22  * Neither the name of the copyright holders nor the names of its contributors may be used to endorse or promote
23  * products derived from this software without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
26  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE  FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30  * WHETHER IN CONTRACT, STRICT LIABILITY,OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  *
33  * To improve the quality of the software, users are encouraged to share modifications, enhancements or bug fixes with
34  * Infineon Technologies AG dave@infineon.com).
35  *********************************************************************************************************************
36  *
37  * Change History
38  * --------------
39  *
40  * 2015-06-20:
41  *     - Initial
42  *
43  * 2016-04-25:
44  *     - Change XMC_ETH_MAC_BUF_SIZE to 1524 to allow for Tagged MAC frame format
45  *
46  * 2016-05-19:
47  *      - Added XMC_ETH_MAC_GetTxBuffer() and XMC_ETH_MAC_GetRxBuffer()
48  *      - Added XMC_ETH_MAC_SetTxBufferSize()
49  *
50  * 2016-06-08:
51  *      - Added XMC_ETH_MAC_IsRxDescriptorOwnedByDma()
52  *
53  * 2017-02-25:
54  *      - XMC_ETH_MAC_SetPortControl() fixed compilation warning
55  *
56  * 2017-04-02:
57  *     - Added XMC_ETH_MAC_InitPTPEx()
58  *     - Added XMC_ETH_MAC_SetPTPTime()
59  *     - Added XMC_ETH_MAC_UpdateAddend()
60  *
61  * 2017-04-11:
62  *     - Added XMC_ETH_MAC_EnablePTPAlarm() and XMC_ETH_MAC_DisablePTPAlarm
63  *
64  * 2017-04-17:
65  *     - Fixed ordering of PTP nanoseconds and seconds in XMC_ETH_MAC_DMA_DESC_t
66  *
67  * 2017-08-07:
68  *     - Added XMC_ETH_MAC_TIMESTAMP_STATUS_t
69  *
70  * 2017-09-27:
71  *     - Added XMC_ETH_MAC_InitEx()
72  *     - XMC_ETH_MAC_SetAddressEx(), XMC_ETH_MAC_GetAddressEx() and XMC_ETH_MAC_SetAddressPerfectFilterEx() which receives a byte array with the MAC address instead of uint64_t
73  *
74  * 2018-06-21:
75  *     - Changed definition of XMC_ETH_MAC_DMA_DESC_t declaring its fields volatile
76  *
77  * 2018-08-08:
78  *     - Fixed XMC_ETH_MAC_SetVLANTag() which now accepts a 32bit tag parameter that allows setting ETV bit to compare only VLAN Tag ID
79  *
80  * @endcond
81  */
82 
83 /**
84  * @addtogroup XMClib XMC Peripheral Library
85  * @{
86  */
87 
88 /**
89  * @addtogroup ETH_MAC
90  * @brief Ethernet Low level driver for XMC4000 microcontroller family.
91  *
92  * The Ethernet MAC (ETH) is a major communication peripheral that supports 10/100
93  * MBit/s data transfer rates in compliance with the IEEE 802.3-2002 standard. The ETH
94  * may be used to implement internet connected applications using IPv4 and IPv6. The
95  * ETH also includes support for IEEE1588 time synchronisation to allow implementation
96  * of Real Time Ethernet protocols.
97  *
98  * The XMC_ETH_MAC low level driver provides functions to configure and initialize
99  * the ETH_MAC hardware peripheral.
100  * @{
101  */
102 
103 #ifndef XMC_ETH_MAC_H
104 #define XMC_ETH_MAC_H
105 
106 /**********************************************************************************************************************
107  * HEADER FILES
108  *********************************************************************************************************************/
109 
110 #include "xmc_common.h"
111 
112 #if defined (ETH0)
113 
114 #include "xmc_eth_mac_map.h"
115 
116 /**********************************************************************************************************************
117  * MACROS
118  *********************************************************************************************************************/
119 
120 #define XMC_ETH_MAC_BUF_SIZE           (1524)     /**< ETH MAC buffer size */
121 #define XMC_ETH_MAC_PHY_MAX_RETRIES    (0xffffUL) /**< Maximum retries */
122 #define XMC_ETH_WAKEUP_REGISTER_LENGTH (8U)       /**< Remote wakeup frame reg length */
123 
124 /**
125  * TDES0 Descriptor TX Packet Control/Status
126  */
127 #define ETH_MAC_DMA_TDES0_OWN  (0x80000000U) /**< Own bit 1=DMA, 0=CPU */
128 #define ETH_MAC_DMA_TDES0_IC   (0x40000000U) /**< Interrupt on competition */
129 #define ETH_MAC_DMA_TDES0_LS   (0x20000000U) /**< Last segment */
130 #define ETH_MAC_DMA_TDES0_FS   (0x10000000U) /**< First segment */
131 #define ETH_MAC_DMA_TDES0_DC   (0x08000000U) /**< Disable CRC */
132 #define ETH_MAC_DMA_TDES0_DP   (0x04000000U) /**< Disable pad */
133 #define ETH_MAC_DMA_TDES0_TTSE (0x02000000U) /**< Transmit time stamp enable */
134 #define ETH_MAC_DMA_TDES0_CIC  (0x00C00000U) /**< Checksum insertion control */
135 #define ETH_MAC_DMA_TDES0_TER  (0x00200000U) /**< Transmit end of ring */
136 #define ETH_MAC_DMA_TDES0_TCH  (0x00100000U) /**< Second address chained */
137 #define ETH_MAC_DMA_TDES0_TTSS (0x00020000U) /**< Transmit time stamp status */
138 #define ETH_MAC_DMA_TDES0_IHE  (0x00010000U) /**< IP header error */
139 #define ETH_MAC_DMA_TDES0_ES   (0x00008000U) /**< Error summary */
140 #define ETH_MAC_DMA_TDES0_JT   (0x00004000U) /**< Jabber timeout */
141 #define ETH_MAC_DMA_TDES0_FF   (0x00002000U) /**< Frame flushed */
142 #define ETH_MAC_DMA_TDES0_IPE  (0x00001000U) /**< IP payload error */
143 #define ETH_MAC_DMA_TDES0_LOC  (0x00000800U) /**< Loss of carrier */
144 #define ETH_MAC_DMA_TDES0_NC   (0x00000400U) /**< No carrier */
145 #define ETH_MAC_DMA_TDES0_LC   (0x00000200U) /**< Late collision */
146 #define ETH_MAC_DMA_TDES0_EC   (0x00000100U) /**< Excessive collision */
147 #define ETH_MAC_DMA_TDES0_VF   (0x00000080U) /**< VLAN frame */
148 #define ETH_MAC_DMA_TDES0_CC   (0x00000078U) /**< Collision count */
149 #define ETH_MAC_DMA_TDES0_ED   (0x00000004U) /**< Excessive deferral */
150 #define ETH_MAC_DMA_TDES0_UF   (0x00000002U) /**< Underflow error */
151 #define ETH_MAC_DMA_TDES0_DB   (0x00000001U) /**< Deferred bit */
152 
153 /**
154  * RDES0 Descriptor RX Packet Status
155  */
156 #define ETH_MAC_DMA_RDES0_OWN  (0x80000000U) /**< Own bit 1=DMA, 0=CPU */
157 #define ETH_MAC_DMA_RDES0_AFM  (0x40000000U) /**< Destination address filter fail */
158 #define ETH_MAC_DMA_RDES0_FL   (0x3FFF0000U) /**< Frame length mask */
159 #define ETH_MAC_DMA_RDES0_ES   (0x00008000U) /**< Error summary */
160 #define ETH_MAC_DMA_RDES0_DE   (0x00004000U) /**< Descriptor error */
161 #define ETH_MAC_DMA_RDES0_SAF  (0x00002000U) /**< Source address filter fail */
162 #define ETH_MAC_DMA_RDES0_LE   (0x00001000U) /**< Length error */
163 #define ETH_MAC_DMA_RDES0_OE   (0x00000800U) /**< Overflow error */
164 #define ETH_MAC_DMA_RDES0_VLAN (0x00000400U) /**< VLAN tag */
165 #define ETH_MAC_DMA_RDES0_FS   (0x00000200U) /**< First descriptor */
166 #define ETH_MAC_DMA_RDES0_LS   (0x00000100U) /**< Last descriptor */
167 #define ETH_MAC_DMA_RDES0_TSA  (0x00000080U) /**< Timestamp available */
168 #define ETH_MAC_DMA_RDES0_LC   (0x00000040U) /**< Late collision */
169 #define ETH_MAC_DMA_RDES0_FT   (0x00000020U) /**< Frame type */
170 #define ETH_MAC_DMA_RDES0_RWT  (0x00000010U) /**< Receive watchdog timeout */
171 #define ETH_MAC_DMA_RDES0_RE   (0x00000008U) /**< Receive error */
172 #define ETH_MAC_DMA_RDES0_DBE  (0x00000004U) /**< Dribble bit error */
173 #define ETH_MAC_DMA_RDES0_CE   (0x00000002U) /**< CRC error */
174 #define ETH_MAC_DMA_RDES0_ESA  (0x00000001U) /**< Extended Status/Rx MAC address */
175 
176 /**********************************************************************************************************************
177  * ENUMS
178  *********************************************************************************************************************/
179 
180 /**
181  * Ethernet MAC status return values
182  */
183 typedef enum XMC_ETH_MAC_STATUS
184 {
185   XMC_ETH_MAC_STATUS_OK    = 0U, /**< Driver accepted application request */
186   XMC_ETH_MAC_STATUS_BUSY  = 1U, /**< Driver is busy and cannot handle request */
187   XMC_ETH_MAC_STATUS_ERROR = 2U  /**< Driver could not fulfil application request */
188 } XMC_ETH_MAC_STATUS_t;
189 
190 /**
191  * Transmission frame
192  */
193 typedef enum XMC_ETH_MAC_TX_FRAME
194 {
195   XMC_ETH_MAC_TX_FRAME_FRAGMENT  = 0x1U, /**< Indicate frame fragment */
196   XMC_ETH_MAC_TX_FRAME_EVENT     = 0x2U, /**< Generate event when frame is transmitted */
197   XMC_ETH_MAC_TX_FRAME_TIMESTAMP = 0x4U  /**< Capture frame time stamp */
198 } XMC_ETH_MAC_TX_FRAME_t;
199 
200 /**
201  * ETH MAC event
202  */
203 typedef enum XMC_ETH_MAC_EVENT
204 {
205   XMC_ETH_MAC_EVENT_PMT = ETH_INTERRUPT_MASK_PMTIM_Msk << 16,        /**< Power management event */
206   XMC_ETH_MAC_EVENT_TIMESTAMP = ETH_INTERRUPT_MASK_TSIM_Msk << 16,   /**< Time stamp event */
207   XMC_ETH_MAC_EVENT_EARLY_RECEIVE = ETH_STATUS_ERI_Msk,              /**< Early receive */
208   XMC_ETH_MAC_EVENT_BUS_ERROR = ETH_STATUS_FBI_Msk,                  /**< Bus error */
209   XMC_ETH_MAC_EVENT_EARLY_TRANSMIT = ETH_STATUS_ETI_Msk,             /**< Early transmit */
210   XMC_ETH_MAC_EVENT_RECEIVE_WATCHDOG_TIMEOUT = ETH_STATUS_RWT_Msk,   /**< Receive watchdog time-out */
211   XMC_ETH_MAC_EVENT_RECEIVE_PROCESS_STOPPED = ETH_STATUS_RPS_Msk,    /**< Receive process stopped */
212   XMC_ETH_MAC_EVENT_RECEIVE_BUFFER_UNAVAILABLE = ETH_STATUS_RU_Msk,  /**< Receive buffer unavailable */
213   XMC_ETH_MAC_EVENT_RECEIVE = ETH_STATUS_RI_Msk,                     /**< Receive event */
214   XMC_ETH_MAC_EVENT_TRANSMIT_UNDERFLOW = ETH_STATUS_UNF_Msk,         /**< Transmit underflow */
215   XMC_ETH_MAC_EVENT_RECEIVE_OVERFLOW = ETH_STATUS_OVF_Msk,           /**< Receive overflow */
216   XMC_ETH_MAC_EVENT_TRANSMIT_JABBER_TIMEOUT = ETH_STATUS_TJT_Msk,    /**< Transmit jabber time-out */
217   XMC_ETH_MAC_EVENT_TRANSMIT_BUFFER_UNAVAILABLE = ETH_STATUS_TU_Msk, /**< Transmit buffer unavailable */
218   XMC_ETH_MAC_EVENT_TRANSMIT_PROCESS_STOPPED = ETH_STATUS_TPS_Msk,   /**< Transmit process stopped */
219   XMC_ETH_MAC_EVENT_TRANSMIT = ETH_STATUS_TI_Msk                     /**< Transmit event */
220 } XMC_ETH_MAC_EVENT_t;
221 
222 /**
223  * Link interface
224  */
225 typedef enum XMC_ETH_LINK_INTERFACE
226 {
227   XMC_ETH_LINK_INTERFACE_MII, /**< Link interface: Media independent interface */
228   XMC_ETH_LINK_INTERFACE_RMII /**< Link interface: Reduced media independent interface */
229 } XMC_ETH_LINK_INTERFACE_t;
230 
231 /**
232  * ETH link status
233  */
234 typedef enum XMC_ETH_LINK_STATUS
235 {
236   XMC_ETH_LINK_STATUS_DOWN, /**< Link status down */
237   XMC_ETH_LINK_STATUS_UP    /**< Link status up */
238 } XMC_ETH_LINK_STATUS_t;
239 
240 /**
241  * ETH link speed
242  */
243 typedef enum XMC_ETH_LINK_SPEED
244 {
245   XMC_ETH_LINK_SPEED_10M  = 0UL << ETH_MAC_CONFIGURATION_FES_Pos, /**< Link speed: 10M */
246   XMC_ETH_LINK_SPEED_100M = 1UL << ETH_MAC_CONFIGURATION_FES_Pos  /**< Link speed: 100M */
247 } XMC_ETH_LINK_SPEED_t;
248 
249 /**
250  * ETH duplex settings (full/half?)
251  */
252 typedef enum XMC_ETH_LINK_DUPLEX
253 {
254   XMC_ETH_LINK_DUPLEX_HALF = 0UL << ETH_MAC_CONFIGURATION_DM_Pos, /**< Half duplex */
255   XMC_ETH_LINK_DUPLEX_FULL = 1UL << ETH_MAC_CONFIGURATION_DM_Pos  /**< Full duplex */
256 } XMC_ETH_LINK_DUPLEX_t;
257 
258 /**
259  * MAC address filter
260  */
261 typedef enum XMC_ETH_MAC_ADDR_FILTER
262 {
263   XMC_ETH_MAC_ADDR_FILTER_MASK_BYTE0 = 0x01000000UL, /**< Address filter mask: byte 0 */
264   XMC_ETH_MAC_ADDR_FILTER_MASK_BYTE1 = 0x02000000UL, /**< Address filter mask: byte 1 */
265   XMC_ETH_MAC_ADDR_FILTER_MASK_BYTE2 = 0x04000000UL, /**< Address filter mask: byte 2 */
266   XMC_ETH_MAC_ADDR_FILTER_MASK_BYTE3 = 0x08000000UL, /**< Address filter mask: byte 3 */
267   XMC_ETH_MAC_ADDR_FILTER_MASK_BYTE4 = 0x10000000UL, /**< Address filter mask: byte 4 */
268   XMC_ETH_MAC_ADDR_FILTER_MASK_BYTE5 = 0x20000000UL, /**< Address filter mask: byte 5 */
269   XMC_ETH_MAC_ADDR_FILTER_SA         = 0x40000000UL  /**< Address filter SA */
270 } XMC_ETH_MAC_ADDR_FILTER_t;
271 
272 /**
273  * Power management events that triggers a PMT interrupt
274  */
275 typedef enum XMC_ETH_MAC_PMT_EVENT
276 {
277   XMC_ETH_MAC_PMT_EVENT_ON_WAKEUP_FRAME         = ETH_PMT_CONTROL_STATUS_RWKPKTEN_Msk,  /**< Wakeup frame */
278   XMC_ETH_MAC_PMT_EVENT_ON_MAGIC_PACKET         = ETH_PMT_CONTROL_STATUS_MGKPKTEN_Msk,  /**< Magic packet */
279   XMC_ETH_MAC_PMT_EVENT_ON_UNICAST_FRAME_FILTER = ETH_PMT_CONTROL_STATUS_GLBLUCAST_Msk  /**< Unicast frame filter */
280 } XMC_ETH_MAC_PMT_EVENT_t;
281 
282 
283 /**
284  * ETH MAC time-stamp configuration enable
285  */
286 typedef enum XMC_ETH_MAC_TIMESTAMP_CONFIG
287 {
288   XMC_ETH_MAC_TIMESTAMP_CONFIG_FINE_UPDATE = ETH_TIMESTAMP_CONTROL_TSCFUPDT_Msk,             /**< Fine update */
289   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_TS_INTERRUPT = ETH_TIMESTAMP_CONTROL_TSTRIG_Msk,       /**< Timestamp Interrupt Trigger Enable */
290   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_ALL_FRAMES = ETH_TIMESTAMP_CONTROL_TSENALL_Msk,        /**< Enable all frames */
291   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_PTPV2 = ETH_TIMESTAMP_CONTROL_TSVER2ENA_Msk,           /**< PTPV2 */
292   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_PTP_OVER_ETHERNET = ETH_TIMESTAMP_CONTROL_TSIPENA_Msk, /**< PTP over ETH */
293   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_PTP_OVER_IPV6 = ETH_TIMESTAMP_CONTROL_TSIPV6ENA_Msk,   /**< PTP over IPV6 */
294   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_PTP_OVER_IPV4 = ETH_TIMESTAMP_CONTROL_TSIPV4ENA_Msk,   /**< PTP over IPV4 */
295   XMC_ETH_MAC_TIMESTAMP_CONFIG_ENABLE_MAC_ADDRESS_FILTER = ETH_TIMESTAMP_CONTROL_TSENMACADDR_Msk /**< MAC address filter */
296 } XMC_ETH_MAC_TIMESTAMP_CONFIG_t;
297 
298 /**
299  * ETH MAC time-stamp status
300  */
301 typedef enum XMC_ETH_MAC_TIMESTAMP_STATUS
302 {
303   XMC_ETH_MAC_TIMESTAMP_STATUS_SECONDS_OVERFLOW = ETH_TIMESTAMP_STATUS_TSSOVF_Msk,           /**< Indicates that the seconds value of the timestamp has overflowed beyond 0xFFFFFFFF */
304   XMC_ETH_MAC_TIMESTAMP_STATUS_TARGET_TIME_REACHED = ETH_TIMESTAMP_STATUS_TSTARGT_Msk,       /**< Indicates that the value of system time is greater or equal to the value specified in the Target_Time_ Seconds Register and Target Time Nanoseconds Register */
305   XMC_ETH_MAC_TIMESTAMP_STATUS_TARGET_TIMER_ERROR = ETH_TIMESTAMP_STATUS_TSTRGTERR_Msk,      /**< Set when the target time, being programmed in Target Time Registers, is already elapsed */
306 } XMC_ETH_MAC_TIMESTAMP_STATUS_t;
307 
308 
309 /**********************************************************************************************************************
310  * DATA STRUCTURES
311  *********************************************************************************************************************/
312 
313 /* Anonymous structure/union guard start */
314 #if defined (__CC_ARM)
315 #pragma push
316 #pragma anon_unions
317 #elif defined (__TASKING__)
318 #pragma warning 586
319 #endif
320 
321 /**
322  * ETH MAC port control
323  */
324 typedef union XMC_ETH_MAC_PORT_CTRL
325 {
326   struct
327   {
328     uint32_t rxd0: 2;     /**< Receive data bit 0 (::XMC_ETH_MAC_PORT_CTRL_RXD0_t) */
329     uint32_t rxd1: 2;     /**< Receive data bit 1 (::XMC_ETH_MAC_PORT_CTRL_RXD1_t) */
330     uint32_t rxd2: 2;     /**< Receive data bit 2 (only MII) (::XMC_ETH_MAC_PORT_CTRL_RXD2_t) */
331     uint32_t rxd3: 2;     /**< Receive data bit 3 (only MII) (::XMC_ETH_MAC_PORT_CTRL_RXD3_t) */
332     uint32_t clk_rmii: 2; /**< RMII: Continuous 50 MHz reference clock.
333                                MII: Receive clock, 25 MHz for 100Mbit/s, 2.5 MHz for 10Mbit/s
334                                (::XMC_ETH_MAC_PORT_CTRL_CLK_RMII_t) */
335     uint32_t crs_dv: 2;   /**< RMII: carrier sense/RX_Data valid. MII: RX_Data valid (::XMC_ETH_MAC_PORT_CTRL_CRS_DV_t) */
336     uint32_t crs: 2;      /**< Carrier sense for only MII (::XMC_ETH_MAC_PORT_CTRL_CRS_t) */
337     uint32_t rxer: 2;     /**< Receive error (::XMC_ETH_MAC_PORT_CTRL_RXER_t) */
338     uint32_t col: 2;      /**< Collision Detect for only MII (::XMC_ETH_MAC_PORT_CTRL_COL_t) */
339     uint32_t clk_tx: 2;   /**< Transmit clock (only MII), 25 MHz for 100Mbit/s, 2.5 MHz for 10Mbit/s (::XMC_ETH_MAC_PORT_CTRL_CLK_TX_t) */
340     uint32_t: 2;          /**< Reserved bits */
341     uint32_t mdio: 2;     /**< Bidirectional, push-pull management data I/O line (::XMC_ETH_MAC_PORT_CTRL_MDIO_t) */
342     uint32_t: 2;          /**< Reserved bits */
343     uint32_t mode: 1;     /**< RMII or MII (::XMC_ETH_MAC_PORT_CTRL_MODE_t) */
344   };
345 
346   uint32_t raw;
347 } XMC_ETH_MAC_PORT_CTRL_t;
348 
349 /**
350  * ETH MAC DMA descriptor
351  */
352 typedef struct XMC_ETH_MAC_DMA_DESC
353 {
354   volatile uint32_t status;                 /**< DMA descriptor status */
355   volatile uint32_t length;                 /**< Descriptor length */
356   volatile uint32_t buffer1;                /**< Buffer 1 */
357   volatile uint32_t buffer2;                /**< Buffer 2 */
358   volatile uint32_t extended_status;        /**< Extended status */
359   volatile uint32_t reserved;               /**< Reserved */
360   volatile uint32_t time_stamp_nanoseconds; /**< Time stamp low */
361   volatile uint32_t time_stamp_seconds;     /**< Time stamp high */
362 } XMC_ETH_MAC_DMA_DESC_t;
363 
364 /**
365  * ETH MAC time
366  */
367 typedef struct XMC_ETH_MAC_TIME
368 {
369   uint32_t seconds;                 /**< Seconds */
370   int32_t nanoseconds;              /**< Nanoseconds */
371 } XMC_ETH_MAC_TIME_t;
372 
373 /**
374  * ETH driver structure
375  */
376 typedef struct XMC_ETH_MAC
377 {
378   ETH_GLOBAL_TypeDef *regs;        /**< ETH module 0 (now, we have a single ETH module) */
379   uint64_t address;              /**< MAC address */
380   XMC_ETH_MAC_DMA_DESC_t *rx_desc; /**< DMA descriptor: RX */
381   XMC_ETH_MAC_DMA_DESC_t *tx_desc; /**< DMA descriptor: TX */
382   uint8_t *rx_buf;                /**< RX buffer */
383   uint8_t *tx_buf;                /**< TX buffer */
384   uint8_t *frame_end;              /**< End of assembled frame fragments */
385   uint8_t num_rx_buf;              /**< How many RX descriptors? */
386   uint8_t num_tx_buf;              /**< How many TX descriptors? */
387   uint8_t tx_index;                /**< Transmit descriptor index */
388   uint8_t rx_index;                /**< Receive descriptor index */
389   uint8_t tx_ts_index;             /**< Transmit time-stamp descriptor index */
390 } XMC_ETH_MAC_t;
391 
392 /* Anonymous structure/union guard end */
393 #if defined (__CC_ARM)
394 #pragma pop
395 #elif defined (__TASKING__)
396 #pragma warning restore
397 #endif
398 
399 /**********************************************************************************************************************
400  * API PROTOTYPES
401  *********************************************************************************************************************/
402 
403 #ifdef __cplusplus
404 extern "C" {
405 #endif
406 
407 /**
408  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
409  * @return XMC_ETH_MAC_STATUS_t Initialization status
410  *
411  * \par<b>Description: </b><br>
412  * Initialize the Ethernet MAC peripheral <br>
413  *
414  * \par
415  * The function sets the link speed, applies the duplex mode, sets auto-negotiation
416  * and loop-back settings.
417  */
418 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_Init(XMC_ETH_MAC_t *const eth_mac);
419 
420 /**
421  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
422  * @return None
423  *
424  * \par<b>Description: </b><br>
425  * Initialize the Ethernet MAC peripheral. <br>
426  * Required when initializing the PHY, to deliver the clocks to the MAC, before MAC is reseted.
427  * \note The module needs to be enabled before using XMC_ETH_MAC_Enable() <br>
428  *
429  * \par
430  * The function sets the link speed, applies the duplex mode, sets auto-negotiation
431  * and loop-back settings.
432  */
433 void XMC_ETH_MAC_InitEx(XMC_ETH_MAC_t *const eth_mac);
434 
435 /**
436  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
437  * @return None
438  *
439  * \par<b>Description: </b><br>
440  * Initialize the RX DMA descriptors <br>
441  *
442  * \par
443  * The function initializes the RX descriptors in a chained configuration. It sets
444  * up the status bit, control bit, buffer length and the buffer pointer.
445  */
446 void XMC_ETH_MAC_InitRxDescriptors(XMC_ETH_MAC_t *const eth_mac);
447 
448 /**
449  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
450  * @return None
451  *
452  * \par<b>Description: </b><br>
453  * Initialize the TX DMA descriptors <br>
454  *
455  * \par
456  * The function initializes the TX descriptors in a chained configuration. It sets
457  * up the status bit, control bit, buffer length and the buffer pointer.
458  */
459 void XMC_ETH_MAC_InitTxDescriptors(XMC_ETH_MAC_t *const eth_mac);
460 
461 /**
462  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
463  * @return None
464  *
465  * \par<b>Description: </b><br>
466  * Enable the Ethernet MAC peripheral <br>
467  *
468  * \par
469  * The function de-asserts the peripheral reset.
470  */
471 void XMC_ETH_MAC_Enable(XMC_ETH_MAC_t *const eth_mac);
472 
473 /**
474  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
475  * @return None
476  *
477  * \par<b>Description: </b><br>
478  * Disable the Ethernet MAC peripheral <br>
479  *
480  * \par
481  * The function asserts the peripheral reset.
482  */
483 void XMC_ETH_MAC_Disable(XMC_ETH_MAC_t *const eth_mac);
484 
485 /**
486  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
487  * @return bool
488  *
489  * \par<b>Description: </b><br>
490  * Check if the ETH MAC is enabled <br>
491  *
492  * \par
493  * The function checks if the ETH MAC is enabled or not. It returns "true" if the
494  * peripheral is enabled, "false" otherwise.
495  */
496 bool XMC_ETH_MAC_IsEnabled(const XMC_ETH_MAC_t *const eth_mac);
497 
498 /**
499  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
500  * @return None
501  *
502  * \par<b>Description: </b><br>
503  * Reset the ETH MAC peripheral <br>
504  *
505  * \par
506  * The function resets the ETH MAC peripheral. It blocks until reset.
507  */
XMC_ETH_MAC_Reset(XMC_ETH_MAC_t * const eth_mac)508 __STATIC_INLINE void XMC_ETH_MAC_Reset(XMC_ETH_MAC_t *const eth_mac)
509 {
510   eth_mac->regs->BUS_MODE |= (uint32_t)ETH_BUS_MODE_SWR_Msk;
511   while ((eth_mac->regs->BUS_MODE & (uint32_t)ETH_BUS_MODE_SWR_Msk) != 0U)
512   {
513   }
514 }
515 
516 /**
517  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
518  * @param phy_addr PHY address
519  * @param reg_addr Register address
520  * @param data The destination to which the read data needs to be copied to
521  * @return XMC_ETH_MAC_STATUS_t ETH MAC status
522  *
523  * \par<b>Description: </b><br>
524  * Read a PHY register <br>
525  *
526  * \par
527  * The function reads a PHY register. It essentially polls busy bit during max
528  * PHY_TIMEOUT time and reads the information into 'data' when not busy.
529  */
530 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_ReadPhy(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr, uint8_t reg_addr, uint16_t *data);
531 
532 /**
533  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
534  * @param phy_addr PHY address
535  * @param reg_addr Register address
536  * @param data The data to write
537  * @return XMC_ETH_MAC_STATUS_t ETH MAC status
538  *
539  * \par<b>Description: </b><br>
540  * Write a PHY register <br>
541  *
542  * \par
543  * The function reads a PHY register. It essentially writes the data and polls
544  * the busy bit until it is no longer busy.
545  */
546 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_WritePhy(XMC_ETH_MAC_t *const eth_mac, uint8_t phy_addr, uint8_t reg_addr, uint16_t data);
547 
548 /**
549  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
550  * @param port_ctrl Port control configuration
551  * @return None
552  *
553  * \par<b>Description: </b><br>
554  * Set port control configuration <br>
555  *
556  * \par
557  * The function sets the port control by writing the configuration into the
558  * CON register.
559  *
560  * \note
561  * MII Mode is only available in:
562  * - XMC4500 LQFP144 and BGA144 packages
563  * - XMC4700 LQFP144 and BGA196 packages
564  * - XMC4800 LQFP144 and BGA196 packages
565  *
566  */
XMC_ETH_MAC_SetPortControl(XMC_ETH_MAC_t * const eth_mac,const XMC_ETH_MAC_PORT_CTRL_t port_ctrl)567 __STATIC_INLINE void XMC_ETH_MAC_SetPortControl(XMC_ETH_MAC_t *const eth_mac, const XMC_ETH_MAC_PORT_CTRL_t port_ctrl)
568 {
569   XMC_UNUSED_ARG(eth_mac);
570   ETH0_CON->CON = (uint32_t)port_ctrl.raw;
571 }
572 
573 /**
574  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
575  * @return XMC_ETH_MAC_STATUS_t ETH MAC status
576  *
577  * \par<b>Description: </b><br>
578  * Set management clock divider <br>
579  *
580  * \par
581  * The function sets the management clock divider by writing to the GMII_ADDRESS
582  * register.
583  */
584 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_SetManagmentClockDivider(XMC_ETH_MAC_t *const eth_mac);
585 
586 /**
587  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
588  * @param addr The MAC address to set
589  * @return None
590  *
591  * \par<b>Description: </b><br>
592  * Set MAC address <br>
593  *
594  * \par
595  * The function sets the MAC address by writing to the MAC_ADDRESS0_HIGH and
596  * MAC_ADDRESS0_LOW registers.
597  */
XMC_ETH_MAC_SetAddress(XMC_ETH_MAC_t * const eth_mac,uint64_t addr)598 __STATIC_INLINE void XMC_ETH_MAC_SetAddress(XMC_ETH_MAC_t *const eth_mac, uint64_t addr)
599 {
600   eth_mac->regs->MAC_ADDRESS0_HIGH = (uint32_t)(addr >> 32);
601   eth_mac->regs->MAC_ADDRESS0_LOW = (uint32_t)addr;
602 }
603 
604 /**
605  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
606  * @param addr Pointer to 6 byte MAC address
607  * @return None
608  *
609  * \par<b>Description: </b><br>
610  * Set MAC address <br>
611  *
612  * \par
613  * The function sets the MAC address by writing to the MAC_ADDRESS0_HIGH and
614  * MAC_ADDRESS0_LOW registers.
615  */
616 void XMC_ETH_MAC_SetAddressEx(XMC_ETH_MAC_t *const eth_mac, uint8_t *const addr);
617 
618 /**
619  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
620  * @return uint64_t The MAC address which has been set
621  *
622  * \par<b>Description: </b><br>
623  * Get MAC address <br>
624  *
625  * \par
626  * The function returns the current ETH MAC address.
627  */
XMC_ETH_MAC_GetAddress(XMC_ETH_MAC_t * const eth_mac)628 __STATIC_INLINE uint64_t XMC_ETH_MAC_GetAddress(XMC_ETH_MAC_t *const eth_mac)
629 {
630   return ((((uint64_t)eth_mac->regs->MAC_ADDRESS0_HIGH << 32)) | (uint64_t)eth_mac->regs->MAC_ADDRESS0_LOW);
631 }
632 
633 /**
634  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
635  * @return uint64_t The MAC address which has been set
636  *
637  * \par<b>Description: </b><br>
638  * Get MAC address <br>
639  *
640  * \par
641  * The function returns the current ETH MAC address.
642  */
643 void XMC_ETH_MAC_GetAddressEx(XMC_ETH_MAC_t *const eth_mac, uint8_t *const addr);
644 
645 /**
646  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
647  * @param index Table entry index
648  * @param addr Address value
649  * @param flags Compare control. OR'ed combination of @ref XMC_ETH_MAC_ADDR_FILTER_t or zero.
650  *
651  * @return None
652  *
653  * \par<b>Description: </b><br>
654  * Set perfect filter for address filtering <br>
655  *
656  * \par
657  * The function can be used to set perfect filter for address filtering.
658  */
659 void XMC_ETH_MAC_SetAddressPerfectFilter(XMC_ETH_MAC_t *const eth_mac, uint8_t index, const uint64_t addr, uint32_t flags);
660 
661 /**
662  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
663  * @param index Table entry index
664  * @param addr Pointer to 6 byte MAC address
665  * @param flags Compare control. OR'ed combination of @ref XMC_ETH_MAC_ADDR_FILTER_t or zero.
666  *
667  * @return None
668  *
669  * \par<b>Description: </b><br>
670  * Set perfect filter for address filtering <br>
671  *
672  * \par
673  * The function can be used to set perfect filter for address filtering.
674  */
675 void XMC_ETH_MAC_SetAddressPerfectFilterEx(XMC_ETH_MAC_t *const eth_mac, uint8_t index, uint8_t *const addr, uint32_t flags);
676 
677 /**
678  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
679  * @param hash The hash to be used for filtering
680  * @return None
681  *
682  * \par<b>Description: </b><br>
683  * Set hash filter for group address filtering <br>
684  *
685  * \par
686  * The function sets up a hash filter for group address filtering. It writes the
687  * given hash value into the HASH_TABLE_LOW and HASH_TABLE_HIGH registers.
688  */
689 void XMC_ETH_MAC_SetAddressHashFilter(XMC_ETH_MAC_t *const eth_mac, const uint64_t hash);
690 
691 /**
692  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
693  * @return None
694  *
695  * \par<b>Description: </b><br>
696  * Enable frame filter <br>
697  *
698  * \par
699  * The function resets the RA bitfield of the MAC_FRAME_FILTER register. This
700  * ensures that the receiver module passes only those frames (to the application)
701  * that pass the SA or DA address filter.
702  */
XMC_ETH_MAC_EnableFrameFilter(XMC_ETH_MAC_t * const eth_mac)703 __STATIC_INLINE void XMC_ETH_MAC_EnableFrameFilter(XMC_ETH_MAC_t *const eth_mac)
704 {
705   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_RA_Msk;
706 }
707 
708 /**
709  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
710  * @return None
711  *
712  * \par<b>Description: </b><br>
713  * Disable frame filter <br>
714  *
715  * \par
716  * The function sets the RA bitfield of the MAC_FRAME_FILTER register. This
717  * ensures that the receiver module passes all received frames, irrespective
718  * of whether they pass the address filter or not.
719  */
XMC_ETH_MAC_DisableFrameFilter(XMC_ETH_MAC_t * const eth_mac)720 __STATIC_INLINE void XMC_ETH_MAC_DisableFrameFilter(XMC_ETH_MAC_t *const eth_mac)
721 {
722   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_RA_Msk;
723 }
724 
725 /**
726  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
727  * @return None
728  *
729  * \par<b>Description: </b><br>
730  * Enable hash perfect filter <br>
731  *
732  * \par
733  * The function sets the HPF bitfield of the MAC_FRAME_FILTER register. The
734  * function configures the address filter to pass a frame if it matches
735  * either the perfect filtering or the hash filtering.
736  */
XMC_ETH_MAC_EnableHashPerfectFilter(XMC_ETH_MAC_t * const eth_mac)737 __STATIC_INLINE void XMC_ETH_MAC_EnableHashPerfectFilter(XMC_ETH_MAC_t *const eth_mac)
738 {
739   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_HPF_Msk;
740 }
741 
742 /**
743  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
744  * @return None
745  *
746  * \par<b>Description: </b><br>
747  * Enable perfect filter <br>
748  *
749  * \par
750  * The function clears the HPF bitfield of the MAC_FRAME_FILTER register. When the
751  * function is invoked, the frame is passed only if it matches the hash filter.
752  */
XMC_ETH_MAC_EnablePerfectFilter(XMC_ETH_MAC_t * const eth_mac)753 __STATIC_INLINE void XMC_ETH_MAC_EnablePerfectFilter(XMC_ETH_MAC_t *const eth_mac)
754 {
755   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_HPF_Msk;
756 }
757 
758 /**
759  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
760  * @return None
761  *
762  * \par<b>Description: </b><br>
763  * Enable source address filter <br>
764  *
765  * \par
766  * The function sets the SAF bitfield of the MAC_FRAME_FILTER register. Verbatim
767  * from the reference manual - "When invoked, the MAC compares the SA field of the
768  * received frames with the values programmed in the enabled SA registers. If the
769  * comparison matches, then the SA Match bit of RxStatus Word is set high. When
770  * this bit is set high and the SA filter fails, the MAC drops the frame.
771  */
XMC_ETH_MAC_EnableSourceAddressFilter(XMC_ETH_MAC_t * const eth_mac)772 __STATIC_INLINE void XMC_ETH_MAC_EnableSourceAddressFilter(XMC_ETH_MAC_t *const eth_mac)
773 {
774   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_SAF_Msk;
775 }
776 
777 /**
778  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
779  * @return None
780  *
781  * \par<b>Description: </b><br>
782  * Disable source address filter <br>
783  *
784  * \par
785  * The function resets the SAF bitfield of the MAC_FRAME_FILTER register. Verbatim
786  * from the reference manual - "When invoked, the MAC forwards the received frame to
787  * the application and updates the SA Match bit of the RxStatus depending on
788  * the SA address comparison".
789  */
XMC_ETH_MAC_DisableSourceAddressFilter(XMC_ETH_MAC_t * const eth_mac)790 __STATIC_INLINE void XMC_ETH_MAC_DisableSourceAddressFilter(XMC_ETH_MAC_t *const eth_mac)
791 {
792   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_SAF_Msk;
793 }
794 
795 /**
796  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
797  * @return None
798  *
799  * \par<b>Description: </b><br>
800  * Enable source address inverse filtering <br>
801  *
802  * \par
803  * The function resets the SAIF bitfield of the MAC_FRAME_FILTER register. Verbatim
804  * from the reference manual - "When invoked, the address check block operates in
805  * inverse filtering mode for the SA address comparison. The frames whose SA matches
806  * the SA registers are marked as failing the SA Address filter".
807  */
XMC_ETH_MAC_EnableSourceAddressInverseFilter(XMC_ETH_MAC_t * const eth_mac)808 __STATIC_INLINE void XMC_ETH_MAC_EnableSourceAddressInverseFilter(XMC_ETH_MAC_t *const eth_mac)
809 {
810   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_SAIF_Msk;
811 }
812 
813 /**
814  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
815  * @return None
816  *
817  * \par<b>Description: </b><br>
818  * Disable source address inverse filtering <br>
819  *
820  * \par
821  * The function resets the SAIF bitfield of the MAC_FRAME_FILTER register. Verbatim
822  * from the reference manual - "When invoked, frames whose SA does not match the SA
823  * registers are marked as failing the SA Address filter".
824  */
XMC_ETH_MAC_DisableSourceAddressInverseFilter(XMC_ETH_MAC_t * const eth_mac)825 __STATIC_INLINE void XMC_ETH_MAC_DisableSourceAddressInverseFilter(XMC_ETH_MAC_t *const eth_mac)
826 {
827   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_SAIF_Msk;
828 }
829 
830 /**
831  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
832  * @return None
833  *
834  * \par<b>Description: </b><br>
835  * Enable destination address inverse filtering <br>
836  *
837  * \par
838  * The function sets the DAIF bitfield of the MAC_FRAME_FILTER register. Verbatim
839  * from the reference manual - "When invoked, the address check block operates in
840  * inverse filtering mode for the DA address comparison for both unicast and
841  * multicast frames".
842  */
XMC_ETH_MAC_EnableDestinationAddressInverseFilter(XMC_ETH_MAC_t * const eth_mac)843 __STATIC_INLINE void XMC_ETH_MAC_EnableDestinationAddressInverseFilter(XMC_ETH_MAC_t *const eth_mac)
844 {
845   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_DAIF_Msk;
846 }
847 
848 /**
849  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
850  * @return None
851  *
852  * \par<b>Description: </b><br>
853  * Disable destination address inverse filtering <br>
854  *
855  * \par
856  * The function sets the DAIF bitfield of the MAC_FRAME_FILTER register. It can
857  * be used to perform normal filtering of frames.
858  */
XMC_ETH_MAC_DisableDestinationAddressInverseFilter(XMC_ETH_MAC_t * const eth_mac)859 __STATIC_INLINE void XMC_ETH_MAC_DisableDestinationAddressInverseFilter(XMC_ETH_MAC_t *const eth_mac)
860 {
861   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_DAIF_Msk;
862 }
863 
864 /**
865  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
866  * @return None
867  *
868  * \par<b>Description: </b><br>
869  * Enable multicast hash filter <br>
870  *
871  * \par
872  * When invoked, the MAC performs destination address filtering of received
873  * multicast frames according to the hash table.
874  */
XMC_ETH_MAC_EnableMulticastHashFilter(XMC_ETH_MAC_t * const eth_mac)875 __STATIC_INLINE void XMC_ETH_MAC_EnableMulticastHashFilter(XMC_ETH_MAC_t *const eth_mac)
876 {
877   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_HMC_Msk;
878 }
879 
880 /**
881  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
882  * @return None
883  *
884  * \par<b>Description: </b><br>
885  * Disable multicast hash filter <br>
886  *
887  * \par
888  * The function disables multicast hash filtering. The MAC performs a perfect
889  * destination address filtering for multicast frames post invocation.
890  */
XMC_ETH_MAC_DisableMulticastHashFilter(XMC_ETH_MAC_t * const eth_mac)891 __STATIC_INLINE void XMC_ETH_MAC_DisableMulticastHashFilter(XMC_ETH_MAC_t *const eth_mac)
892 {
893   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_HMC_Msk;
894 }
895 
896 /**
897  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
898  * @return None
899  *
900  * \par<b>Description: </b><br>
901  * Enable unicast hash filter <br>
902  *
903  * \par
904  * The function enables the MAC to perform destination address filtering of
905  * unicast frames according to the hash table.
906  */
XMC_ETH_MAC_EnableUnicastHashFilter(XMC_ETH_MAC_t * const eth_mac)907 __STATIC_INLINE void XMC_ETH_MAC_EnableUnicastHashFilter(XMC_ETH_MAC_t *const eth_mac)
908 {
909   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_HUC_Msk;
910 }
911 
912 /**
913  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
914  * @return None
915  *
916  * \par<b>Description: </b><br>
917  * Disable unicast hash filter <br>
918  *
919  * \par
920  * The function disables unicast hash filtering. When invoked, the MAC performs a
921  * perfect destination address filtering for unicast frames.
922  */
XMC_ETH_MAC_DisableUnicastHashFilter(XMC_ETH_MAC_t * const eth_mac)923 __STATIC_INLINE void XMC_ETH_MAC_DisableUnicastHashFilter(XMC_ETH_MAC_t *const eth_mac)
924 {
925   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_HUC_Msk;
926 }
927 
928 /**
929  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
930  * @param frame A pointer to a uint8_t constant, holding the frame to be transmitted
931  * @param len Length of the frame to transmit
932  * @param flags Additional flags: ored combination of ::XMC_ETH_MAC_TX_FRAME_t or zero.
933  * @return XMC_ETH_MAC_STATUS_t ETH MAC status (XMC_ETH_MAC_STATUS_BUSY if busy,
934  *         XMC_ETH_MAC_STATUS_OK otherwise).
935  *
936  * \par<b>Description: </b><br>
937  * Send a frame <br>
938  *
939  * \par
940  * The function is used to send a frame. The transmission is done using
941  * the ETH MAC's dedicated DMA unit.
942  */
943 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_SendFrame(XMC_ETH_MAC_t *const eth_mac,
944                                            const uint8_t *frame,
945                                            uint32_t len,
946                                            uint32_t flags);
947 
948 /**
949  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
950  * @param frame A constant pointer to a uint8_t constant, holding the received frame
951  * @param len Frame length?
952  * @return uint32_t Length of the frame
953  *
954  * \par<b>Description: </b><br>
955  * Read a frame <br>
956  *
957  * \par
958  * The function is used to read a frame. The function returns 'len', the length
959  * as specified as the actual parameter in the function call.
960  */
961 uint32_t XMC_ETH_MAC_ReadFrame(XMC_ETH_MAC_t *const eth_mac, uint8_t *const frame, uint32_t len);
962 
963 /**
964  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
965  * @return uint32_t RX frame size
966  *
967  * \par<b>Description: </b><br>
968  * Get RX frame size <br>
969  *
970  * \par
971  * The function is used to get the effective length of the RX frame size.
972  */
973 uint32_t XMC_ETH_MAC_GetRxFrameSize(XMC_ETH_MAC_t *const eth_mac);
974 
975 /**
976  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
977  * @return None
978  *
979  * \par<b>Description: </b><br>
980  * Enable reception of broadcast frames <br>
981  *
982  * \par
983  * This function enables the AFM module to pass all received broadcast frames.
984  */
XMC_ETH_MAC_EnableReceptionBroadcastFrames(XMC_ETH_MAC_t * const eth_mac)985 __STATIC_INLINE void XMC_ETH_MAC_EnableReceptionBroadcastFrames(XMC_ETH_MAC_t *const eth_mac)
986 {
987   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_DBF_Msk;
988 }
989 
990 /**
991  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
992  * @return None
993  *
994  * \par<b>Description: </b><br>
995  * Disable reception of broadcast frames <br>
996  *
997  * \par
998  * The function sets the DBF bitfield of the MAC_FRAME_FILTER register. When set,
999  * the AFM module filters all incoming broadcast frames. In addition, it overrides
1000  * all other filter settings.
1001  */
XMC_ETH_MAC_DisableReceptionBroadcastFrames(XMC_ETH_MAC_t * const eth_mac)1002 __STATIC_INLINE void XMC_ETH_MAC_DisableReceptionBroadcastFrames(XMC_ETH_MAC_t *const eth_mac)
1003 {
1004   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_DBF_Msk;
1005 }
1006 
1007 /**
1008  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1009  * @return None
1010  *
1011  * \par<b>Description: </b><br>
1012  * Enable reception of multicast frames <br>
1013  *
1014  * \par
1015  * The function sets the DBF bitfield of the MAC_FRAME_FILTER register. When set,
1016  * the AFM module filters all incoming broadcast frames. In addition, it overrides
1017  * all other filter settings.
1018  */
XMC_ETH_MAC_EnableReceptionMulticastFrames(XMC_ETH_MAC_t * const eth_mac)1019 __STATIC_INLINE void XMC_ETH_MAC_EnableReceptionMulticastFrames(XMC_ETH_MAC_t *const eth_mac)
1020 {
1021   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_PM_Msk;
1022 }
1023 
1024 /**
1025  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1026  * @return None
1027  *
1028  * \par<b>Description: </b><br>
1029  * Disable reception of multicast frames <br>
1030  *
1031  * \par
1032  * The function disables the reception of multicast frames. When invoked, the AFM
1033  * module passes all received broadcast frames.
1034  */
XMC_ETH_MAC_DisableReceptionMulticastFrames(XMC_ETH_MAC_t * const eth_mac)1035 __STATIC_INLINE void XMC_ETH_MAC_DisableReceptionMulticastFrames(XMC_ETH_MAC_t *const eth_mac)
1036 {
1037   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_PM_Msk;
1038 }
1039 
1040 /**
1041  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1042  * @return None
1043  *
1044  * \par<b>Description: </b><br>
1045  * Enable promiscuous mode <br>
1046  *
1047  * \par
1048  * The function enables the promiscuous mode. In this mode, the address filter
1049  * module passes all incoming frames regardless of its destination or source
1050  * address.
1051  */
XMC_ETH_MAC_EnablePromiscuousMode(XMC_ETH_MAC_t * const eth_mac)1052 __STATIC_INLINE void XMC_ETH_MAC_EnablePromiscuousMode(XMC_ETH_MAC_t *const eth_mac)
1053 {
1054   eth_mac->regs->MAC_FRAME_FILTER |= (uint32_t)ETH_MAC_FRAME_FILTER_PR_Msk;
1055 }
1056 
1057 /**
1058  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1059  * @return None
1060  *
1061  * \par<b>Description: </b><br>
1062  * Disable promiscuous mode <br>
1063  *
1064  * \par
1065  * The function disables the promiscuous mode.
1066  */
XMC_ETH_MAC_DisablePromiscuousMode(XMC_ETH_MAC_t * const eth_mac)1067 __STATIC_INLINE void XMC_ETH_MAC_DisablePromiscuousMode(XMC_ETH_MAC_t *const eth_mac)
1068 {
1069   eth_mac->regs->MAC_FRAME_FILTER &= (uint32_t)~ETH_MAC_FRAME_FILTER_PR_Msk;
1070 }
1071 
1072 /**
1073  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1074  * @return None
1075  *
1076  * \par<b>Description: </b><br>
1077  * Enable RX watchdog <br>
1078  *
1079  * \par
1080  * The function enables the RX watchdog by clearing the WD bitfield of the
1081  * MAC_CONFIGURATION register. When invoked, the MAC does not allow more
1082  * than 2048 bytes of the frame being received.
1083  */
XMC_ETH_MAC_EnableRxWatchdog(XMC_ETH_MAC_t * const eth_mac)1084 __STATIC_INLINE void XMC_ETH_MAC_EnableRxWatchdog(XMC_ETH_MAC_t *const eth_mac)
1085 {
1086   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_WD_Msk;
1087 }
1088 
1089 /**
1090  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1091  * @return None
1092  *
1093  * \par<b>Description: </b><br>
1094  * Disable RX watchdog <br>
1095  *
1096  * \par
1097  * The function disables the RX watchdog by disabling the timer on the RX.
1098  */
XMC_ETH_MAC_DisableRxWatchdog(XMC_ETH_MAC_t * const eth_mac)1099 __STATIC_INLINE void XMC_ETH_MAC_DisableRxWatchdog(XMC_ETH_MAC_t *const eth_mac)
1100 {
1101   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_WD_Msk;
1102 }
1103 
1104 /**
1105  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1106  * @return None
1107  *
1108  * \par<b>Description: </b><br>
1109  * Enable TX jabber <br>
1110  *
1111  * \par
1112  * When the function is invoked, the MAC cuts off the transmitter if the application
1113  * sends out more than 2,048 bytes of data during transmission (10,240 bytes if
1114  * jumbo frames are enabled)
1115  */
XMC_ETH_MAC_EnableTxJabber(XMC_ETH_MAC_t * const eth_mac)1116 __STATIC_INLINE void XMC_ETH_MAC_EnableTxJabber(XMC_ETH_MAC_t *const eth_mac)
1117 {
1118   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_JD_Msk;
1119 }
1120 
1121 /**
1122  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1123  * @return None
1124  *
1125  * \par<b>Description: </b><br>
1126  * Disable TX jabber <br>
1127  *
1128  * \par
1129  * When the function is invoked, the MAC disables the jabber timer on TX.
1130  */
XMC_ETH_MAC_DisableTxJabber(XMC_ETH_MAC_t * const eth_mac)1131 __STATIC_INLINE void XMC_ETH_MAC_DisableTxJabber(XMC_ETH_MAC_t *const eth_mac)
1132 {
1133   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_JD_Msk;
1134 }
1135 
1136 /**
1137  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1138  * @return None
1139  *
1140  * \par<b>Description: </b><br>
1141  * Frame burst enable <br>
1142  *
1143  * \par
1144  * The function can be used to enable frame bursting during transmission in the
1145  * MII half-duplex mode.
1146  */
XMC_ETH_MAC_EnableFrameBurst(XMC_ETH_MAC_t * const eth_mac)1147 __STATIC_INLINE void XMC_ETH_MAC_EnableFrameBurst(XMC_ETH_MAC_t *const eth_mac)
1148 {
1149   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_BE_Msk;
1150 }
1151 
1152 /**
1153  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1154  * @return None
1155  *
1156  * \par<b>Description: </b><br>
1157  * Frame burst disable <br>
1158  *
1159  * \par
1160  * The function can be used to disable frame bursting.
1161  */
XMC_ETH_MAC_DisableFrameBurst(XMC_ETH_MAC_t * const eth_mac)1162 __STATIC_INLINE void XMC_ETH_MAC_DisableFrameBurst(XMC_ETH_MAC_t *const eth_mac)
1163 {
1164   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_BE_Msk;
1165 }
1166 
1167 /**
1168  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1169  * @return None
1170  *
1171  * \par<b>Description: </b><br>
1172  * Jumbo frame enable <br>
1173  *
1174  * \par
1175  * The function can be used to enable jumbo frames. When enabled, the MAC allows
1176  * jumbo frames of 9,018 bytes without reporting a giant frame error in the receive
1177  * frame status.
1178  */
XMC_ETH_MAC_EnableJumboFrame(XMC_ETH_MAC_t * const eth_mac)1179 __STATIC_INLINE void XMC_ETH_MAC_EnableJumboFrame(XMC_ETH_MAC_t *const eth_mac)
1180 {
1181   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_JE_Msk;
1182 }
1183 
1184 /**
1185  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1186  * @return None
1187  *
1188  * \par<b>Description: </b><br>
1189  * Jumbo frame disable <br>
1190  *
1191  * \par
1192  * The function can be used to disable jumbo frames.
1193  */
XMC_ETH_MAC_DisableJumboFrame(XMC_ETH_MAC_t * const eth_mac)1194 __STATIC_INLINE void XMC_ETH_MAC_DisableJumboFrame(XMC_ETH_MAC_t *const eth_mac)
1195 {
1196   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_JE_Msk;
1197 }
1198 
1199 /**
1200  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1201  * @return None
1202  *
1203  * \par<b>Description: </b><br>
1204  * Enable receive own <br>
1205  *
1206  * \par
1207  * The function enables the MAC to receive all packets that are given by the PHY
1208  * while transmitting.
1209  */
XMC_ETH_MAC_EnableRxOwn(XMC_ETH_MAC_t * const eth_mac)1210 __STATIC_INLINE void XMC_ETH_MAC_EnableRxOwn(XMC_ETH_MAC_t *const eth_mac)
1211 {
1212   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_DO_Msk;
1213 }
1214 
1215 /**
1216  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1217  * @return None
1218  *
1219  * \par<b>Description: </b><br>
1220  * Disable receive own <br>
1221  *
1222  * \par
1223  * On invocation of the function, the MAC disables the reception of frames in the
1224  * half-duplex mode.
1225  */
XMC_ETH_MAC_DisableRxOwn(XMC_ETH_MAC_t * const eth_mac)1226 __STATIC_INLINE void XMC_ETH_MAC_DisableRxOwn(XMC_ETH_MAC_t *const eth_mac)
1227 {
1228   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_DO_Msk;
1229 }
1230 
1231 /**
1232  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1233  * @return None
1234  *
1235  * \par<b>Description: </b><br>
1236  * Enable loopback mode <br>
1237  *
1238  * \par
1239  * The function enables the MAC to operate in the loopback mode using the MII.
1240  */
XMC_ETH_MAC_EnableLoopback(XMC_ETH_MAC_t * const eth_mac)1241 __STATIC_INLINE void XMC_ETH_MAC_EnableLoopback(XMC_ETH_MAC_t *const eth_mac)
1242 {
1243   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_LM_Msk;
1244 }
1245 
1246 /**
1247  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1248  * @return None
1249  *
1250  * \par<b>Description: </b><br>
1251  * Disable loopback mode <br>
1252  *
1253  * \par
1254  * The function can be used to disable the loopback mode.
1255  */
XMC_ETH_MAC_DisableLoopback(XMC_ETH_MAC_t * const eth_mac)1256 __STATIC_INLINE void XMC_ETH_MAC_DisableLoopback(XMC_ETH_MAC_t *const eth_mac)
1257 {
1258   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_LM_Msk;
1259 }
1260 
1261 /**
1262  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1263  * @param speed The speed at which the link is set (10M or 100M?)
1264  * @param duplex Duplex settings (half or full duplex?)
1265  * @return None
1266  *
1267  * \par<b>Description: </b><br>
1268  * Set link <br>
1269  *
1270  * \par
1271  * The function sets the link speed and duplex settings.
1272  */
XMC_ETH_MAC_SetLink(XMC_ETH_MAC_t * const eth_mac,XMC_ETH_LINK_SPEED_t speed,XMC_ETH_LINK_DUPLEX_t duplex)1273 __STATIC_INLINE void XMC_ETH_MAC_SetLink(XMC_ETH_MAC_t *const eth_mac,
1274                                          XMC_ETH_LINK_SPEED_t speed,
1275                                          XMC_ETH_LINK_DUPLEX_t duplex)
1276 {
1277   eth_mac->regs->MAC_CONFIGURATION = (eth_mac->regs->MAC_CONFIGURATION &
1278                                       (uint32_t)~(ETH_MAC_CONFIGURATION_DM_Msk | ETH_MAC_CONFIGURATION_FES_Msk)) |
1279                                      (uint32_t)speed | (uint32_t)duplex;
1280 }
1281 
1282 /**
1283  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1284  * @return None
1285  *
1286  * \par<b>Description: </b><br>
1287  * Return RX descriptor <br>
1288  *
1289  * \par
1290  * The function sets the specified DMA RX descriptor own bit.
1291  */
1292 void XMC_ETH_MAC_ReturnRxDescriptor(XMC_ETH_MAC_t *const eth_mac);
1293 
1294 /**
1295  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1296  * @return bool true if RX descriptor is owned by DMA, false otherwise
1297  *
1298  * \par<b>Description: </b><br>
1299  * Is RX descriptor owned by DMA? <br>
1300  *
1301  * \par
1302  * The function checks if the RX descriptor is owned by the DMA.
1303  */
XMC_ETH_MAC_IsRxDescriptorOwnedByDma(XMC_ETH_MAC_t * const eth_mac)1304 __STATIC_INLINE bool XMC_ETH_MAC_IsRxDescriptorOwnedByDma(XMC_ETH_MAC_t *const eth_mac)
1305 {
1306   return ((eth_mac->rx_desc[eth_mac->rx_index].status & ETH_MAC_DMA_RDES0_OWN) != 0U);
1307 }
1308 
1309 /**
1310  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1311  * @return None
1312  *
1313  * \par<b>Description: </b><br>
1314  * Return TX descriptor <br>
1315  *
1316  * \par
1317  * The function sets the specified DMA TX descriptor own bit.
1318  */
1319 void XMC_ETH_MAC_ReturnTxDescriptor(XMC_ETH_MAC_t *const eth_mac);
1320 
1321 /**
1322  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1323  * @return bool true if TX descriptor is owned by DMA, false otherwise
1324  *
1325  * \par<b>Description: </b><br>
1326  * Is TX descriptor owned by DMA? <br>
1327  *
1328  * \par
1329  * The function checks if the TX descriptor is owned by the DMA.
1330  */
XMC_ETH_MAC_IsTxDescriptorOwnedByDma(XMC_ETH_MAC_t * const eth_mac)1331 __STATIC_INLINE bool XMC_ETH_MAC_IsTxDescriptorOwnedByDma(XMC_ETH_MAC_t *const eth_mac)
1332 {
1333   return ((eth_mac->tx_desc[eth_mac->tx_index].status & ETH_MAC_DMA_TDES0_OWN) != 0U);
1334 }
1335 
1336 /**
1337  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1338  * @return None
1339  *
1340  * \par<b>Description: </b><br>
1341  * ETH MAC Enable RX <br>
1342  *
1343  * \par
1344  * The function enables the receiver state machine of the MAC and puts the
1345  * receive process in running state. The DMA then acquires the descriptor
1346  * from the receive list and processes the received frames.
1347  */
XMC_ETH_MAC_EnableRx(XMC_ETH_MAC_t * const eth_mac)1348 __STATIC_INLINE void XMC_ETH_MAC_EnableRx(XMC_ETH_MAC_t *const eth_mac)
1349 {
1350   eth_mac->regs->OPERATION_MODE |= (uint32_t)ETH_OPERATION_MODE_SR_Msk;
1351   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_RE_Msk;
1352 }
1353 
1354 /**
1355  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1356  * @return None
1357  *
1358  * \par<b>Description: </b><br>
1359  * ETH MAC Disable RX <br>
1360  *
1361  * \par
1362  * The function disables the receive process.
1363  */
XMC_ETH_MAC_DisableRx(XMC_ETH_MAC_t * const eth_mac)1364 __STATIC_INLINE void XMC_ETH_MAC_DisableRx(XMC_ETH_MAC_t *const eth_mac)
1365 {
1366   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_RE_Msk;
1367   eth_mac->regs->OPERATION_MODE &= (uint32_t)~ETH_OPERATION_MODE_SR_Msk;
1368 }
1369 
1370 /**
1371  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1372  * @return None
1373  *
1374  * \par<b>Description: </b><br>
1375  * ETH MAC Enable TX <br>
1376  *
1377  * \par
1378  * The function enables the transmit state machine of the MAC and puts the
1379  * transmit process in running state. The DMA then checks the TX list at the
1380  * current position for transmitting a frame.
1381  */
XMC_ETH_MAC_EnableTx(XMC_ETH_MAC_t * const eth_mac)1382 __STATIC_INLINE void XMC_ETH_MAC_EnableTx(XMC_ETH_MAC_t *const eth_mac)
1383 {
1384   eth_mac->regs->OPERATION_MODE |= (uint32_t)ETH_OPERATION_MODE_ST_Msk;
1385   eth_mac->regs->MAC_CONFIGURATION |= (uint32_t)ETH_MAC_CONFIGURATION_TE_Msk;
1386 }
1387 
1388 /**
1389  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1390  * @return None
1391  *
1392  * \par<b>Description: </b><br>
1393  * ETH MAC Disable TX <br>
1394  *
1395  * \par
1396  * The function disables the transmit process.
1397  */
XMC_ETH_MAC_DisableTx(XMC_ETH_MAC_t * const eth_mac)1398 __STATIC_INLINE void XMC_ETH_MAC_DisableTx(XMC_ETH_MAC_t *const eth_mac)
1399 {
1400   eth_mac->regs->MAC_CONFIGURATION &= (uint32_t)~ETH_MAC_CONFIGURATION_TE_Msk;
1401   eth_mac->regs->OPERATION_MODE &= (uint32_t)~ETH_OPERATION_MODE_ST_Msk;
1402 }
1403 
1404 /**
1405  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1406  * @return None
1407  *
1408  * \par<b>Description: </b><br>
1409  * Flush TX <br>
1410  *
1411  * \par
1412  * The function initializes the TX DMA descriptors and enables the DMA transmission.
1413  */
1414 void XMC_ETH_MAC_FlushTx(XMC_ETH_MAC_t *const eth_mac);
1415 
1416 /**
1417  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1418  * @return None
1419  *
1420  * \par<b>Description: </b><br>
1421  * Flush RX <br>
1422  *
1423  * \par
1424  * The function initializes the RX DMA descriptors and enables the DMA transmission.
1425  */
1426 void XMC_ETH_MAC_FlushRx(XMC_ETH_MAC_t *const eth_mac);
1427 
1428 /**
1429  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1430  * @return None
1431  *
1432  * \par<b>Description: </b><br>
1433  * Resume TX <br>
1434  *
1435  * \par
1436  * Verbatim from the reference manual, the function enables the DMA to read the
1437  * current descriptor pointed to by the "current host transmit descriptor" reg.
1438  * If that descriptor is not available (owned by the CPU), the transmission
1439  * returns to the suspend state else the transmission resumes.
1440  */
XMC_ETH_MAC_ResumeTx(XMC_ETH_MAC_t * const eth_mac)1441 __STATIC_INLINE void XMC_ETH_MAC_ResumeTx(XMC_ETH_MAC_t *const eth_mac)
1442 {
1443   eth_mac->regs->STATUS = (uint32_t)ETH_STATUS_TPS_Msk;
1444   eth_mac->regs->TRANSMIT_POLL_DEMAND = 0U;
1445 }
1446 
1447 /**
1448  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1449  * @return None
1450  *
1451  * \par<b>Description: </b><br>
1452  * Resume RX <br>
1453  *
1454  * \par
1455  * Verbatim from the reference manual the function enables the DMA to read the
1456  * current descriptor pointed to by the "current host transmit descriptor" reg.
1457  * If that descriptor is not available (owned by the CPU), the transmission
1458  * returns to the suspend state else the transmission resumes.
1459  */
XMC_ETH_MAC_ResumeRx(XMC_ETH_MAC_t * const eth_mac)1460 __STATIC_INLINE void XMC_ETH_MAC_ResumeRx(XMC_ETH_MAC_t *const eth_mac)
1461 {
1462   eth_mac->regs->STATUS = (uint32_t)ETH_STATUS_RU_Msk;
1463   eth_mac->regs->RECEIVE_POLL_DEMAND = 0U;
1464 }
1465 
1466 /**
1467  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1468  * @return Pointer to current TX buffer
1469  *
1470  * \par<b>Description: </b><br>
1471  * Returns the current TX buffer.
1472  */
XMC_ETH_MAC_GetTxBuffer(XMC_ETH_MAC_t * const eth_mac)1473 __STATIC_INLINE uint8_t *XMC_ETH_MAC_GetTxBuffer(XMC_ETH_MAC_t *const eth_mac)
1474 {
1475   return (uint8_t *)(eth_mac->tx_desc[eth_mac->tx_index].buffer1);
1476 }
1477 
1478 /**
1479  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1480  * @return Pointer to current RX buffer
1481  *
1482  * \par<b>Description: </b><br>
1483  * Returns the current RX buffer.
1484  */
XMC_ETH_MAC_GetRxBuffer(XMC_ETH_MAC_t * const eth_mac)1485 __STATIC_INLINE uint8_t *XMC_ETH_MAC_GetRxBuffer(XMC_ETH_MAC_t *const eth_mac)
1486 {
1487   return (uint8_t *)(eth_mac->rx_desc[eth_mac->rx_index].buffer1);
1488 }
1489 
1490 /**
1491  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1492  * @param size Size of buffer
1493  * @return None
1494  *
1495  * \par<b>Description: </b><br>
1496  * Sets the current TX buffer size.
1497  */
XMC_ETH_MAC_SetTxBufferSize(XMC_ETH_MAC_t * const eth_mac,uint32_t size)1498 __STATIC_INLINE void XMC_ETH_MAC_SetTxBufferSize(XMC_ETH_MAC_t *const eth_mac, uint32_t size)
1499 {
1500   eth_mac->tx_desc[eth_mac->tx_index].length = size;
1501 }
1502 
1503 /**
1504  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1505  * @param event A valid ETH PMT event (XMC_ETH_MAC_PMT_EVENT_t) or a valid combination
1506  *              of logically OR'd events
1507  * @return None
1508  *
1509  * \par<b>Description: </b><br>
1510  * Enable power management event(s) <br>
1511  *
1512  * \par
1513  * The function enables the event(s) that trigger(s) a PMT interrupt.
1514  */
XMC_ETH_MAC_EnablePowerManagmentEvent(XMC_ETH_MAC_t * const eth_mac,uint32_t event)1515 __STATIC_INLINE void XMC_ETH_MAC_EnablePowerManagmentEvent(XMC_ETH_MAC_t *const eth_mac, uint32_t event)
1516 {
1517   eth_mac->regs->PMT_CONTROL_STATUS |= (uint32_t)event;
1518 }
1519 
1520 /**
1521  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1522  * @param event A valid ETH PMT event (XMC_ETH_MAC_PMT_EVENT_t) or a valid combination
1523  *              of logically OR'd events
1524  * @return None
1525  *
1526  * \par<b>Description: </b><br>
1527  * Disable power management event(s) <br>
1528  *
1529  * \par
1530  * The function disables the event(s) that trigger(s) a PMT interrupt.
1531  */
XMC_ETH_MAC_DisablePowerManagmentEvent(XMC_ETH_MAC_t * const eth_mac,uint32_t event)1532 __STATIC_INLINE void XMC_ETH_MAC_DisablePowerManagmentEvent(XMC_ETH_MAC_t *const eth_mac, uint32_t event)
1533 {
1534   eth_mac->regs->PMT_CONTROL_STATUS &= ~(uint32_t)event;
1535 }
1536 
1537 /**
1538  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1539  * @param filter wake-up filter registers
1540  * @return None
1541  *
1542  * \par<b>Description: </b><br>
1543  * Set wakeup frame filter <br>
1544  *
1545  * \par
1546  * The function populates the remote wakeup frame registers.
1547  */
1548 void XMC_ETH_MAC_SetWakeUpFrameFilter(XMC_ETH_MAC_t *const eth_mac,
1549                                       const uint32_t (*const filter)[XMC_ETH_WAKEUP_REGISTER_LENGTH]);
1550 
1551 /**
1552  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1553  * @return bool true if the received packet is a magic packet, false otherwise
1554  *
1555  * \par<b>Description: </b><br>
1556  * Is magic packet received? <br>
1557  *
1558  * \par
1559  * The function checks if the packet received is a magic packet.
1560  */
XMC_ETH_MAC_IsMagicPacketReceived(XMC_ETH_MAC_t * const eth_mac)1561 __STATIC_INLINE bool XMC_ETH_MAC_IsMagicPacketReceived(XMC_ETH_MAC_t *const eth_mac)
1562 {
1563   return (bool)(eth_mac->regs->PMT_CONTROL_STATUS & (uint32_t)ETH_PMT_CONTROL_STATUS_MGKPRCVD_Msk);
1564 }
1565 
1566 /**
1567  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1568  * @return bool true if the received packet is a wakeup frame, false otherwise
1569  *
1570  * \par<b>Description: </b><br>
1571  * Is wakeup frame received? <br>
1572  *
1573  * \par
1574  * The function checks if the packet received is a wakeup frame.
1575  */
XMC_ETH_MAC_IsWakeupFrameReceived(XMC_ETH_MAC_t * const eth_mac)1576 __STATIC_INLINE bool XMC_ETH_MAC_IsWakeupFrameReceived(XMC_ETH_MAC_t *const eth_mac)
1577 {
1578   return (bool)(eth_mac->regs->PMT_CONTROL_STATUS & (uint32_t)ETH_PMT_CONTROL_STATUS_RWKPRCVD_Msk);
1579 }
1580 
1581 /**
1582  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1583  * @return None
1584  *
1585  * \par<b>Description: </b><br>
1586  * Enable power down mode <br>
1587  *
1588  * \par
1589  * The function enables the power down mode of the ETH MAC.
1590  */
XMC_ETH_MAC_EnablePowerDownMode(XMC_ETH_MAC_t * const eth_mac)1591 __STATIC_INLINE void XMC_ETH_MAC_EnablePowerDownMode(XMC_ETH_MAC_t *const eth_mac)
1592 {
1593   eth_mac->regs->PMT_CONTROL_STATUS |= (uint32_t)ETH_PMT_CONTROL_STATUS_PWRDWN_Msk;
1594 }
1595 
1596 /**
1597  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1598  * @return None
1599  *
1600  * \par<b>Description: </b><br>
1601  * Disable power down mode <br>
1602  *
1603  * \par
1604  * The function disables the power down mode of the ETH MAC.
1605  */
XMC_ETH_MAC_DisablePowerDownMode(XMC_ETH_MAC_t * const eth_mac)1606 __STATIC_INLINE void XMC_ETH_MAC_DisablePowerDownMode(XMC_ETH_MAC_t *const eth_mac)
1607 {
1608   eth_mac->regs->PMT_CONTROL_STATUS &= ~(uint32_t)ETH_PMT_CONTROL_STATUS_PWRDWN_Msk;
1609 }
1610 
1611 /**
1612  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1613  * @param tag The (16 bit) VLAN tag to set
1614  * @return None
1615  *
1616  * \par<b>Description: </b><br>
1617  * Set VLAN tag <br>
1618  *
1619  * \par
1620  * The function sets the VLAN tag to identify the VLAN frames.
1621  */
1622 void XMC_ETH_MAC_SetVLANTag(XMC_ETH_MAC_t *const eth_mac, uint32_t tag);
1623 
1624 /**
1625  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1626  * @param config The configuration the PTP should be configured with
1627  * @return None
1628  *
1629  * \par<b>Description: </b><br>
1630  * Initialize PTP <br>
1631  *
1632  * \par
1633  * The function can be used to initialize PTP.
1634  */
1635 void XMC_ETH_MAC_InitPTP(XMC_ETH_MAC_t *const eth_mac, uint32_t config);
1636 
1637 /**
1638  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1639  * @param config Configuration of PTP module. See ::XMC_ETH_MAC_TIMESTAMP_CONFIG_t
1640  * @param time Initialization time
1641  * @return None
1642  *
1643  * \par<b>Description: </b><br>
1644  * Initialize PTP <br>
1645  *
1646  * \par
1647  * The function can be used to initialize PTP given a time parameter in addition
1648  */
1649 void XMC_ETH_MAC_InitPTPEx(XMC_ETH_MAC_t *const eth_mac, uint32_t config, XMC_ETH_MAC_TIME_t *const time);
1650 
1651 /**
1652  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1653  * @param time A constant pointer to XMC_ETH_MAC_TIME_t, pointing to the PTP time
1654  * @return None
1655  *
1656  * \par<b>Description: </b><br>
1657  * Get PTP time <br>
1658  *
1659  * \par
1660  * The function obtains the PTP time and writes the nanoseconds and seconds info
1661  * to the 'time' argument.
1662  */
1663 void XMC_ETH_MAC_GetPTPTime(XMC_ETH_MAC_t *const eth_mac, XMC_ETH_MAC_TIME_t *const time);
1664 
1665 /**
1666  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1667  * @param time A constant pointer to XMC_ETH_MAC_TIME_t, pointing to the PTP time
1668  * @return None
1669  *
1670  * \par<b>Description: </b><br>
1671  * Get PTP time <br>
1672  *
1673  * \par
1674  * The function sets the PTP time give by the time parameter
1675  */
1676 void XMC_ETH_MAC_SetPTPTime(XMC_ETH_MAC_t *const eth_mac, XMC_ETH_MAC_TIME_t *const time);
1677 
1678 /**
1679  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1680  * @param time A constant pointer to XMC_ETH_MAC_TIME_t, pointing to the PTP time
1681  * @return None
1682  *
1683  * \par<b>Description: </b><br>
1684  * Update PTP time <br>
1685  *
1686  * \par
1687  * The function updates the PTP time with the nanoseconds and seconds info contained in
1688  * the 'time' argument.
1689  */
1690 void XMC_ETH_MAC_UpdatePTPTime(XMC_ETH_MAC_t *const eth_mac, const XMC_ETH_MAC_TIME_t *const time);
1691 
1692 /**
1693  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1694  * @param time A constant pointer to XMC_ETH_MAC_TIME_t, pointing to the PTP time
1695  * @return None
1696  *
1697  * \par<b>Description: </b><br>
1698  * Set PTP alarm <br>
1699  *
1700  * \par
1701  * The function programs the TARGET_TIME_NANOSECONDS and TARGET_TIME_SECONDS registers. It can
1702  * be used to schedule an interrupt event triggered when the set alarm time limit is reached.
1703  */
1704 void XMC_ETH_MAC_SetPTPAlarm(XMC_ETH_MAC_t *const eth_mac, const XMC_ETH_MAC_TIME_t *const time);
1705 
1706 /**
1707  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1708  * @return None
1709  *
1710  * \par<b>Description: </b><br>
1711  * Enables timestamp interrupt <br>
1712  *
1713  * \par
1714  * The timestamp interrupt is generated when the System Time becomes greater than the value written
1715  * in the Target Time register (Alarm). After the generation of the Timestamp Trigger Interrupt, the interrupt is disabled.
1716  */
XMC_ETH_MAC_EnablePTPAlarm(XMC_ETH_MAC_t * const eth_mac)1717 __STATIC_INLINE void XMC_ETH_MAC_EnablePTPAlarm(XMC_ETH_MAC_t *const eth_mac)
1718 {
1719   eth_mac->regs->TIMESTAMP_CONTROL |= (uint32_t)ETH_TIMESTAMP_CONTROL_TSTRIG_Msk;
1720 }
1721 
1722 /**
1723  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1724  * @return None
1725  *
1726  * \par<b>Description: </b><br>
1727  * Disables timestamp interrupt <br>
1728  *
1729  * \par
1730  * The timestamp interrupt is generated when the System Time becomes greater than the value written
1731  * in the Target Time register (Alarm). After the generation of the Timestamp Trigger Interrupt, the interrupt is disabled.
1732  */
XMC_ETH_MAC_DisablePTPAlarm(XMC_ETH_MAC_t * const eth_mac)1733 __STATIC_INLINE void XMC_ETH_MAC_DisablePTPAlarm(XMC_ETH_MAC_t *const eth_mac)
1734 {
1735   eth_mac->regs->TIMESTAMP_CONTROL &= (uint32_t)~ETH_TIMESTAMP_CONTROL_TSTRIG_Msk;
1736 }
1737 
1738 
1739 /**
1740  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1741  * @param addend Addend value
1742  * @return None
1743  *
1744  * \par<b>Description: </b><br>
1745  * Adjust PTP clock <br>
1746  *
1747  * \par
1748  * The function is used to adjust the PTP clock (time synchronization) to compensate a reference clock drift.
1749  */
1750 void XMC_ETH_MAC_UpdateAddend(XMC_ETH_MAC_t *const eth_mac, uint32_t addend);
1751 
1752 /**
1753  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1754  * @param correction Correction factor
1755  * @return None
1756  *
1757  * \par<b>Description: </b><br>
1758  * Adjust PTP clock <br>
1759  *
1760  * \par
1761  * The function can be used to adjust the PTP clock (time synchronization). Please see the
1762  * function implementation for more information.
1763  */
1764 void XMC_ETH_MAC_AdjustPTPClock(XMC_ETH_MAC_t *const eth_mac, uint32_t correction);
1765 
1766 /**
1767  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1768  * @return uint32_t Timestamp status
1769  *
1770  * \par<b>Description: </b><br>
1771  * Get PTP status <br>
1772  *
1773  * \par
1774  * The function returns the timestamp status by reading the TIMESTAMP_STATUS register.
1775  * As indicated in the reference manual, all bits of the TIMESTAMP_STATUS register (except
1776  * bits [27:25]) are cleared after the invocation of this function.
1777  */
1778 uint32_t XMC_ETH_MAC_GetPTPStatus(const XMC_ETH_MAC_t *const eth_mac);
1779 
1780 /**
1781  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1782  * @param time A constant pointer to XMC_ETH_MAC_TIME_t, pointing to the RX timestamp
1783  * @return XMC_ETH_MAC_STATUS_t ETH MAC status
1784  *
1785  * \par<b>Description: </b><br>
1786  * Get RX timestamp <br>
1787  *
1788  * \par
1789  * The function can be used to get the RX timestamp.
1790  */
1791 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_GetRxTimeStamp(XMC_ETH_MAC_t *const eth_mac, XMC_ETH_MAC_TIME_t *const time);
1792 
1793 /**
1794  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1795  * @param time A constant pointer to XMC_ETH_MAC_TIME_t, pointing to the TX timestamp
1796  * @return XMC_ETH_MAC_STATUS_t ETH MAC status
1797  *
1798  * \par<b>Description: </b><br>
1799  * Get TX timestamp <br>
1800  *
1801  * \par
1802  * The function can be used to get the TX timestamp.
1803  */
1804 XMC_ETH_MAC_STATUS_t XMC_ETH_MAC_GetTxTimeStamp(XMC_ETH_MAC_t *const eth_mac, XMC_ETH_MAC_TIME_t *const time);
1805 
1806 /**
1807  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1808  * @param event Which event (or a combination of logically OR'd events) needs to be enabled?
1809  * @return None
1810  *
1811  * \par<b>Description: </b><br>
1812  * Enable ETH MAC event(s) <br>
1813  *
1814  * \par
1815  * The function can be used to enable ETH MAC event(s).
1816  */
1817 void XMC_ETH_MAC_EnableEvent(XMC_ETH_MAC_t *const eth_mac, uint32_t event);
1818 
1819 /**
1820  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1821  * @param event Which event (or a combination of logically OR'd events) needs to be disabled?
1822  * @return None
1823  *
1824  * \par<b>Description: </b><br>
1825  * Disable an ETH MAC event(s) <br>
1826  *
1827  * \par
1828  * The function can be used to disable ETH MAC event(s).
1829  */
1830 void XMC_ETH_MAC_DisableEvent(XMC_ETH_MAC_t *const eth_mac, uint32_t event);
1831 
1832 /**
1833  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1834  * @param event The status of which event (or a combination of logically OR'd events) needs to be cleared
1835  * @return None
1836  *
1837  * \par<b>Description: </b><br>
1838  * Clear event status <br>
1839  *
1840  * \par
1841  * The function clears the status of an event passed as a parameter to the function.
1842  */
1843 void XMC_ETH_MAC_ClearEventStatus(XMC_ETH_MAC_t *const eth_mac, uint32_t event);
1844 
1845 /**
1846  * @param eth_mac A constant pointer to XMC_ETH_MAC_t, pointing to the ETH MAC base address
1847  * @return uint32_t Event status
1848  *
1849  * \par<b>Description: </b><br>
1850  * Get event status <br>
1851  *
1852  * \par
1853  * The function returns the ETH status and interrupt status as a single word. The user
1854  * can then check the status of the events by using an appropriate mask.
1855  */
1856 uint32_t XMC_ETH_MAC_GetEventStatus(const XMC_ETH_MAC_t *const eth_mac);
1857 
1858 #ifdef __cplusplus
1859 }
1860 #endif
1861 
1862 /**
1863  * @}
1864  */
1865 
1866 /**
1867  * @}
1868  */
1869 
1870 #endif /* defined (ETH0) */
1871 
1872 #endif /* XMC_ETH_MAC_H */
1873