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

Subversion Repositories openarty

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

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

powered by: WebSVN 2.1.0

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