]> git.rkrishnan.org Git - dttsp.git/blob - pyhw2/hardware.h
Add file missing from pyhw2
[dttsp.git] / pyhw2 / hardware.h
1 // hardware.h
2 // version 2
3
4 #ifndef _hardware_h
5 #define _hardware_h
6
7 #include <sys/types.h>
8 #include <sys/param.h>
9 #include <sys/stat.h>
10 #include <sys/time.h>
11 #include <sys/wait.h>  
12 #include <sys/mman.h>
13 #include <sys/ioctl.h>
14 #include <sys/socket.h>  
15 #include <signal.h>
16 #include <unistd.h>
17 #include <fcntl.h>
18 #include <stdlib.h>
19 #include <values.h>
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <ctype.h>
23 #include <string.h>
24 #include <math.h>
25 #include <assert.h>
26 #include <libgen.h>
27
28 #include <pthread.h>
29 #include <semaphore.h>
30
31 #include <linux/ppdev.h>
32 #include <linux/parport.h>
33
34 #ifndef PRIVATE
35 #define PRIVATE static
36 #endif
37 #ifndef PUBLIC
38 #define PUBLIC extern
39 #endif
40
41 typedef int BOOL;
42 typedef unsigned char BYTE;
43
44 #ifndef FALSE
45 #define FALSE 0
46 #endif
47
48 #ifndef TRUE
49 #define TRUE 1
50 #endif
51
52 PUBLIC double DttSP_SampleRate;
53
54 typedef enum {
55   IARU1 = 1,
56   IARU2 = 2,
57   IARU3 = 3,
58 } BandPlan;
59
60 typedef enum {
61   BYPASS,
62   MEMORY,
63   FULL,
64   LAST,
65 } ATUTuneMode;
66
67 typedef enum {
68   POSITIVE = 0, // DEMI144-28FRS
69   NEGATIVE,     // 25W DEMI
70   NONE,         // For Elecraft or similar XVTR
71 } XVTRTRMode;
72
73 // Constants for BPF relays
74 typedef enum {
75   bsnone = 0,                   //none
76   bs0 = 0x01,                   //2.5MHz LPF
77   bs1 = 0x02,                   //2-6MHz BPF
78   bs2 = 0x08,                   //5-12MHz BPF
79   bs3 = 0x04,                   //10-24MHz BPF
80   bs4 = 0x10,                   //20-40MHz BPF
81   bs5 = 0x20,                   //35-60MHz BPF
82 } BandSetting;
83
84 // PIO Control Pin Numbers
85 typedef enum {
86   EXT = 1,                      //C0
87   BPF = 14,                     //C1
88   DAT = 16,                     //C2
89   ADR = 17,                     //C3
90 } CtrlPin;
91
92 // PIO Status Mask
93 typedef enum {
94   PIN_12        = 0x08,         //S3
95   Dash          = 0x10,         //S4
96   Dot           = 0x20,         //S5
97   PA_DATA       = 0x40,         //S6
98   PIN_11        = 0x80,         //S7
99 } StatusPin;
100
101 // External control port mask
102 typedef enum {
103   P1 = 0x01,
104   P2 = 0x02,
105   P3 = 0x04,
106   P4 = 0x08,
107   P5 = 0x10,
108   P6 = 0x20,
109   P7 = 0x40,
110 } ExtPin;
111
112 // RFE CONTROLS:
113
114 // Control and data lines for RFE serial decoders
115 #define SER             0x01
116 #define SCK             0x02
117 #define SCLR_NOT        0x04
118 #define DCDR_NE         0x20
119
120 // RFE 1:4 Decoder (74HC139) values to drive shift register RCK lines
121 typedef enum {
122   IC11 = 0x00,
123   IC7  = 0x08,
124   IC9  = 0x18,
125   IC10 = 0x10,
126 } RFE_RCK;
127
128 // RFE control constants
129
130 // On board low pass filter relays
131 #define LPF0 0x01
132 #define LPF1 0x02
133 #define LPF2 0x04
134 #define LPF3 0x08
135 #define LPF4 0x10
136 #define LPF5 0x20
137 #define LPF6 0x40
138 #define LPF7 0x80
139 #define LPF8 0x01
140 #define LPF9 0x02
141
142 // Band pass filter relays
143 #define BPF0 0x80
144 #define BPF1 0x40
145 // Note: BPF2 and BPF3 are reverse order
146 // on BPF board
147 #define BPF2 0x10
148 #define BPF3 0x20
149 #define BPF4 0x08
150 #define BPF5 0x04
151
152 // IC11 Variables
153 // Register memory for IC11
154 PUBLIC int ic11_memory;         
155 // Power Amplifier low pass filters
156 #define PAF0            0x01
157 #define PAF1            0x02                            
158 #define PAF2            0x04
159 // Analog to Digital Clock
160 #define ADC_CLK         0x08
161 // Analog to Digital Data In
162 #define ADC_DI          0x10
163 // Analog to Digital Chip Select (inverse logic)
164 #define ADC_CS_NOT      0x20
165 // Power amplifier TR relay
166 #define PATR            0x40
167 // Automatic Tuning Unit control
168 #define ATUCTL          0x80
169
170 // IC7 Variables
171 // Register memory for IC7
172 PUBLIC int ic7_memory;          
173 // Controls both AMP1 and AMP2 relays
174 #define AMP_RLYS        0x03    
175 // 2M transverter TR relay (on for RX) XVRX on schematic
176 #define XVTR_TR_RLY     0x04    
177 // Switches 2M transverter switching relay into signal path
178 #define XVTR_RLY        0x08    
179 // Attenuator relay
180 #define ATTN_RLY        0x10    
181 // Impulse circuit switches impulse into signal path
182 #define IMPULSE_RLY     0x20    
183 // Spare control line to PA (inverse logic)
184 #define PA_BIAS_NOT     0x40    
185 // Generates 5ns Pulse
186 #define IMPULSE         0x80    
187
188 PUBLIC BOOL rfe_enabled;                // True if RFE board is enabled
189 PUBLIC BOOL xvtr_enabled;               // Transverter is enabled
190
191 // done with RFE controls
192
193 // PA variables
194 PUBLIC BOOL pa_enabled;
195 // 0
196 #define PA_LPF_OFF      0                               
197 // 1
198 #define PA_LPF_12_10    PAF0                            
199 // 2
200 #define PA_LPF_17_15    PAF1                            
201 // 3
202 #define PA_LPF_30_20    PAF0+PAF1               
203 // 4
204 #define PA_LPF_60_40    PAF2                            
205 // 5
206 #define PA_LPF_80       PAF2+PAF0               
207 // 6
208 #define PA_LPF_160      PAF2+PAF1               
209 #define PA_FORWARD_PWR  0
210 #define PA_REVERSE_PWR  1
211
212 // Constants latch outputs
213 #define  TR     0x40
214 #define  MUTE   0x80
215 #define  GAIN   0x80
216 #define  WRB    0x40
217 #define  RESET  0x80
218
219 // Latch Memories
220 PUBLIC BandSetting band_relay;
221 PUBLIC int external_output;
222 PUBLIC int mute_relay;
223 PUBLIC int transmit_relay;
224 PUBLIC int gain_relay;
225 PUBLIC int latch_delay;
226
227 // DDS Control Constants
228 // DDS Comparator power down
229 #define COMP_PD         0x10            
230 // DDS Digital Power down
231 #define DIG_PD          0x01            
232 // Bypass DDS PLL
233 #define BYPASS_PLL      0x20            
234 // Internal IO Update
235 #define INT_IOUD        0x01            
236 // Offset Shift Keying enable
237 #define OSK_EN          0x20            
238 // Offset Shift Keying
239 #define OSK_INT         0x10            
240 // Bypass Inverse Sinc Filter
241 #define BYPASS_SINC     0x40            
242 // Set PLL Range
243 #define PLL_RANGE       0x40            
244
245 // DDS Clock properties
246 PUBLIC double dds_clock;
247 PUBLIC int pll_mult;
248 PUBLIC double dds_clock_correction;
249 PUBLIC double sysClock;
250 PUBLIC int ioud_clock;
251 PUBLIC ushort dac_mult;
252
253 // DDS Frequency Control properties
254 PUBLIC double dds_freq;
255 PUBLIC double if_freq;
256 PUBLIC BOOL if_shift;
257 PUBLIC BOOL spur_reduction;
258 PUBLIC double dds_step_size;
259 PUBLIC int sample_rate;
260 PUBLIC int fft_length;
261 PUBLIC double FFT_Bin_Size;
262 PUBLIC int tune_fft;
263 PUBLIC double tune_frac_rel;
264 PUBLIC double vfo_offset;
265 //extern double last_VFO;
266
267 PUBLIC double min_freq;
268 PUBLIC double max_freq;
269
270 // PIO register base address
271 PUBLIC u_short baseAdr;
272
273 // Current Bandplan
274 PUBLIC BandPlan curBandPlan;
275
276 PUBLIC double TWO_TO_THE_48_DIVIDED_BY_200;
277 PUBLIC long last_tuning_word;
278 // private Mutex parallel_mutex;
279 // private Mutex dataline_mutex;
280
281 PUBLIC BOOL usb_enabled;
282
283 #define SDR1K_LATCH_EXT 0x01
284 #define SDR1K_LATCH_BPF 0x02
285
286 //------------------------------------------------------------------------
287
288 PUBLIC BOOL        openPort(char *port);
289 PUBLIC void        closePort(void);
290 PUBLIC void        USB_Sdr1kLatch(int, BYTE);
291 PUBLIC BYTE        USB_Sdr1kGetStatusPort(void);
292 PUBLIC int         USB_Sdr1kGetADC(void);
293 PUBLIC void        USB_Sdr1kDDSReset(void);
294 PUBLIC void        USB_Sdr1kDDSWrite(BYTE addr, BYTE data);
295 PUBLIC void        USB_Sdr1kSRLoad(BYTE reg, BYTE data);
296 PUBLIC void        DttSP_ChangeOsc(double val);
297
298 PUBLIC void        Init                  (void);
299 PUBLIC void        PowerOn               (void);
300 PUBLIC void        StandBy               (void);
301 PUBLIC void        Impulse               (void);
302
303 PUBLIC BYTE        StatusPort            (void);
304 PUBLIC void        SetExt                (ExtPin pin);
305 PUBLIC void        ResExt                (ExtPin pin);
306 PUBLIC BOOL        PinValue              (ExtPin pin);
307 PUBLIC void        SetBPF                (double vfo_value);
308 PUBLIC void        TestPort              (void);
309 PUBLIC void        RCKStrobe             (BOOL ClearReg, RFE_RCK Reg);
310 PUBLIC void        SRLoad                (RFE_RCK Reg, int Data);
311 PUBLIC void        ResetRFE              (void);
312 PUBLIC void        PA_SetLPF             (int i);
313 PUBLIC BYTE        PA_GetADC             (int chan);
314 PUBLIC BOOL        PA_ATUTune            (ATUTuneMode mode);
315
316 PUBLIC BOOL        getEnableLPF0         (void);
317 PUBLIC void        setEnableLPF0         (BOOL value);
318 PUBLIC BOOL        getExtended           (void);
319 PUBLIC void        setExtended           (BOOL value);
320 PUBLIC BOOL        getX2Enabled          (void);
321 PUBLIC void        setX2Enabled          (BOOL value);
322 PUBLIC int         getX2Delay            (void);
323 PUBLIC void        setX2Delay            (int value);
324 PUBLIC BOOL        getRFE_Enabled        (void);
325 PUBLIC void        setRFE_Enabled        (BOOL value);
326 PUBLIC BOOL        getPA_Enabled         (void);
327 PUBLIC void        setPA_Enabled         (BOOL value);
328 PUBLIC BOOL        getXVTR_Enabled       (void);
329 PUBLIC BOOL        setXVTR_Enabled       (BOOL value);
330 PUBLIC BOOL        getUSB_Enabled        (void);
331 PUBLIC void        setUSB_Enabled        (BOOL value);
332 PUBLIC XVTRTRMode  getCurrentXVTRTRMode  (void);
333 PUBLIC void        setCurrentXVTRTRMode  (XVTRTRMode value);
334 PUBLIC int         getLatchDelay         (void);
335 PUBLIC void        setLatchDelay         (int value);
336 PUBLIC double      getMinFreq            (void);
337 PUBLIC double      getMaxFreq            (void);
338 PUBLIC u_short     getBaseAddr           (void);
339 PUBLIC u_short     setBaseAddr           (u_short value);
340 PUBLIC BandSetting getBandRelay          (void);
341 PUBLIC void        setBandRelay          (BandSetting value);
342 PUBLIC BOOL        getTransmitRelay      (void);
343 PUBLIC void        setTransmitRelay      (BOOL value);
344 PUBLIC BOOL        getMuteRelay          (void);
345 PUBLIC void        setMuteRelay          (BOOL value);
346 PUBLIC BOOL        getGainRelay          (void);
347 PUBLIC void        setGainRelay          (BOOL value);
348 PUBLIC int         getExternalOutput     (void);
349 PUBLIC void        setExternalOutput     (int value);
350 PUBLIC double      getDDSClockCorrection (void);
351 PUBLIC void        setDDSClockCorrection (double value);
352 PUBLIC int         getPLLMult            (void);
353 PUBLIC void        setPLLMult            (int value);
354 PUBLIC double      getDDSClock           (void);
355 PUBLIC void        setDDSClock           (double value);
356 PUBLIC BOOL        getIFShift            (void);
357 PUBLIC void        setIFShift            (BOOL value);
358 PUBLIC BOOL        getSpurReduction      (void);
359 PUBLIC BOOL        setSpurReduction      (BOOL value);
360 PUBLIC double      getIFFreq             (void);
361 PUBLIC void        setIFFreq             (double value);
362 PUBLIC double      getDDSFreq            (void);
363 PUBLIC void        setDDSFreq            (double value);
364 PUBLIC int         getSampleRate         (void);
365 PUBLIC void        setSampleRate         (int value);
366 PUBLIC int         getFFTLength          (void);
367 PUBLIC void        setFFTLength          (int value);
368 PUBLIC int         getTuneFFT            (void);
369 PUBLIC double      getTuneFracRel        (void);
370 PUBLIC double      getVFOOffset          (void);
371 PUBLIC void        setVFOOffset          (double value);
372 PUBLIC int         getIOUDClock          (void);
373 PUBLIC void        setIOUDClock          (int value);
374 PUBLIC u_short     getDACMult            (void);
375 PUBLIC void        setDACMult            (u_short value);
376 PUBLIC BOOL        getAMP_Relay          (void);
377 PUBLIC BOOL        setAMP_Relay          (BOOL value);
378 PUBLIC BOOL        getATTN_Relay         (void);
379 PUBLIC void        setATTN_Relay         (BOOL value);
380 PUBLIC BOOL        getXVTR_TR_Relay      (void);
381 PUBLIC BOOL        setXVTR_TR_Relay      (BOOL value);
382 PUBLIC BOOL        getXVTR_Relay         (void);
383 PUBLIC BOOL        setXVTR_Relay         (BOOL value);
384 PUBLIC BOOL        getIMPULSE_Relay      (void);
385 PUBLIC BOOL        setIMPULSE_Relay      (BOOL value);
386 PUBLIC BOOL        getPA_TransmitRelay   (void);
387 PUBLIC BOOL        setPA_TransmitRelay   (BOOL value);
388 PUBLIC BOOL        getPA_BiasOn          (void);
389 PUBLIC BOOL        setPA_BiasOn          (BOOL value);
390
391 //------------------------------------------------------------------------
392
393 #endif