summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/microblaze/apps/txrx_uhd.c83
-rw-r--r--firmware/microblaze/lib/Makefile.inc1
-rw-r--r--firmware/microblaze/lib/net_common.c30
-rw-r--r--firmware/microblaze/lib/pkt_ctrl.c54
-rw-r--r--firmware/microblaze/lib/pkt_ctrl.h47
5 files changed, 119 insertions, 96 deletions
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 <ethertype.h>
#include <arp_cache.h>
#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 <ethertype.h>
#include <string.h>
+#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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "pkt_ctrl.h"
+#include "memory_map.h"
+#include <stdint.h>
+#include <stdbool.h>
+#include <nonstdio.h>
+
+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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INCLUDED_PKT_CTRL_H
+#define INCLUDED_PKT_CTRL_H
+
+#include <stddef.h>
+
+/*!
+ * 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 */