source: trunk/MultiChannelUSB/Paella.v@ 48

Last change on this file since 48 was 48, checked in by demin, 15 years ago

cleanup test circuit

File size: 9.6 KB
Line 
1module 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 inout 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 assign RAM_CLK = 1'b0;
45 assign RAM_CE1 = 1'b0;
46 assign RAM_WE = 1'b0;
47 assign RAM_ADDR = 20'h00000;
48
49 // Turn inout ports to tri-state
50 assign TRG = 4'bz;
51 assign CON_A = 7'bz;
52 assign CON_B = 16'bz;
53 assign CON_C = 13'bz;
54 assign USB_PA0 = 1'bz;
55 assign USB_PA1 = 1'bz;
56 assign USB_PA3 = 1'bz;
57 assign USB_PA7 = 1'bz;
58 assign RAM_DQAP = 1'bz;
59 assign RAM_DQA = 8'bz;
60 assign RAM_DQBP = 1'bz;
61 assign RAM_DQB = 8'bz;
62
63 assign USB_PA2 = ~usb_rden;
64 assign USB_PA4 = usb_addr[0];
65 assign USB_PA5 = usb_addr[1];
66 assign USB_PA6 = ~usb_pktend;
67
68 reg led_reg;
69 assign LED = led_reg;
70
71 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
72 wire usb_fifo_aclr;
73 reg usb_fifo_tx_wrreq;
74 reg usb_fifo_rx_rdreq;
75 wire usb_fifo_tx_full, usb_fifo_rx_empty;
76 reg [7:0] usb_fifo_tx_data;
77 wire [7:0] usb_fifo_rx_data;
78 wire [1:0] usb_addr;
79
80 assign USB_SLRD = ~usb_rdreq;
81 assign USB_SLWR = ~usb_wrreq;
82
83 usb_fifo usb_fifo_unit
84 (
85 .usb_clk(USB_IFCLK),
86 .usb_data(USB_PB),
87 .usb_full(~USB_FLAGB),
88 .usb_empty(~USB_FLAGA),
89 .usb_wrreq(usb_wrreq),
90 .usb_rdreq(usb_rdreq),
91 .usb_rden(usb_rden),
92 .usb_pktend(usb_pktend),
93 .usb_addr(usb_addr),
94
95 .clk(CLK_50MHz),
96 .aclr(usb_fifo_aclr),
97
98 .tx_full(usb_fifo_tx_full),
99 .tx_wrreq((~usb_fifo_tx_full) & usb_fifo_tx_wrreq),
100 .tx_data(usb_fifo_tx_data),
101
102 .rx_empty(usb_fifo_rx_empty),
103 .rx_rdreq((~usb_fifo_rx_empty) & usb_fifo_rx_rdreq),
104 .rx_q(usb_fifo_rx_data)
105 );
106
107 reg [23:0] rx_counter;
108 reg [10:0] tst_counter;
109
110 reg ana_reset [3:0];
111 wire ana_peak_ready [3:0];
112 wire [11:0] ana_peak [3:0];
113
114 reg osc_reset [3:0];
115 wire [9:0] osc_start_addr [3:0];
116 reg [9:0] osc_addr [3:0];
117 wire [15:0] osc_q [3:0];
118 reg [15:0] osc_q_mux;
119
120 reg hst_reset [3:0];
121 reg [11:0] hst_addr [3:0];
122 wire [23:0] hst_q [3:0];
123
124 reg mux_reset, mux_type;
125 reg [1:0] mux_chan, mux_byte, mux_max_byte;
126 reg [15:0] mux_addr, mux_min_addr, mux_max_addr, mux_num_addr;
127 reg [7:0] mux_q;
128
129 reg [3:0] state1, state2;
130 reg adc_fifo_aclr;
131
132 wire adc_clk [3:0];
133
134
135 wire adc_data_ready [3:0];
136 wire [11:0] adc_data [3:0];
137
138 wire [11:0] raw_data [3:0];
139 wire [11:0] uwt_data [3:0];
140 wire [1:0] uwt_flag [3:0];
141
142 assign adc_clk[0] = ADC_FCO;
143 assign adc_clk[1] = ADC_FCO;
144 assign adc_clk[2] = ADC_FCO;
145/*
146 assign adc_clk[3] = CON_B[0];
147 assign adc_data[3] = CON_B[12:1];
148*/
149 wire tst_adc_clk;
150 reg [11:0] tst_adc_data;
151
152 assign adc_clk[3] = tst_adc_clk;
153 assign adc_data[3] = tst_adc_data;
154
155 pll pll_unit(
156 .inclk0(CLK_50MHz),
157 .c0(tst_adc_clk));
158
159/*
160 altserial_flash_loader #(
161 .enable_shared_access("OFF"),
162 .enhanced_mode(1),
163 .intended_device_family("Cyclone III")) sfl_unit (
164 .noe(1'b0),
165 .asmi_access_granted(),
166 .asmi_access_request(),
167 .data0out(),
168 .dclkin(),
169 .scein(),
170 .sdoin());
171*/
172 adc_lvds adc_lvds_unit (
173 .lvds_dco(ADC_DCO),
174 .lvds_fco(ADC_FCO),
175 .lvds_d(ADC_D),
176 .adc_db(adc_data[0]),
177 .adc_dc(adc_data[1]),
178 .adc_dd(adc_data[2]));
179
180 genvar i;
181 generate
182 for (i = 2; i < 4; i = i + 1)
183 begin : MCA_CHAIN
184 adc_fifo adc_fifo_unit (
185 .adc_clk(adc_clk[i]),
186 .adc_data(adc_data[i]),
187 .aclr(adc_fifo_aclr),
188 .rdclk(CLK_50MHz),
189 .ready(adc_data_ready[i]),
190 .raw_data(raw_data[i]),
191 .uwt_data({uwt_flag[i], uwt_data[i]}));
192
193 analyser analyser_unit (
194 .clk(CLK_50MHz),
195 .reset(ana_reset[i]),
196 .data_ready(adc_data_ready[i]),
197 .uwt_flag(uwt_flag[i]),
198 .uwt_data(uwt_data[i]),
199 .peak_ready(ana_peak_ready[i]),
200 .peak(ana_peak[i]));
201/*
202 histogram histogram_unit (
203 .clk(CLK_50MHz),
204 .reset(hst_reset[i]),
205 .data_ready(adc_data_ready[i]),
206 .data(raw_data[i]),
207 .address(hst_addr[i]),
208 .q(hst_q[i]));
209*/
210 histogram histogram_unit (
211 .clk(CLK_50MHz),
212 .reset(hst_reset[i]),
213 .data_ready(ana_peak_ready[i]),
214 .data(ana_peak[i]),
215 .address(hst_addr[i]),
216 .q(hst_q[i]));
217
218 oscilloscope oscilloscope_unit (
219 .clk(CLK_50MHz),
220 .reset(osc_reset[i]),
221 .data_ready(adc_data_ready[i]),
222 .raw_data(raw_data[i]),
223 .uwt_data(uwt_data[i]),
224 .threshold(16'd100),
225 .address(osc_addr[i]),
226 .start_address(osc_start_addr[i]),
227 .q(osc_q[i]));
228 end
229 endgenerate
230
231 integer j;
232
233 always @*
234 begin
235 for (j = 0; j < 4; j = j + 1)
236 begin
237 osc_reset[j] = 1'b0;
238 osc_addr[j] = 10'b0;
239 hst_reset[j] = 1'b0;
240 hst_addr[j] = 12'b0;
241 end
242
243 case({mux_type,mux_chan})
244 3'b000, 3'b001, 3'b010, 3'b011:
245 begin
246 osc_reset[mux_chan] = mux_reset;
247 osc_addr[mux_chan] = mux_addr[9:0];
248 mux_max_byte = 2'd1;
249 mux_min_addr = {6'd0, osc_start_addr[mux_chan]};
250 mux_num_addr = 16'd1023;
251 end
252
253 3'b100, 3'b101, 3'b110, 3'b111:
254 begin
255 hst_reset[mux_chan] = mux_reset;
256 hst_addr[mux_chan] = mux_addr[11:0];
257 mux_max_byte = 2'd2;
258 mux_min_addr = 16'd0;
259 mux_num_addr = 16'd4095;
260 end
261 endcase
262 end
263
264 always @*
265 begin
266 case ({mux_type,mux_byte})
267 5'b000: mux_q = osc_q[mux_chan][7:0];
268 5'b001: mux_q = osc_q[mux_chan][15:8];
269
270 5'b100: mux_q = hst_q[mux_chan][7:0];
271 5'b101: mux_q = hst_q[mux_chan][15:8];
272 5'b110: mux_q = hst_q[mux_chan][23:16];
273
274 default: mux_q = 8'd0;
275 endcase
276 end
277
278
279 always @(posedge CLK_50MHz)
280 begin
281 if (~usb_fifo_rx_empty)
282 begin
283 led_reg <= 1'b0;
284 rx_counter <= 24'd0;
285 end
286 else
287 begin
288 if (&rx_counter)
289 begin
290 led_reg <= 1'b1;
291 end
292 else
293 begin
294 rx_counter <= rx_counter + 24'd1;
295 end
296 end
297
298 case(state1)
299 1:
300 begin
301 usb_fifo_rx_rdreq <= 1'b1;
302 usb_fifo_tx_wrreq <= 1'b0;
303 mux_type <= 1'b0;
304 mux_chan <= 2'd0;
305 mux_byte <= 2'd0;
306 mux_reset <= 1'b0;
307 state1 <= 4'd2;
308 end
309
310 2:
311 begin
312 if (~usb_fifo_rx_empty)
313 begin
314 case (usb_fifo_rx_data)
315 8'h40, 8'h41, 8'h42, 8'h43, 8'h50, 8'h51, 8'h52, 8'h53:
316 begin
317 usb_fifo_rx_rdreq <= 1'b0;
318 mux_type <= usb_fifo_rx_data[4];
319 mux_chan <= usb_fifo_rx_data[1:0];
320 mux_reset <= 1'b1;
321 state1 <= 4'd1;
322 end
323
324 8'h60, 8'h61, 8'h62, 8'h63, 8'h70, 8'h71, 8'h72, 8'h73:
325 begin
326 usb_fifo_rx_rdreq <= 1'b0;
327 mux_type <= usb_fifo_rx_data[4];
328 mux_chan <= usb_fifo_rx_data[1:0];
329 state1 <= 4'd3;
330 end
331
332 8'h30:
333 begin
334 usb_fifo_rx_rdreq <= 1'b0;
335 state1 <= 4'd1;
336 end
337
338 8'h31:
339 begin
340 usb_fifo_rx_rdreq <= 1'b0;
341 tst_counter <= 11'd0;
342 state1 <= 4'd9;
343 end
344 endcase
345 end
346 end
347 // mux transfer
348 3:
349 begin
350 mux_addr <= mux_min_addr;
351 mux_max_addr <= mux_min_addr + mux_num_addr;
352 mux_byte <= 2'd0;
353 state1 <= 4'd4;
354 end
355 4:
356 begin
357 usb_fifo_tx_data <= mux_q;
358 usb_fifo_tx_wrreq <= 1'b1;
359 mux_byte <= 2'd1;
360 state1 <= 4'd5;
361 end
362 5:
363 begin
364 if (~usb_fifo_tx_full)
365 begin
366 usb_fifo_tx_data <= mux_q;
367 if ((mux_byte == mux_max_byte) && (mux_addr == mux_max_addr))
368 begin
369 state1 <= 4'd6;
370 end
371 else
372 begin
373 if (mux_byte == mux_max_byte)
374 begin
375 mux_addr <= mux_addr + 16'd1;
376 mux_byte <= 2'd0;
377 end
378 else
379 begin
380 mux_byte <= mux_byte + 2'd1;
381 end
382 end
383 end
384 end
385 6:
386 begin
387 if (~usb_fifo_tx_full)
388 begin
389 usb_fifo_tx_wrreq <= 1'b0;
390 state1 <= 4'd1;
391 end
392 end
393 // tst transfer
394 7:
395 begin
396 usb_fifo_tx_data <= tst_counter;
397 usb_fifo_tx_wrreq <= 1'b1;
398 tst_counter <= tst_counter + 11'd1;
399 state1 <= 4'd8;
400 end
401 8:
402 begin
403 if (~usb_fifo_tx_full)
404 begin
405 usb_fifo_tx_data <= tst_counter;
406 if (tst_counter == 11'd0)
407 begin
408 state1 <= 4'd9;
409 end
410 else
411 begin
412 tst_counter <= tst_counter + 11'd1;
413 end
414 end
415 end
416 9:
417 begin
418 if (~usb_fifo_tx_full)
419 begin
420 usb_fifo_tx_wrreq <= 1'b0;
421 state1 <= 4'd1;
422 end
423 end
424
425 default:
426 begin
427 state1 <= 4'd1;
428 end
429 endcase
430 end
431
432 always @ (posedge tst_adc_clk)
433 begin
434 case (state2)
435 1:
436 begin
437 tst_adc_data <= 12'd0;
438 state2 <= 4'd2;
439 end
440
441 2:
442 begin
443 tst_adc_data <= 12'd1024;
444 state2 <= 4'd3;
445 end
446
447 3:
448 begin
449 tst_adc_data <= 12'd2048;
450 state2 <= 4'd4;
451 end
452
453 4:
454 begin
455 tst_adc_data <= 12'd3072;
456 state2 <= 4'd5;
457 end
458
459 5:
460 begin
461 tst_adc_data <= 12'd4095;
462 state2 <= 4'd1;
463 end
464
465 default:
466 begin
467 state2 <= 4'd1;
468 end
469 endcase
470 end
471
472endmodule
Note: See TracBrowser for help on using the repository browser.