\hypertarget{gTKR_8c}{
\section{g\-TKR.c File Reference}
\label{gTKR_8c}\index{gTKR.c@{gTKR.c}}
}
Implements command/response for the off board tracker subsystem.  


{\tt \#include $<$string.h$>$}\par
{\tt \#include \char`\"{}gt\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}g\-TKR\_\-p.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{gTKR_8c_a0}{set\-Acc\-Desc\-TKR} (\hyperlink{struct__gtem}{gtem\-Handle} gt, unsigned short gtrc\-Addr, unsigned short gtfe\-Target, unsigned short gtfe\-Addr, unsigned short func, unsigned short reg, \hyperlink{union__accDescTKR}{acc\-Desc\-TKR} $\ast$ad)
\begin{CompactList}\small\item\em initializes an access descriptor for either a GTRC or GTFE \item\end{CompactList}\item 
void \hyperlink{gTKR_8c_a1}{pack\-Payload\-TKR} (\hyperlink{struct__gtem}{gtem\-Handle} gt, unsigned int tkr\-Cmd\-Header, unsigned int tkr\-AD, unsigned long long value, unsigned int $\ast$payload)
\begin{CompactList}\small\item\em Packs the tkr\-Cmd\-Header, tkr\-AD and value into the 64-bit payload. \item\end{CompactList}\item 
int \hyperlink{gTKR_8c_a2}{tkr\-Send\-Cmd} (\hyperlink{struct__gtem}{gtem\-Handle} gt, unsigned short tem\-Addr, unsigned short gtcc\-Addr, unsigned short gtrc\-Addr, unsigned short ext, unsigned short gtfe\-Addr, unsigned short func, unsigned short reg, unsigned long long value, g\-Response $\ast$rsp)
\begin{CompactList}\small\item\em Loads a register with value. \item\end{CompactList}\item 
int \hyperlink{gTKR_8c_a3}{\_\-TKRread} (\hyperlink{struct__gtem}{gtem\-Handle} gt, unsigned short tem\-Addr, unsigned short gtcc\-Addr, unsigned short gtrc\-Addr, unsigned short ext, unsigned short gtfe\-Addr, unsigned short reg, unsigned long long $\ast$val)
\begin{CompactList}\small\item\em Reads a register returing value in {\em val\/}. \item\end{CompactList}\item 
int \hyperlink{gTKR_8c_a4}{g\-GTRC\_\-read\-Evt} (\hyperlink{struct__gtem}{gtem\-Handle} gt, unsigned short tem\-Addr, unsigned short gtcc\-Addr, unsigned short gtrc\-Addr, unsigned short tag)
\begin{CompactList}\small\item\em Sends a read event command to the destination GTFE. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Implements command/response for the off board tracker subsystem. 

\begin{Desc}
\item[Author:]Curt Brune -- \href{mailto:curt@slac.stanford.edu}{\tt curt@slac.stanford.edu} \end{Desc}


\subsection{Function Documentation}
\hypertarget{gTKR_8c_a3}{
\index{gTKR.c@{g\-TKR.c}!_TKRread@{\_\-TKRread}}
\index{_TKRread@{\_\-TKRread}!gTKR.c@{g\-TKR.c}}
\subsubsection[\_\-TKRread]{\setlength{\rightskip}{0pt plus 5cm}int \_\-TKRread (\hyperlink{struct__gtem}{gtem\-Handle} {\em gt}, unsigned short {\em tem\-Addr}, unsigned short {\em gtcc\-Addr}, unsigned short {\em gtrc\-Addr}, unsigned short {\em ext}, unsigned short {\em gtfe\-Addr}, unsigned short {\em reg}, unsigned long long $\ast$ {\em val})}}
\label{gTKR_8c_a3}


Reads a register returing value in {\em val\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gt}]gtem\-Handle for TEM \item[{\em tem\-Addr}]tem\-Addrination of command \item[{\em gtcc\-Addr}]GTCC address \item[{\em gtrc\-Addr}]GTRC address \item[{\em ext}]set for GTFE access \item[{\em gtfe\-Addr}]GTFE address \item[{\em reg}]register of GTRC to read \item[{\em val}]pointer to storage to hold the response of the read command \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
Reads the GTRC/GTFE register specified by {\em gtrc\-Addr\/}, {\em gtfe\-Addr\/}, {\em reg\/}.

The following error codes are returned:

\begin{itemize}
\item GERR\_\-LATP\_\-HEADER\_\-PARITY \item GERR\_\-LATP\_\-CELL\_\-PARITY \item GERR\_\-LATP\_\-TRUNCATE \item GTKR\_\-ERR\_\-SUMMARY \item GTKR\_\-ERR\_\-PARITY \end{itemize}
\hypertarget{gTKR_8c_a4}{
\index{gTKR.c@{g\-TKR.c}!gGTRC_readEvt@{gGTRC\_\-readEvt}}
\index{gGTRC_readEvt@{gGTRC\_\-readEvt}!gTKR.c@{g\-TKR.c}}
\subsubsection[gGTRC\_\-readEvt]{\setlength{\rightskip}{0pt plus 5cm}int g\-GTRC\_\-read\-Evt (\hyperlink{struct__gtem}{gtem\-Handle} {\em gt}, unsigned short {\em tem\-Addr}, unsigned short {\em gtcc\-Addr}, unsigned short {\em gtrc\-Addr}, unsigned short {\em tag})}}
\label{gTKR_8c_a4}


Sends a read event command to the destination GTFE. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gt}]gtem\-Handle for TEM \item[{\em tem\-Addr}]TEM address \item[{\em gtcc\-Addr}]GTCC address \item[{\em gtrc\-Addr}]GTRC address \item[{\em tag}]2-bit tag for read event command \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
Most often the FE address will be the broadcast address \hypertarget{gTKR_8c_a1}{
\index{gTKR.c@{g\-TKR.c}!packPayloadTKR@{packPayloadTKR}}
\index{packPayloadTKR@{packPayloadTKR}!gTKR.c@{g\-TKR.c}}
\subsubsection[packPayloadTKR]{\setlength{\rightskip}{0pt plus 5cm}void pack\-Payload\-TKR (\hyperlink{struct__gtem}{gtem\-Handle} {\em gt}, unsigned int {\em tkr\-Cmd\-Header}, unsigned int {\em tkr\-AD}, unsigned long long {\em value}, unsigned int $\ast$ {\em payload})}}
\label{gTKR_8c_a1}


Packs the tkr\-Cmd\-Header, tkr\-AD and value into the 64-bit payload. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gt}]gtem\-Handle for TEM \item[{\em tkr\-Cmd\-Header}]9-bit TKR command header word \item[{\em tkr\-AD}]17-bit TKR access descriptor word \item[{\em value}]64-bit value to load into TKR register \item[{\em payload}]pointer to 64-bits of pre-allocated storage \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]void\end{Desc}
Packs the bits of {\em tkr\-Cmd\-Header\/}, {\em tkr\-AD\/} and {\em value\/} into the 96-bits pointed to by {\em payload\/}. The packing is specific to \char`\"{}off board\char`\"{} registers for the GTRC and GTFE.

Format of 64-bit payload:

\mbox{[}1\mbox{]}\mbox{[} bits 63-48 \mbox{]}\mbox{[}1\mbox{]}\mbox{[} bits 47-32 \mbox{]}\mbox{[}1\mbox{]}\mbox{[} bits 31-16 \mbox{]}\mbox{[}1\mbox{]}\mbox{[} bits 15-0\mbox{]}\mbox{[}P\mbox{]}

Four 16 bit sections, each preceded by marker bit -- parity at end.

word 0: \mbox{[} 9 bits tkr\-Cmd\-Header \mbox{]}\mbox{[} 17 bits tkr\-AD \mbox{]}\mbox{[} 6 bits payload\mbox{]} word 1: \mbox{[} 32 bits payload \mbox{]} word 2: \mbox{[} 30 bits payload \mbox{[}P\mbox{]}\mbox{[}0\mbox{]} \hypertarget{gTKR_8c_a0}{
\index{gTKR.c@{g\-TKR.c}!setAccDescTKR@{setAccDescTKR}}
\index{setAccDescTKR@{setAccDescTKR}!gTKR.c@{g\-TKR.c}}
\subsubsection[setAccDescTKR]{\setlength{\rightskip}{0pt plus 5cm}static void set\-Acc\-Desc\-TKR (\hyperlink{struct__gtem}{gtem\-Handle} {\em gt}, unsigned short {\em gtrc\-Addr}, unsigned short {\em ext}, unsigned short {\em gtfe\-Addr}, unsigned short {\em func}, unsigned short {\em reg}, \hyperlink{union__accDescTKR}{acc\-Desc\-TKR} $\ast$ {\em ad})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{gTKR_8c_a0}


initializes an access descriptor for either a GTRC or GTFE 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gt}]gtem\-Handle for TEM \item[{\em ad}]pointer to TKR access descriptor \item[{\em ext}]set for GTFE commands \item[{\em gtrc\-Addr}]GTRC address \item[{\em gtfe\-Addr}]GTFE address \item[{\em func}]TKR fucntion code \item[{\em reg}]register of TKR object \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on void\end{Desc}
Sets a tracker access descriptor, destined for either GTRC or GTFE. \hypertarget{gTKR_8c_a2}{
\index{gTKR.c@{g\-TKR.c}!tkrSendCmd@{tkrSendCmd}}
\index{tkrSendCmd@{tkrSendCmd}!gTKR.c@{g\-TKR.c}}
\subsubsection[tkrSendCmd]{\setlength{\rightskip}{0pt plus 5cm}int tkr\-Send\-Cmd (\hyperlink{struct__gtem}{gtem\-Handle} {\em gt}, unsigned short {\em tem\-Addr}, unsigned short {\em gtcc\-Addr}, unsigned short {\em gtrc\-Addr}, unsigned short {\em ext}, unsigned short {\em gtfe\-Addr}, unsigned short {\em func}, unsigned short {\em reg}, unsigned long long {\em value}, g\-Response $\ast$ {\em rsp})}}
\label{gTKR_8c_a2}


Loads a register with value. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gt}]gtem\-Handle for TEM \item[{\em tem\-Addr}]TEM address \item[{\em gtcc\-Addr}]GTCC address \item[{\em gtrc\-Addr}]GTRC address \item[{\em ext}]set for GTFE access \item[{\em gtfe\-Addr}]GTFE address \item[{\em func}]function code to send \item[{\em reg}]register of GTRC to load \item[{\em value}]16-bit value to load into TKR register \item[{\em rsp}]pointer to storage for response \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
Sends load/read/dataless GTRC and GTFE commands 