Forum Discussion
Altera_Forum
Honored Contributor
14 years agoHope this can help you (it is a portion of the attached zip file):
/*
* get_board_mac_addr
*
* Read the MAC address in a board specific way
*
*/
error_t get_board_mac_addr(unsigned char mac_addr)
{
error_t error = 0;
alt_u32 signature;
alt_u32 mac_addr_ptr = EXT_FLASH_BASE + ETHERNET_OPTION_BITS;
/* This last_flash_sector region of flash is examined to see if
* valid network settings are present, indicated by a signature of 0x00005afe at
* the first address of the last flash sector. This hex value is chosen as the
* signature since it looks like the english word "SAFE", meaning that it is
* safe to use these network address values.
*/
/* Get the flash sector with the MAC address. */
signature = IORD_32DIRECT(mac_addr_ptr, 0);
if (signature != 0x00005afe)
{
error = generate_and_store_mac_addr();
}
if (!error)
{
mac_addr = IORD_8DIRECT(mac_addr_ptr, 4);
mac_addr = IORD_8DIRECT(mac_addr_ptr, 5);
mac_addr = IORD_8DIRECT(mac_addr_ptr, 6);
mac_addr = IORD_8DIRECT(mac_addr_ptr, 7);
mac_addr = IORD_8DIRECT(mac_addr_ptr, 8);
mac_addr = IORD_8DIRECT(mac_addr_ptr, 9);
printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n",
mac_addr,
mac_addr,
mac_addr,
mac_addr,
mac_addr,
mac_addr);
}
return error;
}