-
Notifications
You must be signed in to change notification settings - Fork 19
/
gps.txt
213 lines (208 loc) · 6.24 KB
/
gps.txt
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
################################################################################
##
## Filename: gps.txt
## {{{
## Project: AutoFPGA, a utility for composing FPGA designs from peripherals
##
## Purpose: This file describes the three interfaces created by the GPS:
## 1) a GPS-locked clock, 2) a "testbench" which is used to
## measure the performance of the GPS-locked lock, and 3) a wishbone
## controlled UART which can be used to read from the UART stream coming
## from the GPS.
##
## Creator: Dan Gisselquist, Ph.D.
## Gisselquist Technology, LLC
##
################################################################################
## }}}
## Copyright (C) 2017-2024, Gisselquist Technology, LLC
## {{{
## This program is free software (firmware): you can redistribute it and/or
## modify it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or (at
## your option) any later version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License along
## with this program. (It's in the $(ROOT)/doc directory. Run make with no
## target there if the PDF file isn't present.) If not, see
## <http://www.gnu.org/licenses/> for a copy.
## }}}
## License: GPL, v3, as defined and found on www.gnu.org,
## {{{
## http://www.gnu.org/licenses/gpl.html
##
################################################################################
##
## }}}
@$GPSPORT_OFFSET=2
@PREFIX=gck
@DEVID=GPSTRK
@ACCESS=@$(DEVID)_ACCESS
@NADDR=4
@SLAVE.TYPE=DOUBLE
@SLAVE.BUS=wb
@CLOCK.NAME=clk
@$CLKFREQHZ=@$(CLOCK.FREQUENCY)
@$GPS_STEP_EXPONENT=10
@$GPS_STEP=((((1<<60)/@$CLKFREQHZ)>>(@$.GPS_STEP_EXPONENT-4))&0x0fffffff)|((@$.GPS_STEP_EXPONENT&0x0f)<<28)
@GPS_STEP.FORMAT=32'h%08x
@MAIN.PORTLIST=
// The GPS 1PPS signal port
i_gps_pps
@MAIN.PARAM=
localparam [31:0] GPSCLOCK_DEFAULT_STEP = @$.GPS_STEP;
@MAIN.IODECL=
//The GPS Clock
input wire i_gps_pps;
@MAIN.DEFNS=
wire gps_pps, gps_led, gps_locked, gps_tracking;
wire [63:0] gps_now, gps_err, gps_step;
wire [1:0] gps_dbg_tick;
@MAIN.INSERT=
// Verilator lint_off UNUSED
wire [1:0] ck_dbg;
// Verilator lint_on UNUSED
gpsclock #(.DEFAULT_STEP(GPSCLOCK_DEFAULT_STEP))
ppsck(i_clk, 1'b0, gps_pps, ck_pps, gps_led,
@$(SLAVE.PORTLIST),
gps_tracking, gps_now, gps_step, gps_err, gps_locked,
ck_dbg);
@MAIN.ALT=
wire [31:0] pre_step;
assign pre_step = { 16'h00, (({GPSCLOCK_DEFAULT_STEP[27:0],20'h00})
>>GPSCLOCK_DEFAULT_STEP[31:28]) };
always @(posedge i_clk)
{ ck_pps, gps_step[31:0] } <= gps_step + pre_step;
assign gck_stall = 1'b0;
assign gps_now = 64'h0;
assign gps_err = 64'h0;
assign gps_step = 64'h0;
assign gps_led = 1'b0;
assign gps_locked = 1'b0;
@INT.PPS.WIRE=ck_pps
@INT.PPS.PIC=syspic
@REGS.NOTE= // GPS clock tracker, control loop settings registers
@REGS.N=4
@REGS.0= 0 R_GPS_ALPHA ALPHA
@REGS.1= 1 R_GPS_BETA BETA
@REGS.2= 2 R_GPS_GAMMA GAMMA
@REGS.3= 3 R_GPS_STEP STEP
@BDEF.DEFN=
typedef struct GPSTRACKER_S {
unsigned g_alpha, g_beta, g_gamma, g_step;
} GPSTRACKER;
@BDEF.INSERT=
#define SYSINT_PPS SYSINT(@$(INT.PPS.syspic.ID))
@BDEF.IONAME=_gps
@BDEF.IOTYPE= GPSTRACKER
@BDEF.OSVAL=
static volatile @$(BDEF.IOTYPE) *const @$(BDEF.IONAME) = ((@$BDEF.IOTYPE *)@$[0x%08x]REGBASE);
##
##
##
@PREFIX=gtb
@NADDR=8
@SLAVE.TYPE=DOUBLE
@SLAVE.BUS=wb
@CLOCK.NAME=clk
@MAIN.DEFNS=
wire tb_pps;
@MAIN.INSERT=
`ifdef GPSTRK_ACCESS
gpsclock_tb #(.CLOCK_FREQUENCY_HZ(@$(CLOCK.FREQUENCY)))
ppstb(i_clk, ck_pps, tb_pps,
@$(SLAVE.PORTLIST),
gps_err, gps_now, gps_step);
`ifdef GPSTB
assign gps_pps = tb_pps;
`else
assign gps_pps = i_gps_pps;
`endif
`endif
@REGS.NOTE= // GPS clock test bench registers, for measuring the clock trackers performance
@REGS.N=8
@REGS.0= 0 R_GPSTB_FREQ GPSFREQ
@REGS.1= 1 R_GPSTB_JUMP GPSJUMP
@REGS.2= 2 R_GPSTB_ERRHI ERRHI
@REGS.3= 3 R_GPSTB_ERRLO ERRLO
@REGS.4= 4 R_GPSTB_COUNTHI CNTHI
@REGS.5= 5 R_GPSTB_COUNTLO CNTLO
@REGS.6= 6 R_GPSTB_STEPHI STEPHI
@REGS.7= 7 R_GPSTB_STEPLO STEPLO
@BDEF.DEFN=
typedef struct GPSTB_S {
unsigned tb_maxcount, tb_jump;
unsigned long tb_err, tb_count, tb_step;
} GPSTB;
@BDEF.IONAME=_gpstb
@BDEF.IOTYPE=GPSTB
@BDEF.OSVAL=static volatile @$(BDEF.IOTYPE) *const @$(BDEF.IONAME) = ((@$(BDEF.IOTYPE) *)@$[0x%08x](REGBASE));
#
#
#
@PREFIX=gpsu
@INCLUDEFILE=wbuart.txt
@$BAUDRATE=9600
@CLOCK.NAME=clk
@$UARTSETUP=@$(CLOCK.FREQUENCY)/@$(BAUDRATE)
@ACCESS=GPSUART_ACCESS
@INT.INTLIST= GPSRX GPSTX GPSRXF GPSTXF
@INT.GPSRX.WIRE= gpsurx_int
@INT.GPSTX.WIRE= gpsutx_int
@INT.GPSRXF.WIRE= gpsurxf_int
@INT.GPSTXF.WIRE= gpsutxf_int
@INT.GPSRX.PIC= altpic
@INT.GPSTX.PIC= altpic
@INT.GPSRXF.PIC= altpic
@INT.GPSTXF.PIC= altpic
# Clear the other inherited wires, as we don't need them any more.
@INT.UARTRX.WIRE=
@INT.UARTTX.WIRE=
@INT.UARTRXF.WIRE=
@INT.UARTTXF.WIRE=
@INT.UARTRX.PIC=
@INT.UARTTX.PIC=
@INT.UARTRXF.PIC=
@INT.UARTTXF.PIC=
@BDEF.INSERT=
#define SYSINT_GPSRXF ALTINT(@$(INT.GPSRXF.syspic.ID))
#define SYSINT_GPSTXF ALTINT(@$(INT.GPSTXF.altpic.ID))
#define SYSINT_GPSRX ALTINT(@$(INT.GPSRX.altpic.ID))
#define SYSINT_GPSTX ALTINT(@$(INT.GPSTX.altpic.ID))
@TOP.PORTLIST=
// The GPS-UART
i_@$(PREFIX)_rx, o_@$(PREFIX)_tx
@MAIN.PORTLIST=
// The GPS-UART
i_@$(PREFIX)_rx, o_@$(PREFIX)_tx
@MAIN.IODECL=
input wire i_@$(PREFIX)_rx;
output wire o_@$(PREFIX)_tx;
@MAIN.DEFNS=
wire w_@$(PREFIX)_cts_n, w_@$(PREFIX)_rts_n;
assign w_@$(PREFIX)_cts_n=1'b1;
@RTS=w_@$(PREFIX)_rts_n
@CTS=w_@$(PREFIX)_cts_n
@REGS.NOTE= // GPS UART registers, similar to WBUART
@REGS.N=4
@REGS.0= 0 R_GPSU_SETUP GPSSETUP
@REGS.1= 1 R_GPSU_FIFO GPSFIFO
@REGS.2= 2 R_GPSU_UARTRX GPSRX
@REGS.3= 3 R_GPSU_UARTTX GPSTX
@BDEF.IONAME=_@$(PREFIX)
@BDEF.OSDEF=_BOARD_HAS_GPS_UART
@BDEF.OSVAL=static volatile @$(BDEF.IOTYPE) *const @$(BDEF.IONAME) = ((@$(BDEF.IOTYPE) *)(@$[0x%08x](REGBASE)));
@$SIM.PORTOFFSET=@/GPSPORT_OFFSET
@SIM.INIT=
#ifdef @$(ACCESS)
m_@$(PREFIX) = new UARTSIM(FPGAPORT+@$(SIM.PORTOFFSET));
m_@$(PREFIX)->setup(@$[0x%08x](UARTSETUP));
#endif // @$(ACCESS)
#
@RTL.MAKE.GROUP=GPS
@RTL.MAKE.FILES=gpsclock_tb.v gpsclock.v bigadd.v bigsub.v bigsmpy.v