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

Subversion Repositories openarty

[/] [openarty/] [trunk/] [doc/] [src/] [spec.tex] - Blame information for rev 55

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:     OpenArty, an entirely open SoC based upon the Arty platform
7
%%
8
%% Purpose:
9
%%
10
%% Creator:     Dan Gisselquist, Ph.D.
11
%%              Gisselquist Technology, LLC
12
%%
13
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
%%
15
%% Copyright (C) 2015-2016, Gisselquist Technology, LLC
16
%%
17
%% This program is free software (firmware): you can redistribute it and/or
18
%% modify it under the terms of  the GNU General Public License as published
19
%% by the Free Software Foundation, either version 3 of the License, or (at
20
%% your option) any later version.
21
%%
22
%% This program is distributed in the hope that it will be useful, but WITHOUT
23
%% ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
24
%% FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
25
%% for more details.
26
%%
27
%% You should have received a copy of the GNU General Public License along
28
%% with this program.  (It's in the $(ROOT)/doc directory, run make with no
29
%% target there if the PDF file isn't present.)  If not, see
30
%% <http://www.gnu.org/licenses/> for a copy.
31
%%
32
%% License:     GPL, v3, as defined and found on www.gnu.org,
33
%%              http://www.gnu.org/licenses/gpl.html
34
%%
35
%%
36
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37
%%
38
%%
39
\usepackage{import}
40
\usepackage{bytefield}
41 48 dgisselq
\usepackage{listings}
42 2 dgisselq
\project{OpenArty}
43
\title{Specification}
44
\author{Dan Gisselquist, Ph.D.}
45 48 dgisselq
\email{dgisselq (at)  ieee.org}
46 2 dgisselq
\revision{Rev.~0.0}
47
\begin{document}
48
\pagestyle{gqtekspecplain}
49
\titlepage
50
\begin{license}
51
Copyright (C) \theyear\today, Gisselquist Technology, LLC
52
 
53
This project is free software (firmware): you can redistribute it and/or
54
modify it under the terms of  the GNU General Public License as published
55
by the Free Software Foundation, either version 3 of the License, or (at
56
your option) any later version.
57
 
58
This program is distributed in the hope that it will be useful, but WITHOUT
59
ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
60
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
61
for more details.
62
 
63
You should have received a copy of the GNU General Public License along
64
with this program.  If not, see \texttt{http://www.gnu.org/licenses/} for a copy.
65
\end{license}
66
\begin{revisionhistory}
67 36 dgisselq
0.0 &  6/20/2016 & Gisselquist & First Draft \\\hline
68
0.0 & 10/21/2016 & Gisselquist & More Comments Added\\\hline
69 48 dgisselq
0.0 & 11/18/2016 & Gisselquist & Added a getting started section\\\hline
70 2 dgisselq
\end{revisionhistory}
71
% Revision History
72
% Table of Contents, named Contents
73
\tableofcontents
74
\listoffigures
75
\listoftables
76
\begin{preface}
77
\end{preface}
78
 
79 36 dgisselq
\chapter{Introduction}\label{ch:intro}
80 2 dgisselq
\pagenumbering{arabic}
81
\setcounter{page}{1}
82
 
83 48 dgisselq
At {\$ 99}, the Arty is a very economical FPGA platform for doing
84
a lot of things.  It was designed to support the MicroBlaze soft CPU platform,
85
and as a result it has a lot more memory plus ethernet support.  Put together,
86
it feels like it was designed for soft--core CPU development.  Indeed, it has
87
an amazing capability for its price.
88
 
89
Instructions and examples for using the Arty, however, tend to focus on
90
schematic design development techniques.  While these may seem like an
91
appropriate way to introduce a beginner to hardware design, these techniques
92
introduce a whole host of problems.
93
 
94
The first and perhaps biggest problem is that it can be difficult to trouble
95
shoot what is going on.  This is a combination of two factors.  The first is
96
that many of the reference schematic designs make use of proprietary IP.  In
97
an effort to protect both their IP and themselves, companies providing such
98
IP resources often make them opaque, and difficult to see the internals of.
99
As a result, it can be difficult to understand why that IP isn't working in
100
your design.  Further, while many simulation tools exist, only the Xilinx tools
101
will allow full simulation of Xilinx proprietary IP.  Finally, while it may be
102
simple to select a part and ``wire'' it up within a schematic, most IP
103
components have many, many configuration options which are then hidden from the
104
user within the simplified component.  These options may be the difference
105
between successfully using the component and an exercise in frustration.
106
Put together, all of these features of schematic design make the design more
107
difficult to troubleshoot, and often even impossible to troubleshoot using
108
open source tools such as Verilator.
109
 
110
Another problem is that schematic based designs often hide their FPGA resource
111
usage.  They can easily become resource hogs, leaving the designer unaware
112
of the consequences of what he/she is implementing.  As an example, the memory
113
interface generated by Xilinx's Memory Interface Generator (MIG) consumes
114
nearly a full quarter of the Arty's FPGA resources, while delaying responses
115
to requests by upwards of 250~ns.  Further, while Xilinx touts its MicroBlaze
116
processor as only using 800--2500 LUTs, the MicroBlaze architecture requires
117
it be connected to four separate AXI busses, with each of those having
118
five channels, all with their requests and acknowledgement flags.  These
119
can therefore easily consume all of the resources within an architecture, before
120
providing any of the benefit the designer was looking for when they chose to
121
use an FPGA.
122
 
123
 
124 2 dgisselq
% What is old
125 48 dgisselq
%       Arty, XuLA, Learnables using schematic drawing techniques
126 2 dgisselq
% What does the old lack?
127
%       Arty lacks open interfaces, instead using MIG and CoreGen w/ AXI bus
128
% What is new
129
%       OpenArty has its own memory interface controller, and runs everything
130
%       off of an open Wishbone bus structure.
131
% What does the new have that the old lacks
132
%
133
% What performance gain can be expected?
134
%
135
 
136 48 dgisselq
Here in this project, we present another alternative.
137
 
138
First, the OpenArty is entirely built in Verilog, and (with the exception of
139
the MIG controller), it is entirely buit out of OpenSource IP.\footnote{I'm
140
still hoping to place an open memory controller into this design.  This
141
controller is written in logic, but does not yet connect to any hardware ports.}
142
 
143
Second, configuration options, such as cache sizes, can be fine tuned via a
144
CPU options file.
145
 
146
Third, as you will find from examining the RTL sources, this project uses only
147
one bus, and that bus has ony one channel associated with it: a Wishbone Bus.
148
This helps to limit the logic associated with trying to read and write from
149
the CPU, although it may increase problems with fanout.
150
 
151
Finally, because the OpenArty project is made from open source components, the
152
entire design, together with several of its peripherals, can be simulated using
153
Verilator.  This makes it possible to run programs on the ZipCPU within the
154
OpenArty design, and find and examine where such programs (or their peripherals)
155
fail.
156
 
157
Overall, the goals of this OpenArty project include:
158 2 dgisselq
\begin{enumerate}
159
\item Use entirely open interfaces
160
 
161
        This means not using the Memory Interface Generator (MIG), the
162 48 dgisselq
        Xilinx CoreGen IP, etc.
163 2 dgisselq
 
164 48 dgisselq
        (This goal has not yet been achieved.)
165
 
166
\item Use all of Arty's on--board hardware: Flash, DDR3-SDRAM, Ethernet, and
167
        everything else at their full and fastest speed(s).  For example, the
168
        flash will need to be clocked at 82~MHz, not the 50~MHz I've clocked
169
        it at in previous projects.  The DDR3 SDRAM memory should also be able
170
        to support pipelined 32--bit interactions over the Wishbone bus at a
171
        162~MHz clock.  Finally, the Ethernet controller should be supported
172
        by a DMA capable interface that can drive the ethernet at its full
173
        100Mbps rate.
174
 
175
        (Of these, only the ethernet goal has been met.)
176
 
177
\item Run using a 162.5~MHz system clock, if for no other reason than to gain
178
        the experience of building logic that can run that fast.\footnote{The
179 30 dgisselq
        original goal was to run at 200~MHz.  However, the memory controller
180 48 dgisselq
        cannot run faster than about 82~MHz.  If we run it at 81.25~MHz and
181
        double that clock to get our logic clock, that now places us at
182
        162.5~MHz.  200~MHz is \ldots too fast for DDR3 transfers using the
183
        Artix--7 chip on the Arty.}
184 2 dgisselq
 
185 48 dgisselq
        While the wishbone bus has been upgraded so that it may run at
186
        200~MHz, the CPU and memory controller cannot handle this speed (yet).
187
 
188 2 dgisselq
\item Modify the ZipCPU to support an MMU and a data cache, and perhaps even
189
        a floating point unit.
190
 
191 48 dgisselq
        (These are still in development.)
192
 
193
\item The default configuration will also include four Pmods: a USBUART,
194
        a GPS, an SDCard, and an OLEDrgb.
195
 
196
        (These have all been tested, and are known to work.)
197 2 dgisselq
\end{enumerate}
198
 
199
I intend to demonstrate this project with a couple programs:
200
\begin{enumerate}
201 48 dgisselq
\item An NTP Server
202 36 dgisselq
 
203 48 dgisselq
        While the GPS tracking circuit is in place, and while it appears to be
204
        able to track a GPS signal to within about 100ns or so, the
205
        network stack has yet to be built.
206
 
207
\item A ZipOS that can actually load and run programs from the SD Card, rather
208
        than just a static memory image stored in flash on start-up.
209
 
210 36 dgisselq
        This will require a functioning memory management unit (MMU), which
211
        will be a new addition to the ZipCPU created to support this project.
212 48 dgisselq
 
213 36 dgisselq
        For those not familiar with MMU's, an MMU translates memory addresses
214
        from a virtual address space to a physical address space.  This allows
215
        every program running on the ZipCPU to believe that they own the entire
216
        memory address space, while allowing the operating system to allocate
217
        actual physical memory addresses as necessary to support whatever
218
        program needs more (or less) memory.
219 48 dgisselq
 
220
        At this point, the MMU has been written and has passed its bench
221
        testing phase.  It has not (yet) been integrated with the CPU.
222 2 dgisselq
\end{enumerate}
223
 
224
 
225 48 dgisselq
\chapter{Getting Started}\label{ch:getting-started}
226
\section{Building the Core}
227
%
228
\section{Building the board support files}
229
The OpenArty project comes with a series of board support programs that are
230
designed to run from a Linux command line.  The C++ source code for these
231
programs can be found in the sw/host directory.  These programs have two
232
dependencies: the ZipCPU load program depends upon libelf, and the ZipCPU
233
debugger depends upon the ncurses library.  If you have these two libraries,
234 55 dgisselq
your build should proceed without problems.  If now, you may get them simply
235
by ussuing a:
236
\begin{lstlisting}[language=bash]
237
% sudo apt-get install ncurses-dev libelf-dev texinfo
238
\end{lstlisting}
239 2 dgisselq
 
240 55 dgisselq
 
241 48 dgisselq
% TODO: Remove the dependency on ZIPD.
242 36 dgisselq
 
243 48 dgisselq
A make in the sw/host directory should build all of these support programs.
244
These include:
245
\begin{itemize}
246
\item {\tt wbregs}: a program to read and write addresses on the wishbone bus,
247
        and hence to test peripherals independent of the CPU.
248
\item {\tt netuart}: a program to convert the UART device provided by the board
249
        to a TCP/IP device that can be connected to anywhere.
250
\item {\tt wbsettime}: a simple program to set the time on the real-time clock
251
        core within the board.
252
\item {\tt dumpflash}: reads the current contents from the flash memory into a
253
        local file
254
\item {\tt wbprogram}: programs new configuations into the flash
255
\item {\tt netsetup}: reads and decodes the MDIO interface from the ethernet
256
        PHY controller
257
\item {\tt manping}: pings a computer using the ethernet packet interface.
258
        This program does not have any ARP handling, so while it will wait
259
        for a reply, the reply typically comes back in the form of an ARP
260
        request rather than the ping response.
261
\item {\tt zipload}: Loads a program onto the ZipCPU, adjusting flash, block
262
        RAM, and or SDRAM memory to do so.  May also start the program running
263
        if requested.
264
\item {\tt zipstate}: Returns information about whether or not the CPU is
265
        running, is running in user mode, is waiting for an interrupt,
266
        has halted, etc.
267
\item {\tt zipdbg}: a debugger with the capability to halt, reset and step
268
        the CPU, as well as to inspect the state of the CPU following any
269
        unexpected halt.
270
\end{itemize}
271 36 dgisselq
 
272 55 dgisselq
\section{Building the Verilator Simulation}
273
If you are at all interested in building the verilator simulation, you will
274
also need Verilator and GTKMM-3.0.  To get these, you may type:
275
\begin{lstlisting}[language=bash]
276
% sudo apt-get install verilator libgtkmm-3.0-dev
277
\end{lstlisting}
278
At this point, a {\tt make} in the {\tt rtl} directory, followed by a
279
{\tt make} in the {\tt bench/cpp} directory will build a Verilator simulation
280
named {\tt busmaster\_tb}.  You may run this program in place of {\tt netuart},
281
and then access the simulated Arty using the regular board support packages.
282
This simulation will use the TCP/IP port given in {\tt bench/cpp/port.h}, which
283
should be set identically to the port given in {\tt sw/host/port.h} used by
284
{\tt netuart}.
285 48 dgisselq
 
286
 
287 55 dgisselq
 
288
 
289 48 dgisselq
\section{Initially installing the core}
290
The OpenArty core may be installed onto the board via the Xilinx Hardware
291
Manager.  If properly set up, you should be able to open the hardware
292
manager after you build an initial bit stream, open the Arty, select the
293
toplevel bit file, and request Xilinx to load the file.
294
 
295
If you are successful, the four color LEDs will blank while the hardware
296
manager is loading the hardware, and then turn to varying intensities of red.
297
 
298
\section{Connecting the PMods}
299
The OpenArty project is designed to work with four PMods: PModUSBUART,
300
PModGPS, PModSD, and PModOLEDrgb.  These four provide the device with
301
serial port access, absolute time and position information, access to an
302
SD card, and the ability to control a small display.
303
 
304
If you do not have any of these devices, and wish to recover the logic used
305
by them, you may comment out the defines for {\tt GPS\_CLOCK},
306
{\tt SDCARD\_ACCESS}, and {\tt OLEDRGBACCESS} found in the {\tt rtl/busmaster.v}
307
file.  This will recover all but the logic used by the PModUSBUART and PModGPS
308
serial ports, while replacing the registers with read--only memory values of
309
zero.
310
 
311 49 dgisselq
The {\tt arty.xdc} file is designed so that these PMods can be connected as
312
shown in Fig.~\ref{fig:pmod-pic}.
313
\begin{figure}\begin{center}
314
\includegraphics[width=4in]{../gfx/openarty.eps}
315
\caption{Showing how the PMods are Connected}\label{fig:pmod-pic}
316
\end{center}\end{figure}
317
In this example, the PModOLED is connected to PMod port JB, and the PModSD is
318
connected to PMod port JD.  Both the PModGPS and the PModUSBUART are both
319
connected to port JC, with the GPS connected on top and the USBUART on the
320
bottom.
321 48 dgisselq
 
322
\section{Testing the peripherals}
323
OpenArty has been designed so that all of the peripherals live on a
324
memory--mapped wishbone bus.  This bus can be accessed, either by the ZipCPU
325
or by the host controller.  Because of this model, peripherals may be tested
326
and known to work before the CPU is ever turned on.  Two programs make this
327
possible: netuart and wbregs.  Other programs may be built upon this model,
328
as long as they access the bus using the interface outlined in devbus.h.
329
 
330
Of the two programs, netuart simply turns the USB serial port interface of
331
the device into a TCP/IP interface.  Netuart takes one argument, the
332
name of the serial port device which the Arty USB driver has created.  In
333
my case, this tends to be /dev/ttyUSB1, although it has been known to change
334
from time to time:
335
 
336
\begin{lstlisting}[language=bash]
337
% netuart /dev/ttyUSB1
338
\end{lstlisting}
339
 
340
All of the other board support files connect to the TCP/IP port generated
341
by netuart.  The port.h file is a compiled-in file, outlining where this
342
port can be found.  By default, netuart listens to port {\tt 6510} on
343
{\tt localhost}, but it can be configured to listen to any port.  The other
344
board support files will try to connect to netuart at the host and port
345
listed in port.h.  Hence, if properly configured, you should be able to
346
access your Arty to command it, configure it, reload it, etc., from anywhere
347
you have internet access--in my case, from anywhere in the house.
348
 
349
Once you run netuart, you should then be able to watch, as a part of the
350
standard output stream of netuart, all of the interaction with the board.
351
While this may be useful for debugging, it's not all that legible to the
352
user.   Lines that start with \hbox{``\#''} are lines from the device that are not
353
going to any client.  A common line you will see is \hbox{``\# 0''}.  This is
354
just the device saying that its command capability is idle.  Lines that start
355
with \hbox{``< ''} are commands going to the device, and lines starting with
356
\hbox{``> ''} are responses from the core.  So, at this point, run netuart and
357
wait a couple of seconds.  If you do not see a \hbox{``\# 0''} line, then try a
358
different serial port, check that your core is properly configured, etc.  Once
359
you do see a \hbox{``\# 0''} line, then you are ready for the next step.
360
 
361
The easiest way to test the peripherals is via the wbregs command.  This
362
command is similar to the ancient peek and poke commands.  It takes one
363
or two arguments.  If given one argument, it reads from that address on the
364
bus.  If given two arguments, it writes the value of the second argument to
365
the bus location given by the first argument.  Hence one argument peeks
366
at the memory bus, two arguments pokes a value onto the memory bus.
367
 
368
Perhaps an example will help.  At this point, try typing:
369
 
370
\begin{lstlisting}[language=bash]
371
% wbregs version
372
\end{lstlisting}
373
 
374
This should return and print a 32-bit hexadecimal value to your screen,
375
indicating the date of when you last ran make in the root directory before
376
building and installing your configuration into the device.  This can be
377
very useful to know what configuration you are running, and whether or not
378
you have made the changes you thought you had made.
379
 
380
You may have noticed that wbregs read from address 0x0100, but did so by name.
381
Most of the peripherals have names for their addresses.  The C language
382
names for these addresses can be found in regdefs.h, and a mapping to
383
wbregs address names can be found in regdefs.cpp.
384
 
385
Shall we try another?  Let's try adjusting the LEDs.  To turn all the LEDs off,
386
\begin{lstlisting}[language=bash]
387
% wbregs leds 0x0f0
388
\end{lstlisting}
389
To turn them all back on again,
390
\begin{lstlisting}[language=bash]
391
% wbregs leds 0x0ff
392
\end{lstlisting}
393
To turn the low order LED off without changing any others, write
394
\begin{lstlisting}[language=bash]
395
% wbregs leds 0x010
396
\end{lstlisting}
397
 
398
Having fun?  Try running the program startupex.sh from the sw directory.
399
This will set some LEDs and Color LEDs in a fun, startup--looking, pattern.
400
 
401
Ready to test the UART?   Using minicom, connect to the PModUSBUART.  It
402
should also be connected to a /dev/ttyUSBx serial port device.  If you aren't
403
sure, start minicom with:
404
\begin{lstlisting}[language=bash]
405
% minicom -D /dev/ttyUSB2
406
\end{lstlisting}
407
Then, configure minicom to use 115,200 Baud, 8-data bits, one stop bit, and
408
no parity.
409
 
410
Once you've done that, we can test it by sending a character across the UART
411
port:
412
\begin{lstlisting}[language=bash]
413
% wbregs tx 90
414
\end{lstlisting}
415
This should send a `Z' over the UART port.  Did you see a `Z' in minicom?
416
If not, did you set the baud rate right?  The UART is supposed to be set
417
for 115,200 Baud, 8N1 by default.  If not, you can set it to that by writing
418
wbregs setup 705.  The 705 comes from the clock rate, in Hz, divided by
419
115200.  By leaving other higher order bits at zero, this becomes the default
420
baud rate of an 8N1 serial port channel.
421
 
422
Another fun program to run is {\tt netsetup}.  This program takes no arguments,
423
and just reads and decodes the network registers via the MDIO port.  The
424
decoded result will be sent to the screen.
425
 
426
\section{Subsequent Core Updates}
427
The board support file {\tt wbprogram} can be used to write .bit or .bin
428
files to the flash, so that the core can be updated once an initial core
429
is installed and running.
430
Although wbprogram expects the filename to end in either '.bit' or '.bin',
431
this is primarily to keep a user from doing something they don't intend to
432
do.
433
 
434
The basic usage of the wbprogram command is:
435
\begin{lstlisting}[language=bash]
436
% wbprogram [@address] file
437
\end{lstlisting}
438
wbprogram then copies the file to the flash, starting at the Arty address
439
of {\tt @address}.  If no address is given, wbprogram writes the file at the
440
beginning of flash.
441
 
442
An example of how to do this can be found in the {\tt program.sh}.
443
{\tt program.sh} places the new configuration file into the alternate
444
configuration location.  (An alternate script, zprog.sh, places the new
445
configuration at the beginning of the flash, where the FPGA loader will look
446
for it upon power up.)  Once {\tt program.sh} places the new configuration
447
into flash, it then commands the FPGA via the ICAPE2 interface and an IPROG
448
command to reconfigure itself using this new configuration.  As a result, this
449
can be used to load subsequent configurations into the FLASH.
450
 
451
\section{Building the ZipCPU tool-chain}
452
At this point, you should have some confidence that your configuration and
453
hardware are working.  Therefore, let's transition to getting the ZipCPU
454 55 dgisselq
on the hardware up and running.
455
To do this, we'll start with getting a copy
456 48 dgisselq
of the ZipCPU toolchain and building it.  Pick a directory to work in, and
457
then issue:
458
\begin{lstlisting}[language=bash]
459
% git clone https://github.com/ZipCPU/zipcpu
460
\end{lstlisting}
461 55 dgisselq
to get a copy of the ZipCPU project, together with toolchain.  You'll also
462
need to double check that you have the pre-requisite packages to build this
463
tool chain, so on an Ubuntu~14 machine you would issue:
464 48 dgisselq
\begin{lstlisting}[language=bash]
465 55 dgisselq
% sudo apt-get install flex bison libbison-dev
466
% sudo apt-get install libgmp10 libgmp-dev libmpfr-dev libmpc-dev libelf-dev
467
% sudo apt-get install libisl-dev
468
\end{lstlisting}
469
Once these are all in place, you can then switch to the master ZipCPU
470
directory and type,
471
\begin{lstlisting}[language=bash]
472 48 dgisselq
% cd zipcpu; make
473
\end{lstlisting}
474
(you may need to issue the make command a couple of times \ldots)
475
 
476
This will build the GCC compiler for the ZipCPU from source.
477
It will also install this new compiler into the zipcpu/sw/install/cross-tools.
478
This new compiler will be called zip-gcc.
479
 
480
This will also build a copy of the binutils programs for the ZipCPU.  These
481
include the assembler, {\tt zip-gas}, linker, {\tt zip-ld}, disassembler,
482
{\tt zip-objdump}, and many more useful programs.
483
 
484
The next step to using this toolchain is to place it into your path.
485
\begin{lstlisting}[language=bash]
486
% export PATH=$PATH:$PWD/zipcpu/install/cross-tools/bin
487
\end{lstlisting}
488
Once the toolchain is in your path,
489
\begin{lstlisting}[language=bash]
490
% which zip-gcc
491
/home/.../zipcpu/sw/install/cross-tools/bin/zip-gcc
492
\end{lstlisting}
493
should return the location of where this toolchain exists in your path.
494
 
495
\section{Building your first ZipCPU program}
496
Several example programs for the OpenArty project can be found in the
497
{\tt sw/board} directory.  These can be used to test various peripherals from
498
the perspective of the CPU itself.
499
 
500
As a test of the build process, a good first progam to build would be
501
{\tt exstartup}.  This program is very similar to the {\tt startupex.sh} shell
502
script you tried earlier.  It simply plays with the color LEDs and some
503
on board timers.   Once that is finished, it goes into a loop controlling
504
both the normal and the color LEDs based upon the button state and the switch
505
settings.
506
 
507
To build {\tt exstartup}, simply type {\tt make exstartup} from the
508
{\tt sw/board} directory of the {\tt openarty} project.  (Don't forget to
509
include the ZipCPU toolchain into your path before you do this!)
510
 
511
\section{Loading a program}
512
Now that you have built your {\tt exstartup} program, it's time to load it
513
onto the board and start it up.  The {\tt zipload} program can be used to
514
do this.  {\tt zipload} can be found in the sw/host directory.  To load a
515
ZipCPU program into the Arty, just type {\tt zipload} and the program name,
516
such as {\tt exstartup} in this case.  To start the program immediately
517
after loading it, pass the `-r' option to {\tt zipload}.  In our case, you
518
would type:
519
\begin{lstlisting}[language=bash]
520
% zipload -r exstartup
521
\end{lstlisting}
522
 
523
Hopefully, you can see the {\tt exstartup} program now toggling the LED's.
524
Once the initial display stops, you can adjust the switches and press buttons
525
to see how that affects the result.
526
 
527
If you wish to restart the {\tt exstartup} program, or indeed to run another
528
program, you can just run {\tt zipload} again with the new program name.  This
529
will halt the previous program, and then load the new one into memory.  As
530
before, if you use the `-r' option, the program will be started automatically.
531
 
532
\section{Some other test programs}
533
If you have the PModUSBUART, you might wish to try running a ``Hello, World''
534
program.  This can be found in the hello.c file.  It prints ``Hello, World''
535
to the PModUSBUART once every ten seconds.  Had enough of it?  You can stop
536
the CPU by typing {\tt wbregs cpu 0x0400}.  This sends a halt command to the
537
debug register of the ZipCPU.  More information about this debug register, and
538
other things that can be done via the debug register, can be found in the
539
ZipCPU specification.
540
 
541
If you have both the PModUSBUART as well as the PModGPS, the {\tt gpsdump.c}
542
program can be used to forward the NMEA stream from the GPS to the USBUART.
543
This should give you some confidence that the PModGPS is working.
544
 
545
As a third test, {\tt oledtest.c} will initialize the OLEDrgb device and cause
546
it to display one of two images in an alternating fashion.
547
 
548 36 dgisselq
\chapter{Architecture}\label{ch:architecture}
549
My philosophy in peripherals is to keep them simple.  If there is a default
550
mode on the peripheral, setting that mode should not require turning any bits
551
on.  If a peripheral encounters an error condition, a bit may be turned on to
552
indicate this fact, otherwise status bits will be left in the off position.
553
 
554
\subsection{Bus Structure}
555
The OpenArty project contains four bus masters, three of them within the CPU.
556
These masters are the instruction fetch unit, the data read/write unit,
557
and the direct memory access peripheral within the ZipCPU, as well as an
558
external debug port which can be commanded from over the main UART port
559
connecting the Arty to its host.
560
 
561
There is also a second minor peripheral bus located within the ZipCPU
562
ZipSystem.  This bus provides access to a number of peripherals within the
563
ZipSystem, such as timers, counters, and the direct memory access controller.
564
This bus will also be used to configure the memory management unit once
565
integrated.  This bus is only visible to the CPU, and located starting at
566
address {\tt 0xc0000000}.
567
 
568
The ZipCPU debug port is also available on the bus.  This port, however, is
569
only visible to the external debug port.  It can be found at address
570
{\tt 0x08000000} for the control register, and {\tt 0x08000001} for the
571
data register.
572
 
573
Once the MMU has been integrated, it will be placed between the instruction
574
fetch unit, data read/write unit, and the rest of the peripheral bus.
575
 
576
The actual bus chosen for this design is the Wishbone Bus, based upon the
577
pipeline mode defined in the B4 specification.  All optional wires required
578
by this bus structure have been removed, such as the tag lines, the cycle
579
type identifier, the burst type, and so forth.  This was done to simplify
580
the logic within the core.
581
 
582
However, because of the complicated bus structure--particularly because of the
583
number of masters and slaves on the bus and the speed for which the bus is
584
defined, there are a number of delays and arbiters placed on the bus.  As a
585
result, the stall wire which is supposed to be depend upon combinational logic
586
only, has been registered at a number of locations.  What this means is that
587
there are a variety of delays as commands propagate through the bus structure.
588
Most of these are variable, in that they can be turned on or off at build time,
589
or even that the stall line may (or may not) be registered as configured.
590
 
591
All interactions between bus masters and any peripherals passes through the
592
interconnect, located in {\tt busmaster.v}.  This interconnect divides the
593
slaves into separate groups.  The first group of slaves are those for which the
594
bus is supposed to provide fast access to.  These are the DDR3 SDRAM, the
595
flash, the block RAM, and the network.  The next group of slaves will have their
596
acknowledgements delayed by an additional clock.  The final group of slaves
597
are those single register slaves whose results may be known ahead of any read,
598
and who only require one clock to access.  These are grouped together and
599
controlled from within {\tt fastio.v}.
600
 
601
Further information about the Wishbone bus structure found within this core
602
can be found either on the Wishbone datasheet (Ch.~\ref{ch:wishbone}), or in
603
the memory map table in the Registers chapter (Ch.~\ref{ch:registers}).
604
 
605
\subsection{DDR3 SDRAM}
606
 
607
{\em It is the intention of this project to use a completely open source
608
DDR3 SDRAM controller.  While the controller has been written, it has yet to
609
be successfully connected to the physical pins of the port.  Until that time,
610
the design is running using a Wishbone to AXI bus bridge.  Memory may still
611
be read or written, after an initial pipeline delay of roughly 27~clocks per
612
access, at one access per clock.}
613
 
614
{\em The open source SDRAM controller should be able to achieve a delay closer
615
to 9~clocks per access--once I figure out how to connect it to the PHY.}
616
 
617
\subsection{Flash}
618
\subsection{Block RAM}
619
 
620
The block RAM on this board has been arranged into one 32kW section.
621
Programs that use block RAM will run fastest using the block RAM, both for
622
instructions as well as for memory.
623
 
624
\subsection{Ethernet}
625
 
626
The ether net controller has been split into three parts.  The first part is
627
an area of packet memory.  This part is simple: it acts like memory.  The
628
receive memory is read only, whereas the transmit memory is both read and
629
write.  Packets received by the controller will be found in the receive memory,
630
packets transmitted must be in the transmit area of memory.  The octets
631
may be found in memory with the first octet in the most significant byte.
632
This is the easy part.
633
 
634
The format of the packets within this memory is a touch more interesting.
635
With no options turned on, the first 6~bytes are the destination MAC
636
address, the next 6~bytes will be the source MAC address, and the {\em next
637
4~bytes} will be the EtherType repeated twice.  This was done to align the
638
packet, and particularly the IP header, onto word boundaries.  If the hardware
639
CRC has been turned off, the packet must contain its own CRC as well as
640
ensuring that it has a minimum packet length (64 octets) when including that
641
CRC.
642
 
643
With all options turned on, however, things are a touch simpler.  The first
644
two words of the packet contain the destination MAC (for a transmit packet)
645
or the source MAC (for a received packet), followed by the two--octet
646
EtherType.  At this point the packet is word--aligned prior to the IP header.
647
Since broadcast packets are sent to a special destination MAC other than
648
our own, a flag in the command register will indicate this fact.
649
 
650
 
651
The second part of the controller is the MDIO interface.  This follows from
652
the specification, and can be used to toggle the LED's on the ethernet,
653
to force the ethernet into a particular mode, either 10M or 100M, to control
654
auto--negotiation of the speed, and more.  Reads or writes to MDIO memory
655
addresses will command reads or writes via the MDIO port from the FPGA to the
656
ethernet PHY.  As the PHY can only handle 16--bit words, only 16~bits will
657
ever be transferred as a result of any read/write command, the top 16~bits
658
are automatically set to zero.  Further details of this capability may be
659
found within the specification for the chip.
660
 
661
The MDIO interface may be ignored.  If ignored, the defaults within the
662
interface will naturally set up the network connection in full duplex mode (if
663
your hardware supports it), at the highest speed the network will support.
664
However, if you ignore this interface you may not know what problems you are
665
suffering from this interface, if any.  The {\tt netsetup} program has been
666
provided, among the host software, to help diagnose how the various MDIO
667
registers have been set, and what the status is that is being reported from
668
the PHY.
669
 
670
The third part of the controller is the packet command interface.  This
671
consists of two command registers, one for reading and one for writing.
672
Before doing anything with the network, it must first be taken out of
673
reset.  According to the specification for the network chip, this must
674
happen a minimum of one second after power up.  This may be done by simply
675
writing to the transmit command register with the reset bit turned off.
676
 
677
To send a packet, simply write the number of octets in the packet to the
678
transmit control register and set the GO bit ({\tt 0x04000}).  Other bits
679
in this control register can be used to turn off the hardware MAC generation
680
(and removal upon receive), the hardware CRC checking, and/or the hardware
681
IP header checksum validation (but not generation).  The GO bit will remain
682
high while the packet is being sent, and only transition to low once the
683
packet is away.  While the packet is being sent, a zero may be written to the
684
command register to cancel the packet--although this is not recommended.
685
 
686
Packets are automatically received without intervention.  Once a packet has been
687
received, the available bit will be set in the receive command register and
688
a receive packet interrupt will be generated.  The ethernet port will then
689
halt/stall until a user has reset the receive interface so that it may
690
receive the next packet.  Without clearing this interface, the receive port
691
will not accept further packets.  Other status bits in this interface are
692
used to indicate whether packets have been missed (because the interface was
693
busy), or thrown out due to some error such as a CRC error or a more general
694
error.\footnote{It should be possible to extend this interface so that further
695
packets may be read as long as the memory isn't yet full.  This is left as an
696
exercise to others.}
697
 
698
\subsection{SD Card}
699
\subsection{GPS Tracking}
700
\subsection{Configuration port}
701
 
702
The registers associated with the ICAPE2 port have been made accessible
703
to the core via the {\tt wbicapetwo} core.  More information about the meaning
704
of these registers can be found in Xilinx's ``7--Series FPGAs Configuration
705
User's Guide''.
706
 
707
Testing with the OpenArty board has tended to focus on the warmboot capability.
708
Using this capability, a user is able to command the FPGA to reload its
709
configuration.  In support of this, two configuration areas have been
710
defined within memory.  The first is the default configuration, found at
711
the beginning of the flash.  This configuration is sometimes called the ``golden
712
configuration'' within Xilinx's documentation because it is the configuration
713
that the Xilinx device will always start up from after a power on reset.  On
714
the OpenArty, a second configuration may immediately follow the first in flash.
715
Commanding the FPGA to reload it's configuration is as simple as
716
setting the WBSTAR (warm boot start address) register to the location of the
717
new configuration within the flash, and then writing a 15 (a.k.a. IPROG)
718
to the FPGA command register (offset 4 from the beginning of the ICAPE2
719
addresses).  Examples of doing this are found in the
720
{\tt sw/host/zprog.sh} and {\tt sw/host/program.sh} scripts.  The former
721
programs the default configuration and then switches to it,
722
 
723
This configuration capability makes it possible for a user to 1) reprogram
724
the flash with an experimental configuration in the second configuration
725
location, and 2) test the configuration without actually touching the board.
726
If the configuration doesn't work well enough to be communicated with, the
727
board may simply be powered down and it will come back up with the initial
728
or golden configuration.  If the golden configuration ever gets corrupted,
729
or loaded with a configuration that will not work, then the user will need to
730
reload the FPGA from the JTAG port.
731
 
732
\subsection{OLED}
733
\subsection{Real Time Clock}
734
 
735
The Arty board contains a real time clock core together with a companion
736
real time date/calendar core.  The clock core itself contains not only current
737
time, but also a stopwatch, seconds timer, and alarm.  The real time date core
738
can be used to maintain the current date.  The real--time clock core uses the
739
GPS PPS output, as schooled by the GPS tracking circuit, in order to synchronize
740
their subsecond timing to the GPS itself.  Further, the real--time clock core
741
then creates a synchronization wire for the real--time date core.
742
 
743
Neither of these cores exports its subsecond precision to the rest of the
744
design.  This must be done using either the internal GPS tracking wires, or
745
by reading the time information from the tracking test bench.
746
 
747
\subsection{LEDs}
748
 
749
The Arty board contains two sets of LEDs: a plain set of LEDs, and a colored
750
set of LEDs.
751
 
752
The plain set of LEDs is controlled simply from the LED register.  This register
753
can be used to turn these LEDs on and off, either individually or as a whole.
754
It has been designed for atomic access, so only one write to this register
755
is necessary to set any particular LED.
756
 
757
The color LEDs are slightly different.  Each color LED is supported by its
758
own register, which controls three pulse width modulation controllers.  Three
759
groups of eight bits within the color LED register control the PWM thresholds,
760
first for red, then green, and then in the lowest bits for blue.  These are
761
used to turn on and off the various color components of the LEDs.  Using this
762
method, there are $2^{24}$ different colors each of these LEDs may be set
763
to.
764
 
765
\subsection{Buttons}
766
\subsection{Switches}
767
\subsection{Startup counter}
768
 
769
A startup counter has been placed into the basic peripheral I/O area.  This
770
counter simply counts the clocks since startup.  Upon rollover, the high
771
order bit remains set.  This can be used to sequence the start up of components
772
within the design if so desired.
773
 
774
\subsection{GPS UART}
775
The GPS UART, debug control UART, as well as the auxilliary UART, are all
776
based upon the same underlying UART IP core, sometimes known as the WBUART32
777
core.  The setup register is defined within the documentation for that core,
778
and provides for a large baud rate selection, 5-8 data bits, 1-2 stop bits,
779
and several parity choices.  Within OpenArty, the GPS core is initialized
780
to 9.6~kBaud, 8 data bits, no parity, and one stop bit.
781
 
782
When a value is ready to be read from the GPS uart, the GPS interrupt line
783
will go high.  Once read, and only when read, will this interrupt line reset.
784
If the read is successful, only bits within the bottom eight will be set.
785
If a read is attempted when there is no data, when the UART is in a reset
786
condition, or when there has been a framing or parity error (were parity
787
to be turned on), the upper bits of the UART port will be set.
788
 
789
In a like manner, the GPS device can be written to.  Certain strings, if sent
790
to the UART, can be used to change the UARTs baud rate, its serial port
791
settings, or even its reporting interval.  As with the read port, the transmit
792
port will interrupt the CPU when it is idle.  Writing a character to this
793
port will reset the interrupt.  Setting bits other than the bottom eight may
794
result in a break condition being set on this port as well.
795
 
796
Interacting with a controller can therefore be somewhat tricky.  The
797
interrupt controller will trigger whenever the port is ready to be read from,
798
and will re--trigger every clock until the port has been read from.  At this
799
point, the interrupt controller may be reset.  If this is an auxilliary
800
interrupt controller, such as the bus interrupt controller or the ZipSystem's
801
auxiliary controller, the auxiliary controller will then need to be reset,
802
and the bit in the primary controller associated with the auxiliary controller
803
as well.  It is for this reason that the UARTs have been placed on the
804
primary controller only.
805
 
806
It should also be possible to use the DMA to read from (or write to) either
807
UART port.
808
 
809
\subsection{Auxilliary UART}
810
 
811
The Auxilliary UART has roughly the same structure as the GPS UART, save that
812
it's default configuration is for a 115,200~Baud configuration with 8~data bits,
813
no stop bits, and no parity.  Reads, writes, and interrupts are treated in
814
the same fashion.
815
 
816
\subsection{GPIO}
817
 
818
A General Purpose I/O controller has been placed within the design as well.
819
This controller can handle 16--generic input wires, and set 16--generic output
820
wires.  A single register is used to read both input and output wire values,
821
as well as to set output values when written to.
822
 
823
However, to use this controller, you will need to manually configure it
824
(i.e.~change the Verilog source) within the core, in order to wire the various
825
GPIO values up to a device of interest.  This was done for the simple reason
826
that wiring anything new up to the controller will require Verilog changes
827
anyway.  For this reason, the controller has no way of setting wires to high
828
impedence, or pulling them up or down.  Such control may be done within the
829
top level design if necessary.
830
 
831
This controller will set an interrupt if ever any of the input wires within
832
it are changed.  The interrupt may be cleared in the interrupt controller.
833
 
834
\subsection{Linker Script}
835
 
836
A linker script has been created to capture the memory structure needed by
837
a program.  This script may be found in {\tt sw/board/arty.ld}.  It is a
838
sample script, using it is not required.
839
 
840
The script defines three types of memory to the linker: flash, block RAM, and
841
SDRAM.  Programs using this script will naturally start in flash (acting as
842
a ROM memory).  A bootloader must then be used to copy, from flash, those
843
sections of the program that are to be placed in block RAM or SDRAM into
844
their particular memory locations.
845
 
846
The block RAM locations are reserved for the user kernel, and specifically for
847
any part of the code in the {\tt .kernel} section.  C attributes, or assembly
848
{\tt .section} commands, must be used to place items within this section.
849
A final symbol within this section, {\_top\_of\_stack}, is used so that the
850
initial boot loader knows what to set the initial kernel stack to.
851
 
852
The rest of the initial program's memory is placed into
853
SDRAM.\footnote{Hopefully,
854
I'll get a data cache running on the ZipCPU to speed this up.}  At the end,
855
a {\tt \_top\_of\_heap} symbol is set to reference the final location in the
856
setup.  This symbol can then be used as a starting point for a memory allocator.
857
 
858
An example bootloader is provided in {\tt sw/board} that can be linked with
859
any (bare metal, supervisor) program in order to properly load it into memory.
860
 
861 2 dgisselq
\chapter{Software}
862
\section{Directory Structure}
863
\section{Zip CPU Tool Chain}
864
\section{Bench Test Software}
865
\section{Host Software}
866
\begin{itemize}
867
\item {\tt readflash}: As I am loathe to remove anything from
868
        a device that came factory installed, the
869
        {\tt readflash} program reads the original installed
870
        configuration from the flash and dumps it to a file.
871
 
872
\item {\tt wbregs}: This program offers a capability very similar to the
873
        PEEK and POKE capability Apple user's may remember from before the
874
        days of Macintosh.  {\tt wbregs <address>} will read from the
875
        Wishbone bus the value at the given address.  Likewise
876
        {\tt wbregs <address> <value>} will write the given value into the
877
        given address.  While both address and value have the semantics of
878
        numbers acceptable to {\tt strtoul()}, the address can also be a named
879
        address.  Supported names can be found in {\tt regdefs.cpp}, and their
880
        register mapping in {\tt regdefs.h}.
881
\item {\tt ziprun}:
882
\item {\tt zipload}:
883
\end{itemize}
884
 
885
\section{Zip CPU Programs}
886
\begin{itemize}
887
\item {\tt ntpserver}:
888
\item {\tt goldenstart}:
889
\end{itemize}
890
\section{ZipOS}
891
\subsection{System Calls}
892
\begin{itemize}
893
\item {\tt int wait(unsigned event\_mask, int timeout)}
894
\item {\tt int clear(unsigned event\_mask, int timeout)}
895
\item {\tt void post(unsigned event\_mask)}
896
\item {\tt void yield(void) }
897
\item {\tt int read(int fid, void *buf, int len)}
898
\item {\tt int write(int fid, void *buf, int len)}
899
\item {\tt unsigned time(void) }
900
% \item SEMGET
901
% \item SEMPUT
902
\item {\tt void *malloc(void)}
903
\item {\tt void free(void *buf)}
904
% \item FORK
905
% \item opendir
906
% \item EXEC
907
% \item OPEN
908
\end{itemize}
909
\subsection{Scheduler}
910
 
911 36 dgisselq
\chapter{Operation}\label{ch:operation}
912 2 dgisselq
 
913 36 dgisselq
\chapter{Registers}\label{ch:registers}
914 48 dgisselq
There are several address regions within the {\tt OpenArty}, as shown in
915 2 dgisselq
Tbl.~\ref{tbl:memregions}.
916
\begin{table}[htbp]
917 55 dgisselq
\begin{center}\begin{tabular}{|p{2.25in}|p{0.6in}|p{0.35in}|p{2.0in}|}\hline
918
\rowcolor[gray]{0.85} Binary Address & \multicolumn{1}{c|}{Base} & \multicolumn{1}{c|}{Size} & Purpose \\\hline\hline
919
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 0xxx xx--} & \scalebox{0.9}{\tt 0x00000400} & \hfill 128 & Peripheral I/O Control \\\hline
920
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 100y yx--} & \scalebox{0.9}{\tt 0x00000480} & \hfill 32& Debug scope control\\\hline
921
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 1010 xx--} & \scalebox{0.9}{\tt 0x000004a0} & \hfill 16 & RTC control\\\hline
922
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 1011 xx--} & \scalebox{0.9}{\tt 0x000004b0} & \hfill 16 & OLEDrgb control\\\hline
923
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 1100 xx--} & \scalebox{0.9}{\tt 0x000004c0} & \hfill 16 & AUX UART\\\hline
924
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 1101 xx--} & \scalebox{0.9}{\tt 0x000004d0} & \hfill 16 & GPS UART\\\hline
925
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0100 1110 xx--} & \scalebox{0.9}{\tt 0x000004e0} & \hfill 16 & SDCard controller\\\hline
926
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0101 0000 xx--} & \scalebox{0.9}{\tt 0x00000500} & \hfill 16 & GPS Clock loop control\\\hline
927
%\scalebox{0.8}{\tt 00 0000 0000 0000 0001 0101 0001 ----} & \scalebox{0.9}{\tt 0x00000148} & \hfill 16 & {\em Unused}\\\hline
928
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0101 001x xx--} & \scalebox{0.9}{\tt 0x00000520} & \hfill 32 & GPS Testbench\\\hline
929
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0101 010x xx--} & \scalebox{0.9}{\tt 0x00000540} & \hfill 32 & Network packet interface\\\hline
930
%\scalebox{0.8}{\tt 00 0000 0000 0000 0001 0101 011- ----} & \scalebox{0.9}{\tt 0x00000150} & \hfill 16 & {\em Unused}\\\hline
931
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0101 1xxx xx--} & \scalebox{0.9}{\tt 0x00000580} & \hfill 128 & Ethernet MIO configuration\\\hline
932
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0110 0xxx xx--} & \scalebox{0.9}{\tt 0x00000600} & \hfill 128 & Extended Flash Control Port\\\hline
933
\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0110 1xxx xx--} & \scalebox{0.9}{\tt 0x00000680} & \hfill 128 & ICAPE2 Configuration Port\\\hline
934
%\scalebox{0.8}{\tt 00 0000 0000 0000 0000 0111 ---- ----} & \scalebox{0.9}{\tt 0x00000150} & \hfill 16 & {\em Unused}\\\hline
935
%\scalebox{0.8}{\tt 00 0000 0000 0000 0000 1--- ---- ----} & \scalebox{0.9}{\tt 0x00000150} & \hfill 16 & {\em Unused}\\\hline
936
%\scalebox{0.8}{\tt 00 0000 0000 0000 0001 ---- ---- ----} & \scalebox{0.9}{\tt 0x00000150} & \hfill 16 & {\em Unused}\\\hline
937
\scalebox{0.8}{\tt 00 0000 0000 0000 0010 xxxx xxxx xxxx} & \scalebox{0.9}{\tt 0x00002000} & \hfill 4k & Ethernet RX Buffer\\\hline
938
\scalebox{0.8}{\tt 00 0000 0000 0000 0011 xxxx xxxx xxxx} & \scalebox{0.9}{\tt 0x00003000} & \hfill 4k & Ethernet TX Buffer\\\hline
939
\scalebox{0.8}{\tt 00 0000 0000 001x xxxx xxxx xxxx xxxx} & \scalebox{0.9}{\tt 0x00020000} & \hfill 128k & On-chip Block RAM\\\hline
940
\scalebox{0.8}{\tt 00 0001 xxxx xxxx xxxx xxxx xxxx xxxx} & \scalebox{0.9}{\tt 0x01000000} & \hfill 16M & QuadSPI Flash\\\hline
941
\scalebox{0.8}{\tt 00 0001 0000 0000 0000 0000 0000 0000} & \scalebox{0.9}{\tt 0x01000000} & & Configuration Start\\\hline
942
\scalebox{0.8}{\tt 00 0001 0100 0111 0000 0000 0000 0000} & \scalebox{0.9}{\tt 0x011c0000} & & Alternate Configuration\\\hline
943
\scalebox{0.8}{\tt 00 0001 0000 1110 0000 0000 0000 0000} & \scalebox{0.9}{\tt 0x01380000} & & CPU Reset Address\\\hline
944
\scalebox{0.8}{\tt 01 xxxx xxxx xxxx xxxx xxxx xxxx xxxx} & \scalebox{0.9}{\tt 0x10000000} & \hfill 256M & DDR3 SDRAM\\\hline
945
\scalebox{0.8}{\tt 10 0000 0000 0000 0000 0000 0000 0x00} & \scalebox{0.9}{\tt 0x20000000} & \hfill 8 & ZipCPU debug control port---only visible to debug WB master\\\hline
946 2 dgisselq
\end{tabular}
947
\caption{Address Regions}\label{tbl:memregions}
948
\end{center}\end{table}
949 48 dgisselq
These address regions include both read and write memory regions, such as the
950
block RAM, the SDRAM, and the Ethernet TX buffer, as well as read only memory
951
regions, such as the flash memory and the Ethernet RX buffer, as well as a
952
whole lot of memory mapped peripherals.  The purpose of this chapter will be
953
to describe how these memory mapped peripherals are organized, as well as
954
the specific details of how they may be used.
955 2 dgisselq
 
956 48 dgisselq
This address map information is also contained in a couple other locations.
957
First, {\tt sw/host/regdefs.h} maps all of the OpenArty registers to
958
C++ names, whereas {\tt sw/host/regdefs.cpp} maps these C++ names to a more
959
human readable form which is used by {\tt wbregs}.  Second, these registers
960
are also given names as part of several various structures within
961
{\tt sw/board/artyboard.h}.  And then, of course, they are also listed here.
962
 
963
\section{ZipSystem}
964
The ZipSystem wrapper around the ZipCPU provides access to roughly twenty
965
registers that are tightly integrated with the ZipCPU.  These registers are
966
shown in Tbl.~\ref{tbl:zipio}
967 2 dgisselq
\begin{table}[htbp]
968 55 dgisselq
\begin{center}\begin{tabular}{|p{0.9in}|p{0.35in}|p{2.5in}|}\hline
969
\rowcolor[gray]{0.85} Address & \multicolumn{1}{c|}{Size} & Purpose \\\hline\hline
970
\scalebox{0.9}{\tt 0xff000000} & 4 & Primary Zip PIC\\\hline
971
\scalebox{0.9}{\tt 0xff000004} & 4 & Watchdog Timer\\\hline
972
\scalebox{0.9}{\tt 0xff000008} & 4 & Bus Watchdog Timer\\\hline
973
\scalebox{0.9}{\tt 0xff00000c} & 4 & Alternate Zip PIC\\\hline
974
\scalebox{0.9}{\tt 0xff000010} & 4 & ZipTimer-A\\\hline
975
\scalebox{0.9}{\tt 0xff000014} & 4 & ZipTimer-B\\\hline
976
\scalebox{0.9}{\tt 0xff000018} & 4 & ZipTimer-C\\\hline
977
\scalebox{0.9}{\tt 0xff00001c} & 4 & ZipJiffies\\\hline
978
%
979
\scalebox{0.9}{\tt 0xff000020} & 4 & Master task counter\\\hline
980
\scalebox{0.9}{\tt 0xff000024} & 4 & Master prefetch stall counter\\\hline
981
\scalebox{0.9}{\tt 0xff000028} & 4 & Master memory stall counter\\\hline
982
\scalebox{0.9}{\tt 0xff00002c} & 4 & Master instruction counter\\\hline
983
\scalebox{0.9}{\tt 0xff000030} & 4 & User task counter\\\hline
984
\scalebox{0.9}{\tt 0xff000034} & 4 & User prefetch stall counter\\\hline
985
\scalebox{0.9}{\tt 0xff000038} & 4 & User memory stall counter\\\hline
986
\scalebox{0.9}{\tt 0xff00003c} & 4 & User instruction counter\\\hline
987
%
988
\scalebox{0.9}{\tt 0xff000040} & 4 & DMA command register\\\hline
989
\scalebox{0.9}{\tt 0xff000044} & 4 & DMA length\\\hline
990
\scalebox{0.9}{\tt 0xff000048} & 4 & DMA source address\\\hline
991
\scalebox{0.9}{\tt 0xff00004c} & 4 & DMA destination address\\\hline
992
%
993
\scalebox{0.9}{\tt 0xff000050} & 8 & {\em Reserved for MMU context register}\\\hline
994
\scalebox{0.9}{\tt 0xff8xxxxx} & ? & {\em Reserved for MMU TLB}\\\hline
995 2 dgisselq
\end{tabular}
996
\caption{ZipSystem Addresses}\label{tbl:zipio}
997
\end{center}\end{table}
998 48 dgisselq
and described in detail within the ZipCPU specification.
999 2 dgisselq
 
1000 48 dgisselq
Unlike the rest of the address map, these registers are only visible to the
1001
ZipCPU.  While many of them may be read via the debug port, in general accessing
1002
these registers via the {\tt wbregs} command is not so straight forward.
1003
 
1004 2 dgisselq
\section{Peripheral I/O Control}
1005 48 dgisselq
The first section of memory--mapped I/O for the ZipCPU is found near address
1006
{\tt 0x100}.  These peripherals are specifically peripherals that can be
1007
accessed without ever stalling the bus, and with a known and fixed (minimum)
1008
delay.  Tbl.~\ref{tbl:ioregs}
1009 2 dgisselq
\begin{table}[htbp]
1010
\begin{center}\begin{reglist}
1011 55 dgisselq
VERSION  &\scalebox{0.8}{\tt 0x0400} & 32 & R & Build date\\\hline
1012
PIC      &\scalebox{0.8}{\tt 0x0404} & 32 & R/W & Bus Interrupt Controller \\\hline
1013
BUSERR   &\scalebox{0.8}{\tt 0x0408} & 32 & R & Last Bus Error Address\\\hline
1014
PWRCOUNT &\scalebox{0.8}{\tt 0x040c} & 32 & R & Ticks since startup (roughly)\\\hline
1015
BTNSW    &\scalebox{0.8}{\tt 0x0410} & 32 & R/W & Button/Switch controller\\\hline
1016
LEDCTRL  &\scalebox{0.8}{\tt 0x0414} & 32 & R/W & LED Controller \\\hline
1017
RTCDATE  &\scalebox{0.8}{\tt 0x0418} & 32 & R/W & BCD Calendar Date\\\hline
1018
GPIO     &\scalebox{0.8}{\tt 0x041c} & 32 & R/W & GPIO controller\\\hline
1019
CLR-LEDx &\scalebox{0.8}{\tt 0x0420-c} & 32 & R/W & Color LED controller\\\hline
1020
GPSSECS  &\scalebox{0.8}{\tt 0x0430} & 32 & R/W & {\em Reserved for a one-up seconds counter}\\\hline
1021
GPSSUB   &\scalebox{0.8}{\tt 0x0414} & 32 & R/W & GPS PPS tracking subsecond info\\\hline
1022
GPSSTEP  &\scalebox{0.8}{\tt 0x0418} & 32 & R/W & Current GPS step size, units TBD\\\hline
1023
% Unused  &\scalebox{0.8}{\tt 0x041c--0x047f} & 32 & {\em Unused, writes ignored, returns zero upon read}\\\hline
1024 2 dgisselq
% 0x010c-0x010f
1025
\end{reglist}
1026 55 dgisselq
% UARTRX   &\scalebox{0.8}{\tt 0x0430} & 32 & R/W & Aux UART receive byte\\\hline
1027
% UARTTX   &\scalebox{0.8}{\tt 0x0434} & 32 & R/W & Aux UART transmit byte\\\hline
1028
% GPSRX    &\scalebox{0.8}{\tt 0x0438} & 32 & R/W & GPS UART receive byte\\\hline
1029
% GPSTX    &\scalebox{0.8}{\tt 0x0411} & 32 & R/W & GPS UART transmit byte\\\hline
1030
% AUXSETUP &\scalebox{0.8}{\tt 0x0418} & 29 & R/W & Auxilliary UART config\\\hline
1031
% GPSSETUP &\scalebox{0.8}{\tt 0x041c} & 29 & R/W & GPS UART config\\\hline
1032 2 dgisselq
\caption{I/O Peripheral Registers}\label{tbl:ioregs}
1033
\end{center}\end{table}
1034 48 dgisselq
shows the addresses of these I/O peripherals included as part of OpenArty.
1035 2 dgisselq
We'll walk through each of these peripherals in turn, describing how they work.
1036
 
1037 48 dgisselq
\subsection{Version}
1038
One of the simpler peripherals on the board is the {\tt VERSION} peripheral.
1039
This simple returns the date stamp found within {\tt rtl/builddate.v}.  This
1040
stamp is updated any time a {\tt make} command is issued in the main OpenArty
1041
project directory.  Reads from this address return this value, writes to this
1042
address are ignored.
1043
 
1044
This peripheral is {\em very} useful, especially when trying to determine which
1045
version of your configuration you are using, and whether or not the
1046
configuration has been changed or updated as you had intended by loading a new
1047
configuration, by writing a configuration to the flash and issuing an IPROG
1048
command, etc.
1049
 
1050 2 dgisselq
\subsection{Interrupt Controller}
1051
The OpenArty design maintains three interrupt controllers.  Two of them
1052 48 dgisselq
(a primary and an auxiliary) are found within the ZipSystem, and the third is
1053
located on the bus itself.  In terms of functionality, all three interrupt
1054
controllers are the same, and documented in the ZipCPU specification.  Of
1055
these, the primary interrupt controller for the
1056
entire design is the primary interrupt controller within the ZipSystem.
1057
This interrupt controller accepts as inputs, the output of the auxilliary
1058
interrupt controller.
1059
Hence, even though the CPU only supports a single interrupt line, by cascading
1060
it with a second controller, many more interrupts can be supported.
1061 2 dgisselq
 
1062 48 dgisselq
The third interrupt controller is the bus interrupt controller.  While the
1063
CPU can read and write this controller, the interrupt line from this controller
1064
goes to the host interface.  If you see, as an example, an \hbox{``> 4''} in
1065
your {\tt netuart} window, then you will know that OpenArty has sent an
1066
interrupt to a waiting host program.  If what you saw instead was a
1067
\hbox{``\# 4''}, then the interrupt was sent, but no one was listening.
1068
 
1069 2 dgisselq
The primary interrupt controller handles interrupts from the sources listed
1070 48 dgisselq
in Tbl.~\ref{tbl:sys-ints}.
1071 2 dgisselq
\begin{table}[htbp]
1072 55 dgisselq
\begin{center}\begin{tabular}{|p{1.0in}|c|r|p{3.00in}|}\hline
1073 2 dgisselq
\rowcolor[gray]{0.85} Name & Bit Mask & DMAC ID &Description \\\hline\hline
1074 36 dgisselq
SYS\_DMAC   & 0x0001 && The DMA controller is idle.\\\hline
1075
SYS\_JIF    & 0x0002 & 1 & A Jiffies timer has expired.\\\hline
1076
SYS\_TMC    & 0x0004 & 2 & Timer C has timed out.\\\hline
1077
SYS\_TMB    & 0x0008 & 3 & Timer C has timed out.\\\hline
1078
SYS\_TMA    & 0x0010 & 4 & Timer C has timed out.\\\hline
1079
SYS\_AUX    & 0x0020 & 5 & The auxilliary interrupt controller sends an interrupt\\\hline
1080
SYS\_PPS    & 0x0040 & 6 & An interrupt marking the top of the second\\\hline
1081
SYS\_NETRX  & 0x0080 & 7 & A packet has been received via the network\\\hline
1082
SYS\_NETTX  & 0x0100 & 8 & The network controller is idle, having sent its
1083 2 dgisselq
                        last packet\\\hline
1084 55 dgisselq
SYS\_UARTRXF & 0x0200 &  9 & The receive UART FIFO is half-full\\\hline
1085
SYS\_UARTTXF & 0x0400 & 10 & The transmit UART FIFO is less than half-full\\\hline
1086
SYS\_GPSRXF  & 0x0800 & 11 & The GPS receive UART FIFO is half-full\\\hline
1087
SYS\_GPSTXF  & 0x1000 & 12 & The GPS transmit UART FIFO is half-empty\\\hline
1088
SYS\_BUS    & 0x2000 & 13 & The BUS interrupt controller sends an interrupt\\\hline
1089 36 dgisselq
SYS\_OLED   & 0x4000 & 14 & The OLED port is idle\\\hline
1090 2 dgisselq
\end{tabular}
1091
\caption{Primary System Interrupts}\label{tbl:sys-ints}
1092
\end{center}\end{table}
1093 48 dgisselq
These interrupts are listed together with the
1094
mask that would need to be used when referencing them to the interrupt
1095
controller.  In a similar fashion, the auxilliary interrupt controller accepts
1096
inputs from the sources listed in Tbl.~\ref{tbl:aux-ints}.
1097 2 dgisselq
\begin{table}[htbp]
1098 55 dgisselq
\begin{center}\begin{tabular}{|p{0.9in}|c|r|p{3.00in}|}\hline
1099 2 dgisselq
\rowcolor[gray]{0.85} Name & Bit Mask & DMAC ID &Description \\\hline\hline
1100
AUX\_UIC & 0x0001 & 16 & The user instruction counter has overflowed.\\\hline
1101
AUX\_UPC & 0x0002 & 17 & The user prefetch stall counter has overflowed.\\\hline
1102
AUX\_UOC & 0x0004 & 18 & The user ops stall counter has overflowed.\\\hline
1103
AUX\_UTC & 0x0008 & 19 & The user clock tick counter has overflowed.\\\hline
1104
AUX\_MIC & 0x0010 & 20 & The supervisor instruction counter has overflowed.\\\hline
1105
AUX\_MPC & 0x0020 & 21 & The supervisor prefetch stall counter has overflowed.\\\hline
1106
AUX\_MOC & 0x0040 & 22 & The supervisor ops stall counter has overflowed.\\\hline
1107
AUX\_MTC & 0x0080 & 23 & The supervisor clock tick counter has overflowed.\\\hline
1108 55 dgisselq
%
1109
AUX\_PPD    & 0x0100 & 24& True at midnight\\\hline
1110
AUX\_UARTRX & 0x0200 & 25& A byte has been received from the AUX UART port and is ready to be read\\\hline
1111
AUX\_UARTTX & 0x0400 & 26& There's room for another byte in the TXFIFO queue\\\hline
1112
AUX\_GPSRX  & 0x0800 & 27& A byte has been received in the GPS UART interface, and is now ready to be read\\\hline
1113
AUX\_GPSTX  & 0x1000 & 28& There's room in the GPS UART transmit FIFO for another byte\\\hline
1114 2 dgisselq
\end{tabular}
1115
\caption{Auxilliary System Interrupts}\label{tbl:aux-ints}
1116
\end{center}\end{table}
1117 48 dgisselq
These interrupt mask constants are also defined in {\tt sw/board/artyboard.h}
1118
and {\tt sw/board/zipsys.h}.
1119 2 dgisselq
 
1120 48 dgisselq
Finally, the bus interrupt controller handles the interrupts from the sources
1121
listed in Tbl.~\ref{tbl:bus-ints}.
1122 2 dgisselq
\begin{table}[htbp]
1123 55 dgisselq
\begin{center}\begin{tabular}{|p{0.9in}|c|p{3.75in}|}\hline
1124 2 dgisselq
\rowcolor[gray]{0.85} Name & Bit Mask & Description \\\hline\hline
1125
BUS\_BUTTON & 0x0001 & A Button has been pressed. \\\hline
1126
BUS\_SWITCH & 0x0002 & The Scope has completed its collection\\\hline
1127
BUS\_PPS    & 0x0004 & Top of the second\\\hline
1128
BUS\_RTC    & 0x0008 & An alarm or timer has taken place (assuming the RTC
1129
                is installed, and includes both alarm or timer)\\\hline
1130
BUS\_NETRX & 0x0010 & A packet has been received via the network\\\hline
1131
BUS\_NETTX & 0x0020 & The network controller is idle, having sent its
1132
                        last packet\\\hline
1133
BUS\_UARTRX & 0x0040 & A character has been received via the UART\\\hline
1134
BUS\_UARTTX & 0x0080 & The transmit UART is idle, and ready for its next
1135
                character.\\\hline
1136
BUS\_GPIO   & 0x0100 & The GPIO input lines have changed values.\\\hline
1137
BUS\_FLASH  & 0x0200 & The flash device has finished either its erase or
1138
                write cycle, and is ready for its next command. (Alternate
1139
        config only.)\\\hline
1140
BUS\_SCOPE  & 0x0400 & A scope has completed collecting.\\\hline
1141
BUS\_GPSRX  & 0x0800 & A character has been received via GPS\\\hline
1142
BUS\_SDCARD & 0x1000 & The SD-Card controller has become idle\\\hline
1143
BUS\_OLED   & 0x2000 & The OLED interface has become idle\\\hline
1144
BUS\_ZIP    & 0x4000 & True if the ZipCPU has come to a halt\\\hline
1145
\end{tabular}
1146
\caption{Bus Interrupts}\label{tbl:bus-ints}
1147
\end{center}\end{table}
1148 48 dgisselq
You may notice that there is a lot of overlap between these interrupt sources.
1149
That is so that the host can also receive many of the same interrupts the ZipCPU
1150
can receive.
1151 2 dgisselq
 
1152
\subsection{Last Bus Error Address}
1153 48 dgisselq
Should an attempt be made to access a non--existant memory address, or should
1154
multiple devices all return their data at the same time on the bus, a bus
1155
error will be created.  When and if this happens, the address on the bus
1156
when this error was created will be placed into the last bus error address.
1157
This is the only way to set this address.
1158
 
1159
\subsection{Power counter}
1160
Some peripherals may require a certain amount of time from power up or startup
1161
until they can be accessed.  Guaranteeing this amount of time is the purpose
1162
of the power counter.  This simple read only register simply counts up from
1163
zero on every clock, with the exception that once the high order bit is set
1164
then it is never cleared.
1165
 
1166
\subsection{Button and Switch Register}
1167
btn-now / 4'h0 / btncfg / swcfg / btnstate / swstate
1168
The button and switch register includes a variety of fields for reading the
1169
current state of the buttons and switches, and for controlling the two related
1170
interrupts.  The register is separated into several fields, however, as shown
1171
in Fig.~\ref{fig:btnsw}.
1172
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1173
\bitheader{0-31}\\
1174
\bitbox{8}{\em Ignored}
1175
\bitbox{4}{BNOW}
1176
\bitbox{4}{4'h0}
1177
\bitbox{4}{BCFG}
1178
\bitbox{4}{SCFG}
1179
\bitbox{4}{BTN}
1180
\bitbox{4}{SW}
1181
\end{bytefield}
1182
\caption{Button/Switch register layout}\label{fig:btnsw}
1183
\end{center}\end{figure}
1184
The current state of the buttons and switches can be read through the {\tt BNOW}
1185
and {\tt SW} bit--fields.
1186
 
1187
The {\tt BTN} field contains one bit per button.  When a button is pressed,
1188
the respective bit in this field will be set.  It will then remain set until
1189
cleared.  To clear a value in this bit--field, write a `1' to the position you
1190
wish to clear.
1191
 
1192
Then {\tt BCFG} field controls which buttons will trigger a button interrupt.
1193
Should a button be pressed while its corresponding value within this field
1194
is a `1', a button interrupt pulse will be issued.  To set a bit within this
1195
field, you need to not only write the corresponding bit value, but you must
1196
also set an enable bit within the {\tt BTN} field.  Hence, writing a
1197
{\tt 0x0f0f0} will set all of the bits within this field, while {\tt 0x0f000}
1198
will have no effect, and {\tt 0x0030} will clear two bits.  Notice also that,
1199
when clearing a button press from the {\tt BTN} bits, the corresponding
1200
{\tt BCFG} bits will also be cleared.
1201
 
1202
Finally, the {\tt SCFG} field controls whether or not changing a switch value
1203
will cause an interrupt.  As with the {\tt BCFG} field, changing a value
1204
in this register requires writing to the {\tt SW} field as an enable.
1205
 
1206
The use of the enable bit--field lines was added so that reads and writes to
1207
this register wouldn't need special atomic access protections, so that some
1208
configuration bits could be changed without setting all of them, and so that
1209
changes during writes wouldn't go unnoticed.
1210
 
1211
\subsection{LED control register}
1212
The LED control register has a layout similar and enable field similar to that
1213
of the button/switch control register.  These fields can be seen in
1214
Fig.~\ref{fig:ledctrl}
1215
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1216
\bitheader{0-31}\\
1217
\bitbox{24}{\em Ignored}
1218
\bitbox{4}{ENB}
1219
\bitbox{4}{LED}
1220
\end{bytefield}
1221
\caption{LED control register layout}\label{fig:ledctrl}
1222
\end{center}\end{figure}
1223
The bottom four {\tt LED} bits of this register will always contain the current
1224
state of the LEDs.  To change an LED's state, write to this register the new
1225
state with the corresponding {\tt ENB} (enable) bit set.  Hence writing a
1226
{\tt 0x0c0} will turn off LED's two and three, while writing a {\tt 0x033} will
1227
set LED's zero and one, and writing a {\tt 0x0f} will be ignored.
1228
 
1229
\subsection{UART setup registers}
1230
There are two UART setup registers: one for controlling the PModUSBUART setup
1231
and the other for controlling the PMod GPS NMEA UART.  These follow the format
1232
given in the {\tt wbuart32} project, with a bit field shown in
1233
Fig.~\ref{fig:uartsetup}.
1234
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1235
\bitheader{0-31}\\
1236
\bitbox{2}{00}
1237
\bitbox{2}{N}
1238
\bitbox{1}{S}
1239
\bitbox{1}{P}
1240
\bitbox{1}{F}
1241
\bitbox{1}{T}
1242
\bitbox{24}{Clocks per Baud}
1243
\end{bytefield}
1244
\caption{UART setup register format}\label{fig:uartsetup}
1245
\end{center}\end{figure}
1246
In general, the only control needed to set these registers is to set their
1247
baud rate based upon the number of clocks per baud.  Hence, to set a
1248
9600~baud rate, given an 82.5~MHz clock rate, one would set this register to
1249
{\tt 8594}.  The high order bits are designed so that writing a zero to them
1250
sets the interface for 8--data bits, no parity, and one stop bit.
1251
 
1252
The number of data bits may be adjusted by changing the $N$ field from zero,
1253
for eight data bits, on up to three, for five data bits.
1254
 
1255
The $S$ bit determines whether or not the system will insert and require an
1256
extra stop bit.  Setting it to zero sets the system to require only a single
1257
stop bit.
1258
 
1259
The $P$ bit controls whether or not parity is enabled, and the $F$ bit controls
1260
whether or not the parity is fixed.  $T$ controls what type of parity is then
1261
used.  By setting $P$ to zero, parity checking and generation is turned off.
1262
 
1263
Finally, the auxiliary UART (i.e. the PMod USBUART) defaults to 115,200 Baud,
1264
8N1, whereas the GPS UART defaults to 9600 Baud, 8N1.  Both may be adjusted
1265
via this register.
1266
 
1267
\subsection{Color LED registers}
1268
 
1269
Since the Arty has four color LEDs, the OpenArty has four register words to
1270
control those LEDs.  These registers are split into three bit fields, an
1271
8--bit red, 8--bit green, and an 8--bit blue bit field.  The top eight bits
1272
are ignored.  Unlike many of the other OpenArty registers, these bit fields
1273
may be read or written with no special enable values.
1274
 
1275
\subsection{RTC date register}
1276
The real--time--clock date register format is shown in Fig.~\ref{fig:rtcdate}.
1277
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1278
\bitheader{0-31}\\
1279
\bitbox{16}{Year}
1280
        \bitbox{8}{Month}
1281
        \bitbox{8}{Day}\\
1282
\bitbox{4}{Y}
1283
        \bitbox{4}{Y} \bitbox{4}{Y} \bitbox{4}{Y}
1284
\bitbox{4}{M} \bitbox{4}{M}
1285
\bitbox{4}{D} \bitbox{4}{D}\\
1286
\end{bytefield}
1287
\caption{RTC Date register layout}\label{fig:rtcdate}
1288
\end{center}\end{figure}
1289
This is also a very simple register, containing eight binary coded decimal
1290
(BCD) digits.  Due to the nature of this setup, the date can be read quickly
1291
from the hexadecimal value of the register, and dates can be compared validly
1292
to determine if a date is earlier or later than any other.  Writes to the
1293
date register will set the date, otherwise the date will automatically
1294
increment whenever the Real Time Clock rolls over into the next day.
1295
 
1296
Unlike the Linux {\tt ctime} system call, the month value ranges from
1297
one to twelve.  The day of the month ranges from 1~to 31, or whatever is
1298
appropriate for the current month.
1299
 
1300 2 dgisselq
\subsection{General Purpose I/O}
1301 48 dgisselq
% TODO
1302
The General Purpose I/O controller will be the same as the controller from the
1303
S6~SoC once installed.
1304
 
1305
\subsection{UART Data Registers}
1306
Each of the two UARTs, PMod USBUART and PMod GPS, has two data registers and
1307
two interrupts associated with it: one for receive and one for transmit.
1308
As with the rest of the Arty I/O design, these are designed so that unused
1309
extra bits will be zero, and can (usually) quietly be ignored.
1310
 
1311
The receive UART register format is shown in Fig.~\ref{fig:rxuart}.
1312
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1313
\bitheader{0-31}\\
1314
\bitbox{20}{\em Always zero}
1315
\bitbox{1}{B} \bitbox{1}{F} \bitbox{1}{P} \bitbox{1}{I}
1316
\bitbox{8}{Data}\\
1317
\end{bytefield}
1318
\caption{Receive UART register layout}\label{fig:rxuart}
1319
\end{center}\end{figure}
1320
This register may only be read, writes are silently ignored.  If no receive
1321
value is present, the $I$ bit will be set.  If either a parity error, $P$, or
1322
frame error (stop bit not high), $F$, have occurred, those respective bits will
1323
be high.  The error bits are cleared upon successfully receiving a word across
1324
the interface.  Finally, the $B$ bit indicates the line is in a {\tt BREAK}
1325
condition.
1326
 
1327
The interface has been designed for one of two means of accessing it.  The
1328
interface may be polled.  In that case, anding the result with {\tt 0x0f00}
1329
will tell whether the result is invalid.  The interface may also be read upon
1330
a receive interrupt.  In that case, the same bit fields apply, but the $I$ bit
1331
will be guaranteed to be low.  Finally, the interrupt line will continue
1332
generating an interrupt input to the interrupt controller until it has been
1333
read.  Therefore, handling receive UART interrupts requires reading the receive
1334
data and then resetting the interrupt controller.  This also means, though, that
1335
the receive port should work quite well with the DMA controller.
1336
 
1337
As currently implemented, neither transmit nor receive UARTs have attached
1338
FIFOs.  Hence, once a value is ready to be read, it must be read before the
1339
next value is available to be read.
1340
 
1341
The transmit UART register is shown in Fig.~\ref{fig:txuart}.
1342
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1343
\bitheader{0-31}\\
1344
\bitbox{20}{\em Always zero}
1345
        \bitbox{1}{R}
1346
        \bitbox{1}{O}
1347
        \bitbox{1}{B}
1348
        \bitbox{1}{S}
1349
        \bitbox{8}{Data}\\
1350
\end{bytefield}
1351
\caption{Transmit UART register layout}\label{fig:txuart}
1352
\end{center}\end{figure}
1353
Of these bits, the data register is the most important.  Writes to the transmit
1354
UART, with only the bottom eight bits set, will send those bits out the
1355
data port.  Writes with the $B$, or {\tt BREAK} bit, set will place the
1356
transmitter into a {\tt BREAK} condition.  This condition is only cleared by
1357
writing with the $B$ bit clear.  The $S$ bit is a read-only busy bit, true if
1358
the device is still busy sending the last character.  Finally, the $R$ and $O$
1359
bits reflect the current value read on the receive port and the current value
1360
being placed onto the transmit port respectively.
1361
 
1362
As with the receive register, the transmit register has been designed to either
1363
be used in a polling or interrupt fashion.  When polled, the $S$ bit may be
1364
checked to determine if the transmitter is still busy sending the last
1365
character.  When the $S$ bit is clear, the UART transmitter will be responsive
1366
to another character written to it.  In interrupt mode, the device will
1367
constantly trigger an interrupt into the interrupt controller whenever  it is
1368
idle.  As with the receive, the only way to reset this interrupt is to send
1369
a character and then reset the bit in the interrupt controller.
1370
 
1371
\subsection{System seconds counter}
1372
As part of tracking the current time, it is important to have an accurate
1373
seconds counter that increments with every second.  That's what this register
1374
provides.  This plus the subsecond register should be the current time.
1375
 
1376
The problem is setting this register.  While the subsecond time register can be
1377
set using the PPS signal from the GPS, this seconds register will need to be
1378
calculated from the NMEA data stream.  To make this work, this register has been
1379
set up so that not only does it increment by one on the top of any second, but
1380
when written to the register will be bumped by whatever value is written to it.
1381
Hence, to step it forward by a second, write a {\tt 32'h1} to it.  To step it
1382
backwards, write a {\tt 32'hffffffff}.
1383
 
1384
\subsection{GPS Subsecond time}
1385
As part of being able to provide highly accurate time resolution, it is
1386
important to be able to read the current time at any given time.  This
1387
register provides the sub--seconds value associated with the current time.
1388
It is specifically the amount of time since the top of the last second
1389
times $2^{32}$.  As such, it rolls over at the top of each second.  The
1390
top bit can be used as an indication of the second half of the second, etc.
1391
 
1392
\subsection{GPS derived clock step}
1393
This 32--bit value is closely related to the sytem clock frequency.  It is a
1394
{\tt step} value designed so that a $2^{48}$ bit counter, incremented by this
1395
{\tt step} value on every clock tick, will roll over after one second.  To
1396
convert this to the GPS derived clock frequency, apply the formula:
1397
\begin{eqnarray}
1398
f_{\mbox{\tiny CLK}} &=& \frac{2^{48}}{\mbox{\tt STEP}}
1399
\end{eqnarray}
1400
 
1401 2 dgisselq
\section{Debugging Scopes}
1402 48 dgisselq
\section{Real--Time Clock}
1403
% TODO write something more meaningful
1404
The real--time clock controller is part of the {\tt rtcclock} project which
1405
should also be found near this distribution.  The manual for that project
1406
should describe the four registers, clock, timer, stopwatch, and alarm, that
1407
can be controlled herein.
1408
 
1409
\section{SD Card controller}
1410
% TODO write something more meaningful
1411
The SD card controller is part of the {\tt sdspi} project which
1412
should also be found near this distribution.  The manual for that project
1413
should describe the four registers, control, data, and the two FIFO's registers,
1414
that can be controlled herein.
1415
 
1416
\section{GPS PPS Tracking Loop control}
1417
The coefficients for the PLL that tracks the GPS PPS can be controlled via the
1418
registers listed in Tbl.~\ref{tbl:gpsctrl}.
1419
\begin{table}
1420
\begin{center}\begin{reglist}
1421 55 dgisselq
alpha  &\scalebox{0.8}{\tt 0x0500} & 8 & R/W & Recursive Error Averaging Coefficient\\\hline
1422
beta   &\scalebox{0.8}{\tt 0x0504} & 32 & R/W & Phase Tracking Coefficient\\\hline
1423
gamma  &\scalebox{0.8}{\tt 0x0508} & 32 & R/W & Frequency Tracking Coefficient\\\hline
1424
defstep&\scalebox{0.8}{\tt 0x050c} & 32 & R/W & Default clock step\\\hline
1425 48 dgisselq
\end{reglist}
1426
\caption{GPS PPS Tracking Control Registers}\label{tbl:gpsctrl}
1427
\end{center}\end{table}
1428
 
1429
\section{GPS testbench info}
1430
 
1431
The GPS PPS tracking core found within the Arty was originally tested using
1432
a GPS testbench.  Since simulation and performance measurement was a chalelnge,
1433
that testbench has been given a permanent place within the Arty.  Within it,
1434
there are eight registers, grouped into five variables.  These registers are
1435
designed so that, if read in a burst fashion, none of the registers will
1436
change during the burst--guaranteeing their coherency.
1437
 
1438
The first two registers will be ignored, unless specifically enabled by
1439
defining {\tt GPSTB} in busmaster.v.  They are designed to see how the
1440
GPS tracking circuit will respond to an absolutely accurate input.  The
1441
first, the {\tt tb\_maxcount} value, sets the number of clocks per simulated
1442
PPS tick.  The second, the {\tt tb\_jump} value, when written to will cause
1443
the PPS to suddenly be displaced in phase by the value written.  Both of these
1444
are ignored unless the test bench was configured to produce a simulated
1445
PPS signal.
1446
 
1447
The third register is the 64--bit error.  Specifically, this is the value of
1448
the GPS step counter at the top of the second.  In a perfect world, with
1449
perfect tracking, it should be zero.  In a wonderful world with nearly perfect
1450
tracking, this register should be less than the GPS step size.
1451
 
1452
The fourth register is the 64--bit count register.  This indicates the current
1453
time, in 64--bit precision.  The top 32--bits of this register are the same
1454
as the sub--seconds register presented earlier.
1455
 
1456
The final register is the 64--bit step register.  This register is very similar
1457
to the 32--bit {\tt STEP} register discussed earlier.  It is designed so that,
1458
when multiplied by the clock frequency in Hertz, the result should equal
1459
$2^{64}$.  The register, though, captures the current state of the GPS tracking
1460
circuit's estimate of the clock speed of the processor in this fashion.
1461
 
1462
\section{OLEDrgb control}
1463
The OLEDrgb can be controlled by four registers, listed in
1464
Tbl.~\ref{tbl:oledctrl}.
1465
\begin{table}
1466
\begin{center}\begin{reglist}
1467 55 dgisselq
CTRL &\scalebox{0.8}{\tt 0x04b0} & 32 & R/W & Control register\\\hline
1468
REGA &\scalebox{0.8}{\tt 0x04b4} & 32 & R/W & First excess control word\\\hline
1469
REGB &\scalebox{0.8}{\tt 0x04b8} & 32 & R/W & Second excess control word\\\hline
1470
DATA &\scalebox{0.8}{\tt 0x04bc} & 32 & R/W & Data and power register\\\hline
1471 48 dgisselq
\end{reglist}
1472
\caption{OLED Control Registers}\label{tbl:oledctrl}
1473
\end{center}\end{table}
1474
The first three are used to send information across the control port of the
1475
OLEDrgb, the last is used to adjust the power, reset, and I/O line voltage,
1476
as well as to send data values to the device.
1477
 
1478
Unlike the flash, network MDIO registers, or ICAPE port, reads and writes
1479
of this device will not stall the wishbone bus, and will complete immediately.
1480
Commands issued to the device while the controller is busy will therefore be
1481
quietly ignored.
1482
 
1483
Working with the device starts by powering it up.  This sequence is given
1484
by the manufacturer, and it requires the use of data register.  This data
1485
register has one of two interpretations, as shown in Fig.~\ref{fig:odata}.
1486
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1487
\bitheader{0-31}\\
1488
        \bitbox{16}{16'h00}
1489
        \bitbox{16}{Data}\\
1490
\bitbox{13}{13'h00}
1491
        \bitbox{1}{R} \bitbox{1}{V} \bitbox{1}{E}
1492
        \bitbox{13}{13'h00}
1493
        \bitbox{1}{R} \bitbox{1}{V} \bitbox{1}{E} \\
1494
\end{bytefield}
1495
\caption{OLED data register: Data write format, and power control read/write format}\label{fig:odata}
1496
\end{center}\end{figure}
1497
In the first interpretation, data may be sent to the port by simply
1498
writing that data to the port, while leaving the top sixteen bits zero.
1499
(We'll get to this later.)  In the second interpretation, the reset and
1500
power bits may be adjusted by setting the upper bit high (an enable bit),
1501
together with the corresponding lower bit to the value desired.
1502
 
1503
The $R$ bit will be zero if the device is in a reset state (an active low
1504
reset).  The $V$ bit is one if the VCC output is enabled.  The $E$ bit is one
1505
if the PMod is enabled, otherwise the power to the PMod is cut.  Adjusting
1506
these bits requires writing a `1' to the bit you wish to change, and then
1507
at the same time writing the value you wish to change it to in the lower order
1508
bits.  Hence writing a {\tt 0x010001} to the device will turn the power on,
1509
whereas a {\tt 0x010000} will turn it off.  Likewise {\tt 0x040000} will place
1510
the device into reset (active low), and {\tt 0x040004} will release the reset
1511
line.
1512
 
1513
Reads from this port simply return the current values of the $R$, $V$, and
1514
$E$ bits in the least significant 3--bits.
1515
 
1516
The power--up sequence for the device is shown below:
1517
\begin{enumerate}
1518
\item Wait a quarter second from configuration start
1519
\item Power up the device, writing a {\tt 0x050005} to the data port to
1520
        power up, but without setting the reset line yet.
1521
\item Wait four microseconds.
1522
\item Activate the reset line, by writing a {\tt 0x040000} to this data port.
1523
\item Wait another four microseconds.
1524
\item Clear the reset, by writing a {\tt 0x040004} to this data port.
1525
\item Wait another four microseconds.
1526
\item Initialize the display.
1527
\end{enumerate}
1528
 
1529
At this point, a series of commands need to be sent to the devices control
1530
port.  These commands are written to the control register.  The control
1531
register accepts several different types of writes, as shown in
1532
Fig.~\ref{fig:octrl}.
1533
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1534
\bitheader{0-31}\\
1535
        \bitbox{24}{24'h00}
1536
        \bitbox{8}{8'data}\\
1537
\bitbox{15}{15'h00}\bitbox{1}{1}\bitbox{16}{16'data} \\
1538
\bitbox{4}{4'h2}\bitbox{4}{}\bitbox{24}{24'data} \\
1539
\bitbox{4}{N-1}\bitbox{4}{}\bitbox{24}{24'data} \\
1540
\end{bytefield}
1541
\caption{Four separate OLED control register write formats}\label{fig:octrl}
1542
\end{center}\end{figure}
1543
To send a single byte of data, write that byte to the control port.
1544
Two bytes require setting bit sixteen, and they are sent high order byte first.
1545
Sending three or more bytes requires setting the number of bytes you wish to
1546
send, $N$, minus one to the top four bits, followed by the first three bytes,
1547
high order byte first.  To send longer commands, place the next four bytes
1548
into register {\tt A}, and the next four after that into register {\tt B}.
1549
In this manner, the device can send commands of up to 11~bytes in length,
1550
although most commands may be sent and received with writing only a single
1551
word to the control port.
1552
 
1553
The actual set of commands used to initialize the display is rather complex.
1554
Please examine the {\tt oledtest.c} ZipCPU program for an example of how
1555
this might be accomplished.  That program sends a series of commands to the
1556
control port, waiting for the port to become idle inbetween.  When using polled
1557
I/O, the low order bit of the control register will be `1' if the port is busy,
1558
zero if not.
1559
 
1560 2 dgisselq
\section{Internal Configuration Access Port}
1561 48 dgisselq
% TODO write something more meaningful
1562
The Xilinx ICAPE2 controller is part of the {\tt wbicapetwo} project which
1563
should also be found near this distribution.  The ICAPE port offers access to
1564
the internal Xilinx configuration registers.  The exact meaning of these registers is rather complex, and so users are referred to the Xilinx configuration
1565
user guide for more detail.
1566
 
1567
For now, two registers are worth mentioning.  The first is the WBSTAR register,
1568
{\tt 0x01f0}, and the second is the command register, {\tt 0x01e4}.
1569
Writes to the {\tt WBSTAR} register will set the address that the Xilinx
1570
chip will configure itself from upon any warm start configuration request.
1571
(Cold starts always configure from the beginning of flash.)  This address
1572
is relative to the start of the flash, and counted in octets rather than
1573
bus words.  Hence, to command the Xilinx chip to configure itself from an
1574
OpenArty address of {\tt 0x470000}, you would drop the four and multiply by
1575
four, and write {\tt 0x1c0000} to this register.
1576
 
1577
The second register worth mentioning is the command register.  Writing a
1578
15~to this register issues an {\tt IPROG} command, causing the FPGA to
1579
reload itself from the address given in the {\tt WBSTAR} register.
1580
 
1581
Put together, this is the meaning of the two lines in {\tt program.sh}:
1582
\begin{lstlisting}[language=bash]
1583
$WBREGS wbstar 0x01c00000
1584
$WBREGS fpgacmd 15
1585
\end{lstlisting}
1586
 
1587
The success of this configuration request may be determined from the
1588
{\tt BOOTSTS} register, as discussed in the Xilinx's
1589
{\em 7 Series FPGAs Configuration: User Guide}.
1590
 
1591
\section{Network Packet interface control}
1592
Tbl.~\ref{tbl:netpkt}
1593
\begin{table}
1594
\begin{center}\begin{reglist}
1595 55 dgisselq
NETRX  &\scalebox{0.8}{\tt 0x0540} & 32 & R/W & Packet receive control register\\\hline
1596
NETTX  &\scalebox{0.8}{\tt 0x0544} & 32 & R/W & Packet transmit control register\\\hline
1597
MACHI &\scalebox{0.8}{\tt 0x0548} & 16 & R/W & Ethernet MAC, hi order 16-bits\\\hline
1598
MACLO &\scalebox{0.8}{\tt 0x054c} & 32 & R/W & Ethernet MAC, low order 32-bits\\\hline
1599
RXMISS  &\scalebox{0.8}{\tt 0x0550} & 32 & R & Number of valid receive packets missed\\\hline
1600
RXERR&\scalebox{0.8}{\tt 0x0554} & 32 & R & Number of packets not properly received\\\hline
1601
RXCRC&\scalebox{0.8}{\tt 0x0558} & 32 & R & Packets received with CRC errors\\\hline
1602 48 dgisselq
{\em Unused} &\scalebox{0.8}{\tt 0x013f} & 32 & R & Reads zero (Reserved for transmit collision counting)\\\hline
1603
\end{reglist}
1604
\caption{Network Packet control registers}\label{tbl:netpkt}
1605
\end{center}\end{table}
1606 55 dgisselq
shows the eight registers used by the packet interface.  The first two of these
1607
are used for receiving and sending packets respectively.  We'll discuss these
1608
two in a moment.  The next two locations allow you to set your own MAC address.
1609
Doing so will allow the network interface, if so configured, to insert your
1610
MAC address into packets and filter incoming packets for only those containing
1611
your MAC.  The last four values are reserved for internal performance counters.
1612 48 dgisselq
 
1613
From the standpoint of configuring this interface, the network transmit
1614
control register needs to be configured first.  The bits in this register
1615
are shown in Fig.~\ref{fig:nettx}.
1616
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1617
\bitheader{0-31}\\
1618
        \bitbox{4}{0000}
1619
        \bitbox{4}{AW}
1620
        \bitbox{5}{00000}
1621
        \bitbox{1}{I}
1622
        \bitbox{1}{R}
1623
        \bitbox{1}{M}
1624
        \bitbox{1}{C}
1625
        \bitbox{1}{B}
1626
        \bitbox{4}{}
1627
        \bitbox{10}{Len}\\
1628
\end{bytefield}
1629
\caption{Network transmit control register, NETTX}\label{fig:nettx}
1630
\end{center}\end{figure}
1631
By default, the network device is held in a reset state until released by
1632
writing a `0' to the $R$ value of this register.  Other bits in this register
1633
include the $I$ bit, which turns off the hardware IP packet header checksum
1634
check when set, the $M$, which turns off hardware MAC filtering when set,
1635
and $C$, which turns off hardware CRC checking and filtering.  These bits
1636
are designed so that the natural state of the register is to set them to
1637
zero, enabling all hardware checking.  Finally, the $B$ bit will be set to
1638
indicate the interface is busy sending a packet.
1639
 
1640
The other field of this control register is the log address width field.
1641
This field specifies the size of the packet buffers, such that there are
1642
a maximum of $2^{\mbox{\tiny AW}}$ octets in each packet.
1643
 
1644
To use the network transmitter:
1645
\begin{enumerate}
1646
\item Set the $R$ bit to zero.  This will activate the interface,
1647
        removing it from reset.
1648
\item Set the local hardware MAC address into the {\tt MACHI}
1649
        and {\tt MACLO} registers.  (The {\tt MACHI} register holds the top
1650
        16~bits, in its lower 16~bits.)
1651
\item Write a packet into the transmit packet memory area, starting at the
1652
        zero address.
1653
        \begin{enumerate}
1654
        \item If the hardware MAC option, $M$ bit, is set to zero, then
1655
                hardware MAC generation is on.  Place bits {\tt 47\ldots 16}
1656
                of the destination MAC in the first word (address 0 of the
1657
                TX memory), and fill the next word with the last bits of the
1658
                destination MAC and the sixteen bits of the EtherType.
1659
        \item If the hardware MAC option is off, i.e. $M=0$, then the
1660
                first two words contain the destination MAC as before,
1661
                but the second word also contains the top 16--bits of the
1662
                source MAC.  The third word contains the bottom bits of the
1663
                source MAC.  The fourth word then contains the EtherType
1664
                field twice.  Any IP packet then begins on the fifth word.
1665
        \item If the hardware CRC option is off, $C=1$, then a CRC will need
1666
                to be generated and placed into the last 4--octets of the
1667
                message.
1668
        \item Octets are transmitted from from high order bits to low order
1669
                bits.  Hence the first octet transmitted will be from
1670
                bits 31--24 of a given word, the second octet from bits
1671
                23--16, etc.
1672
        \end{enumerate}
1673
\item Once the memory for the packet has been set, sending the packet
1674
        is as simple as writing the packet length (in octets), together with
1675
        any flag bits, to the network transmit control register.
1676
\item If using polled I/O, the transmit control register may be examined to
1677
        see when its busy bit clears.  At that point, another packet may be
1678
        loaded into memory.
1679
\item If using interrupt driven I/O, a network transmit idle interrupt will be
1680
        generated once the transmission is complete.  (This interrupt will
1681
        remain high until another packet transmit command is issued.)
1682
\item To send a subsequent packet, one need only set the memory and write
1683
        the transmit command to the control register.  This will reset the
1684
        interrupt input to the interrupt controller, so a transmit complete
1685
        interrupt may be noticed again.
1686
\end{enumerate}
1687
 
1688
The network receive command register is similar to the transmit
1689
command register.  It is shown in Fig.~\ref{fig:netrx}.
1690
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1691
\bitheader{0-31}\\
1692
        \bitbox{4}{0000}
1693
        \bitbox{4}{AW}
1694
        \bitbox{4}{0000}
1695
        \bitbox{1}{B}
1696
        \bitbox{1}{C}
1697
        \bitbox{1}{E}
1698
        \bitbox{1}{M}
1699
        \bitbox{1}{S}
1700
        \bitbox{1}{V}
1701
        \bitbox{4}{}
1702
        \bitbox{10}{Len}\\
1703
\end{bytefield}
1704
\caption{Network receive control register, NETRX}\label{fig:netrx}
1705
\end{center}\end{figure}
1706
Unlike the transmit command register, there are no configuration fields in
1707
the network receive command register.  The receive configuration bits,
1708
controlling such things as whether or not the device it in reset, or whether
1709
or not to have the hardware filter out bad
1710
CRC's, bad IP header checksums, or MAC addresses not for our machine---these
1711
bits are shared with the transmit configuration register.  On receive,
1712
bits are set to indicate the success or failure of a received packet.
1713
$C$ is set if a packet is received with a CRC error.  $E$ is set if there
1714
was some error in packet receiption.  $M$ is set if a packet is received
1715
and the memory still contains the last packet, causing a packet Miss.
1716
$S$ is set if the receive port is busy.  $V$ is set if a valid packet can be
1717
found in the receive memory.  Each of these status bits may be individually
1718
cleared by writing a `1' to that respective bit.  Writing a `1' to the valid
1719
bit, $V$, also clears the receive port so that another packet may be
1720
received.
1721
 
1722
If the interface is on and no valid packet has been received, then the
1723
packet receive logic is activated.  Any packet received with a valid length
1724
(64~bytes or more), a valid CRC (if hardware CRC checking is on), either our
1725
MAC address (as programmed into the configuration) or a broadcast address,
1726
and a valid IP header (if it's an IP packet), will be copied into the receive
1727
memory.  Once the packet has been received, the $V$ bit will be set high.
1728
If the packet was a broadcast packet, the $B$ bit will also be set.  Writing
1729
a `1' to the $V$ bit of this port will clear the packet firmware, and release
1730
it to receive another packet.
1731
 
1732
This port may be operated as either polled or interrupt drive I/O.  If polled,
1733
then check the $V$ bit.  Once the $V$ bit is one, a packet is ready to be
1734
read from the port.  At the same time $V$ is set to one, an interrupt will
1735
be generated.  This interrupt will not clear until $V$ is cleared.
1736
 
1737
 
1738
\section{Ethernet MDIO configuration registers}
1739
The ethernet PHY has 32~address configuration address registers available
1740
to the board via an MDIO interface.  These are 16--bit registers that may be
1741
read from, or written to the device.  The current implementation locks the
1742
bus while reading from or writing to the device until the operation is
1743
complete.
1744
 
1745
Using these registers, one can tell if the Ethernet is in 10Mbps mode, or
1746
100Mbps mode, or even whether or not a cable is connected.
1747
 
1748
A simple register to query to know if this interface is working is the LEDCR
1749
register, {\tt 0x01b8}.
1750
This register will be set to {\tt 0x0ffff} upon startup, and until the network
1751
port has been turned on.  Once turned on, this register will default to all
1752
zeros.  To manually turn both the LEDs on, write a {\tt 0x030} to the LEDCR
1753
register.  To manually turn them off, write a {\tt 0x036}.  A value of
1754
{\tt 0x00} will set them back to the default mode of indicating the link
1755
status and speed.
1756
 
1757
Please examine the specification for the ethernet PHY for more information
1758
about these registers, what their bits mean, and how the device can be
1759
controlled.
1760
 
1761 2 dgisselq
\section{Flash Memory}
1762 48 dgisselq
% \section{Extended Flash configuration port}
1763
From the standpoint of a user program, flash memory should just work.  This
1764
flash memory was designed with that purpose in mind.  Reads are designed to
1765
just work.
1766
 
1767
If only all that a flash required was reading, life would be good.  However,
1768
flash chips have a rather complex protocol for reading, erasing, and programming
1769
them.  This has made the interface more complex.
1770
 
1771
Still, reads are \ldots nearly simple.  Reads from the flash
1772
memory will automatically be done in Quad--SPI mode and leave the device in
1773
Execuste--In--Place (XIP) mode upon completion.  This means that any initial
1774
read burst will take $22+8N$ QSPI clocks for $N$ words, whereas subsequent
1775
reads will only require $14+8N$ QSPI clocks.  Reading from any of the device
1776
registers will transition the device out of XIP mode, and back into the
1777
extended register mode.
1778
 
1779
Writes are more difficult.  Changing the contents of a flash chip requires
1780
either erasing a sector (or subsector) in order to turns all the zeros to ones
1781
in that sector (or subsector), or it requires writing a page in order to
1782
selectively turn some of the ones back to zeros.  The interface used in the
1783
OpenArty is designed to allow the user complete flexibility over the control
1784
of the flash device, without requiring the device to be commanded explicitly
1785
over a SPI (or QSPI) port.  (The device is connected via such a port, the
1786
interface tries to hide that fact.)
1787
 
1788
The result is that there are many registers used for reading, writing, and
1789
controlling the flash.  A quick list of these registers is shown in
1790
Tbl.~\ref{tbl:flctl}.
1791 2 dgisselq
\begin{table}
1792
\begin{center}\begin{reglist}
1793 55 dgisselq
EWREG  &\scalebox{0.8}{\tt 0x0600} & 32 & R & Erase/write control and status\\\hline
1794
ESTATUS      &\scalebox{0.8}{\tt 0x0604} & 8 & R/W & Bus Interrupt Controller \\\hline
1795
NVCONF   &\scalebox{0.8}{\tt 0x0608} & 16 & R & Last Bus Error Address\\\hline
1796
VCONF &\scalebox{0.8}{\tt 0x060c} & 8 & R & Ticks since startup\\\hline
1797
EVCONF    &\scalebox{0.8}{\tt 0x0610} & 8 & R/W & Button/Switch controller\\\hline
1798
LOCK  &\scalebox{0.8}{\tt 0x0614} & 8 & R/W & LED Controller \\\hline
1799
flagstatus&\scalebox{0.8}{\tt 0x0618} & 8 & R/W & Auxilliary UART config\\\hline
1800
CLEAR   &\scalebox{0.8}{\tt 0x061c} & 8 & R/W & Clear status on write\\\hline
1801
DevID &\scalebox{0.8}{\tt 0x0620-}\hfill & 5x32 & R & Device ID\\
1802
        &\scalebox{0.8}{\tt -0x0630}\hfill & & & \\\hline
1803 2 dgisselq
% asyncID &\scalebox{0.8}{\tt 0x018d} & 32 & R/W & Asynch Read ID.  Write starts the ASynch read, 0xff returned until complete\\\hline
1804 55 dgisselq
% asyncOTP  &\scalebox{0.8}{\tt 0x18e} & 32 & W & Asynch Read OTP.  Write starts the ASynch read, 0xff returned until complete\\\hline
1805
OTP     &\scalebox{0.8}{\tt 0x0640-}\hfill &16x32 & R/W & OTP Memory\\
1806 2 dgisselq
        &\scalebox{0.8}{\hfill\tt -0x19f} & & & \\\hline
1807
% 0x010c-0x010f
1808
\end{reglist}
1809
\caption{Flash control registers}\label{tbl:flctl}
1810
\end{center}\end{table}
1811 48 dgisselq
Many of these registers are defined by the flash itself, and the interface
1812
just provides access to them.  These include the status, non--volatile
1813
configuration, volatile configuration, the extended volatile configuration,
1814
and flag status registers.  In a similar fashion, the Device ID may be read
1815
from the device as well.  These registers are defined in the flash
1816
specification.
1817 2 dgisselq
 
1818 48 dgisselq
One piece of configuration is required, though, before this interface will work
1819
properly either reading or writing.  That is that the fast read (or write)
1820
delay must be set to eight clocks.  To do this, write a {\tt 0x08b} needs to be
1821
written to the volatile configuration register.\footnote{To get the ZipCPU to
1822
start automatically upon power up, or indeed to have the flash start up in a
1823
working mode, the non--volatile configuration register will need to be adjusted
1824
to contain this information on power up.  Please consult the chip specification
1825
to determine what to set that register to.}  To set the volatile configuration
1826
register, disable the write protect found in the erase/write control register,
1827
and then write the new value to the volatile configuration register.
1828
 
1829
Perhaps the most important register of this interface is the erase/write
1830
control register.  This register enables or disables the write protect for
1831
the flash, and issues any erase sector or subsector commands.  The register
1832
itself is a bitfield, shown in Fig.~\ref{fig:fewbits}.
1833
\begin{figure}\begin{center}\begin{bytefield}[endianness=big]{32}
1834
\bitheader{0-31}\\
1835
        \bitbox{1}{W}
1836
        \bitbox{1}{E}
1837
        \bitbox{1}{Q}
1838
        \bitbox{1}{S}
1839
        \bitbox{1}{I}
1840
        \bitbox{1}{V}
1841
        \bitbox{1}{X}
1842
        \bitbox{1}{}
1843
        \bitbox{10}{Sector}
1844
        \bitbox{4}{Sub}
1845
        \bitbox{10}{Key}\\
1846
\end{bytefield}
1847
\caption{Flash Erase/Write control register layout}\label{fig:fewbits}
1848
\end{center}\end{figure}
1849
The bits in this register are:
1850
 
1851
$W$ is a Write-In-Progress bit.  It will be one when read if the device
1852
is busy erasing or writing.  Upon any transition back to zero, the controller
1853
will issue an interrupt.  This bit is also the Erase Command bit.  Write a
1854
`1' to this bit to command the flash to erase either a sector or a subsector.
1855
 
1856
$E$ is a write--enable bit.  Write a `1' to this bit to disable write
1857
protection, and a `0' to this bit to re-enable write protection.  (I highly
1858
recommend keeping write protection enabled.  I had an error in one of my
1859
programs once that erroneously started walking through peripheral register
1860
space and \ldots)
1861
 
1862
$Q$ is set if Quad SPI mode is enabled.  This is currently hardwired to true
1863
within the design, so this bit will never change.
1864
 
1865
$S$ is the subsector erase bit.  Upon any command to erase the device, if this
1866
bit is set then only a subsector will be erased.  If this bit is cleared,
1867
the erase command will erase an entire sector.
1868
 
1869
The $I$ bit is set when the device ID has been read into a local RAM memory.
1870
Hence, reading from the device ID initially takes many clocks, but subsequent
1871
reads should be very fast.
1872
 
1873
The $V$ bit will be set upon any write violation, such as trying to write to
1874
the device with the write protect enabled.  This bit is cleared upon any
1875
write to the erase/write control register.
1876
 
1877
$X$ is the XIP mode.  This is set any time bit 3 of the volatile configuration
1878
register is set, and cleared upon any read from non--flash memory.
1879
 
1880
Twenty four bits constitute the sector address.  When commanding the device
1881
to erase a sector, the register neds to know the top 10 of them.  When
1882
commanding the device to erase a subsector, the controller needs the top
1883
14~bits.  The bottom 10~bits are a key.  Set these to {\tt 10'h1be} in order
1884
to command a (sub)sector erase, or even to just adjust the sector address
1885
kept and maintained in this register.
1886
 
1887
Erasing a sector requires two writes to the erase/write command register.
1888
The first write simply disables the write protect.  To do this, write a
1889
{\tt 0x40000000} to the register.  The second write must be the sector
1890
address added or OR'd to {\tt 0xc00001be}.  When erasing a subsector,
1891
set the subsector bit for these two commands.
1892
 
1893
Writing to a page is similar.  In that case, first disable the write protect
1894
as before, and then write (via burst mode) the new page values to the device.
1895
The actual write is sent to the device as soon as the burst mode is complete.
1896
Hence, writing in separate commands, or writing more than a page (64~words),
1897
will stall the bus.
1898
 
1899
While the write or erase is going on, the erase/write control register may be
1900
read.  Once the erase or write has completed, an interrupt will be generated.
1901
Unlike the UART interrupts, this interrupt does not perpetually generate itself
1902
until cleared.  Hence, you may wish to clear the flash interrupt before
1903
an erase/write operation, and then check for the interrupt upon completion.
1904
Further, while the erase/write operation is ongoing, you must not try to read
1905
from flash memory.  (It is likely to cause a bus error \ldots)
1906
 
1907
The EQSPI lock register returns the lock register value associated with the
1908
currently selected sector.
1909
 
1910
The OTP registers reference one--time--programmable memory on the flash.
1911
This memory, once programmed, {\em can not be cleared}!  Programming this
1912
memory constitues changing certain of the default `1's to zeros, depending
1913
upon the values you write to these registers.  They are written in a fashion
1914
similar to writing/programming a page as described above.
1915
 
1916 30 dgisselq
\chapter{Wishbone Datasheet}\label{ch:wishbone}
1917 2 dgisselq
 
1918
The master and slave interfaces have been simplified with the following
1919
requirement: the {\tt STB} line is not allowed to be high unless the {\tt CYC}
1920
line is high.  In this fashion, a slave may often be able to ignore {\tt CYC}
1921
and only act on the presence of {\tt STB}, knowing that {\tt CYC} must be
1922
active at the same time.
1923
 
1924 30 dgisselq
\chapter{Clocks}\label{ch:clocks}
1925 2 dgisselq
\begin{table}\begin{center}
1926
\begin{clocklist}
1927 30 dgisselq
{\tt i\_clk\_100mhz} & Ext & \multicolumn{2}{c|}{100} &
1928 2 dgisselq
        100~MHz Crystal Oscillator \\\hline
1929 30 dgisselq
{\em Future }{\tt s\_clk} & PLL & 152 & 166 & Internal Logic, Wishbone Clock \\\hline
1930
{\tt s\_clk} & PLL & 83.33 & 75.76& DDR3 SDRAM Controller Clock \\\hline
1931 48 dgisselq
\multicolumn{2}{|c|}{\tt mem\_clk\_200mhz} & 200~MHz & & MIG Reference clock for PHASER generation\\\hline
1932 30 dgisselq
{\tt ddr3\_ck\_}$x$ & DDR & 166.67 & 303 & DDR3 Command Clock\\\hline
1933
{\tt o\_qspi\_sck} & DDR & 95 & & QSPI Flash clock \\\hline
1934
{\tt o\_sd\_clk} & Logic & 50 & 0.100 & SD--Card clock \\\hline
1935
{\tt o\_oled\_sck} & Logic & 166 & & OLED SPI clock \\\hline
1936
{\tt o\_eth\_mdclk} & Logic & 25 & 2.5 & Ethernet MDIO controller clock\\\hline
1937 2 dgisselq
\end{clocklist}
1938
\caption{OpenArty clocks}\label{tbl:clocks}
1939
\end{center}\end{table}
1940
 
1941
\chapter{I/O Ports}
1942
 
1943
Table.~\ref{tbl:ioports}
1944
\begin{table}[htbp]
1945
\begin{center}
1946
\begin{portlist}
1947
i\_clk\_100mhz & 1 & Input & Clock\\\hline
1948
o\_qspi\_cs\_n & 1 & Output & Quad SPI Flash chip select\\\hline
1949
o\_qspi\_sck & 1 & Output & Quad SPI Flash clock\\\hline
1950
io\_qspi\_dat & 4 & Input/Output & Four-wire SPI flash data bus\\\hline
1951
i\_btn & 4 & Input  & Inputs from the two on-board push-buttons\\\hline
1952
i\_sw  & 4 & Input  & Inputs from the two on-board push-buttons\\\hline
1953
o\_led & 4 & Output & Outputs controlling the four on-board LED's\\\hline
1954
o\_clr\_led0 & 3 & Output & \\\hline
1955
o\_clr\_led1 & 3 & Output & \\\hline
1956
o\_clr\_led2 & 3 & Output & \\\hline
1957
o\_clr\_led3 & 3 & Output & \\\hline
1958
i\_uart\_rx & 1 & Input &  UART receive input\\\hline
1959
o\_uart\_tx & 1 & Output & UART transmit output\\\hline\hline
1960
i\_aux\_rx & 1 & Input &  Auxiliary/Pmod UART receive input\\\hline
1961
o\_aux\_tx & 1 & Output & Auxiliary/Pmod UART transmit output\\\hline
1962 55 dgisselq
i\_aux\_rts & 1 & Input &  Auxiliary/Pmod UART ready--to--send\\\hline
1963
o\_aux\_cts & 1 & Output & Auxiliary/Pmod UART clear--to--send\\\hline\hline
1964 2 dgisselq
i\_gps\_rx & 1 & Input &  GPS/Pmod UART receive input\\\hline
1965
o\_gps\_tx & 1 & Output & GPS/Pmod UART transmit output\\\hline
1966
i\_gps\_pps & 1 & Input & GPS Part-per-second (PPS) signal\\\hline
1967
i\_gps\_3df & 1 & Input & GPS\\\hline\hline
1968
o\_oled\_cs\_n & 1 & Output & \\\hline
1969
o\_oled\_sck & 1 & Output & \\\hline
1970
o\_oled\_mosi & 1 & Output & \\\hline
1971
i\_oled\_miso & 1 & Input & \\\hline
1972
o\_oled\_reset & 1 & Output & \\\hline
1973
o\_oled\_dc & 1 & Output & \\\hline
1974
o\_oled\_en & 1 & Output & \\\hline
1975
o\_oled\_pmen & 1 & Output & \\\hline\hline
1976
o\_sd\_sck & 1 & Output & SD Clock\\\hline
1977
i\_sd\_cd & 1 & Input & Card Detect\\\hline
1978
i\_sd\_wp & 1 & Input & Write Protect\\\hline
1979
io\_cmd & 1 & In/Output & SD Bi-directional command wire\\\hline
1980
io\_sd & 4 & In/Output & SD Bi-directional data lines\\\hline\hline
1981
o\_cls\_cs\_n & 1 & Output & CLS Display chip select\\\hline
1982
o\_cls\_sck & 1 & Output & CLS Display clock\\\hline
1983
o\_cls\_mosi & 1 & Output & CLS Display MOSI\\\hline
1984
i\_cls\_miso & 1 & Input & CLS Display MISO\\\hline\hline
1985
\end{portlist}
1986
\caption{List of IO ports}\label{tbl:ioports}
1987
\end{center}\end{table}
1988
lists the various I/O ports associated with OpenArty.
1989
 
1990
 
1991
% Appendices
1992
% Index
1993
\end{document}
1994
 
1995
 

powered by: WebSVN 2.1.0

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