# MDIO Functions
[MDIO]

## Functions

Uint32 | MDIO_open (int instNum, Uint32 mdioModeFlags, Uint32 phyAddr, Handle hMDIO)
void | MDIO_close (Handle hMDIO)
void | MDIO_getStatus (Handle hMDIO, Uint32 *pPhy, Uint32 *pLinkStatus)
Uint32 | MDIO_timerTick (Handle hMDIO)
Uint32 | MDIO_initPHY (Handle hMDIO, Uint32 phyAddr)
Uint32 | MDIO_phyRegRead (Uint32 phyIdx, Uint32 phyReg, Uint16 *pData)
Uint32 | MDIO_phyRegWrite (Uint32 phyIdx, Uint32 phyReg, Uint16 data)

## Function Documentation

void MDIO_close | ( | Handle | hMDIO | ) |

============================================================================
MDIO_close()

Description
Close the MDIO peripheral and disable further operation.

Arguments

            hMDIO   handle to the opened MDIO instance

Return Value None

Pre Condition
MDIO module must be reset and opened before calling this function.

Post Condition
MDIO module is closed. No further operations are possible.

Example:

            #define MDIO_MODEFLG_FD1000      0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32    mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

            MDIO_close( &mdioDev );

============================================================================

void MDIO_getStatus | ( | Handle | hMDIO,
|  | Uint32 * | pPhy,
|  | Uint32 * | pLinkStatus |
| ) |  |  |

============================================================================
MDIO_getStatus()

Description
Called to get the status of the MDIO/PHY

Arguments

            hMDIO       handle to the opened MDIO instance
            pPhy        pointer to the physical address
            pLinkStatus pointer to the link status

Return Value None

Pre Condition
MDIO module must be reset and opened before calling this API

Post Condition
MDIO stauts is returned through the parameters paased in this API.

Example:

            #define MDIO_MODEFLG_FD1000         0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32    mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            //Open the MDIO module
            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

            MDIO_getStatus( &mdioDev, &pPhy, &pLinkStatus );

============================================================================

Uint32 MDIO_initPHY | ( | Handle | hMDIO,
|  | Uint32 | phyAddr |
| ) |  |  |

============================================================================
MDIO_initPHY()

Description
Force a switch to the specified PHY, and start the negotiation process.

Arguments

            hMDIO   handle to the opened MDIO instance
            phyAddr Physical address

Return Value
Returns 1 if the PHY selection completed OK,
else 0

Pre Condition
MDIO module must be reset.

Post Condition
Initializes the specific PHY device.

Example:

            #define MDIO_MODEFLG_FD1000         0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32    mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            //Open the MDIO module
            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

            MDIO_initPHY( &mdioDev, mdioPhyAddr );

============================================================================

Uint32 MDIO_open | ( | int | instNum,
|  | Uint32 | mdioModeFlags,
|  | Uint32 | phyAddr,
|  | Handle | hMDIO |
| ) |  |  |

Interfaces for the MDIO.

  NOTE: When used in an multitasking environment, no MDIO function may be called while another MDIO function is operating on the same device handle in another thread. It is the responsibility of the application to assure adherence to this restriction. ============================================================================
  MDIO_open()

Description
Opens the MDIO peripheral and initialize the MDIO state machine

It is assumed that the MDIO module is reset prior to calling this function.

Arguments

            instNum         Instance number when user is specifying a PHY address for monitoring
                            i.e., MDIO_MODEFLG_SPECPHYADDR mode flag is set.
                            It is hard-coded as 0 when MDIO_MODEFLG_SPECPHYADDR is not set.
            mdioModeFlags   Mode flags
            phyAddr         PHY address user specifies for monitoring. It is bypassed when
                            MDIO_MODEFLG_SPECPHYADDR mode flag is not set.
            hMDIO           Handle to the MDIO device which needs to be initialized.

Return Value Success (0)
MDIO_ERROR_INVALID - A calling parameter is invalid

Pre Condition
The MDIO module must be reset prior to calling this function.

Post Condition
Opens the MDIO peripheral and initialize the MDIO state machine.

Example:

            #define MDIO_MODEFLG_FD1000         0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32         mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

============================================================================

Uint32 MDIO_phyRegRead | ( | Uint32 | phyIdx,
|  | Uint32 | phyReg,
|  | Uint16 * | pData |
| ) |  |  |

============================================================================
MDIO_phyRegRead()

Description
Raw data read of a PHY register.

Arguments

            phyIdx  Physical Index
            phyReg  Physical register
            pData   Data read

Return Value
Returns 1 if the PHY ACK'd the read,
else 0

Pre Condition
MDIO module must be reset and opened. PHY device must be initialized.

Post Condition
Raw data is read from a PHY register.

Example:

            #define MDIO_MODEFLG_FD1000         0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040

            volatile Uint32 phyIdx = PHYREG_CONTROL;
            volatile Uint32 phyReg;
            Uint16 pData;

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32    mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            //Open the MDIO module
            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

            MDIO_initPHY( &mdioDev, mdioPhyAddr );

            MDIO_phyRegRead( phyIdx, ((MDIO_Device *)&mdioDev)->phyReg, pData );

============================================================================

Uint32 MDIO_phyRegWrite | ( | Uint32 | phyIdx,
|  | Uint32 | phyReg,
|  | Uint16 | data |
| ) |  |  |

============================================================================
MDIO_phyRegWrite()

Description
Raw data write of a PHY register.

Arguments

            phyIdx  Physical Index
            phyReg  Physical register
            pData   Data written

Return Value
Returns 1 if the PHY ACK'd the write,
else 0

Pre Condition
MDIO module must be reset and opened. PHY device must be initialized.

Post Condition
Raw data is written to a PHY register.

Example:

            #define MDIO_MODEFLG_FD1000         0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040
            #define PHYREG_SHADOW_EXTLOOPBACK   0x8400

            volatile Uint32 phyIdx = PHYREG_CONTROL;
            volatile Uint32 phyReg;
            Uint16 pData = PHYREG_SHADOW_EXTLOOPBACK;

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32    mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            //Open the MDIO module
            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

            MDIO_initPHY( &mdioDev, mdioPhyAddr );

            MDIO_phyRegWrite( phyIdx, ((MDIO_Device *)&mdioDev)->phyReg, pData );

============================================================================

Uint32 MDIO_timerTick | ( | Handle | hMDIO | ) |

============================================================================
MDIO_timerTick()

Description
Called to signify that approx 100mS have elapsed

Arguments

            hMDIO   Handle to the opened MDIO instance

Return Value
MDIO event code (see MDIO Events).

Pre Condition
MDIO module must be reset and opened before calling this API.

Post Condition
Gets approximately 100mS delay

Example:

            #define MDIO_MODEFLG_FD1000         0x0020
            #define MDIO_MODEFLG_LOOPBACK       0x0040

            MDIO_Device    mdioDev;
            int            instNum = 0;
            Uint32    mdioModeFlags = MDIO_MODEFLG_FD1000 | MDIO_MODEFLG_LOOPBACK;
            Uint32         mdioPhyAddr = 0;

            //Open the MDIO module
            MDIO_open(instNum, mdioModeFlags, mdioPhyAddr, &mdioDev);

            MDIO_timerTick( &mdioDev );

============================================================================

Copyright 2012, Texas Instruments Incorporated