-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathrtcgps.txt
147 lines (145 loc) · 4.33 KB
/
rtcgps.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
################################################################################
##
## Filename: auto-data/rtcgps.txt
##
## Project: AutoFPGA, a utility for composing FPGA designs from peripherals
## {{{
## Purpose:
##
## 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
##
##
################################################################################
##
## }}}
@PREFIX=rtc
@DEVID=RTC
@NADDR=4
@SLAVE.TYPE=DOUBLE
@SLAVE.BUS=wb32
@ACCESS=RTC_ACCESS
@CLOCK.NAME=clk
@CLKFREQHZ=@$(CLOCK.FREQUENCY)
@$CLKSTEP=((1<<48)/@$(CLOCK.FREQUENCY))
@INT.RTC.WIRE=rtc_int
@INT.RTC.PIC=altpic
@MAIN.DEFNS=
// Definitions in support of the GPS driven RTC
// This clock step is designed to match @$(CLOCK.FREQUENCY) Hz
localparam [31:0] RTC_CLKSTEP = @$[32'h%08x](CLKSTEP);
wire @$(PREFIX)_ppd;
wire @$(PREFIX)_pps;
@MAIN.INSERT=
`ifdef GPSTRK_ACCESS
rtcgps #(
.DEFAULT_SPEED(RTC_CLKSTEP)
) u_@$(PREFIX)(
.i_clk(i_clk), .i_reset(i_reset),
@$(SLAVE.ANSIPORTLIST),
.o_interrupt(@$(PREFIX)_int), .o_ppd(@$(PREFIX)_ppd),
.i_gps_valid(gps_tracking), .i_gps_pps(ck_pps),
.i_gps_ckspeed(gps_step[47:16]), .o_rtc_pps(rtc_pps)
);
`else
rtclight #(
.DEFAULT_SPEED(@$[32'h%x](CLKSTEP))
) u_@$(PREFIX)(
.i_clk(i_clk), .i_reset(i_reset),
// Can't use the ANSIPORTLIST tag, because the address widths
// don't match
.i_wb_cyc(@$(SLAVE.PREFIX)_cyc),
.i_wb_stb(@$(SLAVE.PREFIX)_stb),
.i_wb_we(@$(SLAVE.PREFIX)_we),
.i_wb_addr({ 1'b0, @$(SLAVE.PREFIX)_addr[1:0] }),
.i_wb_data(@$(SLAVE.PREFIX)_data),
.i_wb_sel(@$(SLAVE.PREFIX)_sel),
.o_wb_stall(@$(SLAVE.PREFIX)_stall),
.o_wb_ack(@$(SLAVE.PREFIX)_ack),
.o_wb_data(@$(SLAVE.PREFIX)_idata),
.o_interrupt(@$(PREFIX)_int),
.o_pps(rtc_pps),
.o_ppd(@$(PREFIX)_ppd)
);
// Verilator lint_off UNUSED
wire unused_@$(PREFIX);
assign unused_@$(PREFIX) = &{ 1'b0, i_gps_pps };
// Verilator lint_on UNUSED
`endif
@MAIN.ALT=
`ifdef GPSTRK_ACCESS
assign @$(PREFIX)_pps = ck_pps;
`endif
assign @$(PREFIX)_ppd = 1'b0;
@REGS.NOTE= // RTC clock registers
@REGS.N=4
@REGS.0= 0 R_CLOCK CLOCK
@REGS.1= 1 R_TIMER TIMER
@REGS.2= 2 R_STOPWATCH STOPWATCH
@REGS.3= 3 R_CKALARM ALARM CKALARM
@BDEF.DEFN=
typedef struct RTCLIGHT_S {
unsigned r_clock, r_stopwatch, r_timer, r_alarm;
} RTCLIGHT;
@BDEF.IONAME=_rtc
@BDEF.IOTYPE=RTCLIGHT
@BDEF.OSDEF=_BOARD_HAS_RTC
@BDEF.OSVAL=static volatile @$BDEF.IOTYPE *const @$(BDEF.IONAME) = ((@$BDEF.IOTYPE *)@$[0x%08x](REGBASE));
#
#
@RTL.MAKE.GROUP=RTCGPS
@RTL.MAKE.SUBD=rtc
@RTL.MAKE.FILES=rtcgps.v rtcbare.v rtctimer.v rtcstopwatch.v rtcalarm.v rtclight.v
##
##
@PREFIX=subseconds
@DEVID=SUBSECONDS
@NADDR=1
@SLAVE.BUS=wb32
@SLAVE.TYPE=SINGLE
@MAIN.DEFNS=
`ifndef GPSTRK_ACCESS
reg [31:0] r_@$(PREFIX)_data;
`endif
@MAIN.INSERT=
`ifdef GPSTRK_ACCESS
assign @$(SLAVE.PREFIX)_idata = gps_now[31:0];
`else
always @(posedge i_clk)
if (@$(SLAVE.PREFIX)_stb && @$(SLAVE.PREFIX)_we)
r_@$(PREFIX)_data <= @$(SLAVE.PREFIX)_data;
else
r_@$(PREFIX)_data <= r_@$(PREFIX)_data
+ { 16'h0, RTC_CLKSTEP[31:16] };
assign @$(SLAVE.PREFIX)_idata = r_@$(PREFIX)_data;
`endif
@REGS.NOTE= // A register capturing subseconds, locked to GPS if present
@REGS.N=1
@REGS.0= 0 R_SUBSECONDS SUBSECONDS
@BDEF.IONAME=_@$(PREFIX)
@BDEF.IOTYPE=unsigned
@BDEF.OSDEF=_BOARD_HAS_@$(DEVID)
@BDEF.OSVAL=static volatile @$(BDEF.IOTYPE) *const @$(BDEF.IONAME) = ((@$BDEF.IOTYPE *)@$[0x%08x](REGBASE));