Merged features/inband -r4812:5218 into trunk. This group of changes
[debian/gnuradio] / usrp / host / lib / inband / usrp_server.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2007 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 2, 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 <mb_mblock.h>
25 #include <vector>
26
27 /*!
28  * \brief Implements the lowest-level mblock interface to the USRP
29  */
30 class usrp_server : public mb_mblock
31 {
32 public:
33
34   enum error_codes {
35     RQSTD_CAPACITY_UNAVAIL = 0,
36     CHANNEL_UNAVAIL = 1,
37     CHANNEL_INVALID = 2,
38     PERMISSION_DENIED = 3
39   };
40
41   // our ports
42   enum port_types {
43     RX_PORT = 0,
44     TX_PORT = 1
45   };
46   static const int N_PORTS = 4;
47   std::vector<mb_port_sptr> d_tx, d_rx;
48   mb_port_sptr  d_cs;
49
50   static const int D_USB_CAPACITY = 32 * 1024 * 1024;
51   static const int D_MAX_CHANNELS = 16;
52   long d_ntx_chan;
53   long d_nrx_chan;
54
55   struct channel_info {
56     long assigned_capacity;  // the capacity currently assignedby the channel
57     pmt_t owner;              // port ID of the owner of the channel
58   };
59
60   struct channel_info d_chaninfo_tx[D_MAX_CHANNELS];
61   struct channel_info d_chaninfo_rx[D_MAX_CHANNELS];
62
63 public:
64   usrp_server(mb_runtime *rt, const std::string &instance_name, pmt_t user_arg);
65   ~usrp_server();
66
67   void initial_transition();
68   void handle_message(mb_message_sptr msg);
69
70 protected:
71   static int max_capacity() { return D_USB_CAPACITY; }
72
73 private:
74   void handle_cmd_allocate_channel(pmt_t port_id, pmt_t data);
75   void handle_cmd_deallocate_channel(pmt_t port_id, pmt_t data);
76   void handle_cmd_xmit_raw_frame(pmt_t data);
77   int rx_port_index(pmt_t port_id);
78   int tx_port_index(pmt_t port_id);
79   long current_capacity_allocation();
80 };
81
82 #endif /* INCLUDED_USRP_SERVER_H */