NXP's driver library for LPC17xx, ported to mbed's online compiler. Not tested! I had to fix a lot of warings and found a couple of pretty obvious bugs, so the chances are there are more. Original: http://ics.nxp.com/support/documents/microcontrollers/zip/lpc17xx.cmsis.driver.library.zip

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

EMAC_Public_Functions

EMAC_Public_Functions
[EMAC]

Functions

Status EMAC_Init (EMAC_CFG_Type *EMAC_ConfigStruct)
 Initializes the EMAC peripheral according to the specified parameters in the EMAC_ConfigStruct.
void EMAC_DeInit (void)
 De-initializes the EMAC peripheral registers to their default reset values.
int32_t EMAC_CheckPHYStatus (uint32_t ulPHYState)
 Check specified PHY status in EMAC peripheral.
int32_t EMAC_SetPHYMode (uint32_t ulPHYMode)
 Set specified PHY mode in EMAC peripheral.
int32_t EMAC_UpdatePHYStatus (void)
 Auto-Configures value for the EMAC configuration register to match with current PHY mode.
void EMAC_SetHashFilter (uint8_t dstMAC_addr[], FunctionalState NewState)
 Enable/Disable hash filter functionality for specified destination MAC address in EMAC module.
int32_t EMAC_CRCCalc (uint8_t frame_no_fcs[], int32_t frame_len)
 Calculates CRC code for number of bytes in the frame.
void EMAC_SetFilterMode (uint32_t ulFilterMode, FunctionalState NewState)
 Enable/Disable Filter mode for each specified type EMAC peripheral.
FlagStatus EMAC_GetWoLStatus (uint32_t ulWoLMode)
 Get status of Wake On LAN Filter for each specified type in EMAC peripheral, clear this status if it is set.
void EMAC_WritePacketBuffer (EMAC_PACKETBUF_Type *pDataStruct)
 Write data to Tx packet data buffer at current index due to TxProduceIndex.
void EMAC_ReadPacketBuffer (EMAC_PACKETBUF_Type *pDataStruct)
 Read data from Rx packet data buffer at current index due to RxConsumeIndex.
void EMAC_StandardIRQHandler (void)
 Standard EMAC IRQ Handler.
void EMAC_SetupIntCBS (uint32_t ulIntType, EMAC_IntCBSType *pfnIntCb)
 Setup/register Call-back function for each interrupt type in EMAC module.
void EMAC_IntCmd (uint32_t ulIntType, FunctionalState NewState)
 Enable/Disable interrupt for each type in EMAC.
IntStatus EMAC_IntGetStatus (uint32_t ulIntType)
 Check whether if specified interrupt flag is set or not for each interrupt type in EMAC and clear interrupt pending if it is set.
Bool EMAC_CheckReceiveIndex (void)
 Check whether if the current RxConsumeIndex is not equal to the current RxProduceIndex.
Bool EMAC_CheckTransmitIndex (void)
 Check whether if the current TxProduceIndex is not equal to the current RxProduceIndex - 1.
FlagStatus EMAC_CheckReceiveDataStatus (uint32_t ulRxStatType)
 Get current status value of receive data (due to RxConsumeIndex)
uint32_t EMAC_GetReceiveDataSize (void)
 Get size of current Received data in received buffer (due to RxConsumeIndex)
void EMAC_UpdateRxConsumeIndex (void)
 Increase the RxConsumeIndex (after reading the Receive buffer to release the Receive buffer) and wrap-around the index if it reaches the maximum Receive Number.
void EMAC_UpdateTxProduceIndex (void)
 Increase the TxProduceIndex (after writting to the Transmit buffer to enable the Transmit buffer) and wrap-around the index if it reaches the maximum Transmit Number.

Function Documentation

int32_t EMAC_CheckPHYStatus ( uint32_t  ulPHYState )

Check specified PHY status in EMAC peripheral.

Parameters:
[in]ulPHYStateSpecified PHY Status Type, should be:

  • EMAC_PHY_STAT_LINK: Link Status
  • EMAC_PHY_STAT_SPEED: Speed Status
  • EMAC_PHY_STAT_DUP: Duplex Status
Returns:
Status of specified PHY status (0 or 1). (-1) if error.

Note: For EMAC_PHY_STAT_LINK, return value:

  • 0: Link Down
  • 1: Link Up For EMAC_PHY_STAT_SPEED, return value:
  • 0: 10Mbps
  • 1: 100Mbps For EMAC_PHY_STAT_DUP, return value:
  • 0: Half-Duplex
  • 1: Full-Duplex

Definition at line 375 of file lpc17xx_emac.c.

FlagStatus EMAC_CheckReceiveDataStatus ( uint32_t  ulRxStatType )

Get current status value of receive data (due to RxConsumeIndex)

Parameters:
[in]ulRxStatTypeReceived Status type, should be one of following:

  • EMAC_RINFO_CTRL_FRAME: Control Frame
  • EMAC_RINFO_VLAN: VLAN Frame
  • EMAC_RINFO_FAIL_FILT: RX Filter Failed
  • EMAC_RINFO_MCAST: Multicast Frame
  • EMAC_RINFO_BCAST: Broadcast Frame
  • EMAC_RINFO_CRC_ERR: CRC Error in Frame
  • EMAC_RINFO_SYM_ERR: Symbol Error from PHY
  • EMAC_RINFO_LEN_ERR: Length Error
  • EMAC_RINFO_RANGE_ERR: Range error(exceeded max size)
  • EMAC_RINFO_ALIGN_ERR: Alignment error
  • EMAC_RINFO_OVERRUN: Receive overrun
  • EMAC_RINFO_NO_DESCR: No new Descriptor available
  • EMAC_RINFO_LAST_FLAG: last Fragment in Frame
  • EMAC_RINFO_ERR: Error Occurred (OR of all error)
Returns:
Current value of receive data (due to RxConsumeIndex)

Definition at line 923 of file lpc17xx_emac.c.

Bool EMAC_CheckReceiveIndex ( void   )

Check whether if the current RxConsumeIndex is not equal to the current RxProduceIndex.

Parameters:
[in]None
Returns:
TRUE if they're not equal, otherwise return FALSE

Note: In case the RxConsumeIndex is not equal to the RxProduceIndex, it means there're available data has been received. They should be read out and released the Receive Data Buffer by updating the RxConsumeIndex value.

Definition at line 873 of file lpc17xx_emac.c.

Bool EMAC_CheckTransmitIndex ( void   )

Check whether if the current TxProduceIndex is not equal to the current RxProduceIndex - 1.

Parameters:
[in]None
Returns:
TRUE if they're not equal, otherwise return FALSE

Note: In case the RxConsumeIndex is equal to the RxProduceIndex - 1, it means the transmit buffer is available and data can be written to transmit buffer to be sent.

Definition at line 893 of file lpc17xx_emac.c.

int32_t EMAC_CRCCalc ( uint8_t  frame_no_fcs[],
int32_t  frame_len 
)

Calculates CRC code for number of bytes in the frame.

Parameters:
[in]frame_no_fcsPointer to the first byte of the frame
[in]frame_lenlength of the frame without the FCS
Returns:
the CRC as a 32 bit integer

Definition at line 572 of file lpc17xx_emac.c.

void EMAC_DeInit ( void   )

De-initializes the EMAC peripheral registers to their default reset values.

Parameters:
[in]None
Returns:
None

Definition at line 343 of file lpc17xx_emac.c.

uint32_t EMAC_GetReceiveDataSize ( void   )

Get size of current Received data in received buffer (due to RxConsumeIndex)

Parameters:
[in]None
Returns:
Size of received data

Definition at line 937 of file lpc17xx_emac.c.

FlagStatus EMAC_GetWoLStatus ( uint32_t  ulWoLMode )

Get status of Wake On LAN Filter for each specified type in EMAC peripheral, clear this status if it is set.

Parameters:
[in]ulWoLModeWoL Filter mode, should be:

  • EMAC_WOL_UCAST: unicast frames caused WoL
  • EMAC_WOL_UCAST: broadcast frame caused WoL
  • EMAC_WOL_MCAST: multicast frame caused WoL
  • EMAC_WOL_UCAST_HASH: unicast frame that passes the imperfect hash filter caused WoL
  • EMAC_WOL_MCAST_HASH: multicast frame that passes the imperfect hash filter caused WoL
  • EMAC_WOL_PERFECT:perfect address matching filter caused WoL
  • EMAC_WOL_RX_FILTER: the receive filter caused WoL
  • EMAC_WOL_MAG_PACKET: the magic packet filter caused WoL
Returns:
SET/RESET

Definition at line 663 of file lpc17xx_emac.c.

Status EMAC_Init ( EMAC_CFG_Type EMAC_ConfigStruct )

Initializes the EMAC peripheral according to the specified parameters in the EMAC_ConfigStruct.

Parameters:
[in]EMAC_ConfigStructPointer to a EMAC_CFG_Type structure that contains the configuration information for the specified EMAC peripheral.
Returns:
None

Note: This function will initialize EMAC module according to procedure below:

  • Remove the soft reset condition from the MAC
  • Configure the PHY via the MIIM interface of the MAC
  • Select RMII mode
  • Configure the transmit and receive DMA engines, including the descriptor arrays
  • Configure the host registers (MAC1,MAC2 etc.) in the MAC
  • Enable the receive and transmit data paths In default state after initializing, only Rx Done and Tx Done interrupt are enabled, all remain interrupts are disabled (Ref. from LPC17xx UM)

Definition at line 247 of file lpc17xx_emac.c.

void EMAC_IntCmd ( uint32_t  ulIntType,
FunctionalState  NewState 
)

Enable/Disable interrupt for each type in EMAC.

Parameters:
[in]ulIntTypeInterrupt Type, should be:

  • EMAC_INT_RX_OVERRUN: Receive Overrun
  • EMAC_INT_RX_ERR: Receive Error
  • EMAC_INT_RX_FIN: Receive Descriptor Finish
  • EMAC_INT_RX_DONE: Receive Done
  • EMAC_INT_TX_UNDERRUN: Transmit Under-run
  • EMAC_INT_TX_ERR: Transmit Error
  • EMAC_INT_TX_FIN: Transmit descriptor finish
  • EMAC_INT_TX_DONE: Transmit Done
  • EMAC_INT_SOFT_INT: Software interrupt
  • EMAC_INT_WAKEUP: Wakeup interrupt
[in]NewStateNew State of this function, should be:

  • ENABLE.
  • DISABLE.
Returns:
None

Definition at line 826 of file lpc17xx_emac.c.

IntStatus EMAC_IntGetStatus ( uint32_t  ulIntType )

Check whether if specified interrupt flag is set or not for each interrupt type in EMAC and clear interrupt pending if it is set.

Parameters:
[in]ulIntTypeInterrupt Type, should be:

  • EMAC_INT_RX_OVERRUN: Receive Overrun
  • EMAC_INT_RX_ERR: Receive Error
  • EMAC_INT_RX_FIN: Receive Descriptor Finish
  • EMAC_INT_RX_DONE: Receive Done
  • EMAC_INT_TX_UNDERRUN: Transmit Under-run
  • EMAC_INT_TX_ERR: Transmit Error
  • EMAC_INT_TX_FIN: Transmit descriptor finish
  • EMAC_INT_TX_DONE: Transmit Done
  • EMAC_INT_SOFT_INT: Software interrupt
  • EMAC_INT_WAKEUP: Wakeup interrupt
Returns:
New state of specified interrupt (SET or RESET)

Definition at line 852 of file lpc17xx_emac.c.

void EMAC_ReadPacketBuffer ( EMAC_PACKETBUF_Type pDataStruct )

Read data from Rx packet data buffer at current index due to RxConsumeIndex.

Parameters:
[in]pDataStructPointer to a EMAC_PACKETBUF_Type structure data that contain specified information about Packet data buffer.
Returns:
None

Definition at line 705 of file lpc17xx_emac.c.

void EMAC_SetFilterMode ( uint32_t  ulFilterMode,
FunctionalState  NewState 
)

Enable/Disable Filter mode for each specified type EMAC peripheral.

Parameters:
[in]ulFilterModeFilter mode, should be:

  • EMAC_RFC_UCAST_EN: all frames of unicast types will be accepted
  • EMAC_RFC_BCAST_EN: broadcast frame will be accepted
  • EMAC_RFC_MCAST_EN: all frames of multicast types will be accepted
  • EMAC_RFC_UCAST_HASH_EN: The imperfect hash filter will be applied to unicast addresses
  • EMAC_RFC_MCAST_HASH_EN: The imperfect hash filter will be applied to multicast addresses
  • EMAC_RFC_PERFECT_EN: the destination address will be compared with the 6 byte station address programmed in the station address by the filter
  • EMAC_RFC_MAGP_WOL_EN: the result of the magic packet filter will generate a WoL interrupt when there is a match
  • EMAC_RFC_PFILT_WOL_EN: the result of the perfect address matching filter and the imperfect hash filter will generate a WoL interrupt when there is a match
[in]NewStateNew State of this command, should be:

  • ENABLE
  • DISABLE
Returns:
None

Definition at line 637 of file lpc17xx_emac.c.

void EMAC_SetHashFilter ( uint8_t  dstMAC_addr[],
FunctionalState  NewState 
)

Enable/Disable hash filter functionality for specified destination MAC address in EMAC module.

Parameters:
[in]dstMAC_addrPointer to the first MAC destination address, should be 6-bytes length, in order LSB to the MSB
[in]NewStateNew State of this command, should be:

  • ENABLE.
  • DISABLE.
Returns:
None

Note: The standard Ethernet cyclic redundancy check (CRC) function is calculated from the 6 byte destination address in the Ethernet frame (this CRC is calculated anyway as part of calculating the CRC of the whole frame), then bits [28:23] out of the 32 bits CRC result are taken to form the hash. The 6 bit hash is used to access the hash table: it is used as an index in the 64 bit HashFilter register that has been programmed with accept values. If the selected accept value is 1, the frame is accepted.

Definition at line 542 of file lpc17xx_emac.c.

int32_t EMAC_SetPHYMode ( uint32_t  ulPHYMode )

Set specified PHY mode in EMAC peripheral.

Parameters:
[in]ulPHYModeSpecified PHY mode, should be:

  • EMAC_MODE_AUTO
  • EMAC_MODE_10M_FULL
  • EMAC_MODE_10M_HALF
  • EMAC_MODE_100M_FULL
  • EMAC_MODE_100M_HALF
Returns:
Return (0) if no error, otherwise return (-1)

Definition at line 408 of file lpc17xx_emac.c.

void EMAC_SetupIntCBS ( uint32_t  ulIntType,
EMAC_IntCBSType pfnIntCb 
)

Setup/register Call-back function for each interrupt type in EMAC module.

Parameters:
[in]ulIntTypeInterrupt type, should be one of the following:

  • EMAC_INT_RX_OVERRUN: Receive Overrun
  • EMAC_INT_RX_ERR: Receive Error
  • EMAC_INT_RX_FIN: Receive Descriptor Finish
  • EMAC_INT_RX_DONE: Receive Done
  • EMAC_INT_TX_UNDERRUN: Transmit Under-run
  • EMAC_INT_TX_ERR: Transmit Error
  • EMAC_INT_TX_FIN: Transmit descriptor finish
  • EMAC_INT_TX_DONE: Transmit Done
  • EMAC_INT_SOFT_INT: Software interrupt
  • EMAC_INT_WAKEUP: Wakeup interrupt
[in]pfnIntCbPointer to Call-back function used for this interrupt type
Returns:
None

Definition at line 787 of file lpc17xx_emac.c.

void EMAC_StandardIRQHandler ( void   )

Standard EMAC IRQ Handler.

This sub-routine will check these following interrupt and call the call-back function if they're already installed:

  • Overrun Error interrupt in RX Queue
  • Receive Error interrupt: AlignmentError, RangeError, LengthError, SymbolError, CRCError or NoDescriptor or Overrun
  • RX Finished Process Descriptors interrupt (ProduceIndex == ConsumeIndex)
  • Receive Done interrupt
  • Transmit Under-run interrupt
  • Transmit errors interrupt : LateCollision, ExcessiveCollision and ExcessiveDefer, NoDescriptor or Under-run
  • TX Finished Process Descriptors interrupt (ProduceIndex == ConsumeIndex)
  • Transmit Done interrupt
  • Interrupt triggered by software
  • Interrupt triggered by a Wakeup event detected by the receive filter
    Parameters:
    [in]None
    Returns:
    None

Definition at line 740 of file lpc17xx_emac.c.

int32_t EMAC_UpdatePHYStatus ( void   )

Auto-Configures value for the EMAC configuration register to match with current PHY mode.

Parameters:
[in]None
Returns:
Return (0) if no error, otherwise return (-1)

Note: The EMAC configuration will be auto-configured:

  • Speed mode.
  • Half/Full duplex mode

Definition at line 481 of file lpc17xx_emac.c.

void EMAC_UpdateRxConsumeIndex ( void   )

Increase the RxConsumeIndex (after reading the Receive buffer to release the Receive buffer) and wrap-around the index if it reaches the maximum Receive Number.

Parameters:
[in]None
Returns:
None

Definition at line 951 of file lpc17xx_emac.c.

void EMAC_UpdateTxProduceIndex ( void   )

Increase the TxProduceIndex (after writting to the Transmit buffer to enable the Transmit buffer) and wrap-around the index if it reaches the maximum Transmit Number.

Parameters:
[in]None
Returns:
None

Definition at line 968 of file lpc17xx_emac.c.

void EMAC_WritePacketBuffer ( EMAC_PACKETBUF_Type pDataStruct )

Write data to Tx packet data buffer at current index due to TxProduceIndex.

Parameters:
[in]pDataStructPointer to a EMAC_PACKETBUF_Type structure data that contain specified information about Packet data buffer.
Returns:
None

Definition at line 682 of file lpc17xx_emac.c.