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

Subversion Repositories wbuart32

[/] [wbuart32/] [trunk/] [doc/] [src/] [spec.tex] - Blame information for rev 18

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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