Forum Discussion
4 Replies
- Altera_Forum
Honored Contributor
Hope 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; } - Altera_Forum
Honored Contributor
Thenks for your help,
i have another Question, so the address of the MAC is the first address of the last flash sector in the de2 board ( 0x00005AFE). so How can i know in this way the IP? tnx - Altera_Forum
Honored Contributor
I think the first address of the last flash sector is only a signature, the MAC address is found where mac_addr_ptr is pointing.
The IP address is defined in simple_socket_server.h/* * The IP, gateway, and subnet mask address below are used as a last resort * if no network settings can be found, and DHCP (if enabled) fails. You can * edit these as a quick-and-dirty way of changing network settings if desired. * * Default IP addresses are set to all zeros so that DHCP server packets will * penetrate secure routers. If DHCP will not be used, select valid static * IP addresses here, for example: * IP: 192.168.1.234 * Gateway: 192.168.1.1 * Subnet Mask: 255.255.255.0 */# define IPADDR0 192# define IPADDR1 168# define IPADDR2 1# define IPADDR3 234 - Altera_Forum
Honored Contributor
thanks, it's really helpful