Forum Discussion
Altera_Forum
Honored Contributor
14 years agoEthernet Example Design on Cyclone III Dev Board (3C120F780)
Hi, I'm not able to get the Altera's Ethernet Example Design to work on the Cyclone III Dev. Board. I used the "Using the NicheStack TCP/IP Stack - Nios II Edition Tutorial".
PHY INFO...
Altera_Forum
Honored Contributor
14 years agoerror_t generate_mac_addr(unsigned char mac_addr[6])
{ error_t error = -1; alt_u32 ser_num = 0; printf("\nCan't read the MAC address from your board. We will assign you\n"); printf("a MAC address.\n\n"); ser_num = get_serial_number(); if (ser_num) { /* This is the Altera Vendor ID */ mac_addr[0] = 0x0; mac_addr[1] = 0x7; mac_addr[2] = 0xed; /* Reserverd Board identifier */ mac_addr[3] = 0xFF; mac_addr[4] = (ser_num & 0xff00) >> 8; mac_addr[5] = ser_num & 0xff; printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); error = 0; } return error; } /* * get_board_mac_addr * * Read the MAC address in a board specific way * */ error_t get_board_mac_addr(unsigned char mac_addr[6]) { error_t error = 0; alt_u32 signature; if (!error) { signature = IORD_32DIRECT(last_flash_sector, 0); if (signature != 0x00005afe) { error = generate_and_store_mac_addr(); } } if (!error) { mac_addr[0] = IORD_8DIRECT(last_flash_sector, 4); mac_addr[1] = IORD_8DIRECT(last_flash_sector, 5); mac_addr[2] = IORD_8DIRECT(last_flash_sector, 6); mac_addr[3] = IORD_8DIRECT(last_flash_sector, 7); mac_addr[4] = IORD_8DIRECT(last_flash_sector, 8); mac_addr[5] = IORD_8DIRECT(last_flash_sector, 9); printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]); } return error; } /* * get_mac_addr * * Read the MAC address in a board specific way * */ int get_mac_addr(NET net, unsigned char mac_addr[6]) { error_t error = 0; error = get_board_mac_addr(mac_addr); if(error) { /* Failed read MAC address from flash, prompt user to enter serial number to generate MAC address. */ error = generate_mac_addr(mac_addr); } return error; } /* * get_ip_addr() * * This routine is called by InterNiche to obtain an IP address for the * specified network adapter. Like the MAC address, obtaining an IP address is * very system-dependant and therefore this function is exported for the * developer to control. * * In our system, we are either attempting DHCP auto-negotiation of IP address, * or we are setting our own static IP, Gateway, and Subnet Mask addresses our * self. This routine is where that happens. */ int get_ip_addr(alt_iniche_dev *p_dev, ip_addr* ipaddr, ip_addr* netmask, ip_addr* gw, int* use_dhcp) { IP4_ADDR(*ipaddr, IPADDR0, IPADDR1, IPADDR2, IPADDR3); IP4_ADDR(*gw, GWADDR0, GWADDR1, GWADDR2, GWADDR3); IP4_ADDR(*netmask, MSKADDR0, MSKADDR1, MSKADDR2, MSKADDR3); # ifdef DHCP_CLIENT *use_dhcp = 1; # else /* not DHCP_CLIENT */ *use_dhcp = 0; printf("Static IP Address is %d.%d.%d.%d\n", ip4_addr1(*ipaddr), ip4_addr2(*ipaddr), ip4_addr3(*ipaddr), ip4_addr4(*ipaddr)); # endif /* not DHCP_CLIENT */ /* Non-standard API: return 1 for success */ return 1; } /******************************************************************************* * * Flash service functions. * ******************************************************************************/ # include "sys/alt_flash.h" # include "sys/alt_flash_dev.h" /* * FindLastFlashSectorOffset * * <-- pLastFlashSectorOffset Offset of last sector in flash. * * This function finds the offset to the last sector in flash and returns it * in pLastFlashSectorOffset. */ int FindLastFlashSectorOffset( alt_u32 *pLastFlashSectorOffset) { alt_flash_fd *fd; flash_region *regions; int numRegions; flash_region *pLastRegion; int lastFlashSectorOffset; int n; int error = 0; /* Open the flash device. */ fd = alt_flash_open_dev(EXT_FLASH_NAME); if (fd <= 0) error = -1; /* Get the flash info. */ if (!error) error = alt_get_flash_info(fd, ®ions, &numRegions); /* Find the last flash sector. */ if (!error) { pLastRegion = &(regions[0]); for (n = 1; n < numRegions; n++) { if (regions[n].offset > pLastRegion->offset) pLastRegion = &(regions[n]); } lastFlashSectorOffset = pLastRegion->offset + pLastRegion->region_size - pLastRegion->block_size; } /* Return results. */ if (!error) *pLastFlashSectorOffset = lastFlashSectorOffset; return (error); }