%Include "boiler plate" EUDET style
\input{preamble}

% Title info
\subject{\includegraphics[scale=0.7]{figs/AIDA-logo_cmyk.pdf}}
\title{\Large AIDA mini-TLU manual } 
\author{
F. Crescioli$^1$,
D. Cussans$^2$,
A. Dosil Su{\'a}rez$^3$
\bigskip\\
\textit{\footnotesize $ ^1$Laboratoire de physique nucl\'eaire et des hautes \'energies, Paris, France}\\
\textit{\footnotesize $ ^2$University of Bristol, Bristol, United Kingdom}\\
\textit{\footnotesize $ ^3$University of Santiago de Compostela, Spain}\\
}
\date{\normalsize \today}

\vspace{\fill}

\begin{document}

% Title page
\maketitle
\begin{abstract}
\noindent

The AIDA mini Trigger Logic Unit (AIDA mini-TLU) has been conceived as a device to replace 
tens of VME modules and lemo cables dangling around in every test-beam setup.
It permits an easier and remote configuration of the trigger logic through the Ethernet
with added functionalities such as test readout elements without beam.
The generic design of the mini-TLU permits to connect it to a very wide range of devices, 
even LHC like readout systems. This has the benefit of sharing hardware, firmware and DAQ-Software effort.
Also, it implements a 1 ns accuracy TDC.

\end{abstract}


\section{Data Format}
The AIDA mini-TLU records the time stamp of input and internally generated signals with an accuracy better
than 1 ns. The time stamp format is different depending on the signal recorded and the number of input signals
configured in the measuring moment. There are three possible signal types: trigger, internally generated and edge signals.
The internally generated and edge signals have the properties of rising and falling edges. The coding of these names is indicated
in Table \ref{tab:Evt_Type}. Data is sent to the DAQ pc in packages from one to three words of 64 bits.
\begin{table}[t]
\centering
\begin{tabular}{|r|l|}

\hline
0000 & internal trigger \\ \hline
0001 & external trigger \\ \hline
0010 & shutter falling \\ \hline
0011 & shutter rising \\ \hline
0100 & edge falling \\ \hline
0101 & edge rising \\ \hline
0110 & spill off \\ \hline
0111 & spill on \\ \hline

\end{tabular}
\caption{Event type codification}
\label{tab:Evt_Type}
\end{table}


\subsection{Trigger data}
The AIDA TLU will have 12 dedicated trigger inputs. 
The mapping for this type of signal is indicated in Figure \ref{fig:trig_map}. 
The information of this signal is sent in two or three 64 bits word depending on whether any of the 
4 to 11 dedicated trigger inputs are enabled. The AIDA mini-TLU only has four trigger inputs, 
so it will always send only two 64 bits words. \\
The 48 lowest significant bits of the first word indicate the 25 ns time stamp. 
This time stamp is synchronized with the 40 MHz main system clock. 
Bits from 48 to 59 indicate which of the trigger inputs have been fired and the 4 most significant bits indicate the event type. 
In this particular case the possibilities are only internal or external trigger.
The 32 lowest significant bits of the second word indicate the event number.
The 32 highest significant bits are divided in four words of 8 bits. 
Each word indicates the 1 ns accuracy time stamp of the signal received in each dedicated input.
Only in the case that at least one of the 4 to 11 dedicated trigger inputs is enabled, the third word is created and sent out.
This third word contains eight words of eight bits, each indicating the 1 ns time stamp of the trigger in each input.

\begin{figure}
  \centering
    \includegraphics[scale=0.35]{figs/trigger_map.png}
  \caption{Mapping of the trigger signal information. The third word, marked with a star, is only sent when
  at least one of the 4 to 11 dedicated trigger inputs is enabled.}
  \label{fig:trig_map}
\end{figure}

\subsection{Internally generated data}
The internally generated signal information includes the event type, an event number counter and a 25 ns time stamp, as can
be seen in Figure \ref{fig:shut_map}. In this case only one 64 bits word. 
These signals are synchronous with the 40 MHz system clock, therefore only a 25 ns time stamp is needed. \\
The 48 lowest significant bits indicate the 25 ns time stamp. The next 12 bits are the event number and the four most significant
bits indicate the event type.
\begin{figure}
  \centering
    \includegraphics[scale=0.35]{figs/shutter_spill_map.png}
  \caption{Mapping of the internally generated signals information.}
  \label{fig:shut_map}
\end{figure}

\subsection{Edge data}
There are some external signals that can be interesting to record. We call them edge data because we only want to know their 
rising or falling edge time stamps. The data format can be seen in Figure \ref{fig:edge_map}. 
As in the shutter and spill case, only one 64 bits word is sent. The 48 lowest significant bits indicate the 25 ns time stamp and the 
4 highest significant bits indicate the event type, as in every other signals. Bits from 49 to 55 indicate the 1 ns time stamp and
the next 4 bits code which input detected the event.
\begin{figure}
  \centering
    \includegraphics[scale=0.35]{figs/edge_map.png}
  \caption{Mapping of the edge signal information.}
  \label{fig:edge_map}
\end{figure}

\section{Handshake between TLU and DUT}
The AIDA TLU provides two different handshake modes. One EUDET handshake, 
compatible with the old JRA1 TLU, and a new synchronous mode.

\subsection{EUDET handshake (Trigger/busy with trigger number)}
\begin{enumerate}
 \item TLU receives trigger from beam scintillators
 \item TLU asserts TRIGGER
 \item On receipt of TRIGGER going high, the detector asserts BUSY
 \item On receipt of BUSY going high, TLU de-asserts TRIGGER and switches the TRIGGER line to the output of a 
shift register holding the trigger number/data.
 \item The DUT clocks data out of the shift register by toggling TRIGGER CLOCK.
Data changes on the rising edge of TRIGGER CLOCK3 . The least significant bit
of the trigger data is shifted out first. Only the bottom 15-bits of the 32-bit
trigger counter are clocked out. If more than 15 clock pulses are issued on the
TRIGGER CLOCK line the TRIGGER output is set to zero. The DUT should
issue 16 clock pulses which will clock out the bottom 15-bits of the trigger number
and return the TRIGGER line to logical low. This will avoid glitches on the
TRIGGER line when the DUT returns the BUSY line to logical low.
 \item After clocking out the trigger number (and the detector being ready to take more
data, the DUT de-asserts BUSY)
 \item System is ready for triggers again.
\end{enumerate}

\begin{figure}[H]
  \centering
    \includegraphics[scale=0.4]{figs/Trigger_Data_Handshake.png}
  \caption{Timing of signals in ``EUDET Handshake''}
  \label{fig:Trigger_Handshake}
\end{figure}

\subsection{Synchronous mode}
This mode is new for the AIDA TLU and it is incompatible with old handshake modes.
\begin{enumerate}
  \item TLU receives trigger from beam scintillators
  \item TLU asserts TRIGGER synchronous with its internal clock
  \item After one clock cycle the system is ready for triggers again
\end{enumerate}
\begin{itemize}
 \item If at any time the TLU receives a busy signal from DUT, it will veto all incoming triggers while the signal is active
\end{itemize}
\begin{figure}[H]
  \centering
    \includegraphics[scale=0.9]{figs/tlu_timing_diagram_02.pdf}
  \caption{Timing of signals in ``Synchronous mode''}
  \label{fig:Trigger_Handshake}
\end{figure}

\end{document}
