Rebase on master, cleanup for merge
[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_sync_and_start_rx_streaming_cmd
51   {
52     u2_eth_packet_t         h;
53     op_generic_t            sync_op;
54     op_start_rx_streaming_t rx_op;
55     op_generic_t            eop;
56   };
57
58   struct op_stop_rx_cmd {
59     u2_eth_packet_t h;
60     op_generic_t    op;
61     op_generic_t    eop;
62   };
63
64   struct op_config_tx_v2_cmd
65   {
66     u2_eth_packet_t   h;
67     op_config_tx_v2_t op;
68     op_generic_t      eop;
69   };
70
71   struct op_config_mimo_cmd
72   {
73     u2_eth_packet_t   h;
74     op_config_mimo_t  op;
75     op_generic_t      eop;
76   };
77
78   struct op_burn_mac_addr_cmd
79   {
80     u2_eth_packet_t    h;
81     op_burn_mac_addr_t op;
82     op_generic_t       eop;
83   };
84
85   struct op_dboard_info_cmd {
86     u2_eth_packet_t h;
87     op_generic_t    op;
88     op_generic_t    eop;
89   };
90
91   struct op_peek_cmd {
92     u2_eth_packet_t h;
93     op_peek_t       op;
94     op_generic_t    eop;
95   };
96
97   struct op_poke_cmd {
98     u2_eth_packet_t h;
99     op_poke_t       op;
100     // words to write go here
101     // eop must be dynamically written here
102   };
103
104   struct op_freq_cmd {
105     u2_eth_packet_t h;
106     op_freq_t       op;
107     op_generic_t    eop;
108   };
109
110   struct op_gpio_cmd {
111     u2_eth_packet_t h;
112     op_gpio_t       op;
113     op_generic_t    eop;
114   };
115
116   struct op_gpio_set_sels_cmd {
117     u2_eth_packet_t h;
118     op_gpio_set_sels_t op;
119     op_generic_t    eop;
120   };
121
122   /*!
123    * Control mechanism to allow API calls to block waiting for reply packets
124    */
125   class pending_reply
126   {
127   private:
128     unsigned int    d_rid;
129     void           *d_buffer;
130     size_t          d_len;
131
132     // d_mutex is used with d_cond and also protects d_complete
133     omni_mutex      d_mutex;
134     omni_condition  d_cond;
135     bool            d_complete;
136
137   public:
138     /*!
139      * Construct a pending reply from the reply ID, response packet
140      * buffer, and buffer length.
141      */
142     pending_reply(unsigned int rid, void *buffer, size_t len);
143
144     /*!
145      * Destructor. Signals creating thread.
146      */
147     ~pending_reply();
148
149     /*!
150      * Block, waiting for reply packet.
151      * Returns: 1 = ok, reply packet in buffer
152      *          0 = timeout
153      */
154     int wait_for_completion(double secs);
155
156     /*!
157      * Allows creating thread to resume after copying reply into buffer
158      */
159     void notify_completion();
160
161     /*!
162      * Retrieve pending reply ID
163      */
164     unsigned int rid() const { return d_rid; }
165
166     /*!
167      * Retrieve destination buffer address
168      */
169     void *buffer() const { return d_buffer; }
170
171     /*!
172      * Retrieve destination buffer length
173      */
174     size_t len() const { return d_len; }
175   };
176
177 } // namespace usrp2
178
179 #endif /* INCLUDED_CONTROL_H */