| 1 |
18 |
unneback |
//////////////////////////////////////////////////////////////////////
|
| 2 |
|
|
//// ////
|
| 3 |
|
|
//// uart_top.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 top level. ////
|
| 19 |
|
|
//// ////
|
| 20 |
|
|
//// Known problems (limits): ////
|
| 21 |
|
|
//// Note that transmitter and receiver instances are inside ////
|
| 22 |
|
|
//// the uart_regs.v file. ////
|
| 23 |
|
|
//// ////
|
| 24 |
|
|
//// To Do: ////
|
| 25 |
|
|
//// Nothing so far. ////
|
| 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_top.v,v $
|
| 67 |
|
|
// Revision 1.19 2002/07/29 21:16:18 gorban
|
| 68 |
|
|
// The uart_defines.v file is included again in sources.
|
| 69 |
|
|
//
|
| 70 |
|
|
// Revision 1.18 2002/07/22 23:02:23 gorban
|
| 71 |
|
|
// Bug Fixes:
|
| 72 |
|
|
// * Possible loss of sync and bad reception of stop bit on slow baud rates fixed.
|
| 73 |
|
|
// Problem reported by Kenny.Tung.
|
| 74 |
|
|
// * Bad (or lack of ) loopback handling fixed. Reported by Cherry Withers.
|
| 75 |
|
|
//
|
| 76 |
|
|
// Improvements:
|
| 77 |
|
|
// * Made FIFO's as general inferrable memory where possible.
|
| 78 |
|
|
// So on FPGA they should be inferred as RAM (Distributed RAM on Xilinx).
|
| 79 |
|
|
// This saves about 1/3 of the Slice count and reduces P&R and synthesis times.
|
| 80 |
|
|
//
|
| 81 |
|
|
// * Added optional baudrate output (baud_o).
|
| 82 |
|
|
// This is identical to BAUDOUT* signal on 16550 chip.
|
| 83 |
|
|
// It outputs 16xbit_clock_rate - the divided clock.
|
| 84 |
|
|
// It's disabled by default. Define UART_HAS_BAUDRATE_OUTPUT to use.
|
| 85 |
|
|
//
|
| 86 |
|
|
// Revision 1.17 2001/12/19 08:40:03 mohor
|
| 87 |
|
|
// Warnings fixed (unused signals removed).
|
| 88 |
|
|
//
|
| 89 |
|
|
// Revision 1.16 2001/12/06 14:51:04 gorban
|
| 90 |
|
|
// Bug in LSR[0] is fixed.
|
| 91 |
|
|
// All WISHBONE signals are now sampled, so another wait-state is introduced on all transfers.
|
| 92 |
|
|
//
|
| 93 |
|
|
// Revision 1.15 2001/12/03 21:44:29 gorban
|
| 94 |
|
|
// Updated specification documentation.
|
| 95 |
|
|
// Added full 32-bit data bus interface, now as default.
|
| 96 |
|
|
// Address is 5-bit wide in 32-bit data bus mode.
|
| 97 |
|
|
// Added wb_sel_i input to the core. It's used in the 32-bit mode.
|
| 98 |
|
|
// Added debug interface with two 32-bit read-only registers in 32-bit mode.
|
| 99 |
|
|
// Bits 5 and 6 of LSR are now only cleared on TX FIFO write.
|
| 100 |
|
|
// My small test bench is modified to work with 32-bit mode.
|
| 101 |
|
|
//
|
| 102 |
|
|
// Revision 1.14 2001/11/07 17:51:52 gorban
|
| 103 |
|
|
// Heavily rewritten interrupt and LSR subsystems.
|
| 104 |
|
|
// Many bugs hopefully squashed.
|
| 105 |
|
|
//
|
| 106 |
|
|
// Revision 1.13 2001/10/20 09:58:40 gorban
|
| 107 |
|
|
// Small synopsis fixes
|
| 108 |
|
|
//
|
| 109 |
|
|
// Revision 1.12 2001/08/25 15:46:19 gorban
|
| 110 |
|
|
// Modified port names again
|
| 111 |
|
|
//
|
| 112 |
|
|
// Revision 1.11 2001/08/24 21:01:12 mohor
|
| 113 |
|
|
// Things connected to parity changed.
|
| 114 |
|
|
// Clock devider changed.
|
| 115 |
|
|
//
|
| 116 |
|
|
// Revision 1.10 2001/08/23 16:05:05 mohor
|
| 117 |
|
|
// Stop bit bug fixed.
|
| 118 |
|
|
// Parity bug fixed.
|
| 119 |
|
|
// WISHBONE read cycle bug fixed,
|
| 120 |
|
|
// OE indicator (Overrun Error) bug fixed.
|
| 121 |
|
|
// PE indicator (Parity Error) bug fixed.
|
| 122 |
|
|
// Register read bug fixed.
|
| 123 |
|
|
//
|
| 124 |
|
|
// Revision 1.4 2001/05/31 20:08:01 gorban
|
| 125 |
|
|
// FIFO changes and other corrections.
|
| 126 |
|
|
//
|
| 127 |
|
|
// Revision 1.3 2001/05/21 19:12:02 gorban
|
| 128 |
|
|
// Corrected some Linter messages.
|
| 129 |
|
|
//
|
| 130 |
|
|
// Revision 1.2 2001/05/17 18:34:18 gorban
|
| 131 |
|
|
// First 'stable' release. Should be sythesizable now. Also added new header.
|
| 132 |
|
|
//
|
| 133 |
|
|
// Revision 1.0 2001-05-17 21:27:12+02 jacob
|
| 134 |
|
|
// Initial revision
|
| 135 |
|
|
//
|
| 136 |
|
|
//
|
| 137 |
|
|
// synopsys translate_off
|
| 138 |
|
|
`include "timescale.v"
|
| 139 |
|
|
// synopsys translate_on
|
| 140 |
|
|
|
| 141 |
|
|
`include "uart_defines.v"
|
| 142 |
|
|
|
| 143 |
|
|
module uart_top (
|
| 144 |
|
|
wb_clk_i,
|
| 145 |
|
|
|
| 146 |
|
|
// Wishbone signals
|
| 147 |
|
|
wb_rst_i, wb_adr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_stb_i, wb_cyc_i, wb_ack_o, wb_sel_i,
|
| 148 |
|
|
int_o, // interrupt request
|
| 149 |
|
|
|
| 150 |
|
|
// UART signals
|
| 151 |
|
|
// serial input/output
|
| 152 |
|
|
stx_pad_o, srx_pad_i,
|
| 153 |
|
|
|
| 154 |
|
|
// modem signals
|
| 155 |
|
|
rts_pad_o, cts_pad_i, dtr_pad_o, dsr_pad_i, ri_pad_i, dcd_pad_i
|
| 156 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
| 157 |
|
|
, baud_o
|
| 158 |
|
|
`endif
|
| 159 |
|
|
);
|
| 160 |
|
|
|
| 161 |
|
|
parameter uart_data_width = `UART_DATA_WIDTH;
|
| 162 |
|
|
parameter uart_addr_width = `UART_ADDR_WIDTH;
|
| 163 |
|
|
|
| 164 |
|
|
input wb_clk_i;
|
| 165 |
|
|
|
| 166 |
|
|
// WISHBONE interface
|
| 167 |
|
|
input wb_rst_i;
|
| 168 |
|
|
input [uart_addr_width-1:0] wb_adr_i;
|
| 169 |
|
|
input [uart_data_width-1:0] wb_dat_i;
|
| 170 |
|
|
output [uart_data_width-1:0] wb_dat_o;
|
| 171 |
|
|
input wb_we_i;
|
| 172 |
|
|
input wb_stb_i;
|
| 173 |
|
|
input wb_cyc_i;
|
| 174 |
|
|
input [3:0] wb_sel_i;
|
| 175 |
|
|
output wb_ack_o;
|
| 176 |
|
|
output int_o;
|
| 177 |
|
|
|
| 178 |
|
|
// UART signals
|
| 179 |
|
|
input srx_pad_i;
|
| 180 |
|
|
output stx_pad_o;
|
| 181 |
|
|
output rts_pad_o;
|
| 182 |
|
|
input cts_pad_i;
|
| 183 |
|
|
output dtr_pad_o;
|
| 184 |
|
|
input dsr_pad_i;
|
| 185 |
|
|
input ri_pad_i;
|
| 186 |
|
|
input dcd_pad_i;
|
| 187 |
|
|
|
| 188 |
|
|
// optional baudrate output
|
| 189 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
| 190 |
|
|
output baud_o;
|
| 191 |
|
|
`endif
|
| 192 |
|
|
|
| 193 |
|
|
|
| 194 |
|
|
wire stx_pad_o;
|
| 195 |
|
|
wire rts_pad_o;
|
| 196 |
|
|
wire dtr_pad_o;
|
| 197 |
|
|
|
| 198 |
|
|
wire [uart_addr_width-1:0] wb_adr_i;
|
| 199 |
|
|
wire [uart_data_width-1:0] wb_dat_i;
|
| 200 |
|
|
wire [uart_data_width-1:0] wb_dat_o;
|
| 201 |
|
|
|
| 202 |
|
|
wire [7:0] wb_dat8_i; // 8-bit internal data input
|
| 203 |
|
|
wire [7:0] wb_dat8_o; // 8-bit internal data output
|
| 204 |
|
|
wire [31:0] wb_dat32_o; // debug interface 32-bit output
|
| 205 |
|
|
wire [3:0] wb_sel_i; // WISHBONE select signal
|
| 206 |
|
|
wire [uart_addr_width-1:0] wb_adr_int;
|
| 207 |
|
|
wire we_o; // Write enable for registers
|
| 208 |
|
|
wire re_o; // Read enable for registers
|
| 209 |
|
|
//
|
| 210 |
|
|
// MODULE INSTANCES
|
| 211 |
|
|
//
|
| 212 |
|
|
|
| 213 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
| 214 |
|
|
`else
|
| 215 |
|
|
// debug interface wires
|
| 216 |
|
|
wire [3:0] ier;
|
| 217 |
|
|
wire [3:0] iir;
|
| 218 |
|
|
wire [1:0] fcr;
|
| 219 |
|
|
wire [4:0] mcr;
|
| 220 |
|
|
wire [7:0] lcr;
|
| 221 |
|
|
wire [7:0] msr;
|
| 222 |
|
|
wire [7:0] lsr;
|
| 223 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] rf_count;
|
| 224 |
|
|
wire [`UART_FIFO_COUNTER_W-1:0] tf_count;
|
| 225 |
|
|
wire [2:0] tstate;
|
| 226 |
|
|
wire [3:0] rstate;
|
| 227 |
|
|
`endif
|
| 228 |
|
|
|
| 229 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
| 230 |
|
|
//// WISHBONE interface module
|
| 231 |
|
|
uart_wb wb_interface(
|
| 232 |
|
|
.clk( wb_clk_i ),
|
| 233 |
|
|
.wb_rst_i( wb_rst_i ),
|
| 234 |
|
|
.wb_dat_i(wb_dat_i),
|
| 235 |
|
|
.wb_dat_o(wb_dat_o),
|
| 236 |
|
|
.wb_dat8_i(wb_dat8_i),
|
| 237 |
|
|
.wb_dat8_o(wb_dat8_o),
|
| 238 |
|
|
.wb_dat32_o(32'b0),
|
| 239 |
|
|
.wb_sel_i(4'b0),
|
| 240 |
|
|
.wb_we_i( wb_we_i ),
|
| 241 |
|
|
.wb_stb_i( wb_stb_i ),
|
| 242 |
|
|
.wb_cyc_i( wb_cyc_i ),
|
| 243 |
|
|
.wb_ack_o( wb_ack_o ),
|
| 244 |
|
|
.wb_adr_i(wb_adr_i),
|
| 245 |
|
|
.wb_adr_int(wb_adr_int),
|
| 246 |
|
|
.we_o( we_o ),
|
| 247 |
|
|
.re_o(re_o)
|
| 248 |
|
|
);
|
| 249 |
|
|
`else
|
| 250 |
|
|
uart_wb wb_interface(
|
| 251 |
|
|
.clk( wb_clk_i ),
|
| 252 |
|
|
.wb_rst_i( wb_rst_i ),
|
| 253 |
|
|
.wb_dat_i(wb_dat_i),
|
| 254 |
|
|
.wb_dat_o(wb_dat_o),
|
| 255 |
|
|
.wb_dat8_i(wb_dat8_i),
|
| 256 |
|
|
.wb_dat8_o(wb_dat8_o),
|
| 257 |
|
|
.wb_sel_i(wb_sel_i),
|
| 258 |
|
|
.wb_dat32_o(wb_dat32_o),
|
| 259 |
|
|
.wb_we_i( wb_we_i ),
|
| 260 |
|
|
.wb_stb_i( wb_stb_i ),
|
| 261 |
|
|
.wb_cyc_i( wb_cyc_i ),
|
| 262 |
|
|
.wb_ack_o( wb_ack_o ),
|
| 263 |
|
|
.wb_adr_i(wb_adr_i),
|
| 264 |
|
|
.wb_adr_int(wb_adr_int),
|
| 265 |
|
|
.we_o( we_o ),
|
| 266 |
|
|
.re_o(re_o)
|
| 267 |
|
|
);
|
| 268 |
|
|
`endif
|
| 269 |
|
|
|
| 270 |
|
|
// Registers
|
| 271 |
|
|
uart_regs regs(
|
| 272 |
|
|
.clk( wb_clk_i ),
|
| 273 |
|
|
.wb_rst_i( wb_rst_i ),
|
| 274 |
|
|
.wb_addr_i( wb_adr_int ),
|
| 275 |
|
|
.wb_dat_i( wb_dat8_i ),
|
| 276 |
|
|
.wb_dat_o( wb_dat8_o ),
|
| 277 |
|
|
.wb_we_i( we_o ),
|
| 278 |
|
|
.wb_re_i(re_o),
|
| 279 |
|
|
.modem_inputs( {cts_pad_i, dsr_pad_i,
|
| 280 |
|
|
ri_pad_i, dcd_pad_i} ),
|
| 281 |
|
|
.stx_pad_o( stx_pad_o ),
|
| 282 |
|
|
.srx_pad_i( srx_pad_i ),
|
| 283 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
| 284 |
|
|
`else
|
| 285 |
|
|
// debug interface signals enabled
|
| 286 |
|
|
.ier(ier),
|
| 287 |
|
|
.iir(iir),
|
| 288 |
|
|
.fcr(fcr),
|
| 289 |
|
|
.mcr(mcr),
|
| 290 |
|
|
.lcr(lcr),
|
| 291 |
|
|
.msr(msr),
|
| 292 |
|
|
.lsr(lsr),
|
| 293 |
|
|
.rf_count(rf_count),
|
| 294 |
|
|
.tf_count(tf_count),
|
| 295 |
|
|
.tstate(tstate),
|
| 296 |
|
|
.rstate(rstate),
|
| 297 |
|
|
`endif
|
| 298 |
|
|
.rts_pad_o( rts_pad_o ),
|
| 299 |
|
|
.dtr_pad_o( dtr_pad_o ),
|
| 300 |
|
|
.int_o( int_o )
|
| 301 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
| 302 |
|
|
, .baud_o(baud_o)
|
| 303 |
|
|
`endif
|
| 304 |
|
|
|
| 305 |
|
|
);
|
| 306 |
|
|
|
| 307 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
| 308 |
|
|
`else
|
| 309 |
|
|
uart_debug_if dbg(/*AUTOINST*/
|
| 310 |
|
|
// Outputs
|
| 311 |
|
|
.wb_dat32_o (wb_dat32_o[31:0]),
|
| 312 |
|
|
// Inputs
|
| 313 |
|
|
.wb_adr_i (wb_adr_int[`UART_ADDR_WIDTH-1:0]),
|
| 314 |
|
|
.ier (ier[3:0]),
|
| 315 |
|
|
.iir (iir[3:0]),
|
| 316 |
|
|
.fcr (fcr[1:0]),
|
| 317 |
|
|
.mcr (mcr[4:0]),
|
| 318 |
|
|
.lcr (lcr[7:0]),
|
| 319 |
|
|
.msr (msr[7:0]),
|
| 320 |
|
|
.lsr (lsr[7:0]),
|
| 321 |
|
|
.rf_count (rf_count[`UART_FIFO_COUNTER_W-1:0]),
|
| 322 |
|
|
.tf_count (tf_count[`UART_FIFO_COUNTER_W-1:0]),
|
| 323 |
|
|
.tstate (tstate[2:0]),
|
| 324 |
|
|
.rstate (rstate[3:0]));
|
| 325 |
|
|
`endif
|
| 326 |
|
|
|
| 327 |
|
|
initial
|
| 328 |
|
|
begin
|
| 329 |
|
|
`ifdef DATA_BUS_WIDTH_8
|
| 330 |
|
|
$display("(%m) UART INFO: Data bus width is 8. No Debug interface.\n");
|
| 331 |
|
|
`else
|
| 332 |
|
|
$display("(%m) UART INFO: Data bus width is 32. Debug Interface present.\n");
|
| 333 |
|
|
`endif
|
| 334 |
|
|
`ifdef UART_HAS_BAUDRATE_OUTPUT
|
| 335 |
|
|
$display("(%m) UART INFO: Has baudrate output\n");
|
| 336 |
|
|
`else
|
| 337 |
|
|
$display("(%m) UART INFO: Doesn't have baudrate output\n");
|
| 338 |
|
|
`endif
|
| 339 |
|
|
end
|
| 340 |
|
|
|
| 341 |
|
|
endmodule
|
| 342 |
|
|
|
| 343 |
|
|
|