%==============================================================================
% Document header
%==============================================================================
\documentclass[a4paper,11pt]{article}

% Color package
\usepackage[usenames,dvipsnames,table]{xcolor}

% Hyperrefs
\usepackage[
  colorlinks = true,
  linkcolor  = black,
  citecolor  = black,
  urlcolor   = blue,
]{hyperref}

% Longtable
\usepackage{longtable}

% Graphics, multirow
\usepackage{graphicx}
\usepackage{multirow}

% Appendix package
\usepackage[toc,page]{appendix}

\usepackage{fancyhdr}
\setlength{\headheight}{15.2pt}
\pagestyle{fancy}
\fancyhead[L]{\nouppercase{\leftmark}}
\fancyhead[R]{}
\renewcommand{\footrulewidth}{0.4pt}

\usepackage{amssymb}

% Row number command
\newcounter{rownr}
\newcommand{\rownumber}{\stepcounter{rownr}\arabic{rownr}}

%==============================================================================
% Start of document
%==============================================================================
\begin{document}

%------------------------------------------------------------------------------
% Title
%------------------------------------------------------------------------------
\include{cern-title}

%------------------------------------------------------------------------------
% Revision history
%------------------------------------------------------------------------------
\pagebreak
\thispagestyle{empty}

\addcontentsline{toc}{section}{Licensing information}
\section*{Licensing information}

\noindent
This document is licensed under a Creative Commons Attribution-ShareAlike 4.0
International License. If you have not received a copy of the license along with this
work, see \\
\url{http://creativecommons.org/licenses/by-sa/4.0/}

\section*{Revision history}
\addcontentsline{toc}{section}{Revision history}

\centerline
{
  \rowcolors{2}{white}{gray!25}
  \begin{tabular}{l c p{.6\textwidth}}
  \hline
  \multicolumn{1}{c}{\textbf{Date}} & \multicolumn{1}{c}{\textbf{Version}} & \multicolumn{1}{c}{\textbf{Change}} \\
  \hline
  16-12-2014 & 0.1 & First draft \\
  27-01-2015 & 0.2 & Added steps for testing remote reprogramming \\
  \hline
  \end{tabular}
}

\pagebreak
\pdfbookmark[1]{\contentsname}{toc}
\tableofcontents

%==============================================================================
% SEC: Intro
%==============================================================================
\pagebreak
\section{Introduction}
\label{sec:intro}

This document presents the test procedure to be performed prior to the release of
every gateware version of the CONV-TTL-RS485~\cite{conv-ttl-rs485-ohwr} board.

The purpose is to test all the basic features of the board prior to releasing
a new gateware version. The following features are tested:

\begin{itemize}
  \item basic pulse conversion and repetition on all channels
  \begin{itemize}
    \item TTL to TTL
    \item TTL to RS-485
    \item RS-485 to TTL
    \item TTL-BAR to TTL-BAR
    \item TTL-BAR to RS-485
    \item RS-485 to TTL-BAR
    \item RS-485 to RS-485
    \item TTL to TTL-BAR (basic pulse inversion)
  \end{itemize}
  \item no pulses generated on power-on
  \item remote reprogramming
\end{itemize}

%==============================================================================
% SEC: Test preparation
%==============================================================================
\pagebreak
\section{Test preparation}
\label{sec:prep}

This section lists the steps to be taken prior to starting the actual test.
It is recommended to follow the steps listed in the following subsections \textbf{in
sequence}.

%==============================================================================
\subsection{Necessary equipment}
\label{sec:prep-equip}
%==============================================================================

\let \oldlabelitemi=\labelitemi
\let \oldlabelitemii=\labelitemii
\let \oldlabelitemiii=\labelitemiii
\let \oldlabelitemiv=\labelitemiv
\renewcommand{\labelitemi}{$\square$}
\renewcommand{\labelitemii}{$\square$}
\renewcommand{\labelitemiii}{$\square$}
\renewcommand{\labelitemiv}{$\square$}

\begin{itemize}
  \item \textbf{1x} Two-slot ELMA crate
  \item \textbf{1x} CONV-TTL-RS485 device under test (DUT)
  \item \textbf{1x} CONV-TTL-RTM-RS485
  \item \textbf{1x} Pulse generator
  \item \textbf{1x} Oscilloscope
  \item \textbf{4x} Long LEMO 00 cables (1~m or more)
  \item \textbf{4x} Short LEMO 00 cables (12~cm bridge cable or equivalent)
  \item \textbf{4x} BNC male/ LEMO 00 female adapters
  \item \textbf{3x} LEMO 00 "Y" splitter plug
  \item \textbf{2x} LEMO 00 50~$\Omega$ terminations
  \item \textbf{2x} LEMO 0S cables (at least 0.5~m in length)
  \item \textbf{1x} LEMO 00 to 0S adapter
\end{itemize}

%==============================================================================
\subsection{Oscilloscope configuration}
\label{sec:prep-osc}
%==============================================================================

\begin{figure}[b]
  \centerline{\includegraphics[width=\textwidth]{fig/IMG_2334.JPG}}
  \caption{Oscilloscope connections}
  \label{fig:osc-cfg}
\end{figure}

\begin{itemize}
  \item \textbf{Trigger on the rising-edge of the external trigger channel}
  \item Connect \textbf{1x BNC male / LEMO 00 female adapter} to the oscilloscope's \textbf{external trigger channel}
  \item Connect \textbf{2x BNC male / LEMO 00 female adapters} to oscilloscope \textbf{channels 1 and 2}
  \item Connect \textbf{2x LEMO 00 "Y" splitter plugs} to these BNC/LEMO 00 adapters
  \item Connect \textbf{2x 50~$\Omega$ terminations} to one side of each LEMO 00 "Y" splitter
\end{itemize}

Note that any channel on the oscilloscope may be used, even though across this
document we use channels 1 and 2 (Figure~\ref{fig:osc-cfg}).
The trigger may also be set for another channel, it is not necessary to trigger
on the external channel.

%==============================================================================
\subsection{Pulse generator configuration}
\label{sec:prep-pulse-gen}
%==============================================================================

\begin{figure}
  \centerline{\includegraphics[width=.5\textwidth]{fig/IMG_2330.JPG}}
  \caption{Pulse generator connection}
  \label{fig:pulse-gen-cfg}
\end{figure}

\begin{itemize}
  \item Connect \textbf{1x BNC male / LEMO 00 female adapter} together with \textbf{1x LEMO 00 "Y" splitter plug}
  to the \textbf{pulse generator's output}
  \item Connect one side of the \textbf{LEMO 00 "Y" splitter plug} (the \textbf{oscilloscope trigger})
  to the \textbf{oscilloscope's external trigger input} (Figure~\ref{fig:pulse-gen-cfg})
  \item The other side (the \textbf{DUT trigger}) of the \textbf{LEMO 00 "Y" splitter plug} will be used to trigger
  the DUT (Figure~\ref{fig:pulse-gen-cfg})
  \item If the pulse generator is configurable, configure it as follows:
    \begin{itemize}
      \item 1.2~$\mu$s pulses
      \item approx. 5~V on 50~$\Omega$ load
      \item 1 Hz frequency
    \end{itemize}
  \item Turn on the pulse generator output
\end{itemize}


%==============================================================================
\subsection{Board connections}
\label{sec:prep-board}
%==============================================================================

\begin{itemize}
  \item Prepare the \textbf{two-slot ELMA crate}
  \item Plug in the \textbf{CONV-TTL-RS485} in \textbf{slot 1} on the \textbf{front
  part of the crate}, and the \textbf{RTM} in \textbf{slot 1} on the
  \textbf{rear part of the crate}
  \item Using \textbf{short LEMO 00 cables}, make a \textbf{daisy-chain} of the
  \textbf{four INV-TTL channels} on the \textbf{front panel}
  \begin{itemize}
    \item \textbf{INV-TTL channel D OUT} to \textbf{INV-TTL channel C IN}
    \item \textbf{INV-TTL channel C OUT} to \textbf{INV-TTL channel B IN}
    \item \textbf{INV-TTL channel B OUT} to \textbf{INV-TTL channel A IN}
    \item Plug a \textbf{long LEMO 00 cable} in the \textbf{INV-TTL channel A OUT}
    connector
  \end{itemize}
  \item Connect \textbf{1x short LEMO 00 cable} to \textbf{1x LEMO 00 to LEMO 0S adapter}
  \item Connect \textbf{1x short LEMO 0S cable} to the \textbf{0S side of the adapter}
  \item This cable will be used to display the RS-485 signal on the oscilloscope
  \item \textbf{Turn on the ELMA crate}
\end{itemize}

%==============================================================================
\subsection{Test scripts}
\label{sec:prep-test-scripts}
%==============================================================================

Some test scripts will need to be run across this test procedure. These
test scripts can be found in the \textit{software/} folder of the CONV-TTL-BLO
\textit{git} repository~\cite{ctb-repo}. One way to obtain this repository is
by running the following command in a Linux command line:

\begin{small}
\begin{center}
\verb+git clone --depth=1 git://ohwr.org/level-conversion/conv-ttl-blo.git+
\end{center}
\end{small}

%==============================================================================
% SEC: Test procedure
%==============================================================================
\pagebreak
\section{Test procedure}
\label{sec:procedure}

\let \oldlabelenumi=\labelenumi
\let \oldlabelenumii=\labelenumii
\let \oldlabelenumiii=\labelenumiii
\let \oldlabelenumiv=\labelenumiv
\renewcommand{\labelenumi}{\oldlabelenumi     \ $\square$}
\renewcommand{\labelenumii}{\oldlabelenumii   \ $\square$}
\renewcommand{\labelenumiii}{\oldlabelenumiii \ $\square$}
\renewcommand{\labelenumiv}{\oldlabelenumiv   \ $\square$}

\renewcommand{\labelitemi}{\oldlabelitemi}
\renewcommand{\labelitemii}{\oldlabelitemii}
\renewcommand{\labelitemiii}{\oldlabelitemiii}
\renewcommand{\labelitemiv}{\oldlabelitemiv}

It is recommended to go through each of the following subsections in sequence
and follow the steps one by one, ticking on completion. If any error
appears, check your gateware and restart the procedure.

%==============================================================================
\subsection{Preparing the bitstream to the flash}
\label{sec:proc-bstream-download}
%==============================================================================

\begin{enumerate}
  \item Navigate to the gateware releases page and download the binary bundle
  (golden+release) for the latest release:
  \begin{itemize}
    \item \small \url{http://www.ohwr.org/projects/conv-ttl-rs485-gw/wiki/Releases}
  \end{itemize}
  \item Program the bundle to the flash. The steps below show how to download the
  \textit{.bin} binary bundle via \verb=xc3sprog=, by downloading a bistream
  providing a JTAG-to-SPI bridge, for programming the SPI flash:
  \begin{small}
  \begin{verbatim}
wget http://www.ohwr.org/attachments/download/3710/flash_load.bit
xc3sprog -c xpc flash_load.bit
xc3sprog -c xpc -I golden-v0.*.bin:W:0:bin
  \end{verbatim}
  \end{small}
  \item Once this is done, we can now download the new release file (named here
  \verb=conv_ttl_rs485.bin=) to the flash. Note that this bitstream needs to be downloaded
  to address \verb=0x170000=. Using \verb=xc3sprog=:
  \begin{small}
  \begin{verbatim}
xc3sprog -c xpc flash_load.bit
xc3sprog -c xpc -I conv_ttl_rs485.bin:W:1507328:bin
  \end{verbatim}
  \end{small}
  \item The on-board flash should now contain the following memory map, we are ready for testing:
  \begin{itemize}
    \item \verb=0x000000= -- Header bitstream to jump to release bitstream
    \item \verb=0x000044= -- Golden bitstream for fallback on error
    \item \verb=0x170000= -- New release bitstream to be tested
  \end{itemize}
\end{enumerate}

%==============================================================================
\subsection{TTL to RS485 pulse conversion}
\label{sec:proc-ttl-rs485}
%==============================================================================
\begin{figure}[h]
  \centerline{\includegraphics[width=.8\textwidth]{fig/switches}}
  \caption{\label{fig:switches} \textbf{On-board switches}}
\end{figure}

\begin{enumerate}
  \item Make sure the \textbf{TTL switch} (Figure~\ref{fig:switches}) of the CONV-TTL-RS485 is in the \textbf{TTL position (on)}
  \item Make sure the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) is in the \textbf{OFF} position
  \item \label{item:ttl-proc-start} Repeat the following steps for \textbf{all six channels}, \textbf{starting from channel 1} and fill in the
    \textbf{table in Appendix~\ref{app:pulse-validation-ttl}}:
    \begin{enumerate}
      \item Connect the \textbf{DUT trigger} (see Section~\ref{sec:prep-pulse-gen}) to the \textbf{front panel  INV-TTL channel D
        input connector}
      \item Connect \textbf{INV-TTL channel A OUT} to the \textbf{front panel channel input}
      \item \label{item:ttl-meas-start} Connect the \textbf{front panel channel output} to \textbf{oscilloscope channel 1}
      \item Connect \textbf{a rear panel channel output} to \textbf{oscilloscope channel 2}
      \item \label{item:ttl-meas-ttl-out} Check that the characteristics of the signal
        on \textbf{channel 1 of the oscilloscope} are as follows (Figure~\ref{fig:ttl-rs485}):
        \begin{itemize}
          \item approx. 1.2~$\mu$s
          \item approx. 3~V
        \end{itemize}
      \item If the signal characteristics are as above, \textbf{tick} the \textbf{TTL column for the channel} on the \textbf{Front panel} side
        of the table in Appendix~\ref{app:pulse-validation-ttl}
      \item \label{item:ttl-meas-rs485-out} Check that the characteristics of the signals at the
        \textbf{rear panel} are as follows (Figure~\ref{fig:ttl-rs485}):
        \begin{itemize}
          \item approx. 1.2~$\mu$s
          \item approx. 3~V
        \end{itemize}
      \item \label{item:ttl-meas-end} If the signal characteristics are as above, \textbf{tick} the \textbf{RS485} column for the channel
        on the \textbf{Front panel} side of the table in Appendix~\ref{app:pulse-validation-ttl}
    \end{enumerate}
  \item Repeat the following steps for \textbf{channel 5 down to channel 1}:
  \begin{enumerate}
    \item Using a \textbf{short LEMO 0S cable}, connect \textbf{a channel 6 rear-panel output}
      to the \textbf{rear panel channel input connector}
    \item Perform \textbf{steps \ref{item:ttl-meas-start} to \ref{item:ttl-meas-end}}, this time
      ticking the \textbf{TTL} and \textbf{RS485} columns on the \textbf{Rear panel} side of the
      table in Appendix~\ref{app:pulse-validation-ttl}
  \end{enumerate}
  \item \label{item:ttl-proc-end} Test the \textbf{remaining rear panel channel 6 input} by this procedure:
  \begin{enumerate}
    \item Using a \textbf{LEMO 00 cable}, connect \textbf{INV-TTL channel A OUT} to \textbf{TTL channel 1 IN}
    \item Using a \textbf{short LEMO 0S cable}, connect \textbf{rear panel channel 1 OUT} to \textbf{rear panel channel 6 IN}
    \item Perform \textbf{steps \ref{item:ttl-meas-start} to \ref{item:ttl-meas-end}}, this time
      ticking the \textbf{TTL} and \textbf{RS485} columns for \textbf{channel 6} on the \textbf{Rear panel} side of the
      table in Appendix~\ref{app:pulse-validation-ttl}
  \end{enumerate}
  \item Turn off power to the ELMA crate
  \item Change the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) to the \textbf{ON position}
  \item Turn on power to the ELMA crate
  \item Repeat \textbf{steps~\ref{item:ttl-proc-start}~to~\ref{item:ttl-proc-end}}, filling in the table in
    \textbf{Appendix~\ref{app:pulse-validation-ttl-gf}}
  \item Turn off power to the ELMA crate
  \item Change the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) back to the \textbf{OFF position}
\end{enumerate}

\begin{figure}
  \centerline{\includegraphics[width=.8\textwidth]{fig/ttl-rs485.png}}
  \caption{TTL to RS485 conversion waveforms}
  \label{fig:ttl-rs485}
\end{figure}

%==============================================================================
\pagebreak
\subsection{TTL-BAR to RS485 pulse conversion}
\label{sec:proc-ttlbar-rs485}
%==============================================================================
\begin{enumerate}
  \item Make sure the \textbf{TTL switch} (Figure~\ref{fig:switches}) of the CONV-TTL-RS485 is in the \textbf{TTL-BAR position (off)}
  \item Make sure the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) is in the \textbf{OFF} position
  \item \label{item:ttlbar-proc-start} Repeat the following steps for \textbf{all six channels}, \textbf{starting from channel 1} and fill in the
    \textbf{table in Appendix~\ref{app:pulse-validation-ttlbar}}:
    \begin{enumerate}
      \item Connect the \textbf{DUT trigger} (see Section~\ref{sec:prep-pulse-gen}) to the \textbf{front panel  INV-TTL channel C
        input connector}
      \item Connect \textbf{INV-TTL channel A OUT} to the \textbf{front panel channel input}
      \item \label{item:ttlbar-meas-start} Connect the \textbf{front panel channel output} to \textbf{oscilloscope channel 1}
      \item Connect \textbf{a rear panel channel output} to \textbf{oscilloscope channel 2}
      \item \label{item:ttlbar-meas-ttl-out} Check that the characteristics of the signal
        on \textbf{channel 1 of the oscilloscope} are as follows (Figure~\ref{fig:ttlbar-rs485}):
        \begin{itemize}
          \item approx. 1.2~$\mu$s
          \item approx. 3~V
        \end{itemize}
      \item If the signal characteristics are as above, \textbf{tick} the \textbf{TTL column for the channel} on the \textbf{Front panel} side
        of the table in Appendix~\ref{app:pulse-validation-ttlbar}
      \item \label{item:ttlbar-meas-rs485-out} Check that the characteristics of the signals at the
        \textbf{rear panel} are as follows (Figure~\ref{fig:ttlbar-rs485}):
        \begin{itemize}
          \item approx. 1.2~$\mu$s
          \item approx. 3~V
        \end{itemize}
      \item \label{item:ttlbar-meas-end} If the signal characteristics are as above, \textbf{tick} the \textbf{RS485} column for the channel
        on the \textbf{Front panel} side of the table in Appendix~\ref{app:pulse-validation-ttlbar}
    \end{enumerate}
  \item Repeat the following steps for \textbf{channel 5 down to channel 1}:
  \begin{enumerate}
    \item Using a \textbf{short LEMO 0S cable}, connect \textbf{a channel 6 rear-panel output}
      to the \textbf{rear panel channel input connector}
    \item Perform \textbf{steps \ref{item:ttlbar-meas-start} to \ref{item:ttlbar-meas-end}}, this time
      ticking the \textbf{TTL} and \textbf{RS485} columns on the \textbf{Rear panel} side of the
      table in Appendix~\ref{app:pulse-validation-ttlbar}
  \end{enumerate}
  \pagebreak
  \item \label{item:ttlbar-proc-end} Test the \textbf{remaining rear panel channel 6 input} by this procedure:
  \begin{enumerate}
    \item Using a \textbf{LEMO 00 cable}, connect \textbf{INV-TTL channel A OUT} to \textbf{TTL channel 1 IN}
    \item Using a \textbf{short LEMO 0S cable}, connect \textbf{rear panel channel 1 OUT} to \textbf{rear panel channel 6 IN}
    \item Perform \textbf{steps \ref{item:ttlbar-meas-start} to \ref{item:ttlbar-meas-end}}, this time
      ticking the \textbf{TTL} and \textbf{RS485} columns for \textbf{channel 6} on the \textbf{Rear panel} side of the
      table in Appendix~\ref{app:pulse-validation-ttlbar}
  \end{enumerate}
  \item Turn off power to the ELMA crate
  \item Change the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) to the \textbf{ON position}
  \item Turn on power to the ELMA crate
  \item Repeat \textbf{steps~\ref{item:ttlbar-proc-start}~to~\ref{item:ttlbar-proc-end}}, filling in the table in
    \textbf{Appendix~\ref{app:pulse-validation-ttlbar-gf}}
  \item Turn off power to the ELMA crate
  \item Change the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) back to the \textbf{OFF position}
\end{enumerate}

\begin{figure}
  \centerline{\includegraphics[width=.8\textwidth]{fig/ttlbar-rs485.png}}
  \caption{TTL-BAR to RS485 conversion waveforms}
  \label{fig:ttlbar-rs485}
\end{figure}

%==============================================================================
\pagebreak
\subsection{Power-on tests (TTL-BAR)}
\label{sec:proc-power-on-ttlbar}
%==============================================================================
\begin{enumerate}
  \item Remove \textbf{all cables} from the \textbf{TTL and RS485 inputs and outputs}
  \item Make sure the \textbf{TTL switch} (Figure~\ref{fig:switches}) is \textbf{OFF}
  \item Make sure the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) is \textbf{OFF}
  \item \label{item:ttlbar-poweron} Follow this procedure:
  \begin{enumerate}
	  \item Configure the oscilloscope to trigger on the \textbf{falling edge} of the 
	    \textbf{channel 1} input, at \textbf{approx. 2.5~V}
	  \item Connect the \textbf{output of TTL channel 1} to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    TTL-BAR output with an unconnected TTL-BAR input)
	  \item Turn off ELMA crate
	  \item Connect \textbf{1x short LEMO cable} from \textbf{INV-TTL channel A output} to
	    \textbf{TTL channel 6 input}
	  \item Connect the \textbf{output of TTL channel 6} to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    TTL-BAR output with a connected TTL-BAR input)
	  \item Turn off ELMA crate
	  \item Configure the oscilloscope to trigger on the \textbf{rising edge} of the 
	    \textbf{channel 1} input
	  \item Connect \textbf{1x long LEMO 0S cable} from \textbf{RS485 output channel 1}
	  to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    RS485 output with an unconnected TTL-BAR input)  
	  \item Turn off ELMA crate
	  \item Connect \textbf{1x long LEMO cable} from \textbf{RS485 output channel 6}
	  to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    RS485 output with a connected TTL-BAR input)
	  \item Turn off ELMA crate
  \end{enumerate}    
  \item Flip the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) to the \textbf{ON position}
  \item Follow the procedure in step~\ref{item:ttlbar-poweron}
  \item Power-cycle the ELMA crate
  \item Run the \textit{rdchxpcr.py} script (\textit{software/diag/rdchxpcr.py})
    and confirm that all channel counters are 0
  \item Run the \textit{rdtb.py} script (\textit{software/diag/timetag/rdtb.py})
    and confirm that no pulses were stored to the timetag buffer
  \item Turn off ELMA crate
  \item Flip the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) back to the \textbf{OFF position}
\end{enumerate}
  
  
  
%==============================================================================
\subsection{Power-on tests (TTL)}
\label{sec:proc-power-on-ttl}
%==============================================================================
\begin{enumerate}
  \item Remove \textbf{all cables} from the \textbf{TTL and RS485 inputs and outputs}
  \item Put the \textbf{TTL switch} (Figure~\ref{fig:switches}) to the \textbf{ON} position
  \item Make sure the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) is \textbf{OFF}
  \item \label{item:ttl-poweron} Follow this procedure:
  \begin{enumerate}
	  \item Configure the oscilloscope to trigger on the \textbf{rising edge} of the 
	    \textbf{channel 1} input
	  \item Connect the \textbf{output of TTL channel 1} to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    TTL output with an unconnected TTL input)
	  \item Turn off ELMA crate
	  \item Connect \textbf{1x short LEMO cable} from \textbf{INV-TTL channel B output} to
	  \textbf{INV-TTL channel A input}
	  \item Connect \textbf{1x short LEMO cable} from \textbf{INV-TTL channel A} to
	    \textbf{TTL channel 6 input}
	  \item Connect the \textbf{output of TTL channel 6} to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    TTL output with a connected TTL input)
	  \item Turn off ELMA crate
	  \item Connect \textbf{1x long LEMO cable} from \textbf{RS485 output channel 1}
	  to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	    RS485 output with an unconnected TTL input)  
	  \item Turn off ELMA crate
	  \item Connect \textbf{1x long LEMO cable} from \textbf{RS485 output channel 6}
	  to \textbf{oscilloscope channel 1}
	  \item Turn on ELMA crate
	  \item Make sure the oscilloscope does not trigger (no pulse is generated on the
	  RS485 output with a connected TTL input)
	  \item Turn off ELMA crate
  \end{enumerate}    
  \item Flip the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) to the \textbf{ON position}
  \item Follow the procedure in step~\ref{item:ttl-poweron}
  \item Power-cycle the ELMA crate
  \item Run the \textit{rdchxpcr.py} script (\textit{software/diag/rdchxpcr.py})
    and confirm that all channel counters are 0
  \item Run the \textit{rdtb.py} script (\textit{software/diag/timetag/rdtb.py})
    and confirm that no pulses were stored to the timetag buffer
  \item Turn off ELMA crate
  \item Flip the \textbf{glitch filter switch} (Figure~\ref{fig:switches}) back to the \textbf{OFF position}
\end{enumerate}

%==============================================================================
\pagebreak
\subsection{Remote reprogramming test}
\label{sec:proc-multiboot}
%==============================================================================

We will now use the remote reprogramming logic to download a bitstream
to the flash and test that it works. For this, we will download the
binary file for remote reprogramming for the latest release version of the release
gateware and test that it has been correctly programmed to the flash.

\begin{enumerate}
  \item Turn on power to the ELMA crate.
  \item First, check using the \verb=getsr.py= script that the bitstream version
  is the one which you are testing. For example, say you are testing bistream version 1.1:
  \begin{verbatim}
$ cd software/diag/
$ ./getsr.py
[...]
Status register    : 0x00118011
===============================
Gateware version   : v1.1 (0x11)
[...]
  \end{verbatim}
  \item Change directories to the \verb=multiboot= folder and download the  binary file
  for remote reprogramming for the latest release on OHWR to a new \verb=bin/= sub-directory.
  For example, downloading gateware v3.0 would run like this:
  \begin{verbatim}
cd ../multiboot/
mkdir bin
wget http://cern.ch/go/V76d -O bin/conv_ttl_rs485-v1.0.bin
  \end{verbatim}
  \item Run the \verb=multiboot.py= script to download the bitstream to the flash
  and issue the reprogramming command at the end (note that downloading will take
  a long time):
  \begin{verbatim}
$ ./multiboot.py
Successfully connected to some-elma
SysMon firmware v2.31
Slot no.: 1
CONV-TTL-RS485 found in slot 1

Read config reg? (y/n) n
Read from flash? (y/n) n
Write to flash?  (y/n) y
Are you sure?    (y/n) y
Which gateware would you like to program?
   0 -> conv_ttl_rs485-v1.0.bin

Enter your choice : 0
Selected gateware: conv_ttl_rs485-v1.0.bin
Is this okay?    (y/n) y

Issue IPROG?     (y/n) y
MultiBoot bitstream address: 0x170000
Writing bitstream to board in slot 1
  0.81% (0x172f00)
  \end{verbatim}
  \item Once reprogramming is over, the logic will boot to this new bitstream:
  \begin{verbatim}
Writing bitstream to board in slot 1
  100.00% (0x2daa00)
DONE!
Issuing IPROG command to board in slot 1...
IPROG successful!
  \end{verbatim}
  \item To check the programming has indeed succeeded, check the gateware version,
  again using \verb=getsr.py=:
  \begin{verbatim}
$ cd ../diag/
$ ./getsr.py
[...]
Status register    : 0x00118030
===============================
Gateware version   : v3.0 (0x30)
[...]
  \end{verbatim}
\end{enumerate}


%==============================================================================
% APPENDICES
%==============================================================================
\pagebreak

\begin{appendices}

%==============================================================================
% APP: TTL pulse validation table
%==============================================================================
\section{Pulse conversion validation table (TTL, without glitch filter)}
\label{app:pulse-validation-ttl}

\centerline{
\resizebox{.8\textwidth}{!}{
\begin{tabular}{|l|*{2}{c}|*{2}{c}|}
  \hline
  \textbf{Input} & \multicolumn{2}{c|}{\textbf{Front panel}} & \multicolumn{2}{c|}{\textbf{Rear panel}} \\
  \hline
  \textbf{Output} & \textbf{TTL} & \textbf{RS485} & \textbf{TTL} & \textbf{RS485}       \\
  \hline
  \textbf{CH1} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH2} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH3} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH4} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH5} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH6} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \hline
\end{tabular}
}
}

\vspace*{11pt}

Instructions for filling in the table:

\begin{itemize}
  \item Following the test procedure in Section~\ref{sec:proc-ttl-rs485} (steps~\ref{item:ttl-proc-start}~to~\ref{item:ttl-proc-end}),
  tick each box if the output is as expected
  \item Tick the \textbf{TTL} boxes if the TTL output on the front panel is as specified
  in step \ref{item:ttl-meas-ttl-out} (Section~\ref{sec:proc-ttl-rs485})
  \item Tick the \textbf{RS485} boxes if the RS485 output on the rear panel
  is as specified in step \ref{item:ttl-meas-rs485-out} (Section~\ref{sec:proc-ttl-rs485})
\end{itemize}

%==============================================================================
% APP: TTL pulse validation table, GF on
%==============================================================================
\pagebreak
\section{Pulse conversion validation table (TTL, with glitch filter)}
\label{app:pulse-validation-ttl-gf}

\centerline{
\resizebox{.8\textwidth}{!}{
\begin{tabular}{|l|*{2}{c}|*{2}{c}|}
  \hline
  \textbf{Input} & \multicolumn{2}{c|}{\textbf{Front panel}} & \multicolumn{2}{c|}{\textbf{Rear panel}} \\
  \hline
  \textbf{Output} & \textbf{TTL} & \textbf{RS485} & \textbf{TTL} & \textbf{RS485}       \\
  \hline
  \textbf{CH1} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH2} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH3} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH4} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH5} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH6} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \hline
\end{tabular}
}
}

\vspace*{11pt}

Instructions for filling in the table:

\begin{itemize}
  \item Make sure the glitch filter is \textbf{ON}
  \item Following the test procedure in Section~\ref{sec:proc-ttl-rs485} (steps~\ref{item:ttl-proc-start}~to~\ref{item:ttl-proc-end}),
  tick each box if the output is as expected
  \item Tick the \textbf{TTL} boxes if the TTL output on the front panel is as specified
  in step \ref{item:ttl-meas-ttl-out} (Section~\ref{sec:proc-ttl-rs485})
  \item Tick the \textbf{RS485} boxes if the RS485 output on the rear panel
  is as specified in step \ref{item:ttl-meas-rs485-out} (Section~\ref{sec:proc-ttl-rs485})
\end{itemize}

%==============================================================================
% APP: TTL-BAR pulse validation table
%==============================================================================
\pagebreak
\section{Pulse conversion validation table (TTL-BAR, without glitch filter)}
\label{app:pulse-validation-ttlbar}

\centerline{
\resizebox{.8\textwidth}{!}{
\begin{tabular}{|l|*{2}{c}|*{2}{c}|}
  \hline
  \textbf{Input} & \multicolumn{2}{c|}{\textbf{Front panel}} & \multicolumn{2}{c|}{\textbf{Rear panel}} \\
  \hline
  \textbf{Output} & \textbf{TTL} & \textbf{RS485} & \textbf{TTL} & \textbf{RS485}       \\
  \hline
  \textbf{CH1} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH2} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH3} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH4} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH5} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH6} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \hline
\end{tabular}
}
}

\vspace*{11pt}

Instructions for filling in the table:

\begin{itemize}
  \item Following the test procedure in Section~\ref{sec:proc-ttlbar-rs485}
  (steps~\ref{item:ttlbar-proc-start}~to~\ref{item:ttlbar-proc-end}), tick each box if the output
  is as expected
  \item Tick the \textbf{TTL} boxes if the TTL output on the front panel is as specified
  in step \ref{item:ttlbar-meas-ttl-out} (Section~\ref{sec:proc-ttlbar-rs485})
  \item Tick the \textbf{RS485} boxes if the RS485 output on the rear panel
  is as specified in step \ref{item:ttlbar-meas-rs485-out} (Section~\ref{sec:proc-ttlbar-rs485})
\end{itemize}

%==============================================================================
% APP: TTL-BAR pulse validation table, GF on
%==============================================================================
\pagebreak
\section{Pulse conversion validation table (TTL-BAR, with glitch filter)}
\label{app:pulse-validation-ttlbar-gf}

\centerline{
\resizebox{.8\textwidth}{!}{
\begin{tabular}{|l|*{2}{c}|*{2}{c}|}
  \hline
  \textbf{Input} & \multicolumn{2}{c|}{\textbf{Front panel}} & \multicolumn{2}{c|}{\textbf{Rear panel}} \\
  \hline
  \textbf{Output} & \textbf{TTL} & \textbf{RS485} & \textbf{TTL} & \textbf{RS485}       \\
  \hline
  \textbf{CH1} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH2} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH3} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH4} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH5} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \textbf{CH6} & $\square$ & $\square$ & $\square$ & $\square$ \\
  \hline
\end{tabular}
}
}

\vspace*{11pt}

Instructions for filling in the table:

\begin{itemize}
  \item Make sure the glitch filter is \textbf{ON}
  (steps~\ref{item:ttlbar-proc-start}~to~\ref{item:ttlbar-proc-end}), tick each box if the output
  is as expected
  \item Tick the \textbf{TTL} boxes if the TTL output on the front panel is as specified
  in step \ref{item:ttlbar-meas-ttl-out} (Section~\ref{sec:proc-ttlbar-rs485})
  \item Tick the \textbf{RS485} boxes if the RS485 output on the rear panel
  is as specified in step \ref{item:ttlbar-meas-rs485-out} (Section~\ref{sec:proc-ttlbar-rs485})
\end{itemize}
\end{appendices}


%==============================================================================
% Bibliography
%==============================================================================
\pagebreak
\bibliographystyle{ieeetr}
\bibliography{gw-test-procedure}
\addcontentsline{toc}{section}{References}

\end{document}
