diff options
author | Josh Blum <josh@joshknows.com> | 2010-11-17 17:12:01 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-12-11 18:43:09 -0800 |
commit | 68af2b9ccf556f42d7697c73406abdcc31093d1b (patch) | |
tree | 4045a45d702f678446f1d89db3082b548a8f4c8e /firmware/microblaze | |
parent | 58d19c5adf7bde9298ad4363c275f72e4bbecd73 (diff) | |
download | uhd-68af2b9ccf556f42d7697c73406abdcc31093d1b.tar.gz uhd-68af2b9ccf556f42d7697c73406abdcc31093d1b.tar.bz2 uhd-68af2b9ccf556f42d7697c73406abdcc31093d1b.zip |
usrp2: implement routing mode calls, and prefix pkt ctrl calls
Diffstat (limited to 'firmware/microblaze')
-rw-r--r-- | firmware/microblaze/apps/txrx_uhd.c | 18 | ||||
-rw-r--r-- | firmware/microblaze/lib/net_common.c | 4 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.c | 19 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.h | 16 |
4 files changed, 41 insertions, 16 deletions
diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 4adccfed9..938491b0e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -279,10 +279,16 @@ static void handle_inp_packet(uint32_t *buff, size_t num_lines){ * Called when eth phy state changes (w/ interrupts disabled) */ void link_changed_callback(int speed){ - bool link_is_up = speed != 0; - hal_set_leds(link_is_up ? LED_RJ45 : 0x0, LED_RJ45); - printf("\neth link changed: speed = %d\n", speed); - if (link_is_up) send_gratuitous_arp(); + printf("\neth link changed: speed = %d\n", speed); + if (speed != 0){ + hal_set_leds(LED_RJ45, LED_RJ45); + pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_MASTER); + send_gratuitous_arp(); //garp after setting the routing mode + } + else{ + hal_set_leds(0x0, LED_RJ45); + pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE); + } } static void setup_network(void){ @@ -357,10 +363,10 @@ main(void) while(true){ size_t num_lines; - void *buff = claim_incoming_buffer(&num_lines); + void *buff = pkt_ctrl_claim_incoming_buffer(&num_lines); if (buff != NULL){ handle_inp_packet((uint32_t *)buff, num_lines); - release_incoming_buffer(); + pkt_ctrl_release_incoming_buffer(); } int pending = pic_regs->pending; // poll for under or overrun diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index cc08997a0..486a34252 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -128,7 +128,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, ehdr.src = _local_mac_addr; ehdr.ethertype = ethertype; - uint32_t *buff = (uint32_t *)claim_outgoing_buffer(); + uint32_t *buff = (uint32_t *)pkt_ctrl_claim_outgoing_buffer(); // Copy the pieces into the buffer uint32_t *p = buff; @@ -165,7 +165,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, if (total_len < 60) // ensure that we don't try to send a short packet total_len = 60; - commit_outgoing_buffer(total_len/4); + pkt_ctrl_commit_outgoing_buffer(total_len/4); } unsigned int diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 235a09459..f7f808cfc 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -30,24 +30,35 @@ static void set_control(uint32_t value, uint32_t mask){ buffer_pool_ctrl->ctrl = ctrl_shadow; } -void *claim_incoming_buffer(size_t *num_lines){ +void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ + switch(mode){ + case PKT_CTRL_ROUTING_MODE_SLAVE: + set_control(0x0, 0x4); + break; + case PKT_CTRL_ROUTING_MODE_MASTER: + set_control(0x4, 0x4); + break; + } +} + +void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ if ((buffer_pool_status->status & 0x1) != 1) return NULL; *num_lines = (buffer_pool_status->status >> 16) & 0xffff; set_control(0x1, 0x1); return buffer_ram(0); } -void release_incoming_buffer(void){ +void pkt_ctrl_release_incoming_buffer(void){ set_control(0x0, 0x1); while ((buffer_pool_status->status & 0x1) != 0){} } -void *claim_outgoing_buffer(void){ +void *pkt_ctrl_claim_outgoing_buffer(void){ while ((buffer_pool_status->status & 0x2) != 0x2){} return buffer_ram(1); } -void commit_outgoing_buffer(size_t num_lines){ +void pkt_ctrl_commit_outgoing_buffer(size_t num_lines){ set_control(0x2 | (num_lines << 16), 0x2 | (0xffff << 16)); while ((buffer_pool_status->status & 0x2) != 0x0){} set_control(0x0, 0x2); diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 156fc06dc..86fb46d32 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -20,28 +20,36 @@ #include <stddef.h> +typedef enum { + PKT_CTRL_ROUTING_MODE_SLAVE, + PKT_CTRL_ROUTING_MODE_MASTER, +} pkt_ctrl_routing_mode_t; + +//! Set the routing mode for this device +void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); + /*! * Try to claim an incomming buffer. * \param num_lines filled with the buffer size * \return a pointer to the buffer memory or NULL */ -void *claim_incoming_buffer(size_t *num_lines); +void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines); /*! * Release the incoming buffer. Call when done. */ -void release_incoming_buffer(void); +void pkt_ctrl_release_incoming_buffer(void); /*! * Claim an outgoing buffer. * \return a pointer to the buffer */ -void *claim_outgoing_buffer(void); +void *pkt_ctrl_claim_outgoing_buffer(void); /*! * Commit the outgoing buffer. * \param num_lines how many lines written. */ -void commit_outgoing_buffer(size_t num_lines); +void pkt_ctrl_commit_outgoing_buffer(size_t num_lines); #endif /* INCLUDED_PKT_CTRL_H */ |