1 | module Paella
|
---|
2 | (
|
---|
3 | input wire CLK_50MHz,
|
---|
4 | output wire LED,
|
---|
5 |
|
---|
6 | inout wire [3:0] TRG,
|
---|
7 | inout wire [6:0] CON_A,
|
---|
8 | inout wire [15:0] CON_B,
|
---|
9 | input wire [12:0] CON_C,
|
---|
10 | input wire [1:0] CON_BCLK,
|
---|
11 | input wire [1:0] CON_CCLK,
|
---|
12 |
|
---|
13 | input wire ADC_DCO,
|
---|
14 | input wire ADC_FCO,
|
---|
15 | input wire [2:0] ADC_D,
|
---|
16 |
|
---|
17 | output wire USB_SLRD,
|
---|
18 | output wire USB_SLWR,
|
---|
19 | input wire USB_IFCLK,
|
---|
20 | input wire USB_FLAGA, // EMPTY flag for EP6
|
---|
21 | input wire USB_FLAGB, // FULL flag for EP8
|
---|
22 | input wire USB_FLAGC,
|
---|
23 | inout wire USB_PA0,
|
---|
24 | inout wire USB_PA1,
|
---|
25 | output wire USB_PA2,
|
---|
26 | inout wire USB_PA3,
|
---|
27 | output wire USB_PA4,
|
---|
28 | output wire USB_PA5,
|
---|
29 | output wire USB_PA6,
|
---|
30 | inout wire USB_PA7,
|
---|
31 | inout wire [7:0] USB_PB,
|
---|
32 |
|
---|
33 | output wire RAM_CLK,
|
---|
34 | output wire RAM_CE1,
|
---|
35 | output wire RAM_WE,
|
---|
36 | output wire [19:0] RAM_ADDR,
|
---|
37 | inout wire RAM_DQAP,
|
---|
38 | inout wire [7:0] RAM_DQA,
|
---|
39 | inout wire RAM_DQBP,
|
---|
40 | inout wire [7:0] RAM_DQB
|
---|
41 | );
|
---|
42 |
|
---|
43 | // Turn output ports off
|
---|
44 | /*
|
---|
45 | assign RAM_CLK = 1'b0;
|
---|
46 | assign RAM_CE1 = 1'b0;
|
---|
47 | assign RAM_WE = 1'b0;
|
---|
48 | assign RAM_ADDR = 20'h00000;
|
---|
49 | */
|
---|
50 | assign RAM_CLK = CLK_50MHz;
|
---|
51 | assign RAM_CE1 = 1'b0;
|
---|
52 |
|
---|
53 | // Turn inout ports to tri-state
|
---|
54 | assign TRG = 4'bz;
|
---|
55 | assign CON_A = 7'bz;
|
---|
56 | assign CON_B = 16'bz;
|
---|
57 | assign USB_PA0 = 1'bz;
|
---|
58 | assign USB_PA1 = 1'bz;
|
---|
59 | assign USB_PA3 = 1'bz;
|
---|
60 | assign USB_PA7 = 1'bz;
|
---|
61 | // assign RAM_DQAP = 1'bz;
|
---|
62 | // assign RAM_DQA = 8'bz;
|
---|
63 | // assign RAM_DQBP = 1'bz;
|
---|
64 | // assign RAM_DQB = 8'bz;
|
---|
65 |
|
---|
66 | assign USB_PA2 = ~usb_rden;
|
---|
67 | assign USB_PA4 = usb_addr[0];
|
---|
68 | assign USB_PA5 = usb_addr[1];
|
---|
69 | assign USB_PA6 = ~usb_pktend;
|
---|
70 |
|
---|
71 | wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
|
---|
72 | wire usb_aclr;
|
---|
73 | wire usb_tx_wrreq, usb_rx_rdreq;
|
---|
74 | wire usb_tx_full, usb_rx_empty;
|
---|
75 | wire [7:0] usb_tx_data, usb_rx_data;
|
---|
76 | wire [1:0] usb_addr;
|
---|
77 |
|
---|
78 | assign USB_SLRD = ~usb_rdreq;
|
---|
79 | assign USB_SLWR = ~usb_wrreq;
|
---|
80 |
|
---|
81 | usb_fifo usb_unit
|
---|
82 | (
|
---|
83 | .usb_clk(USB_IFCLK),
|
---|
84 | .usb_data(USB_PB),
|
---|
85 | .usb_full(~USB_FLAGB),
|
---|
86 | .usb_empty(~USB_FLAGA),
|
---|
87 | .usb_wrreq(usb_wrreq),
|
---|
88 | .usb_rdreq(usb_rdreq),
|
---|
89 | .usb_rden(usb_rden),
|
---|
90 | .usb_pktend(usb_pktend),
|
---|
91 | .usb_addr(usb_addr),
|
---|
92 |
|
---|
93 | .clk(CLK_50MHz),
|
---|
94 | .aclr(usb_aclr),
|
---|
95 |
|
---|
96 | .tx_full(usb_tx_full),
|
---|
97 | .tx_wrreq(usb_tx_wrreq),
|
---|
98 | .tx_data(usb_tx_data),
|
---|
99 |
|
---|
100 | .rx_empty(usb_rx_empty),
|
---|
101 | .rx_rdreq(usb_rx_rdreq),
|
---|
102 | .rx_q(usb_rx_data)
|
---|
103 | );
|
---|
104 |
|
---|
105 | reg ana_reset [3:0];
|
---|
106 | wire ana_peak_ready [3:0];
|
---|
107 | wire [11:0] ana_peak [3:0];
|
---|
108 |
|
---|
109 | reg osc_reset [3:0];
|
---|
110 | reg [9:0] osc_addr [3:0];
|
---|
111 | wire [9:0] osc_start_addr [3:0];
|
---|
112 | wire [15:0] osc_q [3:0];
|
---|
113 |
|
---|
114 | reg hst_reset [3:0];
|
---|
115 | reg [11:0] hst_addr [3:0];
|
---|
116 | wire [23:0] hst_q [3:0];
|
---|
117 |
|
---|
118 | wire mux_reset, mux_type;
|
---|
119 | wire [1:0] mux_chan, mux_byte;
|
---|
120 | wire [15:0] mux_addr;
|
---|
121 |
|
---|
122 | reg [7:0] mux_q;
|
---|
123 | reg [1:0] mux_max_byte;
|
---|
124 | reg [15:0] mux_min_addr, mux_max_addr;
|
---|
125 |
|
---|
126 | wire adc_clk [3:0];
|
---|
127 | wire adc_data_ready [3:0];
|
---|
128 | wire [11:0] adc_data [3:0];
|
---|
129 |
|
---|
130 | wire [11:0] raw_data [3:0];
|
---|
131 | wire [11:0] uwt_data [3:0];
|
---|
132 | wire [1:0] uwt_flag [3:0];
|
---|
133 |
|
---|
134 | wire [16:0] osc_thrs [3:0];
|
---|
135 | wire adc_pola [3:0];
|
---|
136 |
|
---|
137 | assign osc_thrs[0] = 16'd40;
|
---|
138 | assign osc_thrs[1] = 16'd300;
|
---|
139 | assign osc_thrs[2] = 16'd40;
|
---|
140 | assign osc_thrs[3] = 16'd1650;
|
---|
141 |
|
---|
142 | assign adc_pola[0] = 1'b1;
|
---|
143 | assign adc_pola[1] = 1'b1;
|
---|
144 | assign adc_pola[2] = 1'b1;
|
---|
145 | assign adc_pola[3] = 1'b0;
|
---|
146 |
|
---|
147 | assign adc_clk[0] = ADC_FCO;
|
---|
148 | assign adc_clk[1] = ADC_FCO;
|
---|
149 | assign adc_clk[2] = ADC_FCO;
|
---|
150 |
|
---|
151 | assign adc_clk[3] = ADC_FCO;
|
---|
152 | /*
|
---|
153 | assign adc_clk[3] = CON_CCLK[0];
|
---|
154 | assign adc_data[3] = CON_C[11:0];
|
---|
155 | */
|
---|
156 | adc_para adc_para_unit (
|
---|
157 | .lvds_dco(ADC_DCO),
|
---|
158 | .lvds_fco(ADC_FCO),
|
---|
159 | .para_data_ready(CON_CCLK[0]),
|
---|
160 | .para_data(CON_C[11:0]),
|
---|
161 | .adc_data(adc_data[3]));
|
---|
162 |
|
---|
163 | /*
|
---|
164 | wire adc_pll_clk;
|
---|
165 |
|
---|
166 | adc_pll adc_pll_unit(
|
---|
167 | .inclk0(ADC_FCO),
|
---|
168 | .c0(adc_pll_clk));
|
---|
169 | */
|
---|
170 | /*
|
---|
171 | wire tst_adc_clk;
|
---|
172 | wire [11:0] tst_adc_data;
|
---|
173 |
|
---|
174 | test test_unit(
|
---|
175 | .clk(CLK_50MHz),
|
---|
176 | .tst_clk(tst_adc_clk),
|
---|
177 | .tst_data(tst_adc_data));
|
---|
178 |
|
---|
179 | assign adc_clk[3] = tst_adc_clk;
|
---|
180 | assign adc_data[3] = tst_adc_data;
|
---|
181 | */
|
---|
182 | /*
|
---|
183 | altserial_flash_loader #(
|
---|
184 | .enable_shared_access("OFF"),
|
---|
185 | .enhanced_mode(1),
|
---|
186 | .intended_device_family("Cyclone III")) sfl_unit (
|
---|
187 | .noe(1'b0),
|
---|
188 | .asmi_access_granted(),
|
---|
189 | .asmi_access_request(),
|
---|
190 | .data0out(),
|
---|
191 | .dclkin(),
|
---|
192 | .scein(),
|
---|
193 | .sdoin());
|
---|
194 | */
|
---|
195 |
|
---|
196 | adc_lvds #(
|
---|
197 | .size(3),
|
---|
198 | .width(12)) adc_lvds_unit (
|
---|
199 | .lvds_dco(ADC_DCO),
|
---|
200 | // .lvds_dco(adc_pll_clk),
|
---|
201 | .lvds_fco(ADC_FCO),
|
---|
202 | .lvds_d(ADC_D),
|
---|
203 | .adc_data({ adc_data[0],
|
---|
204 | adc_data[1],
|
---|
205 | adc_data[2]}));
|
---|
206 |
|
---|
207 | genvar i;
|
---|
208 | generate
|
---|
209 | for (i = 1; i < 4; i = i + 1)
|
---|
210 | begin : MCA_CHAIN
|
---|
211 | adc_fifo adc_fifo_unit (
|
---|
212 | .adc_clk(adc_clk[i]),
|
---|
213 | .adc_data(adc_data[i]),
|
---|
214 | .polarity(adc_pola[i]),
|
---|
215 | .clk(CLK_50MHz),
|
---|
216 | .ready(adc_data_ready[i]),
|
---|
217 | .raw_data(raw_data[i]),
|
---|
218 | .uwt_data({uwt_flag[i], uwt_data[i]}));
|
---|
219 |
|
---|
220 | analyser analyser_unit (
|
---|
221 | .clk(CLK_50MHz),
|
---|
222 | .reset(ana_reset[i]),
|
---|
223 | .data_ready(adc_data_ready[i]),
|
---|
224 | .uwt_flag(uwt_flag[i]),
|
---|
225 | .uwt_data(uwt_data[i]),
|
---|
226 | .threshold(12'd10),
|
---|
227 | .peak_ready(ana_peak_ready[i]),
|
---|
228 | .peak(ana_peak[i]));
|
---|
229 |
|
---|
230 | histogram histogram_unit (
|
---|
231 | .clk(CLK_50MHz),
|
---|
232 | .reset(hst_reset[i]),
|
---|
233 | .data_ready(adc_data_ready[i]),
|
---|
234 | .data(raw_data[i]),
|
---|
235 | // .data(uwt_data[i]),
|
---|
236 | .address(hst_addr[i]),
|
---|
237 | .q(hst_q[i]));
|
---|
238 | /*
|
---|
239 | histogram histogram_unit (
|
---|
240 | .clk(CLK_50MHz),
|
---|
241 | .reset(hst_reset[i]),
|
---|
242 | .data_ready(ana_peak_ready[i]),
|
---|
243 | .data(ana_peak[i]),
|
---|
244 | .address(hst_addr[i]),
|
---|
245 | .q(hst_q[i]));
|
---|
246 | */
|
---|
247 | oscilloscope oscilloscope_unit (
|
---|
248 | .clk(CLK_50MHz),
|
---|
249 | .reset(osc_reset[i]),
|
---|
250 | .data_ready(adc_data_ready[i]),
|
---|
251 | .raw_data(raw_data[i]),
|
---|
252 | .uwt_data(uwt_data[i]),
|
---|
253 | .threshold(osc_thrs[i]),
|
---|
254 | .address(osc_addr[i]),
|
---|
255 | .start_address(osc_start_addr[i]),
|
---|
256 | .q(osc_q[i]));
|
---|
257 | end
|
---|
258 | endgenerate
|
---|
259 |
|
---|
260 | integer j;
|
---|
261 |
|
---|
262 | always @*
|
---|
263 | begin
|
---|
264 | for (j = 0; j < 4; j = j + 1)
|
---|
265 | begin
|
---|
266 | osc_reset[j] = 1'b0;
|
---|
267 | osc_addr[j] = 10'b0;
|
---|
268 | hst_reset[j] = 1'b0;
|
---|
269 | hst_addr[j] = 12'b0;
|
---|
270 | end
|
---|
271 |
|
---|
272 | case({mux_type, mux_chan})
|
---|
273 | 3'b000, 3'b001, 3'b010, 3'b011:
|
---|
274 | begin
|
---|
275 | osc_reset[mux_chan] = mux_reset;
|
---|
276 | osc_addr[mux_chan] = mux_addr[9:0];
|
---|
277 | mux_max_byte = 2'd1;
|
---|
278 | mux_min_addr = {6'd0, osc_start_addr[mux_chan]};
|
---|
279 | mux_max_addr = 16'd1023;
|
---|
280 | end
|
---|
281 |
|
---|
282 | 3'b100, 3'b101, 3'b110, 3'b111:
|
---|
283 | begin
|
---|
284 | hst_reset[mux_chan] = mux_reset;
|
---|
285 | hst_addr[mux_chan] = mux_addr[11:0];
|
---|
286 | mux_max_byte = 2'd2;
|
---|
287 | mux_min_addr = 16'd0;
|
---|
288 | mux_max_addr = 16'd4095;
|
---|
289 | end
|
---|
290 | endcase
|
---|
291 | end
|
---|
292 |
|
---|
293 | always @*
|
---|
294 | begin
|
---|
295 | case ({mux_type, mux_byte})
|
---|
296 | 3'b000: mux_q = osc_q[mux_chan][7:0];
|
---|
297 | 3'b001: mux_q = osc_q[mux_chan][15:8];
|
---|
298 |
|
---|
299 | 3'b100: mux_q = hst_q[mux_chan][7:0];
|
---|
300 | 3'b101: mux_q = hst_q[mux_chan][15:8];
|
---|
301 | 3'b110: mux_q = hst_q[mux_chan][23:16];
|
---|
302 |
|
---|
303 | default: mux_q = 8'd0;
|
---|
304 | endcase
|
---|
305 | end
|
---|
306 |
|
---|
307 | control control_unit (
|
---|
308 | .clk(CLK_50MHz),
|
---|
309 | .rx_empty(usb_rx_empty),
|
---|
310 | .tx_full(usb_tx_full),
|
---|
311 | .rx_data(usb_rx_data),
|
---|
312 | .mux_max_byte(mux_max_byte),
|
---|
313 | .mux_min_addr(mux_min_addr),
|
---|
314 | .mux_max_addr(mux_max_addr),
|
---|
315 | .mux_q(mux_q),
|
---|
316 | .mux_reset(mux_reset),
|
---|
317 | .mux_type(mux_type),
|
---|
318 | .mux_chan(mux_chan),
|
---|
319 | .mux_byte(mux_byte),
|
---|
320 | .mux_addr(mux_addr),
|
---|
321 | .rx_rdreq(usb_rx_rdreq),
|
---|
322 | .tx_wrreq(usb_tx_wrreq),
|
---|
323 | .tx_data(usb_tx_data),
|
---|
324 | .ram_we(RAM_WE),
|
---|
325 | .ram_addr(RAM_ADDR),
|
---|
326 | .ram_data({RAM_DQA, RAM_DQAP, RAM_DQB, RAM_DQBP}),
|
---|
327 | .led(LED));
|
---|
328 |
|
---|
329 | endmodule
|
---|