1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
void MAC_Init(void)
{
// Check the duplex mode and perform duplex-mode specific initializations
if(PHYCN & 0x10){
// The device is in full-duplex mode, configure MAC registers
// Padding is turned on.
MAC_Write(MACCF, 0x40B3);
MAC_Write(IPGT, 0x0015);
} else {
// The device is in half-duplex mode, configure MAC registers
// Padding is turned off.
MAC_Write(MACCF, 0x4012);
MAC_Write(IPGT, 0x0012);
}
// Configure the IPGR register
MAC_Write(IPGR, 0x0C12);
// Configure the MAXLEN register to 1518 bytes
MAC_Write(MAXLEN, 0x05EE);
// Copy MAC Address Stored in Flash to MYMAC
FLASHADDRH = 0x1F;
FLASHADDRL = 0xFA;
MYMAC.Char[0] = FLASHAUTORD;
MYMAC.Char[1] = FLASHAUTORD;
MYMAC.Char[2] = FLASHAUTORD;
MYMAC.Char[3] = FLASHAUTORD;
MYMAC.Char[4] = FLASHAUTORD;
MYMAC.Char[5] = FLASHAUTORD;
// Program the MAC address
MAC_SetAddress(&MYMAC);
// Enable Reception and configure Loopback mode
MAC_Write(MACCN, 0x0001); // Enable Reception without loopback
}
//-----------------------------------------------------------------------------
// Indirect MAC Register Access
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// MAC_Write
//-----------------------------------------------------------------------------
//
// Return Value : None
// Parameters :
// 1) unsigned char mac_reg_offset - indirect register address
// 2) unsigned int mac_reg_data - the data to write to mac_reg_offset.
//
// Writes the value <mac_reg_data> to the indirect MAC register located at
// <mac_reg_offset>.
//-----------------------------------------------------------------------------
void MAC_Write(unsigned char mac_reg_offset, unsigned int mac_reg_data)
{
// Step 1: Write the address of the indirect register to MACADDR.
MACADDR = mac_reg_offset;
// Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
MACDATAH = (mac_reg_data >> 8); // Copy High Byte
MACDATAL = (mac_reg_data & 0xFF); // Copy Low Byte
// Step 3: Perform a write on MACRW to transfer the contents of MACDATAH:MACDATAL
// to the indirect MAC register.
MACRW = 0;
return;
}
unsigned int MAC_Read(unsigned char mac_reg_offset)
{
int mac_reg_data;
// Step 1: Write the address of the indirect register to MACADDR.
MACADDR = mac_reg_offset;
// Step 3: Perform a read of MACRW to transfer the contents to MACDATAH:MACDATAL
// from the indirect MAC register.
MACRW;
// Step 2: Copy the contents of <mac_reg_data> to MACDATAH:MACDATAL
mac_reg_data = (MACDATAH << 8) | (MACDATAL & 0xff);
return mac_reg_data;
} |
Partager