![]() |
S32 SDK
|
In order to use the ENET driver in your application, the ENET_DRV_Init() function should be called prior to using the rest of the API. The parameters of this function specify:
The configuration of the module is specified through the enet_config_t structure and contains:
The buffers configuration is specified through the enet_buffer_config_t structure and contains:
In order to de-initialize the driver, the ENET_DRV_Deinit() function shall be used. This function will disable the ENET interrupts and the module, so calling other ENET driver functions after de-initializing the driver will have undefined behavior. In order to use the driver again, ENET_DRV_Init() should be called.
Examples:
Initializing the module
Sending a frame
Receiving a frame - polling method
Receiving a frame - interrupt method
Data Structures | |
struct | enet_buffer_t |
Send/Receive buffer information for the user Implements : enet_buffer_t_Class. More... | |
struct | enet_buffer_config_t |
Defines the ENET buffer descriptors ring configuration structure Implements : enet_buffer_config_t_Class. More... | |
struct | enet_config_t |
Defines the ENET module configuration structure Implements : enet_config_t_Class. More... | |
struct | enet_state_t |
Internal driver state structure Implements : enet_state_t_Class. More... | |
Macros | |
#define | ENET_FRAME_MAX_FRAMELEN 1518U |
Defines the maximum Ethernet frame size. More... | |
#define | ENET_MIN_BUFFERSIZE 64U |
ENET minimum buffer size. More... | |
#define | ENET_BUFF_ALIGN(x) (((uint32_t)(x) + (FEATURE_ENET_BUFF_ALIGNMENT - 1)) & ~(FEATURE_ENET_BUFF_ALIGNMENT - 1)) |
Definitions used for aligning the data buffers. More... | |
#define | ENET_BUFF_IS_ALIGNED(x) (((uint32_t)(x) & ~(FEATURE_ENET_BUFF_ALIGNMENT - 1)) != 0) |
#define | ENET_BUFFDESCR_ALIGN(x) (((uint32_t)(x) + (FEATURE_ENET_BUFFDESCR_ALIGNMENT - 1)) & ~(FEATURE_ENET_BUFFDESCR_ALIGNMENT - 1)) |
Definitions used for aligning the buffer descriptors. More... | |
#define | ENET_BUFFDESCR_IS_ALIGNED(x) (((uint32_t)(x) & ~(FEATURE_ENET_BUFFDESCR_ALIGNMENT - 1)) != 0) |
Typedefs | |
typedef void(* | enet_callback_t) (uint8_t instance, enet_event_t event) |
Callback function invoked when one of the events in "enet_event_t" is encountered Implements : enet_callback_t_Class. More... | |
Initialization and De-initialization | |
void | ENET_DRV_GetDefaultConfig (enet_config_t *config) |
Gets the default configuration structure. More... | |
void | ENET_DRV_Init (uint8_t instance, enet_state_t *state, const enet_config_t *config, const enet_buffer_config_t *bufferConfig, uint8_t *macAddr) |
Initializes the ENET module. More... | |
void | ENET_DRV_Deinit (uint8_t instance) |
Deinitializes the ENET module. More... | |
Transmission and reception operations | |
status_t | ENET_DRV_ReadFrame (uint8_t instance, enet_buffer_t *buff) |
Reads a received Ethernet frame. More... | |
void | ENET_DRV_ProvideRxBuff (uint8_t instance, enet_buffer_t *buff) |
Provides a receive buffer to be used by the driver for reception. More... | |
status_t | ENET_DRV_SendFrame (uint8_t instance, enet_buffer_t *buff) |
Sends an Ethernet frame. More... | |
status_t | ENET_DRV_GetTransmitStatus (uint8_t instance, enet_buffer_t *buff) |
Checks if the transmission of a buffer is complete. More... | |
MDIO configuration and operation | |
void | ENET_DRV_EnableMDIO (uint8_t instance, bool miiPreambleDisabled) |
Enables the MDIO interface. More... | |
status_t | ENET_DRV_MDIORead (uint8_t instance, uint8_t phyAddr, uint8_t phyReg, uint16_t *data, uint32_t timeoutMs) |
Reads the selected register of the PHY. More... | |
status_t | ENET_DRV_MDIOWrite (uint8_t instance, uint8_t phyAddr, uint8_t phyReg, uint16_t data, uint32_t timeoutMs) |
Writes the selected register of the PHY. More... | |
MAC Address configuration | |
void | ENET_DRV_SetMacAddr (uint8_t instance, uint8_t *macAddr) |
Configures the physical address of the MAC. More... | |
void | ENET_DRV_GetMacAddr (uint8_t instance, uint8_t *macAddr) |
Gets the physical address of the MAC. More... | |
void | ENET_DRV_SetUnicastForward (uint8_t instance, uint8_t *macAddr, bool enable) |
Enables/Disables forwarding of unicast traffic having a specific MAC address as destination. More... | |
void | ENET_DRV_SetMulticastForward (uint8_t instance, uint8_t *macAddr, bool enable) |
Enables/Disables forwarding of multicast traffic having a specific MAC address as destination. More... | |
void | ENET_DRV_SetMulticastForwardAll (uint8_t instance, bool enable) |
Enables/Disables forwarding of the multicast traffic, irrespective of the destination MAC address. More... | |
Other basic operations | |
void | ENET_DRV_SetSleepMode (uint8_t instance, bool enable) |
Sets the MAC in sleep mode or normal mode. More... | |
void | ENET_DRV_ConfigCounters (uint8_t instance, bool enable) |
Enables/Disables the MIB counters. More... | |
uint32_t | ENET_DRV_GetCounter (uint8_t instance, enet_counter_t counter) |
Gets statistics from the specified counter. More... | |
#define ENET_BUFF_ALIGN | ( | x | ) | (((uint32_t)(x) + (FEATURE_ENET_BUFF_ALIGNMENT - 1)) & ~(FEATURE_ENET_BUFF_ALIGNMENT - 1)) |
Definitions used for aligning the data buffers.
Definition at line 45 of file enet_driver.h.
#define ENET_BUFF_IS_ALIGNED | ( | x | ) | (((uint32_t)(x) & ~(FEATURE_ENET_BUFF_ALIGNMENT - 1)) != 0) |
Definition at line 46 of file enet_driver.h.
#define ENET_BUFFDESCR_ALIGN | ( | x | ) | (((uint32_t)(x) + (FEATURE_ENET_BUFFDESCR_ALIGNMENT - 1)) & ~(FEATURE_ENET_BUFFDESCR_ALIGNMENT - 1)) |
Definitions used for aligning the buffer descriptors.
Definition at line 49 of file enet_driver.h.
#define ENET_BUFFDESCR_IS_ALIGNED | ( | x | ) | (((uint32_t)(x) & ~(FEATURE_ENET_BUFFDESCR_ALIGNMENT - 1)) != 0) |
Definition at line 50 of file enet_driver.h.
#define ENET_FRAME_MAX_FRAMELEN 1518U |
Defines the maximum Ethernet frame size.
Definition at line 40 of file enet_driver.h.
#define ENET_MIN_BUFFERSIZE 64U |
ENET minimum buffer size.
Definition at line 42 of file enet_driver.h.
typedef void(* enet_callback_t) (uint8_t instance, enet_event_t event) |
Callback function invoked when one of the events in "enet_event_t" is encountered Implements : enet_callback_t_Class.
Definition at line 221 of file enet_driver.h.
enum enet_counter_t |
Statistics counters enumeration Implements : enet_counter_t_Class.
Definition at line 277 of file enet_driver.h.
enum enet_event_t |
Send/Receive internal buffer descriptor Implements : enet_buffer_descriptor_t_Class.
Event specifier for the callback function Implements : enet_event_t_Class
Enumerator | |
---|---|
ENET_RX_EVENT | |
ENET_TX_EVENT | |
ENET_ERR_EVENT | |
ENET_WAKE_UP_EVENT |
Definition at line 209 of file enet_driver.h.
Interrupt sources Implements : enet_interrupt_enable_t_Class.
Definition at line 112 of file enet_driver.h.
enum enet_mii_duplex_t |
Media Independent Interface full-/half-duplex selection Implements : enet_mii_duplex_t_Class.
Enumerator | |
---|---|
ENET_MII_HALF_DUPLEX |
Half-duplex mode. |
ENET_MII_FULL_DUPLEX |
Full-duplex mode. |
Definition at line 76 of file enet_driver.h.
enum enet_mii_mode_t |
Media Independent Interface mode selection Implements : enet_mii_mode_t_Class.
Enumerator | |
---|---|
ENET_MII_MODE |
MII mode for data interface. |
ENET_RMII_MODE |
RMII mode for data interface. |
Definition at line 56 of file enet_driver.h.
enum enet_mii_speed_t |
Media Independent Interface speed selection Implements : enet_mii_speed_t_Class.
Enumerator | |
---|---|
ENET_MII_SPEED_10M |
Speed 10 Mbps. |
ENET_MII_SPEED_100M |
Speed 100 Mbps. |
Definition at line 66 of file enet_driver.h.
Receive accelerator configurations Implements : enet_rx_accelerator_t_Class.
Enumerator | |
---|---|
ENET_RX_ACCEL_REMOVE_PAD | |
ENET_RX_ACCEL_ENABLE_IP_CHECK | |
ENET_RX_ACCEL_ENABLE_PROTO_CHECK | |
ENET_RX_ACCEL_ENABLE_MAC_CHECK | |
ENET_RX_ACCEL_ENABLE_SHIFT16 |
Definition at line 164 of file enet_driver.h.
Special receive control configurations Implements : enet_rx_special_config_t_Class.
Definition at line 86 of file enet_driver.h.
Transmit accelerator configurations Implements : enet_tx_accelerator_t_Class.
Enumerator | |
---|---|
ENET_TX_ACCEL_ENABLE_SHIFT16 | |
ENET_TX_ACCEL_INSERT_IP_CHECKSUM | |
ENET_TX_ACCEL_INSERT_PROTO_CHECKSUM |
Definition at line 153 of file enet_driver.h.
Special transmit control configurations Implements : enet_tx_special_config_t_Class.
Enumerator | |
---|---|
ENET_TX_CONFIG_DISABLE_CRC_APPEND | |
ENET_TX_CONFIG_ENABLE_MAC_ADDR_INSERTION |
Definition at line 102 of file enet_driver.h.
void ENET_DRV_ConfigCounters | ( | uint8_t | instance, |
bool | enable | ||
) |
Enables/Disables the MIB counters.
Note: When enabling the counters, their values are reset.
[in] | instance | Instance number |
[in] | enable | Enable/Disable MIB counters |
Definition at line 737 of file enet_driver.c.
void ENET_DRV_Deinit | ( | uint8_t | instance | ) |
Deinitializes the ENET module.
This function disables the interrupts and then disables the ENET module.
[in] | instance | Instance number |
Definition at line 225 of file enet_driver.c.
void ENET_DRV_EnableMDIO | ( | uint8_t | instance, |
bool | miiPreambleDisabled | ||
) |
Enables the MDIO interface.
[in] | instance | Instance number |
[in] | miiPreambleDisabled | Enables/disables prepending a preamble to the MII management frame. |
Definition at line 444 of file enet_driver.c.
uint32_t ENET_DRV_GetCounter | ( | uint8_t | instance, |
enet_counter_t | counter | ||
) |
Gets statistics from the specified counter.
[in] | instance | Instance number |
[in] | counter | The counter to be read |
Definition at line 768 of file enet_driver.c.
void ENET_DRV_GetDefaultConfig | ( | enet_config_t * | config | ) |
Gets the default configuration structure.
This function gets the default configuration structure, with the following settings:
[out] | config | The configuration structure |
Definition at line 113 of file enet_driver.c.
void ENET_DRV_GetMacAddr | ( | uint8_t | instance, |
uint8_t * | macAddr | ||
) |
Gets the physical address of the MAC.
[in] | instance | Instance number |
[out] | macAddr | The physical address of the MAC |
Definition at line 589 of file enet_driver.c.
status_t ENET_DRV_GetTransmitStatus | ( | uint8_t | instance, |
enet_buffer_t * | buff | ||
) |
Checks if the transmission of a buffer is complete.
This function checks if the transmission of the given buffer is complete.
[in] | instance | Instance number |
[in] | buff | The transmit buffer for which the status shall be checked |
Definition at line 358 of file enet_driver.c.
void ENET_DRV_Init | ( | uint8_t | instance, |
enet_state_t * | state, | ||
const enet_config_t * | config, | ||
const enet_buffer_config_t * | bufferConfig, | ||
uint8_t * | macAddr | ||
) |
Initializes the ENET module.
This function initializes and enables the ENET module, configuring receive and transmit control settings, the receive and transmit descriptors rings, and the MAC physical address.
[in] | instance | Instance number |
[in] | state | Pointer to the state structure which will be used for holding the internal state of the driver. |
[in] | config | The module configuration structure |
[in] | bufferConfig | The buffer descriptors configuration structure |
[in] | macAddr | The physical address of the MAC |
Definition at line 147 of file enet_driver.c.
status_t ENET_DRV_MDIORead | ( | uint8_t | instance, |
uint8_t | phyAddr, | ||
uint8_t | phyReg, | ||
uint16_t * | data, | ||
uint32_t | timeoutMs | ||
) |
Reads the selected register of the PHY.
[in] | instance | Instance number |
[in] | phyAddr | PHY device address |
[in] | phyReg | PHY register address |
[out] | data | Data read from the PHY |
[in] | timeoutMs | Timeout for the read operation (in milliseconds) |
Definition at line 515 of file enet_driver.c.
status_t ENET_DRV_MDIOWrite | ( | uint8_t | instance, |
uint8_t | phyAddr, | ||
uint8_t | phyReg, | ||
uint16_t | data, | ||
uint32_t | timeoutMs | ||
) |
Writes the selected register of the PHY.
[in] | instance | Instance number |
[in] | phyAddr | PHY device address |
[in] | phyReg | PHY register address |
[in] | data | Data to be written in the specified register of the PHY |
[in] | timeoutMs | Timeout for the write operation (in milliseconds) |
Definition at line 473 of file enet_driver.c.
void ENET_DRV_ProvideRxBuff | ( | uint8_t | instance, |
enet_buffer_t * | buff | ||
) |
Provides a receive buffer to be used by the driver for reception.
This function provides a buffer which can further be used by the reception mechanism in order to store the received data.
Note: The application can either provide a buffer previously obtained in a ENET_DRV_ReadFrame call (when it is no longer needed after being fully processed), or allocate a new buffer, pointing to a memory area having the required alignment (see FEATURE_ENET_BUFF_ALIGNMENT). The former approach is recommended as it has a simpler usage model and re-uses the same initial memory range for the entire driver lifetime operation. The later approach could provide more flexibility, but since it involves constant memory free/alloc operations it is only recommended with an efficient pool-based memory allocator.
Important: The driver does not ensure synchronization between different threads trying to provide a buffer at the same time. This synchronization shall be implemented by the application.
Important: The application is responsible for providing one Rx buffer for every frame it receives, otherwise the reception ring can fill-up, affecting further reception.
Usage example:
stat = ENET_DRV_ReadFrame(INST_ETHERNET1, &rxBuff);
if (stat == STATUS_SUCCESS) { process_buffer(&rxBuff); ENET_DRV_ProvideRxBuff(INST_ETHERNET1, &rxBuff); }
[in] | instance | Instance number |
[in] | buff | The buffer to be added to the reception ring |
Definition at line 400 of file enet_driver.c.
status_t ENET_DRV_ReadFrame | ( | uint8_t | instance, |
enet_buffer_t * | buff | ||
) |
Reads a received Ethernet frame.
This function reads the first received Ethernet frame in the Rx queue. The buffer received as parameter will be updated by the driver and the .data field will point to a memory area containing the frame data.
Note: Once the application finished processing the buffer, it could be reused by the driver for further receptions by invoking ENET_DRV_ProvideRxBuff.
Important: The driver does not ensure synchronization between different threads trying to read a frame at the same time. This synchronization shall be implemented by the application.
[in] | instance | Instance number |
[out] | buff | The buffer containing the frame |
Definition at line 261 of file enet_driver.c.
status_t ENET_DRV_SendFrame | ( | uint8_t | instance, |
enet_buffer_t * | buff | ||
) |
Sends an Ethernet frame.
This function sends an Ethernet frame, contained in the buffer received as parameter.
Note: Since the transmission of the frame is not complete when this function returns, the application must not change/alter/re-use the provided buffer until after a call to ENET_DRV_GetTransmitStatus for the same buffer returns STATUS_SUCCESS.
Important: The driver does not ensure synchronization between different threads trying to send a frame at the same time. This synchronization shall be implemented by the application.
[in] | instance | Instance number |
[in] | buff | The buffer containing the frame |
Definition at line 306 of file enet_driver.c.
void ENET_DRV_SetMacAddr | ( | uint8_t | instance, |
uint8_t * | macAddr | ||
) |
Configures the physical address of the MAC.
[in] | instance | Instance number |
[in] | macAddr | The MAC address to be configured |
Definition at line 558 of file enet_driver.c.
void ENET_DRV_SetMulticastForward | ( | uint8_t | instance, |
uint8_t * | macAddr, | ||
bool | enable | ||
) |
Enables/Disables forwarding of multicast traffic having a specific MAC address as destination.
[in] | instance | Instance number |
[in] | macAddr | The physical address |
[in] | enable | If true, the application will receive all the multicast traffic having as destination address the provided MAC address; if false, stop forwarding this kind of traffic |
Definition at line 652 of file enet_driver.c.
void ENET_DRV_SetMulticastForwardAll | ( | uint8_t | instance, |
bool | enable | ||
) |
Enables/Disables forwarding of the multicast traffic, irrespective of the destination MAC address.
[in] | instance | Instance number |
[in] | enable | If true, the application will receive all the multicast traffic; if false, stop forwarding this kind of traffic |
Definition at line 683 of file enet_driver.c.
void ENET_DRV_SetSleepMode | ( | uint8_t | instance, |
bool | enable | ||
) |
Sets the MAC in sleep mode or normal mode.
[in] | instance | Instance number |
[in] | enable | If true, set MAC in sleep mode; if false, set MAC in normal mode |
Definition at line 711 of file enet_driver.c.
void ENET_DRV_SetUnicastForward | ( | uint8_t | instance, |
uint8_t * | macAddr, | ||
bool | enable | ||
) |
Enables/Disables forwarding of unicast traffic having a specific MAC address as destination.
[in] | instance | Instance number |
[in] | macAddr | The physical address |
[in] | enable | If true, the application will receive all the unicast traffic having as destination address the provided MAC address; if false, stop forwarding this kind of traffic |
Definition at line 621 of file enet_driver.c.