diff options
Diffstat (limited to 'firmware/microblaze')
-rw-r--r-- | firmware/microblaze/apps/txrx_uhd.c | 6 | ||||
-rw-r--r-- | firmware/microblaze/lib/net_common.c | 3 | ||||
-rw-r--r-- | firmware/microblaze/lib/pkt_ctrl.c | 39 |
3 files changed, 37 insertions, 11 deletions
diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 8e2a35f58..f922ce4af 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -356,7 +356,11 @@ main(void) register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet); register_udp_listener(USRP2_UDP_UPDATE_PORT, handle_udp_fw_update_packet); - //3) setup ethernet hardware to bring the link up + //3) set the routing mode to slave and send a garp + pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE); + send_gratuitous_arp(); + + //4) setup ethernet hardware to bring the link up ethernet_register_link_changed_callback(link_changed_callback); ethernet_init(); diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index cb1ced46c..48aa460f9 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -168,6 +168,7 @@ send_pkt(eth_mac_addr_t dst, int ethertype, total_len = 60; pkt_ctrl_commit_outgoing_buffer(total_len/4); + //printf("sent %d bytes\n", total_len); } unsigned int @@ -389,6 +390,8 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) void handle_eth_packet(uint32_t *p, size_t nlines) { + //static size_t bcount = 0; + //printf("===> %d\n", bcount++); //print_buffer(p, nlines); padded_eth_hdr_t *eth_hdr = (padded_eth_hdr_t *)p; diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index f7f808cfc..a1e9ec1fe 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -30,36 +30,55 @@ static void set_control(uint32_t value, uint32_t mask){ buffer_pool_ctrl->ctrl = ctrl_shadow; } +static void set_control_bit(int bit){ + set_control(1 << bit, 1 << bit); +} + +static void clr_control_bit(int bit){ + set_control(0 << bit, 1 << bit); +} + +static bool is_status_bit_set(int bit){ + return buffer_pool_status->status & (1 << bit); +} + +#define INP_HS_BIT 0 //CPU out in packet_router.v +#define OUT_HS_BIT 1 //CPU inp in packet_router.v +#define MODE_BIT 2 +#define CLR_BIT 8 + void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ switch(mode){ case PKT_CTRL_ROUTING_MODE_SLAVE: - set_control(0x0, 0x4); + clr_control_bit(MODE_BIT); break; case PKT_CTRL_ROUTING_MODE_MASTER: - set_control(0x4, 0x4); + set_control_bit(MODE_BIT); break; } + set_control_bit(CLR_BIT); //clear after mode change + clr_control_bit(CLR_BIT); //unset the clear signal } void *pkt_ctrl_claim_incoming_buffer(size_t *num_lines){ - if ((buffer_pool_status->status & 0x1) != 1) return NULL; + if (!is_status_bit_set(INP_HS_BIT)) return NULL; *num_lines = (buffer_pool_status->status >> 16) & 0xffff; - set_control(0x1, 0x1); return buffer_ram(0); } void pkt_ctrl_release_incoming_buffer(void){ - set_control(0x0, 0x1); - while ((buffer_pool_status->status & 0x1) != 0){} + set_control_bit(INP_HS_BIT); + while (is_status_bit_set(INP_HS_BIT)){} + clr_control_bit(INP_HS_BIT); } void *pkt_ctrl_claim_outgoing_buffer(void){ - while ((buffer_pool_status->status & 0x2) != 0x2){} + while (!is_status_bit_set(OUT_HS_BIT)){} return buffer_ram(1); } 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); + set_control((1 << OUT_HS_BIT) | (num_lines << 16), (1 << OUT_HS_BIT) | (0xffff << 16)); + while (is_status_bit_set(OUT_HS_BIT)){} + clr_control_bit(OUT_HS_BIT); } |