| CMSIS-Driver Peripheral Interface for Middleware and Application Code |

Loading...
Searching...
No Matches
Content | Data Structures | Enumerations
Ethernet Interface

Ethernet common definitions (Driver_ETH.h) More...

## Content
| Media Interface Types
| Ethernet Media Interface type.
| Ethernet MAC Interface
| Driver API for Ethernet MAC Peripheral (Driver_ETH_MAC.h)
| Ethernet PHY Interface
| Driver API for Ethernet PHY Peripheral (Driver_ETH_PHY.h)

## Data Structures
struct | ARM_ETH_LINK_INFO
| Ethernet link information. More...
struct | ARM_ETH_MAC_ADDR
| Ethernet MAC Address. More...

## Enumerations
enum | ARM_ETH_LINK_STATE { ARM_ETH_LINK_DOWN , ARM_ETH_LINK_UP }
| Ethernet link state. More...

## Description

Ethernet common definitions (Driver_ETH.h)

Ethernet is a networking technology for exchanging data packages between computer systems. Several microcontrollers integrate an Ethernet MAC (Media Access Control) data-link layer that interfaces to an Ethernet PHY (Physical Interface Transceiver).

Wikipedia offers more information about the Ethernet.

Block Diagram

The Ethernet PHY connects typically to the Ethernet MAC using an MII (Media Independent Interface) or RMII (Reduced Media Independent Interface).

Block Diagram of a typical Ethernet Interface

Ethernet API

The following header files define the Application Programming Interface (API) for the Ethernet interface:

- Driver_ETH.h : Common definitions of the Ethernet PHY and MAC part
- Driver_ETH_MAC.h : API for the Ethernet MAC
- Driver_ETH_PHY.h : API for the Ethernet PHY

The driver implementation of the Ethernet MAC is a typical part of a Device Family Pack (DFP) that supports the peripherals of the microcontroller family. The driver implementation of the Ethernet PHY is a typical part of a Network Software Pack, since PHY is typically not integrated into the microcontroller.

Note
  For parameters, the value marked with (default) is the setting after the driver initialization.

Driver Functions

The driver functions are published in the access struct as explained in Common Driver Functions

- ARM_DRIVER_ETH_MAC : access struct for Ethernet MAC driver functions.
- ARM_DRIVER_ETH_PHY : access struct for Ethernet PHY driver functions.

Both drivers are used in combination and usually the Ethernet MAC provides a media interface to the Ethernet PHY. A typical setup sequence for the drivers is shown below:

Example Code

The following example code shows the usage of the Ethernet interface.

extern ARM_DRIVER_ETH_MAC Driver_ETH_MAC0;
extern ARM_DRIVER_ETH_PHY Driver_ETH_PHY0;
static ARM_DRIVER_ETH_MAC *mac;
static ARM_DRIVER_ETH_PHY *phy;
static ARM_ETH_MAC_ADDR own_mac_address;
static ARM_ETH_MAC_CAPABILITIES capabilities;
void ethernet_mac_notify (uint32_t event) {
switch (event) {
:
}
}
void initialize_ethernet_interface (void) {
mac = &Driver_ETH_MAC0;
phy = &Driver_ETH_PHY0;
// Initialize Media Access Controller
capabilities = mac->GetCapabilities ();
mac->Initialize (ethernet_mac_notify);
mac->PowerControl (ARM_POWER_FULL);
if (capabilities.mac_address == 0) {
// populate own_mac_address with the address to use
mac->SetMacAddress(&own_mac_address);
}
else {
mac->GetMacAddress(&own_mac_address);
}
// Initialize Physical Media Interface
if (phy->Initialize (mac->PHY_Read, mac->PHY_Write) == ARM_DRIVER_OK) {
phy->PowerControl (ARM_POWER_FULL);
phy->SetInterface (capabilities.media_interface);
phy->SetMode (ARM_ETH_PHY_AUTO_NEGOTIATE);
}
:
:
}
static ARM_ETH_LINK_STATE ethernet_link; // current link status
void ethernet_check_link_status (void) {
ARM_ETH_LINK_STATE link;
link = phy->GetLinkState ();
if (link == ethernet_link) {
return; // link state unchanged
}
// link state changed
ethernet_link = link;
if (link == ARM_ETH_LINK_UP) { // start transfer
ARM_ETH_LINK_INFO info = phy->GetLinkInfo ();
mac->Control(ARM_ETH_MAC_CONFIGURE,
info.speed << ARM_ETH_MAC_SPEED_Pos |
info.duplex << ARM_ETH_MAC_DUPLEX_Pos |
ARM_ETH_MAC_ADDRESS_BROADCAST);
mac->Control(ARM_ETH_MAC_CONTROL_TX, 1);
mac->Control(ARM_ETH_MAC_CONTROL_RX, 1);
}
else { // stop transfer
mac->Control(ARM_ETH_MAC_FLUSH, ARM_ETH_MAC_FLUSH_TX | ARM_ETH_MAC_FLUSH_RX);
mac->Control(ARM_ETH_MAC_CONTROL_TX, 0);
mac->Control(ARM_ETH_MAC_CONTROL_RX, 0);
}
}
ARM_POWER_FULL
@ ARM_POWER_FULL
Power on: full operation at maximum performance.
Definition: Driver_Common.h:66
ARM_ETH_LINK_UP
@ ARM_ETH_LINK_UP
Link is up.
Definition: Driver_ETH.h:68
ARM_ETH_MAC_DUPLEX_Pos
#define ARM_ETH_MAC_DUPLEX_Pos
Definition: Driver_ETH_MAC.h:86
ARM_ETH_MAC_SPEED_Pos
#define ARM_ETH_MAC_SPEED_Pos
Definition: Driver_ETH_MAC.h:81
ARM_ETH_LINK_INFO::speed
uint32_t speed
Link speed: 0= 10 MBit, 1= 100 MBit, 2= 1 GBit.
Definition: Driver_ETH.h:75
ARM_ETH_LINK_INFO::duplex
uint32_t duplex
Duplex mode: 0= Half, 1= Full.
Definition: Driver_ETH.h:76
ARM_ETH_LINK_STATE
ARM_ETH_LINK_STATE
Ethernet link state.
Definition: Driver_ETH.h:66
ARM_ETH_LINK_INFO
Ethernet link information.
Definition: Driver_ETH.h:74
ARM_ETH_MAC_ADDR
Ethernet MAC Address.
Definition: Driver_ETH.h:83
ARM_ETH_MAC_ADDRESS_BROADCAST
#define ARM_ETH_MAC_ADDRESS_BROADCAST
Accept frames with Broadcast address.
ARM_ETH_MAC_CONTROL_TX
#define ARM_ETH_MAC_CONTROL_TX
Transmitter; arg: 0=disabled (default), 1=enabled.
ARM_ETH_MAC_FLUSH
#define ARM_ETH_MAC_FLUSH
Flush buffer; arg = ARM_ETH_MAC_FLUSH_...
ARM_ETH_MAC_CONFIGURE
#define ARM_ETH_MAC_CONFIGURE
Configure MAC; arg = configuration.
ARM_ETH_MAC_CONTROL_RX
#define ARM_ETH_MAC_CONTROL_RX
Receiver; arg: 0=disabled (default), 1=enabled.
ARM_ETH_MAC_FLUSH_TX
#define ARM_ETH_MAC_FLUSH_TX
Flush Transmit buffer.
ARM_ETH_MAC_FLUSH_RX
#define ARM_ETH_MAC_FLUSH_RX
Flush Receive buffer.
ARM_DRIVER_ETH_MAC::PowerControl
int32_t(* PowerControl)(ARM_POWER_STATE state)
Pointer to ARM_ETH_MAC_PowerControl : Control Ethernet MAC Device Power.
Definition: Driver_ETH_MAC.h:290
ARM_DRIVER_ETH_MAC::GetMacAddress
int32_t(* GetMacAddress)(ARM_ETH_MAC_ADDR *ptr_addr)
Pointer to ARM_ETH_MAC_GetMacAddress : Get Ethernet MAC Address.
Definition: Driver_ETH_MAC.h:291
ARM_ETH_MAC_CAPABILITIES::media_interface
uint32_t media_interface
Ethernet Media Interface type.
Definition: Driver_ETH_MAC.h:272
ARM_DRIVER_ETH_MAC::PHY_Write
int32_t(* PHY_Write)(uint8_t phy_addr, uint8_t reg_addr, uint16_t data)
Pointer to ARM_ETH_MAC_PHY_Write : Write Ethernet PHY Register through Management Interface.
Definition: Driver_ETH_MAC.h:302
ARM_DRIVER_ETH_MAC::Control
int32_t(* Control)(uint32_t control, uint32_t arg)
Pointer to ARM_ETH_MAC_Control : Control Ethernet Interface.
Definition: Driver_ETH_MAC.h:300
ARM_DRIVER_ETH_MAC::GetCapabilities
ARM_ETH_MAC_CAPABILITIES(* GetCapabilities)(void)
Pointer to ARM_ETH_MAC_GetCapabilities : Get driver capabilities.
Definition: Driver_ETH_MAC.h:287
ARM_ETH_MAC_CAPABILITIES::mac_address
uint32_t mac_address
1 = driver provides initial valid MAC address
Definition: Driver_ETH_MAC.h:273
ARM_DRIVER_ETH_MAC::SetMacAddress
int32_t(* SetMacAddress)(const ARM_ETH_MAC_ADDR *ptr_addr)
Pointer to ARM_ETH_MAC_SetMacAddress : Set Ethernet MAC Address.
Definition: Driver_ETH_MAC.h:292
ARM_DRIVER_ETH_MAC::PHY_Read
int32_t(* PHY_Read)(uint8_t phy_addr, uint8_t reg_addr, uint16_t *data)
Pointer to ARM_ETH_MAC_PHY_Read : Read Ethernet PHY Register through Management Interface.
Definition: Driver_ETH_MAC.h:301
ARM_DRIVER_ETH_MAC::Initialize
int32_t(* Initialize)(ARM_ETH_MAC_SignalEvent_t cb_event)
Pointer to ARM_ETH_MAC_Initialize : Initialize Ethernet MAC Device.
Definition: Driver_ETH_MAC.h:288
ARM_DRIVER_ETH_MAC
Access structure of the Ethernet MAC Driver.
Definition: Driver_ETH_MAC.h:285
ARM_ETH_MAC_CAPABILITIES
Ethernet MAC Capabilities.
Definition: Driver_ETH_MAC.h:261
ARM_DRIVER_ETH_PHY::Initialize
int32_t(* Initialize)(ARM_ETH_PHY_Read_t fn_read, ARM_ETH_PHY_Write_t fn_write)
Pointer to ARM_ETH_PHY_Initialize : Initialize PHY Device.
Definition: Driver_ETH_PHY.h:129
ARM_DRIVER_ETH_PHY::SetMode
int32_t(* SetMode)(uint32_t mode)
Pointer to ARM_ETH_PHY_SetMode : Set Ethernet PHY Device Operation mode.
Definition: Driver_ETH_PHY.h:134
ARM_DRIVER_ETH_PHY::PowerControl
int32_t(* PowerControl)(ARM_POWER_STATE state)
Pointer to ARM_ETH_PHY_PowerControl : Control PHY Device Power.
Definition: Driver_ETH_PHY.h:132
ARM_DRIVER_ETH_PHY::GetLinkInfo
ARM_ETH_LINK_INFO(* GetLinkInfo)(void)
Pointer to ARM_ETH_PHY_GetLinkInfo : Get Ethernet PHY Device Link information.
Definition: Driver_ETH_PHY.h:136
ARM_DRIVER_ETH_PHY::SetInterface
int32_t(* SetInterface)(uint32_t interface)
Pointer to ARM_ETH_PHY_SetInterface : Set Ethernet Media Interface.
Definition: Driver_ETH_PHY.h:133
ARM_DRIVER_ETH_PHY::GetLinkState
ARM_ETH_LINK_STATE(* GetLinkState)(void)
Pointer to ARM_ETH_PHY_GetLinkState : Get Ethernet PHY Device Link state.
Definition: Driver_ETH_PHY.h:135
ARM_DRIVER_ETH_PHY
Access structure of the Ethernet PHY Driver.
Definition: Driver_ETH_PHY.h:127
ARM_ETH_PHY_AUTO_NEGOTIATE
#define ARM_ETH_PHY_AUTO_NEGOTIATE
Auto Negotiation mode.
ARM_DRIVER_OK
#define ARM_DRIVER_OK
Operation succeeded.

## Data Structure Documentation

## ◆ ARM_ETH_LINK_INFO

struct ARM_ETH_LINK_INFO

Ethernet link information.

The Ethernet Link information provides parameters about the current established communication.

Returned by:

- ARM_ETH_PHY_GetLinkInfo

Data Fields
uint32_t | speed: 2 | Link speed: 0= 10 MBit, 1= 100 MBit, 2= 1 GBit.
uint32_t | duplex: 1 | Duplex mode: 0= Half, 1= Full.
uint32_t | reserved: 29 |

## ◆ ARM_ETH_MAC_ADDR

struct ARM_ETH_MAC_ADDR

Ethernet MAC Address.

Stores the MAC Address of the Ethernet interface as defined by IEEE 802. Wikipedia offers more information about the MAC Address.

Parameter for:

- ARM_ETH_MAC_GetMacAddress, ARM_ETH_MAC_SetMacAddress, ARM_ETH_MAC_SetAddressFilter

Data Fields
uint8_t | b[6] | MAC Address (6 bytes), MSB first.

## Enumeration Type Documentation

## ◆ ARM_ETH_LINK_STATE

enum ARM_ETH_LINK_STATE

Ethernet link state.

The Ethernet Link status shows if the communication is currently established (up) or interrupted (down).

Returned by:

- ARM_ETH_PHY_GetLinkState

Enumerator
ARM_ETH_LINK_DOWN | Link is down.
ARM_ETH_LINK_UP | Link is up.