diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-15 16:00:07 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-15 16:00:07 -0700 |
commit | e4997af8453980922b469e5d3b66a7b26910dad3 (patch) | |
tree | f19255b35f70670f7674334299453189b2c2a880 /firmware/microblaze | |
parent | 7590f187d0414fd05e23828488166bc4bc88df26 (diff) | |
download | uhd-e4997af8453980922b469e5d3b66a7b26910dad3.tar.gz uhd-e4997af8453980922b469e5d3b66a7b26910dad3.tar.bz2 uhd-e4997af8453980922b469e5d3b66a7b26910dad3.zip |
Ability to burn mac addr and ip addr to usrp2 (over ip/udp for now).
Added firmware support and usrp2 burner host app.
Diffstat (limited to 'firmware/microblaze')
-rw-r--r-- | firmware/microblaze/apps/txrx.c | 44 | ||||
-rw-r--r-- | firmware/microblaze/include/usrp2_i2c_addr.h | 1 | ||||
-rw-r--r-- | firmware/microblaze/lib/ethernet.c | 76 | ||||
-rw-r--r-- | firmware/microblaze/lib/ethernet.h | 11 |
4 files changed, 96 insertions, 36 deletions
diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c index 18bbdd23d..97376ffbd 100644 --- a/firmware/microblaze/apps/txrx.c +++ b/firmware/microblaze/apps/txrx.c @@ -153,9 +153,12 @@ static eth_mac_addr_t get_my_eth_mac_addr(void){ } static struct ip_addr get_my_ip_addr(void){ - struct ip_addr addr; - addr.addr = 192 << 24 | 168 << 16 | 10 << 8 | 2 << 0; - return addr; + return *get_ip_addr(); +} + +static void print_ip_addr(const void *t){ + uint8_t *p = (uint8_t *)t; + printf("%d.%d.%d.%d", p[0], p[1], p[2], p[3]); } void handle_udp_data_packet( @@ -170,21 +173,13 @@ void handle_udp_data_packet( printf("Storing for fast path:\n"); printf(" source mac addr: "); print_mac_addr(fp_mac_addr_src.addr); newline(); - printf(" source ip addr: %d.%d.%d.%d\n", - ((const unsigned char*)&fp_socket_src.addr.addr)[0], - ((const unsigned char*)&fp_socket_src.addr.addr)[1], - ((const unsigned char*)&fp_socket_src.addr.addr)[2], - ((const unsigned char*)&fp_socket_src.addr.addr)[3] - ); + printf(" source ip addr: "); + print_ip_addr(&fp_socket_src.addr); newline(); printf(" source udp port: %d\n", fp_socket_src.port); printf(" destination mac addr: "); print_mac_addr(fp_mac_addr_dst.addr); newline(); - printf(" destination ip addr: %d.%d.%d.%d\n", - ((const unsigned char*)&fp_socket_dst.addr.addr)[0], - ((const unsigned char*)&fp_socket_dst.addr.addr)[1], - ((const unsigned char*)&fp_socket_dst.addr.addr)[2], - ((const unsigned char*)&fp_socket_dst.addr.addr)[3] - ); + printf(" destination ip addr: "); + print_ip_addr(&fp_socket_dst.addr); newline(); printf(" destination udp port: %d\n", fp_socket_dst.port); newline(); } @@ -217,14 +212,24 @@ void handle_udp_ctrl_packet( ******************************************************************/ case USRP2_CTRL_ID_GIVE_ME_YOUR_IP_ADDR_BRO: ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE; - struct ip_addr ip_addr = get_my_ip_addr(); - memcpy(&ctrl_data_out.data.ip_addr, &ip_addr, sizeof(ip_addr)); + memcpy(&ctrl_data_out.data.ip_addr, get_ip_addr(), sizeof(struct ip_addr)); + break; + + case USRP2_CTRL_ID_HERE_IS_A_NEW_IP_ADDR_BRO: + ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_IP_ADDR_DUDE; + set_ip_addr((struct ip_addr *)&ctrl_data_in->data.ip_addr); + memcpy(&ctrl_data_out.data.ip_addr, get_ip_addr(), sizeof(struct ip_addr)); break; case USRP2_CTRL_ID_GIVE_ME_YOUR_MAC_ADDR_BRO: ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE; - eth_mac_addr_t mac_addr = get_my_eth_mac_addr(); - memcpy(&ctrl_data_out.data.mac_addr, &mac_addr, sizeof(mac_addr)); + memcpy(&ctrl_data_out.data.mac_addr, ethernet_mac_addr(), sizeof(eth_mac_addr_t)); + break; + + case USRP2_CTRL_ID_HERE_IS_A_NEW_MAC_ADDR_BRO: + ctrl_data_out.id = USRP2_CTRL_ID_THIS_IS_MY_MAC_ADDR_DUDE; + ethernet_set_mac_addr((eth_mac_addr_t *)&ctrl_data_in->data.mac_addr); + memcpy(&ctrl_data_out.data.mac_addr, ethernet_mac_addr(), sizeof(eth_mac_addr_t)); break; case USRP2_CTRL_ID_GIVE_ME_YOUR_DBOARD_IDS_BRO: @@ -720,6 +725,7 @@ main(void) putstr("\nTxRx-NEWETH\n"); print_mac_addr(ethernet_mac_addr()->addr); newline(); + print_ip_addr(get_ip_addr()); newline(); ethernet_register_link_changed_callback(link_changed_callback); ethernet_init(); diff --git a/firmware/microblaze/include/usrp2_i2c_addr.h b/firmware/microblaze/include/usrp2_i2c_addr.h index 4111cdd55..46f5a7556 100644 --- a/firmware/microblaze/include/usrp2_i2c_addr.h +++ b/firmware/microblaze/include/usrp2_i2c_addr.h @@ -41,6 +41,7 @@ #define MBOARD_REV_LSB 0x00 #define MBOARD_REV_MSB 0x01 #define MBOARD_MAC_ADDR 0x02 +#define MBOARD_IP_ADDR 0x0C // format of daughterboard EEPROM diff --git a/firmware/microblaze/lib/ethernet.c b/firmware/microblaze/lib/ethernet.c index 5402a6c9f..757a36ce4 100644 --- a/firmware/microblaze/lib/ethernet.c +++ b/firmware/microblaze/lib/ethernet.c @@ -271,58 +271,100 @@ ethernet_init(void) } static bool -unprogrammed(const eth_mac_addr_t *t) +unprogrammed(const void *t, size_t len) { int i; + uint8_t *p = (uint8_t *)t; bool all_zeros = true; bool all_ones = true; - for (i = 0; i < 6; i++){ - all_zeros &= t->addr[i] == 0x00; - all_ones &= t->addr[i] == 0xff; + for (i = 0; i < len; i++){ + all_zeros &= p[i] == 0x00; + all_ones &= p[i] == 0xff; } return all_ones | all_zeros; } -static int8_t src_addr_initialized = false; -static eth_mac_addr_t src_addr = {{ +//////////////////// MAC Addr Stuff /////////////////////// + +static int8_t src_mac_addr_initialized = false; +static eth_mac_addr_t src_mac_addr = {{ 0x00, 0x50, 0xC2, 0x85, 0x3f, 0xff }}; const eth_mac_addr_t * ethernet_mac_addr(void) { - if (!src_addr_initialized){ // fetch from eeprom - src_addr_initialized = true; + if (!src_mac_addr_initialized){ // fetch from eeprom + src_mac_addr_initialized = true; // if we're simulating, don't read the EEPROM model, it's REALLY slow - if (hwconfig_simulation_p()) - return &src_addr; + if (hwconfig_simulation_p()) + return &src_mac_addr; eth_mac_addr_t tmp; - bool ok = eeprom_read(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &tmp.addr[0], 6); - if (!ok || unprogrammed(&tmp)){ + bool ok = eeprom_read(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &tmp, sizeof(tmp)); + if (!ok || unprogrammed(&tmp, sizeof(tmp))){ // use the default } else - src_addr = tmp; + src_mac_addr = tmp; } - return &src_addr; + return &src_mac_addr; } bool ethernet_set_mac_addr(const eth_mac_addr_t *t) { - bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &t->addr[0], 6); + bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_MAC_ADDR, &t, sizeof(eth_mac_addr_t)); if (ok){ - src_addr = *t; - src_addr_initialized = true; + src_mac_addr = *t; + src_mac_addr_initialized = true; eth_mac_set_addr(t); } return ok; } +//////////////////// IP Addr Stuff /////////////////////// + +static int8_t src_ip_addr_initialized = false; +static struct ip_addr src_ip_addr = { + (192 << 24 | 168 << 16 | 10 << 8 | 2 << 0) +}; + + +const struct ip_addr *get_ip_addr(void) +{ + if (!src_ip_addr_initialized){ // fetch from eeprom + src_ip_addr_initialized = true; + + // if we're simulating, don't read the EEPROM model, it's REALLY slow + if (hwconfig_simulation_p()) + return &src_ip_addr; + + struct ip_addr tmp; + bool ok = eeprom_read(I2C_ADDR_MBOARD, MBOARD_IP_ADDR, &tmp, sizeof(tmp)); + if (!ok || unprogrammed(&tmp, sizeof(tmp))){ + // use the default + } + else + src_ip_addr = tmp; + } + + return &src_ip_addr; +} + +bool set_ip_addr(const struct ip_addr *t){ + bool ok = eeprom_write(I2C_ADDR_MBOARD, MBOARD_IP_ADDR, &t, sizeof(struct ip_addr)); + if (ok){ + src_ip_addr = *t; + src_ip_addr_initialized = true; + } + + return ok; +} + int ethernet_check_errors(void) { diff --git a/firmware/microblaze/lib/ethernet.h b/firmware/microblaze/lib/ethernet.h index 70b7077c6..8c6d8b567 100644 --- a/firmware/microblaze/lib/ethernet.h +++ b/firmware/microblaze/lib/ethernet.h @@ -20,6 +20,7 @@ #define INCLUDED_ETHERNET_H #include <net/eth_mac_addr.h> +#include <lwip/ip_addr.h> #include <stdbool.h> typedef void (*ethernet_link_changed_callback_t)(int speed); @@ -48,6 +49,16 @@ const eth_mac_addr_t *ethernet_mac_addr(void); */ bool ethernet_set_mac_addr(const eth_mac_addr_t *t); +/*! + * \returns IP address + */ +const struct ip_addr *get_ip_addr(void); + +/*! + * \brief write ip address to eeprom and begin using it + */ +bool set_ip_addr(const struct ip_addr *t); + /* * \brief read RMON regs and return error mask |