source: trunk/MultiChannelUSB/usb_fifo.v@ 28

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

initial commit

File size: 2.0 KB
RevLine 
[27]1module usb_fifo
2 (
3 input wire usb_clk,
4 inout wire [7:0] usb_data,
5 input wire usb_full, usb_empty,
6 output wire usb_wrreq, usb_rdreq, usb_rden, usb_pktend,
7 output wire [1:0] usb_addr,
8
9 input wire clk, aclr,
10 input wire tx_wrreq, rx_rdreq,
11 input wire [7:0] tx_data,
12 output wire tx_full, rx_empty,
13 output wire [7:0] rx_data
14 );
15
16 localparam EPRD_ADDR = 2'b10; // 6
17 localparam EPWR_ADDR = 2'b11; // 8
18
19 // bidirectional data bus
20 wire usb_wren;
21 wire [7:0] usb_datain = usb_data;
22 wire [7:0] usb_dataout;
23
24 assign usb_data = usb_wren ? usb_dataout : 8'bz;
25
26 wire tx_rdreq, tx_empty;
27 wire rx_wrreq, rx_full;
28
29 fifo32x8 fifo_tx_unit (
30 .aclr(aclr),
31 .data(tx_data),
32 .rdclk(usb_clk),
33 .rdreq(tx_rdreq),
34 .wrclk(clk),
35 .wrreq(tx_wrreq),
36 .q(usb_dataout_bis),
37 .rdempty(tx_empty),
38 .wrfull(tx_full));
39
40 fifo32x8 fifo_rx_unit (
41 .aclr(aclr),
42 .data(usb_datain),
43 .rdclk(clk),
44 .rdreq(rx_rdreq),
45 .wrclk(usb_clk),
46 .wrreq(rx_wrreq),
47 .q(rx_data),
48 .rdempty(rx_empty),
49 .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)
58 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
98 end
99
100 assign usb_addr = 2'b11; // FIFO8
101 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;
107
108endmodule
Note: See TracBrowser for help on using the repository browser.