| 1 |
18 |
unneback |
//////////////////////////////////////////////////////////////////////
|
| 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: uart_wb.v,v $
|
| 67 |
|
|
// Revision 1.17 2004/05/21 12:35:15 tadejm
|
| 68 |
|
|
// Added 2 LSB address generation dependent on select lines and LITLE/BIG endian when UART is in 32-bit mode.
|
| 69 |
|
|
//
|
| 70 |
|
|
// Revision 1.16 2002/07/29 21:16:18 gorban
|
| 71 |
|
|
// The uart_defines.v file is included again in sources.
|
| 72 |
|
|
//
|
| 73 |
|
|
// Revision 1.15 2002/07/22 23:02:23 gorban
|
| 74 |
|
|
// Bug Fixes:
|
| 75 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
| 76 |
|
|
// Problem reported by Kenny.Tung.
|
| 77 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
| 78 |
|
|
//
|
| 79 |
|
|
// Improvements:
|
| 80 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
| 81 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
| 82 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
| 83 |
|
|
//
|
| 84 |
|
|
// * Added optional baudrate output (baud_o).
|
| 85 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
| 86 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
| 87 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
| 88 |
|
|
//
|
| 89 |
|
|
// Revision 1.12 2001/12/19 08:03:34 mohor
|
| 90 |
|
|
// Warnings cleared.
|
| 91 |
|
|
//
|
| 92 |
|
|
// Revision 1.11 2001/12/06 14:51:04 gorban
|
| 93 |
|
|
// Bug in LSR[0] is fixed.
|
| 94 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
| 95 |
|
|
//
|
| 96 |
|
|
// Revision 1.10 2001/12/03 21:44:29 gorban
|
| 97 |
|
|
// Updated specification documentation.
|
| 98 |
|
|
// Added full 32-bit data bus interface, now as default.
|
| 99 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
| 100 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
| 101 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
| 102 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
| 103 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
| 104 |
|
|
//
|
| 105 |
|
|
// Revision 1.9 2001/10/20 09:58:40 gorban
|
| 106 |
|
|
// Small synopsis fixes
|
| 107 |
|
|
//
|
| 108 |
|
|
// Revision 1.8 2001/08/24 21:01:12 mohor
|
| 109 |
|
|
// Things connected to parity changed.
|
| 110 |
|
|
// Clock devider changed.
|
| 111 |
|
|
//
|
| 112 |
|
|
// Revision 1.7 2001/08/23 16:05:05 mohor
|
| 113 |
|
|
// Stop bit bug fixed.
|
| 114 |
|
|
// Parity bug fixed.
|
| 115 |
|
|
// WISHBONE read cycle bug fixed,
|
| 116 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
| 117 |
|
|
// PE indicator (Parity Error) bug fixed.
|
| 118 |
|
|
// Register read bug fixed.
|
| 119 |
|
|
//
|
| 120 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
| 121 |
|
|
// FIFO changes and other corrections.
|
| 122 |
|
|
//
|
| 123 |
|
|
// Revision 1.3 2001/05/21 19:12:01 gorban
|
| 124 |
|
|
// Corrected some Linter messages.
|
| 125 |
|
|
//
|
| 126 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
| 127 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
| 128 |
|
|
//
|
| 129 |
|
|
// Revision 1.0 2001-05-17 21:27:13+02 jacob
|
| 130 |
|
|
// Initial revision
|
| 131 |
|
|
//
|
| 132 |
|
|
//
|
| 133 |
|
|
|
| 134 |
|
|
// UART core WISHBONE interface
|
| 135 |
|
|
//
|
| 136 |
|
|
// Author: Jacob Gorban (jacob.gorban@flextronicssemi.com)
|
| 137 |
|
|
// Company: Flextronics Semiconductor
|
| 138 |
|
|
//
|
| 139 |
|
|
|
| 140 |
|
|
// synopsys translate_off
|
| 141 |
|
|
`include "timescale.v"
|
| 142 |
|
|
// synopsys translate_on
|
| 143 |
|
|
`include "uart_defines.v"
|
| 144 |
|
|
|
| 145 |
|
|
module uart_wb (clk, wb_rst_i,
|
| 146 |
|
|
wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_adr_i,
|
| 147 |
|
|
wb_adr_int, wb_dat_i, wb_dat_o, wb_dat8_i, wb_dat8_o, wb_dat32_o, wb_sel_i,
|
| 148 |
|
|
we_o, re_o // Write and read enable output for the core
|
| 149 |
|
|
);
|
| 150 |
|
|
|
| 151 |
|
|
input clk;
|
| 152 |
|
|
|
| 153 |
|
|
// WISHBONE interface
|
| 154 |
|
|
input wb_rst_i;
|
| 155 |
|
|
input wb_we_i;
|
| 156 |
|
|
input wb_stb_i;
|
| 157 |
|
|
input wb_cyc_i;
|
| 158 |
|
|
input [3:0] wb_sel_i;
|
| 159 |
|
|
input [`UART_ADDR_WIDTH-1:0] wb_adr_i; //WISHBONE address line
|
| 160 |
|
|
|
| 161 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
| 162 |
|
|
input [7:0] wb_dat_i; //input WISHBONE bus
|
| 163 |
|
|
output [7:0] wb_dat_o;
|
| 164 |
|
|
reg [7:0] wb_dat_o;
|
| 165 |
|
|
wire [7:0] wb_dat_i;
|
| 166 |
|
|
reg [7:0] wb_dat_is;
|
| 167 |
|
|
`else // for 32 data bus mode
|
| 168 |
|
|
input [31:0] wb_dat_i; //input WISHBONE bus
|
| 169 |
|
|
output [31:0] wb_dat_o;
|
| 170 |
|
|
reg [31:0] wb_dat_o;
|
| 171 |
|
|
wire [31:0] wb_dat_i;
|
| 172 |
|
|
reg [31:0] wb_dat_is;
|
| 173 |
|
|
`endif // !`ifdef DATA_BUS_WIDTH_8
|
| 174 |
|
|
|
| 175 |
|
|
output [`UART_ADDR_WIDTH-1:0] wb_adr_int; // internal signal for address bus
|
| 176 |
|
|
input [7:0] wb_dat8_o; // internal 8 bit output to be put into wb_dat_o
|
| 177 |
|
|
output [7:0] wb_dat8_i;
|
| 178 |
|
|
input [31:0] wb_dat32_o; // 32 bit data output (for debug interface)
|
| 179 |
|
|
output wb_ack_o;
|
| 180 |
|
|
output we_o;
|
| 181 |
|
|
output re_o;
|
| 182 |
|
|
|
| 183 |
|
|
wire we_o;
|
| 184 |
|
|
reg wb_ack_o;
|
| 185 |
|
|
reg [7:0] wb_dat8_i;
|
| 186 |
|
|
wire [7:0] wb_dat8_o;
|
| 187 |
|
|
wire [`UART_ADDR_WIDTH-1:0] wb_adr_int; // internal signal for address bus
|
| 188 |
|
|
reg [`UART_ADDR_WIDTH-1:0] wb_adr_is;
|
| 189 |
|
|
reg wb_we_is;
|
| 190 |
|
|
reg wb_cyc_is;
|
| 191 |
|
|
reg wb_stb_is;
|
| 192 |
|
|
reg [3:0] wb_sel_is;
|
| 193 |
|
|
wire [3:0] wb_sel_i;
|
| 194 |
|
|
reg wre ;// timing control signal for write or read enable
|
| 195 |
|
|
|
| 196 |
|
|
// wb_ack_o FSM
|
| 197 |
|
|
reg [1:0] wbstate;
|
| 198 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
| 199 |
|
|
if (wb_rst_i) begin
|
| 200 |
|
|
wb_ack_o <= #1 1'b0;
|
| 201 |
|
|
wbstate <= #1 0;
|
| 202 |
|
|
wre <= #1 1'b1;
|
| 203 |
|
|
end else
|
| 204 |
|
|
case (wbstate)
|
| 205 |
|
|
0: begin
|
| 206 |
|
|
if (wb_stb_is & wb_cyc_is) begin
|
| 207 |
|
|
wre <= #1 0;
|
| 208 |
|
|
wbstate <= #1 1;
|
| 209 |
|
|
wb_ack_o <= #1 1;
|
| 210 |
|
|
end else begin
|
| 211 |
|
|
wre <= #1 1;
|
| 212 |
|
|
wb_ack_o <= #1 0;
|
| 213 |
|
|
end
|
| 214 |
|
|
end
|
| 215 |
|
|
1: begin
|
| 216 |
|
|
wb_ack_o <= #1 0;
|
| 217 |
|
|
wbstate <= #1 2;
|
| 218 |
|
|
wre <= #1 0;
|
| 219 |
|
|
end
|
| 220 |
|
|
2,3: begin
|
| 221 |
|
|
wb_ack_o <= #1 0;
|
| 222 |
|
|
wbstate <= #1 0;
|
| 223 |
|
|
wre <= #1 0;
|
| 224 |
|
|
end
|
| 225 |
|
|
endcase
|
| 226 |
|
|
|
| 227 |
|
|
assign we_o = wb_we_is & wb_stb_is & wb_cyc_is & wre ; //WE for registers
|
| 228 |
|
|
assign re_o = ~wb_we_is & wb_stb_is & wb_cyc_is & wre ; //RE for registers
|
| 229 |
|
|
|
| 230 |
|
|
// Sample input signals
|
| 231 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
| 232 |
|
|
if (wb_rst_i) begin
|
| 233 |
|
|
wb_adr_is <= #1 0;
|
| 234 |
|
|
wb_we_is <= #1 0;
|
| 235 |
|
|
wb_cyc_is <= #1 0;
|
| 236 |
|
|
wb_stb_is <= #1 0;
|
| 237 |
|
|
wb_dat_is <= #1 0;
|
| 238 |
|
|
wb_sel_is <= #1 0;
|
| 239 |
|
|
end else begin
|
| 240 |
|
|
wb_adr_is <= #1 wb_adr_i;
|
| 241 |
|
|
wb_we_is <= #1 wb_we_i;
|
| 242 |
|
|
wb_cyc_is <= #1 wb_cyc_i;
|
| 243 |
|
|
wb_stb_is <= #1 wb_stb_i;
|
| 244 |
|
|
wb_dat_is <= #1 wb_dat_i;
|
| 245 |
|
|
wb_sel_is <= #1 wb_sel_i;
|
| 246 |
|
|
end
|
| 247 |
|
|
|
| 248 |
|
|
`ifdef DATA_BUS_WIDTH_8 // 8-bit data bus
|
| 249 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
| 250 |
|
|
if (wb_rst_i)
|
| 251 |
|
|
wb_dat_o <= #1 0;
|
| 252 |
|
|
else
|
| 253 |
|
|
wb_dat_o <= #1 wb_dat8_o;
|
| 254 |
|
|
|
| 255 |
|
|
always @(wb_dat_is)
|
| 256 |
|
|
wb_dat8_i = wb_dat_is;
|
| 257 |
|
|
|
| 258 |
|
|
assign wb_adr_int = wb_adr_is;
|
| 259 |
|
|
|
| 260 |
|
|
`else // 32-bit bus
|
| 261 |
|
|
// put output to the correct byte in 32 bits using select line
|
| 262 |
|
|
always @(posedge clk or posedge wb_rst_i)
|
| 263 |
|
|
if (wb_rst_i)
|
| 264 |
|
|
wb_dat_o <= #1 0;
|
| 265 |
|
|
else if (re_o)
|
| 266 |
|
|
case (wb_sel_is)
|
| 267 |
|
|
4'b0001: wb_dat_o <= #1 {24'b0, wb_dat8_o};
|
| 268 |
|
|
4'b0010: wb_dat_o <= #1 {16'b0, wb_dat8_o, 8'b0};
|
| 269 |
|
|
4'b0100: wb_dat_o <= #1 {8'b0, wb_dat8_o, 16'b0};
|
| 270 |
|
|
4'b1000: wb_dat_o <= #1 {wb_dat8_o, 24'b0};
|
| 271 |
|
|
4'b1111: wb_dat_o <= #1 wb_dat32_o; // debug interface output
|
| 272 |
|
|
default: wb_dat_o <= #1 0;
|
| 273 |
|
|
endcase // case(wb_sel_i)
|
| 274 |
|
|
|
| 275 |
|
|
reg [1:0] wb_adr_int_lsb;
|
| 276 |
|
|
|
| 277 |
|
|
always @(wb_sel_is or wb_dat_is)
|
| 278 |
|
|
begin
|
| 279 |
|
|
case (wb_sel_is)
|
| 280 |
|
|
4'b0001 : wb_dat8_i = wb_dat_is[7:0];
|
| 281 |
|
|
4'b0010 : wb_dat8_i = wb_dat_is[15:8];
|
| 282 |
|
|
4'b0100 : wb_dat8_i = wb_dat_is[23:16];
|
| 283 |
|
|
4'b1000 : wb_dat8_i = wb_dat_is[31:24];
|
| 284 |
|
|
default : wb_dat8_i = wb_dat_is[7:0];
|
| 285 |
|
|
endcase // case(wb_sel_i)
|
| 286 |
|
|
|
| 287 |
|
|
`ifdef LITLE_ENDIAN
|
| 288 |
|
|
case (wb_sel_is)
|
| 289 |
|
|
4'b0001 : wb_adr_int_lsb = 2'h0;
|
| 290 |
|
|
4'b0010 : wb_adr_int_lsb = 2'h1;
|
| 291 |
|
|
4'b0100 : wb_adr_int_lsb = 2'h2;
|
| 292 |
|
|
4'b1000 : wb_adr_int_lsb = 2'h3;
|
| 293 |
|
|
default : wb_adr_int_lsb = 2'h0;
|
| 294 |
|
|
endcase // case(wb_sel_i)
|
| 295 |
|
|
`else
|
| 296 |
|
|
case (wb_sel_is)
|
| 297 |
|
|
4'b0001 : wb_adr_int_lsb = 2'h3;
|
| 298 |
|
|
4'b0010 : wb_adr_int_lsb = 2'h2;
|
| 299 |
|
|
4'b0100 : wb_adr_int_lsb = 2'h1;
|
| 300 |
|
|
4'b1000 : wb_adr_int_lsb = 2'h0;
|
| 301 |
|
|
default : wb_adr_int_lsb = 2'h0;
|
| 302 |
|
|
endcase // case(wb_sel_i)
|
| 303 |
|
|
`endif
|
| 304 |
|
|
end
|
| 305 |
|
|
|
| 306 |
|
|
assign wb_adr_int = {wb_adr_is[`UART_ADDR_WIDTH-1:2], wb_adr_int_lsb};
|
| 307 |
|
|
|
| 308 |
|
|
`endif // !`ifdef DATA_BUS_WIDTH_8
|
| 309 |
|
|
|
| 310 |
|
|
endmodule
|
| 311 |
|
|
|
| 312 |
|
|
|
| 313 |
|
|
|
| 314 |
|
|
|
| 315 |
|
|
|
| 316 |
|
|
|
| 317 |
|
|
|
| 318 |
|
|
|
| 319 |
|
|
|
| 320 |
|
|
|