//----------------------------------------------------------------------------- /// Write PHY register /// Return 1 if successfully, 0 if timeout. /// \param PhyAddress PHY Address /// \param Address Register Address /// \param Value Data to write ( Actually 16 bit data ) /// \param retry The retry times, 0 to wait forever until complete. //----------------------------------------------------------------------------- unsigned char EMAC_WritePhy(unsigned char PhyAddress, unsigned char Address, unsigned int Value, unsigned int retry) { AT91C_BASE_EMAC->EMAC_MAN = (AT91C_EMAC_SOF & (0x01 << 30)) | (AT91C_EMAC_CODE & (2 << 16)) | (AT91C_EMAC_RW & (1 << 28)) | (AT91C_EMAC_PHYA & ((PhyAddress & 0x1f) << 23)) | (AT91C_EMAC_REGA & (Address << 18)) | (AT91C_EMAC_DATA & Value) ; if ( EMAC_WaitPhy(retry) == 0 ) { TRACE_ERROR("TimeOut EMAC_WritePhy\n\r"); return 0; } return 1; }
//----------------------------------------------------------------------------- /// Read PHY register. /// Return 1 if successfully, 0 if timeout. /// \param PhyAddress PHY Address /// \param Address Register Address /// \param pValue Pointer to a 32 bit location to store read data /// \param retry The retry times, 0 to wait forever until complete. //----------------------------------------------------------------------------- unsigned char EMAC_ReadPhy(unsigned char PhyAddress, unsigned char Address, unsigned int *pValue, unsigned int retry) { AT91C_BASE_EMAC->EMAC_MAN = (AT91C_EMAC_SOF & (0x01U << 30)) | (AT91C_EMAC_CODE & (2U << 16)) | (AT91C_EMAC_RW & (2U << 28)) | (AT91C_EMAC_PHYA & ((PhyAddress & 0x1fU) << 23)) | (AT91C_EMAC_REGA & (Address << 18)); if ( EMAC_WaitPhy(retry) == 0 ) { TRACE_ERROR("TimeOut EMAC_ReadPhy\n\r"); return 0; } *pValue = ( AT91C_BASE_EMAC->EMAC_MAN & 0x0000ffff ); return 1; }