Spanish Italian
8426 Users    

SUCKERmenu

06 The PHY registrers

The PHY registers
The PHY registers are a 16bit and are accessible the way of MII registers.
To read a PHY register:

  • it is put the the address in the MIREGADR register;
  • setting the bit MIIRD (1) of the MICMD register, starts the reading;
  • attend the end of the reading observing the BUSY bit of the MISTAT register;
  • resetting the MIIRD bit;
  • the data will be present in the MIRDL and MIRDH registers;

To write in a PHY register:

  • put the register address in MIREGADR;
  • first write the byte less important in MIWRL, then writing the byte more important in MIWRH starts the writing.
  • attend that the module PHY finishes the operation.
u16 readPHY(u8 reg){
	setBank(2);
	writeReg(MIREGADR, reg);
	writeReg(MICMD, 0x01);	

	setBank(3);
	while(readMAC(MISTAT) & 1);

	setBank(2);
	writeReg(MICMD, 0x00);	
	
	return readMAC(MIRDL) | (readMAC(MIRDH) << 8 );
}

void writePHY(u8 reg, u16 data){
	setBank(2);
	writeReg(MIREGADR, reg);
	writeReg(MIWRL, LOW(data));
	writeReg(MIWRH, HIGH(data));

	setBank(3);
	while (readMAC(MISTAT) & 1);
}

Others methods
The following are useful to writing/reading more byte from the controller RAM; the address from where are read is contained in the ERDPT registers, while the writing address is contained in the EWRPT registers (are auto increasing).

void encGetArray(u8* buf, u16 len){
	CS = 0;
	spiWrite(RBM);
	while(len--)
		*buf++ = spiRead();
	CS = 1;
}

void encPutArray(u8* buf,u16 len){
	bufSize += len;
	CS = 0;
	spiWrite(WBM);
	while(len--)
		spiWrite(*buf++);
	CS = 1;
}	

void encPutString(const rom u8 *str){
	CS = 0;
	spiWrite(WBM);
	while(*str) {
    		spiWrite(*str++);
		bufSize++;
	}
	CS = 1;
}

Who's new

  • nona
  • finnsail
  • cristipop
  • vivek
  • solohobby

Who's online

There are currently 0 users and 61 guests online.