1 |
2 |
dgisselq |
\documentclass{gqtekspec}
|
2 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
3 |
|
|
%%
|
4 |
|
|
%% Filename: spec.tex
|
5 |
|
|
%%
|
6 |
|
|
%% Project: wbuart32, a full featured UART with simulator
|
7 |
|
|
%%
|
8 |
|
|
%% Purpose: To describe, for LaTeX, how to build the specification file
|
9 |
|
|
%% for the wbuart32 core(s). This file is not nearly as
|
10 |
|
|
%% interesting as the file it creates, so I suggest you read spec.pdf
|
11 |
|
|
%% first, before deciding you are really interested in this file.
|
12 |
|
|
%%
|
13 |
|
|
%% Creator: Dan Gisselquist, Ph.D.
|
14 |
|
|
%% Gisselquist Technology, LLC
|
15 |
|
|
%%
|
16 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
17 |
|
|
%%
|
18 |
|
|
%% Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
19 |
|
|
%%
|
20 |
|
|
%% This program is free software (firmware): you can redistribute it and/or
|
21 |
|
|
%% modify it under the terms of the GNU General Public License as published
|
22 |
|
|
%% by the Free Software Foundation, either version 3 of the License, or (at
|
23 |
|
|
%% your option) any later version.
|
24 |
|
|
%%
|
25 |
|
|
%% This program is distributed in the hope that it will be useful, but WITHOUT
|
26 |
|
|
%% ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
27 |
|
|
%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
28 |
|
|
%% for more details.
|
29 |
|
|
%%
|
30 |
|
|
%% You should have received a copy of the GNU General Public License along
|
31 |
|
|
%% with this program. (It's in the $(ROOT)/doc directory, run make with no
|
32 |
|
|
%% target there if the PDF file isn't present.) If not, see
|
33 |
|
|
%% <http://www.gnu.org/licenses/> for a copy.
|
34 |
|
|
%%
|
35 |
|
|
%% License: GPL, v3, as defined and found on www.gnu.org,
|
36 |
|
|
%% http://www.gnu.org/licenses/gpl.html
|
37 |
|
|
%%
|
38 |
|
|
%%
|
39 |
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
40 |
|
|
%%
|
41 |
|
|
%%
|
42 |
|
|
\usepackage{import}
|
43 |
|
|
\usepackage{bytefield}
|
44 |
|
|
\usepackage{amsmath}
|
45 |
|
|
\project{WBUART32}
|
46 |
|
|
\title{Specification}
|
47 |
|
|
\author{Dan Gisselquist, Ph.D.}
|
48 |
5 |
dgisselq |
\email{dgisselq (at) ieee.org}
|
49 |
2 |
dgisselq |
\revision{Rev.~0.1}
|
50 |
|
|
\begin{document}
|
51 |
|
|
\pagestyle{gqtekspecplain}
|
52 |
|
|
\titlepage
|
53 |
|
|
\begin{license}
|
54 |
5 |
dgisselq |
Copyright (C) 2016--2017, Gisselquist Technology, LLC.
|
55 |
2 |
dgisselq |
|
56 |
|
|
This project is free software (firmware): you can redistribute it and/or
|
57 |
|
|
modify it under the terms of the GNU General Public License as published
|
58 |
|
|
by the Free Software Foundation, either version 3 of the License, or (at
|
59 |
|
|
your option) any later version.
|
60 |
|
|
|
61 |
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
62 |
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
63 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
64 |
|
|
for more details.
|
65 |
|
|
|
66 |
|
|
You should have received a copy of the GNU General Public License along
|
67 |
|
|
with this program. If not, see \texttt{http://www.gnu.org/licenses/} for a copy.
|
68 |
|
|
\end{license}
|
69 |
|
|
\begin{revisionhistory}
|
70 |
5 |
dgisselq |
0.2 & 1/03/2017 & D. Gisselquist & Added test-bench information\\\hline
|
71 |
2 |
dgisselq |
0.1 & 8/26/2016 & D. Gisselquist & Initial Draft Specification\\\hline
|
72 |
|
|
\end{revisionhistory}
|
73 |
|
|
% Revision History
|
74 |
|
|
% Table of Contents, named Contents
|
75 |
|
|
\tableofcontents
|
76 |
|
|
\listoffigures
|
77 |
|
|
\listoftables
|
78 |
|
|
\begin{preface}
|
79 |
|
|
It may be that building a UART is a mandatory coming of age task for any HDL
|
80 |
|
|
designer. The task is simple, easy, and there's not all that much to it.
|
81 |
|
|
This project comes out of some of my first experiences with Verilog.
|
82 |
|
|
|
83 |
5 |
dgisselq |
Since then, it has been augmented with quite a few useful capabilities for
|
84 |
2 |
dgisselq |
simulating a UART connection when using Verilator. It is this, perhaps
|
85 |
|
|
unusual, addition to the core set that makes this core worth taking note of.
|
86 |
|
|
|
87 |
|
|
I hope you find it useful.
|
88 |
|
|
\end{preface}
|
89 |
|
|
|
90 |
|
|
\chapter{Introduction}\label{ch:intro}
|
91 |
|
|
\pagenumbering{arabic}
|
92 |
|
|
\setcounter{page}{1}
|
93 |
|
|
%
|
94 |
|
|
% Introduction
|
95 |
|
|
%
|
96 |
|
|
% This section contains the introduction to the core, describing both its
|
97 |
|
|
% use and its features.
|
98 |
|
|
%
|
99 |
|
|
|
100 |
|
|
% What is old
|
101 |
|
|
The Universal Asynchronous Serial Transport, or UART, has become quite the
|
102 |
|
|
common protocol between devices. It is simple to wire up, easy to use, and
|
103 |
|
|
easy to process. This core provides one implementation of the logic necessary
|
104 |
|
|
to use such a communications scheme.
|
105 |
|
|
|
106 |
|
|
% What does the old lack?
|
107 |
|
|
% What is new
|
108 |
|
|
% What does the new have that the old lacks
|
109 |
|
|
% What performance gain can be expected?
|
110 |
|
|
|
111 |
|
|
While you are likely to find many UART examples out there, this particular
|
112 |
|
|
UART implementation offers something many of these other examples do not: a
|
113 |
|
|
Verilator simulation capability. This will allow the user to connect, via
|
114 |
|
|
a TCP/IP port or a telnet application, to the UART of their desired chip. As
|
115 |
|
|
a result, full two-way interaction can be had between a simulation and a
|
116 |
|
|
terminal or other port. Indeed, this may even be sufficient to connect a
|
117 |
|
|
CPU, capable of running Linux, to a terminal to verify that yes it can truly
|
118 |
|
|
run Linux--all within Verilator.
|
119 |
|
|
|
120 |
5 |
dgisselq |
As a final addition, there are three files in the test bench section which can
|
121 |
|
|
be used as top--level design files to prove whether or not the serial port on
|
122 |
|
|
a given circuit board works.
|
123 |
|
|
|
124 |
2 |
dgisselq |
\chapter{Architecture}\label{ch:arch}
|
125 |
|
|
|
126 |
5 |
dgisselq |
The HDL portion of the core itself consists of four basic files: {\tt rxuart.v},
|
127 |
|
|
{\tt txuart.v}, {\tt ufifo.v} and {\tt wbuart.v}. These are, respectively, the
|
128 |
|
|
receive UART code, the transmit UART code, a fairly generic FIFO, and a fully
|
129 |
|
|
wishbone compliant UART peripheral. This latter files demonstrates one example
|
130 |
|
|
of how the receiver, transmitter, and FIFOs may be connected to a Wishbone bus.
|
131 |
|
|
A fifth file, {\tt wbuart-insert.v}, demonstrates how the {\tt rxuart.v} and
|
132 |
|
|
{\tt txuart.v} files may be included into a module implementing a simpler
|
133 |
|
|
interface.
|
134 |
2 |
dgisselq |
|
135 |
|
|
Each of the core files, {\tt rxuart.v} and {\tt txuart.v}, are fully capable.
|
136 |
|
|
They each accept a 29--bit setup value specifying baud rate, the number of bits
|
137 |
|
|
per byte (between 5 and 8), whether or not parity is used, whether that parity
|
138 |
|
|
is even, odd, or fixed mark or fixed space. This setup register will be
|
139 |
|
|
discussed further in Chap.\ref{ch:registers}.
|
140 |
|
|
|
141 |
|
|
A further note on the {\tt rxuart.v} module is in order. This module double
|
142 |
|
|
latches the input, in the proper two buffer fashion to avoid problems with
|
143 |
|
|
metastability. Then, upon the detection of the start bit (i.e. a high to low
|
144 |
|
|
transition), the port waits a half of a baud, and then starts its baud clock
|
145 |
|
|
so as to sample in the middle of every baud following. The result of this is
|
146 |
|
|
a timing requirement: after $N+2$ baud intervals ($N+3$ if parity is used),
|
147 |
|
|
where $N$ is the number of bits per byte, this calculated middle sample must
|
148 |
|
|
still lie within the associated bit period. This leaves us with the criteria
|
149 |
|
|
that,
|
150 |
|
|
\begin{eqnarray}
|
151 |
|
|
\left|\left(N+2\right)
|
152 |
|
|
\left(\frac{f_{\mbox{\tiny SYS}}}{f_{\mbox{\tiny BAUD}}}
|
153 |
|
|
-{\mbox{\tt CKS}}\right)\right|
|
154 |
|
|
&<& \frac{f_{\mbox{\tiny SYS}}}{2f_{\mbox{\tiny BAUD}}},
|
155 |
|
|
\label{eqn:baudlimit}.
|
156 |
|
|
\end{eqnarray}
|
157 |
|
|
where $f_{\mbox{\tiny SYS}}$ is the system clock frequency,
|
158 |
|
|
$f_{\mbox{\tiny BAUD}}$ is the baud rate or frequency,
|
159 |
|
|
{\tt CKS} is the number of clocks per baud as set in the configuration
|
160 |
|
|
register, and $N$ is the number of bits per byte. What this means is that,
|
161 |
|
|
for transmission rates where $f_{\mbox{\tiny BAUD}}$ approaches
|
162 |
|
|
$f_{\mbox{\tiny SYS}}$, the number of data rates that can actually be
|
163 |
|
|
synthesized becomes limited.
|
164 |
|
|
|
165 |
|
|
Connecting to either {\tt txuart.v} or {\tt rxuart.v} is quite simple. Both
|
166 |
|
|
files have a data port and a strobe. To transmit, set the data and strobe
|
167 |
|
|
lines. Drop the strobe line as soon as the strobe is asserted and the busy line
|
168 |
5 |
dgisselq |
is not.
|
169 |
|
|
Likewise, to connect to the {\tt rxuart.v} port, there is a data
|
170 |
|
|
and a strobe. This time, though, these two wires are outputs of the receive
|
171 |
|
|
module as opposed to inputs.
|
172 |
2 |
dgisselq |
When the strobe is high, the data is valid. It will only be high for one
|
173 |
|
|
clock period. If you wish to connect this output to a bus, a register will be
|
174 |
|
|
needed to hold the strobe high until the data is read. Also, while the strobe
|
175 |
5 |
dgisselq |
is high, the {\tt o\_frame\_err} will indicate whether or not there was a
|
176 |
2 |
dgisselq |
framing error (i.e., no stop bit), and {\tt o\_parity\_err} will indicate
|
177 |
5 |
dgisselq |
whether or not the parity matched. Finally, the {\tt o\_break} line will
|
178 |
|
|
indicate whether the receiver is in a ``break'' state,
|
179 |
2 |
dgisselq |
|
180 |
|
|
The {\tt tx\_busy} line may be inverted and connected to a transmit interrupt
|
181 |
|
|
line. In a similar fashion, the {\tt rx\_stb} line, or the bus equivalent of
|
182 |
5 |
dgisselq |
{\tt rx\_ready}, may be used for receive interrupt lines--although it will need
|
183 |
|
|
to be latched as both {\tt wbuart.v} and {\tt wbuart-insert.v} demonstrate.
|
184 |
2 |
dgisselq |
|
185 |
5 |
dgisselq |
An simple example of how to put this configuration together is found in
|
186 |
2 |
dgisselq |
{\tt wbuart-insert.v}. In this example given, the {\tt rx\_data} register
|
187 |
|
|
will have only the lower eight bits set if the data is valid, higher bits will
|
188 |
|
|
be set upon error conditions, and cleared automatically upon the next byte read.
|
189 |
|
|
In a similar fashion, the {\tt tx\_data} register can be written to with a byte
|
190 |
|
|
in order to transmit that byte. Writing bit nine will place the transmitter
|
191 |
|
|
into a ``break'' condition, only cleared by writing a zero to that bit later.
|
192 |
|
|
Reading from the {\tt tx\_data} register can also be used to determine if the
|
193 |
|
|
transmitter is busy (via polling), whether it is currently in a break condition,
|
194 |
|
|
or even what bit is currently being placed to the output port.
|
195 |
|
|
|
196 |
5 |
dgisselq |
A more comprehensive example of how these UART modules may be used together
|
197 |
|
|
can be found in {\tt wbuart.v}. This file provides a full wishbone interface
|
198 |
|
|
allowing interaction with the core using four registers: a setup register,
|
199 |
|
|
receive register and transmit register as before, as well as a FIFO health
|
200 |
|
|
register through which the size and fill of the FIFO can be queried.
|
201 |
|
|
|
202 |
2 |
dgisselq |
The C++ simulation portion of the code revolves around the file
|
203 |
|
|
{\tt bench/cpp/uartsim.cpp} and its associated header. This file defines a
|
204 |
|
|
class, {\tt UARTSIM}, which can be used to connect the UART to a TCP/IP stream.
|
205 |
|
|
When initialized, this class takes, as input, the TCP/IP port number that the
|
206 |
5 |
dgisselq |
class is to connect with. Setting the port to zero connects the UART to
|
207 |
|
|
the standard input and output file facilities. Once connected, using this
|
208 |
|
|
simulator is as simple as calculating the receive input bit from the transmit
|
209 |
|
|
output bit when the clock is low, and the core takes care of everything else.
|
210 |
2 |
dgisselq |
|
211 |
5 |
dgisselq |
Finally, there are a series of example files found in the bench/verilog
|
212 |
|
|
directory. {\tt helloworld.v} presents an example of a simple UART transmitter
|
213 |
6 |
dgisselq |
sending the ``Hello, World {\textbackslash}r{\textbackslash}n'' message over
|
214 |
|
|
and over again. This example
|
215 |
5 |
dgisselq |
uses only the {\tt txuart.v} module, and can be simulated in Verilator.
|
216 |
|
|
A second test file, {\tt linetest.v}, works by waiting for a line of data to be
|
217 |
|
|
received, after which it parrots that line back to the terminal. This tests
|
218 |
|
|
both {\tt txuart.v} and {\tt rxuart.v}. A third test file, {\tt speechfifo.v}
|
219 |
|
|
tests both the wishbone interface as well as the FIFO, by filling the UART,
|
220 |
|
|
10~samples at a time, with text from Abraham Lincoln's Gettysburg address.
|
221 |
|
|
All three of these files have an internal option to define
|
222 |
|
|
{\tt OPT\_STANDALONE}. If and when defined, they may be used as top--level
|
223 |
|
|
files as part of a UART test.
|
224 |
|
|
|
225 |
2 |
dgisselq |
\chapter{Operation}\label{ch:ops}
|
226 |
|
|
|
227 |
|
|
% This section describes the operation of the core. Specific sequences, such
|
228 |
|
|
% as startup sequences, as well as the modes and states of the block should be
|
229 |
|
|
% described.
|
230 |
|
|
%
|
231 |
|
|
|
232 |
|
|
To use the core, a couple of steps are required. First, wire it up. The
|
233 |
5 |
dgisselq |
{\tt rxuart.v} and {\tt txuart.v} files may be wired up for use individually,
|
234 |
|
|
or using an example such as {\tt wbuart-insert.v}. Alternatively, the
|
235 |
|
|
{\tt wbuart.v} file may be connected to a straight 32--bit wishbone bus.
|
236 |
|
|
Second, set the UART configuration register. This is ideally set by setting
|
237 |
|
|
the {\tt INITIAL\_SETUP} parameter of {\tt rxuart}, {\tt txuart} or even
|
238 |
|
|
{\tt wbuart.v} Alternatively, you can write to the setup register at a later
|
239 |
|
|
time, as is done with the {\tt speechfifo.v} bench test.
|
240 |
2 |
dgisselq |
|
241 |
5 |
dgisselq |
From a simulation standpoint, it will also need to be ``wired'' up in your
|
242 |
|
|
C++ main Verilator file. Somewhere, internal to the top--level Verilator
|
243 |
|
|
C++ simulation file, you'll want to have some setup lines similar to,
|
244 |
2 |
dgisselq |
\begin{tabbing}
|
245 |
5 |
dgisselq |
\hbox to 3.0in{\tt \#include "uartsim.h"} \= {\em // Tell compiler about UARTSIM}\\
|
246 |
|
|
\vdots \\
|
247 |
|
|
{\tt UARTSIM *uartsim;} \> {\em // Declare a variable to hold the simulator}\\
|
248 |
|
|
{\tt uartsim = new UARTSIM(ip\_port);} \> {\em // Create/initialize it with your TCP/IP port \#} \\
|
249 |
|
|
{\tt uartsim->setup(setup\_register\_value);} \> {\em // Tell it the line coding to expect}\\
|
250 |
|
|
\end{tabbing}
|
251 |
|
|
and then another set of lines within your clocked section that look something
|
252 |
|
|
like,
|
253 |
|
|
\begin{tabbing}
|
254 |
2 |
dgisselq |
{\tt if (!clk)} \= \\
|
255 |
5 |
dgisselq |
\> {\tt tb->i\_uart\_rx} {\tt = } {\tt uartsim(tb->o\_uart\_tx);}
|
256 |
2 |
dgisselq |
\end{tabbing}
|
257 |
5 |
dgisselq |
You should be able to find several examples of this in the {\tt helloworld.cpp},
|
258 |
|
|
{\tt linetest.cpp}, and {\tt speechtest.cpp} files. These C++ implementations,
|
259 |
|
|
though, are also complicated by the need for a self--contained testing program
|
260 |
|
|
to be able to capture and know what was placed onto the standard input and
|
261 |
|
|
output streams, hence many of them fork() into two processes so that one
|
262 |
|
|
process can verify the output of the other. Both {\tt speechtest.cpp} and
|
263 |
|
|
{\tt linetest.cpp} allow a {\em -i} option to run in an interactive mode without
|
264 |
|
|
forking. Either way, forking the simulation program shouldn't be needed for
|
265 |
|
|
normal usages of these techniques, but you may find it helpful to know should
|
266 |
|
|
you examine this code or should you wish to build your own test file that
|
267 |
|
|
proves its own output.
|
268 |
2 |
dgisselq |
|
269 |
|
|
To use the transmitter, set the {\tt i\_stb} and {\tt i\_data} wires. Drop
|
270 |
|
|
the strobe line any time after {\tt (i\_stb)\&\&(!o\_busy)}.
|
271 |
|
|
|
272 |
|
|
To use the receiver, grab the data any time {\tt o\_stb} is true.
|
273 |
|
|
|
274 |
|
|
From the standpoint of the bus, there are two ways to handle receiving and
|
275 |
|
|
transmitting: polling and interrupt based, although both work one character at
|
276 |
5 |
dgisselq |
a time. To poll, repeatedly read the receive data register until only bits from
|
277 |
|
|
the bottom eight are set. This is an indication that the byte is
|
278 |
2 |
dgisselq |
valid. Alternatively, you could wait until the an interrupt line is set and
|
279 |
5 |
dgisselq |
then read. In the {\tt wbuart-insert.v} example as well as the {\tt wbuart.v}
|
280 |
|
|
implementation, the {\tt o\_uart\_rx\_int} line will be set ({\tt rx\_int} for
|
281 |
|
|
{\tt wbuart-insert.v}), and automatically cleared upon any read. To write,
|
282 |
|
|
one can read from the transmit data register until the eighth bit, the
|
283 |
|
|
{\tt tx\_busy} bit, is cleared, and then transmit. Alternatively, this
|
284 |
|
|
negation of this bit may be connected to an interrupt line,
|
285 |
|
|
{\tt o\_uart\_tx\_int}. Writing to the port while the transmitter is idle will
|
286 |
|
|
start it transmitting. Writing to the port while it is busy will fill a one
|
287 |
|
|
word buffer that will get sent as soon as the port is idle for one clock.
|
288 |
2 |
dgisselq |
|
289 |
|
|
|
290 |
|
|
\chapter{Registers}\label{ch:registers}
|
291 |
|
|
% This section specifies all internal registers. It should completely cover
|
292 |
|
|
% the interface between the CPU and the host as seen from the software point
|
293 |
|
|
% of view.
|
294 |
|
|
|
295 |
|
|
% List of Registers
|
296 |
|
|
|
297 |
|
|
% Register 1 Description
|
298 |
|
|
%
|
299 |
|
|
% You shall choose the style of register you prefer. Do not use both options
|
300 |
|
|
% in one and the same document. (Table of bits, vs. byetarray type of
|
301 |
|
|
% description).
|
302 |
|
|
|
303 |
5 |
dgisselq |
The {\tt wbuart} core supports four registers, shown in Tbl.~\ref{tbl:reglist}.
|
304 |
|
|
\begin{table}\begin{center}\begin{reglist}
|
305 |
|
|
{\tt SETUP} & 2'b00 & 30 & R/W & UART configuration/setup register.\\\hline
|
306 |
|
|
{\tt FIFO} & 2'b01 & 32 & R & Returns size and status of the FIFOs\\\hline
|
307 |
|
|
{\tt RX\_DATA}& 2'b10 & 13 & R & Read data, reads from the UART.\\\hline
|
308 |
|
|
{\tt TX\_DATA}& 2'b11 & 15 & (R/)W & Transmit data: writes send out the UART.
|
309 |
|
|
\\\hline
|
310 |
2 |
dgisselq |
\end{reglist}\caption{UART Registers}\label{tbl:reglist}
|
311 |
|
|
\end{center}\end{table}
|
312 |
5 |
dgisselq |
We'll cover the format of all of these registers here, as they are defined by
|
313 |
|
|
{\tt wbuart.v}.
|
314 |
2 |
dgisselq |
|
315 |
|
|
\section{Setup Register}
|
316 |
|
|
The setup register is perhaps the most critical of all the registers. This
|
317 |
|
|
is shown in Fig.\ref{fig:SETUP}.
|
318 |
|
|
\begin{figure}\begin{center}
|
319 |
|
|
\begin{bytefield}[endianness=big]{32}
|
320 |
|
|
\bitheader{0-31}\\
|
321 |
|
|
\bitbox{2}{00}
|
322 |
|
|
\bitbox{2}{N}
|
323 |
|
|
\bitbox{1}{S}
|
324 |
|
|
\bitbox{1}{P}
|
325 |
|
|
\bitbox{1}{F}
|
326 |
|
|
\bitbox{1}{T}
|
327 |
|
|
\bitbox{24}{Baud CLKS}
|
328 |
|
|
\end{bytefield}
|
329 |
|
|
\caption{SETUP Register fields}\label{fig:SETUP}
|
330 |
|
|
\end{center}\end{figure}
|
331 |
|
|
It is designed so that, for any 8N1 protocol (eight data bits, no parity, one
|
332 |
5 |
dgisselq |
stop bit), all of the upper bits will be set to zero so that only the number of
|
333 |
|
|
clocks per baud interval needs to be set. The top two bits are unused, making
|
334 |
|
|
this a 30--bit number.\footnote{The top two bits are ideally suited for adding
|
335 |
|
|
in a user configurable hardware flow control: one for flow control in use, zero
|
336 |
|
|
otherwise, but this is only a future upgrade possibility as of this writing.}
|
337 |
|
|
The other fields are: $N$ sets the number of bits per word. A value of zero
|
338 |
|
|
corresponds to 8--bit words, a value of one to seven bit words, and so forth up
|
339 |
|
|
to a value of three for five bit words. $S$ determines the number of stop
|
340 |
|
|
bits. Set this to one for two stop bits, or leave it at zero for a single
|
341 |
|
|
stop bit. $P$ determines whether or not a parity bit is used (1~for parity,
|
342 |
|
|
0~for no parity), while $F$ determines whether or not the parity is fixed.
|
343 |
|
|
Tbl.~\ref{tbl:parity} lists out the various values possible here.
|
344 |
2 |
dgisselq |
\begin{table}\begin{center}
|
345 |
|
|
\begin{tabular}{ccc|l}
|
346 |
|
|
P&F&T&Setting \\\hline\hline
|
347 |
|
|
1 & 0 & 0 & Odd parity \\\hline
|
348 |
|
|
1 & 0 & 1 & Even parity \\\hline
|
349 |
|
|
1 & 1 & 0 & Parity bit is a Space (1'b0)\\\hline
|
350 |
|
|
1 & 1 & 1 & Parity bit is a Mark (1'b1)\\\hline
|
351 |
|
|
|
352 |
|
|
\end{tabular}\caption{Parity setup}\label{tbl:parity}
|
353 |
|
|
\end{center}\end{table}
|
354 |
|
|
|
355 |
6 |
dgisselq |
The final portion of this register is the baud {\tt CLKS}. This is the number
|
356 |
|
|
of ticks of your ssytem clock per baud interval,
|
357 |
|
|
\begin{eqnarray*}
|
358 |
|
|
{\tt CLKS} &=& \frac{f_{\mbox{\tiny SYS}}}{f_{\mbox{\tiny BAUD}}}.
|
359 |
|
|
\end{eqnarray*}
|
360 |
|
|
Rounding to the nearest integer is recommended. Hence, if you have a system
|
361 |
|
|
clock of 100~MHz and wish to achieve 115,200~Baud, you would set {\tt CLKS} to
|
362 |
|
|
\begin{eqnarray*}
|
363 |
|
|
{\tt CLKS}_{\tiny{\tt Example}} &=& \frac{100 \cdot 10^6}{115200}
|
364 |
|
|
\frac{\mbox{Clocks per Second}}{\mbox{Baud Intervals per Second}}
|
365 |
|
|
\approx 868 \mbox{ Clocks per Baud Interval}
|
366 |
|
|
\end{eqnarray*}
|
367 |
|
|
|
368 |
5 |
dgisselq |
Changes to this setup register will take place in the transmitter as soon as
|
369 |
|
|
the transmitter is idle and ready to accept another byte.
|
370 |
|
|
|
371 |
|
|
Changes to this setup register in {\tt rxuart.v} also take place between bytes.
|
372 |
|
|
However, within the {\tt wbuart.v} context, any changes to the setup register
|
373 |
|
|
will also reset the receiver and receive FIFO together. Once reset, the
|
374 |
|
|
receiver will insist on a minimum of sixteen idle baud intervals before
|
375 |
|
|
receiving the next byte.
|
376 |
|
|
|
377 |
|
|
\section{FIFO Register}
|
378 |
|
|
The FIFO register is a read--only register containing information about the
|
379 |
|
|
status of both receive and transmit FIFOs within it. The transmit FIFO
|
380 |
|
|
information is kept in the upper 16--bits, and the receiver FIFO information
|
381 |
|
|
in the lower 1-bits, as shown in Fig.~\ref{fig:FIFO}.
|
382 |
|
|
\begin{figure}\begin{center}
|
383 |
|
|
\begin{bytefield}[endianness=big]{32}
|
384 |
|
|
\bitheader{0-31}\\
|
385 |
|
|
\bitbox[rlt]{4}{LGLN}
|
386 |
|
|
\bitbox[rlt]{10}{TX Fill}
|
387 |
|
|
\bitbox[rlt]{1}{H}
|
388 |
|
|
\bitbox[rlt]{1}{Z}
|
389 |
|
|
\bitbox[rlt]{4}{}
|
390 |
|
|
\bitbox[rlt]{10}{}
|
391 |
|
|
\bitbox[rlt]{1}{}
|
392 |
|
|
\bitbox[rlt]{1}{} \\
|
393 |
|
|
\bitbox[rlb]{4}{}
|
394 |
|
|
\bitbox[rlb]{10}{}
|
395 |
|
|
\bitbox[rlb]{1}{}
|
396 |
|
|
\bitbox[rlb]{1}{}
|
397 |
|
|
\bitbox[rlb]{4}{LGLN}
|
398 |
|
|
\bitbox[rlb]{10}{RX Fill}
|
399 |
|
|
\bitbox[rlb]{1}{H}
|
400 |
|
|
\bitbox[rlb]{1}{Z} \\
|
401 |
|
|
\end{bytefield}
|
402 |
|
|
\caption{RXDATA Register fields}\label{fig:FIFO}
|
403 |
|
|
\end{center}\end{figure}
|
404 |
|
|
We'll discuss each of these bits individually.
|
405 |
|
|
|
406 |
|
|
The {\tt LGLN} field indicates the log base two of the FIFO length. Hence an
|
407 |
|
|
{\tt LGLN} field of four would indicate a FIFO length of sixteen values.
|
408 |
|
|
The FIFO fill indicates the current level of fill. The $H$ bit will be true
|
409 |
|
|
if the FIFO is half full, and the $Z$ bit will be true if the FIFO is non-empty.
|
410 |
|
|
|
411 |
|
|
The $H$ and $Z$ bits also mirror the interrupt bits generated by {\tt wbuart.v}.
|
412 |
|
|
Interrupts will be generated any time the FIFO is half full (on receive), or
|
413 |
|
|
less than half full (on transmit). The same logic applies for the $Z$ bit.
|
414 |
|
|
|
415 |
|
|
Writes to this register are quietly ignored.
|
416 |
|
|
|
417 |
2 |
dgisselq |
\section{RX\_DATA Register}
|
418 |
|
|
Fig.~\ref{fig:RXDATA}
|
419 |
|
|
\begin{figure}\begin{center}
|
420 |
|
|
\begin{bytefield}[endianness=big]{32}
|
421 |
|
|
\bitheader{0-31}\\
|
422 |
5 |
dgisselq |
\bitbox[rlt]{19}{19'h00}
|
423 |
|
|
\bitbox{1}{E}
|
424 |
|
|
\bitbox[rlt]{1}{B}
|
425 |
|
|
\bitbox[rlt]{1}{F}
|
426 |
|
|
\bitbox[rlt]{1}{P}
|
427 |
|
|
\bitbox[rlt]{1}{S}
|
428 |
|
|
\bitbox[rlt]{8}{RWORD} \\
|
429 |
|
|
\bitbox[lrb]{19}{}
|
430 |
|
|
\bitbox{1}{-}
|
431 |
|
|
\bitbox[lrb]{1}{}
|
432 |
|
|
\bitbox[lrb]{1}{}
|
433 |
|
|
\bitbox[lrb]{1}{}
|
434 |
|
|
\bitbox[lrb]{1}{}
|
435 |
|
|
\bitbox[lrb]{8}{}
|
436 |
2 |
dgisselq |
\end{bytefield}
|
437 |
|
|
\caption{RXDATA Register fields}\label{fig:RXDATA}
|
438 |
|
|
\end{center}\end{figure}
|
439 |
|
|
breaks out the various bit fields of the receive
|
440 |
5 |
dgisselq |
data register used in {\tt wbuart.v}. In particular, the $B$ field indicates
|
441 |
|
|
that the receive line is in a break condition. The $F$ and $P$ fields indicate
|
442 |
|
|
that a frame error or parity error has been detected. These bits are not self
|
443 |
|
|
clearing, but rather are cleared by writing to 1's to them. The $S$ field will
|
444 |
|
|
be false when the {\tt RWORD} is valid. Hence, if {\tt (RWORD \& ~0x0ff)} is
|
445 |
|
|
zero there is a word ready to be received without error.
|
446 |
2 |
dgisselq |
|
447 |
5 |
dgisselq |
The $E$ bit is an error bit. When set, it indicates that the FIFO has
|
448 |
|
|
overflowed sometime since the last reset. This bit is also a reset bit.
|
449 |
|
|
In other words, writing a {\tt 1'b0} to this bit will command a receive
|
450 |
|
|
reset: clearing the FIFO, and waiting for the line to be idle before receiving
|
451 |
|
|
another byte. This bit is not implemented in {\tt wbuart-insert.v}, but
|
452 |
|
|
exists in the {\tt wbuart.v} implementation.
|
453 |
|
|
|
454 |
2 |
dgisselq |
\section{TX\_DATA Register}
|
455 |
|
|
Fig.~\ref{fig:TXDATA}
|
456 |
|
|
\begin{figure}\begin{center}
|
457 |
|
|
\begin{bytefield}[endianness=big]{32}
|
458 |
|
|
\bitheader{0-31}\\
|
459 |
5 |
dgisselq |
\bitbox[lrt]{17}{17'h00}
|
460 |
|
|
\bitbox{1}{H}
|
461 |
|
|
\bitbox{1}{Z}
|
462 |
|
|
\bitbox{1}{E}
|
463 |
|
|
\bitbox[lrt]{1}{C}
|
464 |
|
|
\bitbox[lrt]{1}{O}
|
465 |
|
|
\bitbox[lrt]{1}{B}
|
466 |
|
|
\bitbox[lrt]{1}{S}
|
467 |
|
|
\bitbox[lrt]{8}{TWORD} \\
|
468 |
|
|
\bitbox[lrb]{17}{}
|
469 |
|
|
\bitbox{3}{3'h0}
|
470 |
|
|
\bitbox[lrb]{1}{}
|
471 |
|
|
\bitbox[lrb]{1}{}
|
472 |
|
|
\bitbox[lrb]{1}{}
|
473 |
|
|
\bitbox[lrb]{1}{}
|
474 |
|
|
\bitbox[lrb]{8}{}
|
475 |
2 |
dgisselq |
\end{bytefield}
|
476 |
|
|
\caption{TXDATA Register fields}\label{fig:TXDATA}
|
477 |
|
|
\end{center}\end{figure}
|
478 |
|
|
breaks out the various bit fields of the transmit data register used in
|
479 |
5 |
dgisselq |
{\tt wbuart.v}. The $C$ field indicates whether or not the receive
|
480 |
2 |
dgisselq |
data line is high or low, the $O$ field indicates the same for the transmit
|
481 |
5 |
dgisselq |
line. These aren't particularly useful or valuable, but the $C$ bit doesn't
|
482 |
|
|
fit in the receive data register since it would violate the error condition
|
483 |
|
|
detector. These two bits are thrown in here for whatever useful purpose one
|
484 |
|
|
might find. The $B$ field, when set, sends a break condition down the wire.
|
485 |
|
|
Further, writes to the TXDATA register while in a break condition and with the
|
486 |
|
|
$B$ field clear, will clear the transmitter from any break condition without
|
487 |
|
|
transmitting anything. The $S$ field is similar to the RXDATA strobe register.
|
488 |
|
|
It is a read--only bit that will be true any time the transmitter is busy.
|
489 |
|
|
It will be clear only when the transmitter is idle.
|
490 |
2 |
dgisselq |
|
491 |
5 |
dgisselq |
The final three bits, $H$, $Z$, and $E$, are present only in {\tt wbuart.v}.
|
492 |
|
|
These bits indicate $H$ if the FIFO is at least half full, $Z$ if the FIFO is
|
493 |
|
|
empty, and $E$ if the FIFO has experienced an overflow condition since the
|
494 |
|
|
last reset. Writing a {\tt 1'b1} to the $E$ bit will reset the transmit FIFO,
|
495 |
|
|
both clearing any error indication in the FIFO as well as clearing the FIFO
|
496 |
|
|
itself.
|
497 |
2 |
dgisselq |
|
498 |
5 |
dgisselq |
To use the transmitter, simply write a byte to the TXDATA register
|
499 |
|
|
with the upper 24--bits clear to transmit.
|
500 |
|
|
|
501 |
2 |
dgisselq |
\chapter{Clocks}\label{ch:clocks}
|
502 |
|
|
The UART has been tested with a clock as fast as 200~MHz
|
503 |
|
|
(Tbl.~\ref{tbl:clocks}).
|
504 |
|
|
\begin{table}\begin{center}
|
505 |
|
|
\begin{clocklist}
|
506 |
|
|
{\tt i\_clk} & (System) & 200~MHz & & System clock\\\hline
|
507 |
|
|
\end{clocklist}
|
508 |
|
|
\caption{Clock Requirements}\label{tbl:clocks}
|
509 |
|
|
\end{center}\end{table}
|
510 |
|
|
It should be able to use slower clocks, but only subject to the ability to
|
511 |
|
|
properly set the baud rate as shown in Eqn.~\eqref{eqn:baudlimit} on
|
512 |
|
|
Page~\pageref{eqn:baudlimit}.
|
513 |
|
|
|
514 |
|
|
I do not recommend using this core with a baud rate greater than a quarter
|
515 |
|
|
of the system clock rate.
|
516 |
|
|
|
517 |
|
|
% This section specifies all of the clocks. All clocks, clock domain passes
|
518 |
|
|
% and the clock relations should be described.
|
519 |
|
|
|
520 |
|
|
% Name | Source | Rates (MHz) | Remarks | Description
|
521 |
|
|
% | Max|Min|Resolution|
|
522 |
|
|
\chapter{Wishbone Datasheet}\label{ch:wishbone}
|
523 |
|
|
|
524 |
|
|
Tbl.~\ref{tbl:wishbone}
|
525 |
5 |
dgisselq |
\begin{table}[htbp]\begin{center}\begin{tabular}{|p{2.5in}|p{3.5in}|}\hline
|
526 |
|
|
\rowcolor[gray]{0.85} Description & Specification \\\hline\hline
|
527 |
2 |
dgisselq |
Revision level of wishbone & WB B4 spec \\\hline
|
528 |
|
|
Type of interface & Slave, Read/Write, pipeline reads supported \\\hline
|
529 |
|
|
Port size & 32--bit \\\hline
|
530 |
|
|
Port granularity & 32--bit \\\hline
|
531 |
|
|
Maximum Operand Size & 32--bit \\\hline
|
532 |
|
|
Data transfer ordering & (Irrelevant) \\\hline
|
533 |
|
|
Clock constraints & None.\\\hline
|
534 |
5 |
dgisselq |
Signal Names & \begin{tabular}{lll}
|
535 |
|
|
{\tt wbuart.v} & {\tt wbuart-insert.v} & WB Equivalent \\\hline
|
536 |
|
|
{\tt i\_clk} & {\tt i\_wb\_clk} & {\tt CLK\_I} \\
|
537 |
|
|
{\tt i\_rst} & & {\tt RST\_I} \\
|
538 |
|
|
{\tt i\_wb\_cyc} & {\tt i\_wb\_cyc} & {\tt CYC\_I} \\
|
539 |
|
|
{\tt i\_wb\_stb} & {\tt i\_wb\_stb} & {\tt STB\_I} \\
|
540 |
|
|
{\tt i\_wb\_we} & {\tt i\_wb\_we} & {\tt WE\_I} \\
|
541 |
|
|
{\tt i\_wb\_addr} & {\tt i\_wb\_addr} & {\tt ADR\_I} \\
|
542 |
|
|
{\tt i\_wb\_data} & {\tt i\_wb\_data} & {\tt DAT\_I} \\
|
543 |
|
|
{\tt o\_wb\_ack} & {\tt o\_wb\_ack} & {\tt ACK\_O} \\
|
544 |
|
|
{\tt o\_wb\_stall} & {\tt o\_wb\_stall} & {\tt STALL\_O} \\
|
545 |
|
|
{\tt o\_wb\_data} & {\tt o\_wb\_data} & {\tt DAT\_O}
|
546 |
2 |
dgisselq |
\end{tabular}\\\hline
|
547 |
5 |
dgisselq |
\end{tabular}
|
548 |
2 |
dgisselq |
\caption{Wishbone Datasheet}\label{tbl:wishbone}
|
549 |
|
|
\end{center}\end{table}
|
550 |
|
|
is required by the wishbone specification in order to declare the core as
|
551 |
|
|
wishbone compliant, and so it is included here. It references the connections
|
552 |
5 |
dgisselq |
used in {\tt wbuart.v} as well as those exemplified by {\tt wbuart-insert.v}.
|
553 |
|
|
The big thing to notice is that this core acts as a wishbone slave, and that
|
554 |
|
|
all accesses to the core registers are 32--bit reads and writes to this
|
555 |
|
|
interface---not the 8--bit reads or writes that might otherwise be expected.
|
556 |
2 |
dgisselq |
|
557 |
|
|
What this table doesn't show is that all accesses to the port take a single
|
558 |
5 |
dgisselq |
clock for {\tt wbuart-insert.v}, or two clocks for {\tt wbuart.v}. That is, if
|
559 |
|
|
the {\tt i\_wb\_stb} line is high on one clock, the {\tt i\_wb\_ack} line will
|
560 |
|
|
be high the next for single clock access, or the clock after that for two
|
561 |
|
|
clock access. Further, the {\tt o\_wb\_stall} line is tied to zero.
|
562 |
2 |
dgisselq |
|
563 |
|
|
Also, this particular wishbone implementation assumes that if {\tt i\_wb\_stb},
|
564 |
|
|
then {\tt i\_wb\_cyc} will be high as well. Hence it only checks whether or not
|
565 |
|
|
{\tt i\_wb\_stb} is true to determine if a transaction has taken place. If your
|
566 |
|
|
bus does not meet this requirement, you'll need to AND {\tt i\_wb\_stb} with
|
567 |
|
|
{\tt i\_wb\_cyc} before using the core.
|
568 |
|
|
|
569 |
|
|
\chapter{I/O Ports}\label{ch:ioports}
|
570 |
|
|
% This section specifies all of the core IO ports
|
571 |
|
|
|
572 |
5 |
dgisselq |
In it's simplest form, the UART offers simply two I/O ports: the
|
573 |
|
|
{\tt i\_uart\_rx} line to receive, and the {\tt o\_uart\_tx} line to transmit.
|
574 |
|
|
These lines need to be brought to the outside of your design. Within
|
575 |
|
|
Verilator, they need to be connected inside your Verilator test bench, as in:
|
576 |
2 |
dgisselq |
\begin{tabbing}
|
577 |
|
|
{\tt if (!clk)} \= \\
|
578 |
5 |
dgisselq |
\> {\tt tb->i\_uart\_rx} {\tt = } {\tt uartsim(tb->o\_uart\_tx);}
|
579 |
2 |
dgisselq |
\end{tabbing}
|
580 |
|
|
|
581 |
|
|
A more detailed discussion of the connections associated with these modules
|
582 |
5 |
dgisselq |
can begin with Tbl.~\ref{tbl:rxports},
|
583 |
2 |
dgisselq |
\begin{table}\begin{center}\begin{portlist}
|
584 |
|
|
{\tt i\_clk} & 1 & Input & The system clock \\\hline
|
585 |
|
|
{\tt i\_reset} & 1 & Input & A positive, synchronous reset \\\hline
|
586 |
|
|
{\tt i\_setup} & 30 & Input & The 30--bit setup register \\\hline
|
587 |
|
|
{\tt i\_uart} & 1 & Input & The input wire from the outside world. \\\hline
|
588 |
|
|
{\tt o\_wr} & 1 & Output & True if a word was received. At this time,
|
589 |
|
|
{\tt o\_data}, {\tt o\_break}, {\tt o\_parity\_err}, and
|
590 |
|
|
{\tt o\_frame\_err} will also be valid. \\\hline
|
591 |
|
|
{\tt o\_data} & 8 & Output & The received data, valid if {\tt o\_wr} \\\hline
|
592 |
|
|
{\tt o\_break} & 1 & Output & True in the case of a break condition \\\hline
|
593 |
|
|
{\tt o\_parity\_err} & 1 & Output & True if a parity error was detected \\\hline
|
594 |
|
|
{\tt o\_frame\_err} & 1 & Output & True if a frame error was detected \\\hline
|
595 |
|
|
{\tt o\_ck\_uart} & 1 & Output & A synchronized copy of {\tt i\_uart} \\\hline
|
596 |
|
|
\end{portlist}\caption{RXUART port list}\label{tbl:rxports}
|
597 |
|
|
\end{center}\end{table}
|
598 |
5 |
dgisselq |
detailing the I/O ports of the UART receiver, Tbl.~\ref{tbl:txports},
|
599 |
2 |
dgisselq |
\begin{table}\begin{center}\begin{portlist}
|
600 |
|
|
{\tt i\_clk} & 1 & Input & The system clock \\\hline
|
601 |
|
|
{\tt i\_reset} & 1 & Input & A positive, synchronous reset \\\hline
|
602 |
|
|
{\tt i\_setup} & 30 & Input & The 30--bit setup register \\\hline
|
603 |
|
|
{\tt i\_break} & 1 & Input & Set to true to place the transmit channel into a break condition\\\hline
|
604 |
|
|
{\tt i\_wr} & 1 & Input & An input strobe. Set to one when you wish to transmit data, clear once it has been accepted\\\hline
|
605 |
|
|
{\tt i\_data} & 8 & Input & The data to be transmitted, ignored unless
|
606 |
|
|
{\tt (i\_wr)\&\&(!o\_busy)} \\\hline
|
607 |
|
|
{\tt o\_uart} & 1 & Output & The wire to be connected to the external port\\\hline
|
608 |
|
|
{\tt o\_busy} & 1 & Output & True if the transmitter is busy, false if it will receive data\\\hline
|
609 |
|
|
\end{portlist}\caption{TXUART port list}\label{tbl:txports}
|
610 |
|
|
\end{center}\end{table}
|
611 |
5 |
dgisselq |
detailing the I/O ports of the UART transmitter, and Tbl.~\ref{tbl:wbports}
|
612 |
|
|
\begin{table}\begin{center}\begin{tabular}{|p{1.15in}|p{0.1in}|p{0.75in}|p{3.375in}|}
|
613 |
|
|
\rowcolor[gray]{0.85} Port & W & Direction & Description \\\hline\hline
|
614 |
|
|
{\tt i\_uart\_rx}& 1 & Input & The receive wire coming from the external port\\\hline
|
615 |
|
|
{\tt o\_uart\_tx}& 1 & Output & The transmit wire to be connected to the external port\\\hline
|
616 |
|
|
{\tt o\_uart\_rx\_int} & 1 & Output & True if a byte may be read from the receiver\\\hline
|
617 |
|
|
{\tt o\_uart\_tx\_int} & 1 & Output & True if the transmitter is idle\\\hline
|
618 |
|
|
{\tt o\_uart\_rxfifo\_int}&1& Output & True if the receive FIFO is half full\\\hline
|
619 |
|
|
{\tt o\_uart\_txfifo\_int}&1& Output & True if the transmit FIFO is half empty\\\hline
|
620 |
|
|
\end{tabular}\caption{WBUART port list}\label{tbl:wbports}
|
621 |
|
|
\end{center}\end{table}
|
622 |
|
|
detailing the non--wishbone I/O ports of the wishbone controller.
|
623 |
2 |
dgisselq |
|
624 |
|
|
% Appendices
|
625 |
|
|
% A. May be added to outline different specifications. (??)
|
626 |
|
|
|
627 |
|
|
|
628 |
|
|
% Index
|
629 |
|
|
\end{document}
|
630 |
|
|
|
631 |
|
|
|