三.rtl
uart.v
//Module uart
module uart(
pclk,
presetn,
penable,
psel,
pwrite,
paddr,
pwdata,
prdata,
uart_clk,
uart_rstn,
uart_rxd,
uart_txd,
uart_intr
);
input pclk;
input presetn;
input penable;
input psel;
input pwrite;
input [11:0] paddr;
input [31:0] pwdata;
output [31:0] prdata;
input uart_clk;
input uart_rstn;
input uart_rxd;
output uart_txd;
output uart_intr;
apb_uart u_apb_uart(
.PCLK (pclk ),
.PCLK_REQEN (1'b0 ),
.PRESETn (presetn ),
.UARTCLK (uart_clk ),
.nUARTRST (uart_rstn ),
.PSEL (psel ),
.PENABLE (penable ),
.PWRITE (pwrite ),
.PADDR (paddr ),
.PWDATA (pwdata ),
.PRDATA (prdata ),
.nUARTCTS_IN (1'b0 ),
.nUARTDCD_IN (1'b0 ),
.nUARTDSR_IN (1'b0 ),
.nUARTRI_IN (1'b0 ),
.UARTRXD_IN (uart_rxd ),
.UART_CTS_OUT ( ),
.UART_CTS_OEN ( ),
.UART_DCD_OUT ( ),
.UART_DCD_OEN ( ),
.UART_DSR_OUT ( ),
.UART_DSR_OEN ( ),
.UART_RI_OUT ( ),
.UART_RI_OEN ( ),
.UART_RXD_OUT ( ),
.UART_RXD_OEN ( ),
.UARTTXD_OUT (uart_txd ),
.UARTTXD_OEN ( ),
.nUARTOut2_OUT ( ),
.nUARTOut1_OUT ( ),
.nUARTRTS_OUT ( ),
.nUARTDTR_OUT ( ),
.UART_OUT2_OEN ( ),
.UART_OUT1_OEN ( ),
.UART_RTS_OEN ( ),
.UART_DTR_OEN ( ),
.UARTTXDMACLR (1'b0 ),
.UARTRXDMACLR (1'b0 ),
.UARTTXDMASREQ ( ),
.UARTTXDMBREQ ( ),
.UARTRXDMASREQ ( ),
.UARTRXDMABREQ ( ),
.UARTINTR (uart_intr )
);
endmodule //uart
uarttxregfile.v
module uarttxregfile (
PCLK,
PRESETn,
RegFileWrEn,
WrPtr,
RdPtr,
PWDATAIn,
iTXFIFOData
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input RegFileWrEn; // Write Enable
input [3:0] WrPtr; // Write Pointer
input [3:0] RdPtr; // Read Pointer
input [7:0] PWDATAIn; // Data bus
output [7:0] iTXFIFOData; // Read data
// ------------------------------------------------------------------
//
// UartTXRegFile
// =============
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block contains an array of flipflops that serve as the storage
// register file for the transmit FIFO.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire RegFileWrEn; // Write Enable (Module Input)
wire [3:0] WrPtr; // Write Pointer (Module Input)
wire [3:0] RdPtr; // Read Pointer (Module Input)
wire [7:0] PWDATAIn; // Data bus (Module Input)
// ------------------------------------------------------------------
// register declaration
// ------------------------------------------------------------------
reg [7:0] TXRegFile0; // Register File-0 8-bits wide
reg [7:0] TXRegFile1; // Register File-1 8-bits wide
reg [7:0] TXRegFile2; // Register File-2 8-bits wide
reg [7:0] TXRegFile3; // Register File-3 8-bits wide
reg [7:0] TXRegFile4; // Register File-4 8-bits wide
reg [7:0] TXRegFile5; // Register File-5 8-bits wide
reg [7:0] TXRegFile6; // Register File-6 8-bits wide
reg [7:0] TXRegFile7; // Register File-7 8-bits wide
reg [7:0] TXRegFile8; // Register File-8 8-bits wide
reg [7:0] TXRegFile9; // Register File-9 8-bits wide
reg [7:0] TXRegFile10; // Register File-10 8-bits wide
reg [7:0] TXRegFile11; // Register File-11 8-bits wide
reg [7:0] TXRegFile12; // Register File-12 8-bits wide
reg [7:0] TXRegFile13; // Register File-13 8-bits wide
reg [7:0] TXRegFile14; // Register File-14 8-bits wide
reg [7:0] TXRegFile15; // Register File-15 8-bits wide
//reg [7:0] TXRegFile16; // Register File-16 8-bits wide
reg [7:0] NextTXRegFile0; // D-inputs of Register File-0 8-bits wide
reg [7:0] NextTXRegFile1; // D-inputs of Register File-1 8-bits wide
reg [7:0] NextTXRegFile2; // D-inputs of Register File-2 8-bits wide
reg [7:0] NextTXRegFile3; // D-inputs of Register File-3 8-bits wide
reg [7:0] NextTXRegFile4; // D-inputs of Register File-4 8-bits wide
reg [7:0] NextTXRegFile5; // D-inputs of Register File-5 8-bits wide
reg [7:0] NextTXRegFile6; // D-inputs of Register File-6 8-bits wide
reg [7:0] NextTXRegFile7; // D-inputs of Register File-7 8-bits wide
reg [7:0] NextTXRegFile8; // D-inputs of Register File-8 8-bits wide
reg [7:0] NextTXRegFile9; // D-inputs of Register File-9 8-bits wide
reg [7:0] NextTXRegFile10; // D-inputs of Register File-10 8-bits wide
reg [7:0] NextTXRegFile11; // D-inputs of Register File-11 8-bits wide
reg [7:0] NextTXRegFile12; // D-inputs of Register File-12 8-bits wide
reg [7:0] NextTXRegFile13; // D-inputs of Register File-13 8-bits wide
reg [7:0] NextTXRegFile14; // D-inputs of Register File-14 8-bits wide
reg [7:0] NextTXRegFile15; // D-inputs of Register File-15 8-bits wide
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Register array
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)//novas -21013
begin : p_Seq
if (PRESETn == 1'b0)
begin
TXRegFile0 <= 8'b00000000;
TXRegFile1 <= 8'b00000000;
TXRegFile2 <= 8'b00000000;
TXRegFile3 <= 8'b00000000;
TXRegFile4 <= 8'b00000000;
TXRegFile5 <= 8'b00000000;
TXRegFile6 <= 8'b00000000;
TXRegFile7 <= 8'b00000000;
TXRegFile8 <= 8'b00000000;
TXRegFile9 <= 8'b00000000;
TXRegFile10 <= 8'b00000000;
TXRegFile11 <= 8'b00000000;
TXRegFile12 <= 8'b00000000;
TXRegFile13 <= 8'b00000000;
TXRegFile14 <= 8'b00000000;
TXRegFile15 <= 8'b00000000;
end
else
begin
TXRegFile0 <= NextTXRegFile0;
TXRegFile1 <= NextTXRegFile1;
TXRegFile2 <= NextTXRegFile2;
TXRegFile3 <= NextTXRegFile3;
TXRegFile4 <= NextTXRegFile4;
TXRegFile5 <= NextTXRegFile5;
TXRegFile6 <= NextTXRegFile6;
TXRegFile7 <= NextTXRegFile7;
TXRegFile8 <= NextTXRegFile8;
TXRegFile9 <= NextTXRegFile9;
TXRegFile10 <= NextTXRegFile10;
TXRegFile11 <= NextTXRegFile11;
TXRegFile12 <= NextTXRegFile12;
TXRegFile13 <= NextTXRegFile13;
TXRegFile14 <= NextTXRegFile14;
TXRegFile15 <= NextTXRegFile15;
end
end // p_Seq;
// ------------------------------------------------------------------
// Write logic
// ------------------------------------------------------------------
always @(TXRegFile0 or TXRegFile1 or TXRegFile2 or TXRegFile3 or
TXRegFile4 or TXRegFile5 or TXRegFile6 or TXRegFile7 or
TXRegFile8 or TXRegFile9 or TXRegFile10 or TXRegFile11 or
TXRegFile12 or TXRegFile13 or TXRegFile14 or TXRegFile15 or
RegFileWrEn or PWDATAIn or WrPtr)
begin : p_WrPtrComb
NextTXRegFile0 = TXRegFile0;
NextTXRegFile1 = TXRegFile1;
NextTXRegFile2 = TXRegFile2;
NextTXRegFile3 = TXRegFile3;
NextTXRegFile4 = TXRegFile4;
NextTXRegFile5 = TXRegFile5;
NextTXRegFile6 = TXRegFile6;
NextTXRegFile7 = TXRegFile7;
NextTXRegFile8 = TXRegFile8;
NextTXRegFile9 = TXRegFile9;
NextTXRegFile10 = TXRegFile10;
NextTXRegFile11 = TXRegFile11;
NextTXRegFile12 = TXRegFile12;
NextTXRegFile13 = TXRegFile13;
NextTXRegFile14 = TXRegFile14;
NextTXRegFile15 = TXRegFile15;
if(RegFileWrEn == 1'b1)
case (WrPtr)
4'b0000 : NextTXRegFile0 = PWDATAIn;
4'b0001 : NextTXRegFile1 = PWDATAIn;
4'b0010 : NextTXRegFile2 = PWDATAIn;
4'b0011 : NextTXRegFile3 = PWDATAIn;
4'b0100 : NextTXRegFile4 = PWDATAIn;
4'b0101 : NextTXRegFile5 = PWDATAIn;
4'b0110 : NextTXRegFile6 = PWDATAIn;
4'b0111 : NextTXRegFile7 = PWDATAIn;
4'b1000 : NextTXRegFile8 = PWDATAIn;
4'b1001 : NextTXRegFile9 = PWDATAIn;
4'b1010 : NextTXRegFile10 = PWDATAIn;
4'b1011 : NextTXRegFile11 = PWDATAIn;
4'b1100 : NextTXRegFile12 = PWDATAIn;
4'b1101 : NextTXRegFile13 = PWDATAIn;
4'b1110 : NextTXRegFile14 = PWDATAIn;
4'b1111 : NextTXRegFile15 = PWDATAIn;
default : ;
endcase
end // p_WrPtrComb;
// ------------------------------------------------------------------
// Read Mux
// ------------------------------------------------------------------
assign iTXFIFOData = (RdPtr == 4'b0000) ? TXRegFile0
: (RdPtr == 4'b0001) ? TXRegFile1
: (RdPtr == 4'b0010) ? TXRegFile2
: (RdPtr == 4'b0011) ? TXRegFile3
: (RdPtr == 4'b0100) ? TXRegFile4
: (RdPtr == 4'b0101) ? TXRegFile5
: (RdPtr == 4'b0110) ? TXRegFile6
: (RdPtr == 4'b0111) ? TXRegFile7
: (RdPtr == 4'b1000) ? TXRegFile8
: (RdPtr == 4'b1001) ? TXRegFile9
: (RdPtr == 4'b1010) ? TXRegFile10
: (RdPtr == 4'b1011) ? TXRegFile11
: (RdPtr == 4'b1100) ? TXRegFile12
: (RdPtr == 4'b1101) ? TXRegFile13
: (RdPtr == 4'b1110) ? TXRegFile14
: TXRegFile15;
endmodule
// - =================================================================== End of UartTXRegFile ===================================================================
// ----
uarttxfifo.v
module uarttxfifo (
PCLK,
PRESETn,
UARTEN,
TXE,
UARTDRWrEn,
TXFRdPtrIncSync,
FEN,
AbortSync,
TXBUSYSync,
PWDATAIn,
TXIFLSEL,
TXFF,
TXFE,
RdPtrIncDone,
TXShiftData,
TXDataAvlbl,
BUSY,
CharTxComp,
UARTTXIC,
UARTTXIClr,
TXIM,
UARTTXRIS,
UARTTXMIS,
TXFLTE15Full,
TXIntLevel
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input UARTEN; // UART Enable
input TXE; // TX Enable
input UARTDRWrEn ; // TX FIFO Write enable
input TXFRdPtrIncSync;// TX FIFO Rd Ptr Inc
input FEN; // FIFO Enable
input AbortSync; // Transmission aborted
input TXBUSYSync ; // Transmitter busy
input [7:0] PWDATAIn; // Data bus
input [2:0] TXIFLSEL; // fifo interrupt level select
input UARTTXIC; // For Tx Interrupt clear
input TXIM; // Tx Interrupt Mask
input CharTxComp;
output TXFF; // Transmit FIFO Full
output TXFE; // Transmit FIFO Empty
output RdPtrIncDone; // Rd Ptr Inc done
output [7:0] TXShiftData; // Xmit Data
output TXDataAvlbl; // TX Data Available
output BUSY; // UART BUSY
output UARTTXIClr; // Tx Interrupt clear
output UARTTXRIS; // Transmit Raw Interrupt
output UARTTXMIS; // Transmit Masked Interrupt
output TXFLTE15Full; // To DMA block
output TXIntLevel; // Programmable Interrupt Level
// ------------------------------------------------------------------
// UartTXFIFO
// ==========
// ------------------------------------------------------------------
// Overview
// ========
// Writes to the transmit FIFO occur through the APB interface from
// the PCLK domain. Reads from the transmit FIFO occur from the transmit
// block which falls in the UARTCLK clock domain. The FIFO is 8-bit
// wide and 16-deep.
// The UartTXFCntl module contains the control logic for the FIFO. It
// contains a write pointer, a read pointer and a transmit shift
// register. Writes from the APB can occur as close as every two PCLK
// periods. So as to ensure that no writes are missed, the write
// pointer operates on PCLK. To facilitate FIFO fill level calculation
// the read pointer is also operated on PCLK.
// Write data from the APB is written into the location pointed to by
// the current value of the write pointer. If a write occurs to the
// FIFO when it is already full, the write is ignored.
// The TXDataAvlbl output signal is asserted when there is data
// available to be transmitted. Upon detecting this signal, the
// transmitter commences transmission. At the end of transmission of
// one data byte, the transmitter asserts the RdPtrInc signal.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire UARTEN; // UART Enable (Module Input)
wire TXE; // TX Enable (Module Input)
wire UARTDRWrEn ; // TX FIFO Write enable (Module Input)
wire TXFRdPtrIncSync;// TX FIFO Rd Ptr Inc (Module Input)
wire FEN; // FIFO Enable (Module Input)
wire AbortSync; // Transmission aborted (Module Input)
wire TXBUSYSync ; // Transmitter busy (Module Input)
wire [7:0] PWDATAIn; // Data bus (Module Input)
wire [2:0] TXIFLSEL; // fifo interrupt level select (Module Input)
wire UARTTXIC; // For Tx Interrupt clear(Module Input)
wire TXIM; // Tx Interrupt Mask (Module Input)
wire CharTxComp;
wire [3:0] WrPtr;
wire [3:0] RdPtr;
wire RegFileWrEn;
wire [7:0] iTXFIFOData;
// ------------------------------------------------------------------
// The UartTXRegFile is a data buffer implemented using D-types.
// ------------------------------------------------------------------
uarttxregfile uarttxregfile (
.PCLK (PCLK),
.PRESETn (PRESETn),
.RegFileWrEn (RegFileWrEn),
.WrPtr (WrPtr),
.RdPtr (RdPtr),
.PWDATAIn (PWDATAIn),
.iTXFIFOData (iTXFIFOData)
);
// ------------------------------------------------------------------
// The UartTXFCntl block controls accesses to the FIFO register file.
// ------------------------------------------------------------------
uarttxfcntl uarttxfcntl (
.PCLK (PCLK),
.PRESETn (PRESETn),
.TXBUSYSync (TXBUSYSync),
.UARTDRWrEn (UARTDRWrEn),
.iTXFIFOData (iTXFIFOData),
.PWDATAIn (PWDATAIn),
.TXFRdPtrIncSync(TXFRdPtrIncSync),
.FEN (FEN),
.UARTEN (UARTEN),
.TXE (TXE),
.TXIFLSEL (TXIFLSEL),
.AbortSync (AbortSync),
.TXDataAvlbl (TXDataAvlbl),
.RdPtrIncDone (RdPtrIncDone),
.RegFileWrEn (RegFileWrEn),
.WrPtr (WrPtr),
.RdPtr (RdPtr),
.TXShiftData (TXShiftData),
.TXFF (TXFF),
.TXFE (TXFE),
.BUSY (BUSY),
.CharTxComp (CharTxComp),
.TXIM (TXIM),
.UARTTXIC (UARTTXIC),
.UARTTXIClr (UARTTXIClr),
.UARTTXRIS (UARTTXRIS),
.UARTTXMIS (UARTTXMIS),
.TXFLTE15Full (TXFLTE15Full),
.TXIntLevel (TXIntLevel)
);
endmodule
// - ==================== End of UartTXFIFO ====================
// ----
uarttxfcntl.v
module uarttxfcntl (
PCLK,
PRESETn,
TXBUSYSync,
UARTDRWrEn,
iTXFIFOData,
PWDATAIn,
TXFRdPtrIncSync,
FEN,
UARTEN,
TXE,
TXIFLSEL,
AbortSync,
TXDataAvlbl,
RdPtrIncDone,
RegFileWrEn,
WrPtr,
RdPtr,
TXShiftData,
TXFF,
TXFE,
BUSY,
CharTxComp,
TXIM,
UARTTXIC,
UARTTXIClr,
UARTTXRIS,
UARTTXMIS,
TXFLTE15Full,
TXIntLevel
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input TXBUSYSync; // Transmitter busy
input UARTDRWrEn; // TX FIFO Write enable
input [7:0] iTXFIFOData; // To Shft Reg
input [7:0] PWDATAIn; // Data bus.
input TXFRdPtrIncSync;// TX FIFO Rd Ptr Inc
input FEN; // FIFO Enable
input UARTEN; // UART Enable
input TXE; // TX Enable
input [2:0] TXIFLSEL; // Selected interrupt level
input CharTxComp; // Character Tx complete
input TXIM; // TX Interrupt Mask
input UARTTXIC; // For TX Interrupt clear
input AbortSync; // Transmission aborted
output TXDataAvlbl; // TX Data Available
output RdPtrIncDone; // Rd Ptr Inc done
output RegFileWrEn; // Register file write enable
output [3:0] WrPtr; // Write pointer
output [3:0] RdPtr; // Read pointer
output [7:0] TXShiftData; // Xmit Data
output TXFF; // Transmit FIFO Full
output TXFE; // Transmit FIFO Empty
output BUSY; // UART BUSY
output UARTTXIClr; // Tx Interrupt clear
output UARTTXRIS; // Transmit Raw Interrupt
output UARTTXMIS; // Transmit Masked Interrupt
output TXFLTE15Full; // Transmit Masked Interrupt
output TXIntLevel; // Transmit Masked Interrupt
// ------------------------------------------------------------------
// UartTXFCntl
// ===========
// ------------------------------------------------------------------
// Overview
// ========
// The control logic for the transmit FIFO uses two pointers - a write
// pointer and a read pointer. The pointers are 4 bits wide. The write
// pointer points to the location to which the next write data will be
// written into. The read pointer points to the next location whose
// contents will be read out. Both the pointers operate on PCLK so as
// to not miss any writes from the APB and to conveniently calculate
// the FIFO fill level by finding the difference between the pointers.
// When the FIFO is disabled, the pointers do not change and the fill
// status of the holding buffer is indicated by a separate
// bit 'HldBufValid'.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declarations
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire TXBUSYSync; // Transmitter busy (Module Input)
wire UARTDRWrEn; // TX FIFO Write enable (Module Input)
wire [7:0] iTXFIFOData; // To Shft Reg (Module Input)
wire [7:0] PWDATAIn; // Data bus. (Module Input)
wire TXFRdPtrIncSync;// TX FIFO Rd Ptr Inc (Module Input)
wire FEN; // FIFO Enable (Module Input)
wire UARTEN; // UART Enable (Module Input)
wire TXE; // TX Enable (Module Input)
wire [2:0] TXIFLSEL; // Selected interrupt level (Module Input)
wire CharTxComp; // Character Tx complete (Module Input)
wire TXIM; // TX Interrupt Mask (Module Input)
wire UARTTXIC; // For TX Interrupt clear(Module Input)
wire AbortSync; // Transmission abort (Module Input)
wire LoadShiftReg;
// Shift register load trigge
wire WrPtrIncValid;
// Valid Write pointer increment
wire RdPtrIncValid;
// Valid Read pointer increment
wire TXEdge;
// Detects edge in TXIntLevel
wire HldBufValidEdge;
// Detects edge in HldBufValid
wire [4:0] TXFFillLevel;
// FIFO Fill level indication
reg TXFNotEmpty;
// Signal used to indicate whether any data is available in the FIFO
// when the FIFO is enabled
wire NextTXFNotEmpty;
wire FIFOLTEHalfFull;
// FIFO FillLevel compare result
wire FIFOLTEQFull;
// FIFO Fill level compare result
wire FIFOLTE3QFull;
// FIFO Fill level compare result
wire TXFLTEHalfFull;
// Signal to indicate if the transmit FIFO is less than or equal to
// half full. Used to generate the transmit interrupt UARTTXINTR
wire TXFLTEQFull;
// Signal to indicate if the transmit FIFO is less than or equal to
// a quarter full. Used to generate the transmit interrupt UARTTXINTR
wire TXFLTE3QFull;
// Signal to indicate if the transmit FIFO is less than or equal to
// three quarters full. Used to generate the transmit interrupt
// UARTTXINTR
wire TXFLTE8Full;
// Signal to indicate if the transmit FIFO is less than or equal to
// an eighth full. Used to generate the transmit interrupt UARTTXINTR
wire TXFLTE78Full;
// Signal to indicate if the transmit FIFO is less than or equal to
// seven eighth full. Used to generate the transmit interrupt UARTTXINTR
wire FIFOLTE8Full;
// FIFO Fill level compare result
wire FIFOLTE78Full;
// FIFO Fill level compare result
wire FIFOLTE15Full;
// FIFO Fill level compare result
wire Enabled;
// Is the UART Enabled?
wire TXShiftRegEmptyEdge;
// Is there a transition on the TXShiftRegEmpty?
wire [4:0] WrPtrLevel;
// Signal used to calculate the Tx Fifo fill level
wire [4:0] RdPtrLevel;
// Signal used to calculate the Tx Fifo fill level
// ------------------------------------------------------------------
// Register declarations
// ------------------------------------------------------------------
reg [3:0] RdPtr;
// Read pointer (Module Output)
reg [3:0] NextRdPtr;
// D-input of Read pointer vector
reg [3:0] WrPtr;
// write pointer (Module Output)
reg [3:0] NextWrPtr;
// D-input of the write pointer vector
reg DelRdPtrInc;
// Delayed version of TXFRdPtrIncSync - FIFO read pointer increment
// signal used to convert the level on the TXFRdPtrIncSync signal to
// a one-clock wide pulse
reg Wrap;
// Store the condition when the write pointer has rolled over (from
// '1111' to '0000') but the read pointer hasn't. This signal is
// used in calculating the FIFOFillLevel.
reg NextWrap;
// D-input of Wrap bit
reg TXIntLevel;
// Programmable interrupt level
reg HldBufValid;
// Fill status of the holding register. Used in the case when the
// FIFO is disabled
reg DelHldBufValid;
// delayed version of HldBufValid
reg NextHldBufValid;
// D-input of HldBufValid bit
reg [7:0] TXShiftData;
// TXShiftData vector
reg [7:0] NextTXShiftData;
// D-input of TXShiftData vector
reg TXShiftRegEmpty;
// Fill status of the transmit Shift register
// NOTE : The assertion of this signal does not directly mean that the
// shift register is empty. It only implies that the next write to the
// transmit FIFO should fill up the shift register directly instead
// of accumulating in the FIFO.
reg NxtTXShiftRegEmpty;
// D-input of TXShiftRegEmpty bit
reg TXShiftRegEmptyDel;
// Delayed version of TXShiftRegEmpty
reg UARTTXRIS;
// Transmit Raw input register
reg NextUARTTXRIS;
// D-input of UARTTXRIS
reg DelUARTEN;
// Delayed version of the UARTEN signal. Used to detect a rising edge
// on this signal
reg DelTXE;
// Delayed version of the TXE signal. Used to detect a rising edge on
// this signal
reg FIFOFull;
// FIFO full status indication when the FIFO is enabled
reg NextFIFOFull;
// D-input of FIFOFull bit
reg FIFONotEmpty;
// FIFO empty status indication when the FIFO is enabled
reg NextFIFONotEmpty;
// D-input of FIFONotEmpty bit
reg DelAbort;
// Delayed version of Abort input signal
reg ShiftDataAvlbl;
// Shift register contains valid data that is currently beingtransmitted
reg NextShftDatAvlbl;
// D-input of ShftDataAvlbl signal
reg NextTXIntLevel;
// D-input for Programmable interrupt level
reg DelUARTTXIC;
// Delayed version of UARTTXIC signal
reg DelTXIntLevel;
// Delayed version of TxIntLevel
reg TXDataAvlbl; // TX Data Available
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Indicate the availability of data to transmit to the transmit logic.
// Data is said to be available if the FIFO contains valid data or if
// the Shift Register contains valid data.
// ------------------------------------------------------------------
always@(posedge PCLK or negedge PRESETn)//novas -21013
begin
if(PRESETn == 0)
begin
TXDataAvlbl <= 1'b0;
end
else begin
TXDataAvlbl <= NextTXFNotEmpty | NextShftDatAvlbl;
end
end
// ------------------------------------------------------------------
// The UART is BUSY when there is valid data available in the Transmit
// FIFO or when the Transmitter is busy transmitting.
// ------------------------------------------------------------------
assign BUSY = TXDataAvlbl | TXBUSYSync;
// ------------------------------------------------------------------
// Ignore writes to FIFO if FIFO is already full. Use WrPtrIncValid
// signal as the Write enable. The Write pointer increment operation
// occurs only if the FIFO is enabled, but the WrPtrIncValid signal is
// generated independent of whether the FIFO is enabled or not.
// ------------------------------------------------------------------
assign RegFileWrEn = WrPtrIncValid;
// ------------------------------------------------------------------
// Assert and De-assert Done signal the next clock after TXFRdPtrIncSync
// is seen
// ------------------------------------------------------------------
assign RdPtrIncDone = DelRdPtrInc;
// ------------------------------------------------------------------
// Sequential always process for registers/flip-flops in this block
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_PtrsSeq
if (PRESETn == 1'b0)
begin
WrPtr <= 4'b0000;
RdPtr <= 4'b0000;
DelRdPtrInc <= 1'b0;
Wrap <= 1'b0;
HldBufValid <= 1'b0;
TXShiftData <= 8'b00000000;
TXShiftRegEmpty <= 1'b1;
TXShiftRegEmptyDel <= 1'b1;
UARTTXRIS <= 1'b0;
DelUARTEN <= 1'b0;
DelTXE <= 1'b1;
FIFOFull <= 1'b0;
FIFONotEmpty <= 1'b0;
DelAbort <= 1'b0;
ShiftDataAvlbl <= 1'b0;
TXIntLevel <= 1'b0;
DelUARTTXIC <= 1'b0;
DelTXIntLevel <= 1'b0;
DelHldBufValid <= 1'b0;
end
else
begin
WrPtr <= NextWrPtr;
RdPtr <= NextRdPtr;
DelRdPtrInc <= TXFRdPtrIncSync;
Wrap <= NextWrap;
HldBufValid <= NextHldBufValid;
TXShiftData <= NextTXShiftData;
TXShiftRegEmpty <= NxtTXShiftRegEmpty;
TXShiftRegEmptyDel <= TXShiftRegEmpty;
UARTTXRIS <= NextUARTTXRIS;
DelUARTEN <= UARTEN;
DelTXE <= TXE;
FIFOFull <= NextFIFOFull;
FIFONotEmpty <= NextFIFONotEmpty;
DelAbort <= AbortSync;
ShiftDataAvlbl <= NextShftDatAvlbl;
TXIntLevel <= NextTXIntLevel;
DelUARTTXIC <= UARTTXIC;
DelTXIntLevel <= TXIntLevel;
DelHldBufValid <= HldBufValid;
end
end // p_PtrsSeq;
// ------------------------------------------------------------------
// Load the shift register with transmit data from the FIFO when either
// of the following conditions occur:
// * The UART is just enabled, and there is no Abort condition
// * The Abort condition is just removed and the UART is already enabled
// * The Read pointer increment signal (TXFRdPtrIncSync) signal is just
// asserted with the UART being enabled and there being no Abort
// condition.
// ------------------------------------------------------------------
assign LoadShiftReg = ((UARTEN & TXE) & !(AbortSync) &
((DelAbort | !(DelUARTEN) | !(DelTXE)) &
!(ShiftDataAvlbl)) | (TXFRdPtrIncSync &
!(DelRdPtrInc))) & CharTxComp;
// ------------------------------------------------------------------
// Increment the write pointer when there is a write to the FIFO from
// the APB. The increment should be avoided if the transmit FIFO is
// already full or if the TXShiftRegEmpty signal is asserted indicating
// that the next write should go to the shift register directly. If
// TXShiftRegEmpty is not already asserted and if it is about to be
// asserted on the next PCLK (as indicated by the assertion of LoadShift
// Reg with the FIFO being empty), then the write data is to be written
// into the Shift register and not into the FIFO.
// ------------------------------------------------------------------
assign WrPtrIncValid = UARTDRWrEn & ( !(TXShiftRegEmpty) |
( !(TXShiftRegEmpty) & LoadShiftReg & !(TXFNotEmpty))) & ( !(TXFF)
| (TXFF & LoadShiftReg));
// ------------------------------------------------------------------
// Freeze the Write pointer at zero when the FIFO is disabled. When the
// FIFO is enabled and when the WrPtrIncValid signal is asserted,
// increment the Write pointer by 1.
// ------------------------------------------------------------------
always @(*)
begin : p_WrPtrComb
if (FEN == 1'b0)
NextWrPtr = 4'b0000;
else if (WrPtrIncValid == 1'b1)
NextWrPtr = ((WrPtr) + 1'b1);
else
NextWrPtr = WrPtr;
end // p_WrPtrComb;
// ------------------------------------------------------------------
// Increment the read pointer when the FIFO is not already empty and
// either the Shift register is loaded with the next transmit data byte
// or if the fifo is in testmode and there is a read from the fifo.
// ------------------------------------------------------------------
assign RdPtrIncValid = TXFNotEmpty & LoadShiftReg ;
// ------------------------------------------------------------------
// Freeze the read pointer at zero when the FIFO is disabled. When the
// FIFO is enabled and the RdPtrIncValid signal is asserted, increment
// the Read pointer by 1.
// ------------------------------------------------------------------
always @(*)
begin : p_RdPtrComb
if (FEN == 1'b0)
NextRdPtr = 4'b0000;
else if (RdPtrIncValid == 1'b1)
NextRdPtr = ((RdPtr) + 1'b1);
else
NextRdPtr = RdPtr;
end // p_RdPtrComb;
// ------------------------------------------------------------------
// The 'Wrap' bit is used to keep track of the condition when the
// write pointer has wrapped around from '1111' to '0000', but
// the read pointer has not wrapped. This bit is used to calculate
// the FIFOFillLevel. As with the pointers, 'Wrap' is kept
// cleared when the FIFO is disabled.
// ------------------------------------------------------------------
always @ (*)
begin : p_WrapComb
if (FEN == 1'b0)
NextWrap = 1'b0;
else if (((WrPtr == 4'b1111) & (WrPtrIncValid == 1'b1)) ^
((RdPtr == 4'b1111) & (RdPtrIncValid == 1'b1)))
NextWrap = !(Wrap);
else
NextWrap = Wrap;
end // p_WrapComb;
// ------------------------------------------------------------------
// The FIFOFull signal indicates the status of the FIFO when it is
// enabled. When the FIFO is one less than full and there is
// another write to the FIFO, the FIFOFull signal is set. When
// the FIFO is already full and there is a read from the FIFO,
// the FIFOFull signal is de-asserted
// ------------------------------------------------------------------
always @(*)
begin : p_FIFOFull
if (FEN == 1'b0)
NextFIFOFull = 1'b0;
else if ((TXFFillLevel == 5'b01111) && (WrPtrIncValid == 1'b1) &&
(RdPtrIncValid == 1'b0))
NextFIFOFull = 1'b1;
else if ((FIFOFull == 1'b1) && (RdPtrIncValid == 1'b1) &&
(WrPtrIncValid == 1'b0))
NextFIFOFull = 1'b0;
else
NextFIFOFull = FIFOFull;
end // p_FIFOFull;
// ------------------------------------------------------------------
// The FIFONotEmpty signal indicates the status of the FIFO when it is
// enabled. If the FIFO is empty and there is a write to the FIFO,
// the FIFONotEmpty signal is asserted. If one location in the FIFO
// is filled and there is a read from the FIFO, the FIFOEmpty
// signal is asserted.
// ------------------------------------------------------------------
always @(*)
begin : p_FIFONotEmpty
if (FEN == 1'b0)
NextFIFONotEmpty = 1'b0;
else if ((FIFONotEmpty == 1'b0) && (WrPtrIncValid == 1'b1))
NextFIFONotEmpty = 1'b1;
else if ((TXFFillLevel == 5'b00001) && (RdPtrIncValid == 1'b1) &&
(WrPtrIncValid == 1'b0))
NextFIFONotEmpty = 1'b0;
else
NextFIFONotEmpty = FIFONotEmpty;
end // p_FIFONotEmpty;
// ------------------------------------------------------------------
// When the FIFO is disabled, have a single bit to indicate fill status
// while the pointers are frozen at zero. The HldBufValid signal has a
// reset value of 0, toggles to 1 when there is a write and back to
// zero when there is a read. The write and read requests can occur
// simultaneously. The two cases to be considered are when HldBufValid
// is 1 and when it is 0. When a write and read occur simultaneously
// with a byte already in the holding buffer (HldBufValid == 1), the
// write is allowed and HldBufValid remains set (untoggled). When
// HldBufValid is 0 (holding buffer empty), a read cannot occur because
// reads are from the Transmit section which reads data from the
// buffer only if valid data is available.
// ------------------------------------------------------------------
always @(*)
begin : p_BufValid
if (FEN == 1'b1)
NextHldBufValid = 1'b0;
else if ((WrPtrIncValid == 1'b1) ^ (RdPtrIncValid == 1'b1))
NextHldBufValid = !(HldBufValid);
else
NextHldBufValid = HldBufValid;
end // p_BufValid;
// ------------------------------------------------------------------
// Fill status of the transmit Shift register
// NOTE : The assertion of this signal does not directly mean that
// the shift register is empty. It only implies that the next write
// to the transmit FIFO should fill up the shift register directly,
// instead of accumulating in the FIFO
// ------------------------------------------------------------------
always @(*)
begin : p_ShiftRegEmpty
// ------------------------------------------------------------------
// If the UART is disabled, then writes should accumulate in the FIFO
// without updating the transmit shift register
// ------------------------------------------------------------------
if ((UARTEN == 1'b0) || (AbortSync == 1'b1))
NxtTXShiftRegEmpty = 1'b0;
// ------------------------------------------------------------------
// If the FIFO is already empty and the shift register has to be loaded
// with transmit data and there is no write occuring to the FIFO, the
// TXShiftRegEmpty signal is set.
// ------------------------------------------------------------------
else if ((LoadShiftReg == 1'b1) && (TXFNotEmpty == 1'b0) &&
(UARTDRWrEn == 1'b0))
NxtTXShiftRegEmpty = 1'b1;
// ------------------------------------------------------------------
// Else, if there is a write to the FIFO, the shift register is no
// longer empty
// ------------------------------------------------------------------
else if (UARTDRWrEn == 1'b1)
NxtTXShiftRegEmpty = 1'b0;
else
NxtTXShiftRegEmpty = TXShiftRegEmpty;
end // p_ShiftRegEmpty;
// TXShiftRegEmpty edges are only signalled when the UART is enabled.
assign Enabled = UARTEN & TXE;
assign TXShiftRegEmptyEdge = (Enabled == 1'b0) ? 1'b0
: (TXShiftRegEmpty ^ TXShiftRegEmptyDel);
// ------------------------------------------------------------------
// The TXShiftData register holds the transmit data byte.
// ------------------------------------------------------------------
always @ (*)
begin : p_TXShiftData
// ------------------------------------------------------------------
// If the FIFO and the shift register are empty, then on the next write,
// move the write data straight into the shift register.
// If the TXShiftRegEmpty signal is already set or if the Shift register
// has to be loaded with the next transmit byte with the transmit FIFO
// being empty, and, if there is a write to the FIFO at the same time,
// the write data bus contents are copied directly into the Shift
// register.
// ------------------------------------------------------------------
if ((UARTDRWrEn == 1'b1) && ((TXShiftRegEmpty == 1'b1) ||
((TXFNotEmpty == 1'b0) && (LoadShiftReg == 1'b1))))
NextTXShiftData = PWDATAIn;
// ------------------------------------------------------------------
// If the Shift register has to be loaded with the next transmit data
// byte and the FIFO is not empty, then load the data in the FIFO
// pointed to by the current value of the read pointer, into the shift
// register.
// ------------------------------------------------------------------
else if ((LoadShiftReg == 1'b1) && (TXFNotEmpty == 1'b1))
NextTXShiftData = iTXFIFOData;
else
NextTXShiftData = TXShiftData;
end // p_TXShiftData;
// ------------------------------------------------------------------
// The ShiftDataAvlbl signal indicates whether there is valid data
// present in the Transmit shift register. This signal is used to
// generate the TXDataAvlbl output signal.
// ------------------------------------------------------------------
always @(*)
begin : p_ShiftDataAvlbl
if ((TXFNotEmpty == 1'b0) && (UARTDRWrEn == 1'b0))
begin
if ((LoadShiftReg == 1'b1) || (CharTxComp == 1'b1 &&
(UARTEN == 1'b0 || TXE == 1'b0) && TXShiftRegEmpty == 1'b1))
NextShftDatAvlbl = 1'b0;
else
NextShftDatAvlbl = ShiftDataAvlbl;
end
else if ((TXFNotEmpty == 1'b1) && (UARTEN == 1'b0 || TXE == 1'b0))
NextShftDatAvlbl = 1'b0;
else if (((LoadShiftReg == 1'b1) && (TXFNotEmpty == 1'b1) &&
(TXE == 1'b1)) || ((LoadShiftReg == 1'b1) &&
(TXFNotEmpty == 1'b0) && (TXE == 1'b1) &&
(UARTDRWrEn == 1'b1)) || ((TXShiftRegEmpty == 1'b1) &&
(UARTDRWrEn == 1'b1) && (TXE == 1'b1)))
NextShftDatAvlbl = 1'b1;
else
NextShftDatAvlbl = ShiftDataAvlbl;
end // p_ShiftDataAvlbl;
// ------------------------------------------------------------------
// The interrupt fifo level is programmable, it can be either at the
// one eighth, quarter, half, three quarter or seven eighth level.
// ------------------------------------------------------------------
always @(*)
begin : p_TXIntLevel
NextTXIntLevel = TXIntLevel;
case (TXIFLSEL)
3'b000 : NextTXIntLevel = TXFLTE8Full;
3'b001 : NextTXIntLevel = TXFLTEQFull;
3'b010 : NextTXIntLevel = TXFLTEHalfFull;
3'b011 : NextTXIntLevel = TXFLTE3QFull;
3'b100 : NextTXIntLevel = TXFLTE78Full;
default: NextTXIntLevel = 1'b0;
endcase
end // p_TXIntLevel;
// ------------------------------------------------------------------
// UARTTXIClr is a one PCLK-wide pulse used to clear the UARTTXINTR.
// ------------------------------------------------------------------
assign UARTTXIClr = UARTTXIC & !(DelUARTTXIC);
// ------------------------------------------------------------------
// Detect an edge in the interrupt level line and HldBufValid line.
// ------------------------------------------------------------------
assign TXEdge = TXIntLevel ^ DelTXIntLevel;
assign HldBufValidEdge = HldBufValid ^ DelHldBufValid;
// ------------------------------------------------------------------
// Assert the transmit interrupt when either of the following
// conditions are met :
// * The FIFO is enabled and is emptied such that its fill level
// is equal to or below its programmed level
// * The FIFO is disabled and the holding register is empty
// The transmit interrupt is de-asserted when the condition which
// led to its assertion is no longer met. It can also be cleared by
// a write to bit 5 of the Interrupt Clear register.
// ------------------------------------------------------------------
always @(*)
begin : p_UARTTXINTR
NextUARTTXRIS = UARTTXRIS;
if ((FEN == 1'b1) && (TXIntLevel == 1'b1) && (TXEdge == 1'b1))
NextUARTTXRIS = 1'b1;
else if ((FEN == 1'b0) && (HldBufValid == 1'b0) && (HldBufValidEdge == 1'b1))
NextUARTTXRIS = 1'b1;
else if ((FEN == 1'b0) && (HldBufValid == 1'b0) && (UARTTXRIS == 1'b0) &&
(TXShiftRegEmpty == 1'b0) && (TXShiftRegEmptyEdge == 1'b1))
NextUARTTXRIS = 1'b1;
else if (((FEN == 1'b1) && (TXIntLevel == 1'b0) && (TXEdge == 1'b1)) ||
((FEN == 1'b0) && (HldBufValid == 1'b1) && (HldBufValidEdge == 1'b1)))
NextUARTTXRIS = 1'b0;
else if (UARTTXIClr == 1'b1)
NextUARTTXRIS = 1'b0;
end // p_UARTTXINTR
assign UARTTXMIS = UARTTXRIS & TXIM;
// ------------------------------------------------------------------
// Subtract the read pointer from the write pointer to calculate
// the FIFO fill level. Use the Wrap bit to take into account
// whether the write pointer has wrapped without the read pointer
// not having wrapped
// ------------------------------------------------------------------
assign WrPtrLevel = {Wrap,WrPtr};
assign RdPtrLevel = {1'b0,RdPtr};
assign TXFFillLevel = (WrPtrLevel - RdPtrLevel);
// ------------------------------------------------------------------
// When the FIFO is enabled, use the FIFOFull signal to indicate
// FIFO fill status. When the FIFO is disabled, use the
// HldBufValid signal to indicate FIFO fill status.
// ------------------------------------------------------------------
assign TXFF = (FEN == 1'b1) ? FIFOFull : HldBufValid;
// ------------------------------------------------------------------
// When the FIFO is enabled, use the FIFONotEmpty signal to indicate
// FIFO fill status. When the FIFO is disabled, use the
// HldBufValid signal to indicate FIFO fill status.
// ------------------------------------------------------------------
assign NextTXFNotEmpty = (FEN == 1'b1) ? NextFIFONotEmpty : NextHldBufValid;
assign TXFE = !TXFNotEmpty;
always@(posedge PCLK or negedge PRESETn)
begin
if(PRESETn == 0)
begin
TXFNotEmpty <= 1'b0;
end
else begin
TXFNotEmpty <= NextTXFNotEmpty;
end
end
// ------------------------------------------------------------------
// When the FIFO is enabled, use the TXFFillLevel signal to
// find whether the FIFO is less than or equal to an eighth full,
// quarter full, half full, three quarter full or seven eighth full.
// If the FIFO is disabled, the HldBufValid signal will do the job.
// ------------------------------------------------------------------
assign FIFOLTE8Full = (TXFFillLevel <= 5'b00010);
assign TXFLTE8Full = (FEN == 1'b1) ? FIFOLTE8Full : !HldBufValid;
assign FIFOLTEQFull = ((TXFFillLevel) <= 5'b00100);
assign TXFLTEQFull = (FEN == 1'b1) ? FIFOLTEQFull : !HldBufValid;
assign FIFOLTEHalfFull = (TXFFillLevel <= 5'b01000);
assign TXFLTEHalfFull = (FEN == 1'b1) ? FIFOLTEHalfFull : !HldBufValid;
assign FIFOLTE3QFull = ((TXFFillLevel) <= 5'b01100);
assign TXFLTE3QFull = (FEN == 1'b1) ? FIFOLTE3QFull : !HldBufValid;
assign FIFOLTE78Full = (TXFFillLevel <= 5'b01110);
assign TXFLTE78Full = (FEN == 1'b1) ? FIFOLTE78Full : !HldBufValid;
// ------------------------------------------------------------------
// When the FIFO is enabled, use the TXFFillLevel signal to find
// whether the Transmit FIFO has at least one empty location. If the
// FIFO is disabled, the HldBufValid signal will do the job. When the
// transmit FIFO has at least one empty location the TXFLE15Full
// signal is asserted.
// ------------------------------------------------------------------
assign FIFOLTE15Full = (TXFFillLevel <= 5'b01111);
assign TXFLTE15Full = (FEN == 1'b1) ? FIFOLTE15Full : ~HldBufValid;
endmodule
// - ==================== End of UartTXFCntl ====================
uarttxcntl.v
module uarttxcntl (
UARTCLK,
nUARTRST,
RXEnable,
UartRXCntlState,
CTSEn,
nCTSSyncUARTCLK,
Baud16,
TXDataAvlblSync,
RdPtrIncDoneSync,
UARTENSync,
TXESync,
TXShiftData,
WLEN,
STP2,
PEN,
EPS,
BRK,
Zerobaud,
SPS,
TXFRdPtrInc,
TXD,
TXBUSY,
CharTxComp,
StopBaudCnt
);
input UARTCLK ; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input RXEnable; // Rx Enable
input [2:0] UartRXCntlState; // RX state
input CTSEn; // CTS flow control enable
input nCTSSyncUARTCLK; // modem signal
input Baud16; // Bit Period ref
input TXDataAvlblSync; // TX Data Available
input RdPtrIncDoneSync; // TX FIFO Rd pointer Inc done
input UARTENSync; // UART Enable
input TXESync; // TX Enable
input [7:0] TXShiftData; // TX Data
input [1:0] WLEN; // Bits per word
input STP2; // 2 stop bits
input PEN; // Parity enabled
input EPS; // Even Parity Select
input BRK; // Transmit Break
input Zerobaud; // Baud divisor set to 0
input SPS; // Stick Parity Select bit
output TXFRdPtrInc; // TX FIFO Rd Ptr Inc
output TXD; // Internal Transmit Line
output TXBUSY; // Transmitter busy
output CharTxComp; // Character Tx complete
output StopBaudCnt; // Stop Baud Counter
// ------------------------------------------------------------------
// UartTXCntl
// ==========
// ------------------------------------------------------------------
// Overview
// ========
// The transmit state machine shifts out transmit data according to the
// parameters programmed in the LCR_H register. When a Break is to be
// transmitted, the transmit line is pulled LOW. The duration for which
// the TXD line remains low is directly dependent on the duration for
// which the Break bit is set. After break bit is set to 1, the TX line
// is pulled high and for 1 bit time, data transmission is stopped
// to avoid potential glitches in the SIROUT line. If the Uart is
// disabled during transmission the current word will be transmitted and
// then transmission will stop.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK ; // Main UART Clock (Module Input)
wire nUARTRST; // Muxed reset (from nUARTRST)(Module Input)
wire Baud16; // Bit Period ref (Module Input)
wire TXDataAvlblSync; // TX Data Available (Module Input)
wire RdPtrIncDoneSync; // TX FIFO Rd pointer Inc done(Module Input)
wire UARTENSync; // UART Enable (Module Input)
wire TXESync; // TX Enable (Module Input)
wire [1:0] WLEN; // Bits per word (Module Input)
wire STP2; // 2 stop bits (Module Input)
wire PEN; // Parity enabled (Module Input)
wire EPS; // Even Parity Select (Module Input)
wire BRK; // Transmit Break (Module Input)
wire Zerobaud; // Baud divisor set to 0 (Module Input)
wire [7:0] TXShiftData; // TX Data (Module Input)
wire RXEnable; // Rx Enable (Module Input)
wire [2:0] UartRXCntlState; // RX state (Module Input)
wire CTSEn; // CTS flow control enable (Module Input)
wire nCTSSyncUARTCLK; // modem signal (Module Input)
wire SPS; // Stick Parity Select bit (Module Input)
// Aliases
wire AbortTransmit;
wire TXEnable;
wire nBreak;
wire LEN5;
wire LEN6;
wire LEN7;
wire LEN8;
wire Parity;
// Comparators
wire BitCountComp;
wire BitPeriodCmp;
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg TXFRdPtrInc; // TX FIFO Rd Ptr Inc (Module Output)
reg TXBUSY; // Transmitter busy (Module Output)
reg CharTxComp; // Character Tx complete (Module Output)
reg StopBaudCnt; // Stop Baud Counter (Module Output)
// Encoding style: Gray
reg [3:0] UartTXCntlState;
reg [3:0] UartTXCntlNextState;
reg NextTXFRdPtrInc;
reg NextTXBUSY;
// Registers
reg TXDReg;
reg NextTXDReg;
reg [2:0] BitCount;
reg [2:0] NextBitCount;
reg [3:0] BitPeriodCnt;
reg [3:0] NextBitPeriodCnt;
reg [6:0] TXShiftReg;
reg [6:0] NextTXShiftReg;
reg NextCharTxComp;
// ------------------------------------------------------------------
// Expose internal register(s)....
// ------------------------------------------------------------------
assign TXD = TXDReg;
// ------------------------------------------------------------------
// Expansion of aliases...
// ------------------------------------------------------------------
assign AbortTransmit = BRK | Zerobaud;
assign TXEnable = (UARTENSync & TXESync);
assign nBreak = !(BRK);
assign LEN5 = !(WLEN[1]) & !(WLEN[0]) & (!(EPS) ^ TXShiftData[4]
^ TXShiftData[3] ^ TXShiftData[2] ^ TXShiftData[1]
^ TXShiftData[0]);
assign LEN6 = !(WLEN[1]) & WLEN[0] & (!(EPS) ^ TXShiftData[5]
^ TXShiftData[4] ^ TXShiftData[3] ^ TXShiftData[2]
^ TXShiftData[1] ^ TXShiftData[0]);
assign LEN7 = WLEN[1] & !(WLEN[0]) & (!(EPS) ^ TXShiftData[6] ^
TXShiftData[5] ^ TXShiftData[4] ^ TXShiftData[3] ^
TXShiftData[2] ^ TXShiftData[1] ^ TXShiftData[0]);
assign LEN8 = WLEN[1] & WLEN[0] & (!(EPS) ^ TXShiftData[7] ^
TXShiftData[6] ^ TXShiftData[5] ^ TXShiftData[4] ^
TXShiftData[3] ^ TXShiftData[2] ^ TXShiftData[1] ^
TXShiftData[0]);
assign Parity = LEN5 | LEN6 | LEN7 | LEN8;
// ------------------------------------------------------------------
// Expansion of comparators...
// ------------------------------------------------------------------
assign BitCountComp = (BitCount[2:0] == 3'b000);
assign BitPeriodCmp = (BitPeriodCnt[3:0] == 4'b0000);
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin : p_StopBaudCnt
if (nUARTRST == 1'b0)
StopBaudCnt <= 1'b1;
else if (((UartTXCntlState == 4'b0000) && (TXEnable == 1'b0)) &&
((UartRXCntlState == 3'b000) && (RXEnable == 1'b0)))
StopBaudCnt <= 1'b1;
else
StopBaudCnt <= 1'b0;
end // p_StopBaudCnt;
// ------------------------------------------------------------------
// State transition process
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : seq
if (nUARTRST == 1'b0)
begin
UartTXCntlState <= 4'b0000;
TXFRdPtrInc <= 1'b0;
TXBUSY <= 1'b0;
CharTxComp <= 1'b1;
end
else
begin
UartTXCntlState <= UartTXCntlNextState;
TXFRdPtrInc <= NextTXFRdPtrInc;
TXBUSY <= NextTXBUSY;
CharTxComp <= NextCharTxComp;
end
end // seq;
// ------------------------------------------------------------------
// Output and next state logic generation
// ------------------------------------------------------------------
always @(*)
begin : combo
// Default assignments
UartTXCntlNextState = UartTXCntlState;
NextTXFRdPtrInc = 1'b0;
NextTXBUSY = 1'b0;
NextTXDReg = TXDReg;
NextBitCount = BitCount;
NextBitPeriodCnt = BitPeriodCnt;
NextTXShiftReg = TXShiftReg;
NextCharTxComp = CharTxComp;
case (UartTXCntlState)
4'b0000 :
begin
// Transmit data is available and Baud16 is also asserted,
// so shift out the start bit
if ((TXDataAvlblSync & Baud16 & TXEnable & !(AbortTransmit)) == 1'b1)
begin
// Transmit data available in the FIFO, so wait for the next
// Baud16 before shifting out the start bit.
//
// The following has a priority for CTS. If CTS is enabled
// then transmission can only proceed when nUARTCTS is low.
// Else wait for it to be low before proceeding.
//
// If CTS is not enabled, then proceed as normal.
if (CTSEn == 1'b1)
begin
if (nCTSSyncUARTCLK == 1'b0)
begin
NextTXDReg = 1'b0;
NextBitPeriodCnt = 4'b1111;
NextBitCount[2:0] = {1'b1, WLEN[1:0]};
UartTXCntlNextState = 4'b0001;
NextCharTxComp = 1'b0;
NextTXBUSY = 1'b1;
end
else
UartTXCntlNextState = 4'b0000;
end
else
begin
NextTXDReg = 1'b0;
NextBitPeriodCnt = 4'b1111;
NextBitCount[2:0] = {1'b1, WLEN[1:0]};
UartTXCntlNextState = 4'b0001;
NextCharTxComp = 1'b0;
NextTXBUSY = 1'b1;
end
end
else if (((!(AbortTransmit)) && !(Baud16) && TXEnable && TXDataAvlblSync) == 1'b1)
begin
if (CTSEn == 1'b1)
begin
if (nCTSSyncUARTCLK == 1'b0)
begin
UartTXCntlNextState = 4'b0101;
NextTXBUSY = 1'b1;
end
else
UartTXCntlNextState = 4'b0000;
end
else
begin
UartTXCntlNextState = 4'b0101;
NextTXBUSY = 1'b1;
end
end
else if ((BRK) == 1'b1)
begin
NextTXDReg = 1'b0;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0100;
NextCharTxComp = 1'b1;
NextTXBUSY = 1'b1;
end
else if ((!(TXEnable)) == 1'b1)
begin
NextTXDReg = TXDReg;
NextBitPeriodCnt = 4'b1111;
NextBitCount = 3'b000;
UartTXCntlNextState = UartTXCntlState;
NextTXShiftReg = 7'b0000000;
NextTXFRdPtrInc = 1'b0;
NextTXBUSY = 1'b0;
end
else
begin
NextTXFRdPtrInc = 1'b0;
NextTXBUSY = 1'b0;
end
end
4'b0001 :
begin
// Shift out the first data bit, increment BitCnt, reload the
// BitPeriodCnt counter and load the transmit shift register.
if ((Baud16 & BitPeriodCmp & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = TXShiftData[0];
NextBitPeriodCnt = 4'b1111;
NextTXShiftReg[6:0] = TXShiftData[7:1];
UartTXCntlNextState = 4'b0011;
NextCharTxComp = 1'b0;
NextTXBUSY = 1'b1;
// Decrement the BitPeriodCnt counter with Baud16 as the
// count enable to time the start bit.
end
else if ((Baud16 & !(BitPeriodCmp) & !(AbortTransmit)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartTXCntlNextState = 4'b0001;
NextTXBUSY = 1'b1;
end
else
NextTXBUSY = 1'b1;
if ((AbortTransmit) == 1'b1)
begin
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
NextTXDReg = nBreak;
NextTXShiftReg = 7'b0000000;
UartTXCntlNextState = 4'b0111;
NextCharTxComp = 1'b0;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
end
4'b0011 :
begin
// At the end of a bit period, shift in the next bit and reload
// the BitPeriodCnt counter
if ((!(BitCountComp) & BitPeriodCmp & Baud16 & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = TXShiftReg[0];
NextBitCount = BitCount - 1'b1;
NextBitPeriodCnt = 4'b1111;
NextTXShiftReg[5:0] = TXShiftReg[6:1];
NextTXShiftReg[6] = 1'b0;
UartTXCntlNextState = 4'b0011;
NextTXBUSY = 1'b1;
// With Baud16 as the count enable, decrement the BitPeriodCnt
end
else if ((Baud16 & !(BitPeriodCmp) & !(AbortTransmit)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartTXCntlNextState = 4'b0011;
NextTXBUSY = 1'b1;
// All data bits transmitted, parity bit next.
end
else if ((Baud16 & BitPeriodCmp & PEN & !(AbortTransmit) & BitCountComp) == 1'b1)
begin
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0010;
NextCharTxComp = 1'b0;
NextTXBUSY = 1'b1;
if ((SPS & EPS) == 1'b1)
NextTXDReg = 1'b0;
else if ((SPS & !(EPS)) == 1'b1)
NextTXDReg = 1'b1;
else
NextTXDReg = Parity;
// All data bits transmitted. No parity bit programmed,
// but extra stop bit required.
end
else if ((Baud16 & BitPeriodCmp & BitCountComp & !(PEN) & STP2 & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0110;
NextCharTxComp = 1'b1;
NextTXBUSY = 1'b1;
// All data bits transmitted. No parity bit programmed,
// one stop bit programmed.
end
else if ((Baud16 & BitPeriodCmp & BitCountComp & !(PEN) & !(STP2) & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0111;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
else
NextTXBUSY = 1'b1;
if ((AbortTransmit) == 1'b1)
begin
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
NextTXDReg = nBreak;
NextTXShiftReg = 7'b0000000;
UartTXCntlNextState = 4'b0111;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
end
4'b0010 :
begin
// 2 stop bits programmed, so transmit additional stop bit first
if ((Baud16 & BitPeriodCmp & STP2 & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0110;
NextCharTxComp = 1'b1;
NextTXBUSY = 1'b1;
end
else if ((Baud16 & !(BitPeriodCmp) & !(AbortTransmit)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartTXCntlNextState = 4'b0010;
NextTXBUSY = 1'b1;
// Only one stop bit
end
else if ((Baud16 & BitPeriodCmp & !(STP2) & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0111;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
else
NextTXBUSY = 1'b1;
if ((AbortTransmit) == 1'b1)
begin
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
NextTXDReg = nBreak;
NextTXShiftReg = 7'b0000000;
UartTXCntlNextState = 4'b0111;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
end
4'b0110 :
begin
if ((Baud16 & !(BitPeriodCmp) & !(AbortTransmit)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartTXCntlNextState = 4'b0110;
NextTXBUSY = 1'b1;
// One stop bit shifted out, now move to the stop p state to
// shift out the next stop bit
end
else if ((Baud16 & BitPeriodCmp & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0111;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
else
NextTXBUSY = 1'b1;
if ((AbortTransmit) == 1'b1)
begin
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
NextTXDReg = nBreak;
NextTXShiftReg = 7'b0000000;
UartTXCntlNextState = 4'b0111;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
end
4'b0111 :
begin
// If the FIFO has completed the write and there is no more
// data available to be transmitted, then wait for transmit
// data
if (((AbortTransmit | (BitPeriodCmp & Baud16 & !(TXDataAvlblSync))) & RdPtrIncDoneSync) == 1'b1)
begin
NextTXDReg = nBreak;
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
NextTXShiftReg = 7'b0000000;
UartTXCntlNextState = 4'b0000;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b0;
NextTXBUSY = 1'b0;
end
// If the FIFO has completed the write and the last stop
// bit is complete and there is more data available for
// transmission, then if Transmit is enabled proceed with the
// transmission of the next data, otherwise go to the idle
// state and wait for an enable signal
else if ((!(AbortTransmit) & TXDataAvlblSync & Baud16 & BitPeriodCmp & RdPtrIncDoneSync) == 1'b1)
begin
NextBitCount[2:0] = {1'b1, WLEN[1:0]};
NextBitPeriodCnt = 4'b1111;
NextCharTxComp = 1'b1;
NextTXBUSY = 1'b1;
// ----------------------------------------
// For Flow Control need to check whether it is still okay to send
// further data (CTSEn = '1' and nCTSSyncUARTCLK = '0').
// Otherwise normal operation resumes.
// ----------------------------------------
if (CTSEn == 1'b1)
begin
if (nCTSSyncUARTCLK == 1'b0)
begin
UartTXCntlNextState = 4'b0001;
NextTXDReg = 1'b0;
end
else
begin
UartTXCntlNextState = 4'b0000;
NextTXDReg = 1'b1;
end
end
else if (TXEnable == 1'b1)
begin
UartTXCntlNextState = 4'b0001;
NextTXDReg = 1'b0;
end
else
begin
UartTXCntlNextState = 4'b0000;
NextTXDReg = 1'b1;
end
end
else if ((Baud16 & !(BitPeriodCmp) & !(AbortTransmit)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartTXCntlNextState = 4'b0111;
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
else
begin
NextTXFRdPtrInc = 1'b1;
NextTXBUSY = 1'b1;
end
end
4'b0101 :
begin
// Transmit the start bit when the next Baud16 pulse is seen.
// Load BitPeriodCnt with '1111' to count 16 Baud16 pulses
// before the next bit. Also clear the BitCnt counter (which indicates
// the number of bits currently shifted out)
if ((Baud16 & !(AbortTransmit)) == 1'b1)
begin
NextTXDReg = 1'b0;
NextBitCount[2:0] = {1'b1, WLEN[1:0]};
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0001;
NextCharTxComp = 1'b0;
NextTXBUSY = 1'b1;
// If an illegal value is written in the
// bit rate divisor then pull the transmit output line HIGH.
end
else if ((AbortTransmit) == 1'b1)
begin
NextTXDReg = nBreak;
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
UartTXCntlNextState = 4'b0000;
NextTXFRdPtrInc = 1'b0;
NextTXBUSY = 1'b0;
end
else
NextTXBUSY = 1'b1;
end
4'b0100 :
begin
// Break cleared, wait for a bit time, to avoid potential
// glitches on nSIROUT line
if ((!(BRK)) == 1'b1)
begin
NextBitPeriodCnt = 4'b1111;
NextTXDReg = 1'b1;
UartTXCntlNextState = 4'b1100;
NextCharTxComp = 1'b1;
end
else
NextTXBUSY = 1'b1;
end
4'b1100 :
begin
if ((Baud16 & BitPeriodCmp & !(BRK)) == 1'b1)
begin
NextTXDReg = 1'b1;
NextBitCount = 3'b000;
NextBitPeriodCnt = 4'b1111;
NextTXShiftReg = 7'b0000000;
UartTXCntlNextState = 4'b0000;
NextCharTxComp = 1'b1;
NextTXFRdPtrInc = 1'b0;
NextTXBUSY = 1'b0;
end
else if ((Baud16 & !(BitPeriodCmp) & !(BRK)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartTXCntlNextState = 4'b1100;
end
else if ((BRK) == 1'b1)
begin
UartTXCntlNextState = 4'b0100;
NextTXBUSY = 1'b1;
NextCharTxComp = 1'b1;
end
end
default :
UartTXCntlNextState = 4'b0000;
endcase
end // combo;
always @(posedge UARTCLK or negedge nUARTRST)
begin : TXDReg_seq
if (nUARTRST == 1'b0)
TXDReg <= 1'b1;
else
TXDReg <= NextTXDReg;
end // TXDReg_seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : BitCount_seq
if (nUARTRST == 1'b0)
BitCount <= 3'b000;
else
BitCount <= NextBitCount;
end // BitCount_seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : BitPeriodCnt_seq
if (nUARTRST == 1'b0)
BitPeriodCnt <= 4'b1111;
else
BitPeriodCnt <= NextBitPeriodCnt;
end // BitPeriodCnt_seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : TXShiftReg_seq
if (nUARTRST == 1'b0)
TXShiftReg <= 7'b0000000;
else
TXShiftReg <= NextTXShiftReg;
end // TXShiftReg_seq;
endmodule
// Signals: UartTXCntlState<3:0> UartTXCntlNextState<3:0>
// ST_IDLE 0000
// ST_STARTBIT 0001
// ST_SHIFT 0011
// ST_PARITY 0010
// ST_XSTOP 0110
// ST_STPRDPTRINC 0111
// ST_DATAAVLBL 0101
// ST_BREAK 0100
// ST_EXITBREAK 1100
// - ==================== End of UartTXCntl ====================
// ----
uartsynctouclk.v
module uartsynctouclk (
UARTCLK ,
nUARTRST,
SIRLP,
SIREN,
UARTEN,
TXE,
RXE,
TXDataAvlbl,
RXFE,
CTSEn,
LCRUpdate,
ILPRUpdate,
FBRDUpdate,
UARTRXDint,
UARTTXDint,
SIRINint,
nSIROUTint,
RXFWrDone,
RdPtrIncDone,
DCDIM,
DSRIM,
CTSIM,
RIIM,
RTIM,
FEIM,
PEIM,
BEIM,
nUARTDCDint,
nUARTDSRint,
nUARTCTSint,
nUARTRIint,
nUARTRTSint ,
nUARTDTRint ,
nUARTOut2int,
nUARTOut1int,
UARTDCDIC,
UARTDSRIC,
UARTCTSIC,
UARTRIIC,
UARTFEIC,
UARTPEIC,
UARTBEIC,
UARTRTIC,
SIRLPSync,
SIRENSync,
UARTENSync,
TXESync,
RXESync,
TXDataAvlblSync,
RXFESync,
CTSEnSyncUCLK,
LCRUpdateSync,
ILPRUpdateSync,
FBRDUpdateSync,
UARTRXDSync,
SIRINSync,
RXFWrDoneSync,
RdPtrIncDoneSync,
DCDIMSync,
DSRIMSync,
CTSIMSync,
RIIMSync,
RTIMSync,
FEIMSync,
PEIMSync,
BEIMSync,
nDCDSyncUARTCLK,
nDSRSyncUARTCLK,
nCTSSyncUARTCLK,
nRISyncUARTCLK,
UARTDCDICSync,
UARTDSRICSync,
UARTCTSICSync,
UARTRIICSync,
UARTFEICSync,
UARTPEICSync,
UARTBEICSync,
UARTRTICSync,
LBE
);
input UARTCLK ; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input SIRLP; // SIR Low power mode
input SIREN; // SIR Enabled
input UARTEN; // UART Enabled
input TXE; // TX Enabled
input RXE; // RX Enabled
input TXDataAvlbl; // TX Data available
input RXFE; // RX FIFO Empty
input CTSEn; //
input LCRUpdate; // Sync control signal for LCR
input ILPRUpdate; // Sync ctrl signal for ILPR
input FBRDUpdate; // Sync ctrl signal for ILPR
input UARTRXDint; // UART Receive input
input UARTTXDint; // UART Receive input
input SIRINint; // SIR Receive input
input nSIROUTint; // SIR Receive input
input RXFWrDone; // RX FIFO Wr Done
input RdPtrIncDone; // Read Pointer Inc Done
input DCDIM; // UARTDCDINTR Interrupt Enable
input DSRIM; // UARTDSRINTR Interrupt Enable
input CTSIM; // UARTCTSINTR Interrupt Enable
input RIIM; // UARTRIINTR Interrupt Enable
input RTIM; // UARTRTINTR Interrupt Enable
input FEIM; // UARTFEINTR Interrupt Enable
input PEIM; // UARTPEINTR Interrupt Enable
input BEIM; // UARTBEINTR Interrupt Enable
input nUARTDCDint; // Modem signal
input nUARTDSRint; // Modem signal
input nUARTCTSint; // Modem signal
input nUARTRIint; // Modem signal
input nUARTRTSint; // Modem signal
input nUARTDTRint; // Modem signal
input nUARTOut2int; // Modem signal
input nUARTOut1int; // Modem signal
input UARTDCDIC; // Modem DCD Intr Clear
input UARTDSRIC; // Modem DSR Intr Clear
input UARTCTSIC; // Modem CTS Intr Clear
input UARTRIIC; // Modem RI Intr Clear
input UARTFEIC; // For Framing Error Intr Clear
input UARTPEIC; // For Parity Error Intr Clear
input UARTBEIC; // For Break Error Intr Clear
input UARTRTIC; // For Receive Timeout Intr Clear
input LBE; // Loop Back Enable
output SIRLPSync; // To IrDA block
output SIRENSync; // To IrDA block
output UARTENSync; // Sync'ed UART Eable
output TXESync; // Sync'ed TX Eable
output RXESync; // Sync'ed RX Enable
output TXDataAvlblSync; // To Transmit block
output RXFESync; // To Receive block
output CTSEnSyncUCLK; // To Transmit Block
output LCRUpdateSync; // To BaudGen
output ILPRUpdateSync; // To BaudGen block
output FBRDUpdateSync; // To BaudGen block
output UARTRXDSync; // To Receiver
output SIRINSync; // To IrDA block
output RXFWrDoneSync; // To Receiver
output RdPtrIncDoneSync; // To Transmitter
output DCDIMSync; // To Modem block
output DSRIMSync; // To Modem block
output CTSIMSync; // To Modem block
output RIIMSync; // To Modem block
output RTIMSync; // To Receive block
output FEIMSync; // To Receive block
output PEIMSync; // To Receive block
output BEIMSync; // To Receive block
output nDCDSyncUARTCLK; // To Modem block
output nDSRSyncUARTCLK; // To Modem block
output nCTSSyncUARTCLK; // To Modem block
output nRISyncUARTCLK; // To Modem block
output UARTDCDICSync; // To Modem block
output UARTDSRICSync; // To Modem block
output UARTCTSICSync; // To Modem block
output UARTRIICSync; // To Modem block
output UARTFEICSync; // To UART Receiver
output UARTPEICSync; // To UART Receiver
output UARTBEICSync; // To UART Receiver
output UARTRTICSync; // To UART Receiver
// ------------------------------------------------------------------
// UartSynctoUCLK
// ==============
// ------------------------------------------------------------------
// Overview
// ========
// This module synchronises signals crossing over from the PCLK
// domain into the UARTCLK domain.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK ; // Main UART Clock (Module Input)
wire nUARTRST; // Muxed reset (from nUARTRST)(Module Input)
wire UARTRXD;
wire UARTRXDint; // UART Receive wire (Module Input)
wire UARTTXDint;
wire SIRIN;
wire SIRINint;
wire nSIROUTint; // SIR Receive input (Module Input)
wire RXFWrDone; // RX FIFO Wr Done (Module Input)
wire RdPtrIncDone; // Read Pointer Inc Done (Module Input)
wire nDCD;
wire nUARTDCDint;
wire nUARTOut1int; // Modem signal (Module Input)
wire nDSR;
wire nUARTDSRint;
wire nUARTDTRint; // Modem signal (Module Input)
wire nCTS;
wire nUARTCTSint;
wire nUARTRTSint; // Modem signal (Module Input)
wire nRI;
wire nUARTRIint;
wire nUARTOut2int; // Modem signal (Module Input)
wire DCDIM; // UARTDCDINTR Interrupt Enable (Module Input)
wire DSRIM; // UARTDSRINTR Interrupt Enable (Module Input)
wire CTSIM; // UARTCTSINTR Interrupt Enable (Module Input)
wire RIIM; // UARTRIINTR Interrupt Enable (Module Input)
wire RTIM; // UARTRTINTR Interrupt Enable (Module Input)
wire FEIM; // UARTFEINTR Interrupt Enable (Module Input)
wire PEIM; // UARTPEINTR Interrupt Enable (Module Input)
wire BEIM; // UARTBEINTR Interrupt Enable (Module Input)
wire UARTFEIC; // For Framing Error Intr Clear (Module Input)
wire UARTPEIC; // For Parity Error Intr Clear (Module Input)
wire UARTBEIC; // For Break Error Intr Clear (Module Input)
wire UARTRTIC; // For Receive Timeout Intr Clear (Module Input)
wire UARTDCDIC; // Modem DCD Intr Clear (Module Input)
wire UARTDSRIC; // Modem DSR Intr Clear (Module Input)
wire UARTCTSIC; // Modem CTS Intr Clear (Module Input)
wire UARTRIIC; // Modem RI Intr Clear (Module Input)
wire SIRLP; // SIR Low power mode (Module Input)
wire SIREN; // SIR Enabled (Module Input)
wire UARTEN; // UART Enabled (Module Input)
wire TXE; // TX Enabled (Module Input)
wire RXE; // RX Enabled (Module Input)
wire TXDataAvlbl; // TX Data available (Module Input)
wire RXFE; // RX FIFO Empty (Module Input)
wire LCRUpdate; // Sync control signal for LCR (Module Input)
wire ILPRUpdate; // Sync ctrl signal for ILPR (Module Input)
wire FBRDUpdate; // Sync ctrl signal for FBRD (Module Input)
wire LBE; // Loop Back Enable
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg DCDIMSync; // To Modem block (Module Output)
reg DSRIMSync; // To Modem block (Module Output)
reg CTSIMSync; // To Modem block (Module Output)
reg RIIMSync; // To Modem block (Module Output)
reg RTIMSync; // To Receive block (Module Output)
reg FEIMSync; // To Receive block (Module Output)
reg PEIMSync; // To Receive block (Module Output)
reg BEIMSync; // To Receive block (Module Output)
reg UARTFEICSync; // To UART Receiver (Module Output)
reg UARTPEICSync; // To UART Receiver (Module Output)
reg UARTBEICSync; // To UART Receiver (Module Output)
reg UARTRTICSync; // To UART Receiver (Module Output)
reg UARTDCDICSync; // To Modem block (Module Output)
reg UARTDSRICSync; // To Modem block (Module Output)
reg UARTCTSICSync; // To Modem block (Module Output)
reg UARTRIICSync; // To Modem block (Module Output)
reg SIRLPSync; // To IrDA block (Module Output)
reg SIRENSync; // To IrDA block (Module Output)
reg UARTENSync; // Sync'ed UART Eable (Module Output)
reg TXESync; // Sync'ed TX Eable (Module Output)
reg RXESync; // Sync'ed RX Enable (Module Output)
reg TXDataAvlblSync; // To Transmit block (Module Output)
reg RXFESync; // To Receive block (Module Output)
reg LCRUpdateSync; // To BaudGen (Module Output)
reg UARTRXDSync; // To Receiver (Module Output)
reg SIRINSync; // To IrDA block (Module Output)
reg RXFWrDoneSync; // To Receiver (Module Output)
reg RdPtrIncDoneSync; // To Transmitter (Module Output)
reg nDCDSyncUARTCLK; // To Modem block (Module Output)
reg nDSRSyncUARTCLK; // To Modem block (Module Output)
reg nCTSSyncUARTCLK; // To Modem block (Module Output)
reg nRISyncUARTCLK; // To Modem block (Module Output)
reg ILPRUpdateSync; // To BaudGen block (Module Output)
reg FBRDUpdateSync; // To BaudGen block (Module Output)
reg CTSEnSyncUCLK; // To Transmit Block (Module Output)
// ------------------------------------------------------------------
// Intermediate first stage and second stage synchronised signals
// corresponding to each input
// ------------------------------------------------------------------
reg UARTRXDSync1;
// 1st stage synchronised version of UARTRXD input
reg SIRINSync1;
// 1st stage synchronised version of SIRIN input
reg RXFWrDoneSync1;
// 1st stage synchronised version of RXFWrDone input
reg RPTrInDnSync1;
// 1st stage synchronised version of RdPtrIncDone input
reg nDCDSync1;
// 1st stage synchronised version of nDCD input
reg nDSRSync1;
// 1st stage synchronised version of nDSR input
reg nCTSSync1;
// 1st stage synchronised version of nCTS input
reg nRISync1;
// 1st stage synchronised version of nRI input
reg TXDataAvlblSync1;
// 1st stage synchronised version of TXDataAvlbl input
reg CTSEnSync1;
// 1st stage synchronised version of CTSEn
reg RXFESync1;
// 1st stage synchronised version of RXFE input
reg DCDIMSync1;
// 1st stage synchronised version of DCDIM input
reg DSRIMSync1;
// 1st stage synchronised version of DSRIM input
reg CTSIMSync1;
// 1st stage synchronised version of CTSIM input
reg RIIMSync1;
// 1st stage synchronised version of RIIM input
reg RTIMSync1;
// 1st stage synchronised version of RTIM input
reg FEIMSync1;
// 1st stage synchronised version of FEIM input
reg PEIMSync1;
// 1st stage synchronised version of PEIM input
reg BEIMSync1;
// 1st stage synchronised version of BEIM input
reg SIRLPSync1;
// 1st stage synchronised version of SIRLP input
reg SIRENSync1;
// 1st stage synchronised version of SIREN input
reg UARTENSync1;
// 1st stage synchronised version of UARTEN input
reg TXESync1;
// 1st stage synchronised version of TXE input
reg RXESync1;
// 1st stage synchronised version of RXE input
reg LCRUpdateSync1;
// 1st stage synchronised version of LCRUpdate input
reg ILPRUpdateSync1;
// 1st stage synchronised version of ILPRUpdate input
reg FBRDUpdateSync1;
// 1st stage synchronised version of FBRDUpdate input
reg UARTFEICSync1;
// 1st stage synchronised version of UARTFEIC input
reg UARTPEICSync1;
// 1st stage synchronised version of UARTPEIC input
reg UARTBEICSync1;
// 1st stage synchronised version of UARTBEIC input
reg UARTRTICSync1;
// 1st stage synchronised version of UARTRTIC input
reg UARTDCDICSync1;
// 1st stage synchronised version of DCDIC input
reg UARTDSRICSync1;
// 1st stage synchronised version of DSRIC input
reg UARTCTSICSync1;
// 1st stage synchronised version of CTSIC input
reg UARTRIICSync1;
// 1st stage synchronised version of RIIC input
// ------------------------------------------------------------------
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// If the LBE input is asserted, UARTTXDint is connected to UARTRXDint and
// nSIROUTint is connected through an inverter to SIRINint to implement
// loopback. The modem signals are also connected nUARTRTSint to
// nUARTCTSint, nUARTDTRint to nUARTDSRint, nUARTOut2int to nUARTRIint
// and nUARTOut1int to nUARTDCDint to implement loopback.
// ------------------------------------------------------------------
assign UARTRXD = (LBE == 1'b1) ? UARTTXDint : UARTRXDint ;
assign SIRIN = (LBE == 1'b1) ? !(nSIROUTint) : SIRINint ;
assign nCTS = (LBE == 1'b1) ? nUARTRTSint : nUARTCTSint ;
assign nDSR = (LBE == 1'b1) ? nUARTDTRint : nUARTDSRint ;
assign nRI = (LBE == 1'b1) ? nUARTOut2int : nUARTRIint ;
assign nDCD = (LBE == 1'b1) ? nUARTOut1int : nUARTDCDint ;
// ------------------------------------------------------------------
// Synchronisers for Modem-related signals.
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin : p_Modem
if (nUARTRST == 1'b0)
begin
nDCDSync1 <= 1'b0;
nDCDSyncUARTCLK <= 1'b0;
nDSRSync1 <= 1'b0;
nDSRSyncUARTCLK <= 1'b0;
nCTSSync1 <= 1'b0;
nCTSSyncUARTCLK <= 1'b0;
nRISync1 <= 1'b0;
nRISyncUARTCLK <= 1'b0;
end
else
begin
nDCDSync1 <= nDCD;
nDCDSyncUARTCLK <= nDCDSync1;
nDSRSync1 <= nDSR;
nDSRSyncUARTCLK <= nDSRSync1;
nCTSSync1 <= nCTS;
nCTSSyncUARTCLK <= nCTSSync1;
nRISync1 <= nRI;
nRISyncUARTCLK <= nRISync1;
end
end // p_Modem;
// ------------------------------------------------------------------
// Synchronisers for Serial data input signals
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_Receive
if (nUARTRST == 1'b0)
begin
SIRINSync1 <= 1'b0;
SIRINSync <= 1'b0;
UARTRXDSync1 <= 1'b0;
UARTRXDSync <= 1'b0;
end
else
begin
SIRINSync1 <= SIRIN;
SIRINSync <= SIRINSync1;
UARTRXDSync1 <= UARTRXD;
UARTRXDSync <= UARTRXDSync1;
end
end // p_Receive;
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_FIFOs
if (nUARTRST == 1'b0)
begin
RXFWrDoneSync1 <= 1'b0;
RXFWrDoneSync <= 1'b0;
RPTrInDnSync1 <= 1'b0;
RdPtrIncDoneSync <= 1'b0;
RXFESync1 <= 1'b0;
RXFESync <= 1'b0;
CTSEnSync1 <= 1'b0;
CTSEnSyncUCLK <= 1'b0;
end
else
begin
RXFWrDoneSync1 <= RXFWrDone;
RXFWrDoneSync <= RXFWrDoneSync1;
RPTrInDnSync1 <= RdPtrIncDone;
RdPtrIncDoneSync <= RPTrInDnSync1;
RXFESync1 <= RXFE;
RXFESync <= RXFESync1;
CTSEnSync1 <= CTSEn;
CTSEnSyncUCLK <= CTSEnSync1;
end
end // p_FIFOs;
// ------------------------------------------------------------------
// Synchronisers for the LCRUpdate signal and the ILPRUpdate
// signal.
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_Update
if (nUARTRST == 1'b0)
begin
LCRUpdateSync1 <= 1'b0;
LCRUpdateSync <= 1'b0;
ILPRUpdateSync1 <= 1'b0;
ILPRUpdateSync <= 1'b0;
FBRDUpdateSync1 <= 1'b0;
FBRDUpdateSync <= 1'b0;
end
else
begin
LCRUpdateSync1 <= LCRUpdate;
LCRUpdateSync <= LCRUpdateSync1;
ILPRUpdateSync1 <= ILPRUpdate;
ILPRUpdateSync <= ILPRUpdateSync1;
FBRDUpdateSync1 <= FBRDUpdate;
FBRDUpdateSync <= FBRDUpdateSync1;
end
end // p_Update;
// ------------------------------------------------------------------
// Synchroniser for the TXDataAvlbl signal.
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_TXDataAvlbl
if (nUARTRST == 1'b0)
begin
TXDataAvlblSync1 <= 1'b0;
TXDataAvlblSync <= 1'b0;
end
else
begin
TXDataAvlblSync1 <= TXDataAvlbl;
TXDataAvlblSync <= TXDataAvlblSync1;
end
end // p_TXDataAvlbl;
// ------------------------------------------------------------------
// Synchronisers for 'Enable' signals and other related signals.
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_CntlSig
if (nUARTRST == 1'b0)
begin
DCDIMSync1 <= 1'b0;
DCDIMSync <= 1'b0;
DSRIMSync1 <= 1'b0;
DSRIMSync <= 1'b0;
CTSIMSync1 <= 1'b0;
CTSIMSync <= 1'b0;
RIIMSync1 <= 1'b0;
RIIMSync <= 1'b0;
RTIMSync1 <= 1'b0;
RTIMSync <= 1'b0;
FEIMSync1 <= 1'b0;
FEIMSync <= 1'b0;
PEIMSync1 <= 1'b0;
PEIMSync <= 1'b0;
BEIMSync1 <= 1'b0;
BEIMSync <= 1'b0;
SIRLPSync1 <= 1'b0;
SIRLPSync <= 1'b0;
SIRENSync1 <= 1'b0;
SIRENSync <= 1'b0;
UARTENSync1 <= 1'b0;
UARTENSync <= 1'b0;
TXESync1 <= 1'b1;
TXESync <= 1'b1;
RXESync1 <= 1'b1;
RXESync <= 1'b1;
UARTFEICSync1 <= 1'b0;
UARTFEICSync <= 1'b0;
UARTPEICSync1 <= 1'b0;
UARTPEICSync <= 1'b0;
UARTBEICSync1 <= 1'b0;
UARTBEICSync <= 1'b0;
UARTRTICSync1 <= 1'b0;
UARTRTICSync <= 1'b0;
UARTDCDICSync1 <= 1'b0;
UARTDCDICSync <= 1'b0;
UARTDSRICSync1 <= 1'b0;
UARTDSRICSync <= 1'b0;
UARTCTSICSync1 <= 1'b0;
UARTCTSICSync <= 1'b0;
UARTRIICSync1 <= 1'b0;
UARTRIICSync <= 1'b0;
end
else
begin
DCDIMSync1 <= DCDIM;
DCDIMSync <= DCDIMSync1;
DSRIMSync1 <= DSRIM;
DSRIMSync <= DSRIMSync1;
CTSIMSync1 <= CTSIM;
CTSIMSync <= CTSIMSync1;
RIIMSync1 <= RIIM;
RIIMSync <= RIIMSync1;
RTIMSync1 <= RTIM;
RTIMSync <= RTIMSync1;
FEIMSync1 <= FEIM;
FEIMSync <= FEIMSync1;
PEIMSync1 <= PEIM;
PEIMSync <= PEIMSync1;
BEIMSync1 <= BEIM;
BEIMSync <= BEIMSync1;
SIRLPSync1 <= SIRLP;
SIRLPSync <= SIRLPSync1;
SIRENSync1 <= SIREN;
SIRENSync <= SIRENSync1;
UARTENSync1 <= UARTEN;
UARTENSync <= UARTENSync1;
TXESync1 <= TXE;
TXESync <= TXESync1;
RXESync1 <= RXE;
RXESync <= RXESync1;
UARTFEICSync1 <= UARTFEIC;
UARTFEICSync <= UARTFEICSync1;
UARTPEICSync1 <= UARTPEIC;
UARTPEICSync <= UARTPEICSync1;
UARTBEICSync1 <= UARTBEIC;
UARTBEICSync <= UARTBEICSync1;
UARTRTICSync1 <= UARTRTIC;
UARTRTICSync <= UARTRTICSync1;
UARTDCDICSync1 <= UARTDCDIC;
UARTDCDICSync <= UARTDCDICSync1;
UARTDSRICSync1 <= UARTDSRIC;
UARTDSRICSync <= UARTDSRICSync1;
UARTCTSICSync1 <= UARTCTSIC;
UARTCTSICSync <= UARTCTSICSync1;
UARTRIICSync1 <= UARTRIIC;
UARTRIICSync <= UARTRIICSync1;
end
end // p_CntlSig;
endmodule
// - ==================== End of UartSynctoUCLK ====================
uartsynctopclk.v
module uartsynctopclk (
PCLK,
PRESETn,
TXBUSY,
TXFRdPtrInc,
RXFWr,
Abort,
DataStp,
nUARTDCDint,
nUARTDSRint,
nUARTCTSint,
nUARTRIint,
nUARTRTSint,
nUARTDTRint,
nUARTOut2int,
nUARTOut1int,
UARTRISmod,
UARTMISmod,
UARTRISerr,
UARTMISerr,
IntUARTTXDMACLR,
IntUARTRXDMACLR,
CharTxComp,
TXBUSYSync,
TXFRdPtrIncSync,
RXFWrSync,
AbortSync,
nDCDSyncPCLK,
nDSRSyncPCLK,
nCTSSyncPCLK,
nRISyncPCLK,
UARTRTRIS,
UARTRISmodSync,
UARTMISmodSync,
UARTRISerrSync,
UARTMISerrSync,
UARTTXDMACLRSync,
UARTRXDMACLRSync,
CharTxCompSync,
LBE
);
input PCLK; // APB Bus Clock
input PRESETn; // APB Bus Reset
input TXBUSY; // Transmitter Busy
input TXFRdPtrInc; // TX FIFO Read pointer Incr.
input RXFWr; // RX FIFO Write enable
input Abort; // Abort transmission
input DataStp; // Receive Line Idle
input nUARTDCDint; // Modem signal
input nUARTDSRint; // Modem signal
input nUARTCTSint; // Modem signal
input nUARTRIint; // Modem signal
input nUARTRTSint; // Modem signal
input nUARTDTRint; // Modem signal
input nUARTOut2int; // Modem signal
input nUARTOut1int; // Modem signal
input [3:0] UARTRISmod; // Raw interrupt status
input [3:0] UARTMISmod; // Masked interrupt status
input [2:0] UARTRISerr; // Raw error interrupts
input [2:0] UARTMISerr; // Masked error interrupts
input IntUARTTXDMACLR; // DMA Tx Clear
input IntUARTRXDMACLR; // DMA Rx Clear
input CharTxComp; // Char TX Completed
input LBE; // Loop Back Enable
output TXBUSYSync; // To TX FIFO
output TXFRdPtrIncSync; // To TX FIFO
output RXFWrSync; // To RX FIFO
output AbortSync; // To TX FIFO
output nDCDSyncPCLK; // Sync'ed DCD
output nDSRSyncPCLK; // Sync'ed DSR
output nCTSSyncPCLK; // Sync'ed CTS
output nRISyncPCLK; // Sync'ed RI
output UARTRTRIS; // Receive Timeout interrupt
output [3:0] UARTRISmodSync; // Synchro Raw int status
output [3:0] UARTMISmodSync; // Synchro Masked int status
output [2:0] UARTRISerrSync; // Synchro raw error interrupts
output [2:0] UARTMISerrSync; // SynchroMasked error interrupts
output UARTTXDMACLRSync; // Synchro DMA TX Clear
output UARTRXDMACLRSync; // Synchro DMA TX Clear
output CharTxCompSync; // Synchro Char TX Completed
// ------------------------------------------------------------------
// UartSynctoPCLK
// ==============
// ------------------------------------------------------------------
// Overview
// ========
// This module synchronises signals crossing over from the UARTCLK
// domain into the PCLK domain.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Bus Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire nDCD;
wire nUARTDCDint;
wire nUARTOut1int; // Modem signal (Module Input)
wire nDSR;
wire nUARTDSRint;
wire nUARTDTRint; // Modem signal (Module Input)
wire nCTS;
wire nUARTCTSint;
wire nUARTRTSint; // Modem signal (Module Input)
wire nRI;
wire nUARTRIint;
wire nUARTOut2int; // Modem signal (Module Input)
wire TXBUSY; // Transmitter Busy (Module Input)
wire TXFRdPtrInc; // TX FIFO Read pointer Incr. (Module Input)
wire RXFWr; // RX FIFO Write enable (Module Input)
wire Abort; // Abort transmission (Module Input)
wire DataStp; // Receive Line Idle (Module Input)
wire [3:0] UARTRISmod; // Raw interrupt status (Module Input)
wire [3:0] UARTMISmod; // Masked interrupt status (Module Input)
wire [2:0] UARTRISerr; // Raw error interrupts (Module Input)
wire [2:0] UARTMISerr; // Masked error interrupts (Module Input)
wire IntUARTTXDMACLR; // DMA Transmit Clear (Module Input)
wire IntUARTRXDMACLR; // DMA Receive Clear (Module Input)
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg nDCDSyncPCLK; // Sync'ed DCD (Module Output)
reg nDSRSyncPCLK; // Sync'ed DSR (Module Output)
reg nCTSSyncPCLK; // Sync'ed CTS (Module Output)
reg nRISyncPCLK; // Sync'ed RI (Module Output)
reg TXBUSYSync; // To TX FIFO (Module Output)
reg UARTRTRIS; // Receive Timereg interrupt (Module Output)
reg TXFRdPtrIncSync; // To TX FIFO (Module Output)
reg RXFWrSync; // To RX FIFO (Module Output)
reg AbortSync; // To TX FIFO (Module Output)
reg [3:0] UARTRISmodSync; // Synchro Raw int status (Module Output)
reg [3:0] UARTMISmodSync; // Synchro Masked int status (Module Output)
reg [2:0] UARTRISerrSync; // Synchro raw error interrupts(Module Output)
reg [2:0] UARTMISerrSync; // SynchroMasked error interrupts(Module Output)
reg UARTTXDMACLRSync; // Synchro DMA Transmit clear (Module Output)
reg UARTRXDMACLRSync; // Synchro DMA Receive clear (Module Output)
reg CharTxCompSync; // Synchro Char TX Completed (Module Output)
// ------------------------------------------------------------------
// Intermediate first stage and second stage synchronised signals
// corresponding to each input
// ------------------------------------------------------------------
reg DataStpSync1;
// 1st stage synchronised version of DataStp input
reg RXFWrSync1;
// 1st stage synchronised version of RXFWr input
reg TXBUSYSync1;
// 1st stage synchronised version of TXBUSY input
reg TXFRPtrIncSync1;
// 1st stage synchronised version of TXFRdPtrInc input
reg AbortSync1;
// 1st stage synchronised version of Abort input
reg nDCDSync1;
// 1st stage synchronised version of nDCD input
reg nDSRSync1;
// 1st stage synchronised version of nDSR input
reg nCTSSync1;
// 1st stage synchronised version of nCTS input
reg nRISync1;
// 1st stage synchronised version of nRI input
reg [3:0] UARTRISmodSync1;
// 1st stage synchronised version of UARTRISmod
reg [3:0] UARTMISmodSync1;
// 1st stage synchronised version of UARTMISmod
reg [2:0] UARTRISerrSync1;
// 1st stage synchronised version of UARTRISerrSync
reg [2:0] UARTMISerrSync1;
// 1st stage synchronised version of UARTMISerrSync
reg UARTTXDMACLRSync1;
// 1st stage synchronised version of UARTTXDMACLRSync
reg UARTRXDMACLRSync1;
// 1st stage synchronised version of UARTRXDMACLRSync
reg CharTxCompSync1;
// 1st stage synchronised version of CharTxComp input
// ------------------------------------------------------------------
// Main Verilog code
// =================
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// If the LBE input is asserted. The modem signals are also connected nUARTRTSint to
// nUARTCTSint, nUARTDTRint to nUARTDSRint, nUARTOut2int to nUARTRIint
// and nUARTOut1int to nUARTDCDint to implement loopback.
// ------------------------------------------------------------------
assign nCTS = (LBE == 1'b1) ? nUARTRTSint : nUARTCTSint ;
assign nDSR = (LBE == 1'b1) ? nUARTDTRint : nUARTDSRint ;
assign nRI = (LBE == 1'b1) ? nUARTOut2int : nUARTRIint ;
assign nDCD = (LBE == 1'b1) ? nUARTOut1int : nUARTDCDint ;
// ------------------------------------------------------------------
// Synchronisers for FIFO-related signals, interrupts and DMA signals
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)//novas -21013
begin : p_FIFOs
if (PRESETn == 1'b0)
begin
DataStpSync1 <= 1'b0;
UARTRTRIS <= 1'b0;
RXFWrSync1 <= 1'b0;
RXFWrSync <= 1'b0;
TXFRPtrIncSync1 <= 1'b0;
TXFRdPtrIncSync <= 1'b0;
AbortSync1 <= 1'b0;
AbortSync <= 1'b0;
UARTRISmodSync <= 4'b0000;
UARTRISmodSync1 <= 4'b0000;
UARTMISmodSync <= 4'b0000;
UARTMISmodSync1 <= 4'b0000;
UARTRISerrSync <= 3'b000;
UARTRISerrSync1 <= 3'b000;
UARTMISerrSync <= 3'b000;
UARTMISerrSync1 <= 3'b000;
UARTTXDMACLRSync1 <= 1'b0;
UARTTXDMACLRSync <= 1'b0;
UARTRXDMACLRSync1 <= 1'b0;
UARTRXDMACLRSync <= 1'b0;
CharTxCompSync1 <= 1'b0;
CharTxCompSync <= 1'b0;
end
else
begin
DataStpSync1 <= DataStp;
UARTRTRIS <= DataStpSync1;
RXFWrSync1 <= RXFWr;
RXFWrSync <= RXFWrSync1;
TXFRPtrIncSync1 <= TXFRdPtrInc;
TXFRdPtrIncSync <= TXFRPtrIncSync1;
AbortSync1 <= Abort;
AbortSync <= AbortSync1;
UARTRISmodSync1 <= UARTRISmod;
UARTRISmodSync <= UARTRISmodSync1;
UARTMISmodSync1 <= UARTMISmod;
UARTMISmodSync <= UARTMISmodSync1;
UARTRISerrSync1 <= UARTRISerr;
UARTRISerrSync <= UARTRISerrSync1;
UARTMISerrSync1 <= UARTMISerr;
UARTMISerrSync <= UARTMISerrSync1;
UARTTXDMACLRSync1 <= IntUARTTXDMACLR;
UARTTXDMACLRSync <= UARTTXDMACLRSync1;
UARTRXDMACLRSync1 <= IntUARTRXDMACLR;
UARTRXDMACLRSync <= UARTRXDMACLRSync1;
CharTxCompSync1 <= CharTxComp;
CharTxCompSync <= CharTxCompSync1;
end
end // p_FIFOs;
// ------------------------------------------------------------------
// Synchroniser for TXBUSY signal.
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_TXBUSY
if (PRESETn == 1'b0)
begin
TXBUSYSync1 <= 1'b0;
TXBUSYSync <= 1'b0;
end
else
begin
TXBUSYSync1 <= TXBUSY;
TXBUSYSync <= TXBUSYSync1;
end
end // p_TXBUSY;
// ------------------------------------------------------------------
// Synchronisers for Modem-related signals.
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_Modem
if (PRESETn == 1'b0)
begin
nDCDSyncPCLK <= 1'b0;
nDCDSync1 <= 1'b0;
nDSRSyncPCLK <= 1'b0;
nDSRSync1 <= 1'b0;
nCTSSyncPCLK <= 1'b0;
nCTSSync1 <= 1'b0;
nRISyncPCLK <= 1'b0;
nRISync1 <= 1'b0;
end
else
begin
nDCDSync1 <= nDCD;
nDCDSyncPCLK <= nDCDSync1;
nDSRSync1 <= nDSR;
nDSRSyncPCLK <= nDSRSync1;
nCTSSync1 <= nCTS;
nCTSSyncPCLK <= nCTSSync1;
nRISync1 <= nRI;
nRISyncPCLK <= nRISync1;
end
end // p_Modem;
endmodule
// - ==================== End of UartSynctoPCLK ====================
uartrxregfile.v
module uartrxregfile (
PCLK,
PRESETn,
RegFileWrEn,
WrPtr,
RdPtr,
RXFIFOData,
RXFRdData
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input RegFileWrEn; // Write Enable
input [3:0] WrPtr; // Write Pointer
input [3:0] RdPtr; // Read Pointer
input [11:0] RXFIFOData; // Write data
output [11:0] RXFRdData; // Read data
//when the read pointer once is changed, the read data output immediately, do not need any especial read s...
// ------------------------------------------------------------------
//
// UartRXRegFile
// =============
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block contains an array of flipflops that serve as the storage
// register file for the receive FIFO.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire RegFileWrEn; // Write Enable (Module Input)
wire [3:0] WrPtr; // Write Pointer (Module Input)
wire [3:0] RdPtr; // Read Pointer (Module Input)
wire [11:0] RXFIFOData; // Write data (Module Input)
wire [11:0] RXFRdData; // Read data (Module Output)
// ------------------------------------------------------------------
// register declaration
// ------------------------------------------------------------------
reg [11:0] RXRegFile0; // Register File-0 12-bits wide
reg [11:0] RXRegFile1; // Register File-1 12-bits wide
reg [11:0] RXRegFile2; // Register File-2 12-bits wide
reg [11:0] RXRegFile3; // Register File-3 12-bits wide
reg [11:0] RXRegFile4; // Register File-4 12-bits wide
reg [11:0] RXRegFile5; // Register File-5 12-bits wide
reg [11:0] RXRegFile6; // Register File-6 12-bits wide
reg [11:0] RXRegFile7; // Register File-7 12-bits wide
reg [11:0] RXRegFile8; // Register File-8 12-bits wide
reg [11:0] RXRegFile9; // Register File-9 12-bits wide
reg [11:0] RXRegFile10; // Register File-10 12-bits wide
reg [11:0] RXRegFile11; // Register File-11 12-bits wide
reg [11:0] RXRegFile12; // Register File-12 12-bits wide
reg [11:0] RXRegFile13; // Register File-13 12-bits wide
reg [11:0] RXRegFile14; // Register File-14 12-bits wide
reg [11:0] RXRegFile15; // Register File-15 12-bits wide
// reg [11:0] RXRegFile16; // Register File-16 12-bits wide
reg [11:0] NextRXRegFile0; // D-inputs of Register File-0 12-bits wide
reg [11:0] NextRXRegFile1; // D-inputs of Register File-1 12-bits wide
reg [11:0] NextRXRegFile2; // D-inputs of Register File-2 12-bits wide
reg [11:0] NextRXRegFile3; // D-inputs of Register File-3 12-bits wide
reg [11:0] NextRXRegFile4; // D-inputs of Register File-4 12-bits wide
reg [11:0] NextRXRegFile5; // D-inputs of Register File-5 12-bits wide
reg [11:0] NextRXRegFile6; // D-inputs of Register File-6 12-bits wide
reg [11:0] NextRXRegFile7; // D-inputs of Register File-7 12-bits wide
reg [11:0] NextRXRegFile8; // D-inputs of Register File-8 12-bits wide
reg [11:0] NextRXRegFile9; // D-inputs of Register File-9 12-bits wide
reg [11:0] NextRXRegFile10; // D-inputs of Register File-10 12-bits wide
reg [11:0] NextRXRegFile11; // D-inputs of Register File-11 12-bits wide
reg [11:0] NextRXRegFile12; // D-inputs of Register File-12 12-bits wide
reg [11:0] NextRXRegFile13; // D-inputs of Register File-13 12-bits wide
reg [11:0] NextRXRegFile14; // D-inputs of Register File-14 12-bits wide
reg [11:0] NextRXRegFile15; // D-inputs of Register File-15 12-bits wide
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Register array
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)//novas -21013
begin : p_Seq
if (PRESETn == 1'b0)
begin
RXRegFile0 <= 12'b000000000000;
RXRegFile1 <= 12'b000000000000;
RXRegFile2 <= 12'b000000000000;
RXRegFile3 <= 12'b000000000000;
RXRegFile4 <= 12'b000000000000;
RXRegFile5 <= 12'b000000000000;
RXRegFile6 <= 12'b000000000000;
RXRegFile7 <= 12'b000000000000;
RXRegFile8 <= 12'b000000000000;
RXRegFile9 <= 12'b000000000000;
RXRegFile10 <= 12'b000000000000;
RXRegFile11 <= 12'b000000000000;
RXRegFile12 <= 12'b000000000000;
RXRegFile13 <= 12'b000000000000;
RXRegFile14 <= 12'b000000000000;
RXRegFile15 <= 12'b000000000000;
end
else
begin
RXRegFile0 <= NextRXRegFile0;
RXRegFile1 <= NextRXRegFile1;
RXRegFile2 <= NextRXRegFile2;
RXRegFile3 <= NextRXRegFile3;
RXRegFile4 <= NextRXRegFile4;
RXRegFile5 <= NextRXRegFile5;
RXRegFile6 <= NextRXRegFile6;
RXRegFile7 <= NextRXRegFile7;
RXRegFile8 <= NextRXRegFile8;
RXRegFile9 <= NextRXRegFile9;
RXRegFile10 <= NextRXRegFile10;
RXRegFile11 <= NextRXRegFile11;
RXRegFile12 <= NextRXRegFile12;
RXRegFile13 <= NextRXRegFile13;
RXRegFile14 <= NextRXRegFile14;
RXRegFile15 <= NextRXRegFile15;
end
end // p_Seq;
// ------------------------------------------------------------------
// Write logic
// ------------------------------------------------------------------
always @(RXRegFile0 or RXRegFile1 or RXRegFile2 or RXRegFile3 or
RXRegFile4 or RXRegFile5 or RXRegFile6 or RXRegFile7 or
RXRegFile8 or RXRegFile9 or RXRegFile10 or RXRegFile11 or
RXRegFile12 or RXRegFile13 or RXRegFile14 or RXRegFile15 or
RegFileWrEn or RXFIFOData or WrPtr)
begin : p_WrComb
NextRXRegFile0 = RXRegFile0;
NextRXRegFile1 = RXRegFile1;
NextRXRegFile2 = RXRegFile2;
NextRXRegFile3 = RXRegFile3;
NextRXRegFile4 = RXRegFile4;
NextRXRegFile5 = RXRegFile5;
NextRXRegFile6 = RXRegFile6;
NextRXRegFile7 = RXRegFile7;
NextRXRegFile8 = RXRegFile8;
NextRXRegFile9 = RXRegFile9;
NextRXRegFile10 = RXRegFile10;
NextRXRegFile11 = RXRegFile11;
NextRXRegFile12 = RXRegFile12;
NextRXRegFile13 = RXRegFile13;
NextRXRegFile14 = RXRegFile14;
NextRXRegFile15 = RXRegFile15;
if(RegFileWrEn == 1'b1)
case (WrPtr)
4'b0000 : NextRXRegFile0 = RXFIFOData;
4'b0001 : NextRXRegFile1 = RXFIFOData;
4'b0010 : NextRXRegFile2 = RXFIFOData;
4'b0011 : NextRXRegFile3 = RXFIFOData;
4'b0100 : NextRXRegFile4 = RXFIFOData;
4'b0101 : NextRXRegFile5 = RXFIFOData;
4'b0110 : NextRXRegFile6 = RXFIFOData;
4'b0111 : NextRXRegFile7 = RXFIFOData;
4'b1000 : NextRXRegFile8 = RXFIFOData;
4'b1001 : NextRXRegFile9 = RXFIFOData;
4'b1010 : NextRXRegFile10 = RXFIFOData;
4'b1011 : NextRXRegFile11 = RXFIFOData;
4'b1100 : NextRXRegFile12 = RXFIFOData;
4'b1101 : NextRXRegFile13 = RXFIFOData;
4'b1110 : NextRXRegFile14 = RXFIFOData;
4'b1111 : NextRXRegFile15 = RXFIFOData;
default : ;
endcase
end // p_WrComb;
// ------------------------------------------------------------------
// Read Mux
// ------------------------------------------------------------------
assign RXFRdData = (RdPtr == 4'b0000) ? RXRegFile0
: (RdPtr == 4'b0001) ? RXRegFile1
: (RdPtr == 4'b0010) ? RXRegFile2
: (RdPtr == 4'b0011) ? RXRegFile3
: (RdPtr == 4'b0100) ? RXRegFile4
: (RdPtr == 4'b0101) ? RXRegFile5
: (RdPtr == 4'b0110) ? RXRegFile6
: (RdPtr == 4'b0111) ? RXRegFile7
: (RdPtr == 4'b1000) ? RXRegFile8
: (RdPtr == 4'b1001) ? RXRegFile9
: (RdPtr == 4'b1010) ? RXRegFile10
: (RdPtr == 4'b1011) ? RXRegFile11
: (RdPtr == 4'b1100) ? RXRegFile12
: (RdPtr == 4'b1101) ? RXRegFile13
: (RdPtr == 4'b1110) ? RXRegFile14
: RXRegFile15;
endmodule
// - ==================== End of UartRXRegFile ====================
uartrxparshft.v
module uartrxparshft (
UARTCLK ,
nUARTRST,
RXDsampled,
ShiftEn,
SampleParity,
ClearShiftReg,
SPS,
EPS,
PEN,
WLEN,
PEIMSync,
UARTPEICSync,
RecdDATA,
DtPrZero,
ParityError,
UARTPERIS,
UARTPEMIS
);
input UARTCLK ; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input RXDsampled; // Sampled serial input
input ShiftEn; // Shift next bit
input SampleParity; // Enable Parity sample
input ClearShiftReg; // Clear receive shifter
input SPS; // Stick Parity Select
input EPS; // Even Parity Select
input PEN; // Parity enable
input [1:0] WLEN; // Bits per word
input PEIMSync; // Parity Error interrupt mask
input UARTPEICSync; // For Parity Error interrupt clear
output [7:0] RecdDATA; // Received Data
output DtPrZero; // Data bits and Parity bit zero
output ParityError; // Parity Error detected
output UARTPERIS; // Parity Error Raw status
output UARTPEMIS; // Parity Error Masked status
// ------------------------------------------------------------------
//
// UartRXParShft
// =============
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block performs shifting-in of the serial bit stream
// and parity error checking on the received data.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK ; // Main UART Clock (Module Input)
wire nUARTRST; // Muxed reset (from nUARTRST) (Module Input)
wire ShiftEn; // Shift next bit (Module Input)
wire SampleParity; // Enable Parity sample (Module Input)
wire ClearShiftReg; // Clear receive shifter (Module Input)
wire [1:0] WLEN; // Bits per word (Module Input)
wire EPS; // Even Parity Select (Module Input)
wire PEN; // Parity enable (Module Input)
wire PEIMSync; // Parity Error interrupt mask (Module Input)
wire RXDsampled; // Sampled serial input (Module Input)
wire UARTPEICSync; // For Parity Error interrupt clear(Module Input)
wire DataZero; // Indicates that all data bits in the received character are zero
wire ParityEdge; // Detects rising edge on parity error
wire UARTPEIClr; // Parity Error Interrupt Clear(Module Output)
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg ParityError; // Parity Error detected (Module Output)
reg DtPrZero; // Data bits and Parity bit zero(Module Output)
reg UARTPERIS; // Parity Error Raw status (Module Output)
reg [7:0] RXShiftReg; // Receive Data shift register
reg [7:0] NextRXShiftReg; // D-input of Shift register
reg NextParityError; // D-input of iParityError
reg DelParityError; // Delayed version of ParityError
reg NextUARTPERIS; // D-input of UARTPERIS
reg DelUARTPEICSync; // Delayed version of UARTPEICSync
reg NextDtPrZero; // D-input of DtPrZero
reg UARTPEMIS; // Parity Error Masked status (Module Output)
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin : p_ShiftSeq
if (nUARTRST == 1'b0)
begin
RXShiftReg <= 8'b00000000;
ParityError <= 1'b0;
DtPrZero <= 1'b0;
DelParityError <= 1'b0;
DelUARTPEICSync <= 1'b0;
UARTPERIS <= 1'b0;
end
else
begin
RXShiftReg <= NextRXShiftReg;
ParityError <= NextParityError;
DtPrZero <= NextDtPrZero;
DelParityError <= ParityError;
DelUARTPEICSync <= UARTPEICSync;
UARTPERIS <= NextUARTPERIS;
end
end // p_ShiftSeq;
// ------------------------------------------------------------------
// Error Checking
// If 'SampleParity' is asserted then the RXD bit is sampled to
// get the parity bit and the parity error value is calculated.
// ------------------------------------------------------------------
always @ (EPS or RXDsampled or RXShiftReg or SampleParity
or ParityError or ClearShiftReg or SPS)
begin : p_ErrCheck
if (ClearShiftReg == 1'b1)
NextParityError = 1'b0;
else if (SampleParity == 1'b1) begin
// ------------------------------------------------------------------
// If Stick parity is selected then Xor the actual parity bit with
// the inverse of the Even Parity Select bit, otherwise Xor the expected parity
// bit with the actual parity bit received to calculate the parity error
// ------------------------------------------------------------------
if (SPS == 1'b1)
NextParityError = RXDsampled ^ (!(EPS));
else
NextParityError = RXDsampled ^ ( !(EPS)) ^ RXShiftReg[7]
^ RXShiftReg[6] ^ RXShiftReg[5] ^ RXShiftReg[4]
^ RXShiftReg[3] ^ RXShiftReg[2] ^ RXShiftReg[1]
^ RXShiftReg[0];
end else
NextParityError = ParityError;
end // p_ErrCheck;
// ------------------------------------------------------------------
// Shift register
// ------------------------------------------------------------------
always @ (WLEN or ShiftEn or RXDsampled or RXShiftReg or ClearShiftReg)
begin : p_ShiftComb
if (ClearShiftReg == 1'b1)
NextRXShiftReg = 8'b00000000;
else if (ShiftEn == 1'b1)
begin
NextRXShiftReg = 8'b00000000;
case (WLEN)
2'b00 :
// 5 bit data
NextRXShiftReg = {3'b000, RXDsampled, RXShiftReg[4:1]};
2'b01 :
// 6 bit data
NextRXShiftReg = {2'b00, RXDsampled, RXShiftReg[5:1]};
2'b10 :
// 7 bit data
NextRXShiftReg = {1'b0, RXDsampled, RXShiftReg[6:1]};
2'b11 :
// 8 bit data
NextRXShiftReg = {RXDsampled, RXShiftReg[7:1]};
default : ;
endcase
end
else
NextRXShiftReg = RXShiftReg;
end // p_ShiftComb;
// ------------------------------------------------------------------
// 'Break' is said to have been detected when all bits in a frame -
// start bit, data bits, parity bit and stop bits - are zeros.
// This section checks for the Data bits and the parity bit all being
// zeros. This condition is used in detecting the break condition which
// is done in the UartTXCntl block.
// ------------------------------------------------------------------
assign DataZero = (RXShiftReg == 8'b00000000);
always @ (ClearShiftReg or RXDsampled or PEN or DataZero or SampleParity
or DtPrZero)
begin : p_DtPrZero
if(ClearShiftReg == 1'b1)
NextDtPrZero = 1'b0;
else if(PEN == 1'b1)
begin
if((SampleParity == 1'b1) && (RXDsampled == 1'b0))
NextDtPrZero = DataZero;
else
NextDtPrZero = DtPrZero;
end
else
NextDtPrZero = DataZero;
end // p_DtPrZero;
// ------------------------------------------------------------------
// Detect rising edge in Parity Error
// ------------------------------------------------------------------
assign ParityEdge = ParityError & !(DelParityError);
// ------------------------------------------------------------------
// UARTPEIClr is a one PCLK-wide pulse used to clear the UARTPEINTR.
// ------------------------------------------------------------------
assign UARTPEIClr = UARTPEICSync & !(DelUARTPEICSync);
// ------------------------------------------------------------------
// Generate a parity error interrupt when there is a rising edge
// on the framing error line. Clear the error when there is a write
// to bit 7 of the Interrupt clear register.
// ------------------------------------------------------------------
always @ (UARTPERIS or ParityEdge or UARTPEIClr)
begin : p_UARTPEINTR
NextUARTPERIS = UARTPERIS;
if(ParityEdge == 1'b1)
NextUARTPERIS = 1'b1;
else if (UARTPEIClr == 1'b1)
NextUARTPERIS = 1'b0;
end // p_UARTPEINTR;
always @(posedge UARTCLK or negedge nUARTRST)
begin
if (nUARTRST == 1'b0)
begin
UARTPEMIS <= 1'b0;
end
else
begin
UARTPEMIS <= NextUARTPERIS & PEIMSync;
end
end
// ------------------------------------------------------------------
// Assign internal signals to Port
// ------------------------------------------------------------------
assign RecdDATA = RXShiftReg;
endmodule
// - ==================== End of UartRXParShft ====================
uartrxfifo.v
module uartrxfifo (
PCLK,
PRESETn,
RXFWrSync,
RXFRdPtrInc,
RXFIFOData,
UARTECRWrEn,
FEN,
RTSEn,
nUARTRTScr,
RXIFLSEL,
UARTRXIC,
UARTOEIC,
RXIM,
OEIM,
RXFRdData,
RXFWrDone,
RXFE,
RXFF,
OverrunDet,
nUARTRTSint,
RXFGTE1Full,
RXIntLevel,
UARTRXIClr,
UARTOEIClr,
UARTRXRIS,
UARTRXMIS,
UARTOERIS,
UARTOEMIS
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input RXFWrSync; // RX FIFO Write Enable
input RXFRdPtrInc; // RX FIFO Read Pointer Incr
input [10:0] RXFIFOData; // RX FIFO Write data
input UARTECRWrEn; // Overrun error Clear input
input FEN; // FIFO Enable
input nUARTRTScr; // from control register
input [2:0] RXIFLSEL; // fifo interrupt level select
input UARTRXIC; // For Rx Interrupt clear
input UARTOEIC; // For Overrun error Interrupt clear
input RXIM; // Tx Interrupt Mask
input OEIM; // Overrun error Interrupt Mask
input RTSEn; // RTS flow control enable
output [11:0] RXFRdData; // RX FIFO Read Data
output RXFWrDone; // RX FIFO Write Done
output RXFE; // Receive FIFO Empty
output RXFF; // Receive FIFO Full
output OverrunDet; // Overrun Detected
output nUARTRTSint; // modem signal
output RXFGTE1Full; // To DMA block
output RXIntLevel; // Programable Interrupt Level
output UARTRXIClr; // Rx Interrupt clear
output UARTOEIClr; // Rx Interrupt clear
output UARTRXRIS; // Receive Raw Interrupt
output UARTRXMIS; // Receive Masked Interrupt
output UARTOERIS; // Overrun error Raw Interrupt
output UARTOEMIS; // Overrun error Masked Interrupt
// ------------------------------------------------------------------
// UartRXFIFO
// ==========
// ------------------------------------------------------------------
// Overview
// ========
//
// The receive FIFO is a 11-bit wide 16-deep FIFO. It instantiates two
// submodules - UartRXFCntl (which performs the FIFO control function
// and the UartRXRegFile (which is the register file). The receive FIFO
// is implemented as a circular buffer with read and write pointers.
// The pointers operate on PCLK to facilitate APB accesses and
// calculation of FIFO fill level.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire RXFWrSync; // RX FIFO Write Enable (Module Input)
wire RXFRdPtrInc; // RX FIFO Read Pointer Incr(Module Input)
wire [10:0] RXFIFOData; // RX FIFO Write data (Module Input)
wire UARTECRWrEn; // Overrun error Clear signal(Module Input)
wire FEN; // FIFO Enable (Module Input)
wire [2:0] RXIFLSEL; // fifo interrupt level select(Module Input)
wire UARTRXIC; // For Rx Interrupt clear (Module Input)
wire UARTOEIC; // For Overrun error Interrupt clear(Module Input)
wire RXIM; // Tx Interrupt Mask (Module Input)
wire OEIM; // Overrun error Interrupt Mask(Module Input)
wire RTSEn; // RTS flow control enable (Module Input)
wire nUARTRTScr; // from control register (Module Input)
wire RegFileWrEn;
wire [3:0] WrPtr;
wire [3:0] RdPtr;
wire FIFOOverrunDet;
wire [11:0] muxRXFIFOData;
assign muxRXFIFOData = {FIFOOverrunDet, RXFIFOData };
// ------------------------------------------------------------------
// The UartRXFCntl block controls accesses to the FIFO register file.
// ------------------------------------------------------------------
uartrxfcntl uartrxfcntl (
.PCLK (PCLK),
.PRESETn (PRESETn),
.RXFWrSync (RXFWrSync),
.RXFRdPtrInc (RXFRdPtrInc),
.FEN (FEN),
.RTSEn (RTSEn),
.nUARTRTScr (nUARTRTScr),
.UARTECRWrEn (UARTECRWrEn),
.RXIFLSEL (RXIFLSEL),
.RXIM (RXIM),
.OEIM (OEIM),
.UARTRXIC (UARTRXIC),
.UARTOEIC (UARTOEIC),
.WrPtr (WrPtr),
.RdPtr (RdPtr),
.RXFE (RXFE),
.RXFF (RXFF),
.RXFGTE1Full (RXFGTE1Full),
.RXIntLevel (RXIntLevel),
.RegFileWrEn (RegFileWrEn),
.RXFWrDone (RXFWrDone),
.OverrunDet (OverrunDet),
.FIFOOverrunDet (FIFOOverrunDet),
.nUARTRTSint (nUARTRTSint),
.UARTRXIClr (UARTRXIClr),
.UARTOEIClr (UARTOEIClr),
.UARTRXRIS (UARTRXRIS),
.UARTRXMIS (UARTRXMIS),
.UARTOERIS (UARTOERIS),
.UARTOEMIS (UARTOEMIS)
);
// ------------------------------------------------------------------
// The UartRXRegFile is a data buffer implemented using D-types.
// ------------------------------------------------------------------
uartrxregfile uartrxregfile (
.PCLK (PCLK),
.PRESETn (PRESETn),
.RegFileWrEn (RegFileWrEn),
.WrPtr (WrPtr),
.RdPtr (RdPtr),
.RXFIFOData (muxRXFIFOData),
.RXFRdData (RXFRdData)
);
endmodule
// - ==================== End of UartTXFIFO ====================
// ----
uartrxfcntl.v
module uartrxfcntl (
PCLK,
PRESETn,
RXFWrSync,
RXFRdPtrInc,
FEN,
RTSEn,
nUARTRTScr,
UARTECRWrEn,
RXIFLSEL,
RXIM,
OEIM,
UARTRXIC,
UARTOEIC,
WrPtr,
RdPtr,
RXFE,
RXFF,
RXFGTE1Full,
RXIntLevel,
RegFileWrEn,
RXFWrDone,
OverrunDet,
FIFOOverrunDet,
nUARTRTSint,
UARTRXIClr,
UARTOEIClr,
UARTRXRIS,
UARTRXMIS,
UARTOERIS,
UARTOEMIS
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input RXFWrSync; // RX FIFO Write Enable
input RXFRdPtrInc; // RX FIFO Read Pointer Incr.
input FEN; // FIFO Enable
input RTSEn; // RTS flow control enable
input nUARTRTScr; // from UARTCR
input UARTECRWrEn; // Overrun error Clear input
input [2:0] RXIFLSEL; // Selected interrupt level
input RXIM; // RX Interrupt Mask
input OEIM; // Overrun Error Interrupt Mask
input UARTRXIC; // For RX Interrupt clear
input UARTOEIC; // For Overrun error Interrupt clear
output OverrunDet; // Overrun Detected
output RegFileWrEn; // Write Enable to Register File
output RXFWrDone; // RX FIFO Write Done
output FIFOOverrunDet; // Overrun Detected
output UARTRXIClr; // RX Interrupt clear
output [3:0] WrPtr; // Write Pointer
output [3:0] RdPtr; // Read Pointer
output RXFE; // Receive FIFO Empty
output RXFF; // Receive FIFO Full
output UARTOEIClr; // Overrun Error Interrupt Clear
output UARTRXMIS; // Receive Masked Interrupt
output UARTOEMIS; // Overrun Error Masked Int status
output UARTRXRIS; // Receive Raw Interrupt
output UARTOERIS; // Overrun Error Raw Int status
output RXFGTE1Full; // To DMA block
output RXIntLevel; // Programmable Interrupt Level
output nUARTRTSint; // modem signal
// ------------------------------------------------------------------
//
// UartRXFCntl
// ===========
//
// ------------------------------------------------------------------
//
// Overview
// ========
// The control logic for the receive FIFO uses two pointers - a write
// pointer and a read pointer. The pointers are 4 bits wide. The write
// pointer points to the location to which the next write data will be
// written into. The read pointer points to the next location whose
// contents will be read out. Both the pointers operate on PCLK so as to
// serve data consistently to APB accesses and to conveniently calculate
// the FIFO fill level by finding the difference between the pointers.
// When the FIFO is disabled, the pointers do not change and the fill
// status of the holding buffer is indicated by a separate bit
// 'HldBufValid'.
// The overrun condition is met when the receive logic attempts to
// write into the FIFO when the FIFO is already full (if the FIFO is
// enabled) or if the holding buffer is already full (if the FIFO is
// disabled). Once the overrun condition is met, further writes to the
// FIFO are ignored. Two separate overrun signals are generated
// OverrunDet(which is copied into the status register) and
// FIFO0overrunDet(which is copied into the RXFIFO).
// When the UARTECRWrEn input is set, the overrun OverrunDet
// condition is cleared, the FIFO0overrunDet is cleared on the next
// successful write to the RXFIFO.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // Muxed Reset (from BPRESETn) (Module Input)
wire RXFWrSync; // RX FIFO Write Enable (Module Input)
wire RXFRdPtrInc; // RX FIFO Read Pointer Incr. (Module Input)
wire FEN; // FIFO Enable (Module Input)
wire UARTECRWrEn; // Overrun error Clear input (Module Input)
wire [2:0] RXIFLSEL; // Selected interrupt level (Module Input)
wire RXIM; // RX Interrupt Mask (Module Input)
wire OEIM; // Overrun Error Interrupt Mask(Module Input)
wire UARTRXIC; // For RX Interrupt clear (Module Input)
wire UARTOEIC; // For Overrun error Interrupt clear(Module Input)
wire RegFileWrEn; // Write Enable to Register File(Module Output)
wire RXFWrDone; // RX FIFO Write Done (Module Output)
wire RTSEn; // RTS flow control enable (Module Output)
wire nUARTRTScr; // from UARTCR (Module Output)
wire WrPtrIncValid;
// Valid Write Pointer Increment condition detected
wire RdPtrIncValid;
// Valid Read Pointer Increment condition detected
wire OverrunEdge;
// Detects edge in Overrun
wire RXEdge;
// Detects edge in RXIntLevel
wire HldBufValidEdge;
// Detects edge in HldBufValid
wire RXFGTEHalfFull;
// Receive FIFO Greater Than or Equal to Half Full
wire RXFGTEQFull;
// Receive FIFO Greater Than or Equal to Quarter full
wire RXFGTE3QFull;
// Receive FIFO Greater Than or Equal to Three Quarters Full
wire [4:0] RXFFillLevel;
// Receive FIFO Fill level - can take values from 00000 to 10000
wire FIFOGTEHalfFull;
// FIFO Fill level compare result
wire FIFOGTE3QFull;
// FIFO Fill level compare result
wire FIFOGTEQFull;
// FIFO Fill level compare result
wire RXFGTE8Full;
// Receive FIFO Greater Than or Equal to One Eighth Full
wire RXFGTE78Full;
// Receive FIFO Greater Than or Equal to Seven Eighth Full
wire FIFOGTE8Full;
// FIFO Fill level compare result
wire FIFOGTE78Full;
// FIFO Fill level compare result
wire FIFOGTE1Full;
// FIFO Fill level compare result
wire [4:0] WrPtrLevel;
// Signal used to calculate the Rx Fifo fill level
wire [4:0] RdPtrLevel;
// Signal used to calculate the Rx Fifo fill level
wire NextRXFE;
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg [3:0] WrPtr; // Write Pointer (Module Output)
reg [3:0] RdPtr; // Read Pointer (Module Output)
reg nUARTRTSint; // modem signal (Module Output)
reg [3:0] NextRdPtr;
// D-input for Read pointer vector
reg [3:0] NextWrPtr;
// D-input for Write pointer vector
reg Wrap;
// Store the condition when the write pointer has rolled over (from '1111' to
// '0000') but the read pointer hasn't. This signal is used in calculating
// the FIFOFillLevel
reg NextWrap;
// D-input of Wrap bit
reg NextOverrunDet;
// D-input of iOverrunDet bit
reg OverrunDet;
// Overrun Detected
reg FIFO0overrunDet;
// Overrun Detected
reg DelOverrunDet;
// Delayed version of OverrunDet bit
reg NextFIFO0overrunDet;
// D-input of FIFO0overrunDet bit
reg DelRXFWrSync;
// Delayed version of RXFWrSync - FIFO write enable signal
// Used to convert the level on the RXFWrEn signal to a one-clock
// wide pulse
reg HldBufValid;
// Fill status of the receive holding buffer when the FIFO is
// disabled
reg DelHldBufValid;
// delayed version of HldBufValid
reg NextHldBufValid;
// D-input of HldBufValid bit
reg NextUARTRXRIS;
// D-input of UARTRXRIS
reg NextUARTOERIS;
// D-input of UARTOERIS
reg FIFOFull;
// Receive FIFO Full when the FIFO is enabled
reg NextFIFOFull;
// D-input of FIFOFull bit
reg FIFOEmpty;
// Receive FIFO empty when the FIFO is enabled
reg NextFIFOEmpty;
// D-input of FIFOEmpty bit
reg RXIntLevel;
// Programmable interrupt level
reg DelUARTRXIC;
// Delayed version of UARTRXIC signal
reg DelUARTOEIC;
// Delayed version of UARTRXIC signal
reg DelRXIntLevel;
// Delayed version of RXIntLevel
reg UARTRXRIS;
// Receive Raw Interrupt
reg UARTOERIS;
// Overrun Error Raw Int status
reg NextRXIntLevel;
// D-input for Programmable interrupt level
reg NextnUARTRTSint;
// D-input for nUARTRTSint
reg RXFE ;
// ------------------------------------------------------------------
//
// Main verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Generate a one-PCLK wide write enable pulse for the Register File on
// every rising edge on the RXFWrSync signal.
// Mask writes to the Register File if FIFO is full
// ------------------------------------------------------------------
assign RegFileWrEn = ((RXFWrSync & !(DelRXFWrSync)) & !(RXFF));
// ------------------------------------------------------------------
// Assert and De-assert RXFWrDone signal the next clock after
// RXFRdPtrInc is asserted or de-asserted.
// ------------------------------------------------------------------
assign RXFWrDone = DelRXFWrSync;
// ------------------------------------------------------------------
// Sequential always @to infer registers in this block
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)//novas -21013
begin : p_PtrsSeq
if (PRESETn == 1'b0)
begin
WrPtr <= 4'b0000;
RdPtr <= 4'b0000;
Wrap <= 1'b0;
HldBufValid <= 1'b0;
OverrunDet <= 1'b0;
FIFO0overrunDet <= 1'b0;
DelRXFWrSync <= 1'b0;
UARTRXRIS <= 1'b0;
UARTOERIS <= 1'b0;
FIFOFull <= 1'b0;
FIFOEmpty <= 1'b1;
DelUARTRXIC <= 1'b0;
DelUARTOEIC <= 1'b0;
DelRXIntLevel <= 1'b0;
DelHldBufValid <= 1'b0;
DelOverrunDet <= 1'b0;
nUARTRTSint <= 1'b1;
RXIntLevel <= 1'b0;
RXFE <= 1'b0;
end
else
begin
WrPtr <= NextWrPtr;
RdPtr <= NextRdPtr;
Wrap <= NextWrap;
HldBufValid <= NextHldBufValid;
OverrunDet <= NextOverrunDet;
FIFO0overrunDet <= NextFIFO0overrunDet;
DelRXFWrSync <= RXFWrSync;
UARTRXRIS <= NextUARTRXRIS;
UARTOERIS <= NextUARTOERIS;
FIFOFull <= NextFIFOFull;
FIFOEmpty <= NextFIFOEmpty;
DelUARTRXIC <= UARTRXIC;
DelUARTOEIC <= UARTOEIC;
RXIntLevel <= NextRXIntLevel;
DelRXIntLevel <= RXIntLevel;
DelHldBufValid <= HldBufValid;
DelOverrunDet <= OverrunDet;
nUARTRTSint <= NextnUARTRTSint;
RXFE <= NextRXFE;
end
end // p_PtrsSeq;
// ------------------------------------------------------------------
// Increment the write pointer when there is a rising edge on RXFWrSync
// (FIFO write enable) signal. Don't allow write pointer to increment if
// the FIFO is already full.
// If the FIFO is full and there is a simultaneous write and read, the
// write pointer should be incremented.
// ------------------------------------------------------------------
assign WrPtrIncValid = RXFWrSync & !(DelRXFWrSync) & ( !(FIFOFull) | (FIFOFull & RXFRdPtrInc));
// ------------------------------------------------------------------
// Freeze the Write pointer at Zero when the FIFO is disabled. When the
// FIFO is enabled and when the WrPtrIncValid signal is asserted,
// increment the Write pointer by 1.
// ------------------------------------------------------------------
always @(WrPtr or FEN or WrPtrIncValid)
begin : p_WrPtrComb
if (FEN == 1'b0)
NextWrPtr = 4'b0000;
else if (WrPtrIncValid == 1'b1)
NextWrPtr = ((WrPtr) + 1'b1);
else
NextWrPtr = WrPtr;
end // p_WrPtrComb;
// ------------------------------------------------------------------
// Increment the read pointer when there is a read from the APB
// interface. For safety, inhibit reads from having any effect if the
// FIFO is already empty.
// ------------------------------------------------------------------
assign RdPtrIncValid = RXFRdPtrInc & !(FIFOEmpty);
// ------------------------------------------------------------------
// Freeze the Read pointer at Zero when the FIFO is disabled. When the
// FIFO is enabled and when the RdPtrIncValid signal is asserted,
// increment the Read pointer by 1.
// ------------------------------------------------------------------
always @(RdPtr or FEN or RdPtrIncValid)
begin : p_RdPtrComb
if (FEN == 1'b0)
NextRdPtr = 4'b0000;
else if (RdPtrIncValid == 1'b1)
NextRdPtr = ((RdPtr) + 1'b1);
else
NextRdPtr = RdPtr;
end // p_RdPtrComb;
// ------------------------------------------------------------------
// The 'Wrap' bit is used to keep track of the condition when the write
// pointer has wrapped around from '1111' to '0000', but the read
// pointer has not wrapped. This bit is used to calculate the
// FIFOFillLevel. As with the pointers, the wrap is kept cleared when
// the FIFO is disabled. When both the pointers wrap around from '1111'
// to '0000' simultaneously, the Wrap bit remains unchanged.
// ------------------------------------------------------------------
always @(WrPtr or RdPtr or Wrap or FEN or WrPtrIncValid or
RdPtrIncValid)
begin : p_WrapComb
if (FEN == 1'b0)
NextWrap = 1'b0;
else if (((WrPtr == 4'b1111) & (WrPtrIncValid == 1'b1)) ^
((RdPtr == 4'b1111) & (RdPtrIncValid == 1'b1)))
NextWrap = !(Wrap);
else
NextWrap = Wrap;
end // p_WrapComb;
// ------------------------------------------------------------------
// The FIFOFull signal indicates the status of the FIFO when it is
// enabled.
// When the FIFO is one less than full and there is another write to the
// FIFO, the FIFOFull signal is set. When the FIFO is already full and
// there is a read from the FIFO without a simultaneous write, the
// FIFOFull signal is de-asserted
// ------------------------------------------------------------------
always @(*)
begin : p_FIFOFull
if (FEN == 1'b0)
NextFIFOFull = 1'b0;
else if ((RXFFillLevel == 5'b01111) && ((RXFWrSync == 1'b1) &&
(DelRXFWrSync == 1'b0)) && (RXFRdPtrInc == 1'b0))
NextFIFOFull = 1'b1;
else if ((FIFOFull == 1'b1) && (RXFRdPtrInc == 1'b1) &&
!((RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0)))
NextFIFOFull = 1'b0;
else
NextFIFOFull = FIFOFull;
end // p_FIFOFull;
// ------------------------------------------------------------------
// The FIFOEmpty signal indicates the status of the FIFO when it is
// enabled. If the FIFO is empty and there is a write to the FIFO, the
// FIFOEmpty signal is deasserted. If one location in the FIFO is filled
// and there is a read from the FIFO, the FIFOEmpty signal is asserted.
// ------------------------------------------------------------------
always @(*)
begin : p_FIFOEmpty
if (FEN == 1'b0)
NextFIFOEmpty = 1'b1;
else if ((FIFOEmpty == 1'b1) && ((RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0)))
NextFIFOEmpty = 1'b0;
else if ((RXFFillLevel == 5'b00001) && (RXFRdPtrInc == 1'b1) &&
!((RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0)))
NextFIFOEmpty = 1'b1;
else
NextFIFOEmpty = FIFOEmpty;
end // p_FIFOEmpty;
// ------------------------------------------------------------------
// When the FIFO is disabled, have a single bit to indicate fill status
// while the pointers are frozen at zero. Set the HldBufValid signal
// when a rising edge is detected on the RXFWrSync signal. Clear the
// HldBufValid signal when there is a write and a simultaneous read.
// ------------------------------------------------------------------
always @(FEN or RXFWrSync or RXFRdPtrInc or HldBufValid or DelRXFWrSync)
begin : p_BufValid
if (FEN == 1'b1)
NextHldBufValid = 1'b0;
else if ((RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0))
NextHldBufValid = 1'b1;
else if ((RXFRdPtrInc == 1'b1) &&
!((RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0)))
NextHldBufValid = 1'b0;
else
NextHldBufValid = HldBufValid;
end // p_BufValid;
// ------------------------------------------------------------------
// Overrun is set when the FIFO is full and there is another attempt to
// write and there is no simultaneous read from the FIFO. OverrunDet is
// cleared when there is a write to the UARTECR register and
// FIFO0overrunDet is cleared on the next successful write to the RXFIFO.
// ------------------------------------------------------------------
always @(RXFF or RXFWrSync or RXFRdPtrInc or OverrunDet or
FIFO0overrunDet or DelRXFWrSync or UARTECRWrEn)
begin : p_Overrun
if ((RXFF == 1'b1) && (RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0)
&& (RXFRdPtrInc == 1'b0))
begin
NextOverrunDet = 1'b1;
NextFIFO0overrunDet = 1'b1;
end
else if (UARTECRWrEn == 1'b1)
begin
NextOverrunDet = 1'b0;
NextFIFO0overrunDet = FIFO0overrunDet;
end
else if ((RXFWrSync == 1'b1) && (DelRXFWrSync == 1'b0) &&
(RXFF == 1'b0))
begin
NextFIFO0overrunDet = 1'b0;
NextOverrunDet = OverrunDet;
end
else
begin
NextOverrunDet = OverrunDet;
NextFIFO0overrunDet = FIFO0overrunDet;
end
end // p_Overrun;
// ------------------------------------------------------------------
// Generate an Overrun Interrupt (UARTOEINTR) when there is a rising
// edge on the OverrunDet line. Clear the interrupt on a write to
// bit 10 of the Interrupt clear register, using the UARTOEIClr
// signal. The rising edge is detected using the OverrunEdge signal.
// ------------------------------------------------------------------
assign OverrunEdge = OverrunDet & !(DelOverrunDet);
// ------------------------------------------------------------------
// UARTOEIClr is a one PCLK-wide pulse used to clear the UARTOEINTR.
// ------------------------------------------------------------------
assign UARTOEIClr = UARTOEIC & !(DelUARTOEIC);
always @(UARTOERIS or OverrunEdge or UARTOEIClr)
begin : p_UARTOEINTR
NextUARTOERIS = UARTOERIS;
if(OverrunEdge == 1'b1)
NextUARTOERIS = 1'b1;
else if (UARTOEIClr == 1'b1)
NextUARTOERIS = 1'b0;
end // p_UARTOEINTR;
assign UARTOEMIS = UARTOERIS & OEIM;
// ------------------------------------------------------------------
// The interrupt fifo level is programmable, it can be either at the
// quarter, half, three quarter level aswell as empty or full.
// ------------------------------------------------------------------
always @(*)
begin : p_RXIntLevel
NextRXIntLevel = RXIntLevel;
case (RXIFLSEL)
3'b000 : NextRXIntLevel = RXFGTE8Full;
3'b001 : NextRXIntLevel = RXFGTEQFull;
3'b010 : NextRXIntLevel = RXFGTEHalfFull;
3'b011 : NextRXIntLevel = RXFGTE3QFull;
3'b100 : NextRXIntLevel = RXFGTE78Full;
default : NextRXIntLevel = 1'b0;
endcase
end // p_RXIntLevel;
// ------------------------------------------------------------------
// UARTRXIClr is a one PCLK-wide pulse used to clear the UARTRXINTR.
// ------------------------------------------------------------------
assign UARTRXIClr = UARTRXIC & !(DelUARTRXIC);
// ------------------------------------------------------------------
// Detect an edge in the interrupt level line and HldBufValid line.
// ------------------------------------------------------------------
assign RXEdge = RXIntLevel ^ DelRXIntLevel;
assign HldBufValidEdge = HldBufValid ^ DelHldBufValid;
// ------------------------------------------------------------------
// The UARTRXINTR receive interrupt is set if one of the following
// conditions is met :
// * FIFO enabled and FIFO filled to the programmed level
// * FIFO disabled and the holding register is full
// The interrupt is cleared when either the contents of the Receive FIFO
// are read out such that there are the programmed level or more valid
// entries in the FIFO, or when bit 4 of the Interrupt Clear register
// is written to.
// ------------------------------------------------------------------
always @(*)
begin : p_UARTRXINTR
NextUARTRXRIS = UARTRXRIS;
if (((FEN == 1'b1) && (RXIntLevel == 1'b1) && (RXEdge == 1'b1)) ||
((FEN == 1'b0) && (HldBufValid == 1'b1) &&
(HldBufValidEdge == 1'b1)))
NextUARTRXRIS = 1'b1;
else if ((((FEN == 1'b1) && (RXIntLevel == 1'b0) && (RXEdge == 1'b1)) ||
((FEN == 1'b0) && (HldBufValid == 1'b0) &&
(HldBufValidEdge == 1'b1))))
NextUARTRXRIS = 1'b0;
else if (UARTRXIClr == 1'b1)
NextUARTRXRIS = 1'b0;
end // p_UARTRXINTR;
assign UARTRXMIS = UARTRXRIS & RXIM;
// ------------------------------------------------------------------
// The multiplexor determines the assignment of nUARTRTSint. When RTS
// flow control is enabled nUARTRTSint is asserted, (logic 0), when there
// is space in the fifo indicated by RXIntLevel,
// otherwise nUARTRTSint takes the value of bit 11 in the UARTCR.
// ------------------------------------------------------------------
always @(*)
begin : p_nUARTRTSint
NextnUARTRTSint = nUARTRTSint;
if ((RTSEn == 1'b1) && (RXIntLevel == 1'b0))
NextnUARTRTSint = 1'b0;
else if ((RTSEn == 1'b1) && (RXIntLevel == 1'b1))
NextnUARTRTSint = 1'b1;
else if (RTSEn == 1'b0)
NextnUARTRTSint = nUARTRTScr;
end // p_nUARTRTSint
// ------------------------------------------------------------------
// Subtract the read pointer from the write pointer to calculate the
// FIFO fill level. Use the wrap bit to take into account whether the
// write pointer has wrapped without the read pointer not having wrapped
// ------------------------------------------------------------------
assign WrPtrLevel = {Wrap,WrPtr};
assign RdPtrLevel = {1'b0,RdPtr};
assign RXFFillLevel = WrPtrLevel - RdPtrLevel;
// ------------------------------------------------------------------
// When the FIFO is enabled, use the FIFOFull signal to indicate FIFO
// fill status. When the FIFO is disabled, use the HldBufValid signal to
// indicate FIFO fill status.
// ------------------------------------------------------------------
assign RXFF = (FEN == 1'b1) ? FIFOFull : HldBufValid;
// ------------------------------------------------------------------
// When the FIFO is enabled, use the FIFOEmpty signal to indicate FIFO
// fill status. When the FIFO is disabled, use the HldBufValid signal to
// indicate FIFO fill status.
// ------------------------------------------------------------------
assign NextRXFE = (FEN == 1'b1) ? NextFIFOEmpty : !(NextHldBufValid);
// ------------------------------------------------------------------
// When the FIFO is enabled, use the RXFFillLevel signal to find whether
// the FIFO is greater than or equal to a one eighth, quarter, half,
// three quarter or seven eighth level. If the FIFO is disabled,
// the HldBufValid signal will indicate whether the FIFO is filled.
// ------------------------------------------------------------------
assign FIFOGTE8Full = (RXFFillLevel >= 5'b00010);
assign RXFGTE8Full = (FEN == 1'b1) ? FIFOGTE8Full : HldBufValid;
assign FIFOGTEQFull = ((RXFFillLevel) >= 5'b00100);
assign RXFGTEQFull = (FEN == 1'b1) ? FIFOGTEQFull : HldBufValid;
assign FIFOGTEHalfFull = ((RXFFillLevel) >= 5'b01000);
assign RXFGTEHalfFull = (FEN == 1'b1) ? FIFOGTEHalfFull : HldBufValid;
assign FIFOGTE3QFull = ((RXFFillLevel) >= 5'b01100);
assign RXFGTE3QFull = (FEN == 1'b1) ? FIFOGTE3QFull : HldBufValid;
assign FIFOGTE78Full = (RXFFillLevel >= 5'b01110);
assign RXFGTE78Full = (FEN == 1'b1) ? FIFOGTE78Full : HldBufValid;
// ------------------------------------------------------------------
// When the FIFO is enabled, use the RXFFillLevel signal to find
// whether the Receive FIFO contains at least one word. If the
// FIFO is disabled, the HldBufValid signal will do the job. When the
// receive FIFO contains at least one word the RXFGTE1Full
// signal is asserted.
// ------------------------------------------------------------------
assign FIFOGTE1Full = (RXFFillLevel >= 5'b00001);
assign RXFGTE1Full = (FEN == 1'b1) ? FIFOGTE1Full : HldBufValid;
endmodule
uartrxcntl.v
module uartrxcntl (
UARTCLK ,
nUARTRST,
Baud16,
UARTENSync,
SIRENSync,
RXESync,
RXD,
WLEN,
STP2,
PEN,
Zerobaud,
RXFWrDoneSync,
DtPrZero,
UARTFEICSync,
UARTBEICSync,
FEIMSync,
BEIMSync,
ShiftEn,
SampleParity,
RXEnable,
UartRXCntlState,
RXDsampled,
ClearShiftReg,
RXFWr,
ReloadWD,
FramingError,
Break,
RXBUSY,
CharRxComp,
UARTFERIS,
UARTBERIS,
UARTFEMIS,
UARTBEMIS
);
input UARTCLK ; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input Baud16; // Bit Period Reference
input UARTENSync; // UART Enable
input SIRENSync; // SIR Enable
input RXESync; // RXE Enable
input RXD; // Receive serial input
input [1:0] WLEN; // Data bits per word
input STP2; // 2 stop bits
input PEN; // Parity enable
input Zerobaud; // Baud Divisor set to 0
input RXFWrDoneSync; // RX FIFO Write Done
input DtPrZero; // Data bits and Parity bit zero
input UARTFEICSync; // For Framing Error interrupt clear
input UARTBEICSync; // For Framing Error interrupt clear
input FEIMSync; // Framing Error interrupt mask
input BEIMSync; // Break Error Interrupt mask
output ShiftEn; // Shift next bit
output SampleParity; // Enable Parity sample
output RXEnable; // Rx enable
output [2:0] UartRXCntlState; // Rx state
output RXDsampled; // Sampled Rx data stream
output ClearShiftReg; // Clear receive shifter
output RXFWr; // Receive FIFO Write (level)
output ReloadWD; // Restart watchdog counter
output FramingError; // Framing error detected
output Break; // Break detected
output CharRxComp; // Character Rx complete
output RXBUSY; // RX machine busy
output UARTFERIS; // Framing Error Raw status
output UARTBERIS; // Break Error Raw status
output UARTFEMIS; // Framing Error Masked status
output UARTBEMIS; // Break Error Masked status
// ------------------------------------------------------------------
//
// UartRXCntl
// ==========
//
// ------------------------------------------------------------------
//
// Overview
// ========
// The receive state machine controls the timing of sampling the input
// receive bit stream. It detects framing, parity errors. The parameters
// programmed into the LCR_H register are used to interpret the
// receive bit stream.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK ; // Main UART Clock (Module Input)
wire nUARTRST; // Muxed reset (from nUARTRST) (Module Input)
wire Baud16; // Bit Period Reference (Module Input)
wire UARTENSync; // UART Enable (Module Input)
wire SIRENSync; // SIR Enable (Module Input)
wire RXESync; // RXE Enable (Module Input)
wire [1:0] WLEN; // Data bits per word (Module Input)
wire STP2; // 2 stop bits (Module Input)
wire PEN; // Parity enable (Module Input)
wire Zerobaud; // Baud Divisor set to 0 (Module Input)
wire RXFWrDoneSync; // RX FIFO Write Done (Module Input)
wire RXD; // Receive serial input (Module Input)
wire DtPrZero; // Data bits and Parity bit zero(Module Input)
wire UARTFEICSync; // For Framing Error interrupt clear(Module Input)
wire UARTBEICSync; // For Framing Error interrupt clear(Module Input)
wire FEIMSync; // Framing Error interrupt mask(Module Input)
wire BEIMSync; // Break Error Interrupt mask (Module Input)
wire FramingEdge;
wire BreakEdge;
wire UARTFEIClr;
wire UARTBEIClr;
// Aliases
wire AbortReceive;
wire BreakDetStop;
wire BreakDetXStop;
// Comparators
wire BitPeriodCmp;
wire BitCmp;
wire FrmErrCmp;
wire BreakErrCmp;
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
// Encoding style: Gray
reg [2:0] iUartRXCntlState;
reg [2:0] UartRXCntlNextState;
reg SampleParity;
reg RXFWr;
reg ShiftEn;
reg ReloadWD;
reg ClearShiftReg;
reg RXBUSY;
reg UARTBERIS;
reg NextSampleParity;
reg NextRXFWr;
reg NextShiftEn;
reg NextReloadWD;
reg NextClearShiftReg;
reg NextRXBUSY;
reg NextUARTFERIS;
reg NextUARTBERIS;
reg RXD1;
reg RXD2;
reg RXD3;
reg iRXDsampled;
reg DelFramingError;
reg DelBreakError;
reg DelUARTFEICSync;
reg DelUARTBEICSync;
reg iUARTFERIS;
reg UARTFEMIS;
reg UARTBEMIS;
// Registers
reg [3:0] BitPeriodCnt;
reg [3:0] NextBitPeriodCnt;
reg [2:0] BitCnt;
reg [2:0] NextBitCnt;
reg iBreak;
reg NextiBreak;
reg iFramingError;
reg NextiFramingError;
reg iCharRxComp;
reg NextCharRxComp;
// ------------------------------------------------------------------
// Expose internal register(s)...
// ------------------------------------------------------------------
assign Break = iBreak;
assign FramingError = iFramingError;
assign UartRXCntlState= iUartRXCntlState;
assign RXDsampled = iRXDsampled;
assign UARTFERIS = iUARTFERIS;
assign CharRxComp = iCharRxComp;
// ------------------------------------------------------------------
// Expansion of aliases...
// ------------------------------------------------------------------
assign AbortReceive = Zerobaud;
assign RXEnable = (UARTENSync & RXESync);
assign BreakDetStop = !(iRXDsampled) & DtPrZero;
assign BreakDetXStop = !(iRXDsampled) & FrmErrCmp & DtPrZero;
// ------------------------------------------------------------------
// Expansion of comparators...
// ------------------------------------------------------------------
assign BitPeriodCmp = (BitPeriodCnt[3:0] == 4'b0000);
assign BitCmp = (BitCnt[2:0] == 3'b000);
assign FrmErrCmp = (iFramingError == 1'b1);
assign BreakErrCmp = (iBreak == 1'b1);
// ------------------------------------------------------------------
// State transition always @
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin : seq
if (nUARTRST == 1'b0)
begin
iUartRXCntlState <= 3'b000;
SampleParity <= 1'b0;
RXFWr <= 1'b0;
ShiftEn <= 1'b0;
ReloadWD <= 1'b0;
ClearShiftReg <= 1'b1;
RXBUSY <= 1'b0;
DelFramingError <= 1'b0;
DelUARTFEICSync <= 1'b0;
iUARTFERIS <= 1'b0;
DelBreakError <= 1'b0;
DelUARTBEICSync <= 1'b0;
UARTBERIS <= 1'b0;
iCharRxComp <= 1'b1;
end
else
begin
iUartRXCntlState <= UartRXCntlNextState;
SampleParity <= NextSampleParity;
RXFWr <= NextRXFWr;
ShiftEn <= NextShiftEn;
ReloadWD <= NextReloadWD;
ClearShiftReg <= NextClearShiftReg;
RXBUSY <= NextRXBUSY;
DelFramingError <= iFramingError;
DelUARTFEICSync <= UARTFEICSync;
iUARTFERIS <= NextUARTFERIS;
DelBreakError <= iBreak;
DelUARTBEICSync <= UARTBEICSync;
UARTBERIS <= NextUARTBERIS;
iCharRxComp <= NextCharRxComp;
end
end // seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_SampleRXD
if (nUARTRST == 1'b0)
begin
RXD1 <= 1'b1;
RXD2 <= 1'b1;
RXD3 <= 1'b1;
end
else if (Baud16 == 1'b1)
begin
RXD1 <= RXD;
RXD2 <= RXD1;
RXD3 <= RXD2;
end
end // p_SampleRXD;
always @(RXD1 or RXD2 or RXD3)
begin : p_vote
if (((RXD1 == 1'b1) && (RXD2 == 1'b1)) || ((RXD1 == 1'b1)
&& (RXD3 == 1'b1)) || ((RXD2 == 1'b1) && (RXD3 == 1'b1)))
iRXDsampled = 1'b1;
else
iRXDsampled = 1'b0;
end // p_vote;
// ------------------------------------------------------------------
// Output and next state logic generation
// ------------------------------------------------------------------
always @(*)
begin : combo
// Default assignments
UartRXCntlNextState = iUartRXCntlState;
NextSampleParity = 1'b0;
NextRXFWr = 1'b0;
NextShiftEn = 1'b0;
NextReloadWD = 1'b0;
NextClearShiftReg = 1'b0;
NextRXBUSY = 1'b0;
NextBitPeriodCnt = BitPeriodCnt;
NextBitCnt = BitCnt;
NextiBreak = iBreak;
NextiFramingError = iFramingError;
NextCharRxComp = iCharRxComp;
case (iUartRXCntlState)
3'b000 :
//Detect RXD low
begin
if ((!(iRXDsampled)) && (!(AbortReceive)) && RXEnable) == 1'b1)
begin
if (SIRENSync == 1'b1)
NextBitPeriodCnt[3:0] = 4'b0100;
else
NextBitPeriodCnt[3:0] = 4'b1000;
UartRXCntlNextState = 3'b001;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
else
NextClearShiftReg = 1'b1;
end
3'b001 :
begin
// If at any time the RXD line goes HIGH, invalidate the start bit .
if ((Baud16 & iRXDsampled) | AbortReceive) == 1'b1)
begin
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
NextCharRxComp = 1'b1;
end
// Valid start bit detected
else if ((Baud16 & BitPeriodCmp & !(AbortReceive) &
!(iRXDsampled)) == 1'b1)
begin
NextReloadWD = 1'b1;
NextBitPeriodCnt = 4'b1111;
NextBitCnt[2:0] = {1'b1, WLEN[1:0]};
UartRXCntlNextState = 3'b011;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
// Count down from 7 to 0 with Baud16 as the count enable
// to find the middle of the start bit
else if ((Baud16 & !(BitPeriodCmp) & !(AbortReceive)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartRXCntlNextState = 3'b001;
NextRXBUSY = 1'b1;
end
else
NextRXBUSY = 1'b1;
end
3'b011 :
begin
// Decrement BitPeriodCnt with Baud16 as the count enable
if ((Baud16 & !(BitPeriodCmp) & !(AbortReceive)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartRXCntlNextState = 3'b011;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
// Shift in next bit
else if ((Baud16 & BitPeriodCmp & !(BitCmp) & !(AbortReceive))
== 1'b1)
begin
NextShiftEn = 1'b1;
NextBitCnt = BitCnt - 1'b1;
NextBitPeriodCnt = 4'b1111;
UartRXCntlNextState = 3'b011;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
// Parity enabled
else if ((Baud16 & BitCmp & BitPeriodCmp & PEN &
!(AbortReceive)) == 1'b1)
begin
NextShiftEn = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartRXCntlNextState = 3'b010;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
// Parity disabled
else if ((Baud16 & BitCmp & BitPeriodCmp & !(PEN) &
!(AbortReceive)) == 1'b1)
begin
NextShiftEn = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartRXCntlNextState = 3'b101;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
else if (AbortReceive == 1'b1)
begin
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
NextCharRxComp = 1'b1;
end
else
NextRXBUSY = 1'b1;
end
3'b010 :
begin
// Decrement BitPeriodCnt counter to reach the middle of the
// next bit
if ((Baud16 & !(BitPeriodCmp) & !(AbortReceive)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartRXCntlNextState = 3'b010;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
// Sample Parity bit
else if ((Baud16 & BitPeriodCmp & !(AbortReceive)) == 1'b1)
begin
NextSampleParity = 1'b1;
NextBitPeriodCnt = 4'b1111;
UartRXCntlNextState = 3'b101;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
else if (AbortReceive == 1'b1)
begin
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
NextCharRxComp = 1'b1;
end
else
NextRXBUSY = 1'b1;
end
3'b110 :
// Decrement BitPeriodCnt
begin
if ((Baud16 & !(BitPeriodCmp) & !(AbortReceive)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartRXCntlNextState = 3'b110;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
else if (AbortReceive == 1'b1)
begin
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
end
// Wait complete for additional stop bit time
else if ((Baud16 & BitPeriodCmp & !(AbortReceive)) == 1'b1)
begin
NextReloadWD = 1'b1;
NextBitPeriodCnt = 4'b1111;
NextiBreak = BreakDetXStop;
UartRXCntlNextState = 3'b111;
NextRXFWr = 1'b1;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b1;
end
else
NextRXBUSY = 1'b1;
end
3'b111 :
begin
// If the FIFOWrDone signal is asserted and if there was no
// framing error or Abort condition or if the RXD line went
// HIGH then wait for the next start bits
if (((BreakErrCmp) & RXFWrDoneSync & (!(FrmErrCmp)
| iRXDsampled | AbortReceive))) == 1'b1)
begin
NextiBreak = 1'b0;
NextiFramingError = 1'b0;
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
NextCharRxComp = 1'b1;
end
// If there was a framing error, then decrement the BitPeriodCnt
// counter to detect the middle of the next start bit
else if ((Baud16 & !(BitPeriodCmp) & FrmErrCmp & !(AbortReceive)
& !(iRXDsampled) & !(BreakErrCmp)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartRXCntlNextState = 3'b111;
NextRXFWr = 1'b1;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b1;
end
// Framing error detected in previous byte; next bit
// low - taken as start bit for next byte.
else if ((RXFWrDoneSync & !(BreakErrCmp) & BitPeriodCmp
& Baud16 & !(iRXDsampled) & !(AbortReceive) &
FrmErrCmp & RXEnable) == 1'b1)
begin
NextReloadWD = 1'b1;
NextClearShiftReg = 1'b1;
NextBitPeriodCnt = 4'b1111;
NextBitCnt[2:0] = {1'b1, WLEN[1:0]};
NextiBreak = 1'b0;
NextiFramingError = 1'b0;
UartRXCntlNextState = 3'b011;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
end
else if ((BreakErrCmp & RXFWrDoneSync) == 1'b1)
// Break detected
begin
UartRXCntlNextState = 3'b100;
NextRXBUSY = 1'b1;
end
else
begin
NextRXFWr = 1'b1;
NextRXBUSY = 1'b1;
end
end
3'b101 :
// 2 stop bits programmed
begin
if ((Baud16 & BitPeriodCmp & STP2 & !(AbortReceive)) == 1'b1)
begin
NextBitPeriodCnt = 4'b1111;
NextiFramingError = !(iRXDsampled);
UartRXCntlNextState = 3'b110;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b0;
// Decrement BitPeriodCnt counter to reach the middle of the
// next bit
end
else if ((Baud16 & !(BitPeriodCmp) & !(AbortReceive)) == 1'b1)
begin
NextBitPeriodCnt = BitPeriodCnt - 1'b1;
UartRXCntlNextState = 3'b101;
NextRXBUSY = 1'b1;
end
else if (AbortReceive == 1'b1)
begin
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
end
// Only one stop bit
else if ((Baud16 & BitPeriodCmp & !(STP2) & !(AbortReceive))
== 1'b1)
begin
NextReloadWD = 1'b1;
NextBitPeriodCnt = 4'b1111;
NextiBreak = BreakDetStop;
NextiFramingError = !(iRXDsampled);
UartRXCntlNextState = 3'b111;
NextRXFWr = 1'b1;
NextRXBUSY = 1'b1;
NextCharRxComp = 1'b1;
end
else
NextRXBUSY = 1'b1;
end
3'b100 :
// Break released; RXD line high again
begin
if (iRXDsampled == 1'b1)
begin
UartRXCntlNextState = 3'b000;
NextClearShiftReg = 1'b1;
NextCharRxComp = 1'b1;
end
else
NextRXBUSY = 1'b1;
end
default :
UartRXCntlNextState = 3'b000;
endcase
end // combo;
// ------------------------------------------------------------------
// Detect rising edge in Framing Error and Break Error
// ------------------------------------------------------------------
assign BreakEdge = iBreak & !(DelBreakError);
assign FramingEdge = iFramingError & !(DelFramingError);
// ------------------------------------------------------------------
// UARTFEIClr is a one UART-wide pulse used to clear the UARTFEINTR.
// UARTBEIClr is a one UART-wide pulse used to clear the UARTBEINTR.
// ------------------------------------------------------------------
assign UARTFEIClr = UARTFEICSync & !(DelUARTFEICSync);
assign UARTBEIClr = UARTBEICSync & !(DelUARTBEICSync);
// ------------------------------------------------------------------
// Generate a framing error interrupt when there is a rising edge
// on the framing error line. Clear the error when there is a write
// to bit 7 of the Interrupt clear register.
// ------------------------------------------------------------------
always @ (*)
begin : p_UARTFEINTR
NextUARTFERIS = iUARTFERIS;
if(FramingEdge == 1'b1)
NextUARTFERIS = 1'b1;
else if (UARTFEIClr == 1'b1)
NextUARTFERIS = 1'b0;
end // p_UARTFEINTR;
always @(posedge UARTCLK or negedge nUARTRST)
begin
if (nUARTRST == 1'b0)
UARTFEMIS <= 1'b0;
else
UARTFEMIS <= NextUARTFERIS & FEIMSync;
end
// ------------------------------------------------------------------
// Generate a break error interrupt when there is a rising edge
// on the break error line. Clear the error when there is a write
// to bit 7 of the Interrupt clear register.
// ------------------------------------------------------------------
always @ (*)
begin : p_UARTBEINTR
NextUARTBERIS = UARTBERIS;
if(BreakEdge == 1'b1)
NextUARTBERIS = 1'b1;
else if (UARTBEIClr == 1'b1)
NextUARTBERIS = 1'b0;
end // p_UARTBEINTR;
always @(posedge UARTCLK or negedge nUARTRST)
begin
if (nUARTRST == 1'b0)
UARTBEMIS <= 1'b0;
else
UARTBEMIS <= NextUARTBERIS & BEIMSync;
end
always @(posedge UARTCLK or negedge nUARTRST)
begin : BitPeriodCnt_seq
if (nUARTRST == 1'b0)
BitPeriodCnt <= 4'b0000;
else
BitPeriodCnt <= NextBitPeriodCnt;
end // BitPeriodCnt_seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : BitCnt_seq
if (nUARTRST == 1'b0)
BitCnt <= 3'b000;
else
BitCnt <= NextBitCnt;
end // BitCnt_seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : iBreak_seq
if (nUARTRST == 1'b0)
iBreak <= 1'b0;
else
iBreak <= NextiBreak;
end // iBreak_seq;
always @(posedge UARTCLK or negedge nUARTRST)
begin : iFramingError_seq
if (nUARTRST == 1'b0)
iFramingError <= 1'b0;
else
iFramingError <= NextiFramingError;
end // iFramingError_seq;
// Signals: UartRXCntlState<2:0> UartRXCntlNextState<2:0>
// ST_IDLE 000
// ST_STARTBIT 001
// ST_SHIFT 011
// ST_PARITY 010
// ST_XSTOP 110
// ST_FIFOWRITE 111
// ST_STOPBIT 101
// ST_BREAK 100
endmodule
// - ==================== End of UartRXCntl ====================