8769e4522f2e7dcfe38cba6170eef5065c0b1c36
[debian/gnuradio] / usrp2 / host / lib / control.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2009 Free Software Foundation, Inc.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifndef INCLUDED_CONTROL_H
20 #define INCLUDED_CONTROL_H
21
22 #include <gnuradio/omnithread.h>
23 #include <usrp2_eth_packet.h>
24
25 namespace usrp2 {
26
27   struct op_generic_cmd {
28     u2_eth_packet_t h;
29     op_generic_t    op;
30     op_generic_t    eop;
31   };
32
33   /*!
34    * OP_CONFIG_RX_V2 command packet
35    */
36   struct op_config_rx_v2_cmd 
37   {
38     u2_eth_packet_t   h;
39     op_config_rx_v2_t op;
40     op_generic_t      eop;
41   };
42
43   struct op_start_rx_streaming_cmd 
44   {
45     u2_eth_packet_t         h;
46     op_start_rx_streaming_t op;
47     op_generic_t            eop;
48   };
49     
50   struct op_stop_rx_cmd {
51     u2_eth_packet_t h;
52     op_generic_t    op;
53     op_generic_t    eop;
54   };
55
56   struct op_config_tx_v2_cmd 
57   {
58     u2_eth_packet_t   h;
59     op_config_tx_v2_t op;
60     op_generic_t      eop;
61   };
62
63   struct op_config_mimo_cmd
64   {
65     u2_eth_packet_t   h;
66     op_config_mimo_t  op;
67     op_generic_t      eop;
68   };
69
70   struct op_burn_mac_addr_cmd 
71   {
72     u2_eth_packet_t    h;
73     op_burn_mac_addr_t op;
74     op_generic_t       eop;
75   };
76
77   struct op_dboard_info_cmd {
78     u2_eth_packet_t h;
79     op_generic_t    op;
80     op_generic_t    eop;
81   };
82
83   struct op_peek_cmd {
84     u2_eth_packet_t h;
85     op_peek_t       op;
86     op_generic_t    eop;
87   };
88
89   struct op_poke_cmd {
90     u2_eth_packet_t h;
91     op_poke_t       op;
92     // words to write go here
93     // eop must be dynamically written here
94   };
95
96   struct op_freq_cmd {
97     u2_eth_packet_t h;
98     op_freq_t       op;
99     op_generic_t    eop;
100   };
101
102   struct op_gpio_cmd {
103     u2_eth_packet_t h;
104     op_gpio_t       op;
105     op_generic_t    eop;
106   };
107
108   struct op_gpio_set_sels_cmd {
109     u2_eth_packet_t h;
110     op_gpio_set_sels_t op;
111     op_generic_t    eop;
112   };
113
114   /*!
115    * Control mechanism to allow API calls to block waiting for reply packets
116    */    
117   class pending_reply
118   {
119   private:
120     unsigned int    d_rid;
121     void           *d_buffer;
122     size_t          d_len;
123     
124     // d_mutex is used with d_cond and also protects d_complete
125     omni_mutex      d_mutex;
126     omni_condition  d_cond;
127     bool            d_complete;
128
129   public:  
130     /*!
131      * Construct a pending reply from the reply ID, response packet
132      * buffer, and buffer length.
133      */
134     pending_reply(unsigned int rid, void *buffer, size_t len);
135
136     /*!
137      * Destructor. Signals creating thread.
138      */
139     ~pending_reply();
140
141     /*!
142      * Block, waiting for reply packet.
143      * Returns: 1 = ok, reply packet in buffer
144      *          0 = timeout
145      */
146     int wait_for_completion(double secs);
147
148     /*!
149      * Allows creating thread to resume after copying reply into buffer
150      */
151     void notify_completion();
152
153     /*!
154      * Retrieve pending reply ID
155      */
156     unsigned int rid() const { return d_rid; }
157
158     /*!
159      * Retrieve destination buffer address
160      */
161     void *buffer() const { return d_buffer; }
162
163     /*!
164      * Retrieve destination buffer length
165      */
166     size_t len() const { return d_len; }
167   };
168   
169 } // namespace usrp2
170
171 #endif /* INCLUDED_CONTROL_H */