summaryrefslogtreecommitdiffstats
path: root/firmware/microblaze/apps
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/microblaze/apps')
-rw-r--r--firmware/microblaze/apps/Makefile.am3
-rw-r--r--firmware/microblaze/apps/app_common_v2.c28
-rw-r--r--firmware/microblaze/apps/app_common_v2.h8
-rw-r--r--firmware/microblaze/apps/txrx.c92
4 files changed, 98 insertions, 33 deletions
diff --git a/firmware/microblaze/apps/Makefile.am b/firmware/microblaze/apps/Makefile.am
index 2a44b93c3..d3c9fb1d8 100644
--- a/firmware/microblaze/apps/Makefile.am
+++ b/firmware/microblaze/apps/Makefile.am
@@ -62,7 +62,8 @@ noinst_PROGRAMS = \
# tx_drop_SOURCES = tx_drop.c app_common.c
# tx_drop_rate_limited_SOURCES = tx_drop_rate_limited.c app_common.c
# tx_drop2_SOURCES = tx_drop2.c app_common.c
-txrx_SOURCES = txrx.c app_common_v2.c
+txrx_SOURCES = txrx.c
+# app_common_v2.c
factory_test_SOURCES = factory_test.c app_common_v2.c
eth_serdes_SOURCES = eth_serdes.c app_passthru_v2.c
serdes_txrx_SOURCES = serdes_txrx.c app_common_v2.c
diff --git a/firmware/microblaze/apps/app_common_v2.c b/firmware/microblaze/apps/app_common_v2.c
index ad5d186f0..b51148de0 100644
--- a/firmware/microblaze/apps/app_common_v2.c
+++ b/firmware/microblaze/apps/app_common_v2.c
@@ -34,6 +34,7 @@
#include "u2_init.h"
#include <string.h>
#include <stddef.h>
+#include "usrp2_fw_common.h"
volatile bool link_is_up = false; // eth handler sets this
int cpu_tx_buf_dest_port = PORT_ETH;
@@ -537,6 +538,12 @@ static size_t handle_control_packets(
return REPLY_PAYLOAD_MAX_LEN - reply_payload_space;
}
+static void handle_control_packet(
+ const usrp2_ctrl_data_t *data_in, usrp2_ctrl_data_t *data_out
+){
+
+}
+
static void
send_reply(void *reply, size_t reply_len)
{
@@ -611,16 +618,16 @@ handle_control_chan_frame(u2_eth_ip_udp_t *pkt, size_t len)
struct {
uint32_t ctrl_word;
u2_eth_ip_udp_t hdr;
- uint8_t payload[REPLY_PAYLOAD_MAX_LEN];
+ usrp2_ctrl_data_t data;
} reply _AL4;
memset(&reply, 0, sizeof(reply));
// process the control data
- size_t len_out = handle_control_packets(
- (uint8_t*)pkt + sizeof(u2_eth_ip_udp_t),
- len - sizeof(u2_eth_ip_udp_t), reply.payload
+ handle_control_packet(
+ (usrp2_ctrl_data_t*)((uint8_t*)pkt + sizeof(u2_eth_ip_udp_t)),
+ &reply.data
);
- size_t total_len = sizeof(reply) - REPLY_PAYLOAD_MAX_LEN + len_out;
+ size_t total_len = sizeof(reply);
reply.ctrl_word = total_len;
// load the ethernet header
@@ -632,7 +639,7 @@ handle_control_chan_frame(u2_eth_ip_udp_t *pkt, size_t len)
reply.hdr.ip.ip_hl = sizeof(u2_ipv4_hdr_t)/sizeof(uint32_t);
reply.hdr.ip.ip_v = 4;
reply.hdr.ip.ip_tos = 0;
- reply.hdr.ip.ip_len = sizeof(u2_ipv4_hdr_t) + sizeof(u2_udp_hdr_t) + len_out;
+ reply.hdr.ip.ip_len = sizeof(u2_ipv4_hdr_t) + sizeof(u2_udp_hdr_t) + sizeof(usrp2_ctrl_data_t);
reply.hdr.ip.ip_id = 0;
reply.hdr.ip.ip_off = IP_DF;
reply.hdr.ip.ip_ttl = 255;
@@ -645,7 +652,7 @@ handle_control_chan_frame(u2_eth_ip_udp_t *pkt, size_t len)
// load the udp header
reply.hdr.udp.src_port = pkt->udp.dst_port;
reply.hdr.udp.dst_port = pkt->udp.src_port;
- reply.hdr.udp.length = sizeof(u2_udp_hdr_t) + len_out;
+ reply.hdr.udp.length = sizeof(u2_udp_hdr_t) + sizeof(usrp2_ctrl_data_t);
reply.hdr.udp.checksum = 0;
//send the reply
@@ -663,6 +670,7 @@ eth_pkt_inspector(dbsm_t *sm, int bufno)
{
u2_eth_ip_udp_t *pkt = (u2_eth_ip_udp_t *) buffer_ram(bufno);
size_t byte_len = (buffer_pool_status->last_line[bufno] - 3) * 4;
+ printf("Got an eth packet of len %d\n", (int)byte_len);
if (pkt->eth.ethertype != ETHERTYPE_IPV4)
return true; // ignore, probably bogus PAUSE frame from MAC
@@ -670,16 +678,16 @@ eth_pkt_inspector(dbsm_t *sm, int bufno)
// inspect rcvd frame and figure out what do do.
switch (pkt->udp.dst_port){
- case 32768:
+ case USRP2_UDP_CTRL_PORT:
//record the ip and mac addrs (used when setting up data init)
host_dst_ip_addr = pkt->ip.ip_src;
host_src_ip_addr = create_ip_from_host(pkt->ip.ip_src);
host_dst_mac_addr = pkt->eth.src;
host_src_mac_addr = *ethernet_mac_addr();
- handle_control_chan_frame(pkt, byte_len);
+ //handle_control_chan_frame(pkt, byte_len);
return true;
- case 32769:
+ case USRP2_UDP_DATA_PORT:
//record the udp data ports (used when setting up data init)
host_dst_udp_port = pkt->udp.src_port;
host_src_udp_port = pkt->udp.dst_port;
diff --git a/firmware/microblaze/apps/app_common_v2.h b/firmware/microblaze/apps/app_common_v2.h
index fa4c06d9b..8be547fae 100644
--- a/firmware/microblaze/apps/app_common_v2.h
+++ b/firmware/microblaze/apps/app_common_v2.h
@@ -60,13 +60,13 @@ void stop_rx_cmd(void);
void restart_streaming(void);
bool is_streaming(void);
-#include "usrp2_ipv4_packet.h"
-#include "usrp2_udp_packet.h"
+//#include "usrp2_ipv4_packet.h"
+//#include "usrp2_udp_packet.h"
/*!
* \brief consolidated packet: padding + ethernet header + ip header + udp header
*/
-typedef struct {
+/*typedef struct {
uint16_t padding;
u2_eth_hdr_t eth;
u2_ipv4_hdr_t ip;
@@ -79,5 +79,5 @@ extern struct in_addr host_dst_ip_addr;
extern struct in_addr host_src_ip_addr;
extern eth_mac_addr_t host_dst_mac_addr;
extern eth_mac_addr_t host_src_mac_addr;
-
+*/
#endif /* INCLUDED_APP_COMMON_H */
diff --git a/firmware/microblaze/apps/txrx.c b/firmware/microblaze/apps/txrx.c
index d0108c1a5..18f34ad02 100644
--- a/firmware/microblaze/apps/txrx.c
+++ b/firmware/microblaze/apps/txrx.c
@@ -22,6 +22,8 @@
#include "config.h"
#endif
+#include <lwip/ip.h>
+#include <lwip/udp.h>
#include "u2_init.h"
#include "memory_map.h"
#include "spi.h"
@@ -32,16 +34,19 @@
#include "ethernet.h"
#include "nonstdio.h"
#include "usrp2_eth_packet.h"
-#include "usrp2_ipv4_packet.h"
+//#include "usrp2_ipv4_packet.h"
#include "usrp2_udp_packet.h"
#include "dbsm.h"
-#include "app_common_v2.h"
+//#include "app_common_v2.h"
+#include <net/padded_eth_hdr.h>
+#include <net_common.h>
#include "memcpy_wa.h"
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
#include "clocks.h"
#include <vrt/bits.h>
+#include "usrp2_fw_common.h"
#define FW_SETS_SEQNO 1 // define to 0 or 1 (FIXME must be 1 for now)
@@ -71,7 +76,7 @@ static int fw_seqno; // used when f/w is filling in sequence numbers
*/
// DSP Tx reads ethernet header words
-#define DSP_TX_FIRST_LINE ((sizeof(u2_eth_ip_udp_t))/4)
+#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 = {
@@ -134,6 +139,49 @@ bool is_streaming(void){ return streaming_p; }
// ----------------------------------------------------------------
+static eth_mac_addr_t get_my_eth_mac_addr(void){
+ return *ethernet_mac_addr();
+}
+
+static struct ip_addr get_my_ip_addr(void){
+ struct ip_addr addr;
+ addr.addr = 192 << 24 | 168 << 16 | 10 << 8 | 2 << 0;
+ return addr;
+}
+
+static bool _is_data;
+
+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;
+}
+
+void handle_udp_ctrl_packet(
+ struct socket_address src, struct socket_address dst,
+ unsigned char *payload, int payload_len
+){
+ printf("Got ctrl packet #words: %d\n", (int)payload_len);
+ send_udp_pkt(USRP2_UDP_CTRL_PORT, src, payload, payload_len);
+}
+
+/*
+ * 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)
+{
+ _is_data = false;
+ handle_eth_packet(buffer_ram(bufno), buffer_pool_status->last_line[bufno] - 3);
+ return !_is_data;
+}
+
+//------------------------------------------------------------------
+
#define VRT_HEADER_WORDS 5
#define VRT_TRAILER_WORDS 1
@@ -179,13 +227,25 @@ 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)
+ */
+volatile bool link_is_up = false; // eth handler sets this
+void
+link_changed_callback(int speed)
+{
+ link_is_up = speed != 0;
+ hal_set_leds(link_is_up ? LED_RJ45 : 0x0, LED_RJ45);
+ printf("\neth link changed: speed = %d\n", speed);
}
void
@@ -199,23 +259,23 @@ start_rx_streaming_cmd(op_start_rx_streaming_t *p)
} mem _AL4;
memset(&mem, 0, sizeof(mem));
- p->items_per_frame = (1500 - sizeof(u2_eth_ip_udp_t))/sizeof(uint32_t) - (VRT_HEADER_WORDS + VRT_TRAILER_WORDS); //FIXME
+ 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;
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_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.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
@@ -234,7 +294,7 @@ start_rx_streaming_cmd(op_start_rx_streaming_t *p)
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.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;
@@ -324,6 +384,11 @@ main(void)
ethernet_register_link_changed_callback(link_changed_callback);
ethernet_init();
+ register_get_eth_mac_addr(get_my_eth_mac_addr);
+ register_get_ip_addr(get_my_ip_addr);
+ register_udp_listener(USRP2_UDP_CTRL_PORT, handle_udp_ctrl_packet);
+ register_udp_listener(USRP2_UDP_DATA_PORT, handle_udp_data_packet);
+
#if 0
// make bit 15 of Tx gpio's be a s/w output
hal_gpio_set_sel(GPIO_TX_BANK, 15, 's');
@@ -403,12 +468,3 @@ main(void)
}
}
}
-
-//-------------------compile time checks--------------------------------
-#define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case pred:;}
-
-void compile_time_checks(void){
- COMPILE_TIME_ASSERT(sizeof(u2_eth_hdr_t) == 14);
- COMPILE_TIME_ASSERT(sizeof(u2_ipv4_hdr_t) == 20);
- COMPILE_TIME_ASSERT(sizeof(u2_udp_hdr_t) == 8);
-}