-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgp2021.c
372 lines (318 loc) · 5.62 KB
/
gp2021.c
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/***********************************************************************
GPS RECEIVER (GPSRCVR) Ver. 1.18
See comments in GPSRCVR.CPP
12 Channel All-in-View GPS Receiver Program based on Mitel GP2021
chipset
Clifford Kelley <[email protected]>
This program is licensed under GNU GENERAL PUBLIC LICENSE
This LICENSE file must be included with the GPSRCVR code.
***********************************************************************/
#ifdef SOFT
# include "SoftOSGPS.h"
int inpwd(unsigned short int add)
{
return (REG_read[add]);
}
void outpwd(unsigned short int add, unsigned short int data)
{
REG_write[add]=data;
}
#else /* SOFT */
# ifdef __linux__
# ifdef __KERNEL__
# include <asm/io.h>
# else /* __KERNEL__ */
/* #include <sys/io.h> */
# include "SoftOSGPS.h"
# endif /* __KERNEL__ */
# define outpwd(p, v) outw_p(v, p)
# define inpwd(p) inw_p(p)
# else /* __linux__ */
# include <dos.h> /* For Port Memory I/O */
# endif /* __linux__ */
#endif /* SOFT */
extern int Base_address, Register_address, Data_address;
static int ch_status = 1;
void
to_gps (int add, int data)
{
#ifdef SOFT
outpwd (add, data);
#else
if (Base_address)
outpwd (Base_address + ((add & 0xfc) << 8) + ((add & 0x3) << 3), data);
else {
outpwd (Register_address, add);
outpwd (Data_address, data);
}
#endif
}
short int
from_gps (int add)
{
#ifdef SOFT
return inpwd (add);
#else
if (Base_address)
return (inpwd (Base_address + ((add & 0xfc) << 8 ) + ((add & 0x3) << 3 )));
else {
outpwd (Register_address, add);
return (inpwd (Data_address));
}
#endif
}
void
gp2021_latch (void)
{
to_gps (0x80, 0); /* tell 2021 to latch the correllators */
}
int
accum_status (void)
{
return (from_gps (0x82));
}
short int
gp2021_missed (void)
{
return from_gps(0x83);
}
unsigned int
ch_epoch_chk (int ch)
{
return (from_gps ((ch << 3) + 7));
}
void
ch_cntl (int ch, int data)
{
/* printf("ch=%d port=%x\n",ch,port(ch<<3)); */
to_gps (ch << 3, data);
}
void
ch_accum_reset (int ch)
{
to_gps ((ch << 2) + 0x85, 0);
}
void
ch_code_slew (int ch, int data)
{
to_gps ((ch << 2) + 0x84, data);
}
void
program_TIC (long data)
{
unsigned int high, low;
high = ((int) (data >> 16));
low = ((int) (data & 0xffff));
to_gps (0x6d, high);
to_gps (0x6f, low);
}
void
reset_cntl (int data)
{
to_gps (0x7f, data);
/* fprintf(out,"reset data=%x\n",data); */
}
void
ch_carrier (int ch, long freq)
{
int freq_hi, freq_lo;
unsigned int add;
freq_hi = ((int) (freq >> 16));
freq_lo = ((int) (freq & 0xffff));
add = (ch << 3) + 3;
to_gps (add, freq_hi);
add++;
to_gps (add, freq_lo);
}
void
ch_code (int ch, long freq)
{
int freq_hi, freq_lo;
unsigned int add;
freq_hi = (int) (freq >> 16);
freq_lo = (int) (freq & 0xffff);
add = (ch << 3) + 5;
to_gps (add, freq_hi);
add++;
to_gps (add, freq_lo);
}
void
ch_epoch_load (int ch, unsigned int data)
{
to_gps ((ch << 3) + 7, data);
}
void
ch_on (int ch)
{
ch_status = ch_status | (0x1 << (ch+1));
reset_cntl (ch_status);
}
void
system_setup (int data)
{
to_gps (0x7e, data);
}
void
test_control (int data)
{
to_gps (0x7c, data);
}
void
io_config (int data)
{
to_gps (0xf0, data);
}
void
data_retent_w (int data)
{
to_gps (0xe4, data);
}
int
data_retent_r (void)
{
return (from_gps (0xe4));
}
void
data_bus_test_w (int data)
{
to_gps (0xf2, data);
}
int
data_bus_test_r (void)
{
return (from_gps (0xf2));
}
int
self_test (void)
{
unsigned short int indataaax, indata55x, indataaay, indata55y, error;
error = 0;
data_retent_w (0x5500);
data_bus_test_w (0xaa55);
indata55x = data_retent_r ();
indataaax = data_bus_test_r ();
data_retent_w (0xaa00);
data_bus_test_w (0x55aa);
indataaay = data_retent_r ();
indata55y = data_bus_test_r ();
if ((indata55x != 0x5500) || (indataaax != 0xaa55)
|| (indataaay != 0xaa00) || (indata55y != 0x55aa))
{
error = 1;
/* #define DEBUG 1 */
#ifdef DEBUG
#include <stdio.h>
printf ("data line error\n");
printf ("indata55x=%x , indataaax=%x\n", indata55x, indataaax);
printf ("indataaay=%x , indata55y=%x\n", indataaay, indata55y);
#endif
}
return error;
}
int
ch_carrier_DCO_phase (int ch)
{
return (from_gps ((ch << 3) + 0x3));
}
long
ch_carrier_cycle (int ch)
{
long result;
result = from_gps ((ch << 3) + 6);
result = result << 16;
result = result + from_gps ((ch << 3) + 2);
return (result);
}
int
ch_code_phase (int ch)
{
return (from_gps ((ch << 3) + 0x1));
}
unsigned int
ch_epoch (int ch)
{
return (from_gps ((ch << 3) + 4));
}
int
ch_code_DCO_phase (int ch)
{
return (from_gps ((ch << 3) + 5));
}
int
ch_i_track (int ch)
{
return (from_gps ((ch << 2) + 0x84));
}
int
ch_q_track (int ch)
{
return (from_gps ((ch << 2) + 0x85));
}
int
ch_i_prompt (int ch)
{
return (from_gps ((ch << 2) + 0x86));
}
int
ch_q_prompt (int ch)
{
return (from_gps ((ch << 2) + 0x87));
}
#ifdef UNUSED
void
data_tst (int data)
{
to_gps (0xf2, data);
}
void
ch_code_incr_hi (int ch, int data)
{
to_gps ((ch << 3) + 0x5, data);
}
void
ch_code_incr_lo (int ch, int data)
{
to_gps ((ch << 3) + 0x6, data);
}
void
carr_incr_hi (int ch, int data)
{
to_gps ((ch << 3) + 0x3, data);
}
void
carr_incr_lo (char ch, int data)
{
to_gps ((ch << 3) + 0x4, data);
}
void
all_cntl (int data)
{
to_gps (0x70, data);
}
void
multi_cntl (int data)
{
to_gps (0x60, data);
}
void
all_code_slew (int data)
{
to_gps (0x70, data);
}
int
meas_status (void)
{
return (from_gps (0x81));
}
void
ch_off (int ch)
{
ch_status = ch_status & !(0x1 << (ch+1));
reset_cntl (ch_status);
}
void
status_latch (void)
{
to_gps (0x80, 0);
}
#endif /* UNUSED */