-
Notifications
You must be signed in to change notification settings - Fork 1
/
express.h
executable file
·207 lines (183 loc) · 5.81 KB
/
express.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
#ifndef EXPRESS_H
#define EXPRESS_H
#include <sys/types.h>
#include <stdint.h>
#include <stdio.h>
#include "express_server.h"
// Error code
void report_error(int code);
int get_error(void);
#define ERROR_INVALID_VIDEO_CAPTURE -1001
#define ERROR_INVALID_AUDIO_CAPTURE -1002
#define ERROR_FIRMWARE_NOT_FOUND -1003
#define ERROR_FPGA_NOT_FOUND -1004
#define ERROR_EXPRESS_NOT_FOUND -1005
#define ERROR_CONFIG_NOT_FOUND -1006
#define ERROR_ILLEGAL_S2_VALUES -1007
#ifndef __SCMPLX__
typedef struct{
short re;
short im;
}scmplx;
#endif
#define BOOL int
#define USB_VENDOR 0x4B4
#define USB_PROD 0x8613
// Both are out for in add 0x80
#define EP1OUT 0x01
#define EP1IN 0x81
#define EP2OUT 0x02
#define USB_TIMEOUT 100
#define N_USB_TX_BUFFS 20
//
// Addresses of various I2C devices on the DATVExpress board
// Everything has an address including the FPGA
// If the LSB is zero it is a write operation if it is a one
// it is a read operation.
//
#define ADRF6755_ADD 0x80
#define AD7992_ADD 0x40
#define FPGA_ADD 0x8C
#define SI570_ADD 0xAA
#define FLASH_ADD 0xAE
#define FX2_ADD 0x42
#define I2C_WR 0x00
#define I2C_RD 0x01
// Commands to FX2
#define RST_CMD 0x00
#define BK_CMD 0x01
#define TX_CMD 0x02
#define RX_CMD 0x03
// Comparison frequency in the PLL
#define PFD40 40000000.0
// FPGA registers
// Configuration register
#define FPGA_CONFIG_REG 0
#define FPGA_8BIT_MODE 0x00
#define FPGA_16BIT_MODE 0x01
#define FPGA_USE_SI570 0x02
#define FPGA_NULL_INSERT 0x04
// Filter and interpolator register
#define FPGA_FIL_REG 1
#define FPGA_INT_REG 2
#define FPGA_FEC_REG 3
#define IRATE2 0
#define IRATE4 1
#define IRATE8 2
#define IRATE16 3
#define IRATE32 4
#define IRATE64 5
#define IRATEIV 7
// Ancillary values
#define FPGA_CARRIER 0x01
#define FPGA_CALIBRA 0x02
#define FPGA_RAMP 0x04
#define FPGA_PREDIST 0x08
// DC offset registers
#define FPGA_I_DC_MSB_REG 4
#define FPGA_I_DC_LSB_REG 5
#define FPGA_Q_DC_MSB_REG 6
#define FPGA_Q_DC_LSB_REG 7
// Ancillary register
#define FPGA_ANC_REG 8
// Symbol rate registers
#define FPGA_SR_REG 10
// Predistortion register
#define FPGA_PRE_REG 20
// Iteration rates
#define SR_S2_THRESHOLD_HZ 100000000
#define SR_S_THRESHOLD_HZ 100000000
#define SR_THRESHOLD_SI570_HZ 100000000
#define FEC_RATE_12 0
#define FEC_RATE_23 1
#define FEC_RATE_34 2
#define FEC_RATE_56 3
#define FEC_RATE_78 4
// Threshold we need to switch to 8 bit mode
//#define BIT_MODE_THRESHOLD 320000000
enum{ HW_EXPRESS_16, HW_EXPRESS_8 };
#define EXP_OK 1
#define EXP_FAIL -1
#define EXP_MISS -2
#define EXP_IHX -3
#define EXP_RBF -4
#define EXP_CONF -5
#define TP_SIZE 188
#define MAX_Q_LEN 1000
#define SYNC_BYTE 0x47
int express_write_samples(scmplx *s, int len);
int express_write_16_bit_samples(scmplx *s, int len);
int express_write_transport_stream( uint8_t *tp, int len );
void express_deinit(void);
int express_init( const char *fx2, const char *fpga );
void express_set_freq( double freq );
void express_set_level( int level );
void express_set_fec( int fec );
void express_enable( void );
void express_disable( void );
void express_fpga_reset(void);
// Program the symbol rate
int express_set_sr( double sr );
// Select the channel interpolation rate and filter (of 4)
void express_set_interp( int interp );
void express_set_filter( int filter );
void express_set_fec( int fec );
// Read the Version number of the ADRF6755 chip
void express_read_adrf6755_version(void);
// Read the two ADC channels
void express_read_ad7992_chans(void);
// Start the FX2 code running
void express_run(void);
// Load i & q calibration values
void express_set_ical( int offset );
void express_set_qcal( int offset );
// Number of outstanding samples left to send on the hardware
double express_outstanding_queue_size(void);
// Can we queue another buffer
int express_get_tx_queue_size(void);
// Release any outstanding transfrt buffers
void express_release_transfer_buffers(void);
// Used to send a bulk transfer message to the Express board for I2C transmittal
int express_i2c_bulk_transfer(int ep, uint8_t *b, int l );
// Polls the event handler, this is needed for I2C messages as they
// are not handled by the sample transfer routines in Express
void express_handle_events(int n);
// Signal that a Si570 has been detected and configured
void express_si570_fitted(void);
// Enables the DAC and modulator
void express_transmit(void);
// Disables the DAC and modulator
void express_receive(void);
// Set carrier
void express_set_carrier( BOOL b);
// Set/clear calibration output
void express_set_iqcalibrate( BOOL b);
// Toggle linearisation ramp
void express_set_ramp( BOOL b);
// Switch the predistorter on/off
void express_set_predist( BOOL b);
// Update the predistortion table
// it is 256 entries long and can only be updated when predistortion is off
void express_load_ptab( uint8_t add, uint16_t ival, uint16_t qval );
// Used for flow control
BOOL express_context_available(void);
// TX port controll for external relays
void express_set_ports(uint8_t ports);
// Non Express HW prototypes
uint8_t *alloc_buff(void);
// Release a buffer
void rel_buff(uint8_t *b);
// Post a buffer to the tx queue
void post_buff( uint8_t *b);
// Get a buffer from the tx queue
uint8_t *get_buff(void);
// Get tx queue size
int get_buf_qsize(void);
// Initialise the buffers
void buf_init(void);
void null_fmt( void );
void update_cont_counter( void );
void null_pkt( void );
int UDPServerInit(void);
void udp_new_socket_required(void);
#endif // FX2USB_H