| M480 BSP V3.05.001 The Board Support Package for M480 Series

emac.h
Go to the documentation of this file.
1 /**************************************************************************/
9 #ifndef __EMAC_H__
10 #define __EMAC_H__
11
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16
17 #include <stdint.h>
18
31 #define EMAC_PHY_ADDR 1UL
32 #define EMAC_RX_DESC_SIZE 4UL
33 #define EMAC_TX_DESC_SIZE 4UL
34 #define EMAC_CAMENTRY_NB 16UL
35 #define EMAC_MAX_PKT_SIZE 1524UL
37 #define EMAC_LINK_DOWN 0UL
38 #define EMAC_LINK_100F 1UL
39 #define EMAC_LINK_100H 2UL
40 #define EMAC_LINK_10F 3UL
41 #define EMAC_LINK_10H 4UL
43 /* end of group EMAC_EXPORTED_CONSTANTS */
44
45
57 #define EMAC_ENABLE_TX() (EMAC->CTL |= EMAC_CTL_TXON_Msk)
58
59
66 #define EMAC_ENABLE_RX() do{EMAC->CTL |= EMAC_CTL_RXON_Msk; EMAC->RXST = 0;}while(0)
67
74 #define EMAC_DISABLE_TX() (EMAC->CTL &= ~EMAC_CTL_TXON_Msk)
75
76
83 #define EMAC_DISABLE_RX() (EMAC->CTL &= ~EMAC_CTL_RXON_Msk)
84
91 #define EMAC_ENABLE_MAGIC_PKT_WAKEUP() (EMAC->CTL |= EMAC_CTL_WOLEN_Msk)
92
99 #define EMAC_DISABLE_MAGIC_PKT_WAKEUP() (EMAC->CTL &= ~EMAC_CTL_WOLEN_Msk)
100
107 #define EMAC_ENABLE_RECV_BCASTPKT() (EMAC->CAMCTL |= EMAC_CAMCTL_ABP_Msk)
108
115 #define EMAC_DISABLE_RECV_BCASTPKT() (EMAC->CAMCTL &= ~EMAC_CAMCTL_ABP_Msk)
116
123 #define EMAC_ENABLE_RECV_MCASTPKT() (EMAC->CAMCTL |= EMAC_CAMCTL_AMP_Msk)
124
131 #define EMAC_DISABLE_RECV_MCASTPKT() (EMAC->CAMCTL &= ~EMAC_CAMCTL_AMP_Msk)
132
141 #define EMAC_GET_ALARM_FLAG() (EMAC->INTSTS & EMAC_INTSTS_TSALMIF_Msk ? 1 : 0)
142
149 #define EMAC_CLR_ALARM_FLAG() (EMAC->INTSTS = EMAC_INTSTS_TSALMIF_Msk)
150
156 #define EMAC_TRIGGER_RX() do{EMAC->RXST = 0UL;}while(0)
157
163 #define EMAC_TRIGGER_TX() do{EMAC->TXST = 0UL;}while(0)
164
200 #define EMAC_ENABLE_INT(emac, u32eIntSel) ((emac)->INTEN |= (u32eIntSel))
201
237 #define EMAC_DISABLE_INT(emac, u32eIntSel) ((emac)->INTEN &= ~ (u32eIntSel))
238
274 #define EMAC_GET_INT_FLAG(emac, u32eIntTypeFlag) (((emac)->INTSTS & (u32eIntTypeFlag))?1:0)
275
312 #define EMAC_CLEAR_INT_FLAG(emac, u32eIntTypeFlag) ((emac)->INTSTS |= (u32eIntTypeFlag))
313
314 void EMAC_Open(uint8_t *pu8MacAddr);
315 void EMAC_Close(void);
316 void EMAC_SetMacAddr(uint8_t *pu8MacAddr);
317 void EMAC_EnableCamEntry(uint32_t u32Entry, uint8_t pu8MacAddr[]);
318 void EMAC_DisableCamEntry(uint32_t u32Entry);
319
320 uint32_t EMAC_RecvPkt(uint8_t *pu8Data, uint32_t *pu32Size);
321 uint32_t EMAC_RecvPktTS(uint8_t *pu8Data, uint32_t *pu32Size, uint32_t *pu32Sec, uint32_t *pu32Nsec);
322 void EMAC_RecvPktDone(void);
323
324 uint32_t EMAC_SendPkt(uint8_t *pu8Data, uint32_t u32Size);
325 uint32_t EMAC_SendPktDone(void);
326 uint32_t EMAC_SendPktDoneTS(uint32_t *pu32Sec, uint32_t *pu32Nsec);
327
328 void EMAC_EnableTS(uint32_t u32Sec, uint32_t u32Nsec);
329 void EMAC_DisableTS(void);
330 void EMAC_GetTime(uint32_t *pu32Sec, uint32_t *pu32Nsec);
331 void EMAC_SetTime(uint32_t u32Sec, uint32_t u32Nsec);
332 void EMAC_UpdateTime(uint32_t u32Neg, uint32_t u32Sec, uint32_t u32Nsec);
333 void EMAC_EnableAlarm(uint32_t u32Sec, uint32_t u32Nsec);
334 void EMAC_DisableAlarm(void);
335
336 uint32_t EMAC_CheckLinkStatus(void);
337
338 void EMAC_PhyInit(void);
339 int32_t EMAC_FillCamEntry(uint8_t pu8MacAddr[]);
340 uint8_t *EMAC_ClaimFreeTXBuf(void);
341 uint32_t EMAC_GetAvailRXBufSize(void);
342 uint32_t EMAC_SendPktWoCopy(uint32_t u32Size);
343 void EMAC_RecvPktDoneWoRxTrigger(void);
344 /* end of group EMAC_EXPORTED_FUNCTIONS */
346 /* end of group EMAC_Driver */
348 /* end of group Standard_Driver */
350
351 #ifdef __cplusplus
352 }
353 #endif
354
355 #endif /* __NU_EMAC_H__ */
356
357 /*** (C) COPYRIGHT 2016 Nuvoton Technology Corp. ***/
EMAC_FillCamEntry
int32_t EMAC_FillCamEntry(uint8_t pu8MacAddr[])
Fill a MAC address to list and enable.
Definition: emac.c:1011
EMAC_SetTime
void EMAC_SetTime(uint32_t u32Sec, uint32_t u32Nsec)
Set current time stamp.
Definition: emac.c:896
EMAC_PhyInit
void EMAC_PhyInit(void)
EMAC_SetMacAddr
void EMAC_SetMacAddr(uint8_t *pu8MacAddr)
Set the device MAC address.
Definition: emac.c:432
EMAC_GetTime
void EMAC_GetTime(uint32_t *pu32Sec, uint32_t *pu32Nsec)
Get current time stamp.
Definition: emac.c:883
EMAC_EnableAlarm
void EMAC_EnableAlarm(uint32_t u32Sec, uint32_t u32Nsec)
Enable alarm function and set alarm time.
Definition: emac.c:912
EMAC_DisableTS
void EMAC_DisableTS(void)
Disable IEEE1588 time stamp function.
Definition: emac.c:872
EMAC_DisableAlarm
void EMAC_DisableAlarm(void)
Disable alarm function.
Definition: emac.c:926
EMAC_EnableTS
void EMAC_EnableTS(uint32_t u32Sec, uint32_t u32Nsec)
Enable IEEE1588 time stamp function and set current time.
Definition: emac.c:844
EMAC_EnableCamEntry
void EMAC_EnableCamEntry(uint32_t u32Entry, uint8_t pu8MacAddr[])
Fill a CAM entry for MAC address comparison.
Definition: emac.c:444
EMAC_CheckLinkStatus
uint32_t EMAC_CheckLinkStatus(void)
Check Ethernet link status.
Definition: emac.c:965
EMAC_RecvPkt
uint32_t EMAC_RecvPkt(uint8_t *pu8Data, uint32_t *pu32Size)
Receive an Ethernet packet.
Definition: emac.c:483
EMAC_SendPktDone
uint32_t EMAC_SendPktDone(void)
Clean up process after packet(s) are sent.
Definition: emac.c:686
EMAC_Close
void EMAC_Close(void)
This function stop all receive and transmit activity and disable MAC interface.
Definition: emac.c:420
EMAC_DisableCamEntry
void EMAC_DisableCamEntry(uint32_t u32Entry)
Disable a specified CAM entry.
Definition: emac.c:468
EMAC_Open
void EMAC_Open(uint8_t *pu8MacAddr)
Initialize EMAC interface, including descriptors, MAC address, and PHY.
Definition: emac.c:381
EMAC_RecvPktDone
void EMAC_RecvPktDone(void)
Clean up process after a packet is received.
Definition: emac.c:614
EMAC_RecvPktDoneWoRxTrigger
void EMAC_RecvPktDoneWoRxTrigger(void)
Clean up process after a packet is received.
Definition: emac.c:1150
EMAC_UpdateTime
void EMAC_UpdateTime(uint32_t u32Neg, uint32_t u32Sec, uint32_t u32Nsec)
Add a offset to current time.
Definition: emac.c:940
EMAC_SendPktWoCopy
uint32_t EMAC_SendPktWoCopy(uint32_t u32Size)
Send an Ethernet packet.
Definition: emac.c:1062
EMAC_SendPktDoneTS
uint32_t EMAC_SendPktDoneTS(uint32_t *pu32Sec, uint32_t *pu32Nsec)
Clean up process after a packet is sent, and get the time stamp while packet is sent.
Definition: emac.c:769
EMAC_GetAvailRXBufSize
uint32_t EMAC_GetAvailRXBufSize(void)
Get data length of avaiable RX buffer.
Definition: emac.c:1118
EMAC_SendPkt
uint32_t EMAC_SendPkt(uint8_t *pu8Data, uint32_t u32Size)
Send an Ethernet packet.
Definition: emac.c:646
EMAC_ClaimFreeTXBuf
uint8_t * EMAC_ClaimFreeTXBuf(void)
Get avaiable TX buffer address.
Definition: emac.c:1098
EMAC_RecvPktTS
uint32_t EMAC_RecvPktTS(uint8_t *pu8Data, uint32_t *pu32Size, uint32_t *pu32Sec, uint32_t *pu32Nsec)
Receive an Ethernet packet and the time stamp while it's received.
Definition: emac.c:548