source: trunk/MultiChannelUSB/usb_fifo.v@ 32

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

attemp to improve USB interface

File size: 3.0 KB
Line 
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 output wire led
15 );
16
17 // bidirectional data bus
18 reg int_addr, int_wren, int_rden, int_wrreq, int_rdreq;
19 wire [7:0] int_datain = usb_data;
20 wire [7:0] int_dataout;
21
22 assign usb_data = int_wren ? int_dataout : 8'bz;
23
24 wire rx_full, tx_empty;
25 wire rx_ready, tx_ready;
26 reg [8:0] byte_counter;
27 reg [4:0] idle_counter;
28
29 assign led = ~usb_empty;
30
31 fifo32x8 fifo_tx_unit (
32 .aclr(aclr),
33 .data(tx_data),
34 .rdclk(usb_clk),
35 .rdreq(int_wrreq),
36 .wrclk(clk),
37 .wrreq(tx_wrreq),
38 .q(int_dataout),
39 .rdempty(tx_empty),
40 .wrfull(tx_full));
41
42 fifo32x8 fifo_rx_unit (
43 .aclr(aclr),
44 .data(int_datain),
45 .rdclk(clk),
46 .rdreq(rx_rdreq),
47 .wrclk(usb_clk),
48 .wrreq(int_rdreq),
49 .q(rx_data),
50 .rdempty(rx_empty),
51 .wrfull(rx_full));
52
53 assign rx_ready = (~usb_empty) & (~rx_full);
54 assign tx_ready = (~usb_full) & (~tx_empty);
55
56 always @ (posedge usb_clk)
57 begin
58 casez ({rx_ready, tx_ready, int_addr, int_rden})
59 4'b00??: // idle
60 begin
61 int_addr <= 1'b0;
62 int_rden <= 1'b0;
63 int_wren <= 1'b0;
64 int_rdreq <= 1'b0;
65 int_wrreq <= 1'b0;
66 end
67 4'b1?1?: // set read addr
68 begin
69 int_addr <= 1'b0;
70 int_rden <= 1'b0;
71 int_wren <= 1'b0;
72 int_rdreq <= 1'b0;
73 int_wrreq <= 1'b0;
74 end
75 4'b1?00: // enable reads
76 begin
77 int_addr <= 1'b0;
78 int_rden <= 1'b1;
79 int_wren <= 1'b0;
80 int_rdreq <= 1'b0;
81 int_wrreq <= 1'b0;
82 end
83 4'b1?01: // read
84 begin
85 int_addr <= 1'b0;
86 int_rden <= 1'b1;
87 int_wren <= 1'b0;
88 int_rdreq <= 1'b1;
89 int_wrreq <= 1'b0;
90 end
91 4'b0101: // disable reads
92 begin
93 int_addr <= 1'b0;
94 int_rden <= 1'b0;
95 int_wren <= 1'b0;
96 int_rdreq <= 1'b0;
97 int_wrreq <= 1'b0;
98 end
99 4'b0100: // set write addr
100 begin
101 int_addr <= 1'b1;
102 int_rden <= 1'b0;
103 int_wren <= 1'b1;
104 int_rdreq <= 1'b0;
105 int_wrreq <= 1'b0;
106 end
107 4'b011?: // write
108 begin
109 int_addr <= 1'b1;
110 int_rden <= 1'b0;
111 int_wren <= 1'b1;
112 int_rdreq <= 1'b0;
113 int_wrreq <= 1'b1;
114 end
115 endcase
116/*
117 if (usb_pktend)
118 begin
119 byte_counter <= 9'd0;
120 idle_counter <= 5'd0;
121 end
122 else if (usb_wrreq)
123 begin
124 byte_counter <= byte_counter + 9'd1;
125 idle_counter <= 5'd0;
126 end
127 else if ((|byte_counter) & (tx_empty))
128 begin
129 byte_counter <= byte_counter;
130 idle_counter <= idle_counter + 5'd1;
131 end
132*/
133 end
134
135 assign usb_addr = {1'b1, int_addr};
136 assign usb_rden = int_rden;
137 assign usb_rdreq = int_rdreq;
138 assign usb_wrreq = int_wrreq;
139// assign usb_pktend = (&idle_counter);
140 assign usb_pktend = 1'b0;
141
142endmodule
Note: See TracBrowser for help on using the repository browser.