AM64x MCU+ SDK  08.02.00
ETHPHY

The ETHPHY driver provides APIs to control the Ethernet PHY devices present on the board. It accesses the PHY registers using the MDIO module.

Features Supported

Note
Only the commands needed for Industial Protocol examples are supported
  • Commands for following things:
    • Get the PHY link status
    • Set/get speed and half-duplex/full-duplex configuration
    • Configure PHY LEDs
    • Select MII mode
    • Soft-restart PHY
    • Enable Auto MDI-X
    • Disable 1G Advertisement
    • Get auto-negotiation status
    • Get auto-negotiation capability of link partner
    • Configure features like fast link down detection, extended full duplex ability, odd nibble detection and enhanced IPG detection
    • Set Tx/Rx FIFO Half Full Threshold for RGMII mode

SysConfig Features

Note
It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.
  • Option to select the type of Ethernet PHY
    • Supported PHYs
      • DP83869
      • CUSTOM
      • NONE
  • Option to select the MDIO instance to which PHY is connected
  • Option to set the PHY address
  • Based on above parameters, the SysConfig generated code does following:
    • Open the ETHPHY instance using ETHPHY_open API as a part of Board_driversOpen. Handle can used by including "ti_board_open_close.h" file.
    • Close the ETHPHY instance as a part of Board_driversClose
    • Create macros like CONFIG_ETHPHY0 using the name passed in SysConfig. This is used as an index to the array of handles.

Example Usage

Include the below file to access the APIs

#include <board/ethphy.h>
#include <board/ethphy/ethphy_dp83869.h>

Selecting MII mode and soft-resetting the PHY

/*Use CONFIG_ETHPHY0 macro as an index for the handle array*/
/* Select MII mode */
status = ETHPHY_command(gEthPhyHandle[CONFIG_ETHPHY0], ETHPHY_CMD_ENABLE_MII, NULL, 0);
/* Soft-reset PHY */
status = ETHPHY_command(gEthPhyHandle[CONFIG_ETHPHY0], ETHPHY_CMD_SOFT_RESTART, NULL, 0);

Configuring PHY LED sources

ETHPHY_DP83869_LedSourceConfig ledConfig;
/*Use CONFIG_ETHPHY0 macro as an index for the handle array*/
/* Configure source of PHY LEDs */
/* PHY pin LED_0 as link for fast link detection */
ledConfig.ledNum = ETHPHY_DP83869_LED0;
ledConfig.mode = ETHPHY_DP83869_LED_MODE_LINK_OK;
status = ETHPHY_command(gEthPhyHandle[CONFIG_ETHPHY0], ETHPHY_CMD_CONFIGURE_LED_SOURCE, (void *)&ledConfig, sizeof(ledConfig));
/* PHY pin LED_1 as 1G link established */
ledConfig.ledNum = ETHPHY_DP83869_LED1;
ledConfig.mode = ETHPHY_DP83869_LED_MODE_1000BT_LINK_UP;
status = ETHPHY_command(gEthPhyHandle[CONFIG_ETHPHY0], ETHPHY_CMD_CONFIGURE_LED_SOURCE, (void *)&ledConfig, sizeof(ledConfig));
/* PHY pin LED_2 as Rx/Tx Activity */
ledConfig.ledNum = ETHPHY_DP83869_LED2;
ledConfig.mode = ETHPHY_DP83869_LED_MODE_LINK_OK_AND_BLINK_ON_RX_TX;
status = ETHPHY_command(gEthPhyHandle[CONFIG_ETHPHY0], ETHPHY_CMD_CONFIGURE_LED_SOURCE, (void *)&ledConfig, sizeof(ledConfig));
/* PHY pin LED_3 as 100M link established */
ledConfig.ledNum = ETHPHY_DP83869_LED_GPIO;
ledConfig.mode = ETHPHY_DP83869_LED_MODE_10_OR_100BT_LINK_UP;
status = ETHPHY_command(gEthPhyHandle[CONFIG_ETHPHY0], ETHPHY_CMD_CONFIGURE_LED_SOURCE, (void *)&ledConfig, sizeof(ledConfig));

Adding Support for Custom PHY

In the SysConfig for ETHPHY, there are following options apart from the Ethernet PHYs supported in the SDK :

  1. CUSTOM : Generate SysConfig code with a custom PHY name. extern ETHPHY_Fxns gEthPhyFxns_MyEthPhyDevice; will be added in the ti_board_open_close.c file generated by SysConfig. Hence ETHPHY_Fxns should be defined for the custom PHY. Essentially one needs to write code similar to a supported PHY device (For an example, see ${SDK_INSTALL_PATH}/source/board/ethphy/ethphy_dp83869.c). APIs for Ethernet PHY can be used directly in this case.
  2. NONE : SysConfig does not generate any code for ETHPHY. Modules like EtherCAT and Ethernet (ICSS) add instances of ETHPHY in SysConfig. This option can be used if the PHY implementation is custom, and you do not want any code to be generated from SysConfig. APIs for Ethernet PHY can not be used directly in this case.

API

APIs for Ethernet PHY

ETHPHY_CMD_CONFIGURE_LED_SOURCE
#define ETHPHY_CMD_CONFIGURE_LED_SOURCE
Command to configure the source of PHY LEDs. "data" argument should be passed while making ETHPHY_com...
Definition: ethphy.h:95
ETHPHY_CMD_SOFT_RESTART
#define ETHPHY_CMD_SOFT_RESTART
Command for Soft Restart. It restarts the PHY without affecting registers.
Definition: ethphy.h:75
ETHPHY_CMD_ENABLE_MII
#define ETHPHY_CMD_ENABLE_MII
Command to configure the PHY in MII mode.
Definition: ethphy.h:71
ethphy.h
ETHPHY_command
int32_t ETHPHY_command(ETHPHY_Handle handle, uint32_t command, void *data, uint32_t dataSize)
Send a command to the ETHPHY.