1 |
2 |
jclaytons |
// $Id: x7_top.v 900 2015-04-23 03:09:36Z nxp20190 $
|
2 |
|
|
//
|
3 |
|
|
// @brief Sango X7 Main top.
|
4 |
|
|
//
|
5 |
|
|
// @Author Roger Williams <roger.williams@nxp.com>
|
6 |
|
|
//
|
7 |
|
|
// (c) 2015 NXP Semiconductors. All rights reserved.
|
8 |
|
|
//
|
9 |
|
|
// PROPRIETARY INFORMATION
|
10 |
|
|
//
|
11 |
|
|
// The information contained in this file is the property of NXP Semiconductors.
|
12 |
|
|
// Except as specifically authorized in writing by NXP, the holder of this file:
|
13 |
|
|
// (1) shall keep all information contained herein confidential and shall protect
|
14 |
|
|
// same in whole or in part from disclosure and dissemination to all third parties
|
15 |
|
|
// and (2) shall use same for operation and maintenance purposes only.
|
16 |
|
|
// -----------------------------------------------------------------------------
|
17 |
|
|
// 0.01.0 2015-04-16 (RAW) Initial entry
|
18 |
|
|
// 0.02.0 2015-04-18 (RAW) System clock, IO_UPDATE
|
19 |
|
|
// 0.03.0 2015-05-14 (RAW) Incorporated xdig HDL
|
20 |
|
|
// 0.04.0 2016-02-27 (JEC) Updated pin names to match Sango X7 schematic
|
21 |
|
|
// Added DDR3 and MMC interface pins
|
22 |
|
|
//-------------------------------------------------------------------------------
|
23 |
|
|
|
24 |
|
|
`include "version.v"
|
25 |
|
|
`include "timescale.v"
|
26 |
|
|
`include "registers_def.v"
|
27 |
|
|
|
28 |
|
|
|
29 |
|
|
module x7_main
|
30 |
|
|
(
|
31 |
|
|
// 100MHz clock from synthesiser
|
32 |
|
|
input wire FPGA_CLKP_i,
|
33 |
|
|
input wire FPGA_CLKN_i,
|
34 |
|
|
// Asynchronous reset
|
35 |
|
|
input wire RESETN_i,
|
36 |
|
|
// signals between MCU and FPGA
|
37 |
|
|
output reg MISO_o,
|
38 |
|
|
input wire MOSI_i,
|
39 |
|
|
input wire SCLK_i,
|
40 |
|
|
input wire SPI_SSN_i,
|
41 |
|
|
input wire FLASH_SEL_i,
|
42 |
|
|
input wire MCU_CLK_i, // currently unused
|
43 |
|
|
// SPI to synthesiser
|
44 |
|
|
input wire SYN_MISO_i,
|
45 |
|
|
output wire SYN_MOSI_o,
|
46 |
|
|
output wire SYN_SCLK_o,
|
47 |
|
|
output wire DDS_SSN_o,
|
48 |
|
|
output wire RSYN_SSN_o,
|
49 |
|
|
output wire FR_SSN_o,
|
50 |
|
|
output wire MSYN_SSN_o,
|
51 |
|
|
output wire MBW_SSN_o,
|
52 |
|
|
// DDS interface
|
53 |
|
|
output wire DDS_IORST_o,
|
54 |
|
|
output reg DDS_IOUP_o,
|
55 |
|
|
input wire DDS_SYNC_i,
|
56 |
|
|
output wire [2:0] DDS_PS_o,
|
57 |
|
|
// output module SPI interfaces
|
58 |
|
|
input wire [4:1] CH_MISO_i,
|
59 |
|
|
output wire [4:1] CH_MOSI_o,
|
60 |
|
|
output wire [4:1] CH_SCLK_o,
|
61 |
|
|
output wire [4:1] CH_SSN_o,
|
62 |
|
|
output wire [4:1] CH_GATE_o,
|
63 |
|
|
output wire [4:1] BIASON_o,
|
64 |
|
|
inout wire [4:1] CH_CTRL1_io, // currently unused
|
65 |
|
|
inout wire [4:1] CH_CTRL0_io, // currently unused
|
66 |
|
|
// interlocks, front panel
|
67 |
|
|
input wire EXT_UNLOCK_i,
|
68 |
|
|
output wire RF_LED_GRN_o,
|
69 |
|
|
output wire RF_LED_RED_o,
|
70 |
|
|
// 667kHz switching regulator sync clock
|
71 |
|
|
output wire PSYNC_o,
|
72 |
|
|
// 24MHz clock output to USB hub XIN
|
73 |
|
|
output wire USB_CLK_o, // currently unused
|
74 |
|
|
// RF on signals
|
75 |
|
|
output wire RF_IS_ON_o,
|
76 |
|
|
input wire RF_ON_i,
|
77 |
|
|
// external interfaces
|
78 |
|
|
input wire SYNCINX_i, // Currently unused
|
79 |
|
|
output reg SYNCOUTX_o,
|
80 |
|
|
// PA interfaces
|
81 |
|
|
output wire [4:1] CONV_o,
|
82 |
|
|
output wire [4:1] SCK_F_o,
|
83 |
|
|
output wire [4:1] SCK_R_o,
|
84 |
|
|
input wire [4:1] SDO_F_i,
|
85 |
|
|
input wire [4:1] SDO_R_i,
|
86 |
|
|
output wire [4:1] VBUS_EN_o,
|
87 |
|
|
input wire [4:1] TRIGX_i,
|
88 |
|
|
// DDR3 interface
|
89 |
|
|
output wire [14:0] A_o,
|
90 |
|
|
output wire [2:0] BA_o,
|
91 |
|
|
inout wire [15:0] DQ_i,
|
92 |
|
|
output wire [1:0] DM_o,
|
93 |
|
|
output wire [1:0] DQS_o,
|
94 |
|
|
output wire [1:0] DQSN_o,
|
95 |
|
|
output wire CSN_o,
|
96 |
|
|
output wire WEN_o,
|
97 |
|
|
output wire CASN_o,
|
98 |
|
|
output wire RASN_o,
|
99 |
|
|
output wire CK_o,
|
100 |
|
|
output wire CKN_o,
|
101 |
|
|
output wire CKE_o,
|
102 |
|
|
output wire ODT_o,
|
103 |
|
|
// MMC interface (FPGA acts as MMC slave)
|
104 |
|
|
inout wire [7:0] MMC_DAT_io,
|
105 |
|
|
inout wire MMC_CMD_io,
|
106 |
|
|
input wire MMC_CLK_i,
|
107 |
|
|
output wire MMC_IRQN_o
|
108 |
|
|
);
|
109 |
|
|
|
110 |
|
|
//------------------------------------------------------------------------------
|
111 |
|
|
// FPGA_RST signal
|
112 |
|
|
wire FPGA_RST;
|
113 |
|
|
assign FPGA_RST = ~RESETN_i;
|
114 |
|
|
|
115 |
|
|
//------------------------------------------------------------------------------
|
116 |
|
|
// Drive values onto unused signals
|
117 |
|
|
assign USB_CLK_o = 1'b0;
|
118 |
|
|
assign MMC_IRQN_o = 1'b1;
|
119 |
|
|
assign CONV_o = 0;
|
120 |
|
|
assign VBUS_EN_o = 4'b1;
|
121 |
|
|
|
122 |
|
|
assign A_o = 15'b0;
|
123 |
|
|
assign BA_o = 3'b0;
|
124 |
|
|
assign DQ_i = 16'bZ;
|
125 |
|
|
assign DM_o = 2'b0;
|
126 |
|
|
assign DQS_o = 2'b0;
|
127 |
|
|
assign DQSN_o = 2'b1;
|
128 |
|
|
assign CSN_o = 1'b1;
|
129 |
|
|
assign WEN_o = 1'b1;
|
130 |
|
|
assign CASN_o = 1'b1;
|
131 |
|
|
assign RASN_o = 1'b1;
|
132 |
|
|
assign CK_o = 1'b0;
|
133 |
|
|
assign CKN_o = 1'b1;
|
134 |
|
|
assign CKE_o = 1'b0;
|
135 |
|
|
assign ODT_o = 1'b0;
|
136 |
|
|
|
137 |
|
|
//------------------------------------------------------------------------------
|
138 |
|
|
// system clock generation
|
139 |
|
|
wire clkfb, clkin;
|
140 |
|
|
(* keep = "true" *) wire clk; // 100MHz system clock
|
141 |
|
|
(* keep = "true" *) wire clk200; // 200MHz system clock
|
142 |
|
|
(* keep = "true" *) wire clk10; // 10MHz clock
|
143 |
|
|
IBUFGDS IBUFGDS_sysclk (.O(clkin),.I(FPGA_CLKP_i),.IB(FPGA_CLKN_i));
|
144 |
|
|
MMCME2_BASE #(.CLKIN1_PERIOD(10.000),.CLKOUT0_DIVIDE_F(8.0),.CLKOUT1_DIVIDE(4.0),
|
145 |
|
|
.CLKOUT4_DIVIDE(15),.CLKFBOUT_MULT_F(8),.CLKOUT6_DIVIDE(80),
|
146 |
|
|
.CLKOUT4_CASCADE("TRUE"))
|
147 |
|
|
MMCME2_BASE_sysclk (.CLKOUT0(clk),.CLKOUT1(clk200),.CLKOUT4(PSYNC_o),.CLKOUT6(clk10),
|
148 |
|
|
.CLKFBOUT(clkfb),.CLKIN1(clkin),.CLKFBIN(clkfb));
|
149 |
|
|
|
150 |
|
|
//------------------------------------------------------------------------------
|
151 |
|
|
// simple interlock LED logic
|
152 |
|
|
assign RF_IS_ON_o = RF_ON_i & ~EXT_UNLOCK_i;
|
153 |
|
|
assign RF_LED_GRN_o = RF_IS_ON_o;
|
154 |
|
|
assign RF_LED_RED_o = ~RF_IS_ON_o;
|
155 |
|
|
|
156 |
|
|
//------------------------------------------------------------------------------
|
157 |
|
|
// simple MCU to external SPI interface
|
158 |
|
|
reg [5:0] spi_addr = 6'b0;
|
159 |
|
|
reg [3:0] spi_count = 4'b0;
|
160 |
|
|
reg spi_data_valid = 1'b0;
|
161 |
|
|
wire fpga_miso;
|
162 |
|
|
wire spi_addr_valid = (spi_count >= 6);
|
163 |
|
|
wire spi_addr_done = (spi_count >= 8);
|
164 |
|
|
wire spi_sel = (FLASH_SEL_i & ~SPI_SSN_i);
|
165 |
|
|
wire fpga_ss;
|
166 |
|
|
always @(posedge SCLK_i or negedge spi_sel) begin
|
167 |
|
|
if (~spi_sel) begin
|
168 |
|
|
spi_count <= 0;
|
169 |
|
|
spi_addr <= 0;
|
170 |
|
|
end
|
171 |
|
|
else begin
|
172 |
|
|
if (~spi_addr_done)
|
173 |
|
|
spi_count <= spi_count + 1;
|
174 |
|
|
if (~spi_addr_valid)
|
175 |
|
|
spi_addr[5:0] <= {spi_addr[4:0], MOSI_i};
|
176 |
|
|
end
|
177 |
|
|
end
|
178 |
|
|
always @(negedge SCLK_i or negedge spi_sel)
|
179 |
|
|
if (~spi_sel)
|
180 |
|
|
spi_data_valid <= 0;
|
181 |
|
|
else if (spi_addr_done)
|
182 |
|
|
spi_data_valid <= 1;
|
183 |
|
|
// multiplex MCU SPI lines
|
184 |
|
|
assign DDS_SSN_o = ~(spi_data_valid & (spi_addr == 6'h00));
|
185 |
|
|
assign RSYN_SSN_o = ~(spi_data_valid & (spi_addr == 6'h01));
|
186 |
|
|
assign FR_SSN_o = ~(spi_data_valid & (spi_addr == 6'h02));
|
187 |
|
|
assign MSYN_SSN_o = ~(spi_data_valid & (spi_addr == 6'h03));
|
188 |
|
|
assign MBW_SSN_o = ~(spi_data_valid & (spi_addr == 6'h04));
|
189 |
|
|
assign fpga_ss = spi_data_valid & (spi_addr == 6'h10);
|
190 |
|
|
assign CH_SSN_o[1] = ~(spi_data_valid & (spi_addr[5:3] == 3'b100));
|
191 |
|
|
assign CH_SSN_o[2] = ~(spi_data_valid & (spi_addr[5:3] == 3'b101));
|
192 |
|
|
assign CH_SSN_o[3] = ~(spi_data_valid & (spi_addr[5:3] == 3'b110));
|
193 |
|
|
assign CH_SSN_o[4] = ~(spi_data_valid & (spi_addr[5:3] == 3'b111));
|
194 |
|
|
assign SYN_MOSI_o = spi_data_valid & MOSI_i & (spi_addr[5:3] == 3'b000);
|
195 |
|
|
assign CH_MOSI_o[1] = spi_data_valid & MOSI_i & (spi_addr[5:3] == 3'b100);
|
196 |
|
|
assign CH_MOSI_o[2] = spi_data_valid & MOSI_i & (spi_addr[5:3] == 3'b101);
|
197 |
|
|
assign CH_MOSI_o[3] = spi_data_valid & MOSI_i & (spi_addr[5:3] == 3'b110);
|
198 |
|
|
assign CH_MOSI_o[4] = spi_data_valid & MOSI_i & (spi_addr[5:3] == 3'b111);
|
199 |
|
|
assign SYN_SCLK_o = spi_data_valid & SCLK_i & (spi_addr[5:3] == 3'b000);
|
200 |
|
|
assign CH_SCLK_o[1] = spi_data_valid & SCLK_i & (spi_addr[5:3] == 3'b100);
|
201 |
|
|
assign CH_SCLK_o[2] = spi_data_valid & SCLK_i & (spi_addr[5:3] == 3'b101);
|
202 |
|
|
assign CH_SCLK_o[3] = spi_data_valid & SCLK_i & (spi_addr[5:3] == 3'b110);
|
203 |
|
|
assign CH_SCLK_o[4] = spi_data_valid & SCLK_i & (spi_addr[5:3] == 3'b111);
|
204 |
|
|
always @*
|
205 |
|
|
casex (spi_addr)
|
206 |
|
|
6'b010000: MISO_o = spi_data_valid & fpga_miso;
|
207 |
|
|
6'b000xxx: MISO_o = spi_data_valid & SYN_MISO_i;
|
208 |
|
|
6'b100xxx: MISO_o = spi_data_valid & CH_MISO_i[1];
|
209 |
|
|
6'b101xxx: MISO_o = spi_data_valid & CH_MISO_i[2];
|
210 |
|
|
6'b110xxx: MISO_o = spi_data_valid & CH_MISO_i[3];
|
211 |
|
|
6'b111xxx: MISO_o = spi_data_valid & CH_MISO_i[4];
|
212 |
|
|
default: MISO_o = 1'b0;
|
213 |
|
|
endcase
|
214 |
|
|
|
215 |
|
|
// generate 2xDDS_SYNC_i tick I/O_UPDATE strobe at end of DDS SPI write
|
216 |
|
|
reg dds_ssn_dly = 1'b1;
|
217 |
|
|
reg dds_ssn_dly2 = 1'b1;
|
218 |
|
|
reg dds_ioup_dly = 1'b0;
|
219 |
|
|
always @(posedge DDS_SYNC_i or posedge FPGA_RST) begin
|
220 |
|
|
if (FPGA_RST) begin
|
221 |
|
|
dds_ssn_dly <= 1'b0;
|
222 |
|
|
dds_ssn_dly2 <= 1'b0;
|
223 |
|
|
dds_ioup_dly <= 1'b0;
|
224 |
|
|
DDS_IOUP_o <= 1'b0;
|
225 |
|
|
end
|
226 |
|
|
else begin
|
227 |
|
|
dds_ssn_dly <= DDS_SSN_o;
|
228 |
|
|
dds_ssn_dly2 <= dds_ssn_dly;
|
229 |
|
|
dds_ioup_dly <= DDS_IOUP_o;
|
230 |
|
|
if (dds_ssn_dly & ~dds_ssn_dly2)
|
231 |
|
|
DDS_IOUP_o <= 1;
|
232 |
|
|
else if (dds_ioup_dly)
|
233 |
|
|
DDS_IOUP_o <= 0;
|
234 |
|
|
end
|
235 |
|
|
end
|
236 |
|
|
|
237 |
|
|
// tie DDS interface to defaults for now
|
238 |
|
|
assign DDS_IORST_o = 1'b0;
|
239 |
|
|
assign DDS_PS_o = 3'b000;
|
240 |
|
|
|
241 |
|
|
//------------------------------------------------------------------------------
|
242 |
|
|
// SPI-to-register interface
|
243 |
|
|
reg [3:0] fpga_spacount = 3'b0;
|
244 |
|
|
reg [3:0] fpga_spdcount = 4'b0;
|
245 |
|
|
reg [6:0] fpga_spaddr = 7'b0;
|
246 |
|
|
reg [15:0] fpga_spdin = 16'b0;
|
247 |
|
|
reg fpga_spdin_valid = 1'b0;
|
248 |
|
|
reg fpga_sprw = 1'b0;
|
249 |
|
|
reg [15:0] fpga_spdout = 16'b0;
|
250 |
|
|
reg fpga_spdout_load = 1'b0;
|
251 |
|
|
assign fpga_miso = fpga_spdout[15];
|
252 |
|
|
wire fpga_spadone = (fpga_spacount >= 8);
|
253 |
|
|
wire fpga_spdin_last = (fpga_spdcount == 15);
|
254 |
|
|
wire fpga_spdout_first = fpga_spadone & (fpga_spdcount == 0);
|
255 |
|
|
reg [15:0] dat_o = 16'b0;
|
256 |
|
|
|
257 |
|
|
// SPI MOSI_i in -> register write
|
258 |
|
|
// MCU shifts MOSI_i on falling edge of SCLK_i, so sample it on rising edge
|
259 |
|
|
always @(posedge SCLK_i or negedge fpga_ss) begin
|
260 |
|
|
if (~fpga_ss) begin
|
261 |
|
|
fpga_spacount <= 0;
|
262 |
|
|
fpga_spdcount <= 0;
|
263 |
|
|
fpga_spaddr <= 0;
|
264 |
|
|
fpga_sprw <= 0;
|
265 |
|
|
fpga_spdin_valid <= 0;
|
266 |
|
|
end
|
267 |
|
|
else begin
|
268 |
|
|
if (fpga_spadone) begin
|
269 |
|
|
// in data phase, generate write strobe for incoming data every 16th bit
|
270 |
|
|
fpga_spdin_valid <= fpga_spdin_last;
|
271 |
|
|
fpga_spdin[15:0] <= {fpga_spdin[14:0], MOSI_i};
|
272 |
|
|
fpga_spdcount <= fpga_spdcount + 1;
|
273 |
|
|
end
|
274 |
|
|
else begin
|
275 |
|
|
// still in address phase
|
276 |
|
|
fpga_spacount <= fpga_spacount + 1;
|
277 |
|
|
fpga_sprw <= fpga_spaddr[6];
|
278 |
|
|
fpga_spaddr[6:0] <= {fpga_spaddr[5:0], MOSI_i};
|
279 |
|
|
end
|
280 |
|
|
end
|
281 |
|
|
end
|
282 |
|
|
|
283 |
|
|
// register read -> SPI MISO_o out
|
284 |
|
|
// MCU samples MISO_o on rising edge of SCLK_i, so shift it on falling edge
|
285 |
|
|
always @(negedge SCLK_i or posedge fpga_spdout_load)
|
286 |
|
|
if (fpga_spdout_load)
|
287 |
|
|
fpga_spdout <= dat_o;
|
288 |
|
|
else if (fpga_spadone)
|
289 |
|
|
fpga_spdout[15:0] <= {fpga_spdout[14:0], 1'b0};
|
290 |
|
|
|
291 |
|
|
// reclock in 100MHz domain
|
292 |
|
|
reg we = 1'b0;
|
293 |
|
|
reg cs = 1'b0;
|
294 |
|
|
reg oe = 1'b0;
|
295 |
|
|
reg [6:0] adr = 7'b0;
|
296 |
|
|
reg [15:0] dat = 16'b0;
|
297 |
|
|
reg fpga_spdin_valid_dly = 1'b0;
|
298 |
|
|
reg fpga_spdout_first_dly = 1'b0;
|
299 |
|
|
reg fpga_spdout_rd_dly = 1'b0;
|
300 |
|
|
always @(posedge clk) begin
|
301 |
|
|
cs <= fpga_spadone;
|
302 |
|
|
adr <= fpga_spaddr;
|
303 |
|
|
fpga_spdin_valid_dly <= fpga_spdin_valid;
|
304 |
|
|
we <= fpga_spdin_valid & ~fpga_spdin_valid_dly;
|
305 |
|
|
dat <= fpga_spdin;
|
306 |
|
|
// generate 1-tick read strobe before next SCLK_i rising edge
|
307 |
|
|
fpga_spdout_first_dly <= fpga_spdout_first;
|
308 |
|
|
oe <= fpga_sprw & fpga_spdout_first & ~fpga_spdout_first_dly;
|
309 |
|
|
fpga_spdout_load <= oe;
|
310 |
|
|
end
|
311 |
|
|
|
312 |
|
|
//------------------------------------------------------------------------------
|
313 |
|
|
// code from xdig
|
314 |
|
|
wire [`REG_BITS_R] reg_r;
|
315 |
|
|
wire [`REG_BITS_W] reg_w;
|
316 |
|
|
assign reg_r[`VERSION_INDEX] = `VERSION;
|
317 |
|
|
wire [15:0] stat;
|
318 |
|
|
assign reg_r[`STAT_INDEX] = stat;
|
319 |
|
|
wire [15:0] irq;
|
320 |
|
|
assign reg_r[`IRQ_INDEX] = irq;
|
321 |
|
|
|
322 |
|
|
// reclock strobes in 100MHz domain
|
323 |
|
|
reg [15:0] ctrl = 16'b0;
|
324 |
|
|
wire ctrl_RST = ctrl[15]; // reset everything
|
325 |
|
|
wire ctrl_ABT = ctrl[14]; // abort bursts, clear arm
|
326 |
|
|
wire ctrl_TRIG = ctrl[8]; // manually trigger specified channels
|
327 |
|
|
wire ctrl_ARM = ctrl[0]; // arm specified channels for triggering
|
328 |
|
|
always @(posedge clk) begin
|
329 |
|
|
ctrl <= reg_w[`CTRL_INDEX];
|
330 |
|
|
end
|
331 |
|
|
|
332 |
|
|
reg [15:0] irq_clr = 16'b0;
|
333 |
|
|
always @(posedge clk)
|
334 |
|
|
irq_clr <= reg_w[`IRQ_CLR_INDEX];
|
335 |
|
|
|
336 |
|
|
// bit field assignments for CONF register
|
337 |
|
|
wire [15:0] conf = reg_w[`CONF_INDEX];
|
338 |
|
|
wire conf_MEAS_EN = conf[12]; // enable Zmon measurements on specified channels
|
339 |
|
|
wire conf_SRC_EN = conf[8]; // enable RF outputs on specified channels
|
340 |
|
|
wire conf_CONT = conf[4]; // enable continuous retriggering on specified channels
|
341 |
|
|
wire conf_TG_EN = conf[0]; // enable timing generators on specified channels
|
342 |
|
|
|
343 |
|
|
// bit field assignments for TRIG_SRC register
|
344 |
|
|
// 0 = off (manual only), 1-4 = specified TRIG input
|
345 |
|
|
wire [15:0] trig_src = reg_w[`TRIG_SRC_INDEX];
|
346 |
|
|
|
347 |
|
|
// bit field assignments for IRQ_MASK register
|
348 |
|
|
wire [15:0] irq_mask = reg_w[`IRQ_MASK_INDEX];
|
349 |
|
|
|
350 |
|
|
// bit field assignments for SYNC register
|
351 |
|
|
// 0=MCU, 1=GEN, 4-7=TRIG1-4, 8-11=TDONE1-4, 12-15=MDONE1-4, 16-19=CONV[1:4], 20-23=GATE[1:4]
|
352 |
|
|
wire [15:0] sync = reg_w[`SYNC_INDEX];
|
353 |
|
|
wire [7:0] sync_GEN = sync[15:8];
|
354 |
|
|
wire [4:0] sync_SRC = sync[4:0];
|
355 |
|
|
|
356 |
|
|
// bit field assignments for FILTER register
|
357 |
|
|
wire [15:0] filter_len = reg_w[`FILTER_INDEX];
|
358 |
|
|
|
359 |
|
|
// assign RF channel bias enables
|
360 |
|
|
assign VBUS1_EN_o = conf_TG_EN;
|
361 |
|
|
|
362 |
|
|
// pulse generator
|
363 |
|
|
reg [13:0] gprescale = 14'b0;
|
364 |
|
|
reg [7:0] gcount = 8'b0;
|
365 |
|
|
reg gen = 1'b0;
|
366 |
|
|
wire gtick1ms = (gprescale == 14'b0);
|
367 |
|
|
|
368 |
|
|
always @(posedge clk10)
|
369 |
|
|
if (gtick1ms)
|
370 |
|
|
gprescale <= 9999;
|
371 |
|
|
else
|
372 |
|
|
gprescale <= gprescale - 1;
|
373 |
|
|
|
374 |
|
|
always @(posedge clk10)
|
375 |
|
|
if (gtick1ms) begin
|
376 |
|
|
if (gcount == 5)
|
377 |
|
|
gen <= 1;
|
378 |
|
|
else if (gcount == 0)
|
379 |
|
|
gen <= 0;
|
380 |
|
|
if (gcount == 0) begin
|
381 |
|
|
if (sync_GEN > 4)
|
382 |
|
|
gcount <= sync_GEN;
|
383 |
|
|
end
|
384 |
|
|
else
|
385 |
|
|
gcount <= gcount - 1;
|
386 |
|
|
end
|
387 |
|
|
|
388 |
|
|
// input trigger filters
|
389 |
|
|
wire [2:1] trigflt;
|
390 |
|
|
reg [2:1] trigflt_dly = 2'b0;
|
391 |
|
|
wire [2:1] trig_rising = trigflt & ~trigflt_dly;
|
392 |
|
|
wire [2:1] trig_falling = ~trigflt & trigflt_dly;
|
393 |
|
|
trig_filter filter1 (.I(TRIG1X_i), .O(trigflt[1]), .C(clk10), .N(filter_len));
|
394 |
|
|
assign trigflt[2] = gen;
|
395 |
|
|
|
396 |
|
|
// latch decoded trigger at valid rising edge
|
397 |
|
|
always @(posedge clk) begin
|
398 |
|
|
trigflt_dly <= trigflt;
|
399 |
|
|
end
|
400 |
|
|
|
401 |
|
|
// demux signals to timing generators
|
402 |
|
|
reg trig_mux;
|
403 |
|
|
always @* begin
|
404 |
|
|
case (trig_src[1*4-1 -: 4])
|
405 |
|
|
4'd1: trig_mux = trig_falling[1];
|
406 |
|
|
4'd5: trig_mux = trig_falling[2];
|
407 |
|
|
default: trig_mux = 1'b0;
|
408 |
|
|
endcase
|
409 |
|
|
end
|
410 |
|
|
|
411 |
|
|
reg trig = 1'b0;
|
412 |
|
|
always @(posedge clk)
|
413 |
|
|
trig <= ctrl_TRIG | trig_mux;
|
414 |
|
|
|
415 |
|
|
// demux signals for clearing MCU_TRIGIN
|
416 |
|
|
reg rising_mux;
|
417 |
|
|
always @* begin
|
418 |
|
|
case (trig_src[1*4-1 -: 4])
|
419 |
|
|
4'd1: rising_mux = trig_rising[1];
|
420 |
|
|
4'd5: rising_mux = trig_rising[2];
|
421 |
|
|
default: rising_mux = 1'b0;
|
422 |
|
|
endcase
|
423 |
|
|
end
|
424 |
|
|
|
425 |
|
|
// register block decodes
|
426 |
|
|
reg reg_sel;
|
427 |
|
|
reg [4:1] tg_sel;
|
428 |
|
|
wire [15:0] tg_dat[4:1];
|
429 |
|
|
wire [15:0] reg_dat_o;
|
430 |
|
|
|
431 |
|
|
always @* begin
|
432 |
|
|
reg_sel = 0;
|
433 |
|
|
tg_sel = 0;
|
434 |
|
|
dat_o = 16'b0;
|
435 |
|
|
if (adr[6] == 0) begin
|
436 |
|
|
reg_sel = cs;
|
437 |
|
|
dat_o = reg_dat_o;
|
438 |
|
|
end
|
439 |
|
|
else begin
|
440 |
|
|
case (adr[5:4])
|
441 |
|
|
2'd0: begin
|
442 |
|
|
tg_sel[1] = cs;
|
443 |
|
|
dat_o = tg_dat[1];
|
444 |
|
|
end
|
445 |
|
|
2'd1: begin
|
446 |
|
|
tg_sel[2] = cs;
|
447 |
|
|
dat_o = tg_dat[2];
|
448 |
|
|
end
|
449 |
|
|
2'd2: begin
|
450 |
|
|
tg_sel[3] = cs;
|
451 |
|
|
dat_o = tg_dat[3];
|
452 |
|
|
end
|
453 |
|
|
2'd3: begin
|
454 |
|
|
tg_sel[4] = cs;
|
455 |
|
|
dat_o = tg_dat[4];
|
456 |
|
|
end
|
457 |
|
|
endcase
|
458 |
|
|
end
|
459 |
|
|
end
|
460 |
|
|
|
461 |
|
|
localparam WC = 8, WS = 8;
|
462 |
|
|
|
463 |
|
|
wire [1*WC:1] control;
|
464 |
|
|
wire [1*WS-1:0] status;
|
465 |
|
|
wire [15:0] irq_in;
|
466 |
|
|
|
467 |
|
|
assign control[1*WC -: WC] = {ctrl_RST, ctrl_ABT, ctrl_ARM, trig, conf_MEAS_EN,
|
468 |
|
|
conf_SRC_EN, conf_CONT, conf_TG_EN};
|
469 |
|
|
assign stat[1*4-1 -: 4] = status[1*WS-5 -: 4]; // state machine value for each channel
|
470 |
|
|
assign irq_in[1*4-1 -: 4] = status[1*WS-1 -: 4]; // interrupts from each channel
|
471 |
|
|
|
472 |
|
|
// 0=MCU, 1=GEN, 4-7=TRIG1-4, 8-11=TDONE1-4, 12-15=MDONE1-4, 16-19=CONV[1:4], 20-23=GATE[1:4]
|
473 |
|
|
always @*
|
474 |
|
|
case (sync_SRC)
|
475 |
|
|
5'd1: SYNCOUTX_o = gen; // GEN
|
476 |
|
|
5'd4: SYNCOUTX_o = trig; // TRIG
|
477 |
|
|
5'd8: SYNCOUTX_o = irq_in[0]; // TDONE
|
478 |
|
|
5'd12: SYNCOUTX_o = irq_in[12]; // MDONE
|
479 |
|
|
5'd16: SYNCOUTX_o = CONV_o[1]; // CONV
|
480 |
|
|
5'd20: SYNCOUTX_o = CH_GATE_o[1]; // RF_GATE
|
481 |
|
|
default: SYNCOUTX_o = 1'b0;
|
482 |
|
|
endcase
|
483 |
|
|
|
484 |
|
|
wire [4:1] adc_sck;
|
485 |
|
|
assign SCK_F_o = adc_sck;
|
486 |
|
|
assign SCK_R_o = adc_sck;
|
487 |
|
|
|
488 |
|
|
rs irq_latch[15:0] (.Q(irq), .S(irq_mask & irq_in), .R({16{ctrl_RST}} | irq_clr), .C(clk));
|
489 |
|
|
// assign FPGA_IRQN = ~|(irq_mask & irq_in); // IRQ pulse for each event
|
490 |
|
|
assign MMC_IRQN_o = ~|irq; // latched IRQ
|
491 |
|
|
|
492 |
|
|
// Apply default values to unused signals
|
493 |
|
|
assign CH_GATE_o[2] = 1'bZ;
|
494 |
|
|
assign CH_GATE_o[3] = 1'bZ;
|
495 |
|
|
assign CH_GATE_o[4] = 1'bZ;
|
496 |
|
|
assign BIASON_o[1] = 1'bZ;
|
497 |
|
|
assign BIASON_o[2] = 1'bZ;
|
498 |
|
|
assign BIASON_o[3] = 1'bZ;
|
499 |
|
|
assign BIASON_o[4] = 1'bZ;
|
500 |
|
|
assign CH_CTRL1_io[1] = 1'bZ;
|
501 |
|
|
assign CH_CTRL1_io[2] = 1'bZ;
|
502 |
|
|
assign CH_CTRL1_io[3] = 1'bZ;
|
503 |
|
|
assign CH_CTRL1_io[4] = 1'bZ;
|
504 |
|
|
assign CH_CTRL0_io[1] = 1'bZ;
|
505 |
|
|
assign CH_CTRL0_io[2] = 1'bZ;
|
506 |
|
|
assign CH_CTRL0_io[3] = 1'bZ;
|
507 |
|
|
assign CH_CTRL0_io[4] = 1'bZ;
|
508 |
|
|
|
509 |
|
|
// genvar i;
|
510 |
|
|
// for (i=1; i<=4; i=i+1) begin
|
511 |
|
|
// tg tg1 (
|
512 |
|
|
// .clk(clk),
|
513 |
|
|
// .rst_i(fpga_rst),
|
514 |
|
|
// .clk200(clk200),
|
515 |
|
|
// .adr_i(adr[3:0]),
|
516 |
|
|
// .dat_i(dat),
|
517 |
|
|
// .we_i(we),
|
518 |
|
|
// .oe_i(oe),
|
519 |
|
|
// .cs_i(tg_sel[1]),
|
520 |
|
|
// .dat_o(tg_dat[1]),
|
521 |
|
|
// .control(control),
|
522 |
|
|
// .status(status),
|
523 |
|
|
// .rf_gate(CH_GATE_o[1]),
|
524 |
|
|
// .adc_sck_o(adc_sck[1]),
|
525 |
|
|
// .conv_o(CONV_o[1]),
|
526 |
|
|
// .adcr_sdo_i(SDO_R_i[1]),
|
527 |
|
|
// .adcf_sdo_i(SDO_F_i[1])
|
528 |
|
|
// );
|
529 |
|
|
// end
|
530 |
|
|
|
531 |
|
|
registers reggie (
|
532 |
|
|
.clk_i(clk200),
|
533 |
|
|
.rst_i(fpga_rst),
|
534 |
|
|
.adr_i(adr[5:0]),
|
535 |
|
|
.dat_i(dat),
|
536 |
|
|
.we_i(we),
|
537 |
|
|
.oe_i(oe),
|
538 |
|
|
.cs_i(reg_sel),
|
539 |
|
|
.dat_o(reg_dat_o),
|
540 |
|
|
.reg_w(reg_w),
|
541 |
|
|
.reg_r(reg_r)
|
542 |
|
|
);
|
543 |
|
|
|
544 |
|
|
// MMC card command receiver
|
545 |
|
|
wire [47:0] mmc_cmd_raw;
|
546 |
|
|
wire mmc_cmd_done;
|
547 |
|
|
wire mmc_cmd_crc_err;
|
548 |
|
|
wire mmc_cmd_dir_err;
|
549 |
|
|
wire mmc_cmd_stop_err;
|
550 |
|
|
|
551 |
|
|
sd_card_cmd_rx mmc_rx1
|
552 |
|
|
(
|
553 |
|
|
// Asynchronous reset
|
554 |
|
|
.sys_rst_n(RESETN_i),
|
555 |
|
|
// SD/MMC card command signals
|
556 |
|
|
.sd_clk_i(MMC_CLK_i),
|
557 |
|
|
.sd_cmd_i(MMC_CMD_io),
|
558 |
|
|
// Command outputs
|
559 |
|
|
.cmd_raw_o(mmc_cmd_raw),
|
560 |
|
|
.cmd_index_o(),
|
561 |
|
|
.cmd_arg_o(),
|
562 |
|
|
.cmd_done_o(mmc_cmd_done),
|
563 |
|
|
.crc_err_o(mmc_cmd_crc_err),
|
564 |
|
|
.dir_err_o(mmc_cmd_dir_err),
|
565 |
|
|
.stop_err_o(mmc_cmd_stop_err)
|
566 |
|
|
);
|
567 |
|
|
|
568 |
|
|
// MMC card emulator
|
569 |
|
|
wire mmc_cmd;
|
570 |
|
|
wire mmc_cmd_drv;
|
571 |
|
|
wire mmc_cmd_zzz;
|
572 |
|
|
wire mmc_cmd_choice;
|
573 |
|
|
wire [7:0] mmc_dat;
|
574 |
|
|
wire [7:0] mmc_dat_zzz;
|
575 |
|
|
wire [7:0] mmc_dat_choice1;
|
576 |
|
|
wire [7:0] mmc_dat_choice2;
|
577 |
|
|
reg [7:0] mmc_dat_choice3;
|
578 |
|
|
wire mmc_od_mode;
|
579 |
|
|
wire mmc_dat_drv;
|
580 |
|
|
wire [1:0] mmc_dat_siz;
|
581 |
|
|
|
582 |
|
|
wire [31:0] card_fifo_adr;
|
583 |
|
|
wire [7:0] card_fifo_dat_wr;
|
584 |
|
|
wire card_fifo_we;
|
585 |
|
|
wire [7:0] card_fifo_dat_rd;
|
586 |
|
|
wire card_fifo_rd;
|
587 |
|
|
|
588 |
|
|
|
589 |
|
|
// Implement MMC card tri-state drivers at the top level
|
590 |
|
|
assign mmc_cmd_zzz = mmc_cmd?1'bZ:1'b0;
|
591 |
|
|
assign mmc_cmd_choice = mmc_od_mode?mmc_cmd_zzz:mmc_cmd;
|
592 |
|
|
assign MMC_CMD_io = mmc_cmd_drv?mmc_cmd_choice:1'bZ;
|
593 |
|
|
// Create "open drain" data vector
|
594 |
|
|
genvar j;
|
595 |
|
|
for(j=0;j<8;j=j+1) begin
|
596 |
|
|
assign mmc_dat_zzz[j] = mmc_dat[j]?1'bZ:1'b0;
|
597 |
|
|
end
|
598 |
|
|
// Select which data vector to use
|
599 |
|
|
assign mmc_dat_choice1 = mmc_od_mode?mmc_dat_zzz:mmc_dat;
|
600 |
|
|
assign mmc_dat_choice2 = mmc_dat_drv?mmc_dat_choice1:8'bZ;
|
601 |
|
|
// Use always block for readability
|
602 |
|
|
always @(mmc_dat_siz, mmc_dat_choice2)
|
603 |
|
|
if (mmc_dat_siz==0) mmc_dat_choice3 <= {7'bZ,mmc_dat_choice2[0]};
|
604 |
|
|
else if (mmc_dat_siz==1) mmc_dat_choice3 <= {4'bZ,mmc_dat_choice2[3:0]};
|
605 |
|
|
else mmc_dat_choice3 <= mmc_dat_choice2;
|
606 |
|
|
|
607 |
|
|
assign MMC_DAT_io = mmc_dat_choice3;
|
608 |
|
|
|
609 |
|
|
sd_card_emulator #(
|
610 |
|
|
.USE_R4_RESPONSE (1), // Fast I/O read/write (app specific)
|
611 |
|
|
.USE_R5_RESPONSE (0), // Interrupt Request Mode
|
612 |
|
|
.EXT_CSD_INIT_FILE ("ext_csd_init.txt"), // Initial contents of EXT_CSD
|
613 |
|
|
.OCR_USE_DUAL_VOLTAGE (1),
|
614 |
|
|
.OCR_USE_SECTOR_MODE (0),
|
615 |
|
|
.CID_MID (), // Manufacturer ID
|
616 |
|
|
.CID_OID (), // OEM ID
|
617 |
|
|
.CID_CBX (), // 0=Card, 1=BGA, 2=Package On Package
|
618 |
|
|
.CID_PNM (), // Product Name, 6 ASCII chars
|
619 |
|
|
.CID_PRV (), // Product Rev (2 BCD digits, e.g. 6.2=0x62)
|
620 |
|
|
.CID_PSN (), // Product serial number
|
621 |
|
|
.CID_MDT (), // Manufacture Date (Jan=1, 1997=0, e.g. Apr. 2000=0x43)
|
622 |
|
|
.DEF_STAT (), // Read Write, R_0
|
623 |
|
|
.CSD_WORD_3 (), // Read only
|
624 |
|
|
.CSD_WORD_2 (), // Read only
|
625 |
|
|
.CSD_WORD_1 (), // Read only
|
626 |
|
|
.CSD_WORD_0 (), // (31:16) is read only, (15:0) is R_1 default (R/W)
|
627 |
|
|
.DEF_R_Z () // Value returned for nonexistent registers
|
628 |
|
|
) mmc_card_0 (
|
629 |
|
|
|
630 |
|
|
// Asynchronous reset
|
631 |
|
|
.sys_rst_n(RESETN_i),
|
632 |
|
|
.sys_clk(clk200),
|
633 |
|
|
|
634 |
|
|
// Bus interface
|
635 |
|
|
.adr_i(4'b0),
|
636 |
|
|
.sel_i(1'b0),
|
637 |
|
|
.we_i(1'b0),
|
638 |
|
|
.dat_i(32'b0),
|
639 |
|
|
.dat_o(),
|
640 |
|
|
.ack_o(),
|
641 |
|
|
|
642 |
|
|
// SD/MMC card command signals
|
643 |
|
|
.sd_clk_i (MMC_CLK_i),
|
644 |
|
|
.sd_cmd_i (MMC_CMD_io),
|
645 |
|
|
.sd_cmd_o (mmc_cmd),
|
646 |
|
|
.sd_cmd_drv_o (mmc_cmd_drv),
|
647 |
|
|
.sd_od_mode_o (mmc_od_mode), // open drain mode, applies to sd_cmd_o and sd_dat_o
|
648 |
|
|
.sd_dat_i (MMC_DAT_io),
|
649 |
|
|
.sd_dat_o (mmc_dat),
|
650 |
|
|
.sd_dat_drv_o (mmc_dat_drv),
|
651 |
|
|
.sd_dat_siz_o (mmc_dat_siz),
|
652 |
|
|
|
653 |
|
|
// Data FIFO interface
|
654 |
|
|
.buf_adr_o (card_fifo_adr),
|
655 |
|
|
.buf_dat_o (card_fifo_dat_wr),
|
656 |
|
|
.buf_dat_we_o (card_fifo_we),
|
657 |
|
|
.buf_dat_i (card_fifo_dat_rd),
|
658 |
|
|
.buf_dat_rd_o (card_fifo_rd),
|
659 |
|
|
// Card busy indicator
|
660 |
|
|
.busy_i (1'b0)
|
661 |
|
|
);
|
662 |
|
|
|
663 |
|
|
|
664 |
|
|
endmodule
|
665 |
|
|
|
666 |
|
|
module rs
|
667 |
|
|
(
|
668 |
|
|
input wire S, R, C,
|
669 |
|
|
output reg Q = 1'b0
|
670 |
|
|
);
|
671 |
|
|
|
672 |
|
|
always @(posedge C)
|
673 |
|
|
if (R)
|
674 |
|
|
Q <= 0;
|
675 |
|
|
else if (S)
|
676 |
|
|
Q <= 1;
|
677 |
|
|
|
678 |
|
|
endmodule
|