📄 uart_regs.v
字号:
////////////////////////////////////////////////////////////////////////// //////// uart_regs.v //////// //////// //////// This file is part of the "UART 16550 compatible" project //////// http://www.opencores.org/cores/uart16550/ //////// //////// Documentation related to this project: //////// - http://www.opencores.org/cores/uart16550/ //////// //////// Projects compatibility: //////// - WISHBONE //////// RS232 Protocol //////// 16550D uart (mostly supported) //////// //////// Overview (main Features): //////// Registers of the uart 16550 core //////// //////// Known problems (limits): //////// Inserts 1 wait state in all WISHBONE transfers //////// //////// To Do: //////// Nothing or verification. //////// //////// Author(s): //////// - gorban@opencores.org //////// - Jacob Gorban //////// //////// Created: 2001/05/12 //////// Last Updated: (See log for the revision history //////// //////// ////////////////////////////////////////////////////////////////////////////// //////// Copyright (C) 2000 Jacob Gorban, gorban@opencores.org //////// //////// This source file may be used and distributed without //////// restriction provided that this copyright statement is not //////// removed from the file and that any derivative work contains //////// the original copyright notice and the associated disclaimer. //////// //////// This source file is free software; you can redistribute it //////// and/or modify it under the terms of the GNU Lesser General //////// Public License as published by the Free Software Foundation; //////// either version 2.1 of the License, or (at your option) any //////// later version. //////// //////// This source is distributed in the hope that it will be //////// useful, but WITHOUT ANY WARRANTY; without even the implied //////// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //////// PURPOSE. See the GNU Lesser General Public License for more //////// details. //////// //////// You should have received a copy of the GNU Lesser General //////// Public License along with this source; if not, download it //////// from http://www.opencores.org/lgpl.shtml //////// ////////////////////////////////////////////////////////////////////////////// CVS Revision History//// $Log: uart_regs.v,v $// Revision 1.10 2001/06/23 11:21:48 gorban// DL made 16-bit long. Fixed transmission/reception bugs.//// Revision 1.9 2001/05/31 20:08:01 gorban// FIFO changes and other corrections.//// Revision 1.8 2001/05/29 20:05:04 gorban// Fixed some bugs and synthesis problems.//// Revision 1.7 2001/05/27 17:37:49 gorban// Fixed many bugs. Updated spec. Changed FIFO files structure. See CHANGES.txt file.//// Revision 1.6 2001/05/21 19:12:02 gorban// Corrected some Linter messages.//// Revision 1.5 2001/05/17 18:34:18 gorban// First 'stable' release. Should be sythesizable now. Also added new header.//// Revision 1.0 2001-05-17 21:27:11+02 jacob// Initial revision////`include "timescale.v"`include "uart_defines.v"`define UART_DL1 7:0`define UART_DL2 15:8module uart_regs (clk, wb_rst_i, wb_addr_i, wb_dat_i, wb_dat_o, wb_we_i, wb_re_i, // additional signals modem_inputs, stx_pad_o, srx_pad_i, enable, rts_pad_o, dtr_pad_o, int_o );input clk;input wb_rst_i;input [`UART_ADDR_WIDTH-1:0] wb_addr_i;input [7:0] wb_dat_i;output [7:0] wb_dat_o;input wb_we_i;input wb_re_i;output stx_pad_o;input srx_pad_i;input [3:0] modem_inputs;output enable;output rts_pad_o;output dtr_pad_o;output int_o;wire [3:0] modem_inputs;reg enable;wire stx_pad_o; // received from transmitter modulewire srx_pad_i;reg [7:0] wb_dat_o;wire [`UART_ADDR_WIDTH-1:0] wb_addr_i;wire [7:0] wb_dat_i;reg [3:0] ier;reg [3:0] iir;reg [1:0] fcr; /// bits 7 and 6 of fcr. Other bits are ignoredreg [4:0] mcr;reg [7:0] lcr;reg [7:0] lsr;reg [7:0] msr;reg [15:0] dl; // 32-bit divisor latchreg start_dlc; // activate dlc on writing to UART_DL1reg lsr_mask;reg msi_reset; // reset MSR 4 lower bits indicatorreg threi_clear; // THRE interrupt clear flagreg [15:0] dlc; // 32-bit divisor latch counterreg int_o;reg [3:0] trigger_level; // trigger level of the receiver FIFOreg rx_reset;reg tx_reset;wire dlab; // divisor latch access bitwire cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i; // modem status bitswire loopback; // loopback bit (MCR bit 4)wire cts, dsr, ri, dcd; // effective signals (considering loopback)wire rts_pad_o, dtr_pad_o; // modem control outputs//// ASSINGS//assign {cts_pad_i, dsr_pad_i, ri_pad_i, dcd_pad_i} = modem_inputs;assign {cts, dsr, ri, dcd} = loopback ? {mcr[`UART_MC_RTS],mcr[`UART_MC_DTR],mcr[`UART_MC_OUT1],mcr[`UART_MC_OUT2]} : ~{cts_pad_i,dsr_pad_i,ri_pad_i,dcd_pad_i};assign dlab = lcr[`UART_LC_DL];assign loopback = mcr[4];// assign modem outputsassign rts_pad_o = mcr[`UART_MC_RTS];assign dtr_pad_o = mcr[`UART_MC_DTR];// Interrupt signalsreg rls_int; // receiver line status interruptreg rda_int; // receiver data available interruptreg ti_int; // timeout indicator interruptreg thre_int; // transmitter holding register empty interruptreg ms_int; // modem status interrupt// FIFO signalsreg tf_push;reg rf_pop;wire [`UART_FIFO_REC_WIDTH-1:0] rf_data_out;wire rf_error_bit; // an error (parity or framing) is inside the fifowire [`UART_FIFO_COUNTER_W-1:0] rf_count;wire [`UART_FIFO_COUNTER_W-1:0] tf_count;wire [2:0] state;wire [5:0] counter_t;wire [3:0] counter_b;wire rx_lsr_mask;// Transmitter Instanceuart_transmitter transmitter(clk, wb_rst_i, lcr, tf_push, wb_dat_i, enable, stx_pad_o, state, tf_count, tx_reset);// Receiver Instanceuart_receiver receiver(clk, wb_rst_i, lcr, rf_pop, srx_pad_i, enable, rda_int, counter_t, counter_b, rf_count, rf_data_out, rf_error_bit, rf_overrun, rx_reset, rx_lsr_mask);/*always @(posedge clk or posedge wb_rst_i) // synchrounous readingbegin if (wb_rst_i) begin wb_dat_o <= #1 8'b0; end else if (wb_re_i) //if (we're not writing) case (wb_addr_i) `UART_REG_RB : if (dlab) // Receiver FIFO or DL byte 1 wb_dat_o <= #1 dl[`UART_DL1]; else wb_dat_o <= #1 rf_data_out[9:2]; `UART_REG_IE : wb_dat_o <= #1 dlab ? dl[`UART_DL2] : ier; `UART_REG_II : wb_dat_o <= #1 {4'b1100,iir}; `UART_REG_LC : wb_dat_o <= #1 lcr; `UART_REG_LS : wb_dat_o <= #1 lsr; `UART_REG_MS : wb_dat_o <= #1 msr; default: wb_dat_o <= #1 8'b0; // ?? endcase else wb_dat_o <= #1 8'b0;end*/always @(wb_addr_i or dlab or dl or rf_data_out or ier or iir or lcr or lsr or msr)begin case (wb_addr_i) `UART_REG_RB : if (dlab) // Receiver FIFO or DL byte 1 wb_dat_o <= dl[`UART_DL1]; else wb_dat_o <= rf_data_out[9:2]; `UART_REG_IE : wb_dat_o <= dlab ? dl[`UART_DL2] : ier; `UART_REG_II : wb_dat_o <= {4'b1100,iir}; `UART_REG_LC : wb_dat_o <= lcr; `UART_REG_LS : wb_dat_o <= lsr; `UART_REG_MS : wb_dat_o <= msr; default: wb_dat_o <= 8'b0; // ?? endcaseend// rf_pop signal handlingalways @(posedge clk or posedge wb_rst_i)begin if (wb_rst_i) rf_pop <= #1 0; else if (rf_pop) // restore the signal to 0 after one clock cycle rf_pop <= #1 0; else if (wb_re_i && wb_addr_i == `UART_REG_RB && !dlab) rf_pop <= #1 1; // advance read pointerend// lsr_mask signal handlingalways @(posedge clk or posedge wb_rst_i)begin if (wb_rst_i) lsr_mask <= #1 0; else if (lsr_mask) lsr_mask <= #1 0; else if (wb_re_i && wb_addr_i == `UART_REG_LS && !dlab) lsr_mask <= #1 1; // reset bits in the Line Status Registerendassign rx_lsr_mask = lsr_mask;// msi_reset signal handlingalways @(posedge clk or posedge wb_rst_i)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -