|
GNU Radio 3.3.0 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2007,2008,2009,2010 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_USRP2_ETH_PACKET_H 00020 #define INCLUDED_USRP2_ETH_PACKET_H 00021 00022 #include "usrp2_cdefs.h" 00023 #include "usrp2_bytesex.h" 00024 #include "usrp2_mac_addr.h" 00025 #include "usrp2_mimo_config.h" 00026 00027 __U2_BEGIN_DECLS 00028 00029 #define U2_ETHERTYPE 0xBEEF // used in our frames 00030 #define MAC_CTRL_ETHERTYPE 0x8808 // used in PAUSE frames 00031 00032 /* 00033 * All these data structures are BIG-ENDIAN on the wire 00034 */ 00035 00036 // FIXME gcc specific. Really ought to come from compiler.h 00037 #define _AL4 __attribute__((aligned (4))) 00038 00039 /* 00040 * \brief The classic 14-byte ethernet header 00041 */ 00042 typedef struct { 00043 u2_mac_addr_t dst; 00044 u2_mac_addr_t src; 00045 uint16_t ethertype; 00046 } __attribute__((packed)) u2_eth_hdr_t; 00047 00048 /*! 00049 * \brief USRP2 transport header 00050 * 00051 * This enables host->usrp2 flow control and dropped packet detection. 00052 */ 00053 typedef struct { 00054 uint16_t flags; // MBZ, may be used for channel in future 00055 uint16_t fifo_status; // free space in Rx fifo in 32-bit lines 00056 uint8_t seqno; // sequence number of this packet 00057 uint8_t ack; // sequence number of next packet expected 00058 } __attribute__((packed)) u2_transport_hdr_t; 00059 00060 00061 /* 00062 * The fixed payload header of a USRP2 ethernet packet... 00063 * 00064 * Basically there's 1 word of flags and routing info, and 1 word 00065 * of timestamp that specifies when the data was received, or 00066 * when it should be transmitted. The data samples follow immediately. 00067 * 00068 * Transmit packets (from host to U2) 00069 * 00070 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00071 * | Chan | mbz |I|S|E| 00072 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00073 * | Timestamp | 00074 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00075 * 00076 * 00077 * Received packets (from U2 to host) 00078 * 00079 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00080 * | Chan | mbz | 00081 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00082 * | Timestamp | 00083 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 00084 * 00085 * mbz == must be zero 00086 */ 00087 00088 typedef struct { 00089 uint32_t word0; // flags etc 00090 uint32_t timestamp; // time of rx or tx (100 MHz) 00091 } u2_fixed_hdr_t; 00092 00093 00094 #define U2P_CHAN_MASK 0x1f 00095 #define U2P_CHAN_SHIFT 27 00096 00097 #define U2P_TX_IMMEDIATE 0x00000004 // send samples NOW, else at timestamp 00098 #define U2P_TX_START_OF_BURST 0x00000002 // this frame is the start of a burst 00099 #define U2P_TX_END_OF_BURST 0x00000001 // this frame is the end of a burst 00100 00101 #define U2P_ALL_FLAGS 0x00000007 00102 00103 #define CONTROL_CHAN 0x1f 00104 00105 static inline int 00106 u2p_chan(u2_fixed_hdr_t *p) 00107 { 00108 return (ntohl(p->word0) >> U2P_CHAN_SHIFT) & U2P_CHAN_MASK; 00109 } 00110 00111 inline static uint32_t 00112 u2p_word0(u2_fixed_hdr_t *p) 00113 { 00114 return ntohl(p->word0); 00115 } 00116 00117 inline static uint32_t 00118 u2p_timestamp(u2_fixed_hdr_t *p) 00119 { 00120 return ntohl(p->timestamp); 00121 } 00122 00123 inline static void 00124 u2p_set_word0(u2_fixed_hdr_t *p, int flags, int chan) 00125 { 00126 p->word0 = htonl((flags & U2P_ALL_FLAGS) 00127 | ((chan & U2P_CHAN_MASK) << U2P_CHAN_SHIFT)); 00128 } 00129 00130 inline static void 00131 u2p_set_timestamp(u2_fixed_hdr_t *p, uint32_t ts) 00132 { 00133 p->timestamp = htonl(ts); 00134 } 00135 00136 /*! 00137 * \brief consolidated packet: ethernet header + transport header + fixed header 00138 */ 00139 typedef struct { 00140 u2_eth_hdr_t ehdr; 00141 u2_transport_hdr_t thdr; 00142 u2_fixed_hdr_t fixed; 00143 } u2_eth_packet_t; 00144 00145 /* 00146 * full load of samples: 00147 * ethernet header + transport header + fixed header + maximum number of samples. 00148 * sizeof(u2_eth_samples_t) == 1512 00149 * (payload is 1498 bytes, two bytes shorter than 1500 byte MTU) 00150 * (sample numbers are made even to force pairwise alignment in the interleaved case) 00151 */ 00152 00153 #define U2_MAX_SAMPLES 370 00154 #define U2_MIN_SAMPLES 10 00155 00156 typedef struct { 00157 u2_eth_packet_t hdrs; 00158 uint32_t samples[U2_MAX_SAMPLES]; 00159 } u2_eth_samples_t; 00160 00161 /* 00162 * Opcodes for control channel 00163 * 00164 * Reply opcodes are the same as the request opcode with the OP_REPLY_BIT set (0x80). 00165 */ 00166 #define OP_REPLY_BIT 0x80 00167 00168 #define OP_EOP 0 // marks last subpacket in packet 00169 00170 #define OP_ID 1 00171 #define OP_ID_REPLY (OP_ID | OP_REPLY_BIT) 00172 #define OP_BURN_MAC_ADDR 2 00173 #define OP_BURN_MAC_ADDR_REPLY (OP_BURN_MAC_ADDR | OP_REPLY_BIT) 00174 #define OP_READ_TIME 3 // What time is it? (100 MHz counter) 00175 #define OP_READ_TIME_REPLY (OP_READ_TIME | OP_REPLY_BIT) 00176 #define OP_CONFIG_RX_V2 4 00177 #define OP_CONFIG_RX_REPLY_V2 (OP_CONFIG_RX_V2 | OP_REPLY_BIT) 00178 #define OP_CONFIG_TX_V2 5 00179 #define OP_CONFIG_TX_REPLY_V2 (OP_CONFIG_TX_V2 | OP_REPLY_BIT) 00180 #define OP_START_RX_STREAMING 6 00181 #define OP_START_RX_STREAMING_REPLY (OP_START_RX_STREAMING | OP_REPLY_BIT) 00182 #define OP_STOP_RX 7 00183 #define OP_STOP_RX_REPLY (OP_STOP_RX | OP_REPLY_BIT) 00184 #define OP_CONFIG_MIMO 8 00185 #define OP_CONFIG_MIMO_REPLY (OP_CONFIG_MIMO | OP_REPLY_BIT) 00186 #define OP_DBOARD_INFO 9 00187 #define OP_DBOARD_INFO_REPLY (OP_DBOARD_INFO | OP_REPLY_BIT) 00188 #define OP_SYNC_TO_PPS 10 00189 #define OP_SYNC_TO_PPS_REPLY (OP_SYNC_TO_PPS | OP_REPLY_BIT) 00190 #define OP_PEEK 11 00191 #define OP_PEEK_REPLY (OP_PEEK | OP_REPLY_BIT) 00192 #define OP_POKE 12 00193 #define OP_POKE_REPLY (OP_POKE | OP_REPLY_BIT) 00194 #define OP_SET_TX_LO_OFFSET 13 00195 #define OP_SET_TX_LO_OFFSET_REPLY (OP_SET_TX_LO_OFFSET | OP_REPLY_BIT) 00196 #define OP_SET_RX_LO_OFFSET 14 00197 #define OP_SET_RX_LO_OFFSET_REPLY (OP_SET_RX_LO_OFFSET | OP_REPLY_BIT) 00198 #define OP_RESET_DB 15 00199 #define OP_RESET_DB_REPLY (OP_RESET_DB | OP_REPLY_BIT) 00200 #define OP_SYNC_EVERY_PPS 16 00201 #define OP_SYNC_EVERY_PPS_REPLY (OP_SYNC_EVERY_PPS | OP_REPLY_BIT) 00202 #define OP_GPIO_SET_DDR 17 00203 #define OP_GPIO_SET_DDR_REPLY (OP_GPIO_SET_DDR | OP_REPLY_BIT) 00204 #define OP_GPIO_SET_SELS 18 00205 #define OP_GPIO_SET_SELS_REPLY (OP_GPIO_SET_SELS | OP_REPLY_BIT) 00206 #define OP_GPIO_READ 19 00207 #define OP_GPIO_READ_REPLY (OP_GPIO_READ | OP_REPLY_BIT) 00208 #define OP_GPIO_WRITE 20 00209 #define OP_GPIO_WRITE_REPLY (OP_GPIO_WRITE | OP_REPLY_BIT) 00210 #define OP_GPIO_STREAM 21 00211 #define OP_GPIO_STREAM_REPLY (OP_GPIO_STREAM | OP_REPLY_BIT) 00212 #define OP_RX_ANTENNA 22 00213 #define OP_RX_ANTENNA_REPLY (OP_RX_ANTENNA | OP_REPLY_BIT) 00214 #define OP_TX_ANTENNA 23 00215 #define OP_TX_ANTENNA_REPLY (OP_RX_ANTENNA | OP_REPLY_BIT) 00216 00217 /* 00218 * All subpackets are a multiple of 4 bytes long. 00219 * All subpackets start with an 8-bit opcode, an 8-bit len and an 8-bit rid. 00220 */ 00221 #define MAX_SUBPKT_LEN 252 00222 00223 /*! 00224 * \brief Generic request and reply packet 00225 * 00226 * Used by: 00227 * OP_EOP, OP_BURN_MAC_ADDR_REPLY, OP_START_RX_STREAMING_REPLY, 00228 * OP_STOP_RX_REPLY, OP_DBOARD_INFO, OP_SYNC_TO_PPS 00229 */ 00230 typedef struct { 00231 uint8_t opcode; 00232 uint8_t len; 00233 uint8_t rid; 00234 uint8_t ok; // bool 00235 } _AL4 op_generic_t; 00236 00237 /*! 00238 * \brief Reply info from a USRP2 00239 */ 00240 typedef struct { 00241 uint8_t opcode; 00242 uint8_t len; 00243 uint8_t rid; 00244 uint8_t mbz; 00245 u2_mac_addr_t addr; 00246 uint16_t hw_rev; 00247 uint8_t fpga_md5sum[16]; 00248 uint8_t sw_md5sum[16]; 00249 } _AL4 op_id_reply_t; 00250 00251 typedef struct { 00252 uint8_t opcode; 00253 uint8_t len; 00254 uint8_t rid; 00255 uint8_t mbz; 00256 uint32_t items_per_frame; // # of 32-bit data items; MTU=1500: [9,371] 00257 } _AL4 op_start_rx_streaming_t; 00258 00259 typedef struct { 00260 uint8_t opcode; 00261 uint8_t len; 00262 uint8_t rid; 00263 u2_mac_addr_t addr; 00264 } _AL4 op_burn_mac_addr_t; 00265 00266 typedef struct { 00267 uint8_t opcode; 00268 uint8_t len; 00269 uint8_t rid; 00270 uint8_t mbz; 00271 uint32_t time; 00272 } _AL4 op_read_time_reply_t; 00273 00274 00275 /*! 00276 * \brief Configure receiver 00277 */ 00278 typedef struct { 00279 uint8_t opcode; 00280 uint8_t len; 00281 uint8_t rid; 00282 uint8_t mbz; 00283 // bitmask indicating which of the following fields are valid 00284 uint16_t valid; 00285 uint16_t gain; // fxpt_db (Q9.7) 00286 uint32_t freq_hi; // high 32-bits of 64-bit fxpt_freq (Q44.20) 00287 uint32_t freq_lo; // low 32-bits of 64-bit fxpt_freq (Q44.20) 00288 uint32_t decim; // desired decimation factor (NOT -1) 00289 uint32_t scale_iq; // (scale_i << 16) | scale_q [16.0 format] 00290 } _AL4 op_config_rx_v2_t; 00291 00292 // bitmask for "valid" field. If the bit is set, there's 00293 // meaningful data in the corresonding field. 00294 00295 #define CFGV_GAIN 0x0001 // gain field is valid 00296 #define CFGV_FREQ 0x0002 // target_freq field is valid 00297 #define CFGV_INTERP_DECIM 0x0004 // interp or decim is valid 00298 #define CFGV_SCALE_IQ 0x0008 // scale_iq is valid 00299 00300 /*! 00301 * \brief Reply to receiver configuration 00302 */ 00303 typedef struct { 00304 uint8_t opcode; 00305 uint8_t len; 00306 uint8_t rid; 00307 uint8_t mbz; 00308 00309 uint16_t ok; // config was successful (bool) 00310 uint16_t inverted; // spectrum is inverted (bool) 00311 00312 // RF frequency that corresponds to DC in the IF (fxpt_freq) 00313 uint32_t baseband_freq_hi; 00314 uint32_t baseband_freq_lo; 00315 // DDC frequency (fxpt_freq) 00316 uint32_t ddc_freq_hi; 00317 uint32_t ddc_freq_lo; 00318 // residual frequency (fxpt_freq) 00319 uint32_t residual_freq_hi; 00320 uint32_t residual_freq_lo; 00321 00322 } _AL4 op_config_rx_reply_v2_t; 00323 00324 /*! 00325 * \brief Configure transmitter 00326 */ 00327 typedef struct { 00328 uint8_t opcode; 00329 uint8_t len; 00330 uint8_t rid; 00331 uint8_t mbz; 00332 00333 // bitmask indicating which of the following fields are valid 00334 uint16_t valid; 00335 uint16_t gain; // fxpt_db (Q9.7) 00336 uint32_t freq_hi; // high 32-bits of 64-bit fxpt_freq (Q44.20) 00337 uint32_t freq_lo; // low 32-bits of 64-bit fxpt_freq (Q44.20) 00338 uint32_t interp; // desired interpolation factor (NOT -1) 00339 uint32_t scale_iq; // (scale_i << 16) | scale_q [16.0 format] 00340 } _AL4 op_config_tx_v2_t; 00341 00342 /*! 00343 * \brief Reply to configure transmitter 00344 */ 00345 typedef struct { 00346 uint8_t opcode; 00347 uint8_t len; 00348 uint8_t rid; 00349 uint8_t mbz; 00350 00351 uint16_t ok; // config was successful (bool) 00352 uint16_t inverted; // spectrum is inverted (bool) 00353 00354 // RF frequency that corresponds to DC in the IF (fxpt_freq) 00355 uint32_t baseband_freq_hi; 00356 uint32_t baseband_freq_lo; 00357 // DUC frequency (fxpt_freq) 00358 uint32_t duc_freq_hi; 00359 uint32_t duc_freq_lo; 00360 // residual frequency (fxpt_freq) 00361 uint32_t residual_freq_hi; 00362 uint32_t residual_freq_lo; 00363 00364 } _AL4 op_config_tx_reply_v2_t; 00365 00366 /*! 00367 * \brief Configure MIMO clocking, etc (uses generic reply) 00368 */ 00369 typedef struct { 00370 uint8_t opcode; 00371 uint8_t len; 00372 uint8_t rid; 00373 uint8_t flags; // from usrp_mimo_config.h 00374 } op_config_mimo_t; 00375 00376 00377 /*! 00378 * \brief High-level information about daughterboards 00379 */ 00380 typedef struct { 00381 int32_t dbid; //< d'board ID (-1 none, -2 invalid eeprom) 00382 uint32_t freq_min_hi; //< high 32-bits of 64-bit fxpt_freq (Q44.20) 00383 uint32_t freq_min_lo; //< low 32-bits of 64-bit fxpt_freq (Q44.20) 00384 uint32_t freq_max_hi; //< high 32-bits of 64-bit fxpt_freq (Q44.20) 00385 uint32_t freq_max_lo; //< low 32-bits of 64-bit fxpt_freq (Q44.20) 00386 uint16_t gain_min; //< min gain that can be set. fxpt_db (Q9.7) 00387 uint16_t gain_max; //< max gain that can be set. fxpt_db (Q9.7) 00388 uint16_t gain_step_size; //< fxpt_db (Q9.7) 00389 } u2_db_info_t; 00390 00391 00392 /*! 00393 * \brief Reply to d'board info request 00394 */ 00395 typedef struct { 00396 uint8_t opcode; 00397 uint8_t len; 00398 uint8_t rid; 00399 uint8_t ok; // request was successful (bool) 00400 00401 u2_db_info_t tx_db_info; 00402 u2_db_info_t rx_db_info; 00403 } _AL4 op_dboard_info_reply_t; 00404 00405 /*! 00406 * \brief Read from Wishbone memory 00407 */ 00408 typedef struct { 00409 uint8_t opcode; 00410 uint8_t len; 00411 uint8_t rid; 00412 uint8_t mbz; 00413 uint32_t addr; 00414 uint32_t bytes; 00415 } _AL4 op_peek_t; 00416 00417 /*! 00418 * \brief Write to Wishbone memory 00419 */ 00420 typedef struct { 00421 uint8_t opcode; 00422 uint8_t len; 00423 uint8_t rid; 00424 uint8_t mbz; 00425 uint32_t addr; 00426 // Words follow here 00427 } _AL4 op_poke_t; 00428 00429 /* 00430 * Common structure for commands with a single frequency param 00431 * (e.g., set_*_lo_offset, set_*_bw) 00432 */ 00433 typedef struct { 00434 uint8_t opcode; 00435 uint8_t len; 00436 uint8_t rid; 00437 uint8_t mbz; 00438 uint32_t freq_hi; //< high 32-bits of 64-bit fxpt_freq (Q44.20) 00439 uint32_t freq_lo; //< low 32-bits of 64-bit fxpt_freq (Q44.20) 00440 } _AL4 op_freq_t; 00441 00442 /* 00443 * Structures for commands in GPIO system 00444 */ 00445 typedef struct { 00446 uint8_t opcode; // OP_GPIO_SET_DDR, OP_GPIO_WRITE, OP_GPIO_STREAM 00447 uint8_t len; 00448 uint8_t rid; 00449 uint8_t bank; 00450 uint16_t value; 00451 uint16_t mask; 00452 } _AL4 op_gpio_t; 00453 00454 typedef struct { 00455 uint8_t opcode; // OP_GPIO_SET_SELS 00456 uint8_t len; 00457 uint8_t rid; 00458 uint8_t bank; 00459 uint8_t sels[16]; 00460 } _AL4 op_gpio_set_sels_t; 00461 00462 typedef struct { 00463 uint8_t opcode; // OP_GPIO_READ_REPLY 00464 uint8_t len; 00465 uint8_t rid; 00466 uint8_t ok; 00467 uint16_t mbz; 00468 uint16_t value; 00469 } _AL4 op_gpio_read_reply_t; 00470 00471 /* 00472 * ================================================================ 00473 * union of all of subpacket types 00474 * ================================================================ 00475 */ 00476 typedef union { 00477 00478 op_generic_t op_generic; 00479 op_id_reply_t op_id_reply; 00480 op_start_rx_streaming_t op_start_rx_streaming; 00481 op_burn_mac_addr_t op_burn_mac_addr; 00482 op_read_time_reply_t op_read_time_reply; 00483 op_config_rx_v2_t op_config_rx_v2; 00484 op_config_rx_reply_v2_t op_config_rx_reply_v2; 00485 op_config_tx_v2_t op_config_tx_v2; 00486 op_config_tx_reply_v2_t op_config_tx_reply_v2; 00487 op_config_mimo_t op_config_mimo; 00488 op_peek_t op_peek; 00489 op_poke_t op_poke; 00490 op_freq_t op_freq; 00491 op_gpio_t op_gpio; 00492 op_gpio_set_sels_t op_gpio_set_sels; 00493 op_gpio_read_reply_t op_gpio_read_reply; 00494 00495 } u2_subpkt_t; 00496 00497 00498 __U2_END_DECLS 00499 00500 #endif /* INCLUDED_USRP2_ETH_PACKET_H */