1 |
2 |
MichaelA |
////////////////////////////////////////////////////////////////////////////////
|
2 |
|
|
//
|
3 |
|
|
// Copyright 2008-2013 by Michael A. Morris, dba M. A. Morris & Associates
|
4 |
|
|
//
|
5 |
|
|
// All rights reserved. The source code contained herein is publicly released
|
6 |
|
|
// under the terms and conditions of the GNU Lesser Public License. No part of
|
7 |
|
|
// this source code may be reproduced or transmitted in any form or by any
|
8 |
|
|
// means, electronic or mechanical, including photocopying, recording, or any
|
9 |
|
|
// information storage and retrieval system in violation of the license under
|
10 |
|
|
// which the source code is released.
|
11 |
|
|
//
|
12 |
|
|
// The source code contained herein is free; it may be redistributed and/or
|
13 |
|
|
// modified in accordance with the terms of the GNU Lesser General Public
|
14 |
|
|
// License as published by the Free Software Foundation; either version 2.1 of
|
15 |
|
|
// the GNU Lesser General Public License, or any later version.
|
16 |
|
|
//
|
17 |
|
|
// The source code contained herein is freely released WITHOUT ANY WARRANTY;
|
18 |
|
|
// without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
19 |
|
|
// PARTICULAR PURPOSE. (Refer to the GNU Lesser General Public License for
|
20 |
|
|
// more details.)
|
21 |
|
|
//
|
22 |
|
|
// A copy of the GNU Lesser General Public License should have been received
|
23 |
|
|
// along with the source code contained herein; if not, a copy can be obtained
|
24 |
|
|
// by writing to:
|
25 |
|
|
//
|
26 |
|
|
// Free Software Foundation, Inc.
|
27 |
|
|
// 51 Franklin Street, Fifth Floor
|
28 |
|
|
// Boston, MA 02110-1301 USA
|
29 |
|
|
//
|
30 |
|
|
// Further, no use of this source code is permitted in any form or means
|
31 |
|
|
// without inclusion of this banner prominently in any derived works.
|
32 |
|
|
//
|
33 |
|
|
// Michael A. Morris
|
34 |
|
|
// Huntsville, AL
|
35 |
|
|
//
|
36 |
|
|
////////////////////////////////////////////////////////////////////////////////
|
37 |
|
|
|
38 |
|
|
`timescale 1ns / 1ps
|
39 |
|
|
|
40 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
41 |
|
|
// Company: M. A. Morris & Associates
|
42 |
|
|
// Engineer: Michael A. Morris
|
43 |
|
|
//
|
44 |
|
|
// Create Date: 09:37:34 06/15/2008
|
45 |
|
|
/// Design Name: Synchronous Serial Peripheral (SSP) Interface UART
|
46 |
|
|
// Module Name: ../VerilogCoponentsLib/SSP_UART/UART_INT.v
|
47 |
|
|
// Project Name: Verilog Components Library
|
48 |
|
|
// Target Devices: XC3S50A-4VQG100I, XC3S20A-4VQG100I, XC3S700AN-4FFG484I
|
49 |
|
|
// Tool versions: ISE 10.1i SP3
|
50 |
|
|
//
|
51 |
|
|
// Description:
|
52 |
|
|
//
|
53 |
|
|
// This module implements the interrupt request logic for the SSP UART. Inter-
|
54 |
|
|
// rupt requests are generated for four conditions:
|
55 |
|
|
//
|
56 |
|
|
// (1) Transmit FIFO Empty;
|
57 |
|
|
// (2) Transmit FIFO Half Empty;
|
58 |
|
|
// (3) Receive FIFO Half Full;
|
59 |
|
|
// (4) and Receive Timeouts.
|
60 |
|
|
//
|
61 |
|
|
// These four conditions are used as the interrupt sources. Interrupts are not
|
62 |
|
|
// generated for CTS Change-Of-State and Rx Errors because that information is
|
63 |
|
|
// either not useful (CTS) or reported for each received character (RERR). The
|
64 |
|
|
// interrupt flags generated by this module must be combined externally to form
|
65 |
|
|
// an interrupt request to the client.
|
66 |
|
|
//
|
67 |
|
|
// The interrupt flags will be reset/cleared as indicated below except when the
|
68 |
|
|
// rst/clr pulse is coincident with the pulse which would set the flag, the
|
69 |
|
|
// flag remains set so that the new assertion pulse is not lost.
|
70 |
|
|
//
|
71 |
|
|
// There remains a small probability that the second pulse may be lost. This
|
72 |
|
|
// can be remedied by stretching the setting pulse to a width equal to the un-
|
73 |
|
|
// certainty between the setting and resetting pulses: approximately 4 clock
|
74 |
|
|
// cycles when re1ce modules are used to generate the Clr_Int pulse.
|
75 |
|
|
//
|
76 |
|
|
// Dependencies: redet.v, fedet.v
|
77 |
|
|
//
|
78 |
|
|
// Revision History:
|
79 |
|
|
//
|
80 |
|
|
// 0.01 08E15 MAM File Created
|
81 |
|
|
//
|
82 |
|
|
// 1.00 08G24 MAM Corrected the reset function for the four flags.
|
83 |
|
|
// The previous implementation would not reset or
|
84 |
|
|
// allow the flags to be initialized to the "Off"
|
85 |
|
|
// state. Added the RF_EF as a port, and added a
|
86 |
|
|
// rising edge detector on the RF_EF to reset the
|
87 |
|
|
// RTO flag.
|
88 |
|
|
//
|
89 |
|
|
// 1.10 08H10 MAM Changed the reset logic for the iTFE and iTHF
|
90 |
|
|
// so that they remain set until read by the host.
|
91 |
|
|
//
|
92 |
|
|
// 2.00 11B06 MAM Converted to Verilog 2001.
|
93 |
|
|
//
|
94 |
|
|
// 2.10 13G12 MAM Corrected an error regarding the clearing of the
|
95 |
|
|
// interrupt flag bits. Required a change to the
|
96 |
|
|
// USR in module SSP_UART: USR needed to be registered
|
97 |
|
|
// whenever a read operation was performed. The result-
|
98 |
|
|
// ing difference between the interrupt flags in the
|
99 |
|
|
// UART clock domain, and the corresponding USR bits in
|
100 |
|
|
// the SCK domain preserve the interrupt bits until the
|
101 |
|
|
// user has had a chance to read the interrupt flag.
|
102 |
|
|
// Also renamed to iRDA flag to iRHF which is more
|
103 |
|
|
// appropriate since the flag is set only on the rising
|
104 |
|
|
// edge of the RX FIFO Half Full flag.
|
105 |
|
|
//
|
106 |
|
|
// Additional Comments:
|
107 |
|
|
//
|
108 |
|
|
// The interrupt flags are set and reset under a variety of conditions.
|
109 |
|
|
//
|
110 |
|
|
// iTFE - Set on the rising edge of the Transmit FIFO Empty Flag (TF_EF)
|
111 |
|
|
// Rst on Clr_Int.
|
112 |
|
|
//
|
113 |
|
|
// iTHE - Set on the falling edge of Transmit FIFO Half Full (TF_HF)
|
114 |
|
|
// Rst on Clr_Int.
|
115 |
|
|
//
|
116 |
|
|
// iRHF - Set on the rising edge of Receive FIFO Half Full (RF_HF)
|
117 |
|
|
// Rst on Clr_Int or on the falling edge of RF_HF.
|
118 |
|
|
//
|
119 |
|
|
// iRTO - Set on the rising edge of RTO
|
120 |
|
|
// Rst on Clr_Int.
|
121 |
|
|
//
|
122 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
123 |
|
|
|
124 |
|
|
module UART_INT(
|
125 |
|
|
input Rst, // Reset
|
126 |
|
|
input Clk, // Clock
|
127 |
|
|
|
128 |
|
|
input TF_HF, // Transmit FIFO Half-Full Flag
|
129 |
|
|
input TF_EF, // Transmit FIFO Empty Flag
|
130 |
|
|
input RF_HF, // Receive FIFO Half-Full Flag
|
131 |
|
|
input RF_EF, // Receive FIFO Empty Flag
|
132 |
|
|
|
133 |
|
|
input RTO, // Receiver Timeout
|
134 |
|
|
|
135 |
|
|
input Clr_Int, // Clear interrupt pulse
|
136 |
|
|
input [3:0] USR, // USR: {iRTO, iRHF, iTHE, iTFE}
|
137 |
|
|
|
138 |
|
|
output reg iTFE, // Interrupt - Tx FIFO Empty
|
139 |
|
|
output reg iTHE, // Interrupt - Tx FIFO Half Empty
|
140 |
|
|
output reg iRHF, // Interrupt - Rx FIFO Half Full
|
141 |
|
|
output reg iRTO // Interrupt - Receive Time Out Detected
|
142 |
|
|
);
|
143 |
|
|
|
144 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
145 |
|
|
//
|
146 |
|
|
// Local Signal Declarations
|
147 |
|
|
//
|
148 |
|
|
|
149 |
|
|
wire reTF_EF, feTF_HF;
|
150 |
|
|
wire reRF_HF, feRF_HF, reRF_EF;
|
151 |
|
|
wire reRTO;
|
152 |
|
|
|
153 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
154 |
|
|
//
|
155 |
|
|
// Implementation
|
156 |
|
|
//
|
157 |
|
|
|
158 |
|
|
redet RE1 (.rst(Rst), .clk(Clk), .din(TF_EF), .pls(reTF_EF));
|
159 |
|
|
fedet FE1 (.rst(Rst), .clk(Clk), .din(TF_HF), .pls(feTF_HF));
|
160 |
|
|
|
161 |
|
|
redet RE2 (.rst(Rst), .clk(Clk), .din(RF_HF), .pls(reRF_HF));
|
162 |
|
|
fedet FE2 (.rst(Rst), .clk(Clk), .din(RF_HF), .pls(feRF_HF));
|
163 |
|
|
redet RE3 (.rst(Rst), .clk(Clk), .din(RF_EF), .pls(reRF_EF));
|
164 |
|
|
|
165 |
|
|
redet RE4 (.rst(Rst), .clk(Clk), .din(RTO), .pls(reRTO));
|
166 |
|
|
|
167 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
168 |
|
|
//
|
169 |
|
|
// Transmit FIFO Empty Interrupt Flag
|
170 |
|
|
//
|
171 |
|
|
|
172 |
|
|
assign Rst_iTFE = Rst | (iTFE & Clr_Int & USR[0]);
|
173 |
|
|
|
174 |
|
|
always @(posedge Clk or posedge reTF_EF)
|
175 |
|
|
begin
|
176 |
|
|
if(reTF_EF)
|
177 |
|
|
iTFE <= #1 1;
|
178 |
|
|
else if(Rst_iTFE)
|
179 |
|
|
iTFE <= #1 reTF_EF;
|
180 |
|
|
end
|
181 |
|
|
|
182 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
183 |
|
|
//
|
184 |
|
|
// Transmit FIFO Half Empty Interrupt Flag
|
185 |
|
|
//
|
186 |
|
|
|
187 |
|
|
assign Rst_iTHE = Rst | (iTHE & Clr_Int & USR[1]);
|
188 |
|
|
|
189 |
|
|
always @(posedge Clk or posedge feTF_HF)
|
190 |
|
|
begin
|
191 |
|
|
if(feTF_HF)
|
192 |
|
|
iTHE <= #1 1;
|
193 |
|
|
else if(Rst_iTHE)
|
194 |
|
|
iTHE <= #1 feTF_HF;
|
195 |
|
|
end
|
196 |
|
|
|
197 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
198 |
|
|
//
|
199 |
|
|
// Receive Data Available Interrupt Flag
|
200 |
|
|
//
|
201 |
|
|
|
202 |
|
|
assign Rst_iRHF = Rst | (iRHF & (Clr_Int | feRF_HF | reRF_EF) & USR[2]);
|
203 |
|
|
|
204 |
|
|
always @(posedge Clk or posedge reRF_HF)
|
205 |
|
|
begin
|
206 |
|
|
if(reRF_HF)
|
207 |
|
|
iRHF <= #1 1;
|
208 |
|
|
else if(Rst_iRHF)
|
209 |
|
|
iRHF <= #1 reRF_HF;
|
210 |
|
|
end
|
211 |
|
|
|
212 |
|
|
///////////////////////////////////////////////////////////////////////////////
|
213 |
|
|
//
|
214 |
|
|
// Receive Timeout Interrupt Flag
|
215 |
|
|
//
|
216 |
|
|
|
217 |
|
|
assign Rst_iRTO = Rst | (iRTO & Clr_Int & USR[3]);
|
218 |
|
|
|
219 |
|
|
always @(posedge Clk or posedge reRTO)
|
220 |
|
|
begin
|
221 |
|
|
if(reRTO)
|
222 |
|
|
iRTO <= #1 1;
|
223 |
|
|
else if(Rst_iRTO)
|
224 |
|
|
iRTO <= #1 reRTO;
|
225 |
|
|
end
|
226 |
|
|
|
227 |
|
|
endmodule
|