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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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