- Timestamp:
- Sep 3, 2009, 2:34:23 PM (15 years ago)
- Location:
- trunk/MultiChannelUSB
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MultiChannelUSB/Paella.v
r27 r30 23 23 input wire USB_FLAGB, // FULL flag for EP8 24 24 input wire USB_FLAGC, 25 inout wire [7:0] USB_PA, 25 inout wire USB_PA0, 26 inout wire USB_PA1, 27 output wire USB_PA2, 28 inout wire USB_PA3, 29 output wire USB_PA4, 30 output wire USB_PA5, 31 output wire USB_PA6, 32 inout wire USB_PA7, 26 33 inout wire [7:0] USB_PB, 27 34 … … 47 54 assign CON_B = 16'bz; 48 55 assign CON_C = 13'bz; 49 assign USB_PA = {1'bz, ~usb_pktend, usb_addr, 1'bz, ~usb_rden, 2'bz}; 56 assign USB_PA0 = 1'bz; 57 assign USB_PA1 = 1'bz; 58 assign USB_PA3 = 1'bz; 59 assign USB_PA7 = 1'bz; 50 60 assign RAM_DQAP = 1'bz; 51 61 assign RAM_DQA = 8'bz; … … 53 63 assign RAM_DQB = 8'bz; 54 64 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 55 71 reg [31:0] counter; 56 assign LED = counter[24];57 // assign LED = usb_fifo_led;72 // assign LED = counter[24]; 73 assign LED = usb_fifo_rx_empty; 58 74 59 75 wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend; 60 76 wire usb_fifo_aclr, usb_fifo_led; 61 wire usb_fifo_tx_wrreq, usb_fifo_rx_rdreq; 77 reg usb_fifo_tx_wrreq; 78 reg usb_fifo_rx_rdreq; 62 79 wire usb_fifo_tx_full, usb_fifo_rx_empty; 63 wire [7:0] usb_fifo_tx_data, usb_fifo_rx_data; 80 reg [7:0] usb_fifo_tx_data; 81 wire [7:0] usb_fifo_rx_data; 64 82 wire [1:0] usb_addr; 65 83 … … 91 109 reg [9:0] osc_counter; 92 110 reg osc_reset; 93 reg osc_b it_num;111 reg osc_byte_num; 94 112 wire [9:0] osc_start_addr; 95 113 reg [9:0] osc_addr; … … 97 115 98 116 reg hst_reset; 99 reg [1:0] hst_b it_num;117 reg [1:0] hst_byte_num; 100 118 reg [11:0] hst_addr; 101 119 wire [31:0] hst_q; 102 120 103 reg [ 3:0] state0, state1, state2;121 reg [2:0] state0, state1, state2; 104 122 reg adc_fifo_rdreq; 105 123 wire adc_fifo_rdempty; … … 149 167 ); 150 168 151 169 /* 152 170 always @ (posedge adc_clk) 153 171 begin 154 172 counter <= counter + 32'd1; 155 173 end 174 */ 156 175 157 176 always @ (posedge CLK_50MHz) … … 162 181 if (~adc_fifo_rdempty) 163 182 begin 164 adc_counter <= adc_counter + 32'd1;183 // adc_counter <= adc_counter + 32'd1; 165 184 adc_fifo_rdreq <= 1'b1; 166 185 adc_data_ready <= 1'b1; 167 state0 <= 4'd2;186 state0 <= 3'd2; 168 187 end 169 188 end … … 173 192 adc_fifo_rdreq <= 1'b0; 174 193 adc_data_ready <= 1'b0; 175 state0 <= 4'd1;194 state0 <= 3'd1; 176 195 end 177 196 178 197 default: 179 198 begin 180 state0 <= 4'd1;199 state0 <= 3'd1; 181 200 end 182 201 endcase 183 202 end 184 203 204 always @(posedge CLK_50MHz) 205 begin 206 case (state1) 207 1: 208 begin 209 usb_fifo_rx_rdreq <= 1'b0; 210 usb_fifo_tx_wrreq <= 1'b0; 211 hst_reset <= 1'b0; 212 osc_reset <= 1'b0; 213 state1 <= 3'd2; 214 end 215 216 2: 217 begin 218 if (~usb_fifo_rx_empty) 219 begin 220 usb_fifo_rx_rdreq <= 1'b1; 221 case (usb_fifo_rx_data) 222 8'h30: 223 begin 224 hst_reset <= 1'b1; 225 state1 <= 3'd1; 226 end 227 8'h31: 228 begin 229 hst_addr <= 12'd0; 230 hst_byte_num <= 2'd0; 231 state1 <= 3'd3; 232 end 233 8'h32: 234 begin 235 osc_reset <= 1'b1; 236 state1 <= 3'd1; 237 end 238 8'h33: 239 begin 240 osc_addr <= osc_start_addr; 241 osc_counter <= 10'd0; 242 osc_byte_num <= 1'd0; 243 state1 <= 3'd4; 244 end 245 endcase 246 end 247 else 248 begin 249 usb_fifo_rx_rdreq <= 1'b0; 250 end 251 end 252 253 3: 254 begin 255 // hst transfer 256 if (~usb_fifo_tx_full) 257 begin 258 usb_fifo_tx_wrreq <= 1'b1; 259 260 case (hst_byte_num) 261 2'd0: usb_fifo_tx_data <= hst_q[7:0]; 262 2'd1: usb_fifo_tx_data <= hst_q[15:8]; 263 2'd2: usb_fifo_tx_data <= hst_q[23:16]; 264 2'd3: usb_fifo_tx_data <= hst_q[31:24]; 265 endcase 266 267 if (&hst_byte_num) 268 begin 269 hst_byte_num <= 2'd0; 270 if (&hst_addr) 271 begin 272 state1 <= 3'd1; 273 end 274 else 275 begin 276 hst_addr <= hst_addr + 12'd1; 277 end 278 end 279 else 280 begin 281 hst_byte_num <= hst_byte_num + 2'd1; 282 end 283 end 284 else 285 begin 286 usb_fifo_tx_wrreq <= 1'b0; 287 end 288 end 289 290 4: 291 begin 292 // osc transfer 293 if(~usb_fifo_tx_full) 294 begin 295 usb_fifo_tx_wrreq <= 1'b1; 296 297 case (osc_byte_num) 298 1'd0: usb_fifo_tx_data <= osc_q[7:0]; 299 1'd1: usb_fifo_tx_data <= osc_q[15:8]; 300 endcase 301 302 if (osc_byte_num) 303 begin 304 osc_byte_num <= 1'd0; 305 if (&osc_counter) 306 begin 307 state1 <= 3'd1; 308 end 309 else 310 begin 311 osc_addr <= osc_addr + 10'd1; 312 osc_counter <= osc_counter + 10'd1; 313 end 314 end 315 else 316 begin 317 osc_byte_num <= 1'd1; 318 end 319 end 320 else 321 begin 322 usb_fifo_tx_wrreq <= 1'b0; 323 end 324 end 325 326 default: 327 begin 328 // default state is the first one 329 state1 <= 3'd1; 330 end 331 endcase 332 end 333 /* 334 always @(posedge CLK_50MHz) 335 begin 336 case(state1) 337 0: 338 begin 339 usb_fifo_tx_wrreq <= 1'b0; 340 counter <= 32'd0; 341 state1 <= 3'd1; 342 end 343 1: 344 begin 345 if((~usb_fifo_tx_full) & (counter < 32'd512)) 346 begin 347 counter <= counter + 32'd1; 348 state1 <= 3'd2; 349 usb_fifo_tx_data <= 1; 350 usb_fifo_tx_wrreq <= 1'b1; 351 end 352 else 353 begin 354 usb_fifo_tx_wrreq <= 1'b0; 355 end 356 end 357 358 2: 359 begin 360 if((~usb_fifo_tx_full) & (counter < 32'd512)) 361 begin 362 counter <= counter + 32'd1; 363 state1 <= 3'd1; 364 usb_fifo_tx_data <= 0; 365 usb_fifo_tx_wrreq <= 1'b1; 366 end 367 else 368 begin 369 usb_fifo_tx_wrreq <= 1'b0; 370 end 371 end 372 373 default: state1 <= 3'd0; 374 endcase 375 end 376 */ 185 377 always @ (posedge adc_clk) 186 378 begin … … 189 381 begin 190 382 adc_data <= 12'd0; 191 state2 <= 4'd2;383 state2 <= 3'd2; 192 384 end 193 385 … … 195 387 begin 196 388 adc_data <= 12'd1024; 197 state2 <= 4'd3;389 state2 <= 3'd3; 198 390 end 199 391 … … 201 393 begin 202 394 adc_data <= 12'd2048; 203 state2 <= 4'd4;395 state2 <= 3'd4; 204 396 end 205 397 … … 207 399 begin 208 400 adc_data <= 12'd3072; 209 state2 <= 4'd5;401 state2 <= 3'd5; 210 402 end 211 403 … … 213 405 begin 214 406 adc_data <= 12'd4095; 215 state2 <= 4'd1;407 state2 <= 3'd1; 216 408 end 217 409 218 410 default: 219 411 begin 220 state2 <= 4'd1;412 state2 <= 3'd1; 221 413 end 222 414 endcase -
trunk/MultiChannelUSB/usb_fifo.v
r27 r30 13 13 output wire [7:0] rx_data 14 14 ); 15 16 localparam EPRD_ADDR = 2'b10; // 617 localparam EPWR_ADDR = 2'b11; // 818 15 19 16 // bidirectional data bus … … 24 21 assign usb_data = usb_wren ? usb_dataout : 8'bz; 25 22 26 wire tx_rdreq, tx_empty; 27 wire rx_wrreq, rx_full; 23 wire rx_full, tx_empty; 24 reg [8:0] byte_counter; 25 reg [4:0] idle_counter; 28 26 29 27 fifo32x8 fifo_tx_unit ( … … 31 29 .data(tx_data), 32 30 .rdclk(usb_clk), 33 .rdreq( tx_rdreq),31 .rdreq(usb_wrreq), 34 32 .wrclk(clk), 35 33 .wrreq(tx_wrreq), 36 .q(usb_dataout _bis),34 .q(usb_dataout), 37 35 .rdempty(tx_empty), 38 36 .wrfull(tx_full)); … … 44 42 .rdreq(rx_rdreq), 45 43 .wrclk(usb_clk), 46 .wrreq( rx_wrreq),44 .wrreq(usb_rdreq), 47 45 .q(rx_data), 48 46 .rdempty(rx_empty), 49 47 .wrfull(rx_full)); 50 51 reg [31:0] counter; 52 53 reg [2:0] state; 54 reg tx; 55 reg [7:0] dout; 56 57 always @(posedge usb_clk) 48 49 always @ (posedge usb_clk) 58 50 begin 59 case(state) 60 0: 61 begin 62 tx <= 1'b0; 63 counter <= 32'd0; 64 state <= 3'd1; 65 end 66 1: 67 begin 68 if((~usb_full) & (counter < 32'd512)) 69 begin 70 counter <= counter + 32'd1; 71 state <= 3'd2; 72 dout <= 1; 73 tx <= 1'b1; 74 end 75 else 76 begin 77 tx <= 1'b0; 78 end 79 end 80 81 2: 82 begin 83 if((~usb_full) & (counter < 32'd512)) 84 begin 85 counter <= counter + 32'd1; 86 state <= 3'd1; 87 dout <= 0; 88 tx <= 1'b1; 89 end 90 else 91 begin 92 tx <= 1'b0; 93 end 94 end 95 96 default: state <= 3'd0; 97 endcase 51 if (usb_pktend) 52 begin 53 byte_counter <= 9'd0; 54 idle_counter <= 5'd0; 55 end 56 else if (usb_wrreq) 57 begin 58 byte_counter <= byte_counter + 9'd1; 59 idle_counter <= 5'd0; 60 end 61 else if ((|byte_counter) & (tx_empty)) 62 begin 63 byte_counter <= byte_counter; 64 idle_counter <= idle_counter + 5'd1; 65 end 98 66 end 99 67 100 assign usb_ addr = 2'b11; // FIFO8101 assign usb_rdreq = 1'b0; // always TX for now 102 assign usb_ dataout = dout;103 assign usb_wrreq = tx;104 assign usb_ pktend = 1'b0;105 assign usb_ rden = 1'b0;106 assign usb_ wren = tx;68 assign usb_pktend = (&idle_counter); 69 // assign usb_pktend = 1'b0; 70 assign usb_rdreq = (~usb_empty) & (~rx_full); 71 assign usb_wrreq = (~usb_rdreq) & (~usb_full) & (~tx_empty); 72 assign usb_rden = usb_rdreq; 73 assign usb_wren = usb_wrreq; 74 assign usb_addr = usb_empty ? 2'b11 : 2'b10; 107 75 108 76 endmodule
Note:
See TracChangeset
for help on using the changeset viewer.