M480 BSP  V3.05.001
The Board Support Package for M480 Series
Macros | Functions
EMAC Exported Functions

Macros

#define EMAC_ENABLE_TX()
 Enable EMAC Tx function. More...
 
#define EMAC_ENABLE_RX()
 Enable EMAC Rx function. More...
 
#define EMAC_DISABLE_TX()
 Disable EMAC Tx function. More...
 
#define EMAC_DISABLE_RX()
 Disable EMAC Rx function. More...
 
#define EMAC_ENABLE_MAGIC_PKT_WAKEUP()
 Enable EMAC Magic Packet Wakeup function. More...
 
#define EMAC_DISABLE_MAGIC_PKT_WAKEUP()
 Disable EMAC Magic Packet Wakeup function. More...
 
#define EMAC_ENABLE_RECV_BCASTPKT()
 Enable EMAC to receive broadcast packets. More...
 
#define EMAC_DISABLE_RECV_BCASTPKT()
 Disable EMAC to receive broadcast packets. More...
 
#define EMAC_ENABLE_RECV_MCASTPKT()
 Enable EMAC to receive multicast packets. More...
 
#define EMAC_DISABLE_RECV_MCASTPKT()
 Disable EMAC Magic Packet Wakeup function. More...
 
#define EMAC_GET_ALARM_FLAG()
 Check if EMAC time stamp alarm interrupt occurred or not. More...
 
#define EMAC_CLR_ALARM_FLAG()
 Clear EMAC time stamp alarm interrupt flag. More...
 
#define EMAC_TRIGGER_RX()   do{EMAC->RXST = 0UL;}while(0)
 Trigger EMAC Rx function. More...
 
#define EMAC_TRIGGER_TX()   do{EMAC->TXST = 0UL;}while(0)
 Trigger EMAC Tx function. More...
 
#define EMAC_ENABLE_INT(emac, u32eIntSel)
 Enable specified EMAC interrupt. More...
 
#define EMAC_DISABLE_INT(emac, u32eIntSel)
 Disable specified EMAC interrupt. More...
 
#define EMAC_GET_INT_FLAG(emac, u32eIntTypeFlag)
 Get specified interrupt flag/status. More...
 
#define EMAC_CLEAR_INT_FLAG(emac, u32eIntTypeFlag)
 Clear specified interrupt flag/status. More...
 

Functions

void EMAC_Open (uint8_t *pu8MacAddr)
 Initialize EMAC interface, including descriptors, MAC address, and PHY. More...
 
void EMAC_Close (void)
 This function stop all receive and transmit activity and disable MAC interface. More...
 
void EMAC_SetMacAddr (uint8_t *pu8MacAddr)
 Set the device MAC address. More...
 
void EMAC_EnableCamEntry (uint32_t u32Entry, uint8_t pu8MacAddr[])
 Fill a CAM entry for MAC address comparison. More...
 
void EMAC_DisableCamEntry (uint32_t u32Entry)
 Disable a specified CAM entry. More...
 
uint32_t EMAC_RecvPkt (uint8_t *pu8Data, uint32_t *pu32Size)
 Receive an Ethernet packet. More...
 
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. More...
 
void EMAC_RecvPktDone (void)
 Clean up process after a packet is received. More...
 
uint32_t EMAC_SendPkt (uint8_t *pu8Data, uint32_t u32Size)
 Send an Ethernet packet. More...
 
uint32_t EMAC_SendPktDone (void)
 Clean up process after packet(s) are sent. More...
 
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. More...
 
void EMAC_EnableTS (uint32_t u32Sec, uint32_t u32Nsec)
 Enable IEEE1588 time stamp function and set current time. More...
 
void EMAC_DisableTS (void)
 Disable IEEE1588 time stamp function. More...
 
void EMAC_GetTime (uint32_t *pu32Sec, uint32_t *pu32Nsec)
 Get current time stamp. More...
 
void EMAC_SetTime (uint32_t u32Sec, uint32_t u32Nsec)
 Set current time stamp. More...
 
void EMAC_UpdateTime (uint32_t u32Neg, uint32_t u32Sec, uint32_t u32Nsec)
 Add a offset to current time. More...
 
void EMAC_EnableAlarm (uint32_t u32Sec, uint32_t u32Nsec)
 Enable alarm function and set alarm time. More...
 
void EMAC_DisableAlarm (void)
 Disable alarm function. More...
 
uint32_t EMAC_CheckLinkStatus (void)
 Check Ethernet link status. More...
 
void EMAC_PhyInit (void)
 
int32_t EMAC_FillCamEntry (uint8_t pu8MacAddr[])
 Fill a MAC address to list and enable. More...
 
uint8_t * EMAC_ClaimFreeTXBuf (void)
 Get avaiable TX buffer address. More...
 
uint32_t EMAC_GetAvailRXBufSize (void)
 Get data length of avaiable RX buffer. More...
 
uint32_t EMAC_SendPktWoCopy (uint32_t u32Size)
 Send an Ethernet packet. More...
 
void EMAC_RecvPktDoneWoRxTrigger (void)
 Clean up process after a packet is received. More...
 

Detailed Description

HIDDEN_SYMBOLS

Macro Definition Documentation

◆ EMAC_CLEAR_INT_FLAG

#define EMAC_CLEAR_INT_FLAG (   emac,
  u32eIntTypeFlag 
)

Clear specified interrupt flag/status.

Parameters
[in]emacThe pointer of the specified EMAC module
[in]u32eIntTypeFlagInterrupt Type Flag, should be
Return values
0The specified interrupt is not happened. 1 The specified interrupt is happened.

This macro clear specified interrupt flag or interrupt indicator status.

Definition at line 312 of file emac.h.

◆ EMAC_CLR_ALARM_FLAG

#define EMAC_CLR_ALARM_FLAG ( )

Clear EMAC time stamp alarm interrupt flag.

Parameters
None
Returns
None

Definition at line 149 of file emac.h.

◆ EMAC_DISABLE_INT

#define EMAC_DISABLE_INT (   emac,
  u32eIntSel 
)

Disable specified EMAC interrupt.

Parameters
[in]emacThe pointer of the specified EMAC module
[in]u32eIntSelInterrupt type select
Returns
None

This macro disable specified EMAC interrupt.

Definition at line 237 of file emac.h.

◆ EMAC_DISABLE_MAGIC_PKT_WAKEUP

#define EMAC_DISABLE_MAGIC_PKT_WAKEUP ( )

Disable EMAC Magic Packet Wakeup function.

Parameters
None
Returns
None

Definition at line 99 of file emac.h.

◆ EMAC_DISABLE_RECV_BCASTPKT

#define EMAC_DISABLE_RECV_BCASTPKT ( )

Disable EMAC to receive broadcast packets.

Parameters
None
Returns
None

Definition at line 115 of file emac.h.

◆ EMAC_DISABLE_RECV_MCASTPKT

#define EMAC_DISABLE_RECV_MCASTPKT ( )

Disable EMAC Magic Packet Wakeup function.

Parameters
None
Returns
None

Definition at line 131 of file emac.h.

◆ EMAC_DISABLE_RX

#define EMAC_DISABLE_RX ( )

Disable EMAC Rx function.

Parameters
None
Returns
None

Definition at line 83 of file emac.h.

◆ EMAC_DISABLE_TX

#define EMAC_DISABLE_TX ( )

Disable EMAC Tx function.

Parameters
None
Returns
None

Definition at line 74 of file emac.h.

◆ EMAC_ENABLE_INT

#define EMAC_ENABLE_INT (   emac,
  u32eIntSel 
)

Enable specified EMAC interrupt.

Parameters
[in]emacThe pointer of the specified EMAC module
[in]u32eIntSelInterrupt type select
Returns
None

This macro enable specified EMAC interrupt.

Definition at line 200 of file emac.h.

◆ EMAC_ENABLE_MAGIC_PKT_WAKEUP

#define EMAC_ENABLE_MAGIC_PKT_WAKEUP ( )

Enable EMAC Magic Packet Wakeup function.

Parameters
None
Returns
None

Definition at line 91 of file emac.h.

◆ EMAC_ENABLE_RECV_BCASTPKT

#define EMAC_ENABLE_RECV_BCASTPKT ( )

Enable EMAC to receive broadcast packets.

Parameters
None
Returns
None

Definition at line 107 of file emac.h.

◆ EMAC_ENABLE_RECV_MCASTPKT

#define EMAC_ENABLE_RECV_MCASTPKT ( )

Enable EMAC to receive multicast packets.

Parameters
None
Returns
None

Definition at line 123 of file emac.h.

◆ EMAC_ENABLE_RX

#define EMAC_ENABLE_RX ( )

Enable EMAC Rx function.

Parameters
None
Returns
None

Definition at line 66 of file emac.h.

◆ EMAC_ENABLE_TX

#define EMAC_ENABLE_TX ( )

Enable EMAC Tx function.

Parameters
None
Returns
None

Definition at line 57 of file emac.h.

◆ EMAC_GET_ALARM_FLAG

#define EMAC_GET_ALARM_FLAG ( )

Check if EMAC time stamp alarm interrupt occurred or not.

Parameters
None
Returns
If time stamp alarm interrupt occurred or not
Return values
0Alarm interrupt does not occur
1Alarm interrupt occurred

Definition at line 141 of file emac.h.

◆ EMAC_GET_INT_FLAG

#define EMAC_GET_INT_FLAG (   emac,
  u32eIntTypeFlag 
)

Get specified interrupt flag/status.

Parameters
[in]emacThe pointer of the specified EMAC module
[in]u32eIntTypeFlagInterrupt Type Flag, should be
Returns
None

This macro get specified interrupt flag or interrupt indicator status.

Definition at line 274 of file emac.h.

◆ EMAC_TRIGGER_RX

#define EMAC_TRIGGER_RX ( )    do{EMAC->RXST = 0UL;}while(0)

Trigger EMAC Rx function.

Parameters
None
Returns
None

Definition at line 156 of file emac.h.

◆ EMAC_TRIGGER_TX

#define EMAC_TRIGGER_TX ( )    do{EMAC->TXST = 0UL;}while(0)

Trigger EMAC Tx function.

Parameters
None
Returns
None

Definition at line 163 of file emac.h.

Function Documentation

◆ EMAC_CheckLinkStatus()

uint32_t EMAC_CheckLinkStatus ( void  )

Check Ethernet link status.

Parameters
None
Returns
Current link status, could be one of following value.
Note
This API should be called regularly to sync EMAC setting with real connection status

Definition at line 965 of file emac.c.

◆ EMAC_ClaimFreeTXBuf()

uint8_t * EMAC_ClaimFreeTXBuf ( void  )

Get avaiable TX buffer address.

Parameters
None
Returns
An avaiable TX buffer.
Note
This API should be called before EMAC_SendPkt_WoCopy calling. Caller will do data-copy.

Definition at line 1098 of file emac.c.

◆ EMAC_Close()

void EMAC_Close ( void  )

This function stop all receive and transmit activity and disable MAC interface.

Parameters
None
Returns
None

Definition at line 420 of file emac.c.

◆ EMAC_DisableAlarm()

void EMAC_DisableAlarm ( void  )

Disable alarm function.

Parameters
None
Returns
None

Definition at line 926 of file emac.c.

◆ EMAC_DisableCamEntry()

void EMAC_DisableCamEntry ( uint32_t  u32Entry)

Disable a specified CAM entry.

Parameters
[in]u32EntryCAM entry to be disabled
Returns
None

Definition at line 468 of file emac.c.

◆ EMAC_DisableTS()

void EMAC_DisableTS ( void  )

Disable IEEE1588 time stamp function.

Parameters
None
Returns
None

Definition at line 872 of file emac.c.

◆ EMAC_EnableAlarm()

void EMAC_EnableAlarm ( uint32_t  u32Sec,
uint32_t  u32Nsec 
)

Enable alarm function and set alarm time.

Parameters
[in]u32SecSecond value to trigger alarm
[in]u32NsecNano second value to trigger alarm
Returns
None

Definition at line 912 of file emac.c.

◆ EMAC_EnableCamEntry()

void EMAC_EnableCamEntry ( uint32_t  u32Entry,
uint8_t  pu8MacAddr[] 
)

Fill a CAM entry for MAC address comparison.

Parameters
[in]u32EntryMAC entry to fill. Entry 0 is used to store device MAC address, do not overwrite the setting in it.
[in]pu8MacAddrPointer to uint8_t array holds MAC address
Returns
None

Definition at line 444 of file emac.c.

◆ EMAC_EnableTS()

void EMAC_EnableTS ( uint32_t  u32Sec,
uint32_t  u32Nsec 
)

Enable IEEE1588 time stamp function and set current time.

Parameters
[in]u32SecSecond value
[in]u32NsecNano second value
Returns
None

Definition at line 844 of file emac.c.

◆ EMAC_FillCamEntry()

int32_t EMAC_FillCamEntry ( uint8_t  pu8MacAddr[])

Fill a MAC address to list and enable.

Parameters
pu8MacAddrA MAC address
Returns
The CAM index
Return values
-1Failed to fill the MAC address.
0~(EMAC_CAMENTRY_NB-1)The index number of entry location.

Definition at line 1011 of file emac.c.

◆ EMAC_GetAvailRXBufSize()

uint32_t EMAC_GetAvailRXBufSize ( void  )

Get data length of avaiable RX buffer.

Parameters
None
Returns
An data length of avaiable RX buffer.
Note
This API should be called before EMAC_RecvPktDone_WoTrigger calling. Caller will do data-copy.

Definition at line 1118 of file emac.c.

◆ EMAC_GetTime()

void EMAC_GetTime ( uint32_t *  pu32Sec,
uint32_t *  pu32Nsec 
)

Get current time stamp.

Parameters
[out]pu32SecCurrent second value
[out]pu32NsecCurrent nano second value
Returns
None

Definition at line 883 of file emac.c.

◆ EMAC_Open()

void EMAC_Open ( uint8_t *  pu8MacAddr)

Initialize EMAC interface, including descriptors, MAC address, and PHY.

Parameters
[in]pu8MacAddrPointer to uint8_t array holds MAC address
Returns
None
Note
This API configures EMAC to receive all broadcast and multicast packets, but could configure to other settings with EMAC_ENABLE_RECV_BCASTPKT, EMAC_DISABLE_RECV_BCASTPKT, EMAC_ENABLE_RECV_MCASTPKT, and EMAC_DISABLE_RECV_MCASTPKT
Receive(RX) and transmit(TX) are not enabled yet, application must call EMAC_ENABLE_RX and EMAC_ENABLE_TX to enable receive and transmit function.

Definition at line 381 of file emac.c.

◆ EMAC_PhyInit()

void EMAC_PhyInit ( void  )

◆ EMAC_RecvPkt()

uint32_t EMAC_RecvPkt ( uint8_t *  pu8Data,
uint32_t *  pu32Size 
)

Receive an Ethernet packet.

Parameters
[in]pu8DataPointer to a buffer to store received packet (4 byte CRC removed)
[in]pu32SizeReceived packet size (without 4 byte CRC).
Returns
Packet receive success or not
Return values
0No packet available for receive
1A packet is received
Note
Return 0 doesn't guarantee the packet will be sent and received successfully.

Definition at line 483 of file emac.c.

◆ EMAC_RecvPktDone()

void EMAC_RecvPktDone ( void  )

Clean up process after a packet is received.

Parameters
None
Returns
None

EMAC Rx interrupt service routine must call this API to release the resource use by receive process

Note
Application can only call this function once every time EMAC_RecvPkt or EMAC_RecvPktTS returns 1

Definition at line 614 of file emac.c.

◆ EMAC_RecvPktDoneWoRxTrigger()

void EMAC_RecvPktDoneWoRxTrigger ( void  )

Clean up process after a packet is received.

Parameters
None
Returns
None

Caller must call the function to release the resource.

Note
Application can only call this function once every time EMAC_RecvPkt or EMAC_RecvPktTS returns 1
This function is without doing EMAC_TRIGGER_RX.

Definition at line 1150 of file emac.c.

◆ 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.

Parameters
[out]pu8DataPointer to a buffer to store received packet (4 byte CRC removed)
[out]pu32SizeReceived packet size (without 4 byte CRC).
[out]pu32SecSecond value while packet received
[out]pu32NsecNano second value while packet received
Returns
Packet receive success or not
Return values
0No packet available for receive
1A packet is received
Note
Return 0 doesn't guarantee the packet will be sent and received successfully.
Largest Ethernet packet is 1514 bytes after stripped CRC, application must give a buffer large enough to store such packet

Definition at line 548 of file emac.c.

◆ EMAC_SendPkt()

uint32_t EMAC_SendPkt ( uint8_t *  pu8Data,
uint32_t  u32Size 
)

Send an Ethernet packet.

Parameters
[in]pu8DataPointer to a buffer holds the packet to transmit
[in]u32SizePacket size (without 4 byte CRC).
Returns
Packet transmit success or not
Return values
0Transmit failed due to descriptor unavailable.
1Packet is copied to descriptor and triggered to transmit.
Note
Return 1 doesn't guarantee the packet will be sent and received successfully.

Definition at line 646 of file emac.c.

◆ EMAC_SendPktDone()

uint32_t EMAC_SendPktDone ( void  )

Clean up process after packet(s) are sent.

Parameters
None
Returns
Number of packet sent between two function calls

EMAC Tx interrupt service routine must call this API or EMAC_SendPktDoneTS to release the resource use by transmit process

Definition at line 686 of file emac.c.

◆ 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.

Parameters
[in]pu32SecSecond value while packet sent
[in]pu32NsecNano second value while packet sent
Returns
If a packet sent successfully
Return values
0No packet sent successfully, and the value in *pu32Sec and *pu32Nsec are meaningless
1A packet sent successfully, and the value in *pu32Sec and *pu32Nsec is the time stamp while packet sent

EMAC Tx interrupt service routine must call this API or EMAC_SendPktDone to release the resource use by transmit process

Definition at line 769 of file emac.c.

◆ EMAC_SendPktWoCopy()

uint32_t EMAC_SendPktWoCopy ( uint32_t  u32Size)

Send an Ethernet packet.

Parameters
[in]u32SizePacket size (without 4 byte CRC).
Returns
Packet transmit success or not
Return values
0Transmit failed due to descriptor unavailable.
1Triggered to transmit.
Note
Return 1 doesn't guarantee the packet will be sent and received successfully.

Definition at line 1062 of file emac.c.

◆ EMAC_SetMacAddr()

void EMAC_SetMacAddr ( uint8_t *  pu8MacAddr)

Set the device MAC address.

Parameters
[in]pu8MacAddrPointer to uint8_t array holds MAC address
Returns
None

Definition at line 432 of file emac.c.

◆ EMAC_SetTime()

void EMAC_SetTime ( uint32_t  u32Sec,
uint32_t  u32Nsec 
)

Set current time stamp.

Parameters
[in]u32SecSecond value
[in]u32NsecNano second value
Returns
None

Definition at line 896 of file emac.c.

◆ EMAC_UpdateTime()

void EMAC_UpdateTime ( uint32_t  u32Neg,
uint32_t  u32Sec,
uint32_t  u32Nsec 
)

Add a offset to current time.

Parameters
[in]u32NegOffset is negative value (u32Neg == 1) or positive value (u32Neg == 0).
[in]u32SecSecond value to add to current time
[in]u32NsecNano second value to add to current time
Returns
None

Definition at line 940 of file emac.c.