diff options
Diffstat (limited to 'vrt/include')
-rw-r--r-- | vrt/include/Makefile.am | 23 | ||||
-rw-r--r-- | vrt/include/vrt/Makefile.am | 30 | ||||
-rw-r--r-- | vrt/include/vrt/bits.h | 72 | ||||
-rw-r--r-- | vrt/include/vrt/copiers.h | 49 | ||||
-rw-r--r-- | vrt/include/vrt/expanded_header.h | 99 | ||||
-rw-r--r-- | vrt/include/vrt/quadradio.h | 129 | ||||
-rw-r--r-- | vrt/include/vrt/rx.h | 93 | ||||
-rw-r--r-- | vrt/include/vrt/rx_packet_handler.h | 62 |
8 files changed, 557 insertions, 0 deletions
diff --git a/vrt/include/Makefile.am b/vrt/include/Makefile.am new file mode 100644 index 000000000..3ce6a8f32 --- /dev/null +++ b/vrt/include/Makefile.am @@ -0,0 +1,23 @@ +# +# Copyright 2009 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = vrt diff --git a/vrt/include/vrt/Makefile.am b/vrt/include/vrt/Makefile.am new file mode 100644 index 000000000..b710547d9 --- /dev/null +++ b/vrt/include/vrt/Makefile.am @@ -0,0 +1,30 @@ +# +# Copyright 2008,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/>. +# + +include $(top_srcdir)/Makefile.common + +INCLUDES = + +vrtincludedir = $(includedir)/vrt + +vrtinclude_HEADERS = \ + bits.h \ + copiers.h \ + expanded_header.h \ + quadradio.h \ + rx.h \ + rx_packet_handler.h diff --git a/vrt/include/vrt/bits.h b/vrt/include/vrt/bits.h new file mode 100644 index 000000000..bb4227db4 --- /dev/null +++ b/vrt/include/vrt/bits.h @@ -0,0 +1,72 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, or (at your option) + * any later version. + * + * GNU Radio 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef INCLUDED_VRT_BITS_H +#define INCLUDED_VRT_BITS_H + +#include <stdint.h> + + +/* VRT Header bits */ + +#define VRTH_PT_MASK (0xf << 28) +#define VRTH_PT_IF_DATA_NO_SID (0x0 << 28) // IF-Data, no stream id +#define VRTH_PT_IF_DATA_WITH_SID (0x1 << 28) // IF-Data, w/ stream id +#define VRTH_PT_EXT_DATA_NO_SID (0x2 << 28) +#define VRTH_PT_EXT_DATA_WITH_SID (0x3 << 28) +#define VRTH_PT_IF_CONTEXT (0x4 << 28) +#define VRTH_PT_EXT_CONTEXT (0x5 << 28) + +#define VRTH_HAS_CLASSID (1 << 27) +#define VRTH_HAS_TRAILER (1 << 26) // Data pkts only +#define VRTH_START_OF_BURST (1 << 25) // Data (Tx) pkts only +#define VRTH_END_OF_BURST (1 << 24) // Data (Tx) pkts only +#define VRTH_TSM (1 << 24) // Context pkts only + +#define VRTH_TSI_MASK (0x3 << 22) +#define VRTH_TSI_NONE (0x0 << 22) +#define VRTH_TSI_UTC (0x1 << 22) +#define VRTH_TSI_GPS (0x2 << 22) +#define VRTH_TSI_OTHER (0x3 << 22) + +#define VRTH_TSF_MASK (0x3 << 20) +#define VRTH_TSF_NONE (0x0 << 20) +#define VRTH_TSF_SAMPLE_CNT (0x1 << 20) +#define VRTH_TSF_REAL_TIME_PS (0x2 << 20) +#define VRTH_TSF_FREE_RUNNING (0x3 << 20) + +#define VRTH_PKT_CNT_MASK (0xf << 16) +#define VRTH_PKT_SIZE_MASK 0xffff + + +static inline int +vrth_pkt_cnt(uint32_t h) +{ + return (h & VRTH_PKT_CNT_MASK) >> 16; +} + +static inline int +vrth_pkt_size(uint32_t h) +{ + return h & VRTH_PKT_SIZE_MASK; +} + +#endif /* INCLUDED_VRT_BITS_H */ diff --git a/vrt/include/vrt/copiers.h b/vrt/include/vrt/copiers.h new file mode 100644 index 000000000..990538c42 --- /dev/null +++ b/vrt/include/vrt/copiers.h @@ -0,0 +1,49 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, or (at your option) + * any later version. + * + * GNU Radio 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef INCLUDED_VRT_COPIERS_H +#define INCLUDED_VRT_COPIERS_H + +#include <stdint.h> +#include <stddef.h> +#include <complex> + +namespace vrt { + + /*! + * \brief Copy and convert from net format to host format + */ + void + copy_net_16sc_to_host_16sc(size_t nitems, + const uint32_t *items, + std::complex<int16_t> *host_items); + + + /*! + * \brief Copy and convert from net format to host format mapping [-32768, 32767] -> [1.0, +1.0) + */ + void + copy_net_16sc_to_host_32fc(size_t nitems, + const uint32_t *items, + std::complex<float> *host_items); +}; + +#endif /* INCLUDED_VRT_COPIERS_H */ diff --git a/vrt/include/vrt/expanded_header.h b/vrt/include/vrt/expanded_header.h new file mode 100644 index 000000000..0cfca04a1 --- /dev/null +++ b/vrt/include/vrt/expanded_header.h @@ -0,0 +1,99 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, or (at your option) + * any later version. + * + * GNU Radio 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef INCLUDED_VRT_EXPANDED_HEADER_H +#define INCLUDED_VRT_EXPANDED_HEADER_H + +#include <stdint.h> +#include <stddef.h> +#include <vrt/bits.h> + +namespace vrt { + + /*! + * \brief All headers and trailer for VRT IF-Data, Extension-Data, + * IF-Context and Extension-Context packets. + * + * There are fields allocated for each possible header. Their content may + * or may not be valid. Check the header field to confirm their validity. + * All values are in host-endian format. + */ + struct expanded_header { + uint32_t header; // first word of all packets + uint32_t stream_id; // optional stream identifier + uint64_t class_id; // optional class identifier + uint32_t integer_secs; // optional integer seconds timestamp + uint64_t fractional_secs; // optional fractional seconds timestamp + uint32_t trailer; // optional trailer (only possible in data pkts) + + expanded_header() + : header(0) /*, stream_id(0), class_id(0), + integer_secs(0), fractional_secs(0), trailer(0)*/ {} + + + int pkt_type() const { + return (header & VRTH_PT_MASK) >> 28; + } + + int pkt_cnt() const { return vrth_pkt_cnt(header); } + size_t pkt_size() const { return vrth_pkt_size(header); } + + + // packet type predicates + bool if_data_p() const { return s_if_data[pkt_type()]; } + bool ext_data_p() const { return s_ext_data[pkt_type()]; } + bool if_context_p() const { return (header & VRTH_PT_MASK) == VRTH_PT_IF_CONTEXT; } + bool ext_context_p() const { return (header & VRTH_PT_MASK) == VRTH_PT_EXT_CONTEXT; } + + bool data_p() const { return s_data[pkt_type()]; } // if_data_p() || ext_data_p() + bool context_p() const { return s_context[pkt_type()]; } // if_context_p() || ext_context_p() + + // optional info predicates + bool stream_id_p() const { return s_stream_id[pkt_type()]; } + bool class_id_p() const { return (header & VRTH_HAS_CLASSID) != 0; } + bool integer_secs_p() const { return (header & VRTH_TSI_MASK) != 0; } + bool fractional_secs_p() const { return (header & VRTH_TSF_MASK) != 0; } + bool trailer_p() const { return (header & VRTH_HAS_TRAILER) != 0 && data_p(); } + + + // parser + + /*! + * \brief parse packet, fill-in expanded header, start of payload and len of payload + */ + static bool parse(const uint32_t *packet, // in + size_t n32_bit_words_packet, // in + expanded_header *hdr, // out + const uint32_t **payload, // out + size_t *n32_bit_words_payload); // out + + private: + static unsigned char s_if_data[16]; + static unsigned char s_ext_data[16]; + static unsigned char s_data[16]; + static unsigned char s_context[16]; + static unsigned char s_stream_id[16]; + + }; + +}; // vrt + + +#endif /* INCLUDED_VRT_EXPANDED_HEADER_H */ diff --git a/vrt/include/vrt/quadradio.h b/vrt/include/vrt/quadradio.h new file mode 100644 index 000000000..747ca8ef4 --- /dev/null +++ b/vrt/include/vrt/quadradio.h @@ -0,0 +1,129 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, or (at your option) + * any later version. + * + * GNU Radio 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef INCLUDED_VRT_QUADRADIO_H +#define INCLUDED_VRT_QUADRADIO_H + +#include <vrt/rx.h> + +#include <arpa/inet.h> +#include <netinet/in.h> +#include <sys/types.h> +#include <sys/socket.h> + +typedef enum{ + VRT_TEST_SIG_NORMAL=0, + VRT_TEST_SIG_ZEROS=1, + VRT_TEST_SIG_ONES=2, + VRT_TEST_SIG_TOGGLE=3, + VRT_TEST_SIG_RAMP=4, + VRT_TEST_SIG_CUSTOM=5, + + } vrt_test_sig_t; + +namespace vrt { + + /* + * We're not committing to this interface. It's just here so we can make progress... + * + * This implements the ad-hoc control for bringup and has-a vrt::rx + */ + class quadradio + { + int d_ctrl_fd; // socket for control + struct in_addr d_ctrl_port_inaddr; // our ip addr + int d_data_fd; // socket for data (owned by d_rx) + int d_data_port; // our data port number + vrt::rx::sptr d_rx; // has-a rx + + int d_band_select; // band select setting + int d_rx_antenna; // antenna type rf/cal + int d_attenuation0; // attenuation setting + int d_attenuation1; // attenuation setting + bool d_10dB_atten; // 10dB attenuation on/of + + static bool + open_sockets(const char *quad_radio_ip, int quad_radio_ctrl_port, + int *ctrl_fd_ptr, struct in_addr *ctrl_port_inaddr, + int *data_fd_ptr, int *data_port_ptr); + + static bool + send_rx_command(int ctrl_fd, bool start, + struct in_addr addr, int data_port, int samples_per_pkt, int siggen_param); + + static bool + send_stop_rx_command(int ctrl_fd); + + static int control_port() { return 790; } + int data_socket_fd() const { return d_data_fd; } + + bool open(const char *ip); + + void update_dboard_pins(void); + + public: + typedef boost::shared_ptr<quadradio> sptr; + + quadradio(const std::string &ip, size_t rx_bufsize = 0); + ~quadradio(); + + vrt::rx::sptr vrt_rx() const { return d_rx; } + + bool start_streaming(int samples_per_pkt = 0); + bool stop_streaming(); + + + /* convenience methods that ultimately write the dboard pins */ + bool set_center_freq(double target_freq); + bool set_band_select(const std::string &band); + //void set_10dB_atten(bool on); + bool set_attenuation0(int attenuation); + bool select_rx_antenna(const std::string &ant); + bool set_attenuation1(int attenuation); + + /* convenience methods that ultimately call set_hsadc_conf */ + void set_adc_gain(bool on); + void set_dc_offset_comp(bool on); + void set_digital_gain(float gain); + void set_test_signal(vrt_test_sig_t type); + + /* primitives */ + bool set_setting_reg(int regno, int value); + bool set_mem32(int addr, int value); // poke a 32-bit value + bool set_lo_freq(double freq); + bool set_cal_freq(double freq); + bool set_beamforming(int32_t gains[8]); + /* + * The first parameter for these is a bitmask which indicates which + * daughterboard or daughterboards to apply the operation to. + * 0x1 -> dboard 0 + * 0x2 -> dboard 1 + * 0x3 -> dboard 0 and 1... + */ + bool set_dboard_pins(int dboard_bitmask, int v); + bool set_hsadc_conf(int dboard_bitmask, int regno, int value); + bool set_lsdac(int dboard_bitmask, int which_dac, int value); + + }; + +}; + + +#endif /* INCLUDED_QUADRADIO_H */ diff --git a/vrt/include/vrt/rx.h b/vrt/include/vrt/rx.h new file mode 100644 index 000000000..ff3ce85fb --- /dev/null +++ b/vrt/include/vrt/rx.h @@ -0,0 +1,93 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, or (at your option) + * any later version. + * + * GNU Radio 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef INCLUDED_VRT_RX_H +#define INCLUDED_VRT_RX_H + +#include <boost/shared_ptr.hpp> +#include <boost/utility.hpp> +#include <vrt/rx_packet_handler.h> + +namespace vrt { + + class socket_rx_buffer; + + /*! + * Relatively low-level interface to receive VRT packets over a datagram socket. + * + * (We'll refactor this if/when we use a non-UDP transport.) + * No VRT control issues are addressed here. + */ + class rx : boost::noncopyable + { + int d_socket_fd; + socket_rx_buffer *d_srb; + + public: + /*! + * Shared pointer to this class + */ + typedef boost::shared_ptr<rx> sptr; + + /*! + * \brief Static function to return an instance of rx as a shared pointer. + * + * \param socket_fd file descriptor that data grams will be received from. + * It is assumed that some higher-level control software + * opened the appropriate UDP socket for us. This object + * assumes management of the socket's lifetime. The + * socket will be closed when our destructor fires. + * + * \param rx_bufsize is a hint as to the number of bytes of memory + * to allocate for received ethernet frames (0 -> reasonable default) + */ + static sptr make(int socket_fd, size_t rx_bufsize = 0); + + /*! + * \param socket_fd file descriptor that data grams will be received from. + * It is assumed that some higher-level control software + * opened the appropriate UDP socket for us. This object + * assumes management of the socket's lifetime. The + * socket will be closed when our destructor fires. + * + * \param rx_bufsize is a hint as to the number of bytes of memory + * to allocate for received ethernet frames (0 -> reasonable default) + */ + rx(int socket_fd, size_t rx_bufsize = 0); + ~rx(); + + /*! + * \brief Receive packets from the given socket file descriptor. + * + * \p handler will be invoked for all available packets. + * Unless \p dont_wait is true, this function blocks until at + * least one packet has been processed. + */ + bool rx_packets(rx_packet_handler *handler, bool dont_wait = false); + + /* + * \returns the socket_fd. Useful for select or poll. + */ + int socket_fd() const { return d_socket_fd; } + }; + +} + +#endif /* INCLUDED_VRT_RX_H */ diff --git a/vrt/include/vrt/rx_packet_handler.h b/vrt/include/vrt/rx_packet_handler.h new file mode 100644 index 000000000..ad3407813 --- /dev/null +++ b/vrt/include/vrt/rx_packet_handler.h @@ -0,0 +1,62 @@ +/* -*- c++ -*- */ +/* + * Copyright 2009 Free Software Foundation, Inc. + * + * This file is part of GNU Radio + * + * GNU Radio 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, or (at your option) + * any later version. + * + * GNU Radio 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, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#ifndef INCLUDED_VRT_RX_PACKET_HANDLER_H +#define INCLUDED_VRT_RX_PACKET_HANDLER_H + +#include <vrt/expanded_header.h> +#include <stddef.h> + +namespace vrt { + + /*! + * \brief Abstract function object called to handle received VRT packets. + * + * An object derived from this class is passed to vrt_rx_udp::rx_packets + * to process the received packets. + */ + class rx_packet_handler { + public: + virtual ~rx_packet_handler(); + + /*! + * \param payload points to the first 32-bit word of the payload field. + * \param n32_bit_words is the number of 32-bit words in the payload field. + * \param hdr is the expanded version of the mandatory and optional header fields (& trailer). + * + * \p payload points to the raw payload section of the packet received off + * the wire. The data is network-endian (aka big-endian) 32-bit integers. + * + * This is the general purpose, low level interface and relies on other + * functions to handle all required endian-swapping and format conversion + * of the payload. \sa FIXME. + * + * \returns true if the object wants to be called again with new data; + * false if no additional data is wanted. + */ + virtual bool operator()(const uint32_t *payload, + size_t n32_bit_words, + const expanded_header *hdr); + }; + +}; // vrt + + +#endif /* INCLUDED_VRT_RX_PACKET_HANDLER_H */ |