Convert gr-audio-portaudio to Boost via gruel
[debian/gnuradio] / usrp / limbo / inband / usrp_server.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007,2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 #ifndef INCLUDED_USRP_SERVER_H
22 #define INCLUDED_USRP_SERVER_H
23
24 #include <mblock/mblock.h>
25 #include <vector>
26 #include <queue>
27 #include <fstream>
28 #include <usrp_inband_usb_packet.h>
29
30 typedef usrp_inband_usb_packet transport_pkt;   // makes conversion to gigabit easy
31
32 /*!
33  * \brief Implements the lowest-level mblock usb_interface to the USRP
34  */
35 class usrp_server : public mb_mblock
36 {
37 public:
38
39   // our ports
40   enum port_types {
41     RX_PORT = 0,
42     TX_PORT = 1
43   };
44   static const int N_PORTS = 4;
45   std::vector<mb_port_sptr> d_tx, d_rx;
46   mb_port_sptr  d_cs;
47   mb_port_sptr  d_cs_usrp;
48
49   static const int D_USB_CAPACITY = 32 * 1024 * 1024;
50   static const int D_MAX_CHANNELS = 16;
51   long d_ntx_chan;
52   long d_nrx_chan;
53
54   pmt_t d_usrp_dict;
55
56   bool d_fpga_debug;
57   
58   long d_interp_tx;
59   long d_decim_rx;
60
61   // Keep track of the request IDs
62   struct rid_info {
63     pmt_t owner;
64     long user_rid;
65
66     rid_info() {
67       owner = PMT_NIL;
68       user_rid = 0;
69     }
70   };
71
72   static const long D_MAX_RID = 64;
73   std::vector<rid_info> d_rids;
74   
75   struct channel_info {
76     long assigned_capacity;   // the capacity currently assignedby the channel
77     pmt_t owner;              // port ID of the owner of the channel
78
79     channel_info() {
80       assigned_capacity = 0;
81       owner = PMT_NIL;
82     }
83   };
84
85   long d_rx_chan_mask;    // A bitmask representing the channels in the
86                           // receiving state
87
88   std::vector<struct channel_info> d_chaninfo_tx;
89   std::vector<struct channel_info> d_chaninfo_rx;
90
91   std::queue<mb_message_sptr> d_defer_queue;
92
93   bool d_defer;
94   bool d_opened;
95
96   bool d_fake_rx;
97
98 public:
99   usrp_server(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg);
100   ~usrp_server();
101
102   void initial_transition();
103   void handle_message(mb_message_sptr msg);
104
105 protected:
106   static int max_capacity() { return D_USB_CAPACITY; }
107
108 private:
109   void handle_cmd_allocate_channel(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data);
110   void handle_cmd_deallocate_channel(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data);
111   void handle_cmd_xmit_raw_frame(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data);
112   void handle_cmd_to_control_channel(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data);
113   void handle_cmd_start_recv_raw_samples(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data);
114   void handle_cmd_stop_recv_raw_samples(mb_port_sptr port, std::vector<struct channel_info> &chan_info, pmt_t data);
115   int rx_port_index(pmt_t port_id);
116   int tx_port_index(pmt_t port_id);
117   long current_capacity_allocation();
118   void recall_defer_queue();
119   void reset_channels();
120   void handle_response_usrp_read(pmt_t data);
121   bool check_valid(mb_port_sptr port, long channel, std::vector<struct channel_info> &chan_info, pmt_t signal_info);
122   void parse_control_pkt(pmt_t invocation_handle, transport_pkt *pkt);
123   long next_rid();
124   void initialize_registers();
125   void set_register(long reg, long val);
126   void read_register(long reg);
127   void check_register_initialization();
128   void reset_all_registers();
129 };
130
131 #endif /* INCLUDED_USRP_SERVER_H */