| |||||
Technical Support Support Resources
Product Information | MCBXC167: HOW TO ACCESS AX88796 EMBEDDED PHY REGISTERInformation in this article applies to:
QUESTIONI need to access the embedded PHY registers (MR0 - MR31) of the AX88796 ethernet controller to retrieve the link status and to set the autonegotiation advertisement mode. These registers are not memory-mapped. How can I access them? ANSWERThese station management registers are part of the MII interface which needs to be accessed over an internal serial interface. The protocol on this interface is described in chapter 6.5 of the AX88796 manual. The code below can be used to read from or write into these registers.
#include "AX88796.h"
#include <absacc.h>
static void shiftout (unsigned int value, unsigned int count) {
unsigned int mask,i;
unsigned char mdoval;
mask = 1 << (count - 1);
for(i = 0; i < count; i++) { // send 'count' bits to PHY register
if (mask & value) {
mdoval = MEMR_MDO; // MDO=1
} else {
mdoval = 0x00; // MDO=0
}
HVAR(unsigned char, M2EEP) = mdoval;
HVAR(unsigned char, M2EEP) = mdoval | MEMR_MDC; // positive transition of clock
mask >>= 1;
}
}
//WRITE TO AX88796 MII REGISTERS
void Write_MII(unsigned char regad,unsigned int mii_data) {
shiftout (0xF5, 8); // send 4 bits preamble (1111B),
// 2 bits start frame (ST = 01B)
// 2 bits operation code (OP = 01B for 'write')
shiftout (0x10, 5); //Send 5 bits PHY address = 10000B for internal PHY
shiftout (regad, 5); //Send 5 bits PHY register address
shiftout (0x02, 2); //Send 2 bits turnaround time (10B)
shiftout (mii_data, 16);//Send 16 bits data
}
//READ MII AX88796 REGISTERS
unsigned int Read_MII(unsigned char regad) {
unsigned char i, mdival;
unsigned int result;
shiftout (0xF6, 8); // send 4 bits preamble (1111B),
// 2 bits start frame (ST = 01B)
// 2 bits operation code (OP = 10B for 'read')
shiftout (0x10, 5); //Send 5 bits PHY address = 10000B for internal PHY
shiftout (regad, 5); //Send 5 bits PHY register address
shiftout (0x00, 2); //Send 2 bits turnaround time (00B)
result = 0x0000;
for(i = 0; i < 16; ++i){//Read 16 bits of data from PHY
result <<= 1;
HVAR(unsigned char, M2EEP) = MEMR_MDC; // positive transition of clock
mdival = HVAR(unsigned char, M2EEP);
if (mdival & 0x04) {
result |= 0x01;
}
HVAR(unsigned char, M2EEP) = 0x00; // MDO=0
}
return (result);
}
This code fragment can be used with the EasyWeb example (C:\Keil\C166\Boards\Keil MCB-XC167\EasyWEB) as well as all ethernet examples of ARTX-166 (e.g. C:\Keil\C166\AR166\Examples\Http_demo) MORE INFORMATION
Last Reviewed: Thursday, February 09, 2006 | ||||
| |||||