uart验证(5)
uartregblock.v
module uartregblock (
PCLK,
PRESETn,
RXFRdPtrInc,
PWDATAIn,
RXFRdData,
UARTECRWrEn,
UARTLCRHWrEn,
UARTILPRWrEn,
UARTCRWrEn,
UARTICRWrEn,
UARTIBRDWrEn,
UARTFBRDWrEn,
UARTIFLSWrEn,
UARTIMSCWrEn,
UARTDMACRWrEn,
UARTOEIClr,
UARTRTRIS,
UARTRISerrSync,
UARTRISmodSync,
UARTTXIClr,
UARTRXIClr,
LCRUpdate,
ILPRUpdate,
FBRDUpdate,
UARTICR,
RXSTATUS,
UARTLCRH,
UARTLCRM,
UARTLCRL,
UARTILPR,
UARTCR,
UARTIFLS,
UARTDMACR,
UARTFBRD,
UARTIMSC
);
input PCLK; // APB Bus Clock
input PRESETn; // APB Bus Reset
input RXFRdPtrInc; // RX FIFO Read pointer Incr.
input [15:0] PWDATAIn; // Data bus
input [10:8] RXFRdData; // RX Stat bit
input UARTECRWrEn; // Write Enable for UARTECR
input UARTLCRHWrEn; // Write Enable for LCRH_
input UARTILPRWrEn; // Write Enable for ILPR
input UARTCRWrEn; // Write Enable for UARTCR
input UARTICRWrEn; // Write Enable for UARTICR
input UARTIBRDWrEn; // Write Enable for UARTIBRD
input UARTFBRDWrEn; // Write Enable for UARTFBRD
input UARTIFLSWrEn; // Write Enable for UARTIFLS
input UARTIMSCWrEn; // Write Enable for UARTIMSC
input UARTDMACRWrEn; // Write Enable for UARTDMACR
input UARTOEIClr; // Overrun Error Int. Clr
input UARTRTRIS; // Receive Timeout Interrupt
input [2:0] UARTRISerrSync; // Raw error interrupts
input [3:0] UARTRISmodSync; // Raw modem interrupt status
input UARTTXIClr; // UARTICR Tx int. Clr
input UARTRXIClr; // UARTICR Rx int. Clr input [10:8]
output LCRUpdate; // LCR update trigger
output ILPRUpdate; // ILPR update trigger
output FBRDUpdate; // ILPR update trigger
output [10:0] UARTICR; // For Interrupt Clears
output [2:0] RXSTATUS; // RX Stat bits output [6:0]
output [7:0] UARTLCRH; // 1st buffer
output [7:0] UARTLCRM; // 1st buffer
output [7:0] UARTLCRL; // 1st buffer
output [7:0] UARTILPR; // 1st buffer
output [15:0] UARTCR; // CR bits
output [5:0] UARTIFLS; // IFLS bits
output [2:0] UARTDMACR; // CR bits
output [5:0] UARTFBRD; // FBRD bits
output [10:0] UARTIMSC; // modem mask bits
// ------------------------------------------------------------------
// UartRegBlock
// ============
// ------------------------------------------------------------------
// Overview
// ========
// This block contains the normal mode registers for the UART. Write
// data from the PWDATAIn bus is clocked in when the appropriate write
// enable signal is asserted.
// This block contains the first buffer in the 2-buffer synchronisation
// mechanism for the LCR. It also contains the first buffer for the
// 2-buffer synchronisation mechanism for the ILPR.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declarations
// ------------------------------------------------------------------
wire PCLK; // APB Bus Clock (Module Input)
wire PRESETn; // APB Bus Reset (Module Input)
wire RXFRdPtrInc; // RX FIFO Read pointer Incr. (Module Input)
wire UARTECRWrEn; // Write Enable for UARTECR (Module Input)
wire UARTLCRHWrEn; // Write Enable for LCRH_ (Module Input)
wire UARTILPRWrEn; // Write Enable for ILPR (Module Input)
wire UARTCRWrEn; // Write Enable for UARTCR (Module Input)
wire UARTICRWrEn; // Write Enable for UARTICR (Module Input)
wire UARTIBRDWrEn; // Write Enable for UARTIBRD (Module Input)
wire UARTFBRDWrEn; // Write Enable for UARTFBRD (Module Input)
wire UARTIFLSWrEn; // Write Enable for UARTIFLS (Module Input)
wire UARTIMSCWrEn; // Write Enable for UARTIMSC (Module Input)
wire UARTDMACRWrEn; // Write Enable for UARTDMACR (Module Input)
wire [15:0] PWDATAIn; // Data bus (Module Input)
wire UARTOEIClr; // Overrun Error Int. Clr (Module Input)
wire UARTTXIClr; // UARTICR Tx int. Clr (Module Input)
wire UARTRXIClr; // UARTICR Rx int. Clr input [10:8](Module Input)
wire [10:8] RXFRdData; // RX Stat bit (Module Input)
// ------------------------------------------------------------------
// Register declarations
// ------------------------------------------------------------------
reg [7:0] iUARTLCRH; // 1st stage buffer for UARTLCRH.
reg [7:0] NextLCRH; // D-input of iUARTLCRH
reg [7:0] iUARTLCRM; // 1st stage buffer for UARTLCRM
reg [7:0] NextLCRM; // D-input of iUARTLCRM
reg [7:0] iUARTLCRL; // 1st stage buffer for UARTLCRL
reg [7:0] NextLCRL; // D-input of iUARTLCRL
reg iLCRUpdate; // Internal copy of Update trigger for LCR registers
reg NextLCRUpdate; // D-input of iUpdateLCR
reg [5:0] NextUARTFBRD; // D-input of iUARTFBRD
reg [5:0] iUARTFBRD; // Internal copy of UARTFBRD
reg [2:0] iRXSTATUS; // Receive Status bits
reg [2:0] NextRXSTATUS; // D-input of iRXSTATUS
reg [7:0] iUARTILPR; // 1st stage buffer for UARTILPR
reg [7:0] NextILPR; // D-input of iUARTILPR
reg iILPRUpdate; // Internal copy of update trigger for the UARTILPR register
reg iFBRDUpdate; // Internal copy of update trigger for the FBRD register
reg NextILPRUpdate; // D-input of iUpdateILPR
reg NextFBRDUpdate; // D-input of iUpdateILPR
reg [15:0] iUARTCR; // UARTCR
reg [15:0] NextUARTCR; // D-input of UARTCR
reg [2:0] iUARTDMACR; // UARTDMACR
reg [2:0] NextUARTDMACR; // D-input of UARTDMACR
reg [5:0] iUARTIFLS; // UARTIFLS
reg [5:0] NextUARTIFLS; // D-input of UARTIFLS
reg iUARTOEIC; // UARTOEIC (UARTICR(10))
reg iUARTBEIC; // UARTBEIC (UARTICR(9))
reg iUARTPEIC; // UARTBEIC (UARTICR(8))
reg iUARTFEIC; // UARTFEIC (UARTICR(7))
reg iUARTRTIC; // UARTRTIC (UARTICR(6))
reg iUARTTXIC; // UARTTXIC (UARTICR(5))
reg iUARTRXIC; // UARTRXIC (UARTICR(4))
reg iUARTDCDIC; // UARTDCDIC (UARTICR(2))
reg iUARTDSRIC; // UARTDSRIC (UARTICR(3))
reg iUARTCTSIC; // UARTCTSIC (UARTICR(1))
reg iUARTRIIC; // UARTRIIC (UARTICR(0))
reg NextUARTOEIC; // D-input of UARTOEIC
reg NextUARTBEIC; // D-input of UARTBEIC
reg NextUARTPEIC; // D-input of UARTPEIC
reg NextUARTFEIC; // D-input of UARTFEIC
reg NextUARTRTIC; // D-input of UARTRTIC
reg NextUARTDCDIC; // D-input of UARTDCDIC
reg NextUARTDSRIC; // D-input of UARTDSRIC
reg NextUARTCTSIC; // D-input of UARTCTSIC
reg NextUARTRIIC; // D-input of UARTRIIC
reg NextUARTTXIC; // D-input of UARTTXIC
reg NextUARTRXIC; // D-input of UARTRXIC
reg [10:0] UARTIMSC; // Modem mask bit
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Copy the upper 3 bits of data read from the Receive FIFO into
// the RXSTATUS register.
// ------------------------------------------------------------------
always @(RXFRdPtrInc or UARTECRWrEn or RXFRdData or iRXSTATUS)
begin : p_RFStatComb
NextRXSTATUS = iRXSTATUS;
if(UARTECRWrEn == 1'b1)
NextRXSTATUS = 3'b000;
else if(RXFRdPtrInc == 1'b1)
NextRXSTATUS = RXFRdData;
end // p_RFStatComb
// ------------------------------------------------------------------
// Sequential always for Receive FIFO status.
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)//novas -21013
begin : p_RFStatSeq
if(PRESETn == 1'b0)
iRXSTATUS <= 3'b000;
else
iRXSTATUS <= NextRXSTATUS;
end // p_RFStatSeq
// ------------------------------------------------------------------
// Combinational always for 1st stage buffers for LCR. When the
// respective write enable input is asserted or copy the contents of
// the PWDATAIn bus into the corresponding 1st stage buffer.
// ------------------------------------------------------------------
always @(PWDATAIn or iUARTLCRH or iUARTLCRM or iUARTLCRL or UARTIBRDWrEn or
UARTLCRHWrEn )
begin : p_LCRComb
NextLCRH = iUARTLCRH;
NextLCRM = iUARTLCRM;
NextLCRL = iUARTLCRL;
if (UARTLCRHWrEn == 1'b1)
NextLCRH = PWDATAIn[7:0];
if (UARTIBRDWrEn == 1'b1)
NextLCRM = PWDATAIn[15:8];
else
NextLCRM = iUARTLCRM;
if (UARTIBRDWrEn == 1'b1)
NextLCRL = PWDATAIn[7:0];
end // p_LCRComb
// ------------------------------------------------------------------
// Sequential always for first stage buffers for LCR
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_LCRSeq
if(PRESETn == 1'b0)
begin
iUARTLCRH <= 8'b00000000;
iUARTLCRM <= 8'b00000000;
iUARTLCRL <= 8'b00000000;
end
else
begin
iUARTLCRH <= NextLCRH;
iUARTLCRM <= NextLCRM;
iUARTLCRL <= NextLCRL;
end
end // p_LCRSeq
// ------------------------------------------------------------------
// The iLCRUpdate reg toggles with every write into UARTLCRH.
// ------------------------------------------------------------------
always @(iLCRUpdate or UARTLCRHWrEn)
begin : p_UpdtLCRComb
NextLCRUpdate = iLCRUpdate;
if (UARTLCRHWrEn == 1'b1)
NextLCRUpdate = !(iLCRUpdate);
end // p_UpdtLCRComb;
// ------------------------------------------------------------------
// Sequential always for iLCRUpdate.
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_UpdtLCRSeq
if (PRESETn == 1'b0)
iLCRUpdate <= 1'b0;
else
iLCRUpdate <= NextLCRUpdate;
end // p_UpdtLCRSeq
// ------------------------------------------------------------------
// The iFBRDUpdate signal toggles with every write into UARTFBRD.
// ------------------------------------------------------------------
always @(iFBRDUpdate or UARTFBRDWrEn)
begin : p_UpdtFBRDComb
NextFBRDUpdate = iFBRDUpdate;
if(UARTFBRDWrEn == 1'b1)
NextFBRDUpdate = ~iFBRDUpdate;
end // p_UpdtFBRDComb
// ------------------------------------------------------------------
// Sequential process for iFBRDUpdate
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_UpdtFBRDSeq
if(PRESETn == 1'b0)
iFBRDUpdate <= 1'b0;
else
iFBRDUpdate <= NextFBRDUpdate;
end // p_UpdtFBRDSeq
// ------------------------------------------------------------------
// Clock PWDATAIn into UARTFBRD when UARTFBRDWrEn is asserted.
// ------------------------------------------------------------------
always @(UARTFBRDWrEn or iUARTFBRD or PWDATAIn)
begin : p_FBRDComb
NextUARTFBRD = iUARTFBRD;
if(UARTFBRDWrEn == 1'b1)
NextUARTFBRD = PWDATAIn[5:0];
end // p_FBRDComb
// ------------------------------------------------------------------
// Sequential process for UARTFBRD
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_FBRDSeq
if(PRESETn == 1'b0)
iUARTFBRD <= 6'b000000;
else
iUARTFBRD <= NextUARTFBRD;
end // p_FBRDSeq
// ------------------------------------------------------------------
// Clock in PWDATAIn into ILPR when UARTILPRWrEn is asserted.
// ------------------------------------------------------------------
always @(UARTILPRWrEn or iUARTILPR or PWDATAIn)
begin : p_ILPRComb
NextILPR = iUARTILPR;
if(UARTILPRWrEn == 1'b1)
NextILPR = PWDATAIn[7:0];
end // p_ILPRComb
// ------------------------------------------------------------------
// Sequential always for ILPR first stage buffer
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_ILPRSeq
if(PRESETn == 1'b0)
iUARTILPR <= 8'b00000000;
else
iUARTILPR <= NextILPR;
end // p_ILPRSeq
// ------------------------------------------------------------------
// The iILPRUpdate reg toggles with every write to the UARTILPR register
// ------------------------------------------------------------------
always @(iILPRUpdate or UARTILPRWrEn)
begin : p_UpdtILPRComb
NextILPRUpdate = iILPRUpdate;
if (UARTILPRWrEn == 1'b1)
NextILPRUpdate = !(iILPRUpdate);
end // p_UpdtILPRComb
// ------------------------------------------------------------------
// Sequential always for iILPRUpdate
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_UpdtILPRSeq
if (PRESETn == 1'b0)
iILPRUpdate <= 1'b0;
else
iILPRUpdate <= NextILPRUpdate;
end // p_UpdtILPRSeq
// ------------------------------------------------------------------
// Clock PWDATAIn into UARTCR when UARTCRWrEn is asserted.
// ------------------------------------------------------------------
always @(UARTCRWrEn or iUARTCR or PWDATAIn)
begin : p_CRComb
NextUARTCR = iUARTCR;
if(UARTCRWrEn == 1'b1)
NextUARTCR = PWDATAIn[15:0];
else
NextUARTCR = iUARTCR;
end // p_CRComb
// ------------------------------------------------------------------
// Clock PWDATAIn into UARTDMACR when UARTDMACRWrEn is asserted.
// ------------------------------------------------------------------
always @(UARTDMACRWrEn or iUARTDMACR or PWDATAIn)
begin : p_DMACRComb
NextUARTDMACR = iUARTDMACR;
if(UARTDMACRWrEn == 1'b1)
NextUARTDMACR = PWDATAIn[2:0];
end // p_DMACRComb;
// ------------------------------------------------------------------
// Sequential process for UARTDMACR
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_DMACRSeq
if(PRESETn == 1'b0)
iUARTDMACR <= 3'b000;
else
iUARTDMACR <= NextUARTDMACR;
end // p_DMACRSeq;
// ------------------------------------------------------------------
// Sequential always for UARTCR
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_CRSeq
if(PRESETn == 1'b0)
iUARTCR <= 16'b1100000000;
else
iUARTCR <= NextUARTCR;
end // p_CRSeq
// ------------------------------------------------------------------
// Clock PWDATAIn into UARTIFLS when UARTIFLSWrEn is asserted.
// ------------------------------------------------------------------
always @(UARTIFLSWrEn or iUARTIFLS or PWDATAIn)
begin : p_IFLSComb
NextUARTIFLS = iUARTIFLS;
if(UARTIFLSWrEn == 1'b1)
NextUARTIFLS = PWDATAIn[5:0];
end // p_IFLSComb
// ------------------------------------------------------------------
// Sequential always for UARTIFLS
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_IFLSSeq
if(PRESETn == 1'b0)
iUARTIFLS <= 6'b0010010;
else
iUARTIFLS <= NextUARTIFLS;
end // p_IFLSSeq
// ------------------------------------------------------------------
// UARTICR Register : Overrun Error
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTOEIC or UARTOEIClr or PWDATAIn)
begin : p_OEINTComb
NextUARTOEIC = iUARTOEIC;
if(UARTICRWrEn == 1'b1)
NextUARTOEIC = PWDATAIn[10];
else if(UARTOEIClr == 1'b1)
NextUARTOEIC = 1'b0;
end // p_OEINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_OEINTSeq
if(PRESETn == 1'b0)
iUARTOEIC <= 1'b0;
else
iUARTOEIC <= NextUARTOEIC;
end // p_OEINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Break Error
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTBEIC or UARTRISerrSync or PWDATAIn)
begin : p_BEINTComb
NextUARTBEIC = iUARTBEIC;
if(UARTICRWrEn == 1'b1)
NextUARTBEIC = PWDATAIn[9];
else if(UARTRISerrSync[2] == 1'b0)
NextUARTBEIC = 1'b0;
end // p_BEINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_BEINTSeq
if(PRESETn == 1'b0)
iUARTBEIC <= 1'b0;
else
iUARTBEIC <= NextUARTBEIC;
end // p_BEINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Parity Error
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTPEIC or UARTRISerrSync or PWDATAIn)
begin : p_PEINTComb
NextUARTPEIC = iUARTPEIC;
if(UARTICRWrEn == 1'b1)
NextUARTPEIC = PWDATAIn[8];
else if (UARTRISerrSync[1] == 1'b0)
NextUARTPEIC = 1'b0;
end // p_PEINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_PEINTSeq
if(PRESETn == 1'b0)
iUARTPEIC <= 1'b0;
else
iUARTPEIC <= NextUARTPEIC;
end // p_PEINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Framing Error
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTFEIC or UARTRISerrSync or PWDATAIn)
begin : p_FEINTComb
NextUARTFEIC = iUARTFEIC;
if(UARTICRWrEn == 1'b1)
NextUARTFEIC = PWDATAIn[7];
else if(UARTRISerrSync[0] == 1'b0)
NextUARTFEIC = 1'b0;
end // p_FEINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_FEINTSeq
if(PRESETn == 1'b0)
iUARTFEIC <= 1'b0;
else
iUARTFEIC <= NextUARTFEIC;
end // p_FEINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Receive Timeout
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTRTIC or UARTRTRIS or PWDATAIn)
begin : p_RTINTComb
NextUARTRTIC = iUARTRTIC;
if(UARTICRWrEn == 1'b1)
NextUARTRTIC = PWDATAIn[6];
else if (UARTRTRIS == 1'b0)
NextUARTRTIC = 1'b0;
end // p_RTINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_RTINTSeq
if(PRESETn == 1'b0)
iUARTRTIC <= 1'b0;
else
iUARTRTIC <= NextUARTRTIC;
end // p_RTINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Rx Interrupt
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTRXIC or UARTRXIClr or PWDATAIn)
begin : p_RXINTComb
NextUARTRXIC = iUARTRXIC;
if(UARTICRWrEn == 1'b1)
NextUARTRXIC = PWDATAIn[4];
else if (UARTRXIClr == 1'b1)
NextUARTRXIC = 1'b0;
end // p_RXINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_RXINTSeq
if(PRESETn == 1'b0)
iUARTRXIC <= 1'b0;
else
iUARTRXIC <= NextUARTRXIC;
end // p_RXINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Tx Interrupt
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTTXIC or UARTTXIClr or PWDATAIn)
begin : p_TXINTComb
NextUARTTXIC = iUARTTXIC;
if(UARTICRWrEn == 1'b1)
NextUARTTXIC = PWDATAIn[5];
else if (UARTTXIClr == 1'b1)
NextUARTTXIC = 1'b0;
end // p_TXINTComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_TXINTSeq
if(PRESETn == 1'b0)
iUARTTXIC <= 1'b0;
else
iUARTTXIC <= NextUARTTXIC;
end // p_TXINTSeq;
// ------------------------------------------------------------------
// UARTICR Register : Modem DSR Line
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTDSRIC or UARTRISmodSync or PWDATAIn)
begin : p_DSRComb
NextUARTDSRIC = iUARTDSRIC;
if(UARTICRWrEn == 1'b1)
NextUARTDSRIC = PWDATAIn[3];
else if (UARTRISmodSync[3] == 1'b0)
NextUARTDSRIC = 1'b0;
end // p_DSRComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_DSRSeq
if(PRESETn == 1'b0)
iUARTDSRIC <= 1'b0;
else
iUARTDSRIC <= NextUARTDSRIC;
end // p_DSRSeq;
// ------------------------------------------------------------------
// UARTICR Register : Modem DCD Line
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTDCDIC or UARTRISmodSync or PWDATAIn)
begin : p_DCDComb
NextUARTDCDIC = iUARTDCDIC;
if(UARTICRWrEn == 1'b1)
NextUARTDCDIC = PWDATAIn[2];
else if(UARTRISmodSync[2] == 1'b0)
NextUARTDCDIC = 1'b0;
end // p_DCDComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_DCDSeq
if(PRESETn == 1'b0)
iUARTDCDIC <= 1'b0;
else
iUARTDCDIC <= NextUARTDCDIC;
end // p_DCDSeq;
// ------------------------------------------------------------------
// UARTICR Register : Modem CTS Line
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTCTSIC or UARTRISmodSync or PWDATAIn)
begin : p_CTSComb
NextUARTCTSIC = iUARTCTSIC;
if(UARTICRWrEn == 1'b1)
NextUARTCTSIC = PWDATAIn[1];
else if(UARTRISmodSync[1] == 1'b0)
NextUARTCTSIC = 1'b0;
end // p_CTSComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_CTSSeq
if(PRESETn == 1'b0)
iUARTCTSIC <= 1'b0;
else
iUARTCTSIC <= NextUARTCTSIC;
end // p_CTSSeq;
// ------------------------------------------------------------------
// UARTICR Register : Modem RI Line
// ------------------------------------------------------------------
always @(UARTICRWrEn or iUARTRIIC or UARTRISmodSync or PWDATAIn)
begin : p_RIComb
NextUARTRIIC = iUARTRIIC;
if(UARTICRWrEn == 1'b1)
NextUARTRIIC = PWDATAIn[0];
else if(UARTRISmodSync[0] == 1'b0)
NextUARTRIIC = 1'b0;
end // p_RIComb;
always @(posedge PCLK or negedge PRESETn)
begin : p_RISeq
if(PRESETn == 1'b0)
iUARTRIIC <= 1'b0;
else
iUARTRIIC <= NextUARTRIIC;
end // p_RISeq;
assign UARTICR[10] = iUARTOEIC;
assign UARTICR[9] = iUARTBEIC;
assign UARTICR[8] = iUARTPEIC;
assign UARTICR[7] = iUARTFEIC;
assign UARTICR[6] = iUARTRTIC;
assign UARTICR[5] = iUARTTXIC;
assign UARTICR[4] = iUARTRXIC;
assign UARTICR[3] = iUARTDSRIC;
assign UARTICR[2] = iUARTDCDIC;
assign UARTICR[1] = iUARTCTSIC;
assign UARTICR[0] = iUARTRIIC;
// ------------------------------------------------------------------
// UARTIMSC Register
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)
begin : p_Mask
if(PRESETn == 1'b0)
UARTIMSC <= 11'b00000000000;
else if(UARTIMSCWrEn == 1'b1)
UARTIMSC <= PWDATAIn[10:0];
end // p_Mask;
// ------------------------------------------------------------------
// Connect local copies to outputs
// ------------------------------------------------------------------
assign RXSTATUS = iRXSTATUS;
assign UARTLCRH = iUARTLCRH;
assign UARTLCRM = iUARTLCRM;
assign UARTLCRL = iUARTLCRL;
assign UARTFBRD = iUARTFBRD;
assign UARTCR = iUARTCR;
assign UARTILPR = iUARTILPR;
assign LCRUpdate = iLCRUpdate;
assign ILPRUpdate= iILPRUpdate;
assign FBRDUpdate= iFBRDUpdate;
assign UARTIFLS = iUARTIFLS;
assign UARTDMACR = iUARTDMACR;
endmodule
// - ==================== End of UartRegBlock ====================
uartreceive.v
module uartreceive (
UARTCLK ,
nUARTRST,
UARTENSync,
SIRENSync,
RXESync,
Baud16,
WLEN,
STP2,
EPS,
PEN,
SPS,
RXFWrDoneSync,
Zerobaud,
RXFESync,
RXD,
RTIMSync,
FEIMSync,
PEIMSync,
BEIMSync,
UARTRTICSync,
UARTFEICSync,
UARTPEICSync,
UARTBEICSync,
RXFWr,
RXFIFOData,
DataStp,
RXBUSY,
RXEnable,
UartRXCntlState,
UARTRISerr,
UARTMISerr,
UARTEINTRfbp,
CharRxComp
);
input UARTCLK ; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input UARTENSync; // UART Enable
input SIRENSync; // SIR Enable
input RXESync; // RX Enable
input Baud16; // Bit Period Reference
input [1:0] WLEN; // Data bits per word
input STP2; // 2 stop bits
input EPS; // Even Parity Select
input PEN; // Parity enable
input SPS; // Stick Parity Select
input RXFWrDoneSync; // RX FIFO Write Done
input Zerobaud; // Baud Divisor set to 0
input RXFESync; // Receive FIFO Empty
input RXD; // Receive serial input
input RTIMSync; // RX Timeout interrupt Mask
input FEIMSync; // Framing Error interrupt Mask
input PEIMSync; // Parity Error interrupt Mask
input BEIMSync; // Break Error interrupt Mask
input UARTRTICSync; // For RX Timeout interrupt Clear
input UARTFEICSync; // For Framing Error interrupt Clear
input UARTPEICSync; // For Parity Error interrupt Clear
input UARTBEICSync; // For Break Error interrupt Clear
output RXFWr; // Receive FIFO Write (level)
output [10:0] RXFIFOData; // Received Data
output DataStp; // Receive line Idle
output RXBUSY; // Receiver Busy
output RXEnable; // Rx Enable
output [2:0] UartRXCntlState; // Rx state
output [2:0] UARTRISerr; // Raw interrupt status, error signals
output [2:0] UARTMISerr; // Masked Interrupt status, error signals
output UARTEINTRfbp; // Combined int for break, frame, parity
output CharRxComp; // Char Rx complete
// ------------------------------------------------------------------
//
// UartReceive
// ===========
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// The receive section instantiates three sub-modules - UartRXParShft,
// UartRXCntl and UartDataStp. The UartRXCntl block is the main control
// state machine. The UartRXParShft block contains the receive shift
// register and performs parity error checking and frame error checking
// on the received data bit stream.
// The UartdataStp block detects the condition when there is some data
// in the receive FIFO but there has been no activity on the receive
// line for a 32-bit period.
// When the RXD input line goes low, the receive state machine starts
// synchronising to the middle of the start bit. Thereafter, the RXD
// line is sampled at the middle of every bit period. The ShiftEn signal
// from the control state machine to the UartRXParShft block shifts data
// into a shift register in the UartRXParShft block. The SampleStopBit,
// SampleParity and ClearShiftReg signals indicate when the stop bit is
// to be sampled, when the Parity bit is to be sampled and when the
// Shift register is to be cleared to the UartRXParShft block.
// The contents of the shift register in the UartRXParShft block is made
// available as the FIFOData signal. The control state machine also puts
// out a ReloadWD signal whenever a start bit is detected or whenever
// the last stop bit is detected for the UartDataStp state machine to
// reload its internal watchdog counter. This counter is a 9 bit counter
// which counts down on every Baud16. The Zerobaud input signal is
// asserted if the illegal divisor value of 0 is written to the Bit
// rate divisor
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK ; // Main UART Clock
wire nUARTRST; // Muxed reset (from nUARTRST)
wire UARTENSync; // UART Enable
wire SIRENSync; // SIR Enable
wire RXESync; // RX Enable
wire Baud16; // Bit Period Reference
wire [1:0] WLEN; // Data bits per word
wire STP2; // 2 stop bits
wire EPS; // Even Parity Select
wire PEN; // Parity enable
wire RXFWrDoneSync; // RX FIFO Write Done
wire Zerobaud; // Baud Divisor set to 0
wire RXFESync; // Receive FIFO Empty
wire RXD; // Receive serial input
wire RTIMSync; // RX Timeout interrupt Mask
wire FEIMSync; // Framing Error interrupt Mask
wire PEIMSync; // Parity Error interrupt Mask
wire BEIMSync; // Break Error interrupt Mask
wire UARTRTICSync; // For RX Timeout interrupt Clear
wire UARTFEICSync; // For Framing Error interrupt Clear
wire UARTPEICSync; // For Parity Error interrupt Clear
wire UARTBEICSync; // For Break Error interrupt Clear
wire SPS; // Stick Parity Select
wire SampleParity;
wire ShiftEn;
wire ReloadWD;
wire ClearShiftReg;
wire DtPrZero;
wire RXDsampled;
wire UARTBERIS;
wire UARTPERIS;
wire UARTFERIS;
wire UARTBEMIS;
wire UARTPEMIS;
wire UARTFEMIS;
// ------------------------------------------------------------------
// Combine the 3 error related signals generated in this block
// ------------------------------------------------------------------
assign UARTRISerr = {UARTBERIS, UARTPERIS, UARTFERIS};
assign UARTMISerr = {UARTBEMIS, UARTPEMIS, UARTFEMIS};
// ------------------------------------------------------------------
// Combine the 3 error interrupts to form the combined error
// interrupt for frame, break and parity. The overrun error interrupt
// will be added to form the UARTEINTR signal.
// ------------------------------------------------------------------
assign UARTEINTRfbp = UARTBEMIS | UARTPEMIS | UARTFEMIS;
// The Receive control state machine
uartrxcntl uartrxcntl (
.UARTCLK (UARTCLK ),
.nUARTRST (nUARTRST ),
.Baud16 (Baud16 ),
.UARTENSync (UARTENSync ),
.SIRENSync (SIRENSync ),
.RXESync (RXESync ),
.RXD (RXD ),
.WLEN (WLEN ),
.STP2 (STP2 ),
.PEN (PEN ),
.Zerobaud (Zerobaud ),
.RXFWrDoneSync (RXFWrDoneSync ),
.DtPrZero (DtPrZero ),
.UARTFEICSync (UARTFEICSync ),
.UARTBEICSync (UARTBEICSync ),
.FEIMSync (FEIMSync ),
.BEIMSync (BEIMSync ),
.ShiftEn (ShiftEn ),
.SampleParity (SampleParity ),
.RXEnable (RXEnable ),
.UartRXCntlState(UartRXCntlState),
.RXDsampled (RXDsampled ),
.ClearShiftReg (ClearShiftReg ),
.RXFWr (RXFWr ),
.ReloadWD (ReloadWD ),
.FramingError (RXFIFOData[8] ),
.Break (RXFIFOData[10] ),
.RXBUSY (RXBUSY ),
.CharRxComp (CharRxComp ),
.UARTFERIS (UARTFERIS ),
.UARTBERIS (UARTBERIS ),
.UARTFEMIS (UARTFEMIS ),
.UARTBEMIS (UARTBEMIS )
);
// This block contains the receive shift register.
uartrxparshft uartrxparshft (
.UARTCLK (UARTCLK ),
.nUARTRST (nUARTRST ),
.RXDsampled (RXDsampled ),
.ShiftEn (ShiftEn ),
.SampleParity (SampleParity ),
.ClearShiftReg (ClearShiftReg ),
.SPS (SPS ),
.EPS (EPS ),
.PEN (PEN ),
.WLEN (WLEN ),
.PEIMSync (PEIMSync ),
.UARTPEICSync (UARTPEICSync ),
.RecdDATA (RXFIFOData[7:0]),
.DtPrZero (DtPrZero ),
.ParityError (RXFIFOData[9] ),
.UARTPERIS (UARTPERIS ),
.UARTPEMIS (UARTPEMIS )
);
// This state machine detects idle on the receive line
uartdatastp uartdatastp (
.UARTCLK (UARTCLK ),
.nUARTRST (nUARTRST ),
.Baud16 (Baud16 ),
.ReloadWD (ReloadWD ),
.RXFESync (RXFESync ),
.RTIMSync (RTIMSync ),
.UARTRTICSync (UARTRTICSync ),
.DataStp (DataStp )
);
endmodule
// - ==================== End of UartTest ====================
uartmodem.v
module uartmodem (
UARTCLK,
nUARTRST,
SIRENSync,
nDCDSyncUARTCLK,
nDSRSyncUARTCLK,
nCTSSyncUARTCLK,
nRISyncUARTCLK,
UARTDCDICSync,
UARTDSRICSync,
UARTCTSICSync,
UARTRIICSync,
DCDIMSync,
DSRIMSync,
CTSIMSync,
RIIMSync,
UARTMSINT,
UARTRISmod,
UARTMISmod
);
input UARTCLK; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input SIRENSync; // Inhibit MSINT if SIR enabled
input nDCDSyncUARTCLK; // Sync'ed DCD
input nDSRSyncUARTCLK; // Sync'ed DSR
input nCTSSyncUARTCLK; // Sync'ed CTS
input nRISyncUARTCLK; // Sync'ed RI
input UARTDCDICSync; // For UARTDCDINTR Clear
input UARTDSRICSync; // For UARTDSRINTR Clear
input UARTCTSICSync; // For UARTCTSINTR Clear
input UARTRIICSync; // For UARTRIINTR Clear
input DCDIMSync; // DCD Interrupt enable
input DSRIMSync; // DSR Interrupt enable
input CTSIMSync; // CTS Interrupt enable
input RIIMSync; // RI Interrupt enable
output UARTMSINT; // UART Modem Status interrupt
output [3:0] UARTRISmod; // Raw modem interrupt status
output [3:0] UARTMISmod; // Masked modem interrupt status
// ------------------------------------------------------------------
//
// UartModem
// =========
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block asserts the Modem Status Interrupt (UARTMSINT) when any
// change in the modem input lines nDCDSyncUARTCLK, nDSRSyncUARTCLK,
// nCTSSyncUARTCLK and nRISyncUARTCLK is detected.
// The interrupt is cleared when a 1'b1 is written to bit 1 of the
// UARTICR register.
// The UARTMSINTRClr signal is asserted for one UARTCLK period
// whenever a 1'b1 is written to bit 1 of the UARTICR register.
// Change in the modem lines is detected by xoring the signal with
// its delayed version. Once the interrupt is asserted, any further
// changes in the modem lines have no effect on the interrupt status.
// If an edge-detect and UARTMSINTRClr occur at the same time, the
// interrupt is de-asserted for one UARTCLK clock period and then
// asserted again. This helps in systems with edge-triggered
// interrupt controllers.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK; // Main UART Clock (Module Input)
wire nUARTRST; // Muxed reset (from nUARTRST) (Module Input)
wire UARTDCDICSync; // For UARTDCDINTR Clear (Module Input)
wire UARTDSRICSync; // For UARTDSRINTR Clear (Module Input)
wire UARTCTSICSync; // For UARTCTSINTR Clear (Module Input)
wire UARTRIICSync; // For UARTRIINTR Clear (Module Input)
wire DCDIMSync; // DCD Interrupt enable (Module Input)
wire DSRIMSync; // DSR Interrupt enable (Module Input)
wire CTSIMSync; // CTS Interrupt enable (Module Input)
wire RIIMSync; // RI Interrupt enable (Module Input)
wire SIRENSync; // Inhibit MSINT if SIR enabled (Module Input)
wire nDCDSyncUARTCLK; // Sync'ed DCD (Module Input)
wire nDSRSyncUARTCLK; // Sync'ed DSR (Module Input)
wire nCTSSyncUARTCLK; // Sync'ed CTS (Module Input)
wire nRISyncUARTCLK; // Sync'ed RI (Module Input)
wire DCDEdge;
// Indicates that an edge has been detected in the DCD Modem signal
wire DSREdge;
// Indicates that an edge has been detected in the DSR Modem signal
wire CTSEdge;
// Indicates that an edge has been detected in the CTS Modem signal
wire RIEdge;
// Indicates that an edge has been detected in the RI Modem signal
wire UARTDCDIClr;
// Clear signal for UARTDCDINTR interrupt
wire UARTDSRIClr;
// Clear signal for UARTDSRINTR interrupt
wire UARTCTSIClr;
// Clear signal for UARTCTSINTR interrupt
wire UARTRIIClr;
// Clear signal for UARTRIINTR interrupt
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg nDCDd1; // Delayed version of nDCDSyncUARTCLK
reg nDSRd1; // Delayed version of nDSRSyncUARTCLK
reg nCTSd1; // Delayed version of nCTSSyncUARTCLK
reg nRId1; // Delayed version of nRISyncUARTCLK
reg NextUARTDCDRIS; // D-input of raw iUARTDCDINTR
reg NextUARTDSRRIS; // D-input of raw iUARTDSRINTR
reg NextUARTCTSRIS; // D-input of raw iUARTCTSINTR
reg NextUARTRIRIS; // D-input of raw iUARTRIS
reg iUARTRIRIS; // Internal copy of RI raw status
reg iUARTDCDRIS; // Internal copy of DCD raw status
reg iUARTDSRRIS; // Internal copy of DSR raw status
reg iUARTCTSRIS; // Internal copy of CTS raw status
reg DSREdged1; // Delayed version of DSREdge
reg DCDEdged1; // Delayed version of DCDEdge
reg CTSEdged1; // Delayed version of CTSEdge
reg RIEdged1; // Delayed version of RIEdge
reg DelUARTDCDICSync; // Delayed version of UARTDCDICSync.Used to detect edge on UARTDCDICSync
reg DelUARTDSRICSync; // Delayed version of UARTDSRICSync.Used to detect edge on UARTDSRICSync
reg DelUARTCTSICSync; // Delayed version of UARTCTSICSync.Used to detect edge on UARTCTSICSync
reg DelUARTRIICSync; // Delayed version of UARTRIICSync. Used to detect edge on UARTRIICSync
reg iUARTDCDMIS; // Internal copy of DCD masked status
reg iUARTDSRMIS; // Internal copy of DSR masked status
reg iUARTCTSMIS; // Internal copy of CTS masked status
reg iUARTRIMIS; // Internal copy of RI masked status
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Detect an edge in any of the modem control lines
// ------------------------------------------------------------------
assign DCDEdge = nDCDd1 ^ nDCDSyncUARTCLK;
assign DSREdge = nDSRd1 ^ nDSRSyncUARTCLK;
assign CTSEdge = nCTSd1 ^ nCTSSyncUARTCLK;
assign RIEdge = nRId1 ^ nRISyncUARTCLK;
// ------------------------------------------------------------------
// The UARTDCDIC, UARTDSRIC, UARTCTSIC and UARTRIIC signals are one
// UARTCLK-wide pulses used to clear the UARTDCDINTR, UARTDSRINTR,
// UARTCTSINTR and the UARTRIINTR interrupts.
// ------------------------------------------------------------------
assign UARTDCDIClr = UARTDCDICSync & (! DelUARTDCDICSync);
assign UARTDSRIClr = UARTDSRICSync & (! DelUARTDSRICSync);
assign UARTCTSIClr = UARTCTSICSync & (! DelUARTCTSICSync);
assign UARTRIIClr = UARTRIICSync & (! DelUARTRIICSync);
// ------------------------------------------------------------------
// Clear the relevant interrupt on a write to that bit in the
// UARTICR register. If there is another edge detected at the same
// clock, then latch this information in the relevant Edged1 flip-flop
// and assert the interrupt after one UARTCLK clock so as to support
// edge-triggered interrupt controllers.
// ------------------------------------------------------------------
always @(UARTDCDIClr or DCDEdge or DCDEdged1 or SIRENSync or
iUARTDCDRIS)
begin : p_UARTDCDINTR
NextUARTDCDRIS = iUARTDCDRIS;
if ((DCDEdge == 1'b1) || (DCDEdged1 == 1'b1) && (SIRENSync == 1'b0))
NextUARTDCDRIS = 1'b1;
else if ((UARTDCDIClr == 1'b1) || (SIRENSync == 1'b1))
NextUARTDCDRIS = 1'b0;
end // p_UARTDCDINTR;
always @(UARTDSRIClr or DSREdge or DSREdged1 or SIRENSync or
iUARTDSRRIS)
begin : p_UARTDSRINTR
NextUARTDSRRIS = iUARTDSRRIS;
if ((DSREdge == 1'b1) || (DSREdged1 == 1'b1) && (SIRENSync == 1'b0))
NextUARTDSRRIS = 1'b1;
else if ((UARTDSRIClr == 1'b1) || (SIRENSync == 1'b1))
NextUARTDSRRIS = 1'b0;
end // p_UARTDSRINTR;
always @(UARTCTSIClr or CTSEdge or CTSEdged1 or SIRENSync or
iUARTCTSRIS)
begin : p_UARTCTSINTR
NextUARTCTSRIS = iUARTCTSRIS;
if ((CTSEdge == 1'b1) || (CTSEdged1 == 1'b1) && (SIRENSync == 1'b0))
NextUARTCTSRIS = 1'b1;
else if ((UARTCTSIClr == 1'b1) || (SIRENSync == 1'b1))
NextUARTCTSRIS = 1'b0;
end // p_UARTCTSINTR;
always @(UARTRIIClr or RIEdge or RIEdged1 or SIRENSync or iUARTRIRIS)
begin : p_UARTRIINTR
NextUARTRIRIS = iUARTRIRIS;
if ((RIEdge == 1'b1) || (RIEdged1 == 1'b1) && (SIRENSync == 1'b0))
NextUARTRIRIS = 1'b1;
else if ((UARTRIIClr == 1'b1) || (SIRENSync == 1'b1))
NextUARTRIRIS = 1'b0;
end // p_UARTRIINTR;
assign UARTRISmod[3] = iUARTDSRRIS;
assign UARTRISmod[2] = iUARTDCDRIS;
assign UARTRISmod[1] = iUARTCTSRIS;
assign UARTRISmod[0] = iUARTRIRIS;
assign UARTMISmod[3] = iUARTDSRMIS;
assign UARTMISmod[2] = iUARTDCDMIS;
assign UARTMISmod[1] = iUARTCTSMIS;
assign UARTMISmod[0] = iUARTRIMIS;
// ------------------------------------------------------------------
// The combined Modem interrupt UARTMSINT is asserted when any if
// the individual modem interrupts are asserted.
// ------------------------------------------------------------------
assign UARTMSINT = iUARTDCDMIS | iUARTDSRMIS | iUARTCTSMIS | iUARTRIMIS;
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin
if (nUARTRST == 1'b0)
begin
iUARTRIMIS <= 1'b0;
iUARTDCDMIS <= 1'b0;
iUARTDSRMIS <= 1'b0;
iUARTCTSMIS <= 1'b0;
end
else
begin
iUARTRIMIS <= NextUARTRIRIS & RIIMSync;
iUARTDCDMIS <= NextUARTDCDRIS & DCDIMSync;
iUARTDSRMIS <= NextUARTDSRRIS & DSRIMSync;
iUARTCTSMIS <= NextUARTCTSRIS & CTSIMSync;
end
end
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_MSIntReg
if (nUARTRST == 1'b0)
begin
nDCDd1 <= 1'b0;
nDSRd1 <= 1'b0;
nCTSd1 <= 1'b0;
nRId1 <= 1'b0;
iUARTRIRIS <= 1'b0;
iUARTDCDRIS <= 1'b0;
iUARTDSRRIS <= 1'b0;
iUARTCTSRIS <= 1'b0;
DSREdged1 <= 1'b0;
DCDEdged1 <= 1'b0;
CTSEdged1 <= 1'b0;
RIEdged1 <= 1'b0;
DelUARTRIICSync <= 1'b0;
DelUARTDCDICSync <= 1'b0;
DelUARTDSRICSync <= 1'b0;
DelUARTCTSICSync <= 1'b0;
end
else
begin
nDCDd1 <= nDCDSyncUARTCLK;
nDSRd1 <= nDSRSyncUARTCLK;
nCTSd1 <= nCTSSyncUARTCLK;
nRId1 <= nRISyncUARTCLK;
iUARTRIRIS <= NextUARTRIRIS;
iUARTDCDRIS <= NextUARTDCDRIS;
iUARTDSRRIS <= NextUARTDSRRIS;
iUARTCTSRIS <= NextUARTCTSRIS;
DSREdged1 <= DSREdge;
DCDEdged1 <= DCDEdge;
CTSEdged1 <= CTSEdge;
RIEdged1 <= RIEdge;
DelUARTRIICSync <= UARTRIICSync;
DelUARTDCDICSync <= UARTDCDICSync;
DelUARTDSRICSync <= UARTDSRICSync;
DelUARTCTSICSync <= UARTCTSICSync;
end
end // p_MSIntReg;
endmodule
// - ==================== End of UartModem ====================
uartirda.v
module uartirda(
UARTCLK,
nUARTRST,
Baud16,
IrLPBaud16,
SIRLPSync,
SIRENSync,
StopBaudCnt,
TXBUSY,
RXBUSY,
TXD,
SIRINSync,
UARTRXDSync,
UARTTXDint,
RXD,
nSIROUTint
);
input UARTCLK; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input Baud16; // Bit Period reference
input IrLPBaud16; // Low Power pulse width ref
input SIRLPSync; // Low power mode enable
input SIRENSync; // SIR Enable
input StopBaudCnt; // Stop baud counter
input TXBUSY; // UART Transmitter busy
input RXBUSY; // UART Receiver busy
input TXD; // From UART Transmitter
input SIRINSync; // Sync'ed SIR serial input
input UARTRXDSync; // Synced serial receive input
output UARTTXDint; // Made inactive if SIR enabled
output RXD; // Decoded signal to UART Receiver
output nSIROUTint; // SIR Encoded transmit bit stream
// ------------------------------------------------------------------
//
// UartIrDA
// ========
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block contains the encoder and decoder required to encode
// and decode the bit stream into a stream compatible with IrDA
// standards. A 1'b0 is transmitted as a pulse while a 1'b1 is
// encoded as no pulse. In the normal mode, the pulse is 3 Baud16
// periods wide. In the low-power mode, the pulse is 3 IrLPBaud16
// periods wide. Glitches on the SIRIN line are rejected by oversampling
// both in Normal and Low-Power modes, start bits which are less than
// one period of IrLPBaud16 are rejected by the glitch rejection logic.
// IrDA is a half-duplex protocol by specification. Although this
// implementation prevents simultaneous transmission and reception in
// normal mode, software has to ensure that no transmit data is present
// in the transmit FIFO when IrDA reception is in progress. This is
// because the UART receive state machine goes to the idle state at the
// end of every byte of data and there is no way of being sure that
// there is no further data to be received.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// 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 IrLPBaud16; // Low Power pulse width ref (Module Input)
wire SIRLPSync; // Low power mode enable (Module Input)
wire SIRENSync; // SIR Enable (Module Input)
wire TXBUSY; // UART Transmitter busy (Module Input)
wire RXBUSY; // UART Receiver busy (Module Input)
wire TXD; // From UART Transmitter (Module Input)
wire SIRINSync; // Sync'ed SIR serial input (Module Input)
wire UARTRXDSync; // Synced serial receive input (Module Input)
wire StopBaudCnt; // Stop baud counter (Module Input)
wire TCStartEn;
// Used to generate the TCStart signal
wire SIRINStag2Final;
// Combined value of SIRINStag2
wire IrRXBUSY;
wire IrTXBUSY;
// Used to decide full or half duplex mode
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg UARTTXDint;
// Made inactive if SIR enabled (Module Output)
reg RXD;
// Decoded signal to UART Receiver (Module Output)
reg nSIROUTint;
// SIR Encoded transmit bit stream (Module Output)
reg NextSIROUT;
// D-input for SIROUT
reg NmSirout;
// normal mode output
reg NextNmSirout;
// D-input for normal mode output
reg PdSirout;
// low power mode output
reg NextPdSirout;
// D-input for low power mode output
reg NextUARTTXD;
// D-input for UARTTXDint
reg NextRXD;
// D-input for RXD
reg PdTCload;
// Enable reg for the counter PdTcount
reg NextPdTCload;
// D-input for the PdTcount reg
reg TCStart;
// Enable reg for the counter Tcount
reg NextTCStart;
// D-input for the Tcount signal
reg Flag;
// Used to prevent more than one pulse in one bit time in low power mode
reg NextFlag;
// D-input for the Flag signal
reg Rload;
// enable signal for the counter Rcount
reg NextRload;
// D-input for the Rload signal
reg SIRINStag1;
// 1st sample of SIRINSync
reg NextSIRINStag1;
// D-input for SIRINStag1 signal;
reg SIRINStag1a;
// 1st A sample of SIRINSync
reg NextSIRINStag1a;
// D-input for SIRINStag1a signal;
reg SIRINStag2;
// 2nd sample of SIRINSync
reg NextSIRINStag2;
// D-input for SIRINStag2 signal;
reg SIRINStag2a;
// 2ed A sample of SIRINSync
reg NextSIRINStag2a;
// D-input for SIRINStag2a signal;
reg [3:0] Tcount;
// Used in transmitter module to determine one bit period
reg [3:0] Rcount;
// Used in the receiver module to determine one bit period
reg [3:0] NextTcount;
// D-input for the counter Tcount
reg [3:0] NextRcount;
// D-input for the counter Rcount
reg [1:0] PdTcount;
// Used in low power mode to determine pulse width
reg [1:0] NextPdTcount;
// D-input for the counter PdTcount
reg SIRENSyncEoc;
// SIR enable signal for end of Character
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Output synchronising with UARTCLK
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin : p_SyncOut
if (nUARTRST == 1'b0)
begin
UARTTXDint <= 1'b1;
nSIROUTint <= 1'b0;
RXD <= 1'b1;
end
else
begin
UARTTXDint <= NextUARTTXD;
nSIROUTint <= NextSIROUT;
RXD <= NextRXD;
end
end // p_SyncOut;
// why delay the enable signal one clock to use?
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_SIRENSyncEoc
if (nUARTRST == 1'b0)
SIRENSyncEoc <= 1'b0;
else if (StopBaudCnt == 1'b1)
SIRENSyncEoc <= SIRENSync;
end // p_SIRENSyncEoc;
// ------------------------------------------------------------------
// Output module // combining normal and powerdown modes
// ------------------------------------------------------------------
always @ (SIRENSyncEoc or SIRLPSync or PdSirout or TXD or NmSirout)
begin : p_Out
if (SIRENSyncEoc == 1'b0)
begin
NextUARTTXD = TXD;
NextSIROUT = 1'b0;
end
else
begin
NextUARTTXD = 1'b1;
NextSIROUT = (((SIRLPSync) & (NmSirout)) | ((SIRLPSync) &
(PdSirout)));
end
end // p_Out;
assign TCStartEn = ( !((Tcount == 4'b1111) && (TXD == 1'b1)));
// ------------------------------------------------------------------
// This always @ primarily implements the transmitter counter. It is a
// 4-bit counter enabled by the Baud16 and TCStart signals. When a low
// level is detected on the TXD line, the counter is loaded with 15 and
// the TCStart bit is set. As long as this bit is set, the counter
// decrements by 1 on sampling a Baud16 pulse. At the end of the bit
// period (counter == 15), if the TXD line is sampled low, the TCStart
// bit is maintained high. The counter decrements by 1 and the whole
// always @ repeats for the next bit. If the TXD line is sampled high,
// the TCStart bit is cleared. To support half duplex mode operation,
// the TCStart bit and the counter are reset when the IrRXBUSY signal
// becomes active.
// ------------------------------------------------------------------
always @(*)
begin : p_TransCountLoad
NextTcount = Tcount;
NextTCStart = TCStart;
if (SIRENSyncEoc == 1'b0)
begin
NextTcount = 4'b0000;
NextTCStart = 1'b0;
end
else if (IrRXBUSY == 1'b1)
begin
NextTcount = 4'b0000;
NextTCStart = 1'b0;
end
else if ((TXD == 1'b0) && (TCStart == 1'b0))
begin
NextTcount = 4'b1111;
NextTCStart = 1'b1;
end
else if ((TCStart == 1'b1) && (Baud16 == 1'b1))
begin
NextTcount = ((Tcount) - 1'b1);
NextTCStart = TCStartEn;
end
end // p_TransCountLoad;
// ------------------------------------------------------------------
// Set the transmitter output high for 3 Baud16 periods in normal mode
// ------------------------------------------------------------------
// the TCStartEn decide to output 3/16 pulse or not.
// if the value of this signal is 1(input of TXD is 0), the TCount will continue counting, otherwise the TCount will stop counting, and don't output 3/16 pulse.
// see the module above
always @ (Tcount or SIRENSyncEoc or SIRLPSync or NmSirout)
begin : p_TransmitterOut1
if (SIRENSyncEoc == 1'b0)
NextNmSirout = 1'b0;
else if ((SIRLPSync == 1'b0) &&
((Tcount == 4'b1010) || (Tcount == 4'b1001)
|| (Tcount == 4'b1000)))
NextNmSirout = 1'b1;
else if (SIRLPSync == 1'b0)
NextNmSirout = 1'b0;
else
NextNmSirout = NmSirout;
end // p_TransmitterOut1;
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_Transmitter_clk
if (nUARTRST == 1'b0)
begin
Tcount <= 4'b0000;
NmSirout <= 1'b0;
TCStart <= 1'b0;
end
else
begin
NmSirout <= NextNmSirout;
TCStart <= NextTCStart;
Tcount <= NextTcount;
end
end // p_Transmitter_clk;
// ------------------------------------------------------------------
// This always @ implements the low power section of the transmitter.
// In the low power mode, bit period timing commences when the Tcount
// counter reaches a value of 10. At this count, the PdTCload is set
// high. When the next IrLPBaud16 pulse is sampled, the PdTcount counter
// is loaded with 3. The transmitter output is driven high and
// maintained for 3 IrLPBaud16 periods. The PdTCload bit is cleared
// along with the transmitter output. Simultaneously, a flag bit is set
// to prevent reassertion of the transmitter output within the same bit
// period, in cases where the Baud16 frequency is much lower than the
// IrLPBaud16 frequency.
// ------------------------------------------------------------------
always @ ( SIRENSyncEoc or Tcount or SIRLPSync or PdTcount or
IrLPBaud16 or Flag or PdSirout or PdTCload)
begin : p_LowPTransCountLoad
NextFlag = Flag;
NextPdSirout = PdSirout;
NextPdTcount = PdTcount;
NextPdTCload = PdTCload;
if (SIRENSyncEoc == 1'b0)
begin
NextPdTcount = 2'b00;
NextPdSirout = 1'b0;
NextFlag = 1'b0;
NextPdTCload = 1'b0;
end
else if ((Tcount == 4'b1010) && (SIRLPSync == 1'b1) &&
(PdTCload == 1'b0) && (Flag == 1'b0))
NextPdTCload = 1'b1;
else if ((PdTCload == 1'b1) && (IrLPBaud16 == 1'b1)
&& (PdSirout == 1'b0))
begin
NextPdTcount = 2'b11;
NextPdSirout = 1'b1;
end
else if ((PdTCload == 1'b1) && (IrLPBaud16 == 1'b1))
begin
if (PdTcount == 2'b01)
begin
NextPdSirout = 1'b0;
NextFlag = 1'b1;
NextPdTCload = 1'b0;
end
else
NextPdTcount = ((PdTcount) - 1'b1);
end
else if (Tcount == 4'b0001)
NextFlag = 1'b0;
end // p_LowPTransCountLoad;
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_Transmitter_2mclk
if (nUARTRST == 1'b0)
begin
PdTcount <= 2'b00;
PdSirout <= 1'b0;
PdTCload <= 1'b0;
Flag <= 1'b0;
end
else
begin
PdSirout <= NextPdSirout;
PdTcount <= NextPdTcount;
PdTCload <= NextPdTCload;
Flag <= NextFlag;
end
end // p_Transmitter_2mclk;
// ------------------------------------------------------------------
// This always @ implements the glitch rejection logic in the receiver
// section of the IrDA.
// Glitch rejection is performed by sampling the SIRINSync line on the
// IrLPBaud16 clock using two pipeline stages. Glitches of width less
// than one period of IrLPBaud16 are rejected using this method.
// Signals of width more than one period of IrLPBaud16 but less than two
// periods of IrLPBaud16 may or may not be taken as a glitch. Signals of
// width more than two IrLPBaud16 periods are taken as valid signals.
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_deglitcher_clk
if (nUARTRST == 1'b0)
begin
SIRINStag1 <= 1'b1;
SIRINStag2 <= 1'b1;
SIRINStag1a <= 1'b1;
SIRINStag2a <= 1'b1;
end
else
begin
SIRINStag1 <= NextSIRINStag1;
SIRINStag2 <= NextSIRINStag2;
SIRINStag1a <= NextSIRINStag1a;
SIRINStag2a <= NextSIRINStag2a;
end
end // p_deglitcher_clk;
// ------------------------------------------------------------------
// The following detects for a low on SIRINSync of at least 1IrLPBaud16 cycle
// with the registers being updated based on IrLPBaud16 being equal to 1.
// ------------------------------------------------------------------
always @(SIRINSync or SIRINStag1 or IrLPBaud16)
begin : p_deglitcher1
if(IrLPBaud16 == 1'b1)
NextSIRINStag1 = SIRINSync;
else
NextSIRINStag1 = SIRINStag1;
end // p_deglitcher1;
always @(SIRINSync or SIRINStag1 or SIRINStag2 or IrLPBaud16)
begin : p_deglitcher2
if ((IrLPBaud16 == 1'b1) && (SIRINStag1 == SIRINSync))
NextSIRINStag2 = SIRINStag1;
else
NextSIRINStag2 = SIRINStag2;
end // p_deglitcher2;
// ------------------------------------------------------------------
// The following detects for a low on SIRINSync of at least 1IrLPBaud16 cycle
// with the registers being updated based on IrLPBaud16 being equal to 0.
// ------------------------------------------------------------------
always @(SIRINSync or SIRINStag1a or IrLPBaud16)
begin : p_deglitcher1a
if(IrLPBaud16 == 1'b0)
NextSIRINStag1a = SIRINSync;
else
NextSIRINStag1a = SIRINStag1a;
end // p_deglitcher1a;
always @(SIRINSync or SIRINStag1a or SIRINStag2a or IrLPBaud16)
begin : p_deglitcher2a
if ((IrLPBaud16 == 1'b0) && (SIRINStag1a == SIRINSync))
NextSIRINStag2a = SIRINStag1a;
else
NextSIRINStag2a = SIRINStag2a;
end // p_deglitcher2a;
// ------------------------------------------------------------------
// With the above two detections, should catch all SIRINSync pulses which are
// at least 1 IrLPBaud16 pulse wide.
// ------------------------------------------------------------------
assign SIRINStag2Final = ((SIRINStag2 == 1'b0) || (SIRINStag2a == 1'b0))
? 1'b0 : 1'b1;
// ------------------------------------------------------------------
// This always @ converts the valid input bit stream into a stream
// compatible with IrDA standards. The default value of SIRINStag2Final is 1.
// When a low is detected on this line, a 4 bit counter Rcount is
// loaded with a value of 12 and the RXD line is pulled low on the next
// Baud16 clock. The RXD line is held low until the counter rolls over
// from 1 to 0. To support half duplex mode of operation, the counters
// and control signals are reset on sampling the IrTXBUSY line high.
// The RXD line is also restored to its default value of high.
// ------------------------------------------------------------------
always @ ( SIRENSyncEoc or SIRINStag2Final or Baud16 or Rcount or Rload or
RXD or IrTXBUSY or UARTRXDSync)
begin : p_Receiver
NextRXD = RXD;
NextRload = Rload;
NextRcount = Rcount;
if (SIRENSyncEoc == 1'b0)
begin
NextRXD = UARTRXDSync;
NextRload = 1'b0;
NextRcount = 4'b0000;
end
else if (IrTXBUSY == 1'b1)
begin
NextRXD = 1'b1;
NextRload = 1'b0;
NextRcount = 4'b0000;
end
else if ((SIRINStag2Final == 1'b0) && (Rload == 1'b0))
NextRload = 1'b1;
else if ((Baud16 == 1'b1) && (Rload == 1'b1))
begin
if( Rcount == 4'b0000)
begin
NextRcount = 4'b1100;
NextRXD = 1'b0;
NextRload = Rload;
end
else if (Rcount == 4'b0001)
begin
NextRcount = 4'b0000;
NextRload = 1'b0;
NextRXD = 1'b1;
end
else
NextRcount = ((Rcount) - 1'b1);
end
end // p_Receiver;
assign IrRXBUSY = RXBUSY;
assign IrTXBUSY = TXBUSY;
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_Receiver_clk
if (nUARTRST == 1'b0)
begin
Rload <= 1'b0;
Rcount <= 4'b0000;
end
else
begin
Rload <= NextRload;
Rcount <= NextRcount;
end
end // p_Receiver_clk;
endmodule
// - ==================== End of UartIrDA ====================
uartinterrupt.v
module uartinterrupt
(
DataStp,
UARTMSINT,
UARTEINTRfbp,
UARTTXMIS,
UARTRXMIS,
UARTOEMIS,
UARTRTIC,
UARTDSRIC,
UARTDCDIC,
UARTCTSIC,
UARTRIIC,
UARTOEIC,
UARTBEIC,
UARTPEIC,
UARTFEIC,
UARTINTR
);
input DataStp; // for UARTRTINTR
input UARTMSINT; // for UARTMSINTR
input UARTEINTRfbp; // Combined int for break, frame,parity
input UARTTXMIS; // Transmit Interrupt
input UARTRXMIS; // Receive Interrupt
input UARTOEMIS; // Overrun error interrupt
input UARTRTIC; // RTINTR clear
input UARTDSRIC; // DSR MSINTR clear
input UARTDCDIC; // DCD MSINTR clear
input UARTCTSIC; // CTS MSINTR clear
input UARTRIIC; // RI MSINTR clear
input UARTOEIC; // OEINTR clear
input UARTBEIC; // BEINTR clear
input UARTPEIC; // PEINTR clear
input UARTFEIC; // FEINTR clear
output UARTINTR; // Combined interrupt
// ------------------------------------------------------------------
//
// UartInterrupt
// =============
//
// ------------------------------------------------------------------
//
// Overview
// ========
// This block contains the asynchronous interrupt logic. The
// interrupts from the UARTCLK domain are ANDed with the relevant
// interrupt clear signal and taken as outputs. The interrupts are
// generated asynchronously but cleared synchronously with PCLK.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire Declaration
// ------------------------------------------------------------------
wire MSINTRCLR; // Combined Modem interrupt clear wire
wire EINTRCLR; // Combined Error interrupt clear wire
wire ERRINTR; // Combined Er
wire iRTINTR; // Internal version of RTINTR
wire iMSINTR; // Internal version of MSINTR
wire iEINTR; // Internal version of EINTR
// ------------------------------------------------------------------
// Generate a combined modem interrupt clear by ORing together the
// individual modem interrupt clear signals.
// ------------------------------------------------------------------
assign MSINTRCLR = UARTDSRIC | UARTDCDIC | UARTCTSIC | UARTRIIC;
// ------------------------------------------------------------------
// Generate a combined error interrupt clear by ORing together the
// individual error interrupt clear signals.
// ------------------------------------------------------------------
assign EINTRCLR = UARTOEIC | UARTBEIC | UARTPEIC | UARTFEIC;
// ------------------------------------------------------------------
// OR together the break, frame and parity interrupt with the Overrun
// interrupt to generate one combined error interrupt.
// ------------------------------------------------------------------
assign ERRINTR = UARTEINTRfbp | UARTOEMIS;
// ------------------------------------------------------------------
// When the relevant interrupt clear signal is asserted, the
// asynchronous interrupt is cleared.
// ------------------------------------------------------------------
assign iRTINTR = DataStp & (!UARTRTIC);
assign iMSINTR = UARTMSINT & (!MSINTRCLR);
assign iEINTR = ERRINTR & (!EINTRCLR);
// ------------------------------------------------------------------
// Combine all interrupts to generate UARTINTR
// ------------------------------------------------------------------
assign UARTINTR = iRTINTR | iMSINTR | iEINTR | UARTTXMIS | UARTRXMIS;
endmodule //
// - ==================== End of UartInterrupt ====================
uartdma.v
module uartdma (
PCLK,
PRESETn,
UARTEN,
TXDMAE,
RXDMAE,
DMAONERR,
TXE,
RXE,
FEN,
TXIntLevel,
RXIntLevel,
TXFLTE15Full,
RXFGTE1Full,
UARTTXDMACLRSync,
UARTRXDMACLRSync,
UARTEINTR,
TXDMASREQ,
TXDMABREQ,
RXDMASREQ,
RXDMABREQ
);
input PCLK; // APB Clock
input PRESETn; // APB Bus Reset
input UARTEN; // Uart Enable
input TXDMAE; // Transmit DMA Enable
input RXDMAE; // Receive DMA Enable
input DMAONERR; // DMA on Error signal
input TXE; // Transmit Enable
input RXE; // Receive Enable
input FEN; // Fifo enable bit
input TXIntLevel; // Transmit burst length
input RXIntLevel; // Receive burst length
input TXFLTE15Full; // TX FIFO has 1 or more spaces
input RXFGTE1Full; // RX FIFO contains data
input UARTTXDMACLRSync; // DMA clear signal
input UARTRXDMACLRSync; // DMA clear signal
input UARTEINTR; // Raw Uart Error Interrupt
output TXDMASREQ; // Transmit single request
output TXDMABREQ; // Transmit burst request
output RXDMASREQ; // Receive single request
output RXDMABREQ; // Receive burst request
// ------------------------------------------------------------------
//
// UartDMA
// =======
//
// ------------------------------------------------------------------
//
// Overview
// ========
// This block contains the logic for the DMA interface. It generates the
// 4 DMA request signals, UARTTXDMASREQ, UARTTXDMABREQ, UARTRXDMASREQ
// and UARTRXDMABREQ depending on the amount of data in the FIFO's.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declarations
// ------------------------------------------------------------------
wire PCLK; // APB Clock (Module Input)
wire PRESETn; // Muxed Reset (from BPRESETn) (Module Input)
wire UARTEN; // Uart Enable (Module Input)
wire TXDMAE; // Transmit DMA Enable (Module Input)
wire RXDMAE; // Receive DMA Enable (Module Input)
wire DMAONERR; // DMA on Error signal (Module Input)
wire TXFLTE15Full; // TX FIFO has 1 or more spaces (Module Input)
wire RXFGTE1Full; // RX FIFO contains data (Module Input)
wire UARTTXDMACLRSync; // DMA clear signal (Module Input)
wire UARTRXDMACLRSync; // DMA clear signal (Module Input)
wire TXIntLevel; // Transmit burst length (Module Input)
wire RXIntLevel; // Receive burst length (Module Input)
wire UARTEINTR; // Raw Uart Error Interrupt (Module Input)
wire TXE; // Transmit Enable (Module Input)
wire RXE; // Receive Enable (Module Input)
wire FEN; // Fifo enable bit (Module Input)
wire DMATXEn;
// DMA Transmit enable
wire DMARXEn;
// DMA Receive enable
// ------------------------------------------------------------------
// Register declarations
// ------------------------------------------------------------------
reg iTXDMASREQ;
// Transmit single request
reg iTXDMABREQ;
// Transmit burst request
reg iRXDMASREQ;
// Receive single request
reg iRXDMABREQ;
// Receive burst request
reg nextTXDMASREQ;
// D-input of iTXDMASREQ
reg nextTXDMABREQ;
// D-input of iTXDMABREQ
reg nextRXDMASREQ;
// D-input of iRXDMASREQ
reg nextRXDMABREQ;
// D-input of iRXDMABREQ
// ------------------------------------------------------------------
// Main VERILOG code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Connect local copies of signals to ports
// ------------------------------------------------------------------
assign TXDMABREQ = iTXDMABREQ;
assign RXDMABREQ = iRXDMABREQ;
assign TXDMASREQ = iTXDMASREQ;
assign RXDMASREQ = iRXDMASREQ;
// ------------------------------------------------------------------
// Sequential process for registers/flip-flops in this block
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn)//novas -21013
begin : p_Seq
if (PRESETn == 1'b0)
begin
iTXDMASREQ <= 1'b0;
iTXDMABREQ <= 1'b0;
iRXDMASREQ <= 1'b0;
iRXDMABREQ <= 1'b0;
end
else
begin
iTXDMASREQ <= nextTXDMASREQ;
iTXDMABREQ <= nextTXDMABREQ;
iRXDMASREQ <= nextRXDMASREQ;
iRXDMABREQ <= nextRXDMABREQ;
end
end // p_Seq
// ------------------------------------------------------------------
// The DMATXEn is asserted when the UART is enabled and the Transmit
// enable bit is set, and the Transmit DMA bit is set in the
// UARTDMACR register. This can also be asserted when the FIFOs need to be
// tested with DMA.
// ------------------------------------------------------------------
assign DMATXEn = ((UARTEN == 1'b1) && (TXE == 1'b1) && (TXDMAE == 1'b1)) ? 1'b1 : 1'b0;
// ------------------------------------------------------------------
// The transmit single request is set when there is atleast one space
// in the transmit FIFO. It is cleared when either there is a
// UARTTXDMACLRSync signal or when the DMATXEn is not asserted.
// ------------------------------------------------------------------
always @(DMATXEn or UARTTXDMACLRSync or TXFLTE15Full or iTXDMASREQ)
begin : p_TXDMASREQ
if ((DMATXEn == 1'b0) || (UARTTXDMACLRSync == 1'b1))
nextTXDMASREQ = 1'b0;
else if(TXFLTE15Full == 1'b1)
nextTXDMASREQ = 1'b1;
else
nextTXDMASREQ = iTXDMASREQ;
end // p_TXDMASREQ
// ------------------------------------------------------------------
// The transmit burst request is set when there are more spaces than
// the watermark level in the transmit FIFO. It is cleared when
// either there is a UARTTXDMACLRSync signal or when the DMATXEn is not
// asserted.
// ------------------------------------------------------------------
always @(DMATXEn or UARTTXDMACLRSync or FEN or TXIntLevel or iTXDMABREQ)
begin : p_TXDMABREQ
if ((DMATXEn == 1'b0) || (UARTTXDMACLRSync == 1'b1) || (FEN == 1'b0))
nextTXDMABREQ = 1'b0;
else if(TXIntLevel == 1'b1)
nextTXDMABREQ = 1'b1;
else
nextTXDMABREQ = iTXDMABREQ;
end // p_TXDMABREQ
// ------------------------------------------------------------------
// The DMARXEn is asserted when the UART is enabled and the Receive
// enable bit is set, and the Receive DMA bit is set in the
// UARTDMACR register.
// ------------------------------------------------------------------
assign DMARXEn = ((UARTEN == 1'b1) && (RXE == 1'b1) && (RXDMAE == 1'b1)) ? 1'b1 : 1'b0;
// ------------------------------------------------------------------
// The receive single request is set when there is atleast one character
// in the receive FIFO. It is cleared when either there is a UARTRXDMACL
// signal or when the DMARXEn is not asserted.
// ------------------------------------------------------------------
always @(DMARXEn or UARTRXDMACLRSync or DMAONERR or UARTEINTR or RXFGTE1Full
or iRXDMASREQ)
begin : p_RXDMASREQ
if ((DMARXEn == 1'b0) || (UARTRXDMACLRSync == 1'b1) ||
((DMAONERR == 1'b1) && (UARTEINTR == 1'b1)))
nextRXDMASREQ = 1'b0;
else if(RXFGTE1Full == 1'b1)
nextRXDMASREQ = 1'b1;
else
nextRXDMASREQ = iRXDMASREQ;
end // p_RXDMASREQ;
// ------------------------------------------------------------------
// The receive burst request is set when there are more characters than
// the watermark level in the receive FIFO. It is cleared when
// either:
// - there is a UARTRXDMACLRSync signal
// - the DMARXEn is not asserted or
// - the DMAONERR bit is set and the error interrupt line is asserted.
// ------------------------------------------------------------------
always @(DMARXEn or UARTRXDMACLRSync or RXIntLevel or DMAONERR or UARTEINTR or
FEN or iRXDMABREQ)
begin : p_RXDMABREQ
if ((DMARXEn == 1'b0) || (UARTRXDMACLRSync == 1'b1) ||
((DMAONERR == 1'b1) && (UARTEINTR == 1'b1)) || (FEN == 1'b0))
nextRXDMABREQ = 1'b0;
else if(RXIntLevel == 1'b1)
nextRXDMABREQ = 1'b1;
else
nextRXDMABREQ = iRXDMABREQ;
end // p_RXDMABREQ;
endmodule
// - ==================== End of UartDMA ====================
uartdatastp.v
module uartdatastp (
UARTCLK,
nUARTRST,
Baud16,
ReloadWD,
RXFESync,
RTIMSync,
UARTRTICSync,
DataStp
);
input UARTCLK; // Main UART Clock
input nUARTRST; // Muxed reset (from nUARTRST)
input Baud16; // Stream of UARTCLK-wide pulses
input ReloadWD; // Control input from Receiver
input RXFESync; // RX FIFO Empty
input RTIMSync; // RX Timeout Intr. Mask
input UARTRTICSync; // RX Timeout Intr. Clear
output DataStp; // Receive Idle detected
// ------------------------------------------------------------------
//
// UartDataStp
// ===========
//
// ------------------------------------------------------------------
//
// Overview
// ========
// This block detects the RX line going idle. If the Receive line goes
// to HIGH state for more than a 32-bit period and if the Receive FIFO
// is not empty, the receive line is said to have gone idle. This is
// signalled by the block output, DataStp. Once set, the DataStp signal
// goes low only after the Receive FIFO is empty or the RX line goes
// active again.
// To time the 32-bit period, the watchdog counter, that counts down
// with every Baud16 pulse, is initially loaded with a value of
// (32 * 16) -1 == 511. This uses the fact that one bit period is equal
// to 16 times the period of the Baud16 signal.
// ------------------------------------------------------------------
`define ST_ARMED 1'b0
// Idle state
`define ST_TRIGGER 1'b1
// Run state
// ------------------------------------------------------------------
// Encoding style: Gray
// ------------------------------------------------------------------
reg UartDataStpState;
reg UartDataStpNextState;
reg NextDataStp;
reg delUARTRTICSync;
reg DataStp;
// Registers
reg [8:0] WDCount;
reg [8:0] NextWDCount;
// Comparators
wire WDCmp;
// Aliases
wire ReloadCounter;
wire UARTRTIClr;
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Expansion of aliases...
// ------------------------------------------------------------------
assign ReloadCounter = ReloadWD | RXFESync | (!(RTIMSync));
// ------------------------------------------------------------------
// Expansion of comparators...
// ------------------------------------------------------------------
assign WDCmp = (WDCount[8:0] == 9'b000000000) ? 1'b1 : 1'b0;
// ------------------------------------------------------------------
// State transition process
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)//novas -21013
begin : seq
// Set the WDCount to its maximum value of all ones on Reset.
if (nUARTRST == 1'b0)
begin
UartDataStpState <= 1'b0;
DataStp <= 1'b0;
delUARTRTICSync <= 1'b0;
end
else
begin
UartDataStpState <= UartDataStpNextState;
DataStp <= NextDataStp;
delUARTRTICSync <= UARTRTICSync;
end
end // seq;
// ------------------------------------------------------------------
// Receive timeout interrupt clear signal
// signal to clear the interrupt
// ------------------------------------------------------------------
assign UARTRTIClr = (UARTRTICSync) & !(delUARTRTICSync);
// ------------------------------------------------------------------
// Output and next state logic generation
// ------------------------------------------------------------------
always @(*)
begin : combo
// Default assignments
UartDataStpNextState = UartDataStpState;
NextDataStp = 1'b0;
NextWDCount = WDCount;
case (UartDataStpState)
`ST_ARMED :
// This is the reset state of this machine. The DataStp signal is
// not asserted and the WDCount counter counts down on every
// Baud16 pulse.
// Reload the watchdog counter whenever there is activity on the
// Receive line or when the Receive FIFO is empty.
if ((ReloadCounter) == 1'b1)
begin
NextWDCount = 9'b111111111;
UartDataStpNextState = 1'b0;
end
// Keep the watchdog counter counting down so long as the Receive
// FIFO is not empty.
else if ((!(ReloadCounter) & Baud16 & !(WDCmp)) == 1'b1)
begin
NextWDCount = (WDCount) - 1'b1;
UartDataStpNextState = 1'b0;
end
// If the watchdog counter has counted down to zero, then assert
// the DataStp output signal.
else if ((Baud16 & WDCmp & !(ReloadCounter)) == 1'b1)
begin
UartDataStpNextState = 1'b1;
NextDataStp = 1'b1;
end
// Remain in the S_TRIGGER state till the Receive FIFO contents
// have been read out or until there is activity on the receive
// line.
`ST_TRIGGER :
// If there is a write to the UARTICR or if the RX FIFO is
// empty, reload the watchdog counter.
if ((RXFESync == 1'b1) || (UARTRTIClr == 1'b1) || (RTIMSync == 1'b0))
begin
NextWDCount = 9'b111111111;
UartDataStpNextState = 1'b0;
NextDataStp = 1'b0;
end
else
begin
UartDataStpNextState = UartDataStpState;
NextDataStp = DataStp;
end
default :
UartDataStpNextState = 1'b0;
endcase
end // combo;
always @(posedge UARTCLK or negedge nUARTRST)
begin : WDCount_seq
// Set the WDCount to its maximum value of all ones on Reset.
if (nUARTRST == 1'b0)
WDCount <= 9'b111111111;
else
WDCount <= NextWDCount;
end // WDCount_seq;
endmodule
// - ==================== End of UartDataStp ====================
uartbaudcntr.v
module uartbaudcntr (
UARTCLK,
nUARTRST,
LCRUpdateSync,
ILPRUpdateSync,
FBRDUpdateSync,
SIRENSync,
SIRLPSync,
CharTxComp,
CharRxComp,
StopBaudCnt,
FracValue,
UARTLCRHint,
UARTLCRM,
UARTLCRL,
UARTILPR,
Baud16,
IrLPBaud16,
LCRH,
Abort,
Zerobaud
);
input UARTCLK; // Main UART Clock
input nUARTRST; // Muxed Reset (from nUARTRST)
input LCRUpdateSync; // Sync control for LCR
input ILPRUpdateSync; // Sync control for ILPR
input FBRDUpdateSync; // Sync control for FBRD
input SIRENSync; // SIR Enable
input SIRLPSync; // SIR Low power Enable
input CharTxComp; // Character Tx complete
input CharRxComp; // Character Rx complete
input StopBaudCnt; // Stop baud count
input [5:0] FracValue; // Fractional part of baud rate divisor
input [6:0] UARTLCRHint; // 1st stage
input [7:0] UARTLCRM; // 1st stage
input [7:0] UARTLCRL; // 1st stage
input [7:0] UARTILPR; // 1st stage
output Baud16; // Stream of UARTCLK-wide pulses
output IrLPBaud16; // For Low power IrDA
output [6:0] LCRH; // 2nd buffer
output Abort; // TX Abort
output Zerobaud; // Illegal divisor value
// ------------------------------------------------------------------
//
// Purpose : This block contains the 16 bit down counter used to
// generate the Baud16 signal
//
// ------------------------------------------------------------------
//
// UartBaudCntr
// ============
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block generates the Baud16 signal by dividing down the input clock
// UARTCLK. It contains a 16-bit down-counter, which reloads to either the
// LoadValue or (LoadValue + 1) every time it reaches one. The value loaded
// depends on the carry part of an adder. This adder combined with the different
// load values is used to generate a Fractional divider as well.
//
// When the count reaches one, a one UARTCLK clock wide pulse is created
// on the Baud16 signal. This signal is used to add a fractional part to a
// 6-bit adder and the carry output from this adder is used to control the load
// value of the 16-bit counter described earlier.
//
// This block also generates the IrLPBaud16 signal by dividing the
// input UARTCLK by the value (IrDA Low Power Divisor). The
// SIRLPC counter that generates this signal is an 8-bit wide
// down counter.
//
// This module contains the second stage buffers for the LCR
// registers (UARTLCRH, UARTLCRM and UARTLCRL) and the UARTILPR
// register. Data on the corresponding first stage inputs are
// clocked into the second stage buffers when the LCRStg2WrEn
// signal or the ILPRStg2WrEn signal is asserted.
// The LCRStg2WrEn signal is generated by XORing the UpdateLCRSync
// input with the internal delayed version of that signal. The
// delayed version is only updated at the end of the character
// being transmitted or received, so that the registers do not get
// updated during transmission or reception.
// The ILPRStg2WrEn signal is also generated in a similar manner.
//
// ------------------------------------------------------------------
`define FBRDAdderValue 6'b011111
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire UARTCLK; // Main UART Clock (Module Input)
wire nUARTRST; // Muxed Reset (from nUARTRST) (Module Input)
wire [6:0] UARTLCRHint; // 1st stage (Module Input)
wire [7:0] UARTLCRM; // 1st stage (Module Input)
wire [7:0] UARTLCRL; // 1st stage (Module Input)
wire [7:0] UARTILPR; // 1st stage (Module Input)
wire LCRUpdateSync; // Sync control for LCR (Module Input)
wire ILPRUpdateSync; // Sync control for ILPR (Module Input)
wire SIRENSync; // SIR Enable (Module Input)
wire SIRLPSync; // SIR Low power Enable (Module Input)
wire CharTxComp; // Character Tx Complete (Module Input)
wire CharRxComp; // Character Rx Complete (Module Input)
wire StopBaudCnt; // Stop baud count (Module Input)
wire [5:0] FracValue; // Fractional part of baud rate divisor(Module Input)
wire LCRStg2WrEn;
// Load signal for 2nd stage LCR buffers
wire ILPRStg2WrEn;
// Load signal for 2nd stage ILPR buffer
wire [15:0] LoadValue;
// Counter that is used to generate the Baud16 signal
wire iBaud16;
// Internal version of Baud16 signal
wire iIrLPBaud16;
// Internal version of IrLPBaud16 signal
wire FBRDStg2WrEn;
// Delayed version of load signal for 2nd stage of FBRD buffer
wire [6:0] FBRDAdd1;
// Concatenation of 0 and FBRDAdd for 1st part of addition
wire [6:0] FBRDAdd2;
// Concatenation of 0 and FBRD for 2nd part of addition
// ------------------------------------------------------------------
// Register declaration
// ------------------------------------------------------------------
reg [6:0] iLCRH;
// 2nd stage buffer for UARTLCRH
reg [6:0] NextLCRH;
// D-input for LCRH
reg [7:0] LCRM;
// 2nd stage buffer for UARTLCRM
reg [7:0] NextLCRM;
// D-input for LCRM
reg [7:0] LCRL;
// 2nd stage buffer for UARTLCRL
reg [7:0] NextLCRL;
// D-input for LCRL
reg [7:0] ILPR;
// 2nd stage buffer for UARTILPR
reg [7:0] NextILPR;
// D-input for ILPR
reg [5:0] FBRD;
// 2nd stage buffer for UARTFBRD
reg [5:0] NextFBRD;
// D-input for FBRD
reg [15:0] CountBaud16;
// Counter that is used to generate the Baud16 signal
reg [15:0] NextCountBaud16;
// D-input of CountBaud16
reg [7:0] iSIRLPC;
// Internal version of SIRLPC counter that is used to generate the IrLPBaud16 signal
reg [7:0] NextSIRLPC;
// D-input of iSIRLPC
reg LstCntBaud16Bit1;
// Delayed version of Bit 0 of CountBaud16
reg LstSIRLPCBit0;
// Delayed version of Bit 0 of SIRLPC
reg DelLCRUpdate;
// Delayed version of LCRUpdateSync
reg DelILPRUpdate;
// Delayed version of ILPRUpdateSync
reg DelFBRDUpdate;
// Delayed version of FBRDUpdateSync
reg NextDelLCRUpdate;
// D-input of LCRUpdate
reg NextDelILPRUpdate;
// D-input of ILPRUpdate
reg NextDelFBRDUpdate;
// D-input of FBRDUpdate
reg DelLCRStg2WrEn;
// Delayed version of load signal for 2nd stage of LCR buffers
reg DelILPRStg2WrEn;
// Delayed version of load signal for 2nd stage of ILPR buffer
reg iZerobaud;
// internal version of illegal divisor signal
reg UARTFBRDCarry;
// Carry from Fractional baud rate counter
reg NextUARTFBRDCarry;
// Carry from Fractional baud rate counter, next value
reg [6:0] NextUARTFBRDadd;
// Output of addition for UARTFBRDadd
reg [5:0] UARTFBRDadd;
// Sum for fractional baud rate divider
reg StopLPCntr;
// Stop Low power IrDA counter
reg NextStopLPCntr;
// D-input of StopLPCntr
reg Abort; // TX Abort
// ------------------------------------------------------------------
//
// Main Verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Generation of delayed versions of the Update trigger inputs. The
// Delayed Update signals can only change once the current character has
// completed.
// ------------------------------------------------------------------
always @ (posedge UARTCLK or negedge nUARTRST) //novas -21013
begin : p_DelSeq
if (nUARTRST == 1'b0)
begin
DelLCRUpdate <= 1'b0;
DelILPRUpdate <= 1'b0;
DelFBRDUpdate <= 1'b0;
end
else
begin
DelLCRUpdate <= NextDelLCRUpdate;
DelILPRUpdate <= NextDelILPRUpdate;
DelFBRDUpdate <= NextDelFBRDUpdate;
end
end // block: p_DelSeq
always @ (CharRxComp or CharTxComp or LCRUpdateSync or ILPRUpdateSync or
FBRDUpdateSync or DelLCRUpdate or DelILPRUpdate or DelFBRDUpdate)
begin: p_DelComb
if((CharRxComp == 1'b1) && (CharTxComp == 1'b1))
begin
NextDelLCRUpdate = LCRUpdateSync;
NextDelILPRUpdate = ILPRUpdateSync;
NextDelFBRDUpdate = FBRDUpdateSync;
end
else
begin
NextDelLCRUpdate = DelLCRUpdate;
NextDelILPRUpdate = DelILPRUpdate;
NextDelFBRDUpdate = DelFBRDUpdate;
end
end // block: p_DelComb
// ------------------------------------------------------------------
// Generation of load signals for second stage buffers.
// ------------------------------------------------------------------
assign LCRStg2WrEn = (LCRUpdateSync ^ DelLCRUpdate) && (CharRxComp && CharTxComp);
assign ILPRStg2WrEn = (ILPRUpdateSync ^ DelILPRUpdate) && (CharRxComp && CharTxComp);
assign FBRDStg2WrEn = (FBRDUpdateSync ^ DelFBRDUpdate) && (CharRxComp && CharTxComp);
// ------------------------------------------------------------------
// Write into LCRH , LCRM , LCRL and ILPR registers
// ------------------------------------------------------------------
always @(LCRStg2WrEn or ILPRStg2WrEn or FBRDStg2WrEn or iLCRH or LCRM or
LCRL or ILPR or FBRD or UARTLCRHint or UARTLCRM or UARTLCRL or
UARTILPR or FracValue)
begin : p_RegWrComb
NextLCRH = iLCRH;
NextLCRM = LCRM;
NextLCRL = LCRL;
NextILPR = ILPR;
NextFBRD = FBRD;
if (LCRStg2WrEn == 1'b1)
begin
NextLCRH = UARTLCRHint;
NextLCRM = UARTLCRM;
NextLCRL = UARTLCRL;
end
if (ILPRStg2WrEn == 1'b1)
begin
NextILPR = UARTILPR;
end
if (FBRDStg2WrEn == 1'b1)
begin
NextFBRD = FracValue;
end
end // p_RegWrComb;
// ------------------------------------------------------------------
// Sequential process for write
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_RegWrSeq
if(nUARTRST == 1'b0)
begin
iLCRH <= 7'b0000000;
LCRM <= 8'b00000000;
LCRL <= 8'b00000000;
ILPR <= 8'b00000000;
FBRD <= 6'b000000;
end
else
begin
iLCRH <= NextLCRH;
LCRM <= NextLCRM;
LCRL <= NextLCRL;
ILPR <= NextILPR;
FBRD <= NextFBRD;
end
end // p_RegWrSeq;
// ------------------------------------------------------------------
// Assignment of the local copy to port
// ------------------------------------------------------------------
assign LCRH = iLCRH;
// ------------------------------------------------------------------
// Delayed version of LCRStg2WrEn and IrLPRStg2WrEn
// ------------------------------------------------------------------
always @ (posedge UARTCLK or negedge nUARTRST)
begin : p_DelWrEn
if(nUARTRST == 1'b0)
begin
DelLCRStg2WrEn <= 1'b0;
DelILPRStg2WrEn <= 1'b0;
end
else
begin
DelLCRStg2WrEn <= LCRStg2WrEn;
DelILPRStg2WrEn <= ILPRStg2WrEn;
end
end // p_DelWrEn;
// ------------------------------------------------------------------
// Combining LCRM and LCRL registers
// ------------------------------------------------------------------
assign LoadValue = {LCRM, LCRL};
// ------------------------------------------------------------------
// Divide by n+1/n counter:
// Reset the counter to its reload value whenever the StopBaudCnt signal is
// asserted or when the count reaches one or when the reloadValue has been
// updated with a write to the MUBRLCR/UBRLCR registers. When the count reaches
// one, the counter will be reloaded with either n or n+1 depending on the state
// of the carry signal from the adder.
// ------------------------------------------------------------------
always @ (*)
begin : p_X16CntComb
NextCountBaud16 = CountBaud16;
if ((StopBaudCnt == 1'b1) || (DelLCRStg2WrEn == 1'b1) || (iZerobaud == 1'b1))
begin
NextCountBaud16 = LoadValue;
end
else
begin
if (CountBaud16 == 16'b0000000000000001)
begin
if (UARTFBRDCarry == 1'b0)
begin
NextCountBaud16 = LoadValue;
end // if (UARTFBRDCarry == 1'b0)
else
begin
NextCountBaud16 = (LoadValue + 1'b1);
end
end // if (CountBaud16 == 16'b0000000000000001)
else
begin
NextCountBaud16 = (CountBaud16 - 1'b1);
end // else: !if(CountBaud16 == 16'b0000000000000001)
end
end // p_X16CntComb;
// ------------------------------------------------------------------
// Clock in the LSBit of the count to facilitate detection of a zero-to-one
// transition. LstCntBaud16Bit1 is generated from the divide by n/n+1 counter
// and used to generate the Baud16 signal (high for 1 UARTCLK cycle).
// ------------------------------------------------------------------
always @ (posedge UARTCLK or negedge nUARTRST)
begin : p_X16CntSeq
if (nUARTRST == 1'b0)
begin
LstCntBaud16Bit1 <= 1'b0;
CountBaud16 <= 16'b0000000000000000;
end
else
begin
LstCntBaud16Bit1 <= CountBaud16[0];
CountBaud16 <= NextCountBaud16;
end
end // p_X16CntSeq;
// ------------------------------------------------------------------
// For the divide by n/n+1 counter:
// Detect the counter counting down to one by seeing if the
// counter has reached one and the previous value of the
// LSBit is zero.
// ------------------------------------------------------------------
assign iBaud16 = (((LstCntBaud16Bit1 == 1'b0) && (CountBaud16 == 16'b0000000000000001)) ||
((LoadValue == 16'b0000000000000001) && (CountBaud16 == 16'b0000000000000001)));
// ------------------------------------------------------------------
// When the Baud16 signal is high, the adder is loaded with the fractional part.
// Otherwise the adder retains it value. Also, at reset, the adder is
// initialised with the value in FBRDAdderValue. This can be set to a non-zero
// value to average out the pulse spread between /n and /(n+1).
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_AdderSeq
if(nUARTRST == 1'b0)
UARTFBRDadd <= `FBRDAdderValue;
else
UARTFBRDadd <= NextUARTFBRDadd[5:0];
end // block: p_AdderSeq
// Define the two values to add: M + CurrentAdderValue : Note that the MSB
// (Carry) in both is set to zero always.
assign FBRDAdd1 = {1'b0,UARTFBRDadd};
assign FBRDAdd2 = {1'b0,FBRD};
always @ (*)
begin : p_AdderComb
if (StopBaudCnt == 1'b1)
NextUARTFBRDadd = {1'b0, `FBRDAdderValue}; // including carry
else
begin
if (iBaud16 == 1'b1)
NextUARTFBRDadd = FBRDAdd1 + FBRDAdd2;
else
NextUARTFBRDadd = FBRDAdd1;
end // else: !if(StopBaudCnt == 1'b1)
end // block: p_AdderComb
// ------------------------------------------------------------------
// Once Carry is asserted, it should be held high for one UARTCLK cycle, so that
// it can be used to load the 16-bit counter with n+1 (because it will have
// counted down to one). When carry is low and the counter has counted down,
// it should be loaded with n.
// ------------------------------------------------------------------
always @ (posedge UARTCLK or negedge nUARTRST)
begin : p_CarrySeq
if(nUARTRST == 1'b0)
UARTFBRDCarry <= 1'b0;
else
UARTFBRDCarry <= NextUARTFBRDCarry;
end // block: p_CarrySeq
always @ (*)
begin : p_CarryComb
if (StopBaudCnt == 1'b1)
NextUARTFBRDCarry = 1'b0;
else if (iBaud16 == 1'b1)
NextUARTFBRDCarry = NextUARTFBRDadd[6];
else
NextUARTFBRDCarry = UARTFBRDCarry;
end // block: p_CarryComb
// ------------------------------------------------------------------
// If the Load value is 0 and the Fractional divisor value is 0, then
// pull the zerobaud output continuously high, else Zerobaud is 0.
// ------------------------------------------------------------------
always @ (*)
begin : p_ZeroBaud
if ((LoadValue == 16'b0000000000000000) || ((LoadValue == 16'b1111111111111111)
&& (FBRD != 6'b000000)))
begin
iZerobaud = 1'b1;
end
else
begin
iZerobaud = 1'b0;
end
end // p_ZeroBaud;
// ------------------------------------------------------------------
// Assignment of the local copy to port
// ------------------------------------------------------------------
assign Zerobaud = iZerobaud;
// ------------------------------------------------------------------
// Generation of StopLPCntr signal.
// StopLPCntr is asserted when SIRENSync and SIRLPSync are both
// deasserted and CharTxComp and CharRxComp are asserted. This signal
// is used to stop the low power IrDA counter when the Uart is
// operating in normal mode. The current character completes
// transmission or reception before the counter stops.
// ------------------------------------------------------------------
always @ (StopLPCntr or SIRENSync or SIRLPSync or CharTxComp or CharRxComp)
begin : p_StopLPCntrSeqComb
NextStopLPCntr = StopLPCntr;
if ((SIRENSync == 1'b0) && (SIRLPSync == 1'b0) &&
(CharTxComp == 1'b1) && (CharRxComp == 1'b1))
NextStopLPCntr = 1'b1;
else if ((SIRENSync == 1'b1) || (SIRLPSync == 1'b1))
NextStopLPCntr = 1'b0;
end // block: p_StopLPCntrSeqComb
always @ (posedge UARTCLK or negedge nUARTRST)
begin : p_StopLPCntrSeq
if(nUARTRST == 1'b0)
StopLPCntr <= 1'b1;
else
StopLPCntr <= NextStopLPCntr;
end // block: p_StopLPCntrSeq
// ------------------------------------------------------------------
// IrLPBaud16 generation
// The counter is reloaded with it's initial value when any of the
// following occur:
// - the IrDA modes are both disabled and the current character has
// - finished being transmitted or received.
// - StopBaudCnt is asserted.
// - the counter has counted down to 1.
// - a new value has been written to the low power divisor register(ILPR)
// ------------------------------------------------------------------
always @(iSIRLPC or DelILPRStg2WrEn or ILPR or StopBaudCnt or SIRENSync or
SIRLPSync or StopLPCntr)
begin : p_SIRLPCComb
NextSIRLPC = iSIRLPC;
if ((StopBaudCnt == 1'b1) || (DelILPRStg2WrEn == 1'b1) || ((StopLPCntr == 1'b1) &&
(SIRENSync == 1'b0) && (SIRLPSync == 1'b0)))
begin
NextSIRLPC = ILPR;
end
else
begin
if (iSIRLPC == 8'b00000001)
begin
NextSIRLPC = ILPR;
end
else
begin
NextSIRLPC = (iSIRLPC - 1'b1);
end
end
end // p_SIRLPCComb;
// ------------------------------------------------------------------
// Sequential process for the SIRLPC counter.
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin : p_SIRLPCSeq
if(nUARTRST == 1'b0)
begin
LstSIRLPCBit0 <= 1'b0;
iSIRLPC <= 8'b00000000;
end
else
begin
LstSIRLPCBit0 <= iSIRLPC[0];
iSIRLPC <= NextSIRLPC;
end
end // p_SIRLPCSeq;
// ------------------------------------------------------------------
// Detect the counter counting down to one by seeing if the
// counter has reached one and the previous value of the
// LSBit is zero. If ILPR is set to 1, then IrLPBaud16 is pulled high
// ------------------------------------------------------------------
assign iIrLPBaud16 = (((LstSIRLPCBit0 == 1'b0) && (iSIRLPC == 8'b00000001)) ||
(ILPR == 8'b00000001));
// ------------------------------------------------------------------
// Assignment of the local copy to port
// ------------------------------------------------------------------
assign IrLPBaud16 = iIrLPBaud16;
assign Baud16 = iBaud16;
// ------------------------------------------------------------------
// Abort transmission if
// * 'BRK' bit in the LCRH is asserted
// * zerobaud is asserted
// ------------------------------------------------------------------
always @(posedge UARTCLK or negedge nUARTRST)
begin
if(nUARTRST == 1'b0)
begin
Abort <= 1'b0;
end
else
begin
Abort <= ((iLCRH[0] == 1'b1) || (iZerobaud == 1'b1));
end
end
endmodule
// ==================== End of UartBaudCntr ====================
uartapbif.v
module uartapbif (
PCLK,
PRESETn,
PSEL,
PWRITE,
PENABLE,
PADDR,
PWDATA,
RXFF,
TXFF,
RXFE,
TXFE,
BUSY,
UARTTXRIS,
UARTTXMIS,
UARTRXRIS,
UARTRXMIS,
UARTOERIS,
UARTOEMIS,
UARTRTRIS,
UARTRISmodSync,
UARTRISerrSync,
UARTMISerrSync,
UARTMISmodSync,
RXFRdData,
RXSTATUS,
OverrunDet,
UARTLCRH,
UARTLCRM,
UARTLCRL,
UARTFBRD,
UARTCR,
UARTILPR,
UARTIFLS,
UARTIMSC,
UARTDMACR,
nDCDSyncPCLK,
nDSRSyncPCLK,
nCTSSyncPCLK,
nRISyncPCLK,
UARTDRWrEn,
UARTECRWrEn,
UARTLCRHWrEn,
PWDATAIn,
PRDATA,
UARTEINTR,
RXFRdPtrInc,
UARTCRWrEn,
UARTICRWrEn,
UARTILPRWrEn,
UARTIBRDWrEn,
UARTFBRDWrEn,
UARTIFLSWrEn,
UARTIMSCWrEn,
UARTDMACRWrEn
);
input PCLK; // APB Bus clock
input PRESETn; // APB Bus reset
input PSEL; // APB Peripheral select
input PWRITE; // APB Write
input PENABLE; // APB Peripheral enable
input [11:2] PADDR; // APB Addr bus
input [15:0] PWDATA; // Wr databus
input RXFF; // RX FIFO Full
input TXFF; // TX FIFO Full
input RXFE; // RX FIFO Empty
input TXFE; // TX FIFO Empty
input BUSY; // UART Busy
input UARTTXRIS; // Transmit Raw Interrupt
input UARTTXMIS; // Transmit Masked Interrupt
input UARTRXRIS; // Receive Raw Interrupt
input UARTRXMIS; // Receive Masked Interrupt
input UARTOERIS; // Overrun error Raw Interrupt
input UARTOEMIS; // Overrun error Masked Interrupt
input UARTRTRIS; // Receive Timeout interrupt
input [3:0] UARTRISmodSync; // Raw modem status
input [2:0] UARTRISerrSync; // Raw error interrupts
input [2:0] UARTMISerrSync; // Masked error interrupts
input [3:0] UARTMISmodSync; // Masked modem status
input [11:0] RXFRdData; // RX data
input [2:0] RXSTATUS; // RX status
input OverrunDet; // Overrun detected
input [7:0] UARTLCRH; // LCRH
input [7:0] UARTLCRM; // LCRM
input [7:0] UARTLCRL; // LCRL
input [5:0] UARTFBRD; // FBRD
input [15:0] UARTCR; // CR
input [7:0] UARTILPR; // ILPR
input [5:0] UARTIFLS; // IFLS
input [10:0] UARTIMSC; // IMSC
input [2:0] UARTDMACR; // DMA
input nDCDSyncPCLK; // Sync'ed DCD
input nDSRSyncPCLK; // Sync'ed DSR
input nCTSSyncPCLK; // Sync'ed CTS
input nRISyncPCLK; // Sync'ed RI
output UARTDRWrEn; // FIFO Write Enable
output UARTECRWrEn; // Write Enable for ECR
output UARTLCRHWrEn; // Write Enable for LCRH
output [15:0] PWDATAIn; // Int PWDATA
output [31:0] PRDATA; // Read databus
output RXFRdPtrInc; // RX FIFO read
output UARTCRWrEn; // Write Enable for UARTCR
output UARTICRWrEn; // Write Enable for ICR
output UARTILPRWrEn; // Write Enable for ILPR
output UARTIBRDWrEn; // Write Enable for IBRD
output UARTFBRDWrEn; // Write Enable for FBRD
output UARTIFLSWrEn; // Write Enable for IFLS
output UARTIMSCWrEn; // Write Enable for IMSC
output UARTDMACRWrEn; // Write Enable for DMA
output UARTEINTR; // Combined Raw Error interrupt
// ------------------------------------------------------------------
//
// UartApbIf
// =========
//
// ------------------------------------------------------------------
//
// Overview
// ========
// This module decodes APB accesses and generates the read/write
// strobes to the appropriate registers.
//
// ------------------------------------------------------------------
//
// Uart Register Map
// ------------------------------------------------------------------
// Offset Read (Width) Write (Width) Description
// ------------------------------------------------------------------
// 0x00 UARTDR (12bit) UARTDR (8-bit) UART Data register
// 0x04 UARTRSR(4bit) UARTECR Receive Status (Rd)
// Error Clr (Wr)
// 0x08 UARTLCR_H(7bit) UARTLCR_H(7bit) Line Control register,
// High byte
// 0x0C UARTLCR_M(8bit) UARTLCR_M(8bit) Line Control register,
// Middle byte
// 0x10 UARTLCR_L(8bit) UARTLCR_L(8bit) Line Control register,
// Low byte
// 0x14 UARTCR (16bit) UARTCR (16bit) UART Control Register
// 0x18 UARTFR (9bit) - UART Flag register
// 0x1C RESERVED
// - UARTICR Interrupt Clear register
// (Write)
// 0x20 UARTILPR(8bit) UARTILPR(8bit) UART low power counter
// register
// 0x24 UARTIBRD(16bit) UARTIBRD(16bit) Integer Baud Rate Divisor
// Register
// 0x28 UARTFBRD(6bit) UARTFBRD(6bit) Fractional Baud Rate
// Divisor Register
// 0x2C UARTLCR_H(12bit) UARTLCR_H(12bit) Line Control register,
// High byte
// 0x30 UARTCR(16bit) UARTCR(16bit) Control register()
// 0x34 UARTIFLS(6 bit) UARTIFLS(6 bit) Interrupt fifo level
// select register
// 0x38 UARTIMSC(11bit) UARTIMSC(11bit) Interrupt Mask Set/Clear
// 0x3C UARTRIS(11bit) - Raw Interrupt Status
// 0x40 UARTMIS(11bit) - Masked Interrupt Status
// 0x44 - UARTICR(11bit) Interrupt Clear Register
// 0x48 UARTDMACR(3bit) UARTDMACR(3bit) DMA Control Register
// ------------------------------------------------------------------
// Internal Constants
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Normal mode registers address defines.Address decode is for
// bits 2 to 11 (10 bits)
// ------------------------------------------------------------------
`define PADDR_UARTDR 10'b0000000000 // UARTDR at offset 0x00
`define PADDR_UARTRSR 10'b0000000001 // UARTRSR at offset 0x04
`define PADDR_UARTECR 10'b0000000001 // UARTECR at offset 0x04
`define PADDR_UARTFR 10'b0000000110 // UARTFR at offset 0x18
`define PADDR_UARTILPR 10'b0000100000 // UARTILPR at offset 0x20
`define PADDR_UARTIBRD 10'b0000100100 // UARTIBRD at offset 0x24
`define PADDR_UARTFBRD 10'b0000101000 // UARTFBRD at offset 0x28
`define PADDR_UARTLCRH 10'b0000101011 // UARTLCRH at offset 0x2C
`define PADDR_UARTCR 10'b0000110000 // UARTCR at offset 0x30
`define PADDR_UARTIFLS 10'b0000110100 // UARTIFLS at offset 0x34
`define PADDR_UARTIMSC 10'b0000111000 // UARTIMSC at offset 0x38
`define PADDR_UARTRIS 10'b0000111100 // UARTRIS at offset 0x3C
`define PADDR_UARTMIS 10'b0001000000 // UARTMIS at offset 0x40
`define PADDR_UARTICR 10'b0001000100 // UARTICR at offset 0x44
`define PADDR_UARTDMACR 10'b0001001000 // UARTDMACR at offset 0x48
`define PADDR_UARTVS 10'b0001001100 // UARTVS at offset 0x4C
// ------------------------------------------------------------------
// Internal wires
// ------------------------------------------------------------------
wire PCLK; // APB Bus clock
wire PRESETn; // APB Bus Reset
wire PSEL; // APB Peripheral select
wire PENABLE; // APB Peripheral enable
wire PWRITE; // APB Write
wire [11:2] PADDR; // APB Addr bus
wire [15:0] PWDATA; // Wr databus
wire [11:0] RXFRdData; // RX data
wire OverrunDet; // Overrun detecte
wire [2:0] RXSTATUS; // RX status
wire [7:0] UARTLCRH; // LCR
wire [7:0] UARTLCRM; // LCR
wire [7:0] UARTLCRL; // LCR
wire [5:0] UARTFBRD; // FBR
wire TXFE; // TX FIFO Empty
wire [15:0] UARTCR; // CR
wire RXFF; // RX FIFO Full
wire TXFF; // TX FIFO Full
wire RXFE; // RX FIFO Empty
wire BUSY; // UART Busy
wire nDCDSyncPCLK; // Sync'ed DC
wire nDSRSyncPCLK; // Sync'ed DS
wire nCTSSyncPCLK; // Sync'ed CT
wire nRISyncPCLK; // Sync'ed R
wire [7:0] UARTILPR; // ILP
wire [5:0] UARTIFLS; // IFL
wire [10:0] UARTIMSC; // IMS
wire [2:0] UARTDMACR; // DM
wire UARTTXRIS; // Transmit Raw Interrupt
wire UARTTXMIS; // Transmit Masked Interrupt
wire UARTRXRIS; // Receive Raw Interrupt
wire UARTRXMIS; // Receive Masked Interrupt
wire UARTOERIS; // Overrun error Raw Interrupt
wire UARTOEMIS; // Overrun error Masked Interrupt
wire UARTRTRIS; // Receive Timeout interrupt
wire [3:0] UARTRISmodSync; // Raw modem status
wire [2:0] UARTRISerrSync; // Raw error interrupts
wire [2:0] UARTMISerrSync; // Masked error interrupts
wire [3:0] UARTMISmodSync; // Masked modem status
wire [11:2] GatedPADDR; // Save power by gating PADDR internally with PSEL
// ------------------------------------------------------------------
// Read Decodes for Register reads
// ------------------------------------------------------------------
wire UARTDRrd; // UARTDR Read
wire UARTRSRrd; // UARTSR Read
wire UARTLCRHrd; // LCRH Read
wire UARTCRrd; // UARTCR Read
wire UARTFRrd; // UARTFR Read
wire UARTILPRrd; // ILPR Read
wire UARTIBRDrd; // UARTIBRD Read
wire UARTFBRDrd; // UARTFBRD Read
wire UARTIFLSrd; // IFLS Read
wire UARTVSrd; // VS Read
wire UARTIMSCrd; // IMSC Read
wire UARTRISrd; // RIS Read
wire UARTMISrd; // MIS Read
wire UARTDMACRrd; // DMA Read
wire [31:0] NextPRDATA; // D-input of iPRDATA
wire NextUARTEINTR; // D-input of UARTEINTR
wire [3:0] UARTRSR; // RSR concatenation of bits
wire [8:0] UARTFR; // Flag register concatenation of bits
wire [10:0] UARTRIS; // Raw interrupt status register concatenation of modem bits
wire [10:0] UARTMIS; // Masked interrupt status register concatenation of bits
wire WrEn; // Write enable signal common to all addresses in the APB interface
wire RdEn; // Read enable signal common to all addresses in the APB interface
// ------------------------------------------------------------------
// register declaration
// ------------------------------------------------------------------
reg [31:0] PRDATA; // Read databus
reg UARTEINTR; // Combined Raw Error interrupt
// ------------------------------------------------------------------
//
// Main verilog code
// =================
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Define the Version number parameter Vx.y
// VERSION_PAR_X = X
// VERSION_PAR_Y = Y
// ------------------------------------------------------------------
parameter [7:0] VERSION_PAR_X_SUB = 1;
parameter [7:0] VERSION_PAR_Y_SUB = 0;
// ------------------------------------------------------------------
// Write Interface
// ------------------------------------------------------------------
// Save power by preventing change in internal data bus and
// address bus when the device is not selected
// ------------------------------------------------------------------
assign PWDATAIn = (PSEL & PWRITE) ? PWDATA : 16'b0000000000000000 ;
assign GatedPADDR = (PSEL) ? PADDR : 10'b0000000000 ;
assign WrEn = PENABLE & PSEL & PWRITE ;
assign UARTLCRHWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTLCRH ));
assign UARTDRWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTDR ));
assign UARTECRWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTECR ));
assign UARTCRWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTCR ));
assign UARTILPRWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTILPR ));
assign UARTIBRDWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTIBRD ));
assign UARTFBRDWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTFBRD ));
assign UARTIMSCWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTIMSC ));
assign UARTICRWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTICR ));
assign UARTDMACRWrEn= ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTDMACR));
assign UARTIFLSWrEn = ((WrEn == 1'b1) && (GatedPADDR == `PADDR_UARTIFLS ));
// ------------------------------------------------------------------
// Read interface
// ------------------------------------------------------------------
assign RdEn = PSEL & (!PWRITE);
assign UARTLCRHRd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTLCRH ));
assign UARTDRrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTDR ));
assign UARTRSRrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTRSR ));
assign UARTCRrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTCR ));
assign UARTFRrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTFR ));
assign UARTILPRrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTILPR ));
assign UARTIBRDrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTIBRD ));
assign UARTFBRDrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTFBRD ));
assign UARTIMSCrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTIMSC ));
assign UARTRISrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTRIS ));
assign UARTMISrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTMIS ));
assign UARTDMACRrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTDMACR));
assign UARTIFLSrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTIFLS ));
assign UARTVSrd = ((RdEn == 1'b1) && (GatedPADDR == `PADDR_UARTVS ));
assign UARTRSR = {OverrunDet,RXSTATUS};
assign UARTFR = {!!nRISyncPCLK, TXFE, RXFF, TXFF, RXFE,
BUSY, (! nDCDSyncPCLK), (! nDSRSyncPCLK),
(! nCTSSyncPCLK)};
assign UARTRIS = {UARTOERIS, UARTRISerrSync, UARTRTRIS,
UARTTXRIS, UARTRXRIS, UARTRISmodSync};
// The Receive timeout masked and raw interrupts are the same
assign UARTMIS = {UARTOEMIS, UARTMISerrSync, UARTRTRIS,
UARTTXMIS, UARTRXMIS, UARTMISmodSync};
// ------------------------------------------------------------------
// Increment the Read pointer in the RX FIFO after every read from
// the UARTDR register i.e. after every read from the Receive FIFO
// ------------------------------------------------------------------
assign RXFRdPtrInc = PENABLE & UARTDRrd;
// ------------------------------------------------------------------
// Output Mux
// ------------------------------------------------------------------
assign NextPRDATA = (UARTDRrd == 1'b1) ? {20'b0, RXFRdData}
: (UARTRSRrd == 1'b1) ? {28'b0, UARTRSR}
: (UARTLCRHRd == 1'b1) ? {24'b0, UARTLCRH}
: (UARTCRrd == 1'b1) ? {16'b0, UARTCR}
: (UARTFRrd == 1'b1) ? {23'b0, UARTFR}
: (UARTILPRrd == 1'b1) ? {24'b0, UARTILPR}
: (UARTIBRDrd == 1'b1) ? {16'b0, UARTLCRM, UARTLCRL}
: (UARTFBRDrd == 1'b1) ? {26'b0, UARTFBRD}
: (UARTIMSCrd == 1'b1) ? {21'b0, UARTIMSC}
: (UARTRISrd == 1'b1) ? {21'b0, UARTRIS}
: (UARTMISrd == 1'b1) ? {21'b0, UARTMIS}
: (UARTDMACRrd == 1'b1) ? {29'b0, UARTDMACR}
: (UARTIFLSrd == 1'b1) ? {26'b0, UARTIFLS}
: (UARTVSrd == 1'b1) ? ((VERSION_PAR_X_SUB<<24)+(VERSION_PAR_Y_SUB<<16))
: 32'b0;
// ------------------------------------------------------------------
// When the peripheral is not being accessed, 0's are driven
// on the Read databus (PRDATA) so as not to place any restrictions
// on the method of external bus connection. The external data buses of
// the peripherals on the APB may then be connected to the ASB-to-APB
// bridge using Muxed or ORed bus connection method.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Output register.
// ------------------------------------------------------------------
always @(posedge PCLK or negedge PRESETn) //novas -21013
begin
if (PRESETn == 1'b0)
PRDATA <= 32'b0;
else
PRDATA <= NextPRDATA;
end // p_RdSeq;
// ------------------------------------------------------------------
// Combine all raw error interrupts to generate UARTEINTR
// ------------------------------------------------------------------
assign NextUARTEINTR = UARTRISerrSync[0] | UARTRISerrSync[1] |
UARTRISerrSync[2] | UARTOERIS;
always @(posedge PCLK or negedge PRESETn)
begin : p_REIntSeq
if(PRESETn == 1'b0)
UARTEINTR <= 1'b0;
else
UARTEINTR <= NextUARTEINTR;
end // p_REIntSeq;
endmodule
// - ==================== End of UartApbIf ====================
apb_uart.v
module apb_uart(
PCLK, //input 1 //clk and reset
PCLK_REQEN, //input 1 //PCLK enable
PRESETn, //input 1 //
UARTCLK, //input 1 //
nUARTRST, //input 1 //
PSEL, //input 1 //apb interface
PENABLE, //input 1 //
PWRITE, //input 1 //
PADDR, //input 10 //[11:0]
PWDATA, //input 16 //
PRDATA, //input 32 //
nUARTCTS_IN, //input 1 //UART interface
nUARTDCD_IN, //input 1 //
nUARTDSR_IN, //input 1 //
nUARTRI_IN, //input 1 //
UARTRXD_IN, //input 1 //
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, //output 1 //
UARTTXD_OEN, //output 1 //
nSIROUT_OUT, //output 1 //
nUARTOut2_OUT, //output 1 //
nUARTOut1_OUT, //output 1 //
nUARTRTS_OUT, //output 1 //
nUARTDTR_OUT, //output 1 //
UART_OUT2_OEN,
UART_OUT1_OEN,
UART_RTS_OEN,
UART_DTR_OEN,
UARTTXDMACLR, //input 1 //uart dma interface
UARTRXDMACLR, //input 1 //
UARTTXDMASREQ, //output 1 //
UARTTXDMABREQ, //output 1 //
UARTRXDMASREQ, //output 1 //
UARTRXDMABREQ, //output 1 //
UARTINTR //output 1 //uart interrupt
);
input PCLK; // APB Bus Clock
input PCLK_REQEN; // APB Bus Clock Enable
input UARTCLK; // Main UART Clock
input PRESETn; // APB Bus reset
input nUARTRST; // UART Reset
input PSEL; // APB Peripheral select
input PENABLE; // APB Peripheral enable
input PWRITE; // APB Peripheral write
input [11:0] PADDR; // APB Addr bus
input [31:0] PWDATA; // APB write databus
input nUARTCTS_IN; // Modem CTS
input nUARTDCD_IN; // Modem DCD
input nUARTDSR_IN; // Modem DSR
input nUARTRI_IN; // Modem RI
input UARTRXD_IN; // UART Receive input
output UART_CTS_OUT;
output UART_CTS_OEN;
output UART_DCD_OUT;
output UART_DCD_OEN;
output UART_DSR_OUT;
output UART_DSR_OEN;
output UART_RI_OUT;
output UART_RI_OEN;
output UART_RXD_OUT;
output UART_RXD_OEN;
input UARTTXDMACLR; // Transmit DMA Clear
input UARTRXDMACLR; // Receive DMA Clear
output UARTINTR; // Combined interrupt
output [31:0] PRDATA; // Read databus
output UARTTXD_OUT; // UART Transmit line
output UARTTXD_OEN; // UART Transmit line
output nSIROUT_OUT; // SIR Transmit line
output nUARTOut2_OUT; // Modem Out2
output nUARTOut1_OUT; // Modem Out1
output nUARTRTS_OUT; // Modem RTS
output nUARTDTR_OUT; // Modem DTR
output UART_OUT2_OEN;
output UART_OUT1_OEN;
output UART_RTS_OEN;
output UART_DTR_OEN;
output UARTTXDMASREQ; // Transmit DMA single request
output UARTTXDMABREQ; // Transmit DMA burst request
output UARTRXDMASREQ; // Receive DMA single request
output UARTRXDMABREQ; // Receive DMA burst request
// ------------------------------------------------------------------
//
// Uart
// ===
//
// ------------------------------------------------------------------
//
// Overview
// ========
//
// This block is the top level of the UART. This block instantiates the
// functional sub-blocks in the UART.
// The module uartrevand used as a place-holder cell to mark the
// Revision of the Uart. It contains a 2 input AND gate. The 2 input
// pins are tied-off at the top level of the hierarchy. These "TieOffs"
// can be identified during layout and re-wired to "VDD" or "VSS"
// if needed.
//
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Wire declaration
// ------------------------------------------------------------------
wire PCLK; // APB Bus Clock
wire PCLK_REQEN; // APB Bus Clock Enable
wire UARTCLK; // Main UART Clock
wire PRESETn; // AMBA Bus reset
wire nUARTRST; // UART Reset
wire PSEL; // APB Peripheral select
wire PENABLE; // APB Peripheral enable
wire PWRITE; // APB Peripheral write
wire [11:0] PADDR; // APB Addr bus
wire [31:0] PWDATA; // APB write databus
wire nUARTCTS_IN; // Modem CTS
wire nUARTDCD_IN; // Modem DCD
wire nUARTDSR_IN; // Modem DSR
wire nUARTRI_IN; // Modem RI
wire UARTRXD_IN; // UART Receive input
wire UARTTXDMACLR; // Transmit DMA Clear
wire UARTRXDMACLR; // Receive DMA Clear
//wire GPCLK;
wire [15:0] PWDATAIn;
wire UARTLCRHWrEn;
wire UARTCRWrEn;
wire UARTICRWrEn;
wire UARTIBRDWrEn;
wire UARTFBRDWrEn;
wire UARTIMSCWrEn;
wire RXFRdPtrInc;
wire UARTECRWrEn;
wire UARTDRWrEn;
wire [7:0] UARTLCRH;
wire [7:0] UARTLCRM;
wire [7:0] UARTLCRL;
wire [5:0] UARTFBRD;
wire [10:0] RXFIFOData;
wire DataStp;
wire LCRUpdateSync;
wire ILPRUpdateSync;
wire FBRDUpdateSync;
wire Baud16;
wire UARTRXDSync;
wire RXFE;
wire RXFESync;
wire RXFWrDone;
wire RXFWrDoneSync;
wire RXD;
wire RXFWr;
wire RXFWrSync;
wire RXFF;
wire OverrunDet;
wire [6:0] LCRH;
wire TXFRdPtrIncSync;
wire TXFRdPtrInc;
wire RdPtrIncDone;
wire RdPtrIncDoneSync;
wire [7:0] TXShiftData;
wire TXFF;
wire TXFE;
wire Abort;
wire AbortSync;
wire TXDataAvlbl;
wire nDCDSyncUARTCLK;
wire nDSRSyncUARTCLK;
wire nCTSSyncUARTCLK;
wire nRISyncUARTCLK;
wire DCDIMSync;
wire DSRIMSync;
wire CTSIMSync;
wire RIIMSync;
wire RTIMSync;
wire FEIMSync;
wire PEIMSync;
wire BEIMSync;
wire IrLPBaud16;
wire UARTENSync;
wire TXESync;
wire RXESync;
wire SIRLPSync;
wire SIRINSync;
wire TXD;
wire [11:0] RXFRdData;
wire [2:0] RXSTATUS;
wire UARTILPRWrEn;
wire SIRENSync;
wire TXBUSY;
wire TXDataAvlblSync;
wire RXBUSY;
wire nDCDSyncPCLK;
wire nDSRSyncPCLK;
wire nCTSSyncPCLK;
wire nRISyncPCLK;
wire TXBUSYSync;
wire BUSY;
wire UARTRTICSync;
wire UARTFEICSync;
wire UARTPEICSync;
wire UARTBEICSync;
wire UARTDCDICSync;
wire UARTDSRICSync;
wire UARTCTSICSync;
wire UARTRIICSync;
wire CharTxCompSync;
wire [10:0] UARTICR;
wire [7:0] UARTILPR;
wire ILPRUpdate;
wire LCRUpdate;
wire FBRDUpdate;
wire [15:0] UARTCR;
wire UARTTXDint;
wire nSIROUTint;
wire nUARTOut2int;
wire nUARTOut1int;
wire nUARTRTSint;
wire nUARTDTRint;
wire [6:0] uBaudCntrLCRHint;
wire UARTIFLSWrEn;
wire [5:0] UARTIFLS;
wire UARTOEIClr;
wire CharTxComp;
wire CharRxComp;
wire StopBaudCnt;
wire RXEnable;
wire [2:0] UartRXCntlState;
wire [10:0] UARTIMSC;
wire [3:0] UARTRISmodSync;
wire [3:0] UARTMISmodSync;
wire [3:0] UARTRISmod;
wire [3:0] UARTMISmod;
wire [2:0] UARTRISerrSync;
wire [2:0] UARTMISerrSync;
wire [2:0] UARTRISerr;
wire [2:0] UARTMISerr;
wire UARTEINTRfbp;
wire UARTTXRIS;
wire UARTTXMIS;
wire UARTEINTR;
wire UARTTXIClr;
wire UARTRXRIS;
wire UARTRXMIS;
wire UARTRTRIS;
wire UARTRXIClr;
wire UARTOERIS;
wire UARTOEMIS;
wire RXFGTE1Full;
wire RXIntLevel;
wire TXFLTE15Full;
wire TXIntLevel;
wire UARTDMACRWrEn;
wire [2:0] UARTDMACR;
wire inUARTRTScr;
wire UARTTXDMACLRSync;
wire UARTRXDMACLRSync;
wire TXDMASREQ;
wire TXDMABREQ;
wire RXDMASREQ;
wire RXDMABREQ;
wire UARTMSINT;
wire CTSEnSyncUCLK;
wire Zerobaud;
assign nUARTOut2int = ! UARTCR[13];
assign nUARTOut1int = ! UARTCR[12];
assign inUARTRTScr = ! UARTCR[11];
assign nUARTDTRint = ! UARTCR[10];
// Assign outputs from internal signals
wire sir_en;
assign sir_en = UARTCR[1];
assign UARTTXD_OUT = sir_en ? nSIROUTint : UARTTXDint ;
//assign nSIROUT_OUT = nSIROUTint ;
assign nUARTOut2_OUT = nUARTOut2int ;
assign nUARTOut1_OUT = nUARTOut1int ;
assign nUARTRTS_OUT = nUARTRTSint ;
assign nUARTDTR_OUT = nUARTDTRint ;
assign UART_OUT2_OEN = 1'b0;
assign UART_OUT1_OEN = 1'b0;
assign UART_RTS_OEN = 1'b0;
assign UART_DTR_OEN = 1'b0;
assign UART_CTS_OUT = 1'b1;
assign UART_CTS_OEN = 1'b1; //modify by Joseph, UART_CTS is input
assign UART_DCD_OUT = 1'b1;
assign UART_DCD_OEN = 1'b1;
assign UART_DSR_OUT = 1'b1;
assign UART_DSR_OEN = 1'b1;
assign UART_RI_OUT = 1'b1;
assign UART_RI_OEN = 1'b1;
assign UART_RXD_OUT = 1'b1;
assign UART_RXD_OEN = 1'b1;
assign UARTTXD_OEN = 1'b0;
assign UARTTXDMASREQ = TXDMASREQ ;
assign UARTTXDMABREQ = TXDMABREQ ;
assign UARTRXDMASREQ = RXDMASREQ ;
assign UARTRXDMABREQ = RXDMABREQ ;
// ------------------------------------------------------------------
// Define the Version number parameter Vx.y
// VERSION_PAR_X = X
// VERSION_PAR_Y = Y
// ------------------------------------------------------------------
parameter [7:0] VERSION_PAR_X = 1;
parameter [7:0] VERSION_PAR_Y = 2;
// AUTO PCLK
/*
apb_clk_req apb_clk_req_uart(
.psel (1'b1 ),//Here should be AHB Bus clock require signal. Because isn't that signal now, connect it to 1 temporarily.
.clk_i (PCLK ),
.clk_reqen (PCLK_REQEN ),
.clk_o (GPCLK )
);
*/
// Register block for normal mode registers
uartregblock uartregblock (
.PCLK (PCLK),
.PRESETn (PRESETn),
.RXFRdPtrInc (RXFRdPtrInc),
.PWDATAIn (PWDATAIn),
.RXFRdData (RXFRdData[10:8]),
.UARTECRWrEn (UARTECRWrEn),
.UARTLCRHWrEn (UARTLCRHWrEn),
.UARTILPRWrEn (UARTILPRWrEn),
.UARTCRWrEn (UARTCRWrEn),
.UARTICRWrEn (UARTICRWrEn),
.UARTIBRDWrEn (UARTIBRDWrEn),
.UARTFBRDWrEn (UARTFBRDWrEn),
.UARTIFLSWrEn (UARTIFLSWrEn),
.UARTIMSCWrEn (UARTIMSCWrEn),
.UARTDMACRWrEn (UARTDMACRWrEn),
.UARTOEIClr (UARTOEIClr),
.UARTRTRIS (UARTRTRIS),
.UARTRISerrSync (UARTRISerrSync),
.UARTRISmodSync (UARTRISmodSync),
.UARTTXIClr (UARTTXIClr),
.UARTRXIClr (UARTRXIClr),
.LCRUpdate (LCRUpdate),
.ILPRUpdate (ILPRUpdate),
.FBRDUpdate (FBRDUpdate),
.UARTICR (UARTICR),
.RXSTATUS (RXSTATUS),
.UARTLCRH (UARTLCRH),
.UARTLCRM (UARTLCRM),
.UARTLCRL (UARTLCRL),
.UARTILPR (UARTILPR),
.UARTCR (UARTCR),
.UARTIFLS (UARTIFLS),
.UARTDMACR (UARTDMACR),
.UARTFBRD (UARTFBRD),
.UARTIMSC (UARTIMSC)
);
// This block provides the interface to the APB bus
uartapbif #(
.VERSION_PAR_X_SUB (VERSION_PAR_X),
.VERSION_PAR_Y_SUB (VERSION_PAR_Y)
)
uartapbif (
.PCLK (PCLK),
.PRESETn (PRESETn),
.PSEL (PSEL),
.PWRITE (PWRITE),
.PENABLE (PENABLE),
.PADDR (PADDR[11:2]),
.PWDATA (PWDATA[15:0]),
.RXFF (RXFF),
.TXFF (TXFF),
.RXFE (RXFE),
.TXFE (TXFE),
.BUSY (BUSY),
.UARTTXRIS (UARTTXRIS),
.UARTTXMIS (UARTTXMIS),
.UARTRXRIS (UARTRXRIS),
.UARTRXMIS (UARTRXMIS),
.UARTOERIS (UARTOERIS),
.UARTOEMIS (UARTOEMIS),
.UARTRTRIS (UARTRTRIS),
.UARTRISmodSync (UARTRISmodSync),
.UARTRISerrSync (UARTRISerrSync),
.UARTMISerrSync (UARTMISerrSync),
.UARTMISmodSync (UARTMISmodSync),
.RXFRdData (RXFRdData),
.RXSTATUS (RXSTATUS),
.OverrunDet (OverrunDet),
.UARTLCRH (UARTLCRH),
.UARTLCRM (UARTLCRM),
.UARTLCRL (UARTLCRL),
.UARTFBRD (UARTFBRD),
.UARTCR (UARTCR),
.UARTILPR (UARTILPR),
.UARTIFLS (UARTIFLS),
.UARTIMSC (UARTIMSC),
.UARTDMACR (UARTDMACR),
.nDCDSyncPCLK (nDCDSyncPCLK),
.nDSRSyncPCLK (nDSRSyncPCLK),
.nCTSSyncPCLK (nCTSSyncPCLK),
.nRISyncPCLK (nRISyncPCLK),
.UARTDRWrEn (UARTDRWrEn),
.UARTECRWrEn (UARTECRWrEn),
.UARTLCRHWrEn (UARTLCRHWrEn),
.PWDATAIn (PWDATAIn),
.PRDATA (PRDATA),
.UARTEINTR (UARTEINTR),
.RXFRdPtrInc (RXFRdPtrInc),
.UARTCRWrEn (UARTCRWrEn),
.UARTICRWrEn (UARTICRWrEn),
.UARTILPRWrEn (UARTILPRWrEn),
.UARTIBRDWrEn (UARTIBRDWrEn),
.UARTFBRDWrEn (UARTFBRDWrEn),
.UARTIFLSWrEn (UARTIFLSWrEn),
.UARTIMSCWrEn (UARTIMSCWrEn),
.UARTDMACRWrEn (UARTDMACRWrEn)
);
// Synchronisers for signals crossing into PCLK domain
uartsynctopclk uartsynctopclk (
.PCLK (PCLK),
.PRESETn (PRESETn),
.TXBUSY (TXBUSY),
.TXFRdPtrInc (TXFRdPtrInc),
.RXFWr (RXFWr),
.Abort (Abort),
.DataStp (DataStp),
.nUARTDCDint (nUARTDCD_IN),
.nUARTDSRint (nUARTDSR_IN),
.nUARTCTSint (nUARTCTS_IN),
.nUARTRIint (nUARTRI_IN),
.nUARTRTSint (nUARTRTSint),
.nUARTDTRint (nUARTDTRint),
.nUARTOut2int (nUARTOut2int),
.nUARTOut1int (nUARTOut1int),
.UARTRISmod (UARTRISmod),
.UARTMISmod (UARTMISmod),
.UARTRISerr (UARTRISerr),
.UARTMISerr (UARTMISerr),
.IntUARTTXDMACLR (UARTTXDMACLR),
.IntUARTRXDMACLR (UARTRXDMACLR),
.CharTxComp (CharTxComp),
.TXBUSYSync (TXBUSYSync),
.TXFRdPtrIncSync (TXFRdPtrIncSync),
.RXFWrSync (RXFWrSync),
.AbortSync (AbortSync),
.nDCDSyncPCLK (nDCDSyncPCLK),
.nDSRSyncPCLK (nDSRSyncPCLK),
.nCTSSyncPCLK (nCTSSyncPCLK),
.nRISyncPCLK (nRISyncPCLK),
.UARTRTRIS (UARTRTRIS),
.UARTRISmodSync (UARTRISmodSync),
.UARTMISmodSync (UARTMISmodSync),
.UARTRISerrSync (UARTRISerrSync),
.UARTMISerrSync (UARTMISerrSync),
.UARTTXDMACLRSync (UARTTXDMACLRSync),
.UARTRXDMACLRSync (UARTRXDMACLRSync),
.CharTxCompSync (CharTxCompSync),
.LBE (UARTCR[7])
);
// Synchronisers for signals crossing into UARTCLK domain
uartsynctouclk uartsynctouclk (
.UARTCLK (UARTCLK),
.nUARTRST (nUARTRST),
.SIRLP (UARTCR[2]),
.SIREN (UARTCR[1]),
.UARTEN (UARTCR[0]),
.TXE (UARTCR[8]),
.RXE (UARTCR[9]),
.TXDataAvlbl (TXDataAvlbl),
.RXFE (RXFE),
.CTSEn (UARTCR[15]),
.LCRUpdate (LCRUpdate),
.ILPRUpdate (ILPRUpdate),
.FBRDUpdate (FBRDUpdate),
.UARTRXDint (UARTRXD_IN),
.UARTTXDint (UARTTXD_OUT),
.SIRINint (nSIROUT_OUT),
.nSIROUTint (nSIROUTint),
.RXFWrDone (RXFWrDone),
.RdPtrIncDone (RdPtrIncDone),
.DCDIM (UARTIMSC[2]),
.DSRIM (UARTIMSC[3]),
.CTSIM (UARTIMSC[1]),
.RIIM (UARTIMSC[0]),
.RTIM (UARTIMSC[6]),
.FEIM (UARTIMSC[7]),
.PEIM (UARTIMSC[8]),
.BEIM (UARTIMSC[9]),
.nUARTDCDint (nUARTDCD_IN),
.nUARTDSRint (nUARTDSR_IN),
.nUARTCTSint (nUARTCTS_IN),
.nUARTRIint (nUARTRI_IN),
.nUARTRTSint (nUARTRTSint),
.nUARTDTRint (nUARTDTRint),
.nUARTOut2int (nUARTOut2int),
.nUARTOut1int (nUARTOut1int),
.UARTDCDIC (UARTICR[2]),
.UARTDSRIC (UARTICR[3]),
.UARTCTSIC (UARTICR[1]),
.UARTRIIC (UARTICR[0]),
.UARTFEIC (UARTICR[7]),
.UARTPEIC (UARTICR[8]),
.UARTBEIC (UARTICR[9]),
.UARTRTIC (UARTICR[6]),
.SIRLPSync (SIRLPSync),
.SIRENSync (SIRENSync),
.UARTENSync (UARTENSync),
.TXESync (TXESync),
.RXESync (RXESync),
.TXDataAvlblSync (TXDataAvlblSync),
.RXFESync (RXFESync),
.CTSEnSyncUCLK (CTSEnSyncUCLK),
.LCRUpdateSync (LCRUpdateSync),
.ILPRUpdateSync (ILPRUpdateSync),
.FBRDUpdateSync (FBRDUpdateSync),
.UARTRXDSync (UARTRXDSync),
.SIRINSync (SIRINSync),
.RXFWrDoneSync (RXFWrDoneSync),
.RdPtrIncDoneSync (RdPtrIncDoneSync),
.DCDIMSync (DCDIMSync),
.DSRIMSync (DSRIMSync),
.CTSIMSync (CTSIMSync),
.RIIMSync (RIIMSync),
.RTIMSync (RTIMSync),
.FEIMSync (FEIMSync),
.PEIMSync (PEIMSync),
.BEIMSync (BEIMSync),
.nDCDSyncUARTCLK (nDCDSyncUARTCLK),
.nDSRSyncUARTCLK (nDSRSyncUARTCLK),
.nCTSSyncUARTCLK (nCTSSyncUARTCLK),
.nRISyncUARTCLK (nRISyncUARTCLK),
.UARTDCDICSync (UARTDCDICSync),
.UARTDSRICSync (UARTDSRICSync),
.UARTCTSICSync (UARTCTSICSync),
.UARTRIICSync (UARTRIICSync),
.UARTFEICSync (UARTFEICSync),
.UARTPEICSync (UARTPEICSync),
.UARTBEICSync (UARTBEICSync),
.UARTRTICSync (UARTRTICSync),
.LBE (UARTCR[7])
);
// Modem interrupt generation block
uartmodem uartmodem (
.UARTCLK (UARTCLK),
.nUARTRST (nUARTRST),
.SIRENSync (SIRENSync),
.nDCDSyncUARTCLK (nDCDSyncUARTCLK),
.nDSRSyncUARTCLK (nDSRSyncUARTCLK),
.nCTSSyncUARTCLK (nCTSSyncUARTCLK),
.nRISyncUARTCLK (nRISyncUARTCLK),
.UARTDCDICSync (UARTDCDICSync),
.UARTDSRICSync (UARTDSRICSync),
.UARTCTSICSync (UARTCTSICSync),
.UARTRIICSync (UARTRIICSync),
.DCDIMSync (DCDIMSync),
.DSRIMSync (DSRIMSync),
.CTSIMSync (CTSIMSync),
.RIIMSync (RIIMSync),
.UARTMSINT (UARTMSINT),
.UARTRISmod (UARTRISmod),
.UARTMISmod (UARTMISmod)
);
// UART Receiver
uartreceive uartreceive (
.UARTCLK (UARTCLK),
.nUARTRST (nUARTRST),
.UARTENSync (UARTENSync),
.SIRENSync (SIRENSync),
.RXESync (RXESync),
.Baud16 (Baud16),
.WLEN (LCRH[5:4]),
.STP2 (LCRH[3]),
.EPS (LCRH[2]),
.PEN (LCRH[1]),
.SPS (LCRH[6]),
.RXFWrDoneSync (RXFWrDoneSync),
.Zerobaud (Zerobaud),
.RXFESync (RXFESync),
.RXD (RXD),
.RTIMSync (RTIMSync),
.FEIMSync (FEIMSync),
.PEIMSync (PEIMSync),
.BEIMSync (BEIMSync),
.UARTRTICSync (UARTRTICSync),
.UARTFEICSync (UARTFEICSync),
.UARTPEICSync (UARTPEICSync),
.UARTBEICSync (UARTBEICSync),
.RXFWr (RXFWr),
.RXFIFOData (RXFIFOData),
.DataStp (DataStp),
.RXBUSY (RXBUSY),
.RXEnable (RXEnable),
.UartRXCntlState (UartRXCntlState),
.UARTRISerr (UARTRISerr),
.UARTMISerr (UARTMISerr),
.UARTEINTRfbp (UARTEINTRfbp),
.CharRxComp (CharRxComp)
);
// Receive FIFO
uartrxfifo uartrxfifo (
.PCLK (PCLK),
.PRESETn (PRESETn),
.RXFWrSync (RXFWrSync),
.RXFRdPtrInc (RXFRdPtrInc),
.RXFIFOData (RXFIFOData),
.UARTECRWrEn (UARTECRWrEn),
.FEN (UARTLCRH[4]),
.RTSEn (UARTCR[14]),
.nUARTRTScr (inUARTRTScr),
.RXIFLSEL (UARTIFLS[5:3]),
.UARTRXIC (UARTICR[4]),
.UARTOEIC (UARTICR[10]),
.RXIM (UARTIMSC[4]),
.OEIM (UARTIMSC[10]),
.RXFRdData (RXFRdData),
.RXFWrDone (RXFWrDone),
.RXFE (RXFE),
.RXFF (RXFF),
.OverrunDet (OverrunDet),
.nUARTRTSint (nUARTRTSint),
.RXFGTE1Full (RXFGTE1Full),
.RXIntLevel (RXIntLevel),
.UARTRXIClr (UARTRXIClr),
.UARTOEIClr (UARTOEIClr),
.UARTRXRIS (UARTRXRIS),
.UARTRXMIS (UARTRXMIS),
.UARTOERIS (UARTOERIS),
.UARTOEMIS (UARTOEMIS)
);
// Transmit FIFO
uarttxfifo uarttxfifo (
.PCLK (PCLK),
.PRESETn (PRESETn),
.UARTEN (UARTCR[0]),
.TXE (UARTCR[8]),
.UARTDRWrEn (UARTDRWrEn),
.TXFRdPtrIncSync (TXFRdPtrIncSync),
.FEN (UARTLCRH[4]),
.AbortSync (AbortSync),
.TXBUSYSync (TXBUSYSync),
.PWDATAIn (PWDATAIn[7:0]),
.TXIFLSEL (UARTIFLS[2:0]),
.TXFF (TXFF),
.TXFE (TXFE),
.RdPtrIncDone (RdPtrIncDone),
.TXShiftData (TXShiftData),
.TXDataAvlbl (TXDataAvlbl),
.BUSY (BUSY),
.CharTxComp (CharTxCompSync),
.UARTTXIC (UARTICR[5]),
.UARTTXIClr (UARTTXIClr),
.TXIM (UARTIMSC[5]),
.UARTTXRIS (UARTTXRIS),
.UARTTXMIS (UARTTXMIS),
.TXFLTE15Full (TXFLTE15Full),
.TXIntLevel (TXIntLevel)
);
// IrDA encoder/decoder
uartirda uartirda (
.UARTCLK (UARTCLK),
.nUARTRST (nUARTRST),
.Baud16 (Baud16),
.IrLPBaud16 (IrLPBaud16),
.SIRLPSync (SIRLPSync),
.SIRENSync (SIRENSync),
.StopBaudCnt (StopBaudCnt),
.TXBUSY (TXBUSY),
.RXBUSY (RXBUSY),
.TXD (TXD),
.SIRINSync (SIRINSync),
.UARTRXDSync (UARTRXDSync),
.UARTTXDint (UARTTXDint),
.RXD (RXD),
.nSIROUTint (nSIROUTint)
);
// Baud rate generator
uartbaudcntr uartbaudcntr (
.UARTCLK (UARTCLK),
.nUARTRST (nUARTRST),
.LCRUpdateSync (LCRUpdateSync),
.ILPRUpdateSync (ILPRUpdateSync),
.FBRDUpdateSync (FBRDUpdateSync),
.SIRENSync (SIRENSync),
.SIRLPSync (SIRLPSync),
.CharTxComp (CharTxComp),
.CharRxComp (CharRxComp),
.StopBaudCnt (StopBaudCnt),
.FracValue (UARTFBRD[5:0]),
.UARTLCRHint (uBaudCntrLCRHint),
.UARTLCRM (UARTLCRM),
.UARTLCRL (UARTLCRL),
.UARTILPR (UARTILPR),
.Baud16 (Baud16),
.IrLPBaud16 (IrLPBaud16),
.LCRH (LCRH),
.Abort (Abort),
.Zerobaud (Zerobaud)
);
assign uBaudCntrLCRHint = {UARTLCRH[7:5], UARTLCRH[3:0]};
// UART Transmitter
uarttxcntl uarttxcntl (
.UARTCLK (UARTCLK),
.nUARTRST (nUARTRST),
.RXEnable (RXEnable),
.UartRXCntlState (UartRXCntlState),
.CTSEn (CTSEnSyncUCLK),
.nCTSSyncUARTCLK (nCTSSyncUARTCLK),
.Baud16 (Baud16),
.TXDataAvlblSync (TXDataAvlblSync),
.RdPtrIncDoneSync (RdPtrIncDoneSync),
.UARTENSync (UARTENSync),
.TXESync (TXESync),
.TXShiftData (TXShiftData),
.WLEN (LCRH[5:4]),
.STP2 (LCRH[3]),
.PEN (LCRH[1]),
.EPS (LCRH[2]),
.BRK (LCRH[0]),
.Zerobaud (Zerobaud),
.SPS (LCRH[6]),
.TXFRdPtrInc (TXFRdPtrInc),
.TXD (TXD),
.TXBUSY (TXBUSY),
.CharTxComp (CharTxComp),
.StopBaudCnt (StopBaudCnt)
);
// DMA Interface
uartdma uartdma (
.PCLK (PCLK),
.PRESETn (PRESETn),
.UARTEN (UARTCR[0]),
.TXDMAE (UARTDMACR[1]),
.RXDMAE (UARTDMACR[0]),
.DMAONERR (UARTDMACR[2]),
.TXE (UARTCR[8]),
.RXE (UARTCR[9]),
.FEN (UARTLCRH[4]),
.TXIntLevel (TXIntLevel),
.RXIntLevel (RXIntLevel),
.TXFLTE15Full (TXFLTE15Full),
.RXFGTE1Full (RXFGTE1Full),
.UARTTXDMACLRSync (UARTTXDMACLRSync),
.UARTRXDMACLRSync (UARTRXDMACLRSync),
.UARTEINTR (UARTEINTR),
.TXDMASREQ (TXDMASREQ),
.TXDMABREQ (TXDMABREQ),
.RXDMASREQ (RXDMASREQ),
.RXDMABREQ (RXDMABREQ)
);
// Interrupt block
uartinterrupt uartinterrupt (
.DataStp (DataStp),
.UARTMSINT (UARTMSINT),
.UARTEINTRfbp (UARTEINTRfbp),
.UARTTXMIS (UARTTXMIS),
.UARTRXMIS (UARTRXMIS),
.UARTOEMIS (UARTOEMIS),
.UARTRTIC (UARTICR[6]),
.UARTDSRIC (UARTICR[3]),
.UARTDCDIC (UARTICR[2]),
.UARTCTSIC (UARTICR[1]),
.UARTRIIC (UARTICR[0]),
.UARTOEIC (UARTICR[10]),
.UARTBEIC (UARTICR[9]),
.UARTPEIC (UARTICR[8]),
.UARTFEIC (UARTICR[7]),
.UARTINTR (UARTINTR)
);
endmodule
// - ==================== End of Uart ====================
四.sim
Makefile
# -----------------------------------------------------------------
# File name : Makefile
# Title :
# Project : UART Module Verification
# Created :
# Description :
# Notes :
# -----------------------------------------------------------------
## Variables and scripts
SVSEED = random
VERBOSITY = UVM_HIGH
UVM_VER = uvm-1.1
WORKSHOP_MODE = NONE
defines = LITTLE_ENDIAN
uvm_defines = UVM_OBJECT_MUST_HAVE_CONSTRUCTOR
#TEST_NAME = apb_uart_rx_tx
#TEST_NAME = uart_apb_incr_data
#TEST_NAME = apb_to_uart_1stopbit
#TEST_NAME = uart_txrx_fifo_cov
#TEST_NAME = uart_incr_payload_test
uvm_defines = UVM_OBJECT_MUST_HAVE_CONSTRUCTOR+UVM_DEPRECATED_STARTING_PHASE
WORKAREA = ../..
LAB_DIR = ${WORKAREA}/lab6
INCLUDEFILE += +incdir+${LAB_DIR}/env/apb_uvc/
INCLUDEFILE += +incdir+${LAB_DIR}/env/uart_uvc/
INCLUDEFILE += +incdir+${LAB_DIR}/env/uart_ctrl/sequence_lib/
INCLUDEFILE += +incdir+${LAB_DIR}/env/uart_ctrl/sv/
INCLUDEFILE += +incdir+${LAB_DIR}/env/uart_ctrl/tb/
INCLUDEFILE += +incdir+${LAB_DIR}/env/uart_ctrl/test/
INCLUDEFILE += +incdir+${LAB_DIR}/rtl/
compile_options = -sverilog ${INCLUDEFILE} -lca -debug_access+all +define+LITTLE_ENDIAN -kdb +vcs+vcdpluson -timescale="1us/100ns" -l comp.log -ntb_opts ${UVM_VER}
run_options = -l vcs_sim.log
######################################################################
# Targets
######################################################################
#export WORKAREA=${shell pwd}/../..
#export WORKAREA=../..
default : compile run
all: compile run
compile:
vcs -full64 ${compile_options} -f ${LAB_DIR}/scripts/filelist_rtl -f ${LAB_DIR}/scripts/filelist_tb -cm line+cond+tgl+branch
run:
./simv +UVM_TESTNAME=uart_to_apb_test ${run_options} -gui -cm line+cond+tgl+branch +UVM_TR_RECORD +UVM_LOG_RECORD +UVM_VERBOSITY=${VERBOSITY} &
clean:
rm -rf DVEfiles simv.daidir simv.vdb uvm-1.2 vcdplus.vpd vc_hdrs.h vcs_sim.log comp.log csrc inter.vpd ucli.key simv cm.log
浙公网安备 33010602011771号