1 |
746 |
lampret |
//////////////////////////////////////////////////////////////////////
|
2 |
|
|
//// ////
|
3 |
|
|
//// uart_wb.v ////
|
4 |
|
|
//// ////
|
5 |
|
|
//// ////
|
6 |
|
|
//// This file is part of the "UART 16550 compatible" project ////
|
7 |
|
|
//// http://www.opencores.org/cores/uart16550/ ////
|
8 |
|
|
//// ////
|
9 |
|
|
//// Documentation related to this project: ////
|
10 |
|
|
//// - http://www.opencores.org/cores/uart16550/ ////
|
11 |
|
|
//// ////
|
12 |
|
|
//// Projects compatibility: ////
|
13 |
|
|
//// - WISHBONE ////
|
14 |
|
|
//// RS232 Protocol ////
|
15 |
|
|
//// 16550D uart (mostly supported) ////
|
16 |
|
|
//// ////
|
17 |
|
|
//// Overview (main Features): ////
|
18 |
|
|
//// UART core WISHBONE interface. ////
|
19 |
|
|
//// ////
|
20 |
|
|
//// Known problems (limits): ////
|
21 |
|
|
//// Inserts one wait state on all transfers. ////
|
22 |
|
|
//// Note affected signals and the way they are affected. ////
|
23 |
|
|
//// ////
|
24 |
|
|
//// To Do: ////
|
25 |
|
|
//// Nothing. ////
|
26 |
|
|
//// ////
|
27 |
|
|
//// Author(s): ////
|
28 |
|
|
//// - gorban@opencores.org ////
|
29 |
|
|
//// - Jacob Gorban ////
|
30 |
|
|
//// - Igor Mohor (igorm@opencores.org) ////
|
31 |
|
|
//// ////
|
32 |
|
|
//// Created: 2001/05/12 ////
|
33 |
|
|
//// Last Updated: 2001/05/17 ////
|
34 |
|
|
//// (See log for the revision history) ////
|
35 |
|
|
//// ////
|
36 |
|
|
//// ////
|
37 |
|
|
//////////////////////////////////////////////////////////////////////
|
38 |
|
|
//// ////
|
39 |
|
|
//// Copyright (C) 2000, 2001 Authors ////
|
40 |
|
|
//// ////
|
41 |
|
|
//// This source file may be used and distributed without ////
|
42 |
|
|
//// restriction provided that this copyright statement is not ////
|
43 |
|
|
//// removed from the file and that any derivative work contains ////
|
44 |
|
|
//// the original copyright notice and the associated disclaimer. ////
|
45 |
|
|
//// ////
|
46 |
|
|
//// This source file is free software; you can redistribute it ////
|
47 |
|
|
//// and/or modify it under the terms of the GNU Lesser General ////
|
48 |
|
|
//// Public License as published by the Free Software Foundation; ////
|
49 |
|
|
//// either version 2.1 of the License, or (at your option) any ////
|
50 |
|
|
//// later version. ////
|
51 |
|
|
//// ////
|
52 |
|
|
//// This source is distributed in the hope that it will be ////
|
53 |
|
|
//// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
54 |
|
|
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
55 |
|
|
//// PURPOSE. See the GNU Lesser General Public License for more ////
|
56 |
|
|
//// details. ////
|
57 |
|
|
//// ////
|
58 |
|
|
//// You should have received a copy of the GNU Lesser General ////
|
59 |
|
|
//// Public License along with this source; if not, download it ////
|
60 |
|
|
//// from http://www.opencores.org/lgpl.shtml ////
|
61 |
|
|
//// ////
|
62 |
|
|
//////////////////////////////////////////////////////////////////////
|
63 |
|
|
//
|
64 |
|
|
// CVS Revision History
|
65 |
|
|
//
|
66 |
|
|
// $Log: not supported by cvs2svn $
|
67 |
|
|
// Revision 1.14 2002/02/19 16:56:06 mohor
|
68 |
|
|
// Endian define added. Big Byte Endian is selected by default.
|
69 |
|
|
//
|
70 |
|
|
// Revision 1.13 2002/02/07 16:20:20 gorban
|
71 |
|
|
// major bug in 32-bit mode that prevented register access fixed.
|
72 |
|
|
//
|
73 |
|
|
// Revision 1.12 2001/12/19 08:03:34 mohor
|
74 |
|
|
// Warnings cleared.
|
75 |
|
|
//
|
76 |
|
|
// Revision 1.11 2001/12/06 14:51:04 gorban
|
77 |
|
|
// Bug in LSR[0] is fixed.
|
78 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
79 |
|
|
//
|
80 |
|
|
// Revision 1.10 2001/12/03 21:44:29 gorban
|
81 |
|
|
// Updated specification documentation.
|
82 |
|
|
// Added full 32-bit data bus interface, now as default.
|
83 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
84 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
85 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
86 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
87 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
88 |
|
|
//
|
89 |
|
|
// Revision 1.9 2001/10/20 09:58:40 gorban
|
90 |
|
|
// Small synopsis fixes
|
91 |
|
|
//
|
92 |
|
|
// Revision 1.8 2001/08/24 21:01:12 mohor
|
93 |
|
|
// Things connected to parity changed.
|
94 |
|
|
// Clock devider changed.
|
95 |
|
|
//
|
96 |
|
|
// Revision 1.7 2001/08/23 16:05:05 mohor
|
97 |
|
|
// Stop bit bug fixed.
|
98 |
|
|
// Parity bug fixed.
|
99 |
|
|
// WISHBONE read cycle bug fixed,
|
100 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
101 |
|
|
// PE indicator (Parity Error) bug fixed.
|
102 |
|
|
// Register read bug fixed.
|
103 |
|
|
//
|
104 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
105 |
|
|
// FIFO changes and other corrections.
|
106 |
|
|
//
|
107 |
|
|
// Revision 1.3 2001/05/21 19:12:01 gorban
|
108 |
|
|
// Corrected some Linter messages.
|
109 |
|
|
//
|
110 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
111 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
112 |
|
|
//
|
113 |
|
|
// Revision 1.0 2001-05-17 21:27:13+02 jacob
|
114 |
|
|
// Initial revision
|
115 |
|
|
//
|
116 |
|
|
//
|
117 |
|
|
|
118 |
|
|
// UART core WISHBONE interface
|
119 |
|
|
//
|
120 |
|
|
// Author: Jacob Gorban (jacob.gorban@flextronicssemi.com)
|
121 |
|
|
// Company: Flextronics Semiconductor
|
122 |
|
|
//
|
123 |
|
|
|
124 |
|
|
// synopsys translate_off
|
125 |
|
|
`include "timescale.v"
|
126 |
|
|
// synopsys translate_on
|
127 |
|
|
`include "uart_defines.v"
|
128 |
|
|
|
129 |
|
|
module uart_wb (clk, wb_rst_i,
|
130 |
|
|
wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_adr_i,
|
131 |
|
|
wb_adr_int, wb_dat_i, wb_dat_o, wb_dat8_i, wb_dat8_o, wb_dat32_o, wb_sel_i,
|
132 |
|
|
we_o, re_o // Write and read enable output for the core
|
133 |
|
|
);
|
134 |
|
|
|
135 |
|
|
input clk;
|
136 |
|
|
|
137 |
|
|
// WISHBONE interface
|
138 |
|
|
input wb_rst_i;
|
139 |
|
|
input wb_we_i;
|
140 |
|
|
input wb_stb_i;
|
141 |
|
|
input wb_cyc_i;
|
142 |
|
|
input [3:0] wb_sel_i;
|
143 |
|
|
input [`UART_ADDR_WIDTH-1:0] wb_adr_i; //WISHBONE address line
|
144 |
|
|
|
145 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
146 |
|
|
input [7:0] wb_dat_i; //input WISHBONE bus
|
147 |
|
|
output [7:0] wb_dat_o;
|
148 |
|
|
reg [7:0] wb_dat_o;
|
149 |
|
|
wire [7:0] wb_dat_i;
|
150 |
|
|
reg [7:0] wb_dat_is;
|
151 |
|
|
`else // for 32 data bus mode
|
152 |
|
|
input [31:0] wb_dat_i; //input WISHBONE bus
|
153 |
|
|
output [31:0] wb_dat_o;
|
154 |
|
|
reg [31:0] wb_dat_o;
|
155 |
|
|
wire [31:0] wb_dat_i;
|
156 |
|
|
reg [31:0] wb_dat_is;
|
157 |
|
|
`endif // !`ifdef DATA_BUS_WIDTH_8
|
158 |
|
|
|
159 |
|
|
output [`UART_ADDR_WIDTH-1:0] wb_adr_int; // internal signal for address bus
|
160 |
|
|
input [7:0] wb_dat8_o; // internal 8 bit output to be put into wb_dat_o
|
161 |
|
|
output [7:0] wb_dat8_i;
|
162 |
|
|
input [31:0] wb_dat32_o; // 32 bit data output (for debug interface)
|
163 |
|
|
output wb_ack_o;
|
164 |
|
|
output we_o;
|
165 |
|
|
output re_o;
|
166 |
|
|
|
167 |
|
|
wire we_o;
|
168 |
|
|
reg wb_ack_o;
|
169 |
|
|
reg [7:0] wb_dat8_i;
|
170 |
|
|
wire [7:0] wb_dat8_o;
|
171 |
|
|
wire [`UART_ADDR_WIDTH-1:0] wb_adr_int; // internal signal for address bus
|
172 |
|
|
reg [`UART_ADDR_WIDTH-1:0] wb_adr_is;
|
173 |
|
|
reg wb_we_is;
|
174 |
|
|
reg wb_cyc_is;
|
175 |
|
|
reg wb_stb_is;
|
176 |
|
|
reg [3:0] wb_sel_is;
|
177 |
|
|
wire [3:0] wb_sel_i;
|
178 |
|
|
reg wre ;// timing control signal for write or read enable
|
179 |
|
|
|
180 |
|
|
// wb_ack_o FSM
|
181 |
|
|
reg [1:0] wbstate;
|
182 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
183 |
|
|
if (wb_rst_i) begin
|
184 |
|
|
wb_ack_o <= #1 1'b0;
|
185 |
|
|
wbstate <= #1 0;
|
186 |
|
|
wre <= #1 1'b1;
|
187 |
|
|
end else
|
188 |
|
|
case (wbstate)
|
189 |
|
|
0: begin
|
190 |
|
|
if (wb_stb_is & wb_cyc_is) begin
|
191 |
|
|
wre <= #1 0;
|
192 |
|
|
wbstate <= #1 1;
|
193 |
|
|
wb_ack_o <= #1 1;
|
194 |
|
|
end else begin
|
195 |
|
|
wre <= #1 1;
|
196 |
|
|
wb_ack_o <= #1 0;
|
197 |
|
|
end
|
198 |
|
|
end
|
199 |
|
|
1: begin
|
200 |
|
|
wb_ack_o <= #1 0;
|
201 |
|
|
wbstate <= #1 2;
|
202 |
|
|
wre <= #1 0;
|
203 |
|
|
end
|
204 |
|
|
2,3: begin
|
205 |
|
|
wb_ack_o <= #1 0;
|
206 |
|
|
wbstate <= #1 0;
|
207 |
|
|
wre <= #1 0;
|
208 |
|
|
end
|
209 |
|
|
endcase
|
210 |
|
|
|
211 |
|
|
assign we_o = wb_we_is & wb_stb_is & wb_cyc_is & wre ; //WE for registers
|
212 |
|
|
assign re_o = ~wb_we_is & wb_stb_is & wb_cyc_is & wre ; //RE for registers
|
213 |
|
|
|
214 |
|
|
// Sample input signals
|
215 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
216 |
|
|
if (wb_rst_i) begin
|
217 |
|
|
wb_adr_is <= #1 0;
|
218 |
|
|
wb_we_is <= #1 0;
|
219 |
|
|
wb_cyc_is <= #1 0;
|
220 |
|
|
wb_stb_is <= #1 0;
|
221 |
|
|
wb_dat_is <= #1 0;
|
222 |
|
|
wb_sel_is <= #1 0;
|
223 |
|
|
end else begin
|
224 |
|
|
wb_adr_is <= #1 wb_adr_i;
|
225 |
|
|
wb_we_is <= #1 wb_we_i;
|
226 |
|
|
wb_cyc_is <= #1 wb_cyc_i;
|
227 |
|
|
wb_stb_is <= #1 wb_stb_i;
|
228 |
|
|
wb_dat_is <= #1 wb_dat_i;
|
229 |
|
|
wb_sel_is <= #1 wb_sel_i;
|
230 |
|
|
end
|
231 |
|
|
|
232 |
|
|
`ifdef DATA_BUS_WIDTH_8 // 8-bit data bus
|
233 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
234 |
|
|
if (wb_rst_i)
|
235 |
|
|
wb_dat_o <= #1 0;
|
236 |
|
|
else
|
237 |
|
|
wb_dat_o <= #1 wb_dat8_o;
|
238 |
|
|
|
239 |
|
|
always @(wb_dat_is)
|
240 |
|
|
wb_dat8_i = wb_dat_is;
|
241 |
|
|
|
242 |
|
|
assign wb_adr_int = wb_adr_is;
|
243 |
|
|
|
244 |
|
|
`else // 32-bit bus
|
245 |
|
|
// put output to the correct byte in 32 bits using select line
|
246 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
247 |
|
|
if (wb_rst_i)
|
248 |
|
|
wb_dat_o <= #1 0;
|
249 |
|
|
else if (re_o)
|
250 |
|
|
case (wb_sel_is)
|
251 |
|
|
4'b0001: wb_dat_o <= #1 {24'b0, wb_dat8_o};
|
252 |
|
|
4'b0010: wb_dat_o <= #1 {16'b0, wb_dat8_o, 8'b0};
|
253 |
|
|
4'b0100: wb_dat_o <= #1 {8'b0, wb_dat8_o, 16'b0};
|
254 |
|
|
4'b1000: wb_dat_o <= #1 {wb_dat8_o, 24'b0};
|
255 |
|
|
4'b1111: wb_dat_o <= #1 wb_dat32_o; // debug interface output
|
256 |
|
|
default: wb_dat_o <= #1 0;
|
257 |
|
|
endcase // case(wb_sel_i)
|
258 |
|
|
|
259 |
|
|
always @(wb_sel_is or wb_dat_is)
|
260 |
|
|
case (wb_sel_is)
|
261 |
|
|
4'b0001 : wb_dat8_i = wb_dat_is[7:0];
|
262 |
|
|
4'b0010 : wb_dat8_i = wb_dat_is[15:8];
|
263 |
|
|
4'b0100 : wb_dat8_i = wb_dat_is[23:16];
|
264 |
|
|
4'b1000 : wb_dat8_i = wb_dat_is[31:24];
|
265 |
|
|
default : wb_dat8_i = wb_dat_is[7:0];
|
266 |
|
|
endcase // case(wb_sel_i)
|
267 |
|
|
|
268 |
|
|
reg [1:0] adr2 ; // lower 2 bits of regenerated address
|
269 |
|
|
always @(wb_sel_is)
|
270 |
|
|
case (wb_sel_is)
|
271 |
|
|
`ifdef BIG_BYTE_ENDIAN
|
272 |
|
|
4'b0001 : adr2 = 2'b11;
|
273 |
|
|
4'b0010 : adr2 = 2'b10;
|
274 |
|
|
4'b0100 : adr2 = 2'b01;
|
275 |
|
|
4'b1000 : adr2 = 2'b00;
|
276 |
|
|
`else
|
277 |
|
|
4'b0001 : adr2 = 2'b00;
|
278 |
|
|
4'b0010 : adr2 = 2'b01;
|
279 |
|
|
4'b0100 : adr2 = 2'b10;
|
280 |
|
|
4'b1000 : adr2 = 2'b11;
|
281 |
|
|
`endif
|
282 |
|
|
default : adr2 = 2'b0;
|
283 |
|
|
endcase // case(wb_sel_is)
|
284 |
|
|
|
285 |
|
|
assign wb_adr_int = {wb_adr_is[`UART_ADDR_WIDTH-1:2], adr2};
|
286 |
|
|
`endif // !`ifdef DATA_BUS_WIDTH_8
|
287 |
|
|
|
288 |
|
|
endmodule
|
289 |
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
|
|
|
293 |
|
|
|
294 |
|
|
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
|
298 |
|
|
|