source: sandbox/MultiChannelUSB/Paella.v@ 147

Last change on this file since 147 was 145, checked in by demin, 14 years ago

adapt to the new card

File size: 11.0 KB
Line 
1module Paella
2 (
3 input wire CLK_100MHz,
4 output wire LED,
5
6 input wire ADC_DCO,
7 input wire ADC_FCO,
8 input wire [5:0] ADC_D,
9
10 output wire [1:0] SPI_SEL,
11 output wire SPI_SDO,
12 output wire SPI_CLK,
13 output wire ADC_RST,
14
15 output wire USB_SLRD,
16 output wire USB_SLWR,
17 input wire USB_IFCLK,
18 input wire USB_FLAGA, // EMPTY flag for EP6
19 input wire USB_FLAGB, // FULL flag for EP8
20 output wire USB_PA2,
21 output wire USB_PA4,
22 output wire USB_PA6,
23 inout wire [7:0] USB_PB,
24
25 output wire RAM_CLK,
26 output wire RAM_WE,
27 output wire [21:0] RAM_ADDR,
28 inout wire RAM_DQAP,
29 inout wire [7:0] RAM_DQA,
30 inout wire RAM_DQBP,
31 inout wire [7:0] RAM_DQB
32 );
33
34 localparam N = 12;
35
36 // Turn output ports off
37/*
38 assign RAM_CLK = 1'b0;
39 assign RAM_CE1 = 1'b0;
40 assign RAM_WE = 1'b0;
41 assign RAM_ADDR = 20'h00000;
42*/
43 assign ADC_RST = 1'b0;
44
45 assign RAM_CLK = sys_clock;
46
47 assign USB_PA2 = ~usb_rden;
48 assign USB_PA4 = usb_addr;
49 assign USB_PA6 = ~usb_pktend;
50
51 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
52 wire usb_tx_wrreq, usb_rx_rdreq;
53 wire usb_tx_full, usb_rx_empty;
54 wire [7:0] usb_tx_data, usb_rx_data;
55 wire usb_addr;
56
57 assign USB_SLRD = ~usb_rdreq;
58 assign USB_SLWR = ~usb_wrreq;
59
60 usb_fifo usb_unit
61 (
62 .usb_clock(USB_IFCLK),
63 .usb_data(USB_PB),
64 .usb_full(~USB_FLAGB),
65 .usb_empty(~USB_FLAGA),
66 .usb_wrreq(usb_wrreq),
67 .usb_rdreq(usb_rdreq),
68 .usb_rden(usb_rden),
69 .usb_pktend(usb_pktend),
70 .usb_addr(usb_addr),
71
72 .clock(sys_clock),
73
74 .tx_full(usb_tx_full),
75 .tx_wrreq(usb_tx_wrreq),
76 .tx_data(usb_tx_data),
77
78 .rx_empty(usb_rx_empty),
79 .rx_rdreq(usb_rx_rdreq),
80 .rx_q(usb_rx_data)
81 );
82
83 wire [11:0] osc_mux_data [4:0];
84
85 wire [11:0] trg_mux_data;
86 wire trg_flag;
87
88 wire [2:0] coi_data;
89 wire coi_flag;
90
91 wire [4*12-1:0] int_mux_data [N-1:0];
92
93 wire amp_flag1 [N-1:0];
94 wire [11:0] amp_data1 [N-1:0];
95
96 wire amp_flag2 [N-1:0];
97 wire [11:0] amp_data2 [N-1:0];
98
99 wire cnt_good [N-1:0];
100 wire [15:0] cnt_bits_wire;
101
102 wire sys_clock, sys_frame;
103
104 wire [11:0] adc_data [N-1:0];
105 wire [11:0] sys_data [N-1:0];
106 wire [11:0] tst_data;
107
108 wire [11:0] cmp_data;
109 wire [11:0] del_data;
110
111 wire [20:0] cic_data [N-1:0];
112
113 wire [11:0] dec_data [N-1:0];
114 wire [11:0] clp_data [N-1:0];
115 wire [11:0] tmp_data [1:0];
116
117 wire i2c_reset;
118/*
119 sys_pll sys_pll_unit(
120 .inclk0(CLK_100MHz),
121 .c0(sys_clock),
122 .c1(ADC_DCO),
123 .c2(ADC_FCO));
124
125 wire ADC_DCO, ADC_FCO;
126
127 test test_unit(
128 .clock(ADC_FCO),
129 .data(tst_data));
130
131 adc_lvds #(
132 .size(3),
133 .width(12)) adc_lvds_unit (
134 .clock(sys_clock),
135 .lvds_dco(ADC_DCO),
136 .lvds_fco(ADC_FCO),
137 .lvds_d(36'd0),
138 .test(tst_data),
139 .trig(12'd0),
140 .adc_frame(sys_frame),
141 .adc_data({cmp_data, adc_data[2], adc_data[1], adc_data[0]}));
142*/
143 sys_pll sys_pll_unit(
144 .inclk0(CLK_100MHz),
145 .c0(sys_clock));
146
147 adc_lvds #(
148 .size(6),
149 .width(24)) adc_lvds_unit (
150 .clock(sys_clock),
151 .lvds_dco(ADC_DCO),
152 .lvds_fco(ADC_FCO),
153 .lvds_d({ADC_D[5], ADC_D[4], ADC_D[3], ADC_D[2], ADC_D[1], ADC_D[0]}),
154 .adc_frame(sys_frame),
155 .adc_data({
156 adc_data[11], adc_data[10], adc_data[9], adc_data[8],
157 adc_data[7], adc_data[6], adc_data[5], adc_data[4],
158 adc_data[3], adc_data[2], adc_data[1], adc_data[0]}));
159
160 wire [15:0] cfg_bits [31:0];
161 wire [511:0] int_cfg_bits;
162
163 wire [39:0] cfg_mux_selector;
164
165 wire cfg_reset;
166
167 wire [12:0] bus_ssel;
168 wire bus_wren;
169 wire [31:0] bus_addr;
170 wire [15:0] bus_mosi;
171 wire [15:0] bus_miso [10:0];
172 wire [12:0] bus_busy;
173
174 wire [15:0] mrg_bus_miso;
175 wire mrg_bus_busy;
176
177 wire [12*16-1:0] int_bus_miso;
178
179 genvar j;
180
181 generate
182 for (j = 0; j < 32; j = j + 1)
183 begin : CONFIGURATION_OUTPUT
184 assign cfg_bits[j] = int_cfg_bits[j*16+15:j*16];
185 end
186 endgenerate
187
188 configuration configuration_unit (
189 .clock(sys_clock),
190 .reset(cfg_reset),
191 .bus_ssel(bus_ssel[0]),
192 .bus_wren(bus_wren),
193 .bus_addr(bus_addr[4:0]),
194 .bus_mosi(bus_mosi),
195 .bus_miso(bus_miso[0]),
196 .bus_busy(bus_busy[0]),
197 .cfg_bits(int_cfg_bits));
198
199 generate
200 for (j = 0; j < 12; j = j + 1)
201 begin : MUX_DATA
202 assign int_mux_data[j] = {
203 clp_data[j][11:0],
204 dec_data[j][11:0],
205 cic_data[j][19:8],
206 sys_data[j]};
207 end
208 endgenerate
209
210 assign cfg_mux_selector = {cfg_bits[4][7:0], cfg_bits[3], cfg_bits[2]};
211
212 lpm_mux #(
213 .lpm_size(4*12),
214 .lpm_type("LPM_MUX"),
215 .lpm_width(12),
216 .lpm_widths(6)) trg_mux_unit (
217 .sel(cfg_bits[4][13:8]),
218 .data({
219 int_mux_data[11], int_mux_data[10], int_mux_data[9], int_mux_data[8],
220 int_mux_data[7], int_mux_data[6], int_mux_data[5], int_mux_data[4],
221 int_mux_data[3], int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
222 .result(trg_mux_data));
223
224 generate
225 for (j = 0; j < 5; j = j + 1)
226 begin : OSC_CHAIN
227
228 lpm_mux #(
229 .lpm_size(4*12),
230 .lpm_type("LPM_MUX"),
231 .lpm_width(12),
232 .lpm_widths(6)) osc_mux_unit (
233 .sel(cfg_mux_selector[j*8+5:j*8]),
234 .data({
235 int_mux_data[11], int_mux_data[10], int_mux_data[9], int_mux_data[8],
236 int_mux_data[7], int_mux_data[6], int_mux_data[5], int_mux_data[4],
237 int_mux_data[3], int_mux_data[2], int_mux_data[1], int_mux_data[0]}),
238 .result(osc_mux_data[j]));
239 end
240 endgenerate
241
242 trigger trigger_unit (
243 .clock(sys_clock),
244 .frame(sys_frame),
245 .reset(cfg_bits[0][0]),
246 .cfg_data(cfg_bits[5][11:0]),
247 .trg_data(trg_mux_data),
248 .trg_flag(trg_flag));
249
250 oscilloscope oscilloscope_unit (
251 .clock(sys_clock),
252 .frame(sys_frame),
253 .reset(cfg_bits[0][1]),
254 .cfg_data(cfg_bits[5][12]),
255 .trg_flag(trg_flag),
256 .osc_data({cmp_data[3:0], osc_mux_data[4], osc_mux_data[3], osc_mux_data[2], osc_mux_data[1], osc_mux_data[0]}),
257 .ram_wren(RAM_WE),
258 .ram_addr(RAM_ADDR),
259 .ram_data({RAM_DQA, RAM_DQAP, RAM_DQB, RAM_DQBP}),
260 .bus_ssel(bus_ssel[1]),
261 .bus_wren(bus_wren),
262 .bus_addr(bus_addr[19:0]),
263 .bus_mosi(bus_mosi),
264 .bus_miso(bus_miso[1]),
265 .bus_busy(bus_busy[1]));
266
267 new_filter #(.size(12), .width(12)) filter_unit (
268 .clock(sys_clock),
269 .frame(sys_frame),
270 .reset(1'b0),
271 .inp_data({
272 sys_data[11], sys_data[10], sys_data[9], sys_data[08],
273 sys_data[7], sys_data[6], sys_data[5], sys_data[4],
274 sys_data[3], sys_data[2], sys_data[1], sys_data[0]}),
275 .out_data({
276 cic_data[11], cic_data[10], cic_data[9], cic_data[8],
277 cic_data[7], cic_data[6], cic_data[5], cic_data[4],
278 cic_data[3], cic_data[2], cic_data[1], cic_data[0]}));
279
280 generate
281 for (j = 0; j < 3; j = j + 1)
282 begin : DECONV_CHAIN
283
284 deconv #(.shift(22), .width(20), .widthr(12)) deconv_unit (
285 .clock(sys_clock),
286 .frame(sys_frame),
287 .reset(1'b0),
288 .del_data({6'd14, 6'd14, 6'd14, 6'd14}),
289 .amp_data({6'd17, 6'd17, 6'd17, 6'd17}),
290 .tau_data({16'd16320, 16'd16320, 16'd16320, 16'd16320}),
291// .del_data({cfg_bits[16][5:0], cfg_bits[15][13:8], cfg_bits[15][5:0]}),
292// .amp_data({cfg_bits[18][7:0], cfg_bits[17][15:8], cfg_bits[17][7:0]}),
293// .tau_data({cfg_bits[21], cfg_bits[20], cfg_bits[19]}),
294 .inp_data({
295 cic_data[j*4+3][19:0], cic_data[j*4+2][19:0],
296 cic_data[j*4+1][19:0], cic_data[j*4+0][19:0]}),
297 .out_data({
298 dec_data[j*4+3], dec_data[j*4+2],
299 dec_data[j*4+1], dec_data[j*4+0]}));
300
301
302 clip #(.shift(22), .width(20), .widthr(12)) clip_unit (
303 .clock(sys_clock),
304 .frame(sys_frame),
305 .reset(1'b0),
306 .del_data({6'd14, 6'd14, 6'd14, 6'd14}),
307 .amp_data({6'd17, 6'd17, 6'd17, 6'd17}),
308 .tau_data({16'd17166, 16'd17166, 16'd17166, 16'd17166}),
309 .inp_data({
310 cic_data[j*4+3][19:0], cic_data[j*4+2][19:0],
311 cic_data[j*4+1][19:0], cic_data[j*4+0][19:0]}),
312 .out_data({
313 clp_data[j*4+3], clp_data[j*4+2],
314 clp_data[j*4+1], clp_data[j*4+0]}));
315 end
316 endgenerate
317
318 generate
319 for (j = 0; j < 12; j = j + 1)
320 begin : MCA_CHAIN
321
322 assign sys_data[j] = (cfg_bits[1][j]) ? (adc_data[j] ^ 12'hfff) : (adc_data[j]);
323
324 amplitude #(.width(12)) amplitude_unit_1 (
325 .clock(sys_clock),
326 .frame(sys_frame),
327 .reset(cfg_bits[0][2+j]),
328 .cfg_data({1'b0, 12'd0, 12'd5}),
329// .cfg_data({cfg_bits[7+2*j][12:0], cfg_bits[6+2*j][11:0]}),
330 .inp_data(dec_data[j]),
331 .out_flag(amp_flag1[j]),
332 .out_data(amp_data1[j]));
333
334 amplitude #(.width(12)) amplitude_unit_2 (
335 .clock(sys_clock),
336 .frame(sys_frame),
337 .reset(cfg_bits[0][2+j]),
338 .cfg_data({1'b0, 12'd0, 12'd5}),
339// .cfg_data({cfg_bits[7+2*j][12:0], cfg_bits[6+2*j][11:0]}),
340// .inp_data(dec_data[j]),
341 .inp_data(clp_data[j]),
342 .out_flag(amp_flag2[j]),
343 .out_data(amp_data2[j]));
344 end
345 endgenerate
346
347 histogram32 histogram32_unit (
348 .clock(sys_clock),
349 .frame(sys_frame),
350 .reset(cfg_bits[0][5]),
351 .hst_good((amp_flag1[0]) & (cnt_good[0]) & (cfg_bits[13][1])),
352 .hst_data(amp_data1[0]),
353/*
354 .hst_good((amp_flag[j]) & (cnt_good[j]) & (cfg_bits[13][1])),
355 .hst_data(amp_data[j]),
356*/
357 .bus_ssel(bus_ssel[2]),
358 .bus_wren(bus_wren),
359 .bus_addr(bus_addr[12:0]),
360 .bus_mosi(bus_mosi),
361 .bus_miso(bus_miso[2]),
362 .bus_busy(bus_busy[2]));
363
364 counter hst_counter_unit (
365 .clock(sys_clock),
366// .frame((sys_frame) & (~ana_dead[0])),
367 .frame(sys_frame),
368 .reset(cfg_bits[0][8]),
369 .setup(cfg_bits[13][0]),
370 .count(cfg_bits[13][1]),
371 .bus_ssel(bus_ssel[5]),
372 .bus_wren(bus_wren),
373 .bus_addr(bus_addr[1:0]),
374 .bus_mosi(bus_mosi),
375 .bus_miso(bus_miso[5]),
376 .bus_busy(bus_busy[5]),
377 .cnt_good(cnt_good[0]));
378
379
380 i2c_fifo i2c_unit(
381 .clock(sys_clock),
382 .reset(i2c_reset),
383/*
384 normal connection
385 .i2c_sda(I2C_SDA),
386 .i2c_scl(I2C_SCL),
387
388 following is a cross wire connection for EPT
389*/
390 .i2c_sda(I2C_SCL),
391 .i2c_scl(I2C_SDA),
392
393 .bus_ssel(bus_ssel[11]),
394 .bus_wren(bus_wren),
395 .bus_mosi(bus_mosi),
396 .bus_busy(bus_busy[11]));
397
398 spi_fifo spi_unit(
399 .clock(sys_clock),
400 .reset(1'b0),
401 .spi_sel(SPI_SEL),
402 .spi_sdo(SPI_SDO),
403 .spi_clk(SPI_CLK),
404
405 .bus_ssel(bus_ssel[12]),
406 .bus_wren(bus_wren),
407 .bus_mosi(bus_mosi),
408 .bus_busy(bus_busy[12]));
409
410 generate
411 for (j = 0; j < 11; j = j + 1)
412 begin : BUS_OUTPUT
413 assign int_bus_miso[j*16+15:j*16] = bus_miso[j];
414 end
415 endgenerate
416
417 lpm_mux #(
418 .lpm_size(12),
419 .lpm_type("LPM_MUX"),
420 .lpm_width(16),
421 .lpm_widths(4)) bus_miso_mux_unit (
422 .sel(bus_addr[31:28]),
423 .data(int_bus_miso),
424 .result(mrg_bus_miso));
425
426 lpm_mux #(
427 .lpm_size(13),
428 .lpm_type("LPM_MUX"),
429 .lpm_width(1),
430 .lpm_widths(4)) bus_busy_mux_unit (
431 .sel(bus_addr[31:28]),
432 .data(bus_busy),
433 .result(mrg_bus_busy));
434
435 lpm_decode #(
436 .lpm_decodes(13),
437 .lpm_type("LPM_DECODE"),
438 .lpm_width(4)) lpm_decode_unit (
439 .data(bus_addr[31:28]),
440 .eq(bus_ssel));
441
442
443 control control_unit (
444 .clock(sys_clock),
445 .rx_empty(usb_rx_empty),
446 .tx_full(usb_tx_full),
447 .rx_data(usb_rx_data),
448 .rx_rdreq(usb_rx_rdreq),
449 .tx_wrreq(usb_tx_wrreq),
450 .tx_data(usb_tx_data),
451 .bus_wren(bus_wren),
452 .bus_addr(bus_addr),
453 .bus_mosi(bus_mosi),
454 .bus_miso(mrg_bus_miso),
455 .bus_busy(mrg_bus_busy),
456 .led(LED));
457
458/*
459 altserial_flash_loader #(
460 .enable_shared_access("OFF"),
461 .enhanced_mode(1),
462 .intended_device_family("Cyclone III")) sfl_unit (
463 .noe(1'b0),
464 .asmi_access_granted(),
465 .asmi_access_request(),
466 .data0out(),
467 .dclkin(),
468 .scein(),
469 .sdoin());
470*/
471
472endmodule
Note: See TracBrowser for help on using the repository browser.