Help with USRP syntax

Greetings. I am trying to understand the usrp programming syntax so that
I can add USRP support into GRC. Below are a few code snippets from the
USRP sample codes. It seems that rx_subdev_spec can be a tuple (0, 0) or
(1, 0). Would this mean that for tx modules, the tx_subdev_spec is (1,

  1. or (0, 1)? Each tuple corresponds to one of the 4 USRP
    module-sockets?

I noticed that the last 3 of my examples set a mux, and use subdev.
However, the first example is wildly different (I assume the command are
different for different modules?). Is there some way I can find out what
type of commands I need to use for various USRP modules?

The commands involving the subdev are used to set the gain (obviously),
but sometimes you also have to call subdev.set_enable(True)?

Sorry for potentially stupid questions. I am not too familiar with the
USRP, and I would like some advice.

Thank you, -Josh

TX

u = usrp.sink_c (0, self.usrp_interp)

u.set_tx_freq (0, options.cordic_freq)

u.set_pga (0, options.gain)

u.set_pga (1, options.gain)

TX

self.u = usrp.sink_c () # the USRP sink (consumes samples)

options.tx_subdev_spec = usrp.pick_tx_subdevice(self.u)

m = usrp.determine_tx_mux_value(self.u, options.tx_subdev_spec)

self.u.set_mux(m)

self.subdev = usrp.selected_subdev(self.u, options.tx_subdev_spec)

self.subdev.set_gain(self.subdev.gain_range()[1]) # set max Tx gain

self.subdev.set_enable(True) # enable
transmitter

RX

self.u = usrp.source_c() # usrp is data source

self.u.set_decim_rate(usrp_decim)

self.u.set_mux(usrp.determine_rx_mux_value(self.u,
options.rx_subdev_spec))

self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)

RX

u = usrp.source_c(USRP_number, decimation)

u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec))

subdev = usrp.selected_subdev(u, options.rx_subdev_spec)

u.tune(USRP_number, subdev, frequency)

subdev.set_gain(gain)

On Sun, Jan 07, 2007 at 03:13:28AM -0500, Josh B. wrote:

Greetings. I am trying to understand the usrp programming syntax so that
I can add USRP support into GRC.

What’s “GRC”?

Below are a few code snippets from the
USRP sample codes. It seems that rx_subdev_spec can be a tuple (0, 0) or
(1, 0). Would this mean that for tx modules, the tx_subdev_spec is (1,

  1. or (0, 1)? Each tuple corresponds to one of the 4 USRP module-sockets?

I recommend that you just treat the subdev as an opaque type that is
created by code that knows how to parse a subdev spec on the command
line, and which is passed to other code that knows how to interpret
it.

From the command line you specify either -R A, -R B or in rare (nearly
non-existent cases) -R A:0, -R A:1, -R B:0, -R B:1. Same story for
the -T transmit options. The :1 case allows you to specify the
second subdevice on a daughterboard. The only the daughterboards that
supports a second subdevice are the Basic Rx and LF_RX. The :0
option selects one input, :1 the other.

As currently implemented (no promises that any of this stays the same,
and thus my exhortation to treat this as an opaque type), the tuple is
interpreted as (, ), where A -> 0 and B -> 1.

I noticed that the last 3 of my examples set a mux, and use subdev.
However, the first example is wildly different (I assume the command are
different for different modules?). Is there some way I can find out what
type of commands I need to use for various USRP modules?

If you use the recommended approach (use subdev), all daughterboards
are treated identically.

The commands involving the subdev are used to set the gain (obviously),
but sometimes you also have to call subdev.set_enable(True)?

set_enable(True) enables the transmitter on the daugtherboards. Not
all boards support this option. On those boards that don’t, the Tx
path is always “hot”. The other option is to enable the “Auto T/R
switching”, using set_auto_tr(True/False).

Sorry for potentially stupid questions. I am not too familiar with the
USRP, and I would like some advice.

Thank you, -Josh

TX

Don’t call set_pga, set_tx_freq or set_rx_freq. These examples are
obsolete, and were written before the generalized code for handling
daughterboards.

u = usrp.sink_c (0, self.usrp_interp)

u.set_tx_freq (0, options.cordic_freq)

u.set_pga (0, options.gain)

u.set_pga (1, options.gain)

This is the preferred style:

TX

self.subdev.set_gain(self.subdev.gain_range()[1]) # set max Tx gain

self.subdev.set_enable(True) # enable transmitter

These are also good:

RX

u = usrp.source_c(USRP_number, decimation)

u.set_mux(usrp.determine_rx_mux_value(u, options.rx_subdev_spec))

subdev = usrp.selected_subdev(u, options.rx_subdev_spec)

u.tune(USRP_number, subdev, frequency) # First argument is which digital downconverter,
# not USRP_number. It should
be 0 in most cases

subdev.set_gain(gain)

I hope this helped. Ask again if you’ve got more questions.

Eric

On Sun, Jan 07, 2007 at 06:03:53PM -0500, Josh B. wrote:

GRC is my little graphical interface for gnu radio.
Josh Knows | GNU Radio Companion

Thanks.

I want to add graphical source/sink for the USRP. So, I am trying to
figure out a generic way to make a USRP source/sink given a bunch of
parameters. If certain USRP daughter boards need special attention, then
I can make special graphical blocks just for them.

No, you can treat them all the same.

Thank you very much for you response. It helped a lot. I have a few more
questions:
I assume that the tune function only works for certain daughter
boards(setting the center frequency), but is it safe to call regardless?

Tune works for all daughterboards. In general it controls the front
end PLL and the DDC. On boards without a front end PLL, it just tunes
the DDC.

I found this pick_subdevice code (below) in one of the examples. Is
“u.db[0][0].dbid() >= 0” in the format u.db[side][subdevice]? And is
this the correct way to test if a particular subdevice is valid?

Yes. dbid() will be < 0 if there’s no daugtherboard, or if we don’t
recognize it. Note that this is used to provide a default value.
Generally speaking we require the user to specify what they want on
the command line. This is particularly important for folks with both
sides of their USRP populated. Anything that transmits requires the
user to explicitly specify the subdevice. Guessing which board the
user want to use to transmit seems like a very bad idea :wink:

if u.db[0][0].dbid() >= 0: # dbid is < 0 if there’s no d’board
or a problem
return (0, 0)
if u.db[1][0].dbid() >= 0:
return (1, 0)
return (0, 0)

You’re welcome!
Eric