How to write USB 2.0 interface for Windows in C++?


#1

Hi,

I am trying to capture USB 2.0 packets sent over by the USRP in a C++
program. I was able to found a code that does the similar job in Linux:

#include “usrp_standard.h”
// Dumy Function to process USRP data
void process_data(int buffer)
{
}
#define SAMPELS_PER_READ (512) // Must be a multiple of 128
int main (int argc, char **argv)
{
bool loopback_p = false;
bool counting_p = false;
bool width_8_p = false;
int which_board = 0;
int decim = 8; // 32 MB/sec
double center_freq = 0;
int fusb_block_size = 0;
int fusb_nblocks = 0;
int nchannels = 1;
int gain = 0;
int mode = 0;
int noverruns = 0;
bool overrun;
int total_reads = 10000;
int i;
int buf[SAMPELS_PER_READ];
int bufsize = SAMPELS_PER_READ
4;

if (loopback_p) mode |= usrp_standard_rx::FPGA_MODE_LOOPBACK;

if (counting_p) mode |= usrp_standard_rx::FPGA_MODE_COUNTING;

usrp_standard_rx *urx = usrp_standard_rx::make (which_board, decim, 1,
-1,
mode, fusb_block_size, fusb_nblocks);

if (urx == 0)
{
fprintf (stderr, “Error: usrp_standard_rx::make\n”);
exit (1);
}

if (width_8_p)
{
int width = 8;
int shift = 8;
bool want_q = true;
if (!urx->set_format(usrp_standard_rx::make_format(width, shift,
want_q)))
{
fprintf (stderr, “Error: urx->set_format\n”);
exit (1);
}
}
// Set DDC center frequency
urx->set_rx_freq (0, center_freq);
// Set Number of channels
urx->set_nchannels(1);
// Set ADC PGA gain
urx->set_pga(0,gain);
// Set FPGA Mux
urx->set_mux(0x32103210); // Board A only
// Set DDC decimation rate
urx->set_decim_rate(decim);
// Set DDC phase
urx->set_ddc_phase(0,0);

urx->start(); // Start data transfer

printf(“USRP Transfer Started\n”);
// Do USRP Samples Reading
for (i = 0; i < total_reads; i++)
{
urx->read(&buf, bufsize, &overrun);
if (overrun)
{
printf (“USRP Rx Overrun\n”);
noverruns++;
}
// Do whatever you want with the data
process_data(&buf[0]);
}

urx->stop(); // Stop data transfer
printf(“USRP Transfer Stoped\n”);

delete urx;
return 0;
}

I was able to successfully achieve my goal through this code in Linux.
However, I need to implement the same task in Windows. I was initially
suggested to look for usrp_standard.h but I have no idea how to write a
code
(like the one above) which will incorporate this header file and be able
to
do the actual communication. Please provide me with some guidelines in
this
regard.

Thanks.
Ujala


#2

On Mon, Feb 02, 2009 at 05:22:23PM +0500, Ujala Q. wrote:

Hi,

I am trying to capture USB 2.0 packets sent over by the USRP in a C++
program. I was able to found a code that does the similar job in Linux:

[snip]

I was able to successfully achieve my goal through this code in Linux.
However, I need to implement the same task in Windows. I was initially
suggested to look for usrp_standard.h but I have no idea how to write a code
(like the one above) which will incorporate this header file and be able to
do the actual communication. Please provide me with some guidelines in this
regard.

Thanks.
Ujala

The USRP works with MS windows. There’s no special code you need to
write. Just use the interface exported by user_standard.h. If you
use the code in the trunk, it includes the c++ daughterboard support.

Eric


#3

“Just use the interface exported by user_standard.h”
Do you mean I should use the usrp_standard.cc?


#4

On Mon, Feb 02, 2009 at 06:30:20PM +0500, Ujala Q. wrote:

“Just use the interface exported by user_standard.h”
Do you mean I should use the usrp_standard.cc?

Yes.


#5

Other then that, there are a lot of other header files and cc files that
are
included and I have downloaded them manually and compiling them with
usrp_standard.h too, however, I can’t find the header files of type
sys/cdefs.h or sys/time.h


#6

I have downloaded usrp_standard.cc and usrp_standard.h manually. I am
now
trying to compile them in Microsoft Visual C++, but it is giving me a
couple
of errors?


#7

I actually want to interface the USRP and a DSP board together. For this
I
need to write the USB 2.0 interface between them. I am initially trying
to
write a C++ code that will capture the data samples from USRP’s USB 2.0
in
Windows. Later, I will try to use the same code on DSP board. What
information should I know before writing this interface? Also, from
where I
can get to know about the architecture and working of FPGA on the USRP?


#8

On Mon, Feb 02, 2009 at 07:09:21PM +0500, Ujala Q. wrote:

I have downloaded usrp_standard.cc and usrp_standard.h manually. I am now
trying to compile them in Microsoft Visual C++, but it is giving me a couple
of errors?

The easiest way to get this working is to build it using our normal
build system, under Cygwin.

See:

http://gnuradio.org/trac/wiki/BuildGuide
http://gnuradio.org/trac/wiki/WindowsInstall
http://gnuradio.org/trac/wiki/CygwinInstallMain

It may build under MinGW too:

http://gnuradio.org/trac/wiki/MingwInstallMain

You’re on your own if you want to try to use Visual C++.
Others before you have tried and disappeared into the void,
never to be seen again… They left these scratchings in the dirt:
http://gnuradio.org/trac/wiki/WindowsNativeInstall

Eric


#9

On Tue, Feb 03, 2009 at 10:53:01AM +0500, Ujala Q. wrote:

I actually want to interface the USRP and a DSP board together. For this I
need to write the USB 2.0 interface between them. I am initially trying to
write a C++ code that will capture the data samples from USRP’s USB 2.0 in
Windows. Later, I will try to use the same code on DSP board.

OK

What information should I know before writing this interface?

You should have a good understanding of USB 2.0 and in particular the
concepts of endpoints and types of transfers (we primarily use bulk
transfers). The USB 2.0 spec is available on line.

Our abstract interface to the USB primitives is contained in
fusb.{h,cc}. fusb_generic.{h,cc} provides a concrete generic
interface that works, but is likely to be slow. In order to change
the least amount of code, create new concrete classes derived from
those in fusb.h, then create appropriate fusb_sysconfig_* files to
link it in. See fusb_*.{h,cc} for OS specific implementations.

Also, from where I can get to know about the architecture and
working of FPGA on the USRP?

This diagram is pretty good:
http://gnuradio.org/trac/wiki/UsrpRfxDiagrams

The USRP FAQ is good:
http://gnuradio.org/trac/wiki/UsrpFAQ

And of course, you’ve got the FPGA code available to you:
usrp/fpga/toplevel/usrp_std/usrp_std.v

Eric