From 6f2d1b519a14d75a1b6529c6e7738e41329f42c8 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 14 Nov 2010 13:38:42 -0800 Subject: usrp2: pretty much gutted the buffer pool stuff with other misc changes, not in working shape --- firmware/microblaze/apps/txrx_uhd.c | 111 +++++------------------------------- 1 file changed, 15 insertions(+), 96 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 9c1873e1c..2d001cfa8 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -28,12 +28,10 @@ #include "memory_map.h" #include "spi.h" #include "hal_io.h" -#include "buffer_pool.h" #include "pic.h" #include #include "ethernet.h" #include "nonstdio.h" -#include "dbsm.h" #include #include #include "memcpy_wa.h" @@ -48,82 +46,6 @@ #include #include "udp_fw_update.h" -/* - * Full duplex Tx and Rx between ethernet and DSP pipelines - * - * Buffer 1 is used by the cpu to send frames to the host. - * Buffers 2 and 3 are used to double-buffer the DSP Rx to eth flow - * Buffers 4 and 5 are used to double-buffer the eth to DSP Tx eth flow - */ -//#define CPU_RX_BUF 0 // eth -> cpu - -#define DSP_RX_BUF_0 2 // dsp rx -> eth (double buffer) -#define DSP_RX_BUF_1 3 // dsp rx -> eth -#define DSP_TX_BUF_0 4 // eth -> dsp tx (double buffer) -#define DSP_TX_BUF_1 5 // eth -> dsp tx - -/* - * ================================================================ - * configure DSP TX double buffering state machine (eth -> dsp) - * ================================================================ - */ - -// DSP Tx reads ethernet header words -#define DSP_TX_FIRST_LINE ((sizeof(padded_eth_hdr_t) + sizeof(struct ip_hdr) + sizeof(struct udp_hdr))/sizeof(uint32_t)) - -// Receive from ethernet -buf_cmd_args_t dsp_tx_recv_args = { - PORT_ETH, - 0, - BP_LAST_LINE -}; - -// send to DSP Tx -buf_cmd_args_t dsp_tx_send_args = { - PORT_DSP, - DSP_TX_FIRST_LINE, // starts just past transport header - 0 // filled in from last_line register -}; - -dbsm_t dsp_tx_sm; // the state machine - -/* - * ================================================================ - * configure DSP RX double buffering state machine (dsp -> eth) - * ================================================================ - */ - -static const uint32_t rx_ctrl_word = 1 << 16; - -// DSP Rx writes ethernet header words -#define DSP_RX_FIRST_LINE sizeof(rx_ctrl_word)/sizeof(uint32_t) - -static bool dbsm_rx_inspector(dbsm_t *sm, int buf_this){ - size_t num_lines = buffer_pool_status->last_line[buf_this]-DSP_RX_FIRST_LINE; - ((uint32_t*)buffer_ram(buf_this))[0] = (num_lines*sizeof(uint32_t)) | (1 << 16); - return false; -} - -// receive from DSP -buf_cmd_args_t dsp_rx_recv_args = { - PORT_DSP, - DSP_RX_FIRST_LINE, - BP_LAST_LINE -}; - -// send to ETH -buf_cmd_args_t dsp_rx_send_args = { - PORT_ETH, - 0, // starts with ethernet header in line 0 - 0, // filled in from list_line register -}; - -dbsm_t dsp_rx_sm; // the state machine - - -// The mac address of the host we're sending to. -eth_mac_addr_t host_mac_addr; - static void setup_network(void); // ---------------------------------------------------------------- @@ -136,11 +58,6 @@ static struct socket_address fp_socket_src, fp_socket_dst; void start_rx_streaming_cmd(void); void stop_rx_cmd(void); -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( struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len @@ -167,7 +84,7 @@ void handle_udp_data_packet( setup_network(); // kick off the state machine - dbsm_start(&dsp_rx_sm); + //FIME dbsm_start(&dsp_rx_sm); } @@ -382,6 +299,7 @@ void handle_udp_ctrl_packet( * Return true if we handled it here, otherwise * it'll be passed on to the DSP Tx pipe */ +/* static bool eth_pkt_inspector(dbsm_t *sm, int bufno) { @@ -419,6 +337,7 @@ eth_pkt_inspector(dbsm_t *sm, int bufno) handle_eth_packet(buff, len); return true; } +*/ //------------------------------------------------------------------ @@ -486,10 +405,10 @@ static void setup_network(void){ inline static void buffer_irq_handler(unsigned irq) { - uint32_t status = buffer_pool_status->status; + //FIXME uint32_t status = buffer_pool_status->status; - dbsm_process_status(&dsp_tx_sm, status); - dbsm_process_status(&dsp_rx_sm, status); + //FIXME dbsm_process_status(&dsp_tx_sm, status); + //FIXME dbsm_process_status(&dsp_rx_sm, status); } int @@ -529,23 +448,23 @@ main(void) // initialize double buffering state machine for ethernet -> DSP Tx - dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0, - &dsp_tx_recv_args, &dsp_tx_send_args, - eth_pkt_inspector); + //FIXME dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0, +//FIXME &dsp_tx_recv_args, &dsp_tx_send_args, +//FIXME eth_pkt_inspector); // initialize double buffering state machine for DSP RX -> Ethernet - dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0, - &dsp_rx_recv_args, &dsp_rx_send_args, - dbsm_rx_inspector); +//FIXME dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0, +//FIXME &dsp_rx_recv_args, &dsp_rx_send_args, +//FIXME dbsm_rx_inspector); sr_tx_ctrl->clear_state = 1; - bp_clear_buf(DSP_TX_BUF_0); - bp_clear_buf(DSP_TX_BUF_1); +//FIXME bp_clear_buf(DSP_TX_BUF_0); +//FIXME bp_clear_buf(DSP_TX_BUF_1); // kick off the state machine - dbsm_start(&dsp_tx_sm); +//FIXME dbsm_start(&dsp_tx_sm); //int which = 0; -- cgit v1.2.3 From 5d9cf99cad000faee61ddecb6990b414661eb49b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 15 Nov 2010 10:53:24 -0800 Subject: usrp2: implemented packet ctrl to read and write slow path packets from the new interface --- firmware/microblaze/apps/txrx_uhd.c | 83 ++++++------------------------------ firmware/microblaze/lib/Makefile.inc | 1 + firmware/microblaze/lib/net_common.c | 30 +++---------- firmware/microblaze/lib/pkt_ctrl.c | 54 +++++++++++++++++++++++ firmware/microblaze/lib/pkt_ctrl.h | 47 ++++++++++++++++++++ 5 files changed, 119 insertions(+), 96 deletions(-) create mode 100644 firmware/microblaze/lib/pkt_ctrl.c create mode 100644 firmware/microblaze/lib/pkt_ctrl.h (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 2d001cfa8..8a4abadf0 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -45,6 +45,7 @@ #include #include #include "udp_fw_update.h" +#include "pkt_ctrl.h" static void setup_network(void); @@ -83,9 +84,6 @@ void handle_udp_data_packet( //setup network and vrt setup_network(); - // kick off the state machine - //FIME dbsm_start(&dsp_rx_sm); - } #define OTW_GPIO_BANK_TO_NUM(bank) \ @@ -294,28 +292,7 @@ void handle_udp_ctrl_packet( } -/* - * Called when an ethernet packet is received. - * Return true if we handled it here, otherwise - * it'll be passed on to the DSP Tx pipe - */ -/* -static bool -eth_pkt_inspector(dbsm_t *sm, int bufno) -{ - //point me to the ethernet frame - uint32_t *buff = (uint32_t *)buffer_ram(bufno); - - //treat this as fast-path data? - // We have to do this operation as fast as possible. - // Therefore, we do not check all the headers, - // just check that the udp port matches - // and that the vrt header is non zero. - // In the future, a hardware state machine will do this... - if ( //warning! magic numbers approaching.... - (((buff + ((2 + 14 + 20)/sizeof(uint32_t)))[0] & 0xffff) == USRP2_UDP_DATA_PORT) && - ((buff + ((2 + 14 + 20 + 8)/sizeof(uint32_t)))[1] != USRP2_INVALID_VRT_HEADER) - ) return false; +static void handle_inp_packet(uint32_t *buff, size_t num_lines){ //test if its an ip recovery packet typedef struct{ @@ -329,15 +306,13 @@ eth_pkt_inspector(dbsm_t *sm, int bufno) if (recovery_packet->eth_hdr.ethertype == 0xbeee && strncmp(recovery_packet->code, "addr", 4) == 0){ printf("Got ip recovery packet: "); print_ip_addr(&recovery_packet->data.ip_addr); newline(); set_ip_addr(&recovery_packet->data.ip_addr); - return true; + return; } //pass it to the slow-path handler - size_t len = buffer_pool_status->last_line[bufno] - 3; - handle_eth_packet(buff, len); - return true; + handle_eth_packet(buff, num_lines); } -*/ + //------------------------------------------------------------------ @@ -402,15 +377,6 @@ static void setup_network(void){ sr_udp_sm->udp_hdr.checksum = UDP_SM_LAST_WORD; // zero UDP checksum } -inline static void -buffer_irq_handler(unsigned irq) -{ - //FIXME uint32_t status = buffer_pool_status->status; - - //FIXME dbsm_process_status(&dsp_tx_sm, status); - //FIXME dbsm_process_status(&dsp_rx_sm, status); -} - int main(void) { @@ -446,33 +412,14 @@ main(void) ethernet_register_link_changed_callback(link_changed_callback); ethernet_init(); - // initialize double buffering state machine for ethernet -> DSP Tx - - //FIXME dbsm_init(&dsp_tx_sm, DSP_TX_BUF_0, -//FIXME &dsp_tx_recv_args, &dsp_tx_send_args, -//FIXME eth_pkt_inspector); + while(true){ - - // initialize double buffering state machine for DSP RX -> Ethernet - -//FIXME dbsm_init(&dsp_rx_sm, DSP_RX_BUF_0, -//FIXME &dsp_rx_recv_args, &dsp_rx_send_args, -//FIXME dbsm_rx_inspector); - - sr_tx_ctrl->clear_state = 1; -//FIXME bp_clear_buf(DSP_TX_BUF_0); -//FIXME bp_clear_buf(DSP_TX_BUF_1); - - // kick off the state machine -//FIXME dbsm_start(&dsp_tx_sm); - - //int which = 0; - - while(1){ - // hal_gpio_write(GPIO_TX_BANK, which, 0x8000); - // which ^= 0x8000; - - buffer_irq_handler(0); + size_t num_lines; + void *buff = claim_incoming_buffer(&num_lines); + if (buff != NULL){ + handle_inp_packet((uint32_t *)buff, num_lines); + release_incoming_buffer(); + } if(i2c_done) { i2c_done = false; @@ -488,18 +435,12 @@ main(void) int pending = pic_regs->pending; // poll for under or overrun if (pending & PIC_UNDERRUN_INT){ - //dbsm_handle_tx_underrun(&dsp_tx_sm); pic_regs->pending = PIC_UNDERRUN_INT; // clear interrupt putchar('U'); } if (pending & PIC_OVERRUN_INT){ - //dbsm_handle_rx_overrun(&dsp_rx_sm); pic_regs->pending = PIC_OVERRUN_INT; // clear pending interrupt - - // FIXME Figure out how to handle this robustly. - // Any buffers that are emptying should be allowed to drain... - putchar('O'); } } diff --git a/firmware/microblaze/lib/Makefile.inc b/firmware/microblaze/lib/Makefile.inc index 1ca375861..471a244e0 100644 --- a/firmware/microblaze/lib/Makefile.inc +++ b/firmware/microblaze/lib/Makefile.inc @@ -36,6 +36,7 @@ COMMON_SRCS = \ $(top_srcdir)/lib/memset_wa.c \ $(top_srcdir)/lib/nonstdio.c \ $(top_srcdir)/lib/pic.c \ + $(top_srcdir)/lib/pkt_ctrl.c \ $(top_srcdir)/lib/print_addrs.c \ $(top_srcdir)/lib/print_rmon_regs.c \ $(top_srcdir)/lib/print_buffer.c \ diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 1ff7ebde7..cc08997a0 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -35,6 +35,7 @@ #include "if_arp.h" #include #include +#include "pkt_ctrl.h" static inline bool ip_addr_eq(const struct ip_addr a, const struct ip_addr b) @@ -119,13 +120,6 @@ send_pkt(eth_mac_addr_t dst, int ethertype, const void *buf1, size_t len1, const void *buf2, size_t len2) { - // Wait for buffer to become idle - // FIXME can this ever not be ready? - - //hal_set_leds(LED_BUF_BUSY, LED_BUF_BUSY); - //FIXME while((buffer_pool_status->status & BPS_IDLE(CPU_TX_BUF)) == 0) - //FIXME ; - //hal_set_leds(0, LED_BUF_BUSY); // Assemble the header padded_eth_hdr_t ehdr; @@ -134,9 +128,10 @@ send_pkt(eth_mac_addr_t dst, int ethertype, ehdr.src = _local_mac_addr; ehdr.ethertype = ethertype; - uint32_t *p = 0;//FIXME buffer_ram(CPU_TX_BUF); + uint32_t *buff = (uint32_t *)claim_outgoing_buffer(); // Copy the pieces into the buffer + uint32_t *p = buff; *p++ = 0x0; // slow path memcpy_wa(p, &ehdr, sizeof(ehdr)); // 4 lines p += sizeof(ehdr)/sizeof(uint32_t); @@ -166,26 +161,11 @@ send_pkt(eth_mac_addr_t dst, int ethertype, p += len2/sizeof(uint32_t); } - size_t total_len = 0;//FIXME (p - buffer_ram(CPU_TX_BUF)) * sizeof(uint32_t); + size_t total_len = (p - buff) * sizeof(uint32_t); if (total_len < 60) // ensure that we don't try to send a short packet total_len = 60; - - // wait until nobody else is sending to the ethernet - //FIXME if (ac_could_be_sending_to_eth){ - //hal_set_leds(LED_ETH_BUSY, LED_ETH_BUSY); - //FIXME dbsm_wait_for_opening(ac_could_be_sending_to_eth); - //hal_set_leds(0x0, LED_ETH_BUSY); - //FIXME } - - - // fire it off - //FIXME bp_send_from_buf(CPU_TX_BUF, cpu_tx_buf_dest_port, 1, 0, total_len/4); - - // wait for it to complete (not long, it's a small pkt) - //FIXME while((buffer_pool_status->status & (BPS_DONE(CPU_TX_BUF) | BPS_ERROR(CPU_TX_BUF))) == 0) - //FIXME ; - //FIXME bp_clear_buf(CPU_TX_BUF); + commit_outgoing_buffer(total_len/4); } unsigned int diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c new file mode 100644 index 000000000..235a09459 --- /dev/null +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -0,0 +1,54 @@ +/* + * Copyright 2010 Ettus Research LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "pkt_ctrl.h" +#include "memory_map.h" +#include +#include +#include + +static void set_control(uint32_t value, uint32_t mask){ + static uint32_t ctrl_shadow = 0; + + ctrl_shadow &= ~mask; + ctrl_shadow |= value & mask; + + buffer_pool_ctrl->ctrl = ctrl_shadow; +} + +void *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){ + set_control(0x0, 0x1); + while ((buffer_pool_status->status & 0x1) != 0){} +} + +void *claim_outgoing_buffer(void){ + while ((buffer_pool_status->status & 0x2) != 0x2){} + return buffer_ram(1); +} + +void 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 new file mode 100644 index 000000000..156fc06dc --- /dev/null +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -0,0 +1,47 @@ +/* + * Copyright 2010 Ettus Research LLC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef INCLUDED_PKT_CTRL_H +#define INCLUDED_PKT_CTRL_H + +#include + +/*! + * 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); + +/*! + * Release the incoming buffer. Call when done. + */ +void release_incoming_buffer(void); + +/*! + * Claim an outgoing buffer. + * \return a pointer to the buffer + */ +void *claim_outgoing_buffer(void); + +/*! + * Commit the outgoing buffer. + * \param num_lines how many lines written. + */ +void commit_outgoing_buffer(size_t num_lines); + +#endif /* INCLUDED_PKT_CTRL_H */ -- cgit v1.2.3 From b621dea91eeebe05c4823bc2da8780fa12997169 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 17 Nov 2010 16:12:00 -0800 Subject: usrp2: replaced spi and i2c async stuff with sync (since were out of the fast-path) --- firmware/microblaze/apps/txrx_uhd.c | 95 +++++------------------------------ firmware/microblaze/lib/Makefile.inc | 1 - firmware/microblaze/lib/spi.c | 6 ++- firmware/microblaze/lib/spi.h | 8 +-- firmware/microblaze/lib/u2_init.c | 2 - firmware/microblaze/usrp2/Makefile.am | 4 +- 6 files changed, 22 insertions(+), 94 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 8a4abadf0..4adccfed9 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -40,12 +40,12 @@ #include #include "clocks.h" #include "usrp2/fw_common.h" -#include #include #include #include #include "udp_fw_update.h" #include "pkt_ctrl.h" +#include "banal.h" static void setup_network(void); @@ -55,10 +55,6 @@ static void setup_network(void); static eth_mac_addr_t fp_mac_addr_src, fp_mac_addr_dst; static struct socket_address fp_socket_src, fp_socket_dst; -// ---------------------------------------------------------------- -void start_rx_streaming_cmd(void); -void stop_rx_cmd(void); - void handle_udp_data_packet( struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len @@ -89,33 +85,6 @@ void handle_udp_data_packet( #define OTW_GPIO_BANK_TO_NUM(bank) \ (((bank) == USRP2_DIR_RX)? (GPIO_RX_BANK) : (GPIO_TX_BANK)) -//setup the output data -static usrp2_ctrl_data_t ctrl_data_out; -static struct socket_address i2c_src; -static struct socket_address spi_src; - -static volatile bool i2c_done = false; -void i2c_read_done_callback(void) { - //printf("I2C read done callback\n"); - i2c_async_data_ready(ctrl_data_out.data.i2c_args.data); - i2c_done = true; - i2c_register_callback(0); -} - -void i2c_write_done_callback(void) { - //printf("I2C write done callback\n"); - i2c_done = true; - i2c_register_callback(0); -} - -static volatile bool spi_done = false; -static volatile uint32_t spi_readback_data; -void get_spi_readback_data(void) { - ctrl_data_out.data.spi_args.data = spi_get_data(); - spi_done = true; - spi_register_callback(0); -} - void handle_udp_ctrl_packet( struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len @@ -141,6 +110,7 @@ void handle_udp_ctrl_packet( } //setup the output data + usrp2_ctrl_data_t ctrl_data_out; ctrl_data_out.proto_ver = USRP2_FW_COMPAT_NUM; ctrl_data_out.id=USRP2_CTRL_ID_HUH_WHAT; ctrl_data_out.seq=ctrl_data_in->seq; @@ -154,7 +124,6 @@ void handle_udp_ctrl_packet( case USRP2_CTRL_ID_WAZZUP_BRO: ctrl_data_out.id = USRP2_CTRL_ID_WAZZUP_DUDE; memcpy(&ctrl_data_out.data.ip_addr, get_ip_addr(), sizeof(struct ip_addr)); - send_udp_pkt(USRP2_UDP_CTRL_PORT, src, &ctrl_data_out, sizeof(ctrl_data_out)); break; /******************************************************************* @@ -162,21 +131,19 @@ void handle_udp_ctrl_packet( ******************************************************************/ case USRP2_CTRL_ID_TRANSACT_ME_SOME_SPI_BRO:{ //transact - bool success = spi_async_transact( - //(ctrl_data_in->data.spi_args.readback == 0)? SPI_TXONLY : SPI_TXRX, + uint32_t result = spi_transact( + (ctrl_data_in->data.spi_args.readback == 0)? SPI_TXONLY : SPI_TXRX, ctrl_data_in->data.spi_args.dev, //which device ctrl_data_in->data.spi_args.data, //32 bit data ctrl_data_in->data.spi_args.num_bits, //length in bits - (ctrl_data_in->data.spi_args.mosi_edge == USRP2_CLK_EDGE_RISE)? SPIF_PUSH_FALL : SPIF_PUSH_RISE | //flags - (ctrl_data_in->data.spi_args.miso_edge == USRP2_CLK_EDGE_RISE)? SPIF_LATCH_RISE : SPIF_LATCH_FALL, - get_spi_readback_data //callback + (ctrl_data_in->data.spi_args.mosi_edge == USRP2_CLK_EDGE_RISE)? SPIF_PUSH_FALL : SPIF_PUSH_RISE | + (ctrl_data_in->data.spi_args.miso_edge == USRP2_CLK_EDGE_RISE)? SPIF_LATCH_RISE : SPIF_LATCH_FALL ); //load output + ctrl_data_out.data.spi_args.data = result; ctrl_data_out.id = USRP2_CTRL_ID_OMG_TRANSACTED_SPI_DUDE; - spi_src = src; } -// send_udp_pkt(USRP2_UDP_CTRL_PORT, src, &ctrl_data_out, sizeof(ctrl_data_out)); break; /******************************************************************* @@ -184,13 +151,11 @@ void handle_udp_ctrl_packet( ******************************************************************/ case USRP2_CTRL_ID_DO_AN_I2C_READ_FOR_ME_BRO:{ uint8_t num_bytes = ctrl_data_in->data.i2c_args.bytes; - i2c_register_callback(i2c_read_done_callback); - i2c_async_read( + i2c_read( ctrl_data_in->data.i2c_args.addr, + ctrl_data_out.data.i2c_args.data, num_bytes ); - i2c_src = src; -// i2c_dst = dst; ctrl_data_out.id = USRP2_CTRL_ID_HERES_THE_I2C_DATA_DUDE; ctrl_data_out.data.i2c_args.bytes = num_bytes; } @@ -198,14 +163,11 @@ void handle_udp_ctrl_packet( case USRP2_CTRL_ID_WRITE_THESE_I2C_VALUES_BRO:{ uint8_t num_bytes = ctrl_data_in->data.i2c_args.bytes; - i2c_register_callback(i2c_read_done_callback); - i2c_async_write( + i2c_write( ctrl_data_in->data.i2c_args.addr, ctrl_data_in->data.i2c_args.data, num_bytes ); - i2c_src = src; -// i2c_dst = dst; ctrl_data_out.id = USRP2_CTRL_ID_COOL_IM_DONE_I2C_WRITE_DUDE; ctrl_data_out.data.i2c_args.bytes = num_bytes; } @@ -237,7 +199,6 @@ void handle_udp_ctrl_packet( } ctrl_data_out.id = USRP2_CTRL_ID_OMG_POKED_REGISTER_SO_BAD_DUDE; - send_udp_pkt(USRP2_UDP_CTRL_PORT, src, &ctrl_data_out, sizeof(ctrl_data_out)); break; case USRP2_CTRL_ID_PEEK_AT_THIS_REGISTER_FOR_ME_BRO: @@ -260,7 +221,6 @@ void handle_udp_ctrl_packet( } ctrl_data_out.id = USRP2_CTRL_ID_WOAH_I_DEFINITELY_PEEKED_IT_DUDE; - send_udp_pkt(USRP2_UDP_CTRL_PORT, src, &ctrl_data_out, sizeof(ctrl_data_out)); break; case USRP2_CTRL_ID_SO_LIKE_CAN_YOU_READ_THIS_UART_BRO:{ @@ -287,9 +247,8 @@ void handle_udp_ctrl_packet( default: ctrl_data_out.id = USRP2_CTRL_ID_HUH_WHAT; - send_udp_pkt(USRP2_UDP_CTRL_PORT, src, &ctrl_data_out, sizeof(ctrl_data_out)); } - + send_udp_pkt(USRP2_UDP_CTRL_PORT, src, &ctrl_data_out, sizeof(ctrl_data_out)); } static void handle_inp_packet(uint32_t *buff, size_t num_lines){ @@ -316,28 +275,11 @@ static void handle_inp_packet(uint32_t *buff, size_t num_lines){ //------------------------------------------------------------------ -/* - * 1's complement sum for IP and UDP headers - * - * init chksum to zero to start. - */ -static unsigned int -CHKSUM(unsigned int x, unsigned int *chksum) -{ - *chksum += x; - *chksum = (*chksum & 0xffff) + (*chksum>>16); - *chksum = (*chksum & 0xffff) + (*chksum>>16); - return x; -} - /* * Called when eth phy state changes (w/ interrupts disabled) */ -volatile bool link_is_up = false; // eth handler sets this -void -link_changed_callback(int speed) -{ - link_is_up = speed != 0; +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(); @@ -421,17 +363,6 @@ main(void) release_incoming_buffer(); } - if(i2c_done) { - i2c_done = false; - send_udp_pkt(USRP2_UDP_CTRL_PORT, i2c_src, &ctrl_data_out, sizeof(ctrl_data_out)); - //printf("Sending UDP packet from main loop for I2C...\n"); - } - - if(spi_done) { - spi_done = false; - send_udp_pkt(USRP2_UDP_CTRL_PORT, spi_src, &ctrl_data_out, sizeof(ctrl_data_out)); - } - int pending = pic_regs->pending; // poll for under or overrun if (pending & PIC_UNDERRUN_INT){ diff --git a/firmware/microblaze/lib/Makefile.inc b/firmware/microblaze/lib/Makefile.inc index 471a244e0..d99fc4d98 100644 --- a/firmware/microblaze/lib/Makefile.inc +++ b/firmware/microblaze/lib/Makefile.inc @@ -30,7 +30,6 @@ COMMON_SRCS = \ $(top_srcdir)/lib/hal_io.c \ $(top_srcdir)/lib/hal_uart.c \ $(top_srcdir)/lib/i2c.c \ - $(top_srcdir)/lib/i2c_async.c \ $(top_srcdir)/lib/mdelay.c \ $(top_srcdir)/lib/memcpy_wa.c \ $(top_srcdir)/lib/memset_wa.c \ diff --git a/firmware/microblaze/lib/spi.c b/firmware/microblaze/lib/spi.c index 2a41a1bfa..af0d8a68f 100644 --- a/firmware/microblaze/lib/spi.c +++ b/firmware/microblaze/lib/spi.c @@ -20,9 +20,9 @@ #include "pic.h" #include "nonstdio.h" -void (*volatile spi_callback)(void); //SPI callback when xfer complete. +//void (*volatile spi_callback)(void); //SPI callback when xfer complete. -static void spi_irq_handler(unsigned irq); +//static void spi_irq_handler(unsigned irq); void spi_init(void) @@ -66,6 +66,7 @@ spi_transact(bool readback, int slave, uint32_t data, int length, uint32_t flags return 0; } +/* void spi_register_callback(void (*volatile callback)(void)) { spi_callback = callback; } @@ -106,3 +107,4 @@ spi_async_transact(int slave, uint32_t data, int length, uint32_t flags, void (* return true; } +*/ diff --git a/firmware/microblaze/lib/spi.h b/firmware/microblaze/lib/spi.h index 54618cedd..71245150a 100644 --- a/firmware/microblaze/lib/spi.h +++ b/firmware/microblaze/lib/spi.h @@ -48,12 +48,12 @@ void spi_wait(void); uint32_t spi_transact(bool readback, int slave, uint32_t data, int length, uint32_t flags); -uint32_t spi_get_data(void); +//uint32_t spi_get_data(void); //static void spi_irq_handler(unsigned irq); -void spi_register_callback(void (*volatile callback)(void)); +//void spi_register_callback(void (*volatile callback)(void)); -bool -spi_async_transact(int slave, uint32_t data, int length, uint32_t flags, void (*volatile callback)(void)); +//bool +//spi_async_transact(int slave, uint32_t data, int length, uint32_t flags, void (*volatile callback)(void)); // ---------------------------------------------------------------- // Routines that manipulate the FLASH SPI BUS diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 2a6ae5a60..a2669103a 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -22,7 +22,6 @@ #include "hal_io.h" #include "hal_uart.h" #include "i2c.h" -#include "i2c_async.h" #include "mdelay.h" #include "clocks.h" #include "usrp2/fw_common.h" @@ -59,7 +58,6 @@ u2_init(void) // init i2c so we can read our rev pic_init(); // progammable interrupt controller i2c_init(); - i2c_register_handler(); //for using async I2C hal_enable_ints(); // flash all leds to let us know board is alive diff --git a/firmware/microblaze/usrp2/Makefile.am b/firmware/microblaze/usrp2/Makefile.am index 7a58e7253..7fd353204 100644 --- a/firmware/microblaze/usrp2/Makefile.am +++ b/firmware/microblaze/usrp2/Makefile.am @@ -24,8 +24,6 @@ AM_LDFLAGS = \ $(COMMON_LFLAGS) \ -Wl,-defsym -Wl,_TEXT_START_ADDR=0x0050 \ -Wl,-defsym -Wl,_STACK_SIZE=3072 - -LDADD = libusrp2.a LDADD = libusrp2.a @@ -38,7 +36,7 @@ libusrp2_a_SOURCES = \ $(COMMON_SRCS) \ sd.c \ ethernet.c \ - udp_fw_update.c + udp_fw_update.c noinst_PROGRAMS = \ usrp2_txrx_uhd.elf -- cgit v1.2.3 From 68af2b9ccf556f42d7697c73406abdcc31093d1b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Wed, 17 Nov 2010 17:12:01 -0800 Subject: usrp2: implement routing mode calls, and prefix pkt ctrl calls --- firmware/microblaze/apps/txrx_uhd.c | 18 ++++++++++++------ firmware/microblaze/lib/net_common.c | 4 ++-- firmware/microblaze/lib/pkt_ctrl.c | 19 +++++++++++++++---- firmware/microblaze/lib/pkt_ctrl.h | 16 ++++++++++++---- 4 files changed, 41 insertions(+), 16 deletions(-) (limited to 'firmware/microblaze/apps') 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 +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 */ -- cgit v1.2.3 From a1f3a6605077ffb3275b094c58e8e9cdf78a899d Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 18 Nov 2010 19:30:55 -0800 Subject: packet_router: enable the serdes and always send GARP --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/u2_init.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 938491b0e..c61bc647c 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -283,12 +283,12 @@ void link_changed_callback(int 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); } + send_gratuitous_arp(); } static void setup_network(void){ diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index a2669103a..9302c90b2 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -78,6 +78,8 @@ u2_init(void) printf("ad9510 reg[0x%x] = 0x%x\n", rr, vv); } #endif - + + output_regs->serdes_ctrl = (SERDES_ENABLE | SERDES_RXEN); + return true; } -- cgit v1.2.3 From 8f07cc031b944668f18112fd9ec11228227e2207 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 18 Nov 2010 20:10:50 -0800 Subject: packet_router: take that back and only garp when link is up (FIXME initial state before garp call) --- firmware/microblaze/apps/txrx_uhd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index c61bc647c..8e2a35f58 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -283,12 +283,12 @@ void link_changed_callback(int speed){ if (speed != 0){ hal_set_leds(LED_RJ45, LED_RJ45); pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_MASTER); + send_gratuitous_arp(); } else{ hal_set_leds(0x0, LED_RJ45); pkt_ctrl_set_routing_mode(PKT_CTRL_ROUTING_MODE_SLAVE); } - send_gratuitous_arp(); } static void setup_network(void){ -- cgit v1.2.3 From 9f28245c26c46e57448c4d8f3a2c4e038d6abd2a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 19 Nov 2010 15:23:51 -0800 Subject: packet_router: added helper functions to packet router, added clear, fixed handshake, garp at start --- firmware/microblaze/apps/txrx_uhd.c | 6 +++++- firmware/microblaze/lib/net_common.c | 3 +++ firmware/microblaze/lib/pkt_ctrl.c | 39 +++++++++++++++++++++++++++--------- 3 files changed, 37 insertions(+), 11 deletions(-) (limited to 'firmware/microblaze/apps') 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); } -- cgit v1.2.3 From 6004410a7b73a52d95b8f5f0cf0fa969bef4e910 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Sun, 21 Nov 2010 13:36:25 -0800 Subject: packet_router: implemented code to program the addresses into the router --- firmware/microblaze/apps/txrx_uhd.c | 6 +++--- firmware/microblaze/lib/net_common.c | 15 +++------------ firmware/microblaze/lib/net_common.h | 4 +--- firmware/microblaze/lib/pkt_ctrl.c | 24 ++++++++++++++++++++++++ firmware/microblaze/lib/pkt_ctrl.h | 7 +++++++ 5 files changed, 38 insertions(+), 18 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index f922ce4af..741167c0e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -348,9 +348,9 @@ main(void) printf("Firmware compatibility number: %d\n", USRP2_FW_COMPAT_NUM); //1) register the addresses into the network stack - register_mac_addr(ethernet_mac_addr()); - register_ip_addr(get_ip_addr()); - + register_addrs(ethernet_mac_addr(), get_ip_addr()); + pkt_ctrl_register_addrs(ethernet_mac_addr(), get_ip_addr()); + //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet); diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 48aa460f9..e9b633b13 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -39,21 +39,12 @@ static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; -static inline bool -ip_addr_eq(const struct ip_addr a, const struct ip_addr b) -{ - return a.addr == b.addr; -} - // ------------------------------------------------------------------------ static eth_mac_addr_t _local_mac_addr; -void register_mac_addr(const eth_mac_addr_t *mac_addr){ - _local_mac_addr = *mac_addr; -} - static struct ip_addr _local_ip_addr; -void register_ip_addr(const struct ip_addr *ip_addr){ +void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr){ + _local_mac_addr = *mac_addr; _local_ip_addr = *ip_addr; } @@ -382,7 +373,7 @@ handle_arp_packet(struct arp_eth_ipv4 *p, size_t size) sip.addr = get_int32(p->ar_sip); tip.addr = get_int32(p->ar_tip); - if (ip_addr_eq(tip, _local_ip_addr)){ // They're looking for us... + if (memcmp(&tip, &_local_ip_addr, sizeof(_local_ip_addr)) == 0){ // They're looking for us... send_arp_reply(p, _local_mac_addr); } } diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 9d6a3e345..5e364adeb 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -26,9 +26,7 @@ typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); -void register_mac_addr(const eth_mac_addr_t *mac_addr); - -void register_ip_addr(const struct ip_addr *ip_addr); +void register_addrs(const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr); void register_udp_listener(int port, udp_receiver_t rcvr); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 9f662122d..52ba80e3a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -47,6 +47,30 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 +void pkt_ctrl_register_addrs( + const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr +){ + //program in the ip addr + set_control(0x1 << 4, 0x7 << 4); + set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); + set_control(0x2 << 4, 0x7 << 4); + set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); + + //program in the mac addr + set_control(0x3 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[0] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[1] << 24, 0xff00 << 16); + set_control(0x4 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[2] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[3] << 24, 0xff00 << 16); + set_control(0x5 << 4, 0x7 << 4); + set_control((uint32_t)mac_addr->addr[4] << 16, 0x00ff << 16); + set_control((uint32_t)mac_addr->addr[5] << 24, 0xff00 << 16); + + //clear cmd + set_control(0x0, 0x7 << 4); +} + void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ switch(mode){ case PKT_CTRL_ROUTING_MODE_SLAVE: diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 86fb46d32..761209530 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -19,12 +19,19 @@ #define INCLUDED_PKT_CTRL_H #include +#include +#include typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; +//! Register this devices addresses into the router +void pkt_ctrl_register_addrs( + const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr +); + //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); -- cgit v1.2.3 From 95499e2e132b1c619704b6fbc452e661633b3233 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 22 Nov 2010 13:54:48 -0800 Subject: packet_router: dont register mac, also reorganized some tidbits --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/banal.h | 18 ------------------ firmware/microblaze/lib/net_common.c | 11 +++++++++-- firmware/microblaze/lib/net_common.h | 7 +++++++ firmware/microblaze/lib/pkt_ctrl.c | 23 ++++------------------- firmware/microblaze/lib/pkt_ctrl.h | 7 ++----- firmware/microblaze/lib/u2_init.c | 10 ---------- 7 files changed, 23 insertions(+), 55 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 741167c0e..6f852bb18 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -349,7 +349,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_register_addrs(ethernet_mac_addr(), get_ip_addr()); + pkt_ctrl_register_ip_addr(get_ip_addr()); //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); diff --git a/firmware/microblaze/lib/banal.h b/firmware/microblaze/lib/banal.h index 634234350..eb7ed509a 100644 --- a/firmware/microblaze/lib/banal.h +++ b/firmware/microblaze/lib/banal.h @@ -19,27 +19,9 @@ #define INCLUDED_BANAL_H #include -#include #define dimof(x) (sizeof(x)/sizeof(x[0])) -/* - * 1's complement sum for IP and UDP headers - * - * init chksum to zero to start. - */ -static inline unsigned int -CHKSUM(unsigned int x, unsigned int *chksum) -{ - *chksum += x; - *chksum = (*chksum & 0xffff) + (*chksum>>16); - *chksum = (*chksum & 0xffff) + (*chksum>>16); - return x; -} - -unsigned int -chksum_buffer(unsigned short *buf, int nshorts, unsigned int initial_chksum); - //-------------- unsigned get_int 8, 16, 32, 64 --------------// static inline uint8_t diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index e9b633b13..9804ae4c5 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -162,7 +162,15 @@ send_pkt(eth_mac_addr_t dst, int ethertype, //printf("sent %d bytes\n", total_len); } -unsigned int +unsigned int CHKSUM(unsigned int x, unsigned int *chksum) +{ + *chksum += x; + *chksum = (*chksum & 0xffff) + (*chksum>>16); + *chksum = (*chksum & 0xffff) + (*chksum>>16); + return x; +} + +static unsigned int chksum_buffer(unsigned short *buf, int nshorts, unsigned int initial_chksum) { unsigned int chksum = initial_chksum; @@ -172,7 +180,6 @@ chksum_buffer(unsigned short *buf, int nshorts, unsigned int initial_chksum) return chksum; } - void send_ip_pkt(struct ip_addr dst, int protocol, const void *buf0, size_t len0, diff --git a/firmware/microblaze/lib/net_common.h b/firmware/microblaze/lib/net_common.h index 5e364adeb..4004ca6e6 100644 --- a/firmware/microblaze/lib/net_common.h +++ b/firmware/microblaze/lib/net_common.h @@ -23,6 +23,13 @@ #include #include +/* + * 1's complement sum for IP and UDP headers + * + * init chksum to zero to start. + */ +unsigned int CHKSUM(unsigned int x, unsigned int *chksum); + typedef void (*udp_receiver_t)(struct socket_address src, struct socket_address dst, unsigned char *payload, int payload_len); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index 52ba80e3a..9870a1f8a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -47,28 +47,15 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 -void pkt_ctrl_register_addrs( - const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr -){ +void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr){ //program in the ip addr - set_control(0x1 << 4, 0x7 << 4); + set_control(0x1 << 4, 0x3 << 4); set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); - set_control(0x2 << 4, 0x7 << 4); + set_control(0x2 << 4, 0x3 << 4); set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); - //program in the mac addr - set_control(0x3 << 4, 0x7 << 4); - set_control((uint32_t)mac_addr->addr[0] << 16, 0x00ff << 16); - set_control((uint32_t)mac_addr->addr[1] << 24, 0xff00 << 16); - set_control(0x4 << 4, 0x7 << 4); - set_control((uint32_t)mac_addr->addr[2] << 16, 0x00ff << 16); - set_control((uint32_t)mac_addr->addr[3] << 24, 0xff00 << 16); - set_control(0x5 << 4, 0x7 << 4); - set_control((uint32_t)mac_addr->addr[4] << 16, 0x00ff << 16); - set_control((uint32_t)mac_addr->addr[5] << 24, 0xff00 << 16); - //clear cmd - set_control(0x0, 0x7 << 4); + set_control(0x0, 0x3 << 4); } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ @@ -80,8 +67,6 @@ void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ 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){ diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 761209530..2e175bca0 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -20,17 +20,14 @@ #include #include -#include typedef enum { PKT_CTRL_ROUTING_MODE_SLAVE, PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; -//! Register this devices addresses into the router -void pkt_ctrl_register_addrs( - const eth_mac_addr_t *mac_addr, const struct ip_addr *ip_addr -); +//! Register the IP address into the router +void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr); //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); diff --git a/firmware/microblaze/lib/u2_init.c b/firmware/microblaze/lib/u2_init.c index 9302c90b2..191a0e816 100644 --- a/firmware/microblaze/lib/u2_init.c +++ b/firmware/microblaze/lib/u2_init.c @@ -27,16 +27,6 @@ #include "usrp2/fw_common.h" #include "nonstdio.h" -unsigned char u2_hw_rev_major; -unsigned char u2_hw_rev_minor; - -static inline void -get_hw_rev(void) -{ - bool ok = eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV, &u2_hw_rev_minor, 1); - ok &= eeprom_read(USRP2_I2C_ADDR_MBOARD, USRP2_EE_MBOARD_REV+1, &u2_hw_rev_major, 1); -} - /* * We ought to arrange for this to be called before main, but for now, * we require that the user's main call u2_init as the first thing... -- cgit v1.2.3 From 07de916b7646c78d4ad5ba9104d52343e993d198 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 23 Nov 2010 18:09:51 -0800 Subject: packet_router: added sregs for ip addr and ports the pkt control now programs the inspector with port and ip addr set the eth mac to pass all unicast added easy debug flag to net common --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/eth_mac.c | 4 +++- firmware/microblaze/lib/net_common.c | 10 ++++++---- firmware/microblaze/lib/pkt_ctrl.c | 16 +++++----------- firmware/microblaze/lib/pkt_ctrl.h | 8 ++++++-- firmware/microblaze/usrp2/memory_map.h | 2 ++ firmware/microblaze/usrp2p/memory_map.h | 2 ++ 7 files changed, 25 insertions(+), 19 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 6f852bb18..8ee53ac3e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -349,7 +349,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_register_ip_addr(get_ip_addr()); + pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_DATA_PORT); //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); diff --git a/firmware/microblaze/lib/eth_mac.c b/firmware/microblaze/lib/eth_mac.c index 034a4d494..581a5c69f 100644 --- a/firmware/microblaze/lib/eth_mac.c +++ b/firmware/microblaze/lib/eth_mac.c @@ -28,6 +28,7 @@ void eth_mac_set_addr(const eth_mac_addr_t *src) { + /* disable because MAC_SET_PASS_ALL is set below eth_mac->ucast_hi = (((unsigned int)src->addr[0])<<8) + ((unsigned int)src->addr[1]); @@ -36,6 +37,7 @@ eth_mac_set_addr(const eth_mac_addr_t *src) (((unsigned int)src->addr[3])<<16) + (((unsigned int)src->addr[4])<<8) + (((unsigned int)src->addr[5])); +*/ } @@ -45,7 +47,7 @@ eth_mac_init(const eth_mac_addr_t *src) eth_mac->miimoder = 25; // divider from CPU clock (50MHz/25 = 2MHz) eth_mac_set_addr(src); - eth_mac->settings = MAC_SET_PAUSE_EN | MAC_SET_PASS_BCAST | MAC_SET_PASS_UCAST | MAC_SET_PAUSE_SEND_EN; + eth_mac->settings = MAC_SET_PAUSE_EN | MAC_SET_PASS_BCAST | MAC_SET_PASS_UCAST | MAC_SET_PAUSE_SEND_EN | MAC_SET_PASS_ALL; eth_mac->pause_time = 38; eth_mac->pause_thresh = 1200; diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 9804ae4c5..947f41dae 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -37,6 +37,8 @@ #include #include "pkt_ctrl.h" +static const bool debug = false; + static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; // ------------------------------------------------------------------------ @@ -159,7 +161,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); + if (debug) printf("sent %d bytes\n", (int)total_len); } unsigned int CHKSUM(unsigned int x, unsigned int *chksum) @@ -388,9 +390,9 @@ 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); + static size_t bcount = 0; + if (debug) printf("===> %d\n", (int)bcount++); + if (debug) 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 9870a1f8a..f4b4b7825 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -17,8 +17,6 @@ #include "pkt_ctrl.h" #include "memory_map.h" -#include -#include #include static void set_control(uint32_t value, uint32_t mask){ @@ -47,15 +45,11 @@ static bool is_status_bit_set(int bit){ #define MODE_BIT 2 #define CLR_BIT 8 -void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr){ - //program in the ip addr - set_control(0x1 << 4, 0x3 << 4); - set_control((ip_addr->addr & 0x0000ffff) << 16, 0xffff << 16); - set_control(0x2 << 4, 0x3 << 4); - set_control((ip_addr->addr & 0xffff0000) << 0, 0xffff << 16); - - //clear cmd - set_control(0x0, 0x3 << 4); +void pkt_ctrl_program_inspector( + const struct ip_addr *ip_addr, uint16_t dsp_udp_port +){ + buffer_pool_ctrl->ip_addr = ip_addr->addr; + buffer_pool_ctrl->udp_ports = dsp_udp_port; } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 2e175bca0..927d1fc7a 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -19,6 +19,8 @@ #define INCLUDED_PKT_CTRL_H #include +#include +#include #include typedef enum { @@ -26,8 +28,10 @@ typedef enum { PKT_CTRL_ROUTING_MODE_MASTER, } pkt_ctrl_routing_mode_t; -//! Register the IP address into the router -void pkt_ctrl_register_ip_addr(const struct ip_addr *ip_addr); +//! Program the decision values into the packet inspector +void pkt_ctrl_program_inspector( + const struct ip_addr *ip_addr, uint16_t dsp_udp_port +); //! Set the routing mode for this device void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode); diff --git a/firmware/microblaze/usrp2/memory_map.h b/firmware/microblaze/usrp2/memory_map.h index 2b07ff148..25c800893 100644 --- a/firmware/microblaze/usrp2/memory_map.h +++ b/firmware/microblaze/usrp2/memory_map.h @@ -247,6 +247,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t ctrl; + volatile uint32_t ip_addr; + volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) } buffer_pool_ctrl_t; #define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE) diff --git a/firmware/microblaze/usrp2p/memory_map.h b/firmware/microblaze/usrp2p/memory_map.h index 431dc19e7..dedfdac8b 100644 --- a/firmware/microblaze/usrp2p/memory_map.h +++ b/firmware/microblaze/usrp2p/memory_map.h @@ -274,6 +274,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t ctrl; + volatile uint32_t ip_addr; + volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) } buffer_pool_ctrl_t; #define buffer_pool_ctrl ((buffer_pool_ctrl_t *) BUFFER_POOL_CTRL_BASE) -- cgit v1.2.3 From 096405b9291d1d3b3ac37d9768232cca43a37db6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Fri, 10 Dec 2010 18:57:17 -0800 Subject: packet_router: added control register to set the udp control port --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/pkt_ctrl.c | 5 +++-- firmware/microblaze/lib/pkt_ctrl.h | 2 +- firmware/microblaze/usrp2/memory_map.h | 3 ++- firmware/microblaze/usrp2p/memory_map.h | 3 ++- 5 files changed, 9 insertions(+), 6 deletions(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index 8ee53ac3e..dc41e56c4 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -349,7 +349,7 @@ main(void) //1) register the addresses into the network stack register_addrs(ethernet_mac_addr(), get_ip_addr()); - pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_DATA_PORT); + pkt_ctrl_program_inspector(get_ip_addr(), USRP2_UDP_CTRL_PORT, USRP2_UDP_DATA_PORT); //2) register callbacks for udp ports we service register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet); diff --git a/firmware/microblaze/lib/pkt_ctrl.c b/firmware/microblaze/lib/pkt_ctrl.c index d2bfc339d..7e095ec00 100644 --- a/firmware/microblaze/lib/pkt_ctrl.c +++ b/firmware/microblaze/lib/pkt_ctrl.c @@ -20,10 +20,11 @@ #include void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t dsp_udp_port + const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port ){ buffer_pool_ctrl->ip_addr = ip_addr->addr; - buffer_pool_ctrl->udp_ports = dsp_udp_port; + buffer_pool_ctrl->ctrl_ports = ctrl_port; + buffer_pool_ctrl->data_ports = data_port; } void pkt_ctrl_set_routing_mode(pkt_ctrl_routing_mode_t mode){ diff --git a/firmware/microblaze/lib/pkt_ctrl.h b/firmware/microblaze/lib/pkt_ctrl.h index 927d1fc7a..346e22094 100644 --- a/firmware/microblaze/lib/pkt_ctrl.h +++ b/firmware/microblaze/lib/pkt_ctrl.h @@ -30,7 +30,7 @@ typedef enum { //! Program the decision values into the packet inspector void pkt_ctrl_program_inspector( - const struct ip_addr *ip_addr, uint16_t dsp_udp_port + const struct ip_addr *ip_addr, uint16_t ctrl_port, uint16_t data_port ); //! Set the routing mode for this device diff --git a/firmware/microblaze/usrp2/memory_map.h b/firmware/microblaze/usrp2/memory_map.h index 09aef643e..23d96389f 100644 --- a/firmware/microblaze/usrp2/memory_map.h +++ b/firmware/microblaze/usrp2/memory_map.h @@ -248,7 +248,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t misc_ctrl; volatile uint32_t ip_addr; - volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) + volatile uint32_t ctrl_ports; //ctrl (low 16) other (high 16) + volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) volatile uint32_t cpu_out_ctrl; volatile uint32_t cpu_inp_ctrl; } buffer_pool_ctrl_t; diff --git a/firmware/microblaze/usrp2p/memory_map.h b/firmware/microblaze/usrp2p/memory_map.h index 277f433c5..5edb3b313 100644 --- a/firmware/microblaze/usrp2p/memory_map.h +++ b/firmware/microblaze/usrp2p/memory_map.h @@ -275,7 +275,8 @@ hwconfig_wishbone_divisor(void) typedef struct { volatile uint32_t misc_ctrl; volatile uint32_t ip_addr; - volatile uint32_t udp_ports; //dsp0 (low 16) dsp1 (high 16) + volatile uint32_t ctrl_ports; //ctrl (low 16) other (high 16) + volatile uint32_t data_ports; //dsp0 (low 16) dsp1 (high 16) volatile uint32_t cpu_out_ctrl; volatile uint32_t cpu_inp_ctrl; } buffer_pool_ctrl_t; -- cgit v1.2.3 From 219bcb1af4a84010f3349acb5f352fa3ce3f76d7 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 13 Dec 2010 15:54:56 -0800 Subject: packet_router: reject icmp dest unreachable when port does not match --- firmware/microblaze/apps/txrx_uhd.c | 2 +- firmware/microblaze/lib/net_common.c | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'firmware/microblaze/apps') diff --git a/firmware/microblaze/apps/txrx_uhd.c b/firmware/microblaze/apps/txrx_uhd.c index dc41e56c4..e9c98c26e 100644 --- a/firmware/microblaze/apps/txrx_uhd.c +++ b/firmware/microblaze/apps/txrx_uhd.c @@ -53,7 +53,7 @@ static void setup_network(void); // the fast-path setup global variables // ---------------------------------------------------------------- static eth_mac_addr_t fp_mac_addr_src, fp_mac_addr_dst; -static struct socket_address fp_socket_src, fp_socket_dst; +extern struct socket_address fp_socket_src, fp_socket_dst; void handle_udp_data_packet( struct socket_address src, struct socket_address dst, diff --git a/firmware/microblaze/lib/net_common.c b/firmware/microblaze/lib/net_common.c index 947f41dae..a34ca615b 100644 --- a/firmware/microblaze/lib/net_common.c +++ b/firmware/microblaze/lib/net_common.c @@ -41,6 +41,9 @@ static const bool debug = false; static const eth_mac_addr_t BCAST_MAC_ADDR = {{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}; +//used in the top level application... +struct socket_address fp_socket_src, fp_socket_dst; + // ------------------------------------------------------------------------ static eth_mac_addr_t _local_mac_addr; @@ -265,6 +268,11 @@ handle_icmp_packet(struct ip_addr src, struct ip_addr dst, if (icmp->code == ICMP_DUR_PORT){ // port unreachable //handle destination port unreachable (the host ctrl+c'd the app): + //filter out non udp data response + struct ip_hdr *ip = (struct ip_hdr *)(((uint8_t*)icmp) + sizeof(struct icmp_echo_hdr)); + struct udp_hdr *udp = (struct udp_hdr *)(((char *)ip) + IP_HLEN); + if (IPH_PROTO(ip) != IP_PROTO_UDP || udp->dest != fp_socket_dst.port) return; + //end async update packets per second sr_tx_ctrl->cyc_per_up = 0; -- cgit v1.2.3