aboutsummaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/microblaze/apps/Makefile.am2
-rw-r--r--firmware/microblaze/apps/txrx.c89
2 files changed, 62 insertions, 29 deletions
diff --git a/firmware/microblaze/apps/Makefile.am b/firmware/microblaze/apps/Makefile.am
index 6d993ef8c..ff426cf8c 100644
--- a/firmware/microblaze/apps/Makefile.am
+++ b/firmware/microblaze/apps/Makefile.am
@@ -21,7 +21,7 @@ include $(top_srcdir)/Makefile.common
LDADD = $(top_srcdir)/lib/libu2fw.a
-AM_CFLAGS += -I$(top_srcdir)/../../host/lib/usrp/mboard
+AM_CFLAGS += -I$(top_srcdir)/../../host/lib/usrp
noinst_PROGRAMS = txrx.elf
diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c
index 77c8e498c..1724284b0 100644
--- a/firmware/microblaze/apps/txrx.c
+++ b/firmware/microblaze/apps/txrx.c
@@ -47,6 +47,8 @@
#include <i2c.h>
#include <lsdac.h>
#include <lsadc.h>
+#include <ethertype.h>
+#include <arp_cache.h>
#define FW_SETS_SEQNO 1 // define to 0 or 1 (FIXME must be 1 for now)
@@ -136,10 +138,14 @@ static int streaming_frame_count = 0;
bool is_streaming(void){ return streaming_p; }
-
// ----------------------------------------------------------------
+// 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;
-void start_rx_streaming_cmd(void *p);
+// ----------------------------------------------------------------
+void start_rx_streaming_cmd(void);
void stop_rx_cmd(void);
static eth_mac_addr_t get_my_eth_mac_addr(void){
@@ -158,8 +164,38 @@ void handle_udp_data_packet(
struct socket_address src, struct socket_address dst,
unsigned char *payload, int payload_len
){
- //TODO store the reply port
- _is_data = true;
+ //forward this data to the dsp when the payload is sufficient
+ //the small payload is used to give the device the udp source port
+ if (payload_len > sizeof(uint32_t)){
+ _is_data = true;
+ return;
+ }
+
+ //its a tiny payload, load the fast-path variables
+ fp_mac_addr_src = get_my_eth_mac_addr();
+ arp_cache_lookup_mac(&src.addr, &fp_mac_addr_dst);
+ fp_socket_src = dst;
+ fp_socket_dst = src;
+ 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 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 udp port: %d\n", fp_socket_dst.port);
+ newline();
}
#define OTW_GPIO_BANK_TO_NUM(bank) \
@@ -423,7 +459,7 @@ void handle_udp_ctrl_packet(
stop_rx_cmd();
}
else{
- start_rx_streaming_cmd(NULL);
+ start_rx_streaming_cmd();
}
ctrl_data_out.id = USRP2_CTRL_ID_CONFIGURED_THAT_STREAMING_DUDE;
@@ -480,7 +516,7 @@ eth_pkt_inspector(dbsm_t *sm, int bufno)
//------------------------------------------------------------------
#define VRT_HEADER_WORDS 5
-#define VRT_TRAILER_WORDS 1
+#define VRT_TRAILER_WORDS 0
void
restart_streaming(void)
@@ -491,7 +527,7 @@ restart_streaming(void)
sr_rx_ctrl->clear_overrun = 1; // reset
sr_rx_ctrl->vrt_header = (0
| VRTH_PT_IF_DATA_WITH_SID
- | VRTH_HAS_TRAILER
+ | ((VRT_TRAILER_WORDS)? VRTH_HAS_TRAILER : 0)
| VRTH_TSI_OTHER
| VRTH_TSF_SAMPLE_CNT
| (VRT_HEADER_WORDS+streaming_items_per_frame+VRT_TRAILER_WORDS));
@@ -524,14 +560,14 @@ restart_streaming(void)
*
* init chksum to zero to start.
*/
-/*static unsigned int
+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)
@@ -546,7 +582,7 @@ link_changed_callback(int speed)
}
void
-start_rx_streaming_cmd(void *p)
+start_rx_streaming_cmd(void)
{
/*
* Construct ethernet header and preload into two buffers
@@ -556,31 +592,31 @@ start_rx_streaming_cmd(void *p)
} mem _AL4;
memset(&mem, 0, sizeof(mem));
- //p->items_per_frame = (1500)/sizeof(uint32_t) - (DSP_TX_FIRST_LINE + VRT_HEADER_WORDS + VRT_TRAILER_WORDS); //FIXME
- //mem.ctrl_word = (VRT_HEADER_WORDS+p->items_per_frame+VRT_TRAILER_WORDS)*sizeof(uint32_t) | 1 << 16;
+ streaming_items_per_frame = (1500)/sizeof(uint32_t) - (DSP_TX_FIRST_LINE + VRT_HEADER_WORDS + VRT_TRAILER_WORDS); //FIXME
+ mem.ctrl_word = (VRT_HEADER_WORDS+streaming_items_per_frame+VRT_TRAILER_WORDS)*sizeof(uint32_t) | 1 << 16;
memcpy_wa(buffer_ram(DSP_RX_BUF_0), &mem, sizeof(mem));
memcpy_wa(buffer_ram(DSP_RX_BUF_1), &mem, sizeof(mem));
//setup ethernet header machine
- /*sr_udp_sm->eth_hdr.mac_dst_0_1 = (host_dst_mac_addr.addr[0] << 8) | host_dst_mac_addr.addr[1];
- sr_udp_sm->eth_hdr.mac_dst_2_3 = (host_dst_mac_addr.addr[2] << 8) | host_dst_mac_addr.addr[3];
- sr_udp_sm->eth_hdr.mac_dst_4_5 = (host_dst_mac_addr.addr[4] << 8) | host_dst_mac_addr.addr[5];
- sr_udp_sm->eth_hdr.mac_src_0_1 = (host_src_mac_addr.addr[0] << 8) | host_src_mac_addr.addr[1];
- sr_udp_sm->eth_hdr.mac_src_2_3 = (host_src_mac_addr.addr[2] << 8) | host_src_mac_addr.addr[3];
- sr_udp_sm->eth_hdr.mac_src_4_5 = (host_src_mac_addr.addr[4] << 8) | host_src_mac_addr.addr[5];
- sr_udp_sm->eth_hdr.ether_type = ETHERTYPE_IPV4;*/
+ sr_udp_sm->eth_hdr.mac_dst_0_1 = (fp_mac_addr_dst.addr[0] << 8) | fp_mac_addr_dst.addr[1];
+ sr_udp_sm->eth_hdr.mac_dst_2_3 = (fp_mac_addr_dst.addr[2] << 8) | fp_mac_addr_dst.addr[3];
+ sr_udp_sm->eth_hdr.mac_dst_4_5 = (fp_mac_addr_dst.addr[4] << 8) | fp_mac_addr_dst.addr[5];
+ sr_udp_sm->eth_hdr.mac_src_0_1 = (fp_mac_addr_src.addr[0] << 8) | fp_mac_addr_src.addr[1];
+ sr_udp_sm->eth_hdr.mac_src_2_3 = (fp_mac_addr_src.addr[2] << 8) | fp_mac_addr_src.addr[3];
+ sr_udp_sm->eth_hdr.mac_src_4_5 = (fp_mac_addr_src.addr[4] << 8) | fp_mac_addr_src.addr[5];
+ sr_udp_sm->eth_hdr.ether_type = ETHERTYPE_IPV4;
//setup ip header machine
- /*unsigned int chksum = 0;
+ unsigned int chksum = 0;
sr_udp_sm->ip_hdr.ver_ihl_tos = CHKSUM(0x4500, &chksum); // IPV4, 5 words of header (20 bytes), TOS=0
sr_udp_sm->ip_hdr.total_length = UDP_SM_INS_IP_LEN; // Don't checksum this line in SW
sr_udp_sm->ip_hdr.identification = CHKSUM(0x0000, &chksum); // ID
sr_udp_sm->ip_hdr.flags_frag_off = CHKSUM(0x4000, &chksum); // don't fragment
sr_udp_sm->ip_hdr.ttl_proto = CHKSUM(0x2011, &chksum); // TTL=32, protocol = UDP (17 decimal)
//sr_udp_sm->ip_hdr.checksum .... filled in below
- uint32_t src_ip_addr = host_src_ip_addr.s_addr;
- uint32_t dst_ip_addr = host_dst_ip_addr.s_addr;
+ uint32_t src_ip_addr = fp_socket_src.addr.addr;
+ uint32_t dst_ip_addr = fp_socket_dst.addr.addr;
sr_udp_sm->ip_hdr.src_addr_high = CHKSUM(src_ip_addr >> 16, &chksum); // IP src high
sr_udp_sm->ip_hdr.src_addr_low = CHKSUM(src_ip_addr & 0xffff, &chksum); // IP src low
sr_udp_sm->ip_hdr.dst_addr_high = CHKSUM(dst_ip_addr >> 16, &chksum); // IP dst high
@@ -588,17 +624,14 @@ start_rx_streaming_cmd(void *p)
sr_udp_sm->ip_hdr.checksum = UDP_SM_INS_IP_HDR_CHKSUM | (chksum & 0xffff);
//setup the udp header machine
- sr_udp_sm->udp_hdr.src_port = host_src_udp_port;
- sr_udp_sm->udp_hdr.dst_port = host_dst_udp_port;
+ sr_udp_sm->udp_hdr.src_port = fp_socket_src.port;
+ sr_udp_sm->udp_hdr.dst_port = fp_socket_dst.port;
sr_udp_sm->udp_hdr.length = UDP_SM_INS_UDP_LEN;
- sr_udp_sm->udp_hdr.checksum = UDP_SM_LAST_WORD; // zero UDP checksum*/
+ sr_udp_sm->udp_hdr.checksum = UDP_SM_LAST_WORD; // zero UDP checksum
if (FW_SETS_SEQNO)
fw_seqno = 0;
- //streaming_items_per_frame = p->items_per_frame;
- //time_secs = p->time_secs;
- //time_ticks = p->time_ticks;
restart_streaming();
}