3 * Copyright 2007 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #ifndef INCLUDED_USRP_INBAND_USB_PACKET_H_
23 #define INCLUDED_USRP_INBAND_USB_PACKET_H_
25 #include <usrp_bytesex.h>
26 #include <mb_mblock.h>
28 static const int USB_PKT_SIZE = 512; // bytes
29 static const int MAX_PAYLOAD = USB_PKT_SIZE-2*sizeof(uint32_t);
31 class usrp_inband_usb_packet {
33 // keep raw packet in USRP-endian order
37 unsigned char d_payload[MAX_PAYLOAD];
42 FL_OVERRUN = 0x80000000,
43 FL_UNDERRUN = 0x40000000,
44 FL_DROPPED = 0x20000000,
45 FL_END_OF_BURST = 0x10000000,
46 FL_START_OF_BURST = 0x08000000,
48 FL_ALL_FLAGS = 0xf8000000
51 static const int FL_OVERRUN_SHIFT = 31;
52 static const int FL_UNDERRUN_SHIFT = 30;
53 static const int FL_DROPPED_SHIFT = 29;
54 static const int FL_END_OF_BURST_SHIFT = 28;
55 static const int FL_START_OF_BURST_SHIFT = 27;
57 static const int RSSI_MASK = 0x3f;
58 static const int RSSI_SHIFT = 21;
60 static const int CHAN_MASK = 0x1f;
61 static const int CHAN_SHIFT = 16;
63 static const int TAG_MASK = 0xf;
64 static const int TAG_SHIFT = 9;
66 static const int PAYLOAD_LEN_MASK = 0x1ff;
67 static const int PAYLOAD_LEN_SHIFT = 0;
71 void set_timestamp(uint32_t timestamp){
72 d_timestamp = host_to_usrp_u32(timestamp);
75 void set_end_of_burst() {
76 uint32_t word0 = usrp_to_host_u32(d_word0);
77 word0 |= 1<<FL_END_OF_BURST_SHIFT;
78 d_word0 = host_to_usrp_u32(word0);
81 void set_header(int flags, int chan, int tag, int payload_len){
82 uint32_t word0 = ((flags & FL_ALL_FLAGS)
83 | ((chan & CHAN_MASK) << CHAN_SHIFT)
84 | ((tag & TAG_MASK) << TAG_SHIFT)
85 | ((payload_len & PAYLOAD_LEN_MASK) << PAYLOAD_LEN_SHIFT));
86 d_word0 = host_to_usrp_u32(word0);
89 uint32_t timestamp() const {
90 return usrp_to_host_u32(d_timestamp);
94 uint32_t word0 = usrp_to_host_u32(d_word0);
95 return (word0 >> RSSI_SHIFT) & RSSI_MASK;
99 uint32_t word0 = usrp_to_host_u32(d_word0);
100 return (word0 >> CHAN_SHIFT) & CHAN_MASK;
104 uint32_t word0 = usrp_to_host_u32(d_word0);
105 return (word0 >> TAG_SHIFT) & TAG_MASK;
108 int payload_len() const {
109 uint32_t word0 = usrp_to_host_u32(d_word0);
110 return (word0 >> PAYLOAD_LEN_SHIFT) & PAYLOAD_LEN_MASK;
114 return usrp_to_host_u32(d_word0) & FL_ALL_FLAGS;
117 int overrun() const {
118 return (usrp_to_host_u32(d_word0) & FL_OVERRUN) >> FL_OVERRUN_SHIFT;
122 int underrun() const {
123 return (usrp_to_host_u32(d_word0) & FL_UNDERRUN) >> FL_UNDERRUN_SHIFT;
127 int start_of_burst() const {
128 return (usrp_to_host_u32(d_word0) & FL_START_OF_BURST) >> FL_START_OF_BURST_SHIFT;
131 int end_of_burst() const {
132 return (usrp_to_host_u32(d_word0) & FL_END_OF_BURST) >> FL_END_OF_BURST_SHIFT;
135 int dropped() const {
136 return (usrp_to_host_u32(d_word0) & FL_DROPPED) >> FL_DROPPED_SHIFT;
139 unsigned char *payload() {
143 static int max_payload() {