source: firmware/FTU/doc/v2/FTU_firmware_v2.tex@ 11770

Last change on this file since 11770 was 10047, checked in by weitzel, 14 years ago
timeout implemented for FTU RS485 communication; new version of FTU docu
File size: 25.1 KB
Line 
1\documentclass[a4paper,11pt]{report}
2
3\usepackage{float}
4\usepackage{graphicx}
5\usepackage{url}
6\usepackage[T1]{fontenc}
7\usepackage{amsmath}
8\usepackage{longtable}
9\usepackage{parskip}
10\usepackage{pifont}
11\usepackage{array}
12
13\setlength{\oddsidemargin}{0cm}
14\setlength{\evensidemargin}{0cm}
15\setlength{\topmargin}{0cm}
16
17\textwidth 6.2in
18\textheight 9in
19\columnsep 0.25in
20
21\pagestyle{plain}
22\setcounter{tocdepth}{1}
23
24\title{\vspace*{-7cm} \Huge \bf FTU Firmware Specifications}
25\author{\Large Quirin Weitzel\footnote{Contact for questions and suggestions concerning this
26 document: {\tt qweitzel@phys.ethz.ch}}, Patrick Vogler}
27\date{\vspace*{0.5cm} \Large v2~~~-~~~October 2010}
28
29\begin{document}
30
31\maketitle
32
33\newpage
34
35\tableofcontents
36
37\chapter{Introduction}
38
39The FACT Trigger Unit (FTU) is a Mezzanine Card attached to the FACT
40Pre-Amplifier (FPA) board. On the FPA, the analog signals of nine adjacent
41pixels are summed up, and the total signal is compared to a threshold. Four
42such trigger patches are hosted by one FPA. The corresponding four digital
43trigger signals are processed further by the FTU, generating a single trigger
44primitive out of them. A total of 40 FTU boards exists in the FACT
45camera. Their trigger primitives are collected at one central point, the FACT
46Trigger Master (FTM)\footnote{For more information about the FACT trigger
47 system see: P.~Vogler, {\it Development of a trigger system for a Cherenkov
48 Telescope Camera based on Geiger-mode avalanche photodiodes}, Master
49 Thesis, ETH Zurich, 2010.}. The FTM serves also as slow control master for
50the FTUs, which are connected in groups of ten to RS485 data buses for this
51purpose. These buses are realized on the midplanes of the four crates inside
52the camera.
53
54The main component on each FTU is a FPGA\footnote{Xilinx Spartan-3AN family
55 (XC3S400AN-4FGG400C); for programming information see:
56 \url{http://www.xilinx.com/support/documentation/user_guides/ug331.pdf}
57 (Spartan-3 Generation FPGA User Guide).}, fulfilling different tasks within
58the board. The purpose of this document is to describe the main features of
59the firmware of this device, which is identical for all 40 boards. After a
60brief summary of the FTU functionality and its digital components, a general
61overview of the firmware design is given. In the following, all FPGA registers
62available for reading and writing are listed. Afterwards the communication
63with the FTM is detailed, and the most important finite state machines
64implemented are explained.
65
66\chapter{FTU Tasks and Digital Components}
67
68In order to define the thresholds for the individual trigger patches, four
69channels of an octal \mbox{12-bit} Digital-to-Analog Converter (DAC) are
70used. This chip\footnote{Details concerning specific electronics components as
71 well as schematics can be found at the FACT construction page:
72 \url{http://ihp-pc1.ethz.ch/FACT} (password protected).} is accessed by the
73FPGA through a Serial Peripheral Interface (SPI). A fifth channel of the same
74DAC is employed to control a $n$-out-of-4 majority coincidence logic,
75generating the trigger primitive out of the patch signals. The FTU can
76furthermore switch off single pixels within the trigger patches by disabling
77the corresponding input buffers just before the summation stage on the
78FPA. However, the decision to switch off a pixel for the trigger or to change
79the threshold for a patch is not taken by the FTU itself, but has to come in
80form of a command from the FTM.
81
82For each of the four trigger patches, the FTU counts the number of triggers
83within a certain time period. Also the number of trigger primitives after the
84$n$-out-of-4 majority coincidence is counted. In this way, the rates per patch
85and per board are known for each FTU. The counters are implemented inside the
86FPGA with a range of 30\,bit. In case the number of triggers exceeds this
87limit, an overflow flag is set. The counting period is changeable from outside
88between 500\,ms and 128\,s with a resolution of 8\,bit.
89
90Each FTU board has one RS485 communication interface to the FTM. Ten boards
91are connected to one bus, where they are operated in slave-mode. Only in case
92a read or write command for a specific FTU arrives from the FTM, this board
93will react and answer. Broadcast commands are not supported by the current
94firmware version. To avoid data collisions on the buses, the FTM has to
95address the FTUs one by one to read out the rates for example. A RS485
96interface is implemented inside the FPGA, including frame receiving, data
97buffering and instruction decoding. It is minimal in the sense that no stacked
98commands, command buffering or interrupts are supported. Outside the FPGA, a
99RS485 driver/receiver chip translates the signal levels between the
100differential bus lines and the FPGA logic levels. This chip is enabled for
101data transmission or data receiving, respectively.
102
103\chapter{Firmware Organization}
104\label{cha:organization}
105
106The FTU firmware is written in VHDL (VHSIC Hardware Description Language). For
107some of its components the Xilinx core generator tools\footnote{Xilinx ISE
108 Design Suite, release 11.5, homepage: \url{http://www.xilinx.com}
109 (downloads, documentation).} have been used. In this chapter, an overview of
110the firmware content is given, followed by a listing of the files containing
111the source code. The complete project is available from the FACT
112repository\footnote{Project page: \url{https://fact.isdc.unige.ch/trac}
113 (password protected).}.
114
115\section{Design Overview}
116\label{sec:organization:design}
117
118The highest level entity in the firmware is called {\tt FTU\_top}. Its ports
119are the physical connections of the FPGA on the FTU board. Inside {\tt
120 FTU\_top} other entities are instantiated, representing different functional
121modules. They are discussed in the following subsections. For important
122numbers and constants the package {\tt ftu\_constants} inside the library {\tt
123 ftu\_definitions} has been created. A second package {\tt ftu\_array\_types}
124contains customized array types.
125
126\subsection{\tt FTU\_clk\_gen}
127
128This is an interface to the Digital Clock Managers (DCM) of the FPGA. At the
129moment only one DCM is used, providing the central 50\,MHz clock. Once the DCM
130has locked and is providing a stable frequency {\tt FTU\_clk\_gen} sends a
131ready signal. This is a prerequisite for the board to enter the {\tt RUNNING}
132state. {\tt FTU\_clk\_gen} also generates a central 1\,MHz clock for the rate
133counters (by division, not using a second DCM). In addition, some modules
134within the FTU design have their own built-in clock dividers to generate
135custom frequencies.
136
137\subsection{\tt FTU\_dual\_port\_ram64}
138\label{sec:organization:design:ram}
139
140All FTU registers which can be set from outside during operation are stored in
141a dual-port block RAM (Random Access Memory). The FPGA provides specific
142resources for this purpose, and therefore the RAM has been created using the
143Xilinx core generator tools. The entity {\tt FTU\_dual\_port\_ram64} serves as
144an interface to the RAM, the actual gate level description is stored directly
145in the net-list file {\tt FTU\_dual\_port\_ram64.ngc}. Thus this file is part
146of the design, although not available as source code. The RAM has a size of
14764\,bytes and two fully featured ports to access its content. One port is
148based on 1-byte words, the other one on 2-byte words. The corresponding
149address space is presented together with the register tables in
150chapter~\ref{cha:registers}. In addition to the control registers, also the
151current counter readings are stored in the RAM.
152
153\subsection{\tt FTU\_rate\_counter}
154\label{sec:organization:design:counter}
155
156Here the trigger counting is done. A rate counter has a range of 30\,bit and
157counts until a defined period is finished. This period is derived from an
1588-bit prescaling value $y$ as $ T = \frac{y+1}{2}$\,s. In total five such
159counters are instantiated which are running and set up synchronously. If the
160FTU settings are changed during operation all counters are reset. Only in case
161a full period has been finished without interruption, the number of counts
162from each counter is stored in the RAM. An overflow flag is set by the
163counters if necessary.
164
165\subsection{\tt FTU\_spi\_interface}
166
167The octal DAC defining the trigger thresholds is controlled by means of a
168SPI. As soon as the {\tt FTU\_spi\_interface} entity receives a start signal,
169it will clock out the data pending at one of its input ports to the DAC. These
170data are provided in form of a customized array. The generation of the serial
171clock, the distribution of the DAC values to the right addresses and the
172actual transmission of the data to the chip are performed by three more
173entities, which are instantiated inside {\tt FTU\_spi\_interface}. Once the
174transmission has started or finished, respectively, a signal is pulled.
175
176\subsection{\tt FTU\_rs485\_control}
177
178The communication between the FTU and the FTM is handled by a RS485
179interface. The top level entity of this module is called {\tt
180 FTU\_rs485\_control}. It contains a state machine and further sub-entities
181for frame receiving or transmitting, byte buffering and instruction
182decoding. The details of the underlying protocol and the possible instructions
183are detailed in chapter~\ref{cha:communication}. In case an instruction has
184been decoded successfully, the main FTU control is informed and the
185corresponding data (like new DAC values) are provided. After the command has
186been executed an answer is send to the FTM. {\tt FTU\_rs485\_control} has
187direct control of the involved transmitter/receiver chip outside the FPGA and
188takes care that it is only transmitting if this particular FTU has been
189contacted by the FTM. In this way also the rates are send on request. The baud
190rate is adjustable and defined in the library {\tt ftu\_definitions}.
191
192\subsection{\tt FTU\_control}
193
194This entity contains the main state machine of the FTU firmware. It receives
195control, ready, start, etc. flags from all modules and interfaces and reacts
196accordingly by changing to a new state. This may be done with some delay,
197depending on what the board is doing at the moment. {\tt FTU\_control} is
198furthermore the only place in the design from where the RAM is read or
199written. The state machine is described in more detail in
200chapter~\ref{cha:fsm}.
201
202\subsection{\tt FTU\_dna\_gen}
203\label{sec:organization:design:dna}
204
205In order to be able to unambiguously identify each FTU during operation, the
206device identifier\footnote{This unique identifier has 57\,bit and is built-in
207 for each FPGA of the Spartan-3A series. For more information see:
208 \url{http://www.xilinx.com/support/documentation/user_guides/ug332.pdf}
209 (Spartan-3 Generation Configuration User Guide).} (DNA) of its FPGA is
210used. After power-up this DNA is read-out once by {\tt FTU\_dna\_gen} and
211stored for later usage inside {\tt FTU\_top} as a permanent signal.
212
213\section{File Structure}
214
215Table~\ref{tab:files} specifies all source files necessary to compile the
216firmware for the FTU boards\footnote{As of October 2010; the file structure
217 might still be changed.}. For each file its location path inside the
218directory {\tt firmware} of the FACT repository is stated. Furthermore it is
219indicated whether a certain file is needed for the simulation and/or the
220hardware implementation. The design entities described in
221section~\ref{sec:organization:design} are contained in those files which have
222the corresponding prefix. The file {\tt ucrc\_par.vhd} has been downloaded
223from OpenCores\footnote{Ultimate CRC project:
224 \url{http://www.opencores.org/cores/ultimate_crc} (free software under the
225 terms of the GNU General Public License).}.
226
227\begin{table}[htbp]
228 \centering
229 \begin{tabular}{|l|l|l|l|l|}
230 \hline
231 file name & location & simulation & implement & comment \\
232 \hline\hline
233 {\tt FTU\_top.vhd} & {\tt FTU} & yes & yes & top level entity\\
234 \hline
235 {\tt FTU\_top\_tb.vhd} & {\tt FTU} & yes & no & test bench\\
236 \hline
237 {\tt ftu\_definitions.vhd} & {\tt FTU} & yes & yes & library\\
238 \hline
239 {\tt ftu\_board.ucf} & {\tt FTU} & no & yes & pin constraints\\
240 \hline
241 {\tt FTU\_control.vhd} & {\tt FTU} & yes & yes & top state machine\\
242 \hline\hline
243 {\tt FTU\_clk\_gen.vhd} & {\tt FTU/clock} & yes & yes & clock interface\\
244 \hline
245 {\tt FTU\_dcm\_50M\_to\_50M.vhd} & {\tt FTU/clock} & yes & yes & clock manager\\
246 \hline\hline
247 {\tt FTU\_rate\_counter.vhd} & {\tt FTU/counter} & yes & yes & trigger counter\\
248 \hline\hline
249 {\tt FTU\_spi\_interface.vhd} & {\tt FTU/dac\_spi} & yes & yes & SPI top entity\\
250 \hline
251 {\tt FTU\_spi\_clock\_gen.vhd} & {\tt FTU/dac\_spi} & yes & yes & serial clock\\
252 \hline
253 {\tt FTU\_distributor.vhd} & {\tt FTU/dac\_spi} & yes & yes & DAC loop\\
254 \hline
255 {\tt FTU\_controller.vhd} & {\tt FTU/dac\_spi} & yes & yes & low level SPI\\
256 \hline\hline
257 {\tt FTU\_dna\_gen.vhd} & {\tt FTU/dna} & yes & yes & DNA readout\\
258 \hline\hline
259 {\tt FTU\_dual\_port\_ram64.vhd} & {\tt FTU/ram64} & yes & yes & RAM interface\\
260 \hline
261 {\tt FTU\_dual\_port\_ram64.ngc} & {\tt FTU/ram64} & no & yes & RAM netlist\\
262 \hline\hline
263 {\tt FTU\_rs485\_control.vhd} & {\tt FTU/rs485} & yes & yes & RS485 top entity\\
264 \hline
265 {\tt FTU\_rs485\_interpreter.vhd} & {\tt FTU/rs485} & yes & yes & data decoding\\
266 \hline
267 {\tt FTU\_rs485\_receiver.vhd} & {\tt FTU/rs485} & yes & yes & 28-byte buffer\\
268 \hline
269 {\tt FTU\_rs485\_interface.vhd} & {\tt FTU/rs485} & yes & yes & low level RS485\\
270 \hline
271 {\tt ucrc\_par.vhd} & {\tt FTU/rs485} & yes & yes & check sum\\
272 \hline
273 \end{tabular}
274 \caption{List of all source files needed to compile the FTU firmware.}
275 \label{tab:files}
276\end{table}
277
278\chapter{Register Tables}
279\label{cha:registers}
280
281There are 41 accessible control and rate registers implemented in the FTU
282firmware, each with a size of 8\,bit. They are organized as a 64-byte RAM (see
283also section~\ref{sec:organization:design:ram}), the last 23 bytes of which
284are empty and serve as spares. Table~\ref{tab:RAM} presents an overview of the
285address space inside the RAM, more details can be found in
286tables~\ref{tab:enables} - \ref{tab:overflow}. Registers marked as read-only
287cannot be written by the FTM, but are updated by the FTU itself.
288
289\begin{table}[htbp]
290 \centering
291 \begin{tabular}{|c|l|l|}
292 \hline
293 RAM address & register block & comment\\
294 \hline\hline
295 $00 \dots 07$ & enable patterns & read/write\\
296 \hline
297 $08 \dots 27$ & rate counters & read-only\\
298 \hline
299 $28 \dots 37$ & DAC settings & read/write\\
300 \hline
301 $38$ & prescaling $y$ (see section~\ref{sec:organization:design:counter}) & read/write \\
302 \hline
303 $39$ & overflow bits & read-only \\
304 \hline
305 $40$ & check sum error counter & read-only\\
306 \hline
307 $41 \dots 63$ & empty & spare \\
308 \hline
309 \end{tabular}
310 \caption{Overview of the register mapping inside the RAM.}
311 \label{tab:RAM}
312\end{table}
313
314\section{Enable Patterns}
315
316\begin{table}[htbp]
317 \centering
318 %\small
319 \begin{tabular}{|c||l|l|l|l|l|l|l|l|}
320 \hline
321 address & bit~7 & bit~6 & bit~5 & bit~4 & bit~3 & bit~2 & bit~1 & bit~0 \\
322 \hline\hline
323 00 & En\_A7 & En\_A6 & En\_A5 & En\_A4 & En\_A3 & En\_A2 & En\_A1 &
324 En\_A0 \\
325 \hline
326 01 & \- & \- & \- & \- & \- & \- & \- & En\_A8 \\
327 \hline
328 02 & En\_B7 & En\_B6 & En\_B5 & En\_B4 & En\_B3 & En\_B2 & En\_B1 &
329 En\_B0 \\
330 \hline
331 03 & \- & \- & \- & \- & \- & \- & \- & En\_B8 \\
332 \hline
333 04 & En\_C7 & En\_C6 & En\_C5 & En\_C4 & En\_C3 & En\_C2 & En\_C1 &
334 En\_C0 \\
335 \hline
336 05 & \- & \- & \- & \- & \- & \- & \- & En\_C8 \\
337 \hline
338 06 & En\_D7 & En\_D6 & En\_D5 & En\_D4 & En\_D3 & En\_D2 & En\_D1 &
339 En\_D0 \\
340 \hline
341 07 & \- & \- & \- & \- & \- & \- & \- & En\_D8\\
342 \hline
343 \end{tabular}
344 \caption{Mapping of the $4 \times 9$ enable bits inside the RAM.}
345 \label{tab:enables}
346\end{table}
347
348\section{Rate Counters}
349
350\begin{table}[htbp]
351 \centering
352 %\small
353 \begin{tabular}{|c||l|l|l|l|l|l|l|l|}
354 \hline
355 address & bit~7 & bit~6 & bit~5 & bit~4 & bit~3 & bit~2 & bit~1 & bit~0 \\
356 \hline\hline
357 08 & Ct\_A7 & Ct\_A6 & Ct\_A5 & Ct\_A4 & Ct\_A3 & Ct\_A2 & Ct\_A1 & Ct\_A0 \\
358 \hline
359 09 & Ct\_A15 & Ct\_A14 & Ct\_A13 & Ct\_A12 & Ct\_A11 & Ct\_A10 & Ct\_A9 & Ct\_A8 \\
360 \hline
361 10 & Ct\_A23 & Ct\_A22 & Ct\_A21 & Ct\_A20 & Ct\_A19 & Ct\_A18 & Ct\_A17 & Ct\_A16 \\
362 \hline
363 11 & 0 & 0 & Ct\_A29 & Ct\_A28 & Ct\_A27 & Ct\_A26 & Ct\_A25 & Ct\_A24 \\
364 \hline\hline
365 $\dots$ & $\dots$ & $\dots$ & $\dots$ & $\dots$ & $\dots$ & $\dots$ & $\dots$ & $\dots$ \\
366 \hline\hline
367 20 & Ct\_D7 & Ct\_D6 & Ct\_D5 & Ct\_D4 & Ct\_D3 & Ct\_D2 & Ct\_D1 & Ct\_D0 \\
368 \hline
369 21 & Ct\_D15 & Ct\_D14 & Ct\_D13 & Ct\_D12 & Ct\_D11 & Ct\_D10 & Ct\_D9 & Ct\_D8 \\
370 \hline
371 22 & Ct\_D23 & Ct\_D22 & Ct\_D21 & Ct\_D20 & Ct\_D19 & Ct\_D18 & Ct\_D17 & Ct\_D16 \\
372 \hline
373 23 & 0 & 0 & Ct\_D29 & Ct\_D28 & Ct\_D27 & Ct\_D26 & Ct\_D25 & Ct\_D24 \\
374 \hline\hline
375 24 & Ct\_T7 & Ct\_T6 & Ct\_T5 & Ct\_T4 & Ct\_T3 & Ct\_T2 & Ct\_T1 & Ct\_T0 \\
376 \hline
377 25 & Ct\_T15 & Ct\_T14 & Ct\_T13 & Ct\_T12 & Ct\_T11 & Ct\_T10 & Ct\_T9 & Ct\_T8 \\
378 \hline
379 26 & Ct\_T23 & Ct\_T22 & Ct\_T21 & Ct\_T20 & Ct\_T19 & Ct\_T18 & Ct\_T17 & Ct\_T16 \\
380 \hline
381 27 & 0 & 0 & Ct\_T29 & Ct\_T28 & Ct\_T27 & Ct\_T26 & Ct\_T25 & Ct\_T24 \\
382 \hline
383 \end{tabular}
384 \caption{Mapping of the four patch counter (A--D) and the trigger counter
385 reading (T) inside the RAM. The two most significant bits of the 32 bits per counter are always
386 set to 0.}
387 \label{tab:rates}
388\end{table}
389
390\section{DAC Settings}
391
392\begin{table}[htbp]
393 \centering
394 \begin{tabular}{|c|l|}
395 \hline
396 address & data[$7 \dots 0$]\\
397 \hline\hline
398 28 & DAC\_A\_[$7 \dots 0$] \\
399 \hline
400 29 & DAC\_A\_[$15 \dots 8$] \\
401 \hline
402 $\dots$ & $\dots$\\
403 \hline
404 34 & DAC\_D\_[$7 \dots 0$] \\
405 \hline
406 35 & DAC\_D\_[$15 \dots 8$] \\
407 \hline
408 36 & DAC\_H\_[$7 \dots 0$] \\
409 \hline
410 37 & DAC\_H\_[$15 \dots 8$] \\
411 \hline
412 \end{tabular}
413 \caption{Mapping of the DAC values (12\,bit) for the thresholds (DAC\_A -- DAC\_D) and the
414 $n$-out-of-4 logic (DAC\_H) inside the RAM; the bits $15\dots 12$ are filled up with zeros.}
415 \label{tab:dacs}
416\end{table}
417
418\section{Overflow Bits}
419
420\begin{table}[htbp]
421 \centering
422 \begin{tabular}{|l|c|c|c|c|c|c|}
423 \hline
424 bit & $7 \dots 5$ & 4 & 3 & 2 & 1 & 0 \\
425 \hline\hline
426 0 & not used & overflow\_T & overflow\_D & overflow\_C & overflow\_B & overflow\_A \\
427 \hline
428 \end{tabular}
429 \caption{Bit mapping inside the RAM overflow register (address 39).}
430 \label{tab:overflow}
431\end{table}
432
433\chapter{Communication with FTM}
434\label{cha:communication}
435
436The slow control system between the FTU boards (slaves) and the FTM (master)
437is based on two transmission sequences: Either the FTM is sending data to a
438particular FTU, or a particular FTU is answering to the FTM. Broadcast
439commands are not supported. Each board has a unique 1-byte address for
440identification on the RS485 buses, which is 0--63 for the FTUs\footnote{Two
441 bits are used to specify the crate, four bits to indicate the slot position
442 within a crate. This 6-bit address is different from the 57-bit DNA which is
443 FPGA-bound (see section~\ref{sec:organization:design:dna}).} and 192 for the
444FTM. The transmission sequences are of fixed length (28\,byte) and, if
445necessary, filled up with arbitrary data. In case the data transmission is
446disturbed or not complete, a time-out system ensures that the communication
447doesn't get stuck\footnote{At a baud rate of 250\,kHz, for example, this
448 time-out is set to 2\,ms on the FTU side.}. In the following, the slow
449control protocol, the instruction codes and the check sum error-detection are
450discussed.
451
452\section{Transmission Protocol}
453
454Table~\ref{tab:protocol} summarizes the structure of the data sequences sent
455between the FTM and the FTUs. A FTU only replies if contacted by the FTM. The
456answer is a copy of the received data package with swapped source/destination
457address and eventually the requested data. Byte 26 is used to transmit the
458number of CRC errors counted by a FTU until a valid sequence arrived. In that
459case the number of errors is communicated and the error counter is set to 0.
460
461\begin{table}[htbp]
462 \centering
463 \begin{tabular}{|c|l|l|}\hline
464 byte & content & comment \\
465 \hline\hline
466 $00$ & start delimiter & ASCI @ (binary "01000000")\\
467 \hline
468 $01$ & destination address & 192 (FTM) or slot position 0--63 (FTUs)\\
469 \hline
470 $02$ & source address & 192 (FTM) or slot position 0--63 (FTUs)\\
471 \hline
472 $03$ & firmware ID & firmware version of source FPGA\\
473 \hline
474 $04$ & instruction / info & see section~\ref{cha:communication:instr}\\
475 \hline
476 $05 \dots 25$ & 21 byte data & DACs, rates, etc.\\
477 \hline
478 $26$ & CRC error counter & number of CRC errors on FTU \\
479 \hline
480 $27$ & check sum & CRC-8-CCITT, see section~\ref{cha:communication:crc}\\
481 \hline
482 \end{tabular}
483 \caption{Composition of the FTM-FTU slow control data packages.}
484 \label{tab:protocol}
485\end{table}
486
487\section{Instruction Table}
488\label{cha:communication:instr}
489
490A set of eight instructions has been foreseen for the communication between
491the FTM and the FTUs. They are listed in table~\ref{tab:instructions}
492including a short description. In case a FTU receives the ping-pong command,
493it returns also the DNA of its FPGA (see
494section~\ref{sec:organization:design:dna}). Combined with the 6-bit address,
495which is related to the geographical position insided the camera crates, it is
496therefore possible to identify each FTU.
497
498\begin{table}[htbp]
499 \centering
500 \begin{tabular}{|c|l|l|}
501 \hline
502 code & instruction & description \\
503 \hline\hline
504 00 & set DAC & write new values into DAC registers \\
505 \hline
506 01 & read DAC & read back content of DAC registers \\
507 \hline
508 02 & read rates & read out rates and overflow bits \\
509 \hline
510 03 & set enable & write new patterns into enable registers \\
511 \hline
512 04 & read enable & read back content of enable registers \\
513 \hline
514 05 & ping-pong & ping a FTU to check communication (see text)\\
515 \hline
516 06 & set counter mode & write into the prescaling register \\
517 \hline
518 07 & read counter mode & read back prescaling and overflow registers \\
519 \hline
520 \end{tabular}
521 \caption{Instruction set for the FTM-FTU slow control communication.}
522 \label{tab:instructions}
523\end{table}
524
525\section{CRC Calculation}
526\label{cha:communication:crc}
527
528The integrity of the 28-byte data packages is evaluated by means of a Cyclic
529Redundancy Check (CRC). An 8-CCITT CRC has been chosen which is based on the
530polynomial $x^8 + x^2 + x + 1$ (100000111). Bytes 0--26 of
531table~\ref{tab:protocol} constitute the input vector for the CRC calculation,
532the resulting 1-byte check sum being compared with the one transmitted by the
533FTM (byte 27 in table~\ref{tab:protocol}). If the check sum turns out to be
534wrong, the FTU doesn't answer and increases the number of error counts in its
535corresponding register (RAM address 40). The FTM will consequently run into a
536time-out and repeat its command.
537
538\chapter{Finite State Machines}
539\label{cha:fsm}
540
541There are several finite state machines (FSM) used in the FTU firmware design,
542distributed over several files. They are in principal all running in parallel,
543some of them are, however, only waking up if triggered by the main
544control. This is for example the case for the SPI interface controlling the
545DAC settings. Since the most complicated FSMs are inside {\tt FTU\_control}
546and {\tt FTU\_rs485\_control} (see section~\ref{sec:organization:design}),
547they are explained in more detail in this chapter.
548
549\section{Main Control FSM}
550
551This state machine has full control over the FTU board during operation. After
552power-up or reboot it is in an {\tt IDLE} state, waiting for the DCMs to
553lock. Afterwards it passes through two {\tt INIT} sequences, where default
554values for all registers are written to the RAM and the DNA is read out. The
555defaults are all defined in the library {\tt ftu\_definitions}. When the
556initialization has finished, the {\tt RUNNING} state is entered. This is the
557principal state during which the board is counting triggers. {\tt RUNNING} is
558left only if a counting period has finished and the number of counts is stored
559in the RAM, or if a command has arrived via RS485 and is communicated by the
560responsible FSM (see next section). A dedicated state has been implemented for
561each possible command and, if appropriate, also for the subsequent change of
562settings (e.g. {\tt CONFIG\_DAC}). In any case the board goes back to {\tt
563 RUNNING}.
564
565\section{RS485 Control FSM}
566
567The main and default state of this FSM is {\tt RECEIVE}. This means that the
568RS485 receiver is enabled and the board is waiting for commands from the
569FTM. If a full 28-byte package has arrived and correctly been
570decoded\footnote{This involves a further state machine which is inside the
571 file {\tt FTU\_rs485\_interpreter.vhd}}, the main control FSM is informed
572about the instruction (e.g. new DACs). The RS485 FSM then enters a wait state
573(e.g. {\tt SET\_DAC\_WAIT}) until it gets an internal ready signal. It
574subsequently sends the answer to the FTM (e.g. {\tt SET\_DAC\_TRANSMIT}) and
575goes back to {\tt RECEIVE}. While during {\tt RECEIVE} the RS485 FSM and all
576processes below are running in parallel to the main control FSM, the sequence
577of states in case a command has arrived is prescribed.
578
579\end{document}
Note: See TracBrowser for help on using the repository browser.