00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2008,2009 Free Software Foundation, Inc. 00004 * 00005 * This program is free software: you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation, either version 3 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #ifndef INCLUDED_CONTROL_H 00020 #define INCLUDED_CONTROL_H 00021 00022 #include <gnuradio/omnithread.h> 00023 #include <usrp2_eth_packet.h> 00024 00025 namespace usrp2 { 00026 00027 struct op_generic_cmd { 00028 u2_eth_packet_t h; 00029 op_generic_t op; 00030 op_generic_t eop; 00031 }; 00032 00033 /*! 00034 * OP_CONFIG_RX_V2 command packet 00035 */ 00036 struct op_config_rx_v2_cmd 00037 { 00038 u2_eth_packet_t h; 00039 op_config_rx_v2_t op; 00040 op_generic_t eop; 00041 }; 00042 00043 struct op_start_rx_streaming_cmd 00044 { 00045 u2_eth_packet_t h; 00046 op_start_rx_streaming_t op; 00047 op_generic_t eop; 00048 }; 00049 00050 struct op_stop_rx_cmd { 00051 u2_eth_packet_t h; 00052 op_generic_t op; 00053 op_generic_t eop; 00054 }; 00055 00056 struct op_config_tx_v2_cmd 00057 { 00058 u2_eth_packet_t h; 00059 op_config_tx_v2_t op; 00060 op_generic_t eop; 00061 }; 00062 00063 struct op_config_mimo_cmd 00064 { 00065 u2_eth_packet_t h; 00066 op_config_mimo_t op; 00067 op_generic_t eop; 00068 }; 00069 00070 struct op_burn_mac_addr_cmd 00071 { 00072 u2_eth_packet_t h; 00073 op_burn_mac_addr_t op; 00074 op_generic_t eop; 00075 }; 00076 00077 struct op_dboard_info_cmd { 00078 u2_eth_packet_t h; 00079 op_generic_t op; 00080 op_generic_t eop; 00081 }; 00082 00083 struct op_peek_cmd { 00084 u2_eth_packet_t h; 00085 op_peek_t op; 00086 op_generic_t eop; 00087 }; 00088 00089 struct op_poke_cmd { 00090 u2_eth_packet_t h; 00091 op_poke_t op; 00092 // words to write go here 00093 // eop must be dynamically written here 00094 }; 00095 00096 struct op_freq_cmd { 00097 u2_eth_packet_t h; 00098 op_freq_t op; 00099 op_generic_t eop; 00100 }; 00101 00102 struct op_gpio_cmd { 00103 u2_eth_packet_t h; 00104 op_gpio_t op; 00105 op_generic_t eop; 00106 }; 00107 00108 struct op_gpio_set_sels_cmd { 00109 u2_eth_packet_t h; 00110 op_gpio_set_sels_t op; 00111 op_generic_t eop; 00112 }; 00113 00114 /*! 00115 * Control mechanism to allow API calls to block waiting for reply packets 00116 */ 00117 class pending_reply 00118 { 00119 private: 00120 unsigned int d_rid; 00121 omni_mutex d_mutex; 00122 omni_condition d_cond; 00123 void *d_buffer; 00124 size_t d_len; 00125 00126 public: 00127 /*! 00128 * Construct a pending reply from the reply ID, response packet 00129 * buffer, and buffer length. 00130 */ 00131 pending_reply(unsigned int rid, void *buffer, size_t len); 00132 00133 /*! 00134 * Destructor. Signals creating thread. 00135 */ 00136 ~pending_reply(); 00137 00138 /*! 00139 * Block, waiting for reply packet. 00140 * Returns: 1 = ok, reply packet in buffer 00141 * 0 = timeout 00142 */ 00143 int wait(double secs); 00144 00145 /*! 00146 * Allows creating thread to resume after copying reply into buffer 00147 */ 00148 void signal(); 00149 00150 /*! 00151 * Retrieve pending reply ID 00152 */ 00153 unsigned int rid() const { return d_rid; } 00154 00155 /*! 00156 * Retrieve destination buffer address 00157 */ 00158 void *buffer() const { return d_buffer; } 00159 00160 /*! 00161 * Retrieve destination buffer length 00162 */ 00163 size_t len() const { return d_len; } 00164 }; 00165 00166 } // namespace usrp2 00167 00168 #endif /* INCLUDED_CONTROL_H */