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
RevLine 
[27]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,
[41]15 input wire [2:0] ADC_D,
[27]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,
[30]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,
[27]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;
[30]54 assign USB_PA0 = 1'bz;
55 assign USB_PA1 = 1'bz;
56 assign USB_PA3 = 1'bz;
57 assign USB_PA7 = 1'bz;
[27]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
[30]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
[31]68 reg led_reg;
69 assign LED = led_reg;
[27]70
71 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend;
[35]72 wire usb_fifo_aclr;
[30]73 reg usb_fifo_tx_wrreq;
74 reg usb_fifo_rx_rdreq;
[27]75 wire usb_fifo_tx_full, usb_fifo_rx_empty;
[30]76 reg [7:0] usb_fifo_tx_data;
77 wire [7:0] usb_fifo_rx_data;
[27]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),
[34]94
[27]95 .clk(CLK_50MHz),
96 .aclr(usb_fifo_aclr),
[34]97
98 .tx_full(usb_fifo_tx_full),
99 .tx_wrreq((~usb_fifo_tx_full) & usb_fifo_tx_wrreq),
[27]100 .tx_data(usb_fifo_tx_data),
[34]101
[27]102 .rx_empty(usb_fifo_rx_empty),
[37]103 .rx_rdreq((~usb_fifo_rx_empty) & usb_fifo_rx_rdreq),
[35]104 .rx_q(usb_fifo_rx_data)
[27]105 );
106
[37]107 reg [23:0] rx_counter;
[35]108 reg [10:0] tst_counter;
109
[45]110 reg ana_reset [3:0];
111 wire ana_peak_ready [3:0];
112 wire [11:0] ana_peak [3:0];
[44]113
[45]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];
[44]118 reg [15:0] osc_q_mux;
119
[45]120 reg hst_reset [3:0];
121 reg [11:0] hst_addr [3:0];
122 wire [23:0] hst_q [3:0];
[27]123
[45]124 reg mux_reset, mux_type;
125 reg [1:0] mux_chan, mux_byte, mux_max_byte;
[48]126 reg [15:0] mux_addr, mux_min_addr, mux_max_addr, mux_num_addr;
[45]127 reg [7:0] mux_q;
[44]128
[45]129 reg [3:0] state1, state2;
[27]130 reg adc_fifo_aclr;
131
[45]132 wire adc_clk [3:0];
[41]133
134
[45]135 wire adc_data_ready [3:0];
136 wire [11:0] adc_data [3:0];
[41]137
[45]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;
[48]145/*
[45]146 assign adc_clk[3] = CON_B[0];
147 assign adc_data[3] = CON_B[12:1];
[48]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
[27]155 pll pll_unit(
156 .inclk0(CLK_50MHz),
[48]157 .c0(tst_adc_clk));
158
[41]159/*
[38]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());
[41]171*/
172 adc_lvds adc_lvds_unit (
173 .lvds_dco(ADC_DCO),
174 .lvds_fco(ADC_FCO),
175 .lvds_d(ADC_D),
[45]176 .adc_db(adc_data[0]),
177 .adc_dc(adc_data[1]),
178 .adc_dd(adc_data[2]));
[44]179
180 genvar i;
181 generate
[48]182 for (i = 2; i < 4; i = i + 1)
[44]183 begin : MCA_CHAIN
184 adc_fifo adc_fifo_unit (
[45]185 .adc_clk(adc_clk[i]),
186 .adc_data(adc_data[i]),
[44]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]}));
[27]192
[44]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
[27]230
[46]231 integer j;
232
[44]233 always @*
[27]234 begin
[46]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
[45]243 case({mux_type,mux_chan})
244 3'b000, 3'b001, 3'b010, 3'b011:
[27]245 begin
[45]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]};
[48]250 mux_num_addr = 16'd1023;
[27]251 end
[45]252
253 3'b100, 3'b101, 3'b110, 3'b111:
[27]254 begin
[45]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;
[48]259 mux_num_addr = 16'd4095;
[27]260 end
261 endcase
262 end
[45]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];
[35]269
[45]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
[30]279 always @(posedge CLK_50MHz)
280 begin
[37]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
[35]298 case(state1)
[30]299 1:
300 begin
[37]301 usb_fifo_rx_rdreq <= 1'b1;
[30]302 usb_fifo_tx_wrreq <= 1'b0;
[45]303 mux_type <= 1'b0;
304 mux_chan <= 2'd0;
305 mux_byte <= 2'd0;
306 mux_reset <= 1'b0;
[35]307 state1 <= 4'd2;
[30]308 end
309
310 2:
311 begin
312 if (~usb_fifo_rx_empty)
313 begin
314 case (usb_fifo_rx_data)
[45]315 8'h40, 8'h41, 8'h42, 8'h43, 8'h50, 8'h51, 8'h52, 8'h53:
[30]316 begin
[37]317 usb_fifo_rx_rdreq <= 1'b0;
[45]318 mux_type <= usb_fifo_rx_data[4];
319 mux_chan <= usb_fifo_rx_data[1:0];
320 mux_reset <= 1'b1;
[35]321 state1 <= 4'd1;
[30]322 end
[45]323
324 8'h60, 8'h61, 8'h62, 8'h63, 8'h70, 8'h71, 8'h72, 8'h73:
[30]325 begin
[37]326 usb_fifo_rx_rdreq <= 1'b0;
[45]327 mux_type <= usb_fifo_rx_data[4];
328 mux_chan <= usb_fifo_rx_data[1:0];
[35]329 state1 <= 4'd3;
[30]330 end
[45]331
[44]332 8'h30:
[35]333 begin
[37]334 usb_fifo_rx_rdreq <= 1'b0;
[35]335 state1 <= 4'd1;
336 end
[45]337
[44]338 8'h31:
[35]339 begin
[37]340 usb_fifo_rx_rdreq <= 1'b0;
[35]341 tst_counter <= 11'd0;
342 state1 <= 4'd9;
343 end
[30]344 endcase
345 end
346 end
[45]347 // mux transfer
[30]348 3:
349 begin
[45]350 mux_addr <= mux_min_addr;
[48]351 mux_max_addr <= mux_min_addr + mux_num_addr;
[45]352 mux_byte <= 2'd0;
[35]353 state1 <= 4'd4;
354 end
355 4:
356 begin
[45]357 usb_fifo_tx_data <= mux_q;
358 usb_fifo_tx_wrreq <= 1'b1;
359 mux_byte <= 2'd1;
360 state1 <= 4'd5;
[30]361 end
[34]362 5:
363 begin
364 if (~usb_fifo_tx_full)
365 begin
[45]366 usb_fifo_tx_data <= mux_q;
367 if ((mux_byte == mux_max_byte) && (mux_addr == mux_max_addr))
[30]368 begin
[45]369 state1 <= 4'd6;
[30]370 end
[35]371 else
[34]372 begin
[45]373 if (mux_byte == mux_max_byte)
[35]374 begin
[45]375 mux_addr <= mux_addr + 16'd1;
376 mux_byte <= 2'd0;
[35]377 end
[45]378 else
379 begin
380 mux_byte <= mux_byte + 2'd1;
381 end
[34]382 end
[30]383 end
384 end
[45]385 6:
[30]386 begin
[35]387 if (~usb_fifo_tx_full)
[30]388 begin
[35]389 usb_fifo_tx_wrreq <= 1'b0;
390 state1 <= 4'd1;
[30]391 end
[34]392 end
[35]393 // tst transfer
[45]394 7:
[34]395 begin
[35]396 usb_fifo_tx_data <= tst_counter;
[34]397 usb_fifo_tx_wrreq <= 1'b1;
[35]398 tst_counter <= tst_counter + 11'd1;
[45]399 state1 <= 4'd8;
[34]400 end
[45]401 8:
[34]402 begin
403 if (~usb_fifo_tx_full)
[30]404 begin
[35]405 usb_fifo_tx_data <= tst_counter;
[48]406 if (tst_counter == 11'd0)
[34]407 begin
[45]408 state1 <= 4'd9;
[34]409 end
410 else
411 begin
[35]412 tst_counter <= tst_counter + 11'd1;
[34]413 end
[30]414 end
415 end
[45]416 9:
[30]417 begin
[34]418 if (~usb_fifo_tx_full)
[30]419 begin
[34]420 usb_fifo_tx_wrreq <= 1'b0;
[35]421 state1 <= 4'd1;
[30]422 end
423 end
[35]424
425 default:
426 begin
427 state1 <= 4'd1;
428 end
[30]429 endcase
430 end
[48]431
432 always @ (posedge tst_adc_clk)
[27]433 begin
434 case (state2)
435 1:
436 begin
[48]437 tst_adc_data <= 12'd0;
[35]438 state2 <= 4'd2;
[27]439 end
440
441 2:
442 begin
[48]443 tst_adc_data <= 12'd1024;
[35]444 state2 <= 4'd3;
[27]445 end
446
447 3:
448 begin
[48]449 tst_adc_data <= 12'd2048;
[35]450 state2 <= 4'd4;
[27]451 end
452
453 4:
454 begin
[48]455 tst_adc_data <= 12'd3072;
[35]456 state2 <= 4'd5;
[27]457 end
458
459 5:
460 begin
[48]461 tst_adc_data <= 12'd4095;
[35]462 state2 <= 4'd1;
[27]463 end
464
465 default:
466 begin
[35]467 state2 <= 4'd1;
[27]468 end
469 endcase
470 end
[48]471
[27]472endmodule
Note: See TracBrowser for help on using the repository browser.