summaryrefslogtreecommitdiff
path: root/usrp2/host/lib/control.h
blob: 46ce791ea3019915432ca498b639db143b4c2343 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* -*- c++ -*- */
/*
 * 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/>.
 */

#ifndef INCLUDED_CONTROL_H
#define INCLUDED_CONTROL_H

#include <gnuradio/omnithread.h>
#include <usrp2_eth_packet.h>

namespace usrp2 {

  struct op_generic_cmd {
    u2_eth_packet_t h;
    op_generic_t    op;
    op_generic_t    eop;
  };

  /*!
   * OP_CONFIG_RX_V2 command packet
   */
  struct op_config_rx_v2_cmd
  {
    u2_eth_packet_t   h;
    op_config_rx_v2_t op;
    op_generic_t      eop;
  };

  struct op_start_rx_streaming_cmd
  {
    u2_eth_packet_t	    h;
    op_start_rx_streaming_t op;
    op_generic_t	    eop;
  };

  struct op_sync_and_start_rx_streaming_cmd
  {
    u2_eth_packet_t	    h;
    op_generic_t            sync_op;
    op_start_rx_streaming_t rx_op;
    op_generic_t	    eop;
  };

  struct op_stop_rx_cmd {
    u2_eth_packet_t h;
    op_generic_t    op;
    op_generic_t    eop;
  };

  struct op_config_tx_v2_cmd
  {
    u2_eth_packet_t   h;
    op_config_tx_v2_t op;
    op_generic_t      eop;
  };

  struct op_config_mimo_cmd
  {
    u2_eth_packet_t   h;
    op_config_mimo_t  op;
    op_generic_t      eop;
  };

  struct op_burn_mac_addr_cmd
  {
    u2_eth_packet_t    h;
    op_burn_mac_addr_t op;
    op_generic_t       eop;
  };

  struct op_dboard_info_cmd {
    u2_eth_packet_t h;
    op_generic_t    op;
    op_generic_t    eop;
  };

  struct op_peek_cmd {
    u2_eth_packet_t h;
    op_peek_t       op;
    op_generic_t    eop;
  };

  struct op_poke_cmd {
    u2_eth_packet_t h;
    op_poke_t       op;
    // words to write go here
    // eop must be dynamically written here
  };

  struct op_freq_cmd {
    u2_eth_packet_t h;
    op_freq_t       op;
    op_generic_t    eop;
  };

  struct op_gpio_cmd {
    u2_eth_packet_t h;
    op_gpio_t       op;
    op_generic_t    eop;
  };

  struct op_gpio_set_sels_cmd {
    u2_eth_packet_t h;
    op_gpio_set_sels_t op;
    op_generic_t    eop;
  };

  /*!
   * Control mechanism to allow API calls to block waiting for reply packets
   */
  class pending_reply
  {
  private:
    unsigned int    d_rid;
    void           *d_buffer;
    size_t	    d_len;

    // d_mutex is used with d_cond and also protects d_complete
    omni_mutex      d_mutex;
    omni_condition  d_cond;
    bool	    d_complete;

  public:
    /*!
     * Construct a pending reply from the reply ID, response packet
     * buffer, and buffer length.
     */
    pending_reply(unsigned int rid, void *buffer, size_t len);

    /*!
     * Destructor. Signals creating thread.
     */
    ~pending_reply();

    /*!
     * Block, waiting for reply packet.
     * Returns: 1 = ok, reply packet in buffer
     *          0 = timeout
     */
    int wait_for_completion(double secs);

    /*!
     * Allows creating thread to resume after copying reply into buffer
     */
    void notify_completion();

    /*!
     * Retrieve pending reply ID
     */
    unsigned int rid() const { return d_rid; }

    /*!
     * Retrieve destination buffer address
     */
    void *buffer() const { return d_buffer; }

    /*!
     * Retrieve destination buffer length
     */
    size_t len() const { return d_len; }
  };

} // namespace usrp2

#endif /* INCLUDED_CONTROL_H */