OpenCores
URL https://opencores.org/ocsvn/m16c5x/m16c5x/trunk

Subversion Repositories m16c5x

[/] [m16c5x/] [trunk/] [RTL/] [Src/] [UART_RTO.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
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:     06:50:40 06/14/2008 
45
// Design Name:     Synchronous Serial Peripheral (SSP) Interface UART 
46
// Module Name:     ../VerilogCoponentsLib/SSP_UART/UART_RTO.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: This module implements a receive timeout timer which sets a
52
//              flag to indicate that the timeout occured. The flag is cleared
53
//              by reset or by the reading of the Receive Holding Register.
54
//
55
//              The Receive Timeout Val should be set by the client module to a
56
//              value which corresponds to the desired timeout value in terms
57
//              of the number of bit times. This module scales the 16x bit rate
58
//              clock enable by 16 to set the internal bit rate clock enable.
59
//              The client module provide the character frame length and the 
60
//              number of characters to delay. The character frame length
61
//              varies as a function of the frame format, e.g. 8N1, 8E2, or
62
//              7O1. The number of characters to delay for the timeout is a
63
//              fixed number of character periods, e.g. 3, in most cases. The
64
//              module allows these values to be independently specified.
65
//              
66
//
67
// Dependencies:    none
68
//
69
// Revision History:
70
//
71
//  0.01    08E14   MAM     File Created
72
//
73
//  1.00    08E14   MAM     Initial Release
74
//
75
//  1.10    08E14   MAM     Changed the input parameters to have two delay 
76
//                          parameters: CCntVal - character length; and
77
//                                      RTOVal  - # characters to delay.
78
//                          The result is a faster implementation, and one
79
//                          the RTOVal can usually be set as a constant.
80
//
81
//  1.11    08E15   MAM     Changed Module Name
82
//
83
//  2.00    11B06   MAM     Converted to Verilog 2001.
84
//
85
// Additional Comments:
86
//
87
///////////////////////////////////////////////////////////////////////////////
88
 
89
module UART_RTO(
90
    input   Rst,
91
    input   Clk,
92
 
93
    input   CE_16x,
94
 
95
    input   WE_RHR,
96
    input   RE_RHR,
97
 
98
    input   [3:0] CCntVal,
99
    input   [3:0] RTOVal,
100
 
101
    output  reg RcvTimeout
102
);
103
 
104
///////////////////////////////////////////////////////////////////////////////
105
//
106
//  Local Signal Declarations
107
//
108
 
109
    wire    Clr_RTOArm;
110
    reg     RTOArm;
111
 
112
    wire    Clr_BCnt;
113
    reg     [3:0] BCnt;
114
    reg     TC_BCnt;
115
 
116
    wire    Clr_CCnt;
117
    reg     [3:0] CCnt;
118
    reg     TC_CCnt;
119
 
120
    wire    Clr_RTOCnt, CE_RTOCnt;
121
    reg     [3:0] RTOCnt;
122
    reg     TC_RTOCnt;
123
 
124
    wire    Clr_RTO, CE_RTO;
125
 
126
///////////////////////////////////////////////////////////////////////////////
127
//
128
//  Implementation
129
//
130
//  RTO Arm FF
131
//      Armed with each received character, cleared by Rst, RE_RHR, or timeout
132
//
133
 
134
assign Clr_RTOArm = RE_RHR | CE_RTO;
135
 
136
always @(posedge Clk)
137
begin
138
    if(Rst)
139
        RTOArm <= #1 0;
140
    else if(Clr_RTOArm)
141
        RTOArm <= #1 0;
142
    else if(WE_RHR)
143
        RTOArm <= #1 1;
144
end
145
 
146
///////////////////////////////////////////////////////////////////////////////
147
//
148
//  Bit Rate Divider
149
//      Held in reset until RTO Armed or if Rst asserted
150
//
151
 
152
assign Clr_BCnt = Rst | WE_RHR | Clr_RTOArm | ~RTOArm;
153
 
154
always @(posedge Clk)
155
begin
156
    if(Clr_BCnt)
157
        BCnt <= #1 0;
158
    else if(CE_16x)
159
        BCnt <= #1 BCnt + 1;
160
end
161
 
162
always @(posedge Clk)
163
begin
164
    if(Clr_BCnt)
165
        TC_BCnt <= #1 0;
166
    else if(CE_16x)
167
        TC_BCnt <= #1 (BCnt == 4'b1110);
168
end
169
 
170
///////////////////////////////////////////////////////////////////////////////
171
//
172
//  Character Frame Divider
173
//      Held in reset until RTO Armed or if Rst asserted
174
//
175
 
176
assign Clr_CCnt = Clr_BCnt;
177
assign CE_CCnt = CE_16x & TC_BCnt;
178
 
179
always @(posedge Clk)
180
begin
181
    if(Clr_CCnt)
182
        CCnt <= #1 CCntVal;
183
    else if(CE_CCnt)
184
        CCnt <= #1 ((TC_CCnt) ? CCntVal : CCnt - 1);
185
end
186
 
187
always @(posedge Clk)
188
begin
189
    if(Clr_CCnt)
190
        TC_CCnt <= #1 0;
191
    else if(CE_16x)
192
        TC_CCnt <= #1 (CCnt == 0);
193
end
194
 
195
///////////////////////////////////////////////////////////////////////////////   
196
//
197
//  Receive Timeout Counter
198
//      Held in reset until RTO Armed or if Rst asserted
199
//      Counts bit periods when RTO Armed
200
 
201
assign Clr_RTOCnt = Clr_BCnt;
202
assign CE_RTOCnt  = CE_16x & TC_BCnt & TC_CCnt;
203
 
204
always @(posedge Clk)
205
begin
206
    if(Clr_RTOCnt)
207
        RTOCnt <= #1 RTOVal;
208
    else if(CE_RTOCnt)
209
        RTOCnt <= #1 ((TC_RTOCnt) ? RTOVal : RTOCnt - 1);
210
end
211
 
212
always @(posedge Clk)
213
begin
214
    if(Clr_RTOCnt)
215
        TC_RTOCnt <= #1 0;
216
    else if(CE_16x)
217
        TC_RTOCnt <= #1 (RTOCnt == 0);
218
end
219
 
220
///////////////////////////////////////////////////////////////////////////////
221
//
222
//  Receive Timeout Latch
223
//      Cleared by Rst or any read of the RHR
224
//      Set by RTOCnt terminal count
225
 
226
assign Clr_RTO = RE_RHR;
227
assign CE_RTO  = CE_16x & TC_BCnt & TC_CCnt & TC_RTOCnt;
228
 
229
always @(posedge Clk)
230
begin
231
    if(Rst)
232
        RcvTimeout <= #1 0;
233
    else if(Clr_RTO)
234
        RcvTimeout <= #1 0;
235
    else if(CE_RTO)
236
        RcvTimeout <= #1 1;
237
end
238
 
239
endmodule

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.