GNU Radio's HOWTO Package
gn3s.h
Go to the documentation of this file.
1 /*----------------------------------------------------------------------------------------------*/
2 /*! \file gn3s.h
3 //
4 // FILENAME: gn3s.h
5 //
6 // DESCRIPTION: Defines the GN3S class.
7 //
8 // DEVELOPERS: Gregory W. Heckler (2003-2009)
9 //
10 // LICENSE TERMS: Copyright (c) Gregory W. Heckler 2009
11 //
12 // This file is part of the GPS Software Defined Radio (GPS-SDR)
13 //
14 // The GPS-SDR is free software; you can redistribute it and/or modify it under the terms of the
15 // GNU General Public License as published by the Free Software Foundation; either version 2 of
16 // the License, or (at your option) any later version. The GPS-SDR is distributed in the hope that
17 // it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 // more details.
20 //
21 // Note: Comments within this file follow a syntax that is compatible with
22 // DOXYGEN and are utilized for automated document extraction
23 //
24 // Reference:
25 */
26 /*----------------------------------------------------------------------------------------------*/
27 
28 
29 #ifndef GN3S_H_
30 #define GN3S_H_
31 
32 
33 /* Includes */
34 /*--------------------------------------------------------------*/
35 #include <unistd.h>
36 #include <stdio.h>
37 #include <errno.h>
38 #include <string.h>
39 #include <math.h>
40 #include <libusb.h>
41 /*--------------------------------------------------------------*/
42 
43 
44 /* FX2 Configuration Structure */
45 /*--------------------------------------------------------------*/
46 struct fx2Config
47 {
48  int interface;
50  libusb_device_handle *udev;
51 };
52 /*--------------------------------------------------------------*/
53 
54 
55 /* FX2 Stuff */
56 /*--------------------------------------------------------------*/
57 #define RX_ENDPOINT (0x86)
58 #define VRT_VENDOR_IN (0xC0)
59 #define VRT_VENDOR_OUT (0x40)
60 #define RX_INTERFACE (2)
61 #define RX_ALTINTERFACE (0)
62 #define VRQ_GET_STATUS (0x80)
63 #define GS_RX_OVERRUN (1) //!< Returns 1 byte
64 #define VRQ_XFER (0x01)
65 /*--------------------------------------------------------------*/
66 
67 
68 /* GN3S Stuff */
69 /*--------------------------------------------------------------*/
70 #define GN3S_VID (0x16C0)
71 #define GN3S_PID (0x072F)
72 #define VID_OLD (0x1781)
73 #define PID_OLD (0x0B39)
74 #define PROG_SET_CMD (0xE600)
75 #define USB_BUFFER_SIZE (16384) //!< 8 MB
76 #define USB_BLOCK_SIZE (512) //!< 16KB is hard limit
77 #define USB_NBLOCKS (USB_BUFFER_SIZE / USB_BLOCK_SIZE)
78 #define USB_NTRANSFERS (16)
79 #define USB_TIMEOUT (1000)
80 /*--------------------------------------------------------------*/
81 
82 
83 /* The firmware is embedded into the executable */
84 /*--------------------------------------------------------------*/
86 /*--------------------------------------------------------------*/
87 
88 
89 /*--------------------------------------------------------------*/
90 /*! \ingroup CLASSES
91  *
92  */
93 class gn3s
94 {
95 
96  private:
97 
98  /* First or second board */
99  int which;
100 
101  /* GN3S FX2 Stuff */
102  struct fx2Config fx2_config;
103  struct libusb_device *fx2_device;
104  struct libusb_device_handle *fx2_handle;
105  struct libusb_transfer *transfer[USB_NTRANSFERS];
106 
107  /* USB IDs */
108  unsigned int gn3s_vid, gn3s_pid;
109 
110  /* Pull in the binary firmware */
111  int fstart;
112  int fsize;
113  //char *gn3s_firmware;
114 
115  public:
116 
117  gn3s(int _which); //!< Constructor
118  ~gn3s(); //!< Destructor
119 
120  /* FX2 functions */
121  struct libusb_device* usb_fx2_find(unsigned int vid, unsigned int pid, char info, int ignore);
122  bool usb_fx2_configure(struct libusb_device *fx2, fx2Config *fx2c);
125  int read(unsigned char *buff, int bytes);
126  int write_cmd(int request, int value, int index, unsigned char *bytes, int len);
127  bool _get_status(int which, bool *trouble);
128  bool check_rx_overrun();
129  bool usrp_xfer(char VRQ_TYPE, bool start);
130 
131  /* Used to flash the GN3S */
132  int atoz(char *s);
133  void upload_ram(unsigned char *buf, int start, int len);
134  void program_fx2(char *filename, char mem);
135  int prog_gn3s_board();
136 
137 };
138 /*--------------------------------------------------------------*/
139 
140 
141 #endif /*GN3S_H_ */
Definition: gn3s.h:93
bool check_rx_overrun()
int interface
Definition: gn3s.h:48
bool usb_fx2_start_transfers()
gn3s(int _which)
Constructor.
Definition: gn3s.h:46
#define USB_NTRANSFERS
Definition: gn3s.h:78
bool usb_fx2_configure(struct libusb_device *fx2, fx2Config *fx2c)
bool _get_status(int which, bool *trouble)
bool usrp_xfer(char VRQ_TYPE, bool start)
bool usb_fx2_cancel_transfers()
int atoz(char *s)
~gn3s()
Destructor.
int prog_gn3s_board()
void program_fx2(char *filename, char mem)
int altinterface
Definition: gn3s.h:49
void upload_ram(unsigned char *buf, int start, int len)
int read(unsigned char *buff, int bytes)
libusb_device_handle * udev
Definition: gn3s.h:50
char _binary_usrp_gn3s_firmware_ihx_start[]
struct libusb_device * usb_fx2_find(unsigned int vid, unsigned int pid, char info, int ignore)
int write_cmd(int request, int value, int index, unsigned char *bytes, int len)