summaryrefslogtreecommitdiffstats
path: root/firmware/x300/include
diff options
context:
space:
mode:
authorBen Hilburn <ben.hilburn@ettus.com>2014-02-04 11:04:07 -0800
committerBen Hilburn <ben.hilburn@ettus.com>2014-02-04 11:04:07 -0800
commit178ac3f1c9950d383c8f64b3df464c0f943c4a23 (patch)
tree318ed621a7b59b7d34d4ce6e4a92f73f0bcef509 /firmware/x300/include
parent2718ac110fa931cc29daf7cb3dc5ab6230ee02ab (diff)
downloaduhd-178ac3f1c9950d383c8f64b3df464c0f943c4a23.tar.gz
uhd-178ac3f1c9950d383c8f64b3df464c0f943c4a23.tar.bz2
uhd-178ac3f1c9950d383c8f64b3df464c0f943c4a23.zip
Merging USRP X300 and X310 support!!
Diffstat (limited to 'firmware/x300/include')
-rw-r--r--firmware/x300/include/chinch.h109
-rw-r--r--firmware/x300/include/ethernet.h53
-rw-r--r--firmware/x300/include/ethertype.h27
-rw-r--r--firmware/x300/include/if_arp.h153
-rw-r--r--firmware/x300/include/link_state_route_proto.h56
-rw-r--r--firmware/x300/include/mdelay.h29
-rw-r--r--firmware/x300/include/print_addrs.h15
-rw-r--r--firmware/x300/include/printf.h108
-rw-r--r--firmware/x300/include/stdint.h34
-rw-r--r--firmware/x300/include/u3_net_stack.h113
-rw-r--r--firmware/x300/include/udp_uart.h37
-rw-r--r--firmware/x300/include/wb_i2c.h18
-rw-r--r--firmware/x300/include/wb_pkt_iface64.h44
-rw-r--r--firmware/x300/include/wb_uart.h23
-rw-r--r--firmware/x300/include/wb_utils.h24
-rw-r--r--firmware/x300/include/xge_mac.h37
-rw-r--r--firmware/x300/include/xge_phy.h78
17 files changed, 958 insertions, 0 deletions
diff --git a/firmware/x300/include/chinch.h b/firmware/x300/include/chinch.h
new file mode 100644
index 000000000..a3e70337a
--- /dev/null
+++ b/firmware/x300/include/chinch.h
@@ -0,0 +1,109 @@
+//
+// Copyright 2013 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_CHINCH_H
+#define INCLUDED_CHINCH_H
+
+#include <wb_utils.h>
+#include <stdbool.h>
+#include <printf.h>
+
+#define STATUS_CHAIN(x, status) if (status) status = (x)
+#define STATUS_MERGE(x, status) status &= (x)
+#define STATUS_CHAIN_DBG(x, status) STATUS_CHAIN(x, status); printf("%s: %s\n", #x, status?"succeeded":"failed!")
+
+//The unit for this timeout is somewhat arbitrary. We could use the counter reg to enforce this in
+//terms of clock cycles but that is not worth the extra code
+static const uint32_t CHINCH_DEFAULT_XACT_TIMEOUT = 32768;
+static const uint32_t CHINCH_FLASH_MAX_BUF_WRITES = 32;
+
+//-----------------------------------------------------
+// Peek-Poke interface for the Chinch
+//-----------------------------------------------------
+bool chinch_poke(const uint32_t addr, const uint32_t data, bool half_word, uint32_t timeout);
+bool chinch_peek(const uint32_t addr, uint32_t* data, bool half_word, uint32_t timeout);
+
+static inline bool chinch_poke32(const uint32_t addr, const uint32_t data) {
+ return chinch_poke(addr, data, false /*half word*/, CHINCH_DEFAULT_XACT_TIMEOUT);
+}
+static inline bool chinch_poke16(const uint32_t addr, const uint32_t data) {
+ return chinch_poke(addr, data, true /*half word*/, CHINCH_DEFAULT_XACT_TIMEOUT);
+}
+static inline bool chinch_peek32(const uint32_t addr, uint32_t* data) {
+ return chinch_peek(addr, data, false /*half word*/, CHINCH_DEFAULT_XACT_TIMEOUT);
+}
+static inline bool chinch_peek16(const uint32_t addr, uint32_t* data) {
+ return chinch_peek(addr, data, true /*half word*/, CHINCH_DEFAULT_XACT_TIMEOUT);
+}
+
+//-----------------------------------------------------
+// Flash access
+//-----------------------------------------------------
+bool chinch_flash_init();
+void chinch_flash_cleanup();
+bool chinch_flash_select_sector(uint32_t sector);
+bool chinch_flash_erase_sector();
+bool chinch_flash_read_buf(uint32_t offset, uint16_t* buf, uint32_t size);
+bool chinch_flash_write_buf(uint32_t offset, uint16_t* buf, uint32_t size);
+
+static inline bool chinch_flash_read(uint32_t offset, uint16_t* data) {
+ return chinch_flash_read_buf(offset, data, 1);
+}
+static inline bool chinch_flash_write(uint32_t offset, uint16_t data) {
+ return chinch_flash_write_buf(offset, &data, 1);
+}
+
+//-----------------------------------------------------
+// FPGA Configuration
+//-----------------------------------------------------
+typedef uint8_t config_status_t;
+static const config_status_t CHINCH_CONFIG_RUNNING = 0;
+static const config_status_t CHINCH_CONFIG_DISABLED = 1;
+static const config_status_t CHINCH_CONFIG_COMPLETED = 2;
+static const config_status_t CHINCH_CONFIG_ERROR = 3;
+
+void chinch_start_config(); //Caution: This operation will make the ZPU self-destruct!
+config_status_t chinch_get_config_status();
+
+//-----------------------------------------------------
+// Read-back interface for user initiated
+// PCIe register transactions
+//-----------------------------------------------------
+typedef uint8_t pcie_xact_size_t;
+static const pcie_xact_size_t PCIE_XACT_32_BIT = 0;
+static const pcie_xact_size_t PCIE_XACT_16_BIT = 1;
+
+typedef uint8_t pcie_xact_t;
+static const pcie_xact_t PCIE_XACT_ERROR = 0;
+static const pcie_xact_t PCIE_XACT_READ = 1;
+static const pcie_xact_t PCIE_XACT_WRITE = 2;
+
+typedef bool (*pcie_register_xact_responder_t)(uint32_t response, uint32_t timeout);
+
+typedef struct
+{
+ pcie_xact_t type;
+ uint32_t addr;
+ uint32_t data;
+ pcie_xact_size_t size;
+ pcie_register_xact_responder_t respond;
+} pcie_register_xact_t;
+
+bool check_pcie_user_regport(pcie_register_xact_t** xact_info_hdl);
+bool forward_pcie_user_xact_to_wb();
+
+
+#endif /* INCLUDED_CHINCH_H */
diff --git a/firmware/x300/include/ethernet.h b/firmware/x300/include/ethernet.h
new file mode 100644
index 000000000..52f14d05b
--- /dev/null
+++ b/firmware/x300/include/ethernet.h
@@ -0,0 +1,53 @@
+/* -*- c -*- */
+/*
+ * Copyright 2007,2009 Free Software Foundation, Inc.
+ * Copyright 2009 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_ETHERNET_H
+#define INCLUDED_ETHERNET_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+typedef void (*ethernet_link_changed_callback_t)(int ethnum, int speed);
+
+#define MDIO_PORT 4
+
+/*!
+ * \brief one time call to initialize ethernet
+ */
+void xge_ethernet_init(const uint32_t eth);
+
+/*!
+ * \brief Return number of ethernet interfaces
+ */
+int ethernet_ninterfaces(void);
+
+
+void dump_mdio_regs(const uint8_t eth, uint32_t mdio_port);
+
+/*!
+ * \brief Test status of SFP+ modules
+ */
+void
+xge_poll_sfpp_status(const uint32_t eth);
+
+//! get the link status of eth (true for link up)
+bool ethernet_get_link_up(const uint32_t eth);
+
+#endif /* INCLUDED_ETHERNET_H */
diff --git a/firmware/x300/include/ethertype.h b/firmware/x300/include/ethertype.h
new file mode 100644
index 000000000..235981193
--- /dev/null
+++ b/firmware/x300/include/ethertype.h
@@ -0,0 +1,27 @@
+/* -*- c++ -*- */
+/*
+ * Copyright 2009-2011 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_ETHERTYPE_H
+#define INCLUDED_ETHERTYPE_H
+
+// all we care about
+
+#define ETHERTYPE_IPV4 0x0800
+#define ETHERTYPE_ARP 0x0806
+
+
+#endif /* INCLUDED_ETHERTYPE_H */
diff --git a/firmware/x300/include/if_arp.h b/firmware/x300/include/if_arp.h
new file mode 100644
index 000000000..63519c4be
--- /dev/null
+++ b/firmware/x300/include/if_arp.h
@@ -0,0 +1,153 @@
+/*
+ * INET An implementation of the TCP/IP protocol suite for the LINUX
+ * operating system. INET is implemented using the BSD Socket
+ * interface as the means of communication with the user level.
+ *
+ * Global definitions for the ARP (RFC 826) protocol.
+ *
+ * Version: @(#)if_arp.h 1.0.1 04/16/93
+ *
+ * Authors: Original taken from Berkeley UNIX 4.3, (c) UCB 1986-1988
+ * Portions taken from the KA9Q/NOS (v2.00m PA0GRI) source.
+ * Ross Biro
+ * Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
+ * Florian La Roche,
+ * Jonathan Layes <layes@loran.com>
+ * Arnaldo Carvalho de Melo <acme@conectiva.com.br> ARPHRD_HWX25
+ *
+ * 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
+ * 2 of the License, or (at your option) any later version.
+ */
+#ifndef _LINUX_IF_ARP_H
+#define _LINUX_IF_ARP_H
+
+/* ARP protocol HARDWARE identifiers. */
+#define ARPHRD_NETROM 0 /* from KA9Q: NET/ROM pseudo */
+#define ARPHRD_ETHER 1 /* Ethernet 10Mbps */
+#define ARPHRD_EETHER 2 /* Experimental Ethernet */
+#define ARPHRD_AX25 3 /* AX.25 Level 2 */
+#define ARPHRD_PRONET 4 /* PROnet token ring */
+#define ARPHRD_CHAOS 5 /* Chaosnet */
+#define ARPHRD_IEEE802 6 /* IEEE 802.2 Ethernet/TR/TB */
+#define ARPHRD_ARCNET 7 /* ARCnet */
+#define ARPHRD_APPLETLK 8 /* APPLEtalk */
+#define ARPHRD_DLCI 15 /* Frame Relay DLCI */
+#define ARPHRD_ATM 19 /* ATM */
+#define ARPHRD_METRICOM 23 /* Metricom STRIP (new IANA id) */
+#define ARPHRD_IEEE1394 24 /* IEEE 1394 IPv4 - RFC 2734 */
+#define ARPHRD_EUI64 27 /* EUI-64 */
+#define ARPHRD_INFINIBAND 32 /* InfiniBand */
+
+/* Dummy types for non ARP hardware */
+#define ARPHRD_SLIP 256
+#define ARPHRD_CSLIP 257
+#define ARPHRD_SLIP6 258
+#define ARPHRD_CSLIP6 259
+#define ARPHRD_RSRVD 260 /* Notional KISS type */
+#define ARPHRD_ADAPT 264
+#define ARPHRD_ROSE 270
+#define ARPHRD_X25 271 /* CCITT X.25 */
+#define ARPHRD_HWX25 272 /* Boards with X.25 in firmware */
+#define ARPHRD_CAN 280 /* Controller Area Network */
+#define ARPHRD_PPP 512
+#define ARPHRD_CISCO 513 /* Cisco HDLC */
+#define ARPHRD_HDLC ARPHRD_CISCO
+#define ARPHRD_LAPB 516 /* LAPB */
+#define ARPHRD_DDCMP 517 /* Digital's DDCMP protocol */
+#define ARPHRD_RAWHDLC 518 /* Raw HDLC */
+
+#define ARPHRD_TUNNEL 768 /* IPIP tunnel */
+#define ARPHRD_TUNNEL6 769 /* IP6IP6 tunnel */
+#define ARPHRD_FRAD 770 /* Frame Relay Access Device */
+#define ARPHRD_SKIP 771 /* SKIP vif */
+#define ARPHRD_LOOPBACK 772 /* Loopback device */
+#define ARPHRD_LOCALTLK 773 /* Localtalk device */
+#define ARPHRD_FDDI 774 /* Fiber Distributed Data Interface */
+#define ARPHRD_BIF 775 /* AP1000 BIF */
+#define ARPHRD_SIT 776 /* sit0 device - IPv6-in-IPv4 */
+#define ARPHRD_IPDDP 777 /* IP over DDP tunneller */
+#define ARPHRD_IPGRE 778 /* GRE over IP */
+#define ARPHRD_PIMREG 779 /* PIMSM register interface */
+#define ARPHRD_HIPPI 780 /* High Performance Parallel Interface */
+#define ARPHRD_ASH 781 /* Nexus 64Mbps Ash */
+#define ARPHRD_ECONET 782 /* Acorn Econet */
+#define ARPHRD_IRDA 783 /* Linux-IrDA */
+/* ARP works differently on different FC media .. so */
+#define ARPHRD_FCPP 784 /* Point to point fibrechannel */
+#define ARPHRD_FCAL 785 /* Fibrechannel arbitrated loop */
+#define ARPHRD_FCPL 786 /* Fibrechannel public loop */
+#define ARPHRD_FCFABRIC 787 /* Fibrechannel fabric */
+ /* 787->799 reserved for fibrechannel media types */
+#define ARPHRD_IEEE802_TR 800 /* Magic type ident for TR */
+#define ARPHRD_IEEE80211 801 /* IEEE 802.11 */
+#define ARPHRD_IEEE80211_PRISM 802 /* IEEE 802.11 + Prism2 header */
+#define ARPHRD_IEEE80211_RADIOTAP 803 /* IEEE 802.11 + radiotap header */
+
+#define ARPHRD_VOID 0xFFFF /* Void type, nothing is known */
+#define ARPHRD_NONE 0xFFFE /* zero header length */
+
+/* ARP protocol opcodes. */
+#define ARPOP_REQUEST 1 /* ARP request */
+#define ARPOP_REPLY 2 /* ARP reply */
+#define ARPOP_RREQUEST 3 /* RARP request */
+#define ARPOP_RREPLY 4 /* RARP reply */
+#define ARPOP_InREQUEST 8 /* InARP request */
+#define ARPOP_InREPLY 9 /* InARP reply */
+#define ARPOP_NAK 10 /* (ATM)ARP NAK */
+
+
+/* ARP Flag values. */
+#define ATF_COM 0x02 /* completed entry (ha valid) */
+#define ATF_PERM 0x04 /* permanent entry */
+#define ATF_PUBL 0x08 /* publish entry */
+#define ATF_USETRAILERS 0x10 /* has requested trailers */
+#define ATF_NETMASK 0x20 /* want to use a netmask (only
+ for proxy entries) */
+#define ATF_DONTPUB 0x40 /* don't answer this addresses */
+
+typedef unsigned short __be16;
+
+/*
+ * This structure defines an ethernet arp header.
+ */
+struct arphdr
+{
+ __be16 ar_hrd; /* format of hardware address */
+ __be16 ar_pro; /* format of protocol address */
+ unsigned char ar_hln; /* length of hardware address */
+ unsigned char ar_pln; /* length of protocol address */
+ __be16 ar_op; /* ARP opcode (command) */
+
+#if 0
+ /*
+ * Ethernet looks like this : This bit is variable sized however...
+ */
+ unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */
+ unsigned char ar_sip[4]; /* sender IP address */
+ unsigned char ar_tha[ETH_ALEN]; /* target hardware address */
+ unsigned char ar_tip[4]; /* target IP address */
+#endif
+
+};
+
+/*
+ * This structure defines an ethernet arp header.
+ */
+struct arp_eth_ipv4
+{
+ __be16 ar_hrd; /* format of hardware address */
+ __be16 ar_pro; /* format of protocol address */
+ unsigned char ar_hln; /* length of hardware address */
+ unsigned char ar_pln; /* length of protocol address */
+ __be16 ar_op; /* ARP opcode (command) */
+
+ unsigned char ar_sha[6]; /* sender hardware address */
+ unsigned char ar_sip[4]; /* sender IP address */
+ unsigned char ar_tha[6]; /* target hardware address */
+ unsigned char ar_tip[4]; /* target IP address */
+};
+
+
+#endif /* _LINUX_IF_ARP_H */
diff --git a/firmware/x300/include/link_state_route_proto.h b/firmware/x300/include/link_state_route_proto.h
new file mode 100644
index 000000000..8feb3e717
--- /dev/null
+++ b/firmware/x300/include/link_state_route_proto.h
@@ -0,0 +1,56 @@
+
+// Copyright 2013 Ettus Research LLC
+
+#ifndef INCLUDED_LINK_STATE_ROUTE_PROTO_H
+#define INCLUDED_LINK_STATE_ROUTE_PROTO_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+#include <lwip/ip_addr.h>
+
+//http://en.wikipedia.org/wiki/Link-state_routing_protocol
+
+//! Initialize internals and handler registration
+void link_state_route_proto_init(void);
+
+/*!
+ * Advances the internal counter to determine expired entries.
+ * Call this periodically, along with the other periodic calls.
+ */
+void link_state_route_proto_tick(void);
+
+//! Initiate a periodic update to the neighbor table
+void link_state_route_proto_update(const uint8_t ethno);
+
+//! Flood the network with information about routes
+void link_state_route_proto_flood(const uint8_t ethno);
+
+/*!
+ * Updates the causes cycle cache for the given source ethno.
+ */
+void link_state_route_proto_update_cycle_cache(const uint8_t ethno);
+
+/*!
+ * Determine if the given link is the cause of a cycle (aka routing loop)
+ * This call does not run the algorithm, but rather checks the cache.
+ * This call also differs from the one below, takes the ethnos.
+ */
+bool link_state_route_proto_causes_cycle_cached(const uint8_t eth_src, const uint8_t eth_dst);
+
+//! Determine if the given link is the cause of a cycle (aka routing loop)
+bool link_state_route_proto_causes_cycle(const struct ip_addr *src, const struct ip_addr *dst);
+
+typedef struct
+{
+ struct ip_addr node;
+ struct ip_addr nbor;
+} ls_node_mapping_t;
+
+/*!
+ * Get a pointer to the node mapping table.
+ * The table length will be set to *length.
+ */
+const ls_node_mapping_t *link_state_route_get_node_mapping(size_t *length);
+
+#endif /* INCLUDED_LINK_STATE_ROUTE_PROTO_H */
diff --git a/firmware/x300/include/mdelay.h b/firmware/x300/include/mdelay.h
new file mode 100644
index 000000000..226bbb3f7
--- /dev/null
+++ b/firmware/x300/include/mdelay.h
@@ -0,0 +1,29 @@
+/* -*- c -*- */
+/*
+ * Copyright 2007 Free Software Foundation, Inc.
+ *
+ * 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_MDELAY_H
+#define INCLUDED_MDELAY_H
+
+/*!
+ * \brief Delay about ms milliseconds
+ *
+ * If simulating, _very_ short delay
+ */
+void mdelay(int ms);
+
+#endif /* INCLUDED_MDELAY_H */
diff --git a/firmware/x300/include/print_addrs.h b/firmware/x300/include/print_addrs.h
new file mode 100644
index 000000000..1aa5d6888
--- /dev/null
+++ b/firmware/x300/include/print_addrs.h
@@ -0,0 +1,15 @@
+// Copyright 2013 Ettus Research LLC
+
+#ifndef INCLUDED_PRINT_ADDRS_H
+#define INCLUDED_PRINT_ADDRS_H
+
+char *mac_addr_to_str_r(const void *addr, char *str);
+char *ip_addr_to_str_r(const void *addr, char *str);
+
+char *mac_addr_to_str(const void *addr);
+char *ip_addr_to_str(const void *addr);
+
+//void print_mac_addr(const void *addr);
+//void print_ip_addr(const void *addr);
+
+#endif /* INCLUDED_PRINT_ADDRS_H */
diff --git a/firmware/x300/include/printf.h b/firmware/x300/include/printf.h
new file mode 100644
index 000000000..6b3088dbe
--- /dev/null
+++ b/firmware/x300/include/printf.h
@@ -0,0 +1,108 @@
+/*
+File: printf.h
+
+Copyright (C) 2004 Kustaa Nyholm
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library 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 Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+This library is realy just two files: 'printf.h' and 'printf.c'.
+
+They provide a simple and small (+200 loc) printf functionality to
+be used in embedded systems.
+
+I've found them so usefull in debugging that I do not bother with a
+debugger at all.
+
+They are distributed in source form, so to use them, just compile them
+into your project.
+
+Two printf variants are provided: printf and sprintf.
+
+The formats supported by this implementation are: 'd' 'u' 'c' 's' 'x' 'X'.
+
+Zero padding and field width are also supported.
+
+If the library is compiled with 'PRINTF_SUPPORT_LONG' defined then the
+long specifier is also
+supported. Note that this will pull in some long math routines (pun intended!)
+and thus make your executable noticably longer.
+
+The memory foot print of course depends on the target cpu, compiler and
+compiler options, but a rough guestimate (based on a H8S target) is about
+1.4 kB for code and some twenty 'int's and 'char's, say 60 bytes of stack space.
+Not too bad. Your milage may vary. By hacking the source code you can
+get rid of some hunred bytes, I'm sure, but personally I feel the balance of
+functionality and flexibility versus code size is close to optimal for
+many embedded systems.
+
+To use the printf you need to supply your own character output function,
+something like :
+
+ void putc ( void* p, char c)
+ {
+ while (!SERIAL_PORT_EMPTY) ;
+ SERIAL_PORT_TX_REGISTER = c;
+ }
+
+Before you can call printf you need to initialize it to use your
+character output function with something like:
+
+ init_printf(NULL,putc);
+
+Notice the 'NULL' in 'init_printf' and the parameter 'void* p' in 'putc',
+the NULL (or any pointer) you pass into the 'init_printf' will eventually be
+passed to your 'putc' routine. This allows you to pass some storage space (or
+anything realy) to the character output function, if necessary.
+This is not often needed but it was implemented like that because it made
+implementing the sprintf function so neat (look at the source code).
+
+The code is re-entrant, except for the 'init_printf' function, so it
+is safe to call it from interupts too, although this may result in mixed output.
+If you rely on re-entrancy, take care that your 'putc' function is re-entrant!
+
+The printf and sprintf functions are actually macros that translate to
+'tfp_printf' and 'tfp_sprintf'. This makes it possible
+to use them along with 'stdio.h' printf's in a single source file.
+You just need to undef the names before you include the 'stdio.h'.
+Note that these are not function like macros, so if you have variables
+or struct members with these names, things will explode in your face.
+Without variadic macros this is the best we can do to wrap these
+fucnction. If it is a problem just give up the macros and use the
+functions directly or rename them.
+
+For further details see source code.
+
+regs Kusti, 23.10.2004
+*/
+
+
+#ifndef __TFP_PRINTF__
+#define __TFP_PRINTF__
+
+#include <stdarg.h>
+
+void init_printf(void* putp,void (*putf) (void*,char));
+
+void tfp_printf(char *fmt, ...);
+void tfp_sprintf(char* s,char *fmt, ...);
+
+void tfp_format(void* putp,void (*putf) (void*,char),char *fmt, va_list va);
+
+#define printf tfp_printf
+#define sprintf tfp_sprintf
+#define PRINTF_LONG_SUPPORT 1
+//#define PRINTF_LONG_LONG_SUPPORT 1 //IJB gcc for ZPU long long appears to have bugs
+
+#endif
diff --git a/firmware/x300/include/stdint.h b/firmware/x300/include/stdint.h
new file mode 100644
index 000000000..b5a8611a9
--- /dev/null
+++ b/firmware/x300/include/stdint.h
@@ -0,0 +1,34 @@
+/* -*- c -*- */
+/*
+ * Copyright 2007,2009 Free Software Foundation, Inc.
+ *
+ * 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_STDINT_H
+#define INCLUDED_STDINT_H
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef long long int int64_t;
+typedef unsigned long long int uint64_t;
+
+typedef int intptr_t;
+typedef unsigned int uintptr_t;
+
+#endif /* INCLUDED_STDINT_H */
diff --git a/firmware/x300/include/u3_net_stack.h b/firmware/x300/include/u3_net_stack.h
new file mode 100644
index 000000000..cbf714e20
--- /dev/null
+++ b/firmware/x300/include/u3_net_stack.h
@@ -0,0 +1,113 @@
+
+// Copyright 2012-2013 Ettus Research LLC
+
+#ifndef INCLUDED_U3_NET_STACK_H
+#define INCLUDED_U3_NET_STACK_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+#include <wb_pkt_iface64.h>
+
+//----------------------------------------------------------------------
+
+#include <lwip/ip_addr.h>
+#include <lwip/ip.h>
+#include <lwip/udp.h>
+#include <lwip/icmp.h>
+#include <if_arp.h>
+#include <ethertype.h>
+
+typedef struct
+{
+ uint8_t addr[6];
+} eth_mac_addr_t;
+
+typedef struct
+{
+ uint8_t ethno;
+ uint8_t pad[5];
+ eth_mac_addr_t dst;
+ eth_mac_addr_t src;
+ uint16_t ethertype;
+} padded_eth_hdr_t;
+
+//------------------ init stuff ------------------------------------
+
+void u3_net_stack_init(wb_pkt_iface64_config_t *config);
+
+void u3_net_stack_init_eth(const uint8_t ethno, const eth_mac_addr_t *mac, const struct ip_addr *ip, const struct ip_addr *subnet);
+
+const struct ip_addr *u3_net_stack_get_ip_addr(const uint8_t ethno);
+
+const struct ip_addr *u3_net_stack_get_subnet(const uint8_t ethno);
+
+const struct ip_addr *u3_net_stack_get_bcast(const uint8_t ethno);
+
+const eth_mac_addr_t *u3_net_stack_get_mac_addr(const uint8_t ethno);
+
+uint32_t u3_net_stack_get_stat_counts(const uint8_t ethno);
+
+//------------------ udp handling ------------------------------------
+
+typedef void (*u3_net_stack_udp_handler_t)(
+ const uint8_t,
+ const struct ip_addr *, const struct ip_addr *,
+ const uint16_t, const uint16_t,
+ const void *, const size_t
+);
+
+void u3_net_stack_register_udp_handler(
+ const uint16_t port,
+ const u3_net_stack_udp_handler_t handler
+);
+
+void u3_net_stack_send_udp_pkt(
+ const uint8_t ethno,
+ const struct ip_addr *dst,
+ const uint16_t src_port,
+ const uint16_t dst_port,
+ const void *buff,
+ const size_t num_bytes
+);
+
+//------------------ icmp handling ------------------------------------
+
+typedef void (*u3_net_stack_icmp_handler_t)(
+ const uint8_t,
+ const struct ip_addr *, const struct ip_addr *,
+ const uint16_t, const uint16_t,
+ const void *, const size_t
+);
+
+void u3_net_stack_register_icmp_handler(
+ const uint8_t type,
+ const uint8_t code,
+ const u3_net_stack_icmp_handler_t handler
+);
+
+void u3_net_stack_send_icmp_pkt(
+ const uint8_t ethno,
+ const uint8_t type,
+ const uint8_t code,
+ const uint16_t id,
+ const uint16_t seq,
+ const struct ip_addr *dst,
+ const void *buff,
+ const size_t num_bytes
+);
+
+//------------------ entry point ------------------------------------
+
+void u3_net_stack_handle_one(void);
+
+//------------------ arp handling ------------------------------------
+
+void u3_net_stack_send_arp_request(const uint8_t ethno, const struct ip_addr *addr);
+
+//commented out to make private - do we need cache update outside this module?
+//void u3_net_stack_arp_cache_update(const struct ip_addr *ip_addr, const eth_mac_addr_t *mac_addr, const uint8_t ethno);
+
+const eth_mac_addr_t *u3_net_stack_arp_cache_lookup(const struct ip_addr *ip_addr);
+
+#endif /* INCLUDED_U3_NET_STACK_H */
diff --git a/firmware/x300/include/udp_uart.h b/firmware/x300/include/udp_uart.h
new file mode 100644
index 000000000..4a33a9299
--- /dev/null
+++ b/firmware/x300/include/udp_uart.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2011-2013 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_UDP_UART_H
+#define INCLUDED_UDP_UART_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+/*!
+ * Initialize the UDP/UART module.
+ * Registers handler into the network.
+ */
+void udp_uart_init(const uint32_t uart_base, const uint16_t udp_port);
+
+/*!
+ * Polls the UART state machine,
+ * and sends messages over UDP.
+ */
+void udp_uart_poll(void);
+
+#endif /* INCLUDED_UDP_UART_H */
diff --git a/firmware/x300/include/wb_i2c.h b/firmware/x300/include/wb_i2c.h
new file mode 100644
index 000000000..cb307f373
--- /dev/null
+++ b/firmware/x300/include/wb_i2c.h
@@ -0,0 +1,18 @@
+
+// Copyright 2012 Ettus Research LLC
+
+#ifndef INCLUDED_WB_I2C_H
+#define INCLUDED_WB_I2C_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+void wb_i2c_init(const uint32_t base, const size_t clk_rate);
+
+bool wb_i2c_read(const uint32_t base, const uint8_t i2c_addr, uint8_t *buf, size_t len);
+
+bool wb_i2c_write(const uint32_t base, const uint8_t i2c_addr, const uint8_t *buf, size_t len);
+
+
+#endif /* INCLUDED_WB_I2C_H */
diff --git a/firmware/x300/include/wb_pkt_iface64.h b/firmware/x300/include/wb_pkt_iface64.h
new file mode 100644
index 000000000..aa3c174ed
--- /dev/null
+++ b/firmware/x300/include/wb_pkt_iface64.h
@@ -0,0 +1,44 @@
+
+// Copyright 2012 Ettus Research LLC
+
+#ifndef INCLUDED_WB_PKT_IFACE64_H
+#define INCLUDED_WB_PKT_IFACE64_H
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdbool.h>
+
+//! opaque, dont touch insides
+typedef struct
+{
+ uint32_t base;
+ uint32_t ctrl;
+ uint32_t config_addr;
+} wb_pkt_iface64_config_t;
+
+//! Init the wb slave for packet interface
+wb_pkt_iface64_config_t wb_pkt_iface64_init(const uint32_t base, const size_t ctrl_offset);
+
+/*!
+ * Poll if an packet has been received.
+ * If yes, return the pointer to the pkt, num_bytes is set.
+ * Otherwise, return null.
+ */
+const void *wb_pkt_iface64_rx_try_claim(wb_pkt_iface64_config_t *config, size_t *num_bytes);
+
+/*!
+ * Release the hold on a received packet.
+ */
+void wb_pkt_iface64_rx_release(wb_pkt_iface64_config_t *config);
+
+/*!
+ * Aquire the buffer for an outgoing packet.
+ */
+void *wb_pkt_iface64_tx_claim(wb_pkt_iface64_config_t *config);
+
+/*!
+ * Submit an outgoing packet from a filled the buffer.
+ */
+void wb_pkt_iface64_tx_submit(wb_pkt_iface64_config_t *config, const size_t num_bytes);
+
+#endif /* INCLUDED_WB_PKT_IFACE64_H */
diff --git a/firmware/x300/include/wb_uart.h b/firmware/x300/include/wb_uart.h
new file mode 100644
index 000000000..46dd97441
--- /dev/null
+++ b/firmware/x300/include/wb_uart.h
@@ -0,0 +1,23 @@
+
+// Copyright 2012 Ettus Research LLC
+
+#ifndef INCLUDED_WB_UART_H
+#define INCLUDED_WB_UART_H
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+//! Init the uart in question
+void wb_uart_init(const uint32_t base, const size_t div);
+
+//! Put character blocking
+void wb_uart_putc(const uint32_t base, const int ch);
+
+//! Put character not blocking - false for fail
+bool wb_uart_try_putc(const uint32_t base, const int ch);
+
+//! Get character non blocking, -1 for none
+int wb_uart_getc(const uint32_t base);
+
+#endif /* INCLUDED_WB_UART_H */
diff --git a/firmware/x300/include/wb_utils.h b/firmware/x300/include/wb_utils.h
new file mode 100644
index 000000000..34be51b8f
--- /dev/null
+++ b/firmware/x300/include/wb_utils.h
@@ -0,0 +1,24 @@
+
+// Copyright 2012 Ettus Research LLC
+
+#ifndef INCLUDED_WB_UTILS_H
+#define INCLUDED_WB_UTILS_H
+
+#include <stdint.h>
+
+#define localparam static const int
+
+static inline void wb_poke32(const uint32_t addr, const uint32_t data)
+{
+ *((volatile uint32_t *)addr) = data;
+}
+
+static inline uint32_t wb_peek32(const uint32_t addr)
+{
+ const uint32_t data = *((volatile uint32_t *)addr);
+ return data;
+}
+
+#define SR_ADDR(base, offset) ((base) + (offset)*4)
+
+#endif /* INCLUDED_WB_UTILS_H */
diff --git a/firmware/x300/include/xge_mac.h b/firmware/x300/include/xge_mac.h
new file mode 100644
index 000000000..d288bdd8d
--- /dev/null
+++ b/firmware/x300/include/xge_mac.h
@@ -0,0 +1,37 @@
+
+#ifndef INCLUDED_XGE_MAC_H
+#define INCLUDED_XGE_MAC_H
+
+#define HAVE_OPENCORES_XGEMAC 1
+
+#ifdef HAVE_OPENCORES_XGEMAC
+#define XGE_TX_ENABLE (1 << 0) // Set to enable transmission.
+// Interupt register bits.
+#define XGE_RX_FRAG_ERR (1 << 8)
+#define XGE_RX_CRC_ERR (1 << 7)
+#define XGE_RX_PAUSE (1 << 6)
+#define XGE_REMOTE_FAULT (1 << 5)
+#define XGE_LOCAL_FAULT (1 << 4)
+#define XGE_RX_UNDERFLOW (1 << 3)
+#define XGE_RX_OVERFLOW (1 << 2)
+#define XGE_TX_UNDERFLOW (1 << 1)
+#define XGE_TX_OVERFLOW (1 << 0)
+#endif
+
+// MDIO OP
+#define XGE_MDIO_CLAUSE(n) ((n & 0x1) << 12)
+#define CLAUSE45 1
+#define CLAUSE22 0
+#define XGE_MDIO_OP(n) ((n & 0x3) << 10)
+#define MDIO_ADDRESS 0
+#define MDIO_WRITE 1
+#define MDIO_READ 3
+#define MDIO_C22_WRITE 2
+#define MDIO_C22_READ 1
+#define MDIO_READ_POST 2
+#define XGE_MDIO_ADDR(n) ((n & 0x1f) << 5)
+#define XGE_MDIO_MMD(n) ((n & 0x1f) << 0)
+
+#endif
+
+
diff --git a/firmware/x300/include/xge_phy.h b/firmware/x300/include/xge_phy.h
new file mode 100644
index 000000000..eeb94753e
--- /dev/null
+++ b/firmware/x300/include/xge_phy.h
@@ -0,0 +1,78 @@
+
+#ifndef INCLUDED_XGE_PHY_H
+#define INCLUDED_XGE_PHY_H
+
+#define HAVE_AEL2005_PHY 1
+
+//
+// IEEE 802.3ae Clause 45 managable device types (DEVAD)
+//
+#define XGE_MDIO_DEVICE_PMA 1
+#define XGE_MDIO_DEVICE_WIS 2
+#define XGE_MDIO_DEVICE_PCS 3
+#define XGE_MDIO_DEVICE_PHY_XS 4
+#define XGE_MDIO_DEVICE_DTE_XS 5
+#define XGE_MDIO_DEVICE_TC 6
+
+//
+// IEEE 802.3ae Clause 45 register set for MDIO
+//
+#define XGE_MDIO_CONTROL1 0
+#define XGE_MDIO_STATUS1 1
+#define XGE_MDIO_DEVID1 2
+#define XGE_MDIO_DEVID2 3
+#define XGE_MDIO_SPEED 4
+#define XGE_MDIO_DEVICES1 5
+#define XGE_MDIO_DEVICES2 6
+#define XGE_MDIO_CONTROL2 7
+#define XGE_MDIO_STATUS2 8
+#define XGE_MDIO_LANESTATUS 24
+#define XGE_MDIO_TESTCTRL 25
+#define XILINX_CORE_VERSION 65535
+
+//
+// QR2 AEL2005 Phy address on MDIO (PORT ADDR)
+//
+#define XGE_MDIO_ADDR_PHY_A 0
+
+//
+// QR2 MDIO address of FPGA XAUI (DTE XS) (PORT ADDR)
+//
+#define XGE_MDIO_ADDR_XAUI_A 2
+
+//
+// ID's for all XGE interfaces
+#define XGE_A 0
+
+// PHY module types
+enum {
+ SFFP_TYPE_NONE,
+ SFFP_TYPE_SR,
+ SFFP_TYPE_LR,
+ SFFP_TYPE_LRM,
+ SFFP_TYPE_TWINAX,
+ SFFP_TYPE_TWINAX_LONG,
+ SFFP_TYPE_UNKNOWN,
+ SFFP_TYPE_1000BASE_SX,
+ SFFP_TYPE_1000BASE_LX,
+ SFFP_TYPE_1000BASE_T
+};
+
+// PHY module I2C device address
+// (I2C device driver shifts "7bit" address left 1 bit)
+// SFF-8431 specifys the I2C address as 8 bits with lSB as X
+enum {
+ MODULE_DEV_ADDR = (0xa0 >> 1),
+ SFF_DEV_ADDR = (0xa2 >>1),
+};
+
+// SFPP module status
+enum {
+ SFFP_NO_CHANGE,
+ SFFP_REMOVED,
+ SFFP_INSERTED
+};
+
+#endif
+
+