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

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [doc/] [src/] [spec.tex] - Blame information for rev 51

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 7 dgisselq
\documentclass{gqtekspec}
2 50 dgisselq
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
%%
4
%% Filename:    spec.tex
5
%%
6
%% Project:     CMod S6 System on a Chip, ZipCPU demonstration project
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 7 dgisselq
\usepackage{import}
40
\usepackage{bytefield}
41
\project{CMod S6 SoC}
42
\title{Specification}
43
\author{Dan Gisselquist, Ph.D.}
44
\email{dgisselq (at) opencores.org}
45 41 dgisselq
\revision{Rev.~0.3}
46 7 dgisselq
\begin{document}
47
\pagestyle{gqtekspecplain}
48
\titlepage
49
\begin{license}
50
Copyright (C) \theyear\today, Gisselquist Technology, LLC
51
 
52
This project is free software (firmware): you can redistribute it and/or
53
modify it under the terms of  the GNU General Public License as published
54
by the Free Software Foundation, either version 3 of the License, or (at
55
your option) any later version.
56
 
57
This program is distributed in the hope that it will be useful, but WITHOUT
58
ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
59
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
60
for more details.
61
 
62
You should have received a copy of the GNU General Public License along
63
with this program.  If not, see \texttt{http://www.gnu.org/licenses/} for a copy.
64
\end{license}
65
\begin{revisionhistory}
66 50 dgisselq
0.5 & 2/13/2017 & Gisselquist & Draft updates to support the 8-bit byte ZipCPU
67
                \\\hline
68 41 dgisselq
0.3 & 5/23/2016 & Gisselquist & Draft for comment, includes ZipOS and PMod
69
                pin mapping\\\hline
70 36 dgisselq
0.2 & 5/14/2016 & Gisselquist & Updated Draft, still not complete \\\hline
71 7 dgisselq
0.1 & 4/22/2016 & Gisselquist & First Draft \\\hline
72
\end{revisionhistory}
73
% Revision History
74
% Table of Contents, named Contents
75
\tableofcontents
76
\listoffigures
77
\listoftables
78
\begin{preface}
79
The Zip CPU was built with the express purpose of being an area optimized,
80
32--bit FPGA soft processor.
81
 
82 41 dgisselq
The S6~SoC is designed to prove that the Zip~CPU has met this goal.
83
 
84
There are two side--effects to this.  First, the project proves how capable a
85
CMod--S6 is, and second, this project provides demonstration implementations
86
of how to interact with a variety of PMod devices: the audio amplifier,
87
the serial 2--line LCD display, the USBUART, and the 16--character numeric
88
keypad.
89 7 dgisselq
\end{preface}
90
 
91
\chapter{Introduction}
92
\pagenumbering{arabic}
93
\setcounter{page}{1}
94
 
95 41 dgisselq
% What is old
96
The Zip~CPU is a soft core CPU designed to fit within an FPGA, to use a minimum
97
amount of the FPGA's resources, and yet to provide the services of a fully
98
capable 32--bit computer.  It is based upon a Von~Neumann architecure and so a
99
single 32--bit wishbone bus provides it with access to both peripherals and
100
memory.
101 7 dgisselq
 
102 41 dgisselq
% What does the old lack?
103
Previous demonstrations of the Zip~CPU have focused on larger FPGAs, such as
104
the Spartan--6 LX9 and LX25 and the Artix--7 35T.  On these FPGA's,
105
the Zip~CPU runs in a pipelined configuration where it is tightly integrated
106
with a prefetch/instruction cache.  While these demonstrations have shown that
107
the Zip~CPU can act as a very simple CPU in these environments, they really
108
haven't demonstrated the ability of the Zip~CPU to use only a minimum amount
109
of the FPGA's resources.
110
 
111
% What is new
112
The CMod~S6 board provides the opportunity for that demonstration rather nicely.
113
% What does the new have that the old lacks
114 7 dgisselq
\begin{enumerate}
115 36 dgisselq
\item The Spartan--6 LX4 FPGA is very limited in its resources:
116 7 dgisselq
        It only has 2,400 look--up tables (LUTs), and can only support
117
        a 4,096~Word RAM memory (16 kB).
118
\item With only 4kW RAM, the majority of any program will need to be placed into
119 41 dgisselq
        and run from flash.
120 7 dgisselq
\item While the chip has enough area for the CPU, it doesn't have enough area
121
        to include the CPU and \ldots write access to the flash, debug access,
122 41 dgisselq
        wishbone command access from the UART, pipelined CPU operations,
123
        a prefetch cache and more.  Other solutions will need to be found.
124 7 dgisselq
\end{enumerate}
125
 
126
Of course, if someone just wants the functionality of a small, cheap, CPU,
127
this project does not fit that role very well.  While the S6 is not very
128 41 dgisselq
expensive at nearly \$70, it is still an order of magnitude greater than it's
129
CPU competitors in price.  This includes such CPU's as the Raspberry Pi Zero
130
(\$5), or even the TeensyLC (\$12).
131 7 dgisselq
 
132 41 dgisselq
% What performance gain can be expected?
133 7 dgisselq
 
134 41 dgisselq
If, on the other hand, what you want is a small, cheap, CPU that can be
135
embedded within an FPGA without using too much of the FPGA's resources, this
136
project will demonstrate that possibility as well as some utility.
137
Alternatively, if you wish to study how to get a CPU to work in a small,
138
constrained environment, this project may be what you are looking for.
139
 
140
Finally, because the Zip~CPU and the included ZipOS are as small and simple as
141
they are, the code base found here will be simpler to understand than the
142
code bases for some of these other projects.  For example, the Zip~CPU
143
instruction set is very simple.  With less than 40 instructions, it is much
144
easier to understand and learn than the ARM instruction set.  Further, unlike
145
the ARM, the entire specification for and description of the Zip~CPU is
146
publicly available.  Likewise, an operating system such as the ZipOS that has
147
less than \hbox{3,000} lines of code will be much easier to understand than any
148
Linux operating system--even if it has much less functionality.
149
 
150 7 dgisselq
\chapter{Architecture}
151
Fig.~\ref{fig:architecture}
152
\begin{figure}\begin{center}
153
\includegraphics[width=5in]{../gfx/s6bones.eps}
154 41 dgisselq
\caption{CMod S6 SoC Architecture: Zip~CPU and
155 7 dgisselq
        Peripherals}\label{fig:architecture}
156
\end{center}\end{figure}
157 41 dgisselq
shows the basic internal architecture of the S6~SoC.  In summary, it consists
158
of a CPU
159 7 dgisselq
coupled with a variety of peripherals for the purpose of controlling the
160 41 dgisselq
external peripherals of the S6~SoC: flash, LEDs, buttons, and GPIO.  External
161
devices may also be added on, and have been added on as part of this project,
162
such as an audio device, an external serial port, an external keypad, and an
163
external display.  All of these devices are then available for the CPU to
164
interact with.
165 7 dgisselq
 
166
If you are familiar with the Zip CPU, you'll notice this architecture provides
167
no access to the Zip CPU debug port.  There simply wasn't enough room on the
168 41 dgisselq
device.  Debugging the Zip~CPU will instead need to take place via other means,
169 7 dgisselq
such as dumping all registers and/or memory to the serial port on any reboot.
170
 
171 41 dgisselq
Further, the Zip~CPU has no ability to write to flash memory.  For this reason,
172
there exists an alternate CMod S6~SoC architecture, shown in
173 7 dgisselq
Fig.~\ref{fig:altarchitecture}.
174
\begin{figure}\begin{center}
175
\includegraphics[width=5in]{../gfx/altbones.eps}
176
\caption{Alternate CMod S6 SoC Architecture: Peripherals, with no
177
        CPU}\label{fig:altarchitecture}
178
\end{center}\end{figure}
179
Using this alternate architecture, it should be possible to test the peripherals
180
and program the flash memory.  Both architectures may be loaded into the flash,
181
together with the programming code for the Zip CPU.
182
 
183 36 dgisselq
The basic approach to loading the board is actually quite simple.  Using the
184
Digilent ADEPT JTAG configuration program, {\tt djtgcfg}, the alternate
185
configuration may be written directly to the device.  Once this alternate
186 41 dgisselq
configuration has been loaded, the flash may be examined and programmed using
187
the {\tt zipload} utility.  This utility uses Digilent's Asynchronous Parallel
188
Port interface (DEPP) to communicate with the device, and in particular to
189
tell the device what to write to the flash.  When writing to the flash,
190
the {\tt zipload} utility will program both a primary and an alternate
191
FPGA configuration into the configuration section of the flash, as well as
192
computer code into the rest of the flash.  Once complete, the system may then be
193 36 dgisselq
reloaded with the primary configuration file which will contain an image of
194
the CPU.  The CPU will then begin following the instructions found in flash
195
memory.
196 7 dgisselq
 
197
 
198 50 dgisselq
\chapter{Getting Started}
199
\section{Building the Compiler}
200
%% git clone
201
%% Setting zip_param_cis to zero
202
%% Setting ZIP_DIVIDE to zero
203
%% Setting ZIP_PIPELINED to zero        -- Disables the ZIP_ATOMIC instructions
204
%% Setting ZIP_THUMB to zero            -- Disables the CIS instructions
205
\section{Building the ADEPT Utilities}
206
% Install the digilent adept utilities
207
%   Expand the tar file
208
%   tar -xvzf digilent.adept.utilities_2.2.1-x86_64.tar.gz
209
%   Install them
210
%   cd digilent.adept.utilities_2.2.1-x86_64.tar.gz
211
%   sudo ./install.sh
212
%       Answer Y to install the binaries into /usr/local/bin, and again
213
%       to place the manual pages into /usr/local/man.
214
% Install the Digilent ADEPT Runtime
215
% Answer Y to store the libraries into /usr/local/lib64/digilent/adept
216
% Answer Y to install system binaries into /usr/sbin
217
% Answer Y to install data into /usr/share/digilent/adept/data
218
% Answer Y to install runtime configuration data files into /etc
219
%
220
\section{Building and Running the Host Software}
221
\section{Building the Board Software}
222
\section{Building the ZipOS}
223
 
224 36 dgisselq
\chapter{Software}
225 41 dgisselq
This chapter provides an overview of the software that is available to support
226
the S6~SoC.  This includes not only the RTL, the Makefiles, and the software
227
that will run on the Zip~CPU within the S6~SoC, but also the support software
228
necessary for communicating with the S6~SoC in its alternate configuration.
229
 
230 36 dgisselq
\section{Directory Structure}
231
\begin{itemize}
232
\item[{\tt trunk/bench}] Contains software for emulating the S6 without the S6
233
        present.
234
  \begin{itemize}
235
        \item[{\tt trunk/bench/cpp}]  All of the bench testing software is
236
                written in C++, so it is found in this directory.  Primary
237
                among these programs is the {\tt zip\_sim} program which will
238 41 dgisselq
                simulate the Zip~CPU within the S6~SoC.  Specifically, it
239 36 dgisselq
                simulates everything at or below the {\tt busmaster.v} level.
240 7 dgisselq
 
241 36 dgisselq
                Some, although not all, of the peripherals have been simulated
242
                and made a part of this simulation.  These include the
243
                Quad--SPI flash, the UART, and the LED's.
244
 
245
  \end{itemize}
246 41 dgisselq
\item[{\tt trunk/doc}] All of the documentation for the S6~SoC project may be
247 36 dgisselq
        found in this documentation directory.  Specifically, I would commend
248
        your attention to anything with a {\tt .pdf} extension, as these
249
        are the completed documents.  Among these you should find a copy of the
250
        GPL copyright under which this software is released, as well as a
251
        pre--built copy of this document.
252
  \begin{itemize}
253
        \item[{\tt trunk/doc/gfx}] Here is where the graphics are located in
254
                support of this specification document.
255
        \item[{\tt trunk/doc/src}] And here is where the \LaTeX files are
256
                kept that were used in building both this document as well as
257
                the GPL copyright.
258
  \end{itemize}
259 41 dgisselq
\item[{\tt trunk/rtl}] Verilog files.  The two top--level files are
260
        {\tt toplevel.v} for the primary top level module, and
261
        {\tt alttop.v} for the alternate load.
262 36 dgisselq
  \begin{itemize}
263 41 dgisselq
        \item[{\tt trunk/rtl/cpu}]      Verilog files containing the Zip~CPU
264 36 dgisselq
                core and peripherals.  The toplevel file here is the
265
                {\tt zipbones.v} file, although some of the peripherals, such
266
                as the {\tt ziptimer.v} are referenced independently.
267
  \end{itemize}
268
\item[{\tt trunk/sw}] The main software directory, primarily a repository
269
        for software subdirectories beneath it.
270
  \begin{itemize}
271
        \item[{\tt trunk/sw/dev}]  This directory holds a variety of
272 41 dgisselq
                simple programs for the Zip~CPU, such as {\tt helloworld},
273 36 dgisselq
                {\tt doorbell} and {\tt doorbell2}, as well as software drivers
274
                for various peripherals, such as the real--time clock simulator,
275
                and the keypad and display device drivers.
276
        \item[{\tt trunk/sw/host}]  This directory holds support software which
277
                can be built on and run on the host machine.  Building this
278
                software will involve adjusting the Makefile so that it knows
279
                where your local ADEPT installation directory is.\footnote{Many
280
                of the programs also depend upon the serial number of my CMod
281
                S6 device.  This will need to be adjusted in any new install.}
282
                Once built, you will find a variety of very useful programs
283
                within here.
284
        \item[{\tt trunk/sw/zipos}]  This directory contains the source code for
285
                        a rudimentary, very basic, operating system that I
286
                        call the ZipOS.
287
  \end{itemize}
288
\end{itemize}
289
 
290 41 dgisselq
\section{Zip CPU Tool Chain}
291
To build programs for the Zip~CPU, you will need the Zip~CPU toolchain.  You
292
can find this as part of the Zip~CPU project, available at OpenCores.  Building
293
the Zip~CPU project should result in a set of binaries in the
294
\hbox{\tt zipcpu/trunk/sw/install/cross-tools/bin} directory.  Make this
295
directory a part of your path, and you should be able to build the CMod S6
296
Zip~CPU software.  Specifically, you will need to use {\tt zip-gcc},
297
{\tt zip-as}, {\tt zip-ld}, and {\tt zip-cpp}.  Other tools, such as
298
{\tt zip-objdump} and {\tt zip-readelf}, may also prove to be very useful when
299
trying to figure out what is going on within the SoC.
300 36 dgisselq
 
301
\section{Bench Test Software}
302
 
303
Bench testing software currently consists of the {\tt zip\_sim} program found
304
within {\tt trunk/bench/cpp}.  This program requires Verilator to run, and
305 41 dgisselq
simulates in a cycle accurate fashion, the entire S6~SoC from {\tt busmaster.v}
306 36 dgisselq
on down.  Further, the external Quad--SPI flash memory, UART, and LED's are
307
also simulated, although the 2--line display, audio, and keypad are not.
308
 
309
\section{Host Software}
310 41 dgisselq
Several software programs have been built to support the S6~SoC from a nearby
311
host.  These programs include:
312 36 dgisselq
\begin{itemize}
313
\item {\tt dumpuart}: My current approach to debugging involves
314
        dumping the state of the registers and memory to the
315
        UART upon reboot.  The dumpuart command found here is
316
        designed to make certain that the UART is first set
317 41 dgisselq
        up correctly at 9600~Baud, and second that everything
318 36 dgisselq
        read from the UART is directly sent to both a file and
319
        to the screen.  In this fashion, it is similar to the
320
        UNIX {\tt tee} program, save for its serial port
321
        attachment.
322
\item {\tt readflash}: As I am loathe to remove anything from
323
        a device that came factory installed, the
324
        {\tt readflash} program reads the original installed
325
        configuration from the flash and dumps it to a file.
326
 
327 41 dgisselq
        This program is only useful when the alternate configuration is loaded.
328
 
329
\item {\tt wbregs}: This program offers a capability very similar to the
330
        PEEK and POKE capability Apple user's may remember from before the
331
        days of Macintosh.  {\tt wbregs <address>} will read from the
332
        Wishbone bus the value at the given address.  Likewise
333
        {\tt wbregs <address> <value>} will write the given value into the
334
        given address.  While both address and value have the semantics of
335
        numbers acceptable to {\tt strtoul()}, the address can also be a named
336
        address.  Supported names can be found in {\tt regdefs.cpp}, and their
337
        register mapping in {\tt regdefs.h}.
338
 
339
        As examples, {\tt wbregs version}, will return the build date, or
340
        version of the RTL.  {\tt wbregs spio} reads the special purpose
341
        I/O register, and {\tt wbregs gpio 0xffffffff} will set all output
342
        GPIO ports high while {\tt wbregs gpio 0xffff0000} will set all
343
        output GPIO ports to ground.
344
 
345
        This program is only useful when the alternate configuration is loaded.
346
 
347
\item {\tt zipload}: This is the primary program you will need to get your
348
        software loaded on the CMod.  It takes three arguments.  The first is
349
        the name of the primary Xilinx configuration file, the second is the
350
        name of an alternate Xilinx configuration file, and the third is the
351
        name of the Zip~CPU program you wish to write to Flash memory.
352
 
353
        Each of these arguments is optional.  For example, if only one
354
        configuration file is given, the loader will load the primary
355
        configuration.  If only one Zip~CPU program is given, the program will
356
        be loaded into the program memory area and the configuration file areas
357 36 dgisselq
        will be left untouched.
358 41 dgisselq
 
359
        This program is only useful when the alternate configuration is loaded.
360 36 dgisselq
\end{itemize}
361 41 dgisselq
\section{Zip CPU Programs}
362
The following are a list of simple, independent, single-task example programs
363
that will run on the S6~SoC:
364 36 dgisselq
\begin{itemize}
365
\item {\tt helloworld}: The first program any programmer should build,
366
        ``Hello, world!''  This program sends the string, ``Hello, world!''
367
        over the UART connection once per second.  It is a very valuable
368
        program because, if you can get this program running, you know you have
369
        a lot of things working and working correctly.  For example, running
370
        this program means you can run the {\tt zip-gcc} compiler, load
371 50 dgisselq
        the auxiliary configuration, load the program info flash memory, load
372 36 dgisselq
        the primary configuration, and read from the UART port.  It also means
373
        that you must have the UART port properly configured and wired to your
374
        CMod board.
375
\item {\tt doorbell}: This annoying program verifies the functionality of the
376
        audio device by playing a doorbell sound to the audio port.  It will
377
        then wait ten seconds, and play the doorbell sound again (and again,
378
        and again).  (It gets old after a while ...)
379
\item {\tt doorbell2}: This adds to the functionality of the {\tt doorbell}
380
        program a wait for keypress, and a display of the current time on the
381
        2--line display.  While almost our fully functional program, this
382
        does not include any menus to configure the device or set time, since
383
        it doesn't include any keypad functionality.
384
\item {\tt kptest}: A test of whether or not they keypad driver works.  When
385 41 dgisselq
        run, anytime a key is pressed, the key's associated printable character
386
        will be sent to the UART.  Further, pressing an `F' on the keypad will
387
        also send a newline over the UART, in case you wish to keep your lines
388
        from getting too long.
389 36 dgisselq
\end{itemize}
390
\section{ZipOS}
391 41 dgisselq
The ZipOS is a brand new operating system, specifically designed to run on the
392
ZipCPU.  It is both pre--emptive and multitasking, although with many
393
limitations.  Those familiar with the internals of other operating systems, such
394
as Linux, may laugh that I call this an Operating System at all: it has no
395
memory management unit, no paging, no virtual memory, no file I/O access, no
396
network stack, no ability to dynamically add or remove tasks, indeed it hardly
397
has any of the things most often associated with an Operating System.  It does,
398
however, handle interrupts, support multiple pre--emptive tasks in a
399
multitasking, timesharing fashion, and it supports some very basic and
400
rudimentary system calls.  In a similar fashion, it does contain just about all
401
of the functionality necessary for a multi--tasking microcontroller built
402
around a do--forever loop.  For its size, I consider it an impressive
403
achievement.  You are welcome to disagree with me, however.
404 36 dgisselq
 
405 41 dgisselq
This version of the ZipOS starts in the {\tt resetdump.s} code, so that upon
406 36 dgisselq
any startup the ZipOS will dump register contents, the BusError register, and
407
any scope contents to the UART.  This can take some time, so you may wish to
408 41 dgisselq
configure what you really wish to send--if anything.  If desired,
409
{\tt resetdump} can also be configured to also dump the entire memory as well
410
while only using 9~memory locations.  All of this is quite useful in case the
411
Zip~CPU encounters a bus error or other sort of error that causes it to hang,
412
stall, or reboot, as the CPU registers are very carefully not touched prior to
413
being sent to the UART output port.  This extends to all registers save the
414
supervisor PC and CC registers, which would've been reset by a reboot anyway.
415 36 dgisselq
 
416 41 dgisselq
{\tt resetdump.s} then calls a rudimentary bootloader, to load the parts of
417 36 dgisselq
the ZipOS that need to run faster into Block RAM.  The choice of what parts
418
to load into Block RAM is made on a file by file basis, and found within
419
the linker script, {\tt cmodram.ld}.
420
 
421
Upon completion, {\tt resetdump.s} calls the entry routine for the O/S,
422
{\tt kernel\_entry()} found in {\tt kernel.c}.  This is the main task loop for
423
the entire O/S, and worth studying if you are interested in understanding how
424
the O/S works.
425
 
426
The user tasks are found (mostly) within {\tt doorbell.c}, also found in the
427
ZipOS directory.  This file contains two kernel entry points, {\tt kntasks()},
428 41 dgisselq
which returns the number of user tasks the kernel needs to know about, and
429 36 dgisselq
{\tt kinit()}, which builds each of the tasks and connects their file
430
descriptors to the various devices they will be referencing.
431 41 dgisselq
\subsection{System Calls}
432
The ZipOS supports a variety of system calls, listed here:
433 36 dgisselq
\begin{itemize}
434 41 dgisselq
\item {\tt int wait(unsigned event\_mask, int timeout)}
435
 
436
        Halts the execution of a process until an event matching the
437
        {\tt event\_mask} takes place, or a {\tt timeout} (in milliseconds)
438
        has been reached.  The events that can take place are a
439 36 dgisselq
        bitmask of the various interrupts the CPU supports, together with a
440 41 dgisselq
        bitmask of the software interrupt values found in {\tt swint.h}.
441 36 dgisselq
 
442 41 dgisselq
        The {\tt timeout} value can either be zero, to return immediately with
443
        the list of events that have taken place, negative, to wait
444
        indefinitely, or a positive number of milliseconds in order to wait at
445
        least that time for the event of interest to take place.
446 36 dgisselq
 
447 41 dgisselq
        Waiting on a zero event mask allows a process to sleep for any number
448
        of requested milliseconds.
449 36 dgisselq
 
450
        When wait returns, any events returned by the wait have been cleared.
451
 
452
        The other thing to be aware of is that events may accumulate before the
453 41 dgisselq
        wait system call.  Nothing within the wait system call clears prior
454
        events.  These prior events be returned and cleared, though, if
455
        the wait call indicates an interest in those events.
456
 
457
        Upon return, the a bitmask of events that have taken place will be
458
        returned to the process.
459
 
460
\item {\tt int clear(unsigned event\_mask, int timeout)}
461
 
462
        This system call works closely with the wait system call.  Indeed,
463
        when the timeout given is zero, the two function nearly identically.
464
        It clears any of the requested events which may be pending, and returns
465
        a bit mask of the events that were pending and cleared.
466
 
467
        However, if the timeout is given (and is positive), then {\tt clear()}
468
        starts a timer.  Once the timer has completed, a timeout event,
469
        {\tt SWINT\_TIMEOUT}, will be generated and made available to the task
470
        to wait upon it.
471
 
472
        In a similar fashion, if the timeout is negative, then any pending
473
        timeout is cleared.
474
 
475
\item {\tt void post(unsigned event\_mask)}
476
 
477 50 dgisselq
        Certain software devices, such as the real--time clock and the doorbell
478 36 dgisselq
        reader, need the ability of being able to post events to any listener
479
        within the O/S.  The POST system call allows them to POST events in
480
        this manner.
481 41 dgisselq
 
482
        Were the ZipOS to be closer to a secure O/S, it might restrict what
483
        events each process could post.  Right now, however, any process can
484
        post any event--whether it be a hardware or a software generated event.
485
 
486
\item {\tt void yield(void) }
487
 
488
        This is simply a way of being nice to other processes.  This system
489 36 dgisselq
        call takes no arguments and simply asks the scheduler to schedule the
490
        next process.  It does not take this process off of the ready to run
491
        list, so the next process may be this one.  However, since the scheduler
492 41 dgisselq
        is a round--robin scheduler, it will only return to this process once
493
        it has gone through all other available processes checking whether or
494
        not they are available to be run.
495
 
496
\item {\tt int read(int fid, void *buf, int len)}
497
 
498
        This is roughly the same system call as the POSIX read() system
499
        call.  It reads some number of words (not octets) from the file
500
        descriptor (device) specified by {\tt fid} into the memory address
501
        range starting at {\tt buf} and {\tt len} words long.  If the memory
502
        requested is unavailable,
503 36 dgisselq
        the read will wait until it is available, possibly indefinitely.
504 41 dgisselq
 
505
        Upon return, the {\tt read()} function call returns the number of
506
        words actually read, or a negative value on error.
507
 
508
        As a future feature, a {\tt read()} system call should be able to be
509
        interrupted by a timeout.  This feature has not (yet) been implemented,
510
        but will likely be implemented via a combination of the {\tt clear()}
511
        system calls ability to set timeouts together with the {\tt read()}
512
        functions ability to wait for available data.
513
 
514
\item {\tt int write(int fid, void *buf, int len)}
515
 
516
        This is roughly the same system call as the POSIX {\tt write()} system
517 36 dgisselq
        call.  It writes some number of memory addresses (words, not octets),
518 41 dgisselq
        to the given file descriptor.  If there is no reader task or device
519
        associated with the file descriptor, then the {\tt write()} system
520
        call will block forever once the internal pipe fills up.  Otherwise,
521
        if something is reading from the file descriptor's pipe, the writing
522
        task will only stall until the data is either written to the receiving
523
        task, or copied into a memory buffer.
524
 
525
        Upon return, the {\tt write()} system call returns the number of words
526
        actually written to the system pipe (not necessarily the number that
527
        have been read), or a negative value on error.
528
 
529
\item {\tt unsigned time(void) }
530
 
531
        Returns the number of seconds since startup.  Eventually, this will
532 36 dgisselq
        return the number of seconds since January 1, 1970, and be identical
533
        to the UNIX system time() command, but that may not happen on this
534
        project.
535 41 dgisselq
 
536 36 dgisselq
% \item SEMGET
537
% \item SEMPUT
538 41 dgisselq
 
539
\item {\tt void *malloc(void)}
540
 
541
        Allocates memory from the system/kernel heap.  This is a very low
542
        overhead memory allocator that, while it does allocate memory, cannot
543
        free it later.  It is nearly 100\% efficient since only one memory
544
        address, the top of the heap, is used to determine what memory has
545
        been allocated.
546
 
547
\item {\tt void free(void *buf)}
548
 
549
        This function is a do--nothing stub.
550
 
551 36 dgisselq
\end{itemize}
552
\subsection{Scheduler}
553 41 dgisselq
The ZipOS currently supports only a round--robin scheduler.  Tasks are executed
554 36 dgisselq
in the order they were created, as long as they are available to be executed.
555
If no tasks are available to be run, the Scheduler will run the idle task which
556
puts the CPU to sleep while waiting for an interrupt.
557
 
558 7 dgisselq
\chapter{Operation}
559 41 dgisselq
The {\tt doorbell} program has been built to illustrate the operation of both
560
the Zip~CPU, the ZipOS, as well as showing off how all of the various
561
peripherals work.  It was envisioned after my family and I experienced an
562
unexpected visitor during the wee hours of the morning.  The {\tt doorbell}
563
program is designed to couple the doorbell and the exterior lights to a
564
single button.  Hence, when the doorbell to the house is pressed, the exterior
565
light is turned on for a half an hour.  This, then, would make it difficult
566
for someone to see inside during this time.
567 7 dgisselq
 
568 41 dgisselq
This chapter will present an example of how the {\tt doorbell} program works.
569
 
570
To run the {\tt doorbell} program, you will first need to build the various
571
RTL and software support programs just to get the {\tt doorbell} program on
572
the device:
573
\begin{enumerate}
574
\item First build the primary and alternate .bit files by building
575
        with {\tt toplevel.v} and then {\tt alttop.v} as your top--level
576
        RTL files.  I like to place my Xilinx work directoy into
577
        {\tt trunk/xilinx}, and if you do the same the load scripts that
578
        are referenced next will work.
579
 
580
        Before going on, double check that both configuration .bit files were
581
        created, that they each fit within the device (there would be errors
582
        if they did not), and that they met their respective timing
583
        requirements.
584
 
585
\item Then, load the alternate bit file into the S6~SoC.  You will need
586
        the Digilent tools installed in order to do this.  Having done so,
587
        you may run {\tt make axload} from the {\tt trunk/} directory.
588
        If you didn't run the Xilinx ISE from within {\tt tunk/xilinx},
589
        you may need to find your .bit files and adjust where they load
590
        from, but this should be fairly straight--forward from the instructions
591
        within the Makefile.
592
\item Build the software found in the host directory.  This sotware depends
593
        upon Digilent's ADEPT toolsuite, so you will need to adjust the
594
        Makefile so that it references the toolsuite.
595
 
596
        {\em Note:} Currently, the host software is serial--number locked to
597
        my own CMod--S6.  Until I fix this and make it more user friendly,
598
        you'll want to switch your software to reference your own CMod.
599
        To do this, look for the {\tt "SN:\ldots"} lines within the `*.cpp'
600
        files.  Currently, there is one such line within wbregs, another
601
        within readflash, and the last within zipload.  To find our your own
602
        device's serial number, type {\tt djtgcfg enum}.  It should find one
603
        (or more) CMod devices connected to your system, and list each of
604
        their serial numbers.
605
 
606
        Once you've done this, you should have a working set of host support
607
        programs: readflash, wbregs, and zipload.
608
 
609
\item Using {\tt wbregs}, you may now test your configuration.  {\tt wbregs}
610
        works like the peek and poke programs from a generation ago.
611
        {\tt wbregs <address>} will return the value of the memory (or
612
        peripheral) found at the {\tt <address>}.  Some addresses have names,
613
        such as {\tt UART}, {\tt SPIO}, {\tt GPIO}, {\tt PIC}, and so forth.
614
        These names are found in {\tt trunk/sw/host/regdefs.cpp}, and their
615
        mappings in {\tt trunk/sw/host/regdefs.h}.
616
 
617
        As examples, if you type {\tt wbregs version} you should be able
618
        to read the version (a.k.a. build date) from the currently installed
619
        .bit file.  Likewise if you type {\tt wbregs uart 65}, you should see
620
        an `A' (i.e. a 65) sent from the S6~SoC over the serial port.
621
        {\tt wbregs uart} by itself will read a single character from the
622
        serial port and so on.
623
 
624
        You should be able to test all of your peripherals by hand using
625
        {\tt wbregs}: GPIO, Flash, UART, keypad, buttons, LEDs, Interrupt
626
        controller, timer, etc.\footnote{The display and audio devices may be
627
        more difficult since these require multiple interactions over the
628
        course of a short period of time to work.}  This should give you some
629
        confidence in how these peripherals work, should you need it.  You
630
        may also use this time to verify that your wiring is properly set up.
631
 
632
\item If you wish to make certain you keep track of the original Flash bitfile
633
        that came with your device, you may read it out using {\tt readflash}.
634
        This will dump the contents of you flash onto {\tt qspiflash.bin}.
635
        You may then wish to change the name of this file, lest you overwrite
636
        it by running {\tt readflash} again later.
637
 
638
\item At this point, it's time to build the programs for the Zip~CPU.  To do
639
        this, you will first need to download the Zip~CPU project.  When
640
        building that project, it will create a directory of programs
641
        (including its compiler) in
642
        {\tt zipcpu/trunk/sw/install/cross-tools/bin}.
643
        Include this directory into your path.
644
 
645
\item Change into {\tt trunk/sw/dev} to build some device testing files.
646
        {\tt make} by itself should build some of these.
647
 
648
        You should now be ready to run some basic tests on the S6~SoC.
649
 
650
\item Let's test the UART first: back out to the main directory {\tt trunk/},
651
        and run\break
652
        {\tt sw/host/zipload sw/dev/helloworld} and then {\tt make xload}.
653
        Now, examine your UART port.  (You do have the PModUSBUART installed
654
        and connected, right?)  You should see ``Hello, world!'' printed
655
        over and over again once each second.
656
 
657
\item You may try other test files in a similar manner, such as
658
        {\tt trunk/sw/dev/doorbell} and\break
659
        {\tt trunk/sw/dev/doorbell2}.  The first of these will just play the
660
        doorbell over and over again, whereas the second one will wait for a
661
        button press before playing the doorbell sound.
662
 
663
\item Now let's go and build the ZipOS together with it's user files.  To do
664
        this, enter into the {\tt trunk/sw/zipos} directory and type
665
        {\tt make}.  If all goes well, you should now have a program named
666
        {\tt trunk/sw/zipos/doorbell} which you can load into your S6~SoC as
667
        well.
668
 
669
\item A final load, and we'll be done.  To do this, make {\tt axload} again,
670
        and this time {\tt sw/host/zipload xilinx/toplevel.bit sw/zipos/doorbell}.
671
        When you power on your device the next time, or after you
672
        {\tt make xload}, you'll find the ZipOS running on the Zip~CPU.
673
 
674
\item To test the doorbell, press one of the buttons.  You should hear a
675
        doorbell coming out of the PModAMP2 audio port.
676
 
677
\item You should also be able to read the time on the LCD display.  It will be
678
        the wrong time (the number of seconds since power on \ldots).  To set
679
        the correct time, press `A' on the keypad and then type in the 6--digit
680
        time: HHMMSS.
681
 
682
        If you make a mistake, the `C' key can be used for a backspace.
683
 
684
\item You can also set the time of ``dawn'' by pressing a `B' on the keypad
685
        and then typing in the time ``dawn'' should be at.  The same is
686
        true for dusk, only you'll need to start that by pressing a `C' on the
687
        keypad.
688
 
689
\item Now, when the doorbell rings, the LCD will show the time the doorbell
690
        was pressed.  If the time is at night, the ourdoor light (oops, I
691
        mean LED\#3) will turn on for a half an hour (currently set to
692
        30~seconds, since I don't have the patience to wait a half hour while
693
        testing).
694
\end{enumerate}
695
 
696
Now that you've made it this far, you can go back and examine what was done
697
along the way, and perhaps even modify it for your own personal application.
698
 
699 7 dgisselq
\chapter{Registers}
700
There are several address regions on the S6~SoC, as shown in
701
Tbl.~\ref{tbl:memregions}.
702
\begin{table}[htbp]
703
\begin{center}\begin{tabular}{|p{0.75in}|p{0.75in}|p{0.5in}|p{3.0in}|}\hline
704
\rowcolor[gray]{0.85} Start & End & & Purpose \\\hline\hline
705 50 dgisselq
\scalebox{0.9}{\tt 0x0000400} & \scalebox{0.9}{\tt 0x00043f} & R/W & Peripheral I/O Control \\\hline
706
\scalebox{0.9}{\tt 0x0000800} & \scalebox{0.9}{\tt 0x00080f} & R/(W) & Debugging scope\\\hline
707
\scalebox{0.9}{\tt 0x0004000} & \scalebox{0.9}{\tt 0x03fff} & R/W & 16kB On-Chip Block RAM \\\hline
708
\scalebox{0.9}{\tt 0x1000000} & \scalebox{0.9}{\tt 0x7fffff} & R & 16~MB SPI Flash memory\\\hline
709 7 dgisselq
\end{tabular}
710
\caption{Address Regions}\label{tbl:memregions}
711
\end{center}\end{table}
712
In general, the address regions that are made up of RAM or flash act like
713
memory.  The RAM can be read and written, and the flash acts like read only
714 41 dgisselq
memory.\footnote{The Flash can be written, but only by an external command
715 50 dgisselq
while in the alternate configuration.}  Furthermore, {\em only} the RAM offers
716
the capability of byte-wise writes across the bus.
717 7 dgisselq
 
718 41 dgisselq
This isn't quite true with the other address regions.  Accessing the I/O
719
region, while it will act like a memory, it may also have side-effects.  For
720
example, reading from the debugging scope device's data port will read a word
721
from the scope's buffer and advance the buffer pointer.  (More on that later.)
722 7 dgisselq
 
723 41 dgisselq
Finally, to keep the address decoder simple, many of these addresses are
724
multiply mapped.  Hence you may find the I/O peripherals mapped throughout the
725 50 dgisselq
{\tt 0x0400}--{\tt 0x07ff} address region.  Other memory addresses are similarly
726 41 dgisselq
overmapped.  This overmapping was a resource minimization feature, to get the
727 50 dgisselq
bus to fit within a minimum number of FPGA resources.  For this reason,
728
addresses not explicitly defined in this specification are undefined.
729
Likewise, attempting to write a byte or half-word to anything other than RAM
730
will have undefined results.
731 41 dgisselq
 
732 36 dgisselq
\section{Peripheral I/O Control}
733 7 dgisselq
Tbl.~\ref{tbl:ioregs}
734
\begin{table}[htbp]
735
\begin{center}\begin{reglist}
736 50 dgisselq
PIC    &\scalebox{0.8}{\tt 0x0400} & 32 & R/W & Interrupt Controller \\\hline
737
BUSERR &\scalebox{0.8}{\tt 0x0404} & 32 & R & Last Bus Error Address\\\hline
738
TIMER   &\scalebox{0.8}{\tt 0x0408} & 32 & R/W & ZipTimer\\\hline
739
WDOG   &\scalebox{0.8}{\tt 0x040c} & 32 & R/W & Watchdog Timer\\\hline
740
PWM    &\scalebox{0.8}{\tt 0x0410} & 32 & R/W & PWM Audio Controller\\\hline
741
SPIO   &\scalebox{0.8}{\tt 0x0414} & 32 & R/W & Special Purpose I/O, Keypad, LED Controller \\\hline
742
GPIO   &\scalebox{0.8}{\tt 0x0418} & 32 & R/W & GPIO Controller \\\hline
743
UART   &\scalebox{0.8}{\tt 0x041c} & 32 & R/W & UART data\\\hline
744
VERSION &\scalebox{0.8}{\tt 0x0420} & 32 & R & Build date\\\hline
745 7 dgisselq
\end{reglist}
746
\caption{I/O Peripheral Registers}\label{tbl:ioregs}
747
\end{center}\end{table}
748
shows the addresses of various I/O peripherals included as part of the SoC.
749 41 dgisselq
We'll walk through each of these peripherals in turn, describing how they work.
750 7 dgisselq
 
751 36 dgisselq
\subsection{Interrupt Controller}
752 41 dgisselq
The programmable interrupt controller (PIC) is identical to the one found with
753
the ZipSystem.  The layout of the PIC bits is shown in Fig.~\ref{fig:picreg}.
754 36 dgisselq
\begin{figure}\begin{center}
755
\begin{bytefield}[endianness=big]{32}
756
\bitheader{0-31} \\
757
        \bitbox{1}{E}
758 41 dgisselq
        \bitbox{15}{Enabled Ints}
759 36 dgisselq
        \bitbox{1}{A}
760 41 dgisselq
        \bitbox{15}{Currently Active Ints}
761 36 dgisselq
        \\
762
\end{bytefield}
763
\caption{Programmable Interrupt Control (PIC) Register}\label{fig:picreg}
764
\end{center}\end{figure}
765
This controller supports up to fifteen interrupts, however only twelve are
766 41 dgisselq
defined within the SoC.  These are listed in Tbl.~\ref{tbl:hw-ints}.
767
\begin{table}[htbp]
768
\begin{center}\begin{tabular}{|p{0.9in}|p{0.75in}|p{3.75in}|}\hline
769
\rowcolor[gray]{0.85} Name & Bit Mask & Description \\\hline\hline
770
INT\_BUTTON & 0x001 & A Button has been pressed. \\\hline
771
INT\_BUSERR & 0x002 & A Wishbone bus error has taken place\\\hline
772
INT\_SCOPE  & 0x004 & The Scope has completed its collection\\\hline
773
INT\_RTC    & 0x008 & An alarm or timer has taken place (assuming the RTC
774
                is installed, and includes both alarm or timer)\\\hline
775
INT\_TIMA   & 0x010 & Timer-A has reached zero\\\hline
776
INT\_TIMB   & 0x020 & Timer-B has reached zero\\\hline
777
INT\_UARTRX & 0x040 & A character has been received via the UART\\\hline
778
INT\_UARTTX & 0x080 & The transmit UART is idle, and ready for its next
779
                character.\\\hline
780
INT\_KEYPAD & 0x100 & One of the keypad wires has been pulled low. \\\hline
781
INT\_AUDIO  & 0x200 & The audio device is ready for its next sample\\\hline
782
INT\_GPIO   & 0x400 & The GPIO input lines have changed values.\\\hline
783
INT\_FLASH  & 0x800 & The flash device has finished either its erase or
784
                write cycle, and is ready for its next command. (Alternate
785
        config only.)\\\hline
786
\end{tabular}
787
\caption{Hardware Interrupts}\label{tbl:hw-ints}
788
\end{center}\end{table}
789
If any interrupt line is active, the PIC controller
790
will have that bit set among its active set.  Once set, the bit and hence the
791 36 dgisselq
interrupt can only be cleared by writing to the controller.  Interrupts can
792
also be enabled as well.  The enabled bit mask controls which interrupt lines
793
are permitted to interrupt the CPU. Hence, just because an interrupt is active
794 41 dgisselq
doesn't mean it will interrupt the CPU--the corresponding bit in the enable
795
mask must be set as well.
796 36 dgisselq
Finally, then {\tt A} or {\tt ANY} bit will be high if any interrupts are both
797
enabled and active, whereas the {\tt E} or global interrupt enable bit can be
798
set to allow the PIC to interrupt the CPU or cleared to disable all interrupts.
799 7 dgisselq
 
800 36 dgisselq
To keep operations on this register atomic, most of the bits of this register
801
have special meanings upon write.  The one exception to this is the global
802
interrupt enable bit.  On any write, interrupts will be globally enabled or
803
disabled based upon the value of this bit.  Further, the {\tt ANY} bit is a
804
read only bit, so writes to it have no effect.
805
 
806
Enabling specific interrupts, via writes to the enable lines, are different.
807
To enable a specific interrupt, enable all interrupts and
808 41 dgisselq
set the mask bit associated with the specific interrupt you wish to enable.
809
Hence writing a {\tt 0x80010000} will enable interrupt line zero
810
({\tt INT\_BUTTON}), while also enabling all previously enabled interrupts.
811 36 dgisselq
To disable a specific interrupt, disable all interrupts and write a one to the
812
enable line of the interrupt you wish to disable.  In this fashion, writing a
813
{\tt 0x00010000} will disable all interrupts and leave interrupt line zero
814
disabled when the interrupts are re--enabled later, whereas {\tt 0x07fff0000}
815
will disable all specific interrupts.
816
 
817
Interrupts are acknowledged in a fashion similar to enabling interrupts.  By
818
writing a `1' to the active bit mask, the interrupt will be acknowledged and
819
reset, whereas writing a `0' leaves the interrupt untouched.  In this fashion,
820
as individual interrupts are handled, a `1' may be written to this bottom mask
821 50 dgisselq
to clear the interrupt.  Be aware, however, that any write for the purpose of
822
acknowledging an interrupt will also globally enable or disable interrupts.
823 36 dgisselq
 
824
\subsection{Last Bus Error Address}
825 41 dgisselq
The Bus Error peripheral simply records the address of the last bus error,
826
and sets an interrupt upon receiving a bus error.  (The interrupt itself
827
is kind of useless ...) The address can be useful when debugging.  While the
828
peripheral may only be read,
829 7 dgisselq
setting it is really as easy as creating a bus error and trapping the result.
830 36 dgisselq
Another use for this is upon any reboot, it is possible to read the address
831
of the last bus error and perhaps learn something of what caused the CPU to
832
restart.
833 7 dgisselq
 
834 36 dgisselq
\subsection{ZipTimer}
835 50 dgisselq
The S6~SoC contains two ZipTimers, one general purpose and one watchdog,
836
available for the CPU to use.  These are both countdown timers.  Writing any
837
non--zero value to them will cause them to immediately start counting down
838
from that value towards zero, and to interrupt the CPU upon the transition to
839
zero.  Writing a new value while the timer is
840 41 dgisselq
running will cause that new value to automatically load into the timer and
841
start counting from there.  Writing a zero to the timer disables the timer, and
842
causes it to stop.
843 7 dgisselq
 
844 50 dgisselq
The general purpose ZipTimer can be set to auto reload by setting the top bit
845
as well as the interval.  When so set, the timer will automatically
846 36 dgisselq
load it's last set value upon reaching zero and interrupting the CPU.  This
847
effectively turns it into an interrupt timer if desired.  To set this feature,
848
write to the timer the number of clock ticks before an interrupt, but also set
849 41 dgisselq
the high order bit.  In this fashion, writing a {\tt 0x8001387f} will interrupt
850 36 dgisselq
the CPU every millisecond, starting one millisecond after the write takes place
851 41 dgisselq
(assuming an 80~MHz system clock).\footnote{Note that, since the timer spends
852
a cycle at zero, setting it for a 80,000 cycle period requires setting the
853
timer value to one less than 80,000.}
854 7 dgisselq
 
855 50 dgisselq
The watchdog timer has been wired for a different purpose.  It does not support
856
auto reload, nor will it interrupt the CPU.  When this timer transitions to
857
zero, the CPU will be rebooted.  One way to use this timer would be in
858
conjunction with the general purpose timer, and to write a number to it upon
859
any entry to the interrupt service routine.  If given enough time, this would
860
cause the CPU to reboot if for any reason it locked up and failed to interrupt
861
at the general timer interrupt request time.
862 36 dgisselq
 
863 50 dgisselq
The ZipOS uses the ZipTimer for task swapping.  By setting the timer for
864 41 dgisselq
1~ms, the ZipOS examines every task for a potential task swap every millisecond.
865
Of course, if the various tasks are running from Flash at 52~clocks per
866
instruction, this means that as few as 1,538~instructions may be executed
867
between timer interrupts, but this can be tuned if necessary for better
868
performance.
869
 
870 36 dgisselq
\subsection{PWM Audio Controller}
871
The bit fields of the PWM Audio controller are shown in Fig.~\ref{fig:pwmreg}.
872 7 dgisselq
\begin{figure}\begin{center}
873
\begin{bytefield}[endianness=big]{32}
874
\bitheader{0-31} \\
875 36 dgisselq
        \bitbox{10}{Unused}
876
        \bitbox{1}{S}
877
        \bitbox{1}{G}
878
        \bitbox{3}{}
879
        \bitbox{1}{E}
880
        \bitbox{16}{Sample}
881
        \\
882
\end{bytefield}
883
\caption{PWM Audio Controller Bitfields}\label{fig:pwmreg}
884
\end{center}\end{figure}
885
This controller has been designed for easy writing.  To send a sample to the
886
PWM audio controller, simply write the sample to the controller and clear the
887 41 dgisselq
PWM audio interrupt---{\em in that order}.  When the audio interrupts the CPU
888
again, it is ready for the next sample.  Do note, however, that the audio
889
interrupt can only be cleared once a new sample has been written to it.
890
Attempts to clear it prior to that will have no effect.  (This is why the
891
order matters.)
892 36 dgisselq
 
893
The audio sample rate has been fixed at 8~kHz.  While changing this rate is
894
easy to do within {\tt busmaster.v}, the rate itself takes some work to keep
895 41 dgisselq
up with, so I wouldn't recommend going faster.
896 36 dgisselq
 
897
The audio controller supports two additional functionalities, however.  The
898
first is that the {\tt E} bit will be set upon any read when or if the audio
899 41 dgisselq
controller is ready for another sample and the Audio interrupt has been
900
asserted.  By polling this bit, for example, the audio driver can be run without
901
using the interrupt functionality.
902 36 dgisselq
 
903
The second functionality has to do with the two auxiliary control bits present
904
in the PModAMP2 audio device.  These are the gain and shutdown bits.  To set
905
these bits, write a sample to the controller while also setting the {\tt E}
906
bit.  When the {\tt E} bit is set upon any write, the shutdown and gain bits
907
will also be set.  (Be aware, the shutdown bit is negative logic.)  Hence, one
908
may start this interface by writing a {\tt 0x0310000} to the device, and later
909
shut it back off by writing a {\tt 0x010000}.
910
 
911
\subsection{Special Purpose I/O}
912
 
913
Register {\tt SPIO}, as shown in Fig.~\ref{fig:spioreg},
914
\begin{figure}\begin{center}
915
\begin{bytefield}[endianness=big]{32}
916
\bitheader{0-31} \\
917 7 dgisselq
\begin{leftwordgroup}{Read}\bitbox[lrt]{16}{Zeros}
918
        \bitbox[lrt]{4}{Kpad}
919
        \bitbox[lrt]{4}{Kpad}
920
        \bitbox[lrt]{2}{00}
921
        \bitbox[lrt]{2}{Btn}
922
        \bitbox[lrt]{4}{LED} \\
923
\bitbox[lrb]{16}{}
924
        \bitbox[lrb]{4}{Col Out}
925
        \bitbox[lrb]{4}{Row In}
926
        \bitbox[lrb]{2}{}
927
        \bitbox[lrb]{2}{}
928
        \bitbox[lrb]{4}{}\end{leftwordgroup} \\
929
\begin{leftwordgroup}{Write}\bitbox[lrt]{16}{Ignored}
930
        \bitbox[lrt]{4}{Col}
931
        \bitbox[lrt]{4}{Col}
932
        \bitbox[lrt]{4}{LED}
933
        \bitbox[lrt]{4}{LED} \\
934
\bitbox[lrb]{16}{}
935
        \bitbox[lrb]{4}{Out}
936
        \bitbox[lrb]{4}{Enable}
937
        \bitbox[lrb]{4}{Enable}
938
        \bitbox[lrb]{4}{}\end{leftwordgroup} \\
939
\end{bytefield}
940
\caption{SPIO Control Register}\label{fig:spioreg}
941
\end{center}\end{figure}
942
is a Special Purpose Input/Output (SPIO) register. It is
943
designed to control the on-board LED's, buttons, and keypad.  Upon any read,
944
the register reads the current state of the keypad column output, the keypad
945
row input, the buttons and the LED's.  Writing is more difficult, in order to
946
make certain that parts of these registers can be modified atomically.
947
Specifically, to change an LED, write the new value as well as a `1' to the
948
corresponding LED change enable bit.  The same goes for the keypad column
949 41 dgisselq
output, a `1' needs to be written to the corresponding change enable bit in
950
order for a new value to be accepted.
951 7 dgisselq
 
952 36 dgisselq
As examples, writing a {\tt 0x0ff} to the {\tt SPIO} register will turn all
953
LED's on, {\tt 0x0f0} will turn all LED's off, and {\tt 0x011} and {\tt 0x010}
954
will turn LED0 on and then off again respectively.
955
 
956 41 dgisselq
The keypad is a little bit tricker.  To wait for a keypad interrupt, one needs
957
to set the column outputs to zero.  To do this, write a {\tt 0x0f00} to the
958
{\tt SPIO} register.  When a user then presses a key, one of the row inputs
959
will go low and an interrupt will be asserted.  The key must then be debounced,
960
and the ZipOS debounces keys for 5~ms.  Once debounced, the key may be read.
961
To do this, set half of the columns to zero, such as by writing a {\tt 0x0cf00}
962
to the {\tt SPIO} register.  If one of the row values is still zero, then
963
one of the two columns tested corresponded with the key.  This can then be
964
repeated until the correct column has been determined, at which point the
965
row can be read and the key known.
966
 
967 7 dgisselq
The controller will generate a keypad interrupt whenever any row input is
968 41 dgisselq
zero, and a button interrupt whenever any button value is a one.  This is a
969
level triggered interrupt, not edge triggered.  What that means is that,
970
once generated, the interrupt will need to be disabled until the key or button
971
is released---there will be no interrupt for the release, that part will need
972
to be done in software.
973 7 dgisselq
 
974 36 dgisselq
\subsection{General Purpose I/O}
975 7 dgisselq
The General Purpose Input and Output (GPIO) control register, shown in
976
Fig.~\ref{fig:gpioreg},
977
\begin{figure}\begin{center}
978
\begin{bytefield}[endianness=big]{32}
979
\bitheader{0-31} \\
980
\bitbox[lrtb]{16}{Current Input Vals (x16)}\bitbox[lrt]{16}{Current Output} \\
981
\bitbox[lrtb]{16}{Output Change Enable}\bitbox[lrb]{16}{Values (16-outs)}
982
\end{bytefield}
983
\caption{GPIO Control Register}\label{fig:gpioreg}
984
\end{center}\end{figure}
985
is quite simple to use: when read, the top 16--bits indicate
986
the value of the 16--input GPIO pins, whereas the bottom 16--bits indicate
987
the value being placed on the 16--output GPIO pins.  To change a GPIO pin,
988 36 dgisselq
write the new pin's value to this register, together with setting the
989 41 dgisselq
corresponding pin in the bit-mask represented by the upper 16--bits.  For
990
example, to set output pin 0, write a {\tt 0x010001} to the GPIO device.  To
991
clear output pin 0, write a {\tt 0x010000}.  Likewise pin two may be set by
992
writing a {\tt 0x020002}, and both pins may be set by writing {\tt 0x030003},
993
etc.  This makes it possible to adjust some output pins independent of the
994
others.
995 7 dgisselq
 
996
The GPIO controller, like the keypad or SPIO controller, will also generate
997
an interrupt.  The GPIO interrupt is generated whenever a GPIO input line
998 36 dgisselq
changes.  The interrupt is not selective: if any line changes, a GPIO interrupt
999 41 dgisselq
will be generated.  There are no ``do not care'' lines (although the GPIO
1000
controller could be easily adjusted to make such ``do-not-care'' lines if
1001
necessary \ldots).
1002 7 dgisselq
 
1003
Of the 16 GPIO inputs and the 16 GPIO outputs, two lines have been taken for
1004 41 dgisselq
I2C support, and a third has been stolen to make the PMod's fit on the
1005
board.  GPIO line zero, for both input and output, is an I2C data line,
1006 36 dgisselq
{\tt io\_sda}, and GPIO line one is an I2C clock line, {\tt io\_scl}.  If the
1007 41 dgisselq
output of either of these lines is set to zero, the GPIO controller will pull
1008
the line low.  Otherwise, the line is pulled up so that other devices may pull
1009
it low.  If either line is low, when the output control bit is high,
1010 7 dgisselq
it is an indicator that another device is sending data across these wires.
1011 41 dgisselq
Likewise GPIO input line 15 has been fixed to ground in order to support
1012
placing the keypad next to the S6~SoC.
1013 7 dgisselq
 
1014 36 dgisselq
\subsection{UART Data Register}
1015 41 dgisselq
Moving on to the UART \ldots although the UART module itself
1016
within the S6~SoC is highly configurable, as built
1017 7 dgisselq
the UART can only handle 9600~Baud, 8--data bits, no parity, and one stop bit.
1018 50 dgisselq
Changing this involves changing the constant {\tt UART\_SETUP} within
1019
{\tt toplevel.v}.  Further,  the UART has only a single byte data buffer, so
1020 41 dgisselq
reading from the port has a real--time requirement associated with it: the
1021 36 dgisselq
data buffer must be emptied before the next value is read.
1022 7 dgisselq
Attempts to read from this port will either return an 8--bit data value from
1023
the port, or if no values are available it will return an {\tt 0x0100}
1024 36 dgisselq
indicating that fact.  In general, reading from the UART port involves first
1025
waiting for the interrupt to be ready, second reading from the port itself,
1026
and then third immediately  clearing the interrupt.  (The interrupt cannot
1027
be cleared while data is waiting.)  Writing to the UART port is done in a
1028 41 dgisselq
similar fashion.  First, wait until the UART transmit interrupt is asserted
1029 50 dgisselq
(this will likely be most of the time), second, write to the UART port, and
1030
then third, clear the interrupt.  As with the read interrupt, clearing the
1031 41 dgisselq
transmit interrupt prior to writing to the port will have no effect.  Likewise,
1032
clearing the transmit interrupt after the byte has been written will have no
1033
affect either.
1034 7 dgisselq
 
1035 36 dgisselq
\section{Debugging Scope}
1036
The debugging scope consists of two registers, a control register and a data
1037 41 dgisselq
register.  It needs to be internally wired to 32--wires, internal to the
1038
S6~SoC, that will be of interest when debugging.  For further details on how
1039
to configure and use this scope, please see the {\tt WBSCOPE} project on
1040
OpenCores.
1041 36 dgisselq
 
1042
\section{On-Chip Block RAM}
1043
 
1044
The block RAM is the fastest memory available to the processor.  It is also
1045
the {\em only} writeable memory available to the processor.  Hence all
1046 41 dgisselq
non-constant program data {\em must} be placed into block RAM.  The Zip~CPU
1047 36 dgisselq
can also run instructions from the block RAM if extra speed is desired.  When
1048 41 dgisselq
runnning from block RAM, the Zip~CPU will nominally take 8~clocks per
1049
instruction, for an effective rate of 10~MIPS.  Loads or stores to block RAM
1050
will take one clock longer.
1051 36 dgisselq
 
1052
\section{Flash Memory}
1053
The flash memory has been arbitrarily sectioned into three sections, one for
1054
a primary configuration, a second section for an alternate configuration file,
1055
and the third section for any program and data.  These regions are shown in
1056
Tbl.~\ref{tbl:flash-addresses}.
1057
\begin{table}[htbp]
1058
\begin{center}\begin{tabular}{|p{0.75in}|p{0.75in}|p{0.5in}|p{3.0in}|}\hline
1059
\rowcolor[gray]{0.85} Start & End & & Purpose \\\hline\hline
1060 50 dgisselq
\scalebox{0.9}{\tt 0x1000000} & \scalebox{0.9}{\tt 0x10fffff} & R & Primary configuration space\\\hline
1061
\scalebox{0.9}{\tt 0x1100000} & \scalebox{0.9}{\tt 0x11fffff} & R & Alternate configuration space\\\hline
1062
\scalebox{0.9}{\tt 0x1200000} & \scalebox{0.9}{\tt 0x1ffffff} & R & Zip~CPU program memory\\\hline
1063 36 dgisselq
\end{tabular}
1064
\caption{Flash Address Regions}\label{tbl:flash-addresses}
1065
\end{center}\end{table}
1066 41 dgisselq
The host program {\tt zipload} can be used to load a Zip~CPU program and
1067 36 dgisselq
configuration files into this address space.  To use it, first load the
1068
alternate configuration into the FPGA.  Then pass it, as arguments, the
1069 41 dgisselq
primary, and alternate (if desired), configuration files followed by the
1070
Zip~CPU program file.  Then, when the primary configuration is loaded again,
1071
perhaps upon power up, the Zip~CPU will automatically start running from it's
1072 36 dgisselq
{\tt RESET\_ADDRESS}, {\tt 0x480000}.
1073
 
1074 41 dgisselq
When running from Flash memory, the Zip~CPU will nominally take 52~clocks per
1075 36 dgisselq
instruction, for an effective speed of about 1.5~MIPS.
1076
 
1077 41 dgisselq
When using {\tt zipload}, the first bit file argument will load the first
1078
configuration space, the second bit file argument will load the second
1079
configuration space, and the third argument will load the Zip~CPU program
1080
into its space.
1081
 
1082 7 dgisselq
\chapter{Clocks}
1083
 
1084
The S6~SoC is designed to run off of one master clock.  This clock is derived
1085 41 dgisselq
from the 8~MHz input clock on the board, by multiplying it up to 80~MHz.  The
1086
code for doing this can be found in both {\tt toplevel.v} and {\tt alttop.v}.
1087 7 dgisselq
 
1088 41 dgisselq
\chapter{I/O Ports}
1089 7 dgisselq
 
1090 41 dgisselq
Table.~\ref{tbl:ioports}
1091 7 dgisselq
\begin{table}[htbp]
1092
\begin{center}
1093
\begin{portlist}
1094
i\_clk\_8mhz & 1 & Input & Clock\\\hline
1095
o\_qspi\_cs\_n & 1 & Output & Quad SPI Flash chip select\\\hline
1096
o\_qspi\_sck & 1 & Output & Quad SPI Flash clock\\\hline
1097
io\_qspi\_dat & 4 & Input/Output & Four-wire SPI flash data bus\\\hline
1098
i\_btn & 2 & Input  & Inputs from the two on-board push-buttons\\\hline
1099
o\_led & 4 & Output & Outputs controlling the four on-board LED's\\\hline
1100
o\_pwm & 1 & Output & Audio output, via pulse width modulator\\\hline
1101
\multicolumn{2}{|l|}{o\_pwm\_shutdown\_n, 1}& Output & Audio output shutdown control\\\hline
1102
o\_pwm\_gain & 1 & Output & Audio output 20~dB gain enable\\\hline
1103
i\_uart & 1 & Input &  UART receive input\\\hline
1104
o\_uart & 1 & Output & UART transmit output\\\hline
1105 41 dgisselq
o\_uart\_cts & 1 & Output & H/W flow control response, true if the internal
1106
        single-byte receive buffer is empty.\\\hline
1107
i\_uart\_rts & 1 & Input & H/W flow control, true if the PModUSBUART wishes
1108
                to send a byte\\\hline
1109 7 dgisselq
i\_kp\_row & 4 & Output & Four wires to activate the four rows of the keypad\\\hline
1110
o\_kp\_col & 4 & Output & Return four wires, from the keypads columns \\\hline
1111
i\_gpio & 14 & Output & General purpose logic input lines\\\hline
1112
o\_gpio & 14 & Output & General purpose logic output lines\\\hline
1113
io\_scl & 1 & Input/Output & I2C clock port\\\hline
1114
io\_sda & 1 & Input/Output & I2C data port\\\hline
1115
\end{portlist}
1116
\caption{List of IO ports}\label{tbl:ioports}
1117
\end{center}\end{table}
1118 41 dgisselq
lists the various I/O ports associated with the S6~SoC.  These ports are named
1119
in roughly the same manner they are used.  The four UART pins,
1120
{\tt i\_uart}, {\tt o\_uart}, {\tt i\_uart\_rts} and {\tt o\_uart\_cts},
1121
connect to the PModUSBUART.  The three PWM pins, {\tt o\_pwm},
1122
{\tt o\_pwm\_gain}, and {\tt o\_pwm\_shutdown\_n}, control the PModAMP2 audio
1123
device.  The eight pins, {\tt i\_kp\_row[3:0]} and {\tt o\_kp\_col[3:0]},
1124
control the PModKYPD keypad.  The final PMod, PModCLS, is controlled via the
1125
SPI lines formed from {\tt o\_gpio[4:2]} and {\tt i\_gpio[2]}.  This display
1126
could also be controlled via I2C, {\tt io\_sda} and {\tt io\_scl}, although that
1127
is not part of the current demonstration software.
1128 18 dgisselq
 
1129 41 dgisselq
The assignment of these pins to external output I/O pins is shown in
1130
Fig.~\ref{fig:physicalio}.
1131
\begin{figure}
1132 18 dgisselq
\begin{center}
1133
\includegraphics[height=7in]{../gfx/pinout.eps}
1134 41 dgisselq
\caption{Physical Locations of Device I/O Ports}\label{fig:physicalio}
1135
\end{center}\end{figure}
1136
Although pin assignment to the actual S6~board has been rather arbitrary, there
1137
is a touch of method to the madness.  In particular, the S6~SoC pin placement
1138
supports placing the PMods in the configuration shown in
1139
Fig.~\ref{fig:pmodplaces}.
1140
\begin{figure}
1141
\begin{center}
1142
\includegraphics[height=7in]{../gfx/pmodmap.eps}
1143
\caption{Suggested mapping of I/O ports to PMod Locations}\label{fig:pmodplaces}
1144
\end{center}\end{figure}
1145
From this figure you can see that I have tried to minimize the amount of
1146
movement necessary to install any particular PMods, while also making the
1147
greatest use of pins on board.  What may not be obvious from this picture
1148
is that the PMod power and ground lines are all connected to power and ground
1149
rails separate from the CMod itself.
1150
 
1151
As with any piece of open source firmware, these pin assignments are fairly
1152
arbitrary and easy to adjust by making changes to the {\tt cmod.ucf} and
1153
{\tt cmodtop.ucf} files.  The main difference between those two files being
1154
the DEPP interface supported by alternate configuration, which uses
1155
{\tt cmod.ucf}.
1156
 
1157 7 dgisselq
% Appendices
1158
% Index
1159
\end{document}
1160
 
1161
 

powered by: WebSVN 2.1.0

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