\hypertarget{latp_8c}{
\section{latp.c File Reference}
\label{latp_8c}\index{latp.c@{latp.c}}
}
Implements LATp networking protocol functions.  


{\tt \#include \char`\"{}latp\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}GNAT/gio.h\char`\"{}}\par
{\tt \#include \char`\"{}GNAT/bndl.h\char`\"{}}\par
{\tt \#include \char`\"{}GNAT/latp.h\char`\"{}}\par
{\tt \#include \char`\"{}gnat\_\-p.h\char`\"{}}\par
{\tt \#include $<$string.h$>$}\par
{\tt \#include $<$stdio.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{latp_8c_a0}{
\#define \hyperlink{latp_8c_a0}{LATP\_\-TYPE\_\-CMD\_\-RSP}\ (0)}
\label{latp_8c_a0}

\begin{CompactList}\small\item\em Expect cmd/rsp data in FIFO. \item\end{CompactList}\item 
\hypertarget{latp_8c_a1}{
\#define \hyperlink{latp_8c_a1}{LATP\_\-TYPE\_\-EVENT}\ (1)}
\label{latp_8c_a1}

\begin{CompactList}\small\item\em Expect event data in FIFO. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
int \hyperlink{latp_8c_a4}{calc\-Parity} (unsigned int n\-Words, unsigned int $\ast$arr)
\begin{CompactList}\small\item\em Calculates the odd parity in {\em arr\/}. \item\end{CompactList}\item 
void \hyperlink{latp_8c_a5}{srv\-Intr} (\hyperlink{struct__gnat}{gnat\-Handle} gh)
\begin{CompactList}\small\item\em ISR that gives the m\_\-sync\-Sem semaphore when the record FIFO has a packet ready. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a6}{g\-Wait\-Packet\-IRQ} (\hyperlink{struct__gnat}{gnat\-Handle} gh)
\begin{CompactList}\small\item\em Blocks on the ISR semaphore waiting for LATp packet ready IRQ. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a7}{\_\-\_\-dump\-FIFO} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short n\-Words)
\begin{CompactList}\small\item\em Dumps {\em n\-Words\/} from FIFO (if FIFO is non-empty). \item\end{CompactList}\item 
int \hyperlink{latp_8c_a8}{\_\-\_\-err\-Dump} (\hyperlink{struct__gnat}{gnat\-Handle} gh)
\begin{CompactList}\small\item\em Dumps response buffers and response FIFO. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a9}{g\-Read\-Rsp} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{struct__gResponse}{g\-Response} $\ast$rsp\-Info)
\begin{CompactList}\small\item\em Transfers data from the record FIFO to the {\em rsp\-Info\/} structure. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a10}{send\-LATp\-Cell} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{struct__LATp__Cell}{LATp\_\-Cell} $\ast$p\-Cell, unsigned char last\-Cell)
\begin{CompactList}\small\item\em Loads a LATp cell into the playback FIFO. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a11}{g\-Load\-Packet} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{struct__gResponse}{g\-Response} $\ast$rsp\-Info, unsigned short dest, unsigned short n\-Word16, unsigned short $\ast$payload)
\begin{CompactList}\small\item\em Loads a LATp packet into the COMM board FIFO. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a12}{g\-Send\-Packet} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{struct__gResponse}{g\-Response} $\ast$rsp\-Info, unsigned short dest, unsigned short n\-Word16, unsigned short $\ast$payload)
\begin{CompactList}\small\item\em Sends a LATp packet on the LAT network. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a13}{g\-Send\-LAM} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short dest\-Addr)
\begin{CompactList}\small\item\em Sends the \char`\"{}Look At Me\char`\"{} message to the LAT node {\em dest\-Addr\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a14}{g\-Set\-Addr} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short addr)
\begin{CompactList}\small\item\em Sets the source address of the LATp interface associated with {\em gh\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a15}{g\-Get\-Addr} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short $\ast$addr)
\begin{CompactList}\small\item\em Gets the source address of the LATp interface associated with {\em gh\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a16}{g\-Reset\-Comm\-Stats} (\hyperlink{struct__gnat}{gnat\-Handle} gh)
\begin{CompactList}\small\item\em Resets the network statistics for the LATp interface associated with {\em gh\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a17}{g\-Get\-TXstats} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{union__LATp__TXstats}{LATp\_\-TXstats} $\ast$tx\-Stats)
\begin{CompactList}\small\item\em Returns the current transmission statistics. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a18}{g\-Set\-TXstats} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{union__LATp__TXstats}{LATp\_\-TXstats} $\ast$tx\-Stats)
\begin{CompactList}\small\item\em Sets the current transmission statistics from {\em tx\-Stats\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a19}{g\-Get\-RXstats} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{union__LATp__RXstats}{LATp\_\-RXstats} $\ast$rx\-Stats)
\begin{CompactList}\small\item\em Returns the current recieve statistics. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a20}{g\-Set\-RXstats} (\hyperlink{struct__gnat}{gnat\-Handle} gh, \hyperlink{union__LATp__RXstats}{LATp\_\-RXstats} $\ast$rx\-Stats)
\begin{CompactList}\small\item\em Sets the current recieve statistics from {\em rx\-Stats\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a21}{g\-Set\-LATp\-Chnl} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned char chnl)
\begin{CompactList}\small\item\em Sets the incoming LATp channel number for the board. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a22}{g\-Set\-LATp\-Mode} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned char mode)
\begin{CompactList}\small\item\em Sets the running mode of the board. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a23}{g\-Set\-Protocol} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short proto)
\begin{CompactList}\small\item\em Sets the protocol to use. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a24}{g\-Get\-Protocol} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short $\ast$proto)
\begin{CompactList}\small\item\em Gets the current LATp protocol. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a25}{g\-Set\-Timeout} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short timeout)
\begin{CompactList}\small\item\em Sets the timeout to use for LATp interface. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a26}{set\-LATp\-Cell\-Header\-Parity} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short p)
\begin{CompactList}\small\item\em {\em p\/} determines if the LATp Cell\-Header Parity is inverted \item\end{CompactList}\item 
int \hyperlink{latp_8c_a27}{get\-LATp\-Cell\-Header\-Parity} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short $\ast$p)
\begin{CompactList}\small\item\em Returns the current LATp cell header parity setting in {\em p\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a28}{set\-LATp\-Cell\-Body\-Parity} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short p)
\begin{CompactList}\small\item\em {\em p\/} determines if the LATp Cell\-Body Parity is inverted \item\end{CompactList}\item 
int \hyperlink{latp_8c_a29}{get\-LATp\-Cell\-Body\-Parity} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short $\ast$p)
\begin{CompactList}\small\item\em Returns current LATp Cell\-Body Parity in {\em p\/}. \item\end{CompactList}\item 
int \hyperlink{latp_8c_a30}{set\-LATp\-Skip\-Rsp\-Words} (\hyperlink{struct__gnat}{gnat\-Handle} gh, unsigned short n\-Skip)
\begin{CompactList}\small\item\em {\em n\-Skip\/} controls how many FIFO words to skip before storing read back data. \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
\hypertarget{latp_8c_a2}{
int \hyperlink{latp_8c_a2}{gnat\_\-irq\-Delay} = 0}
\label{latp_8c_a2}

\begin{CompactList}\small\item\em Delay used in task\-Delay() before reading FIFO. \item\end{CompactList}\item 
unsigned short \hyperlink{latp_8c_a3}{\_\-LAMpayload} \mbox{[}$\,$\mbox{]}
\begin{CompactList}\small\item\em Array of 16-bit words to use at paylod for Look At Me command. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Implements LATp networking protocol functions. 

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


\subsection{Function Documentation}
\hypertarget{latp_8c_a7}{
\index{latp.c@{latp.c}!__dumpFIFO@{\_\-\_\-dumpFIFO}}
\index{__dumpFIFO@{\_\-\_\-dumpFIFO}!latp.c@{latp.c}}
\subsubsection[\_\-\_\-dumpFIFO]{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-dump\-FIFO (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em n\-Words})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{latp_8c_a7}


Dumps {\em n\-Words\/} from FIFO (if FIFO is non-empty). 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em n\-Words}]number of words to drain from FIFO. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK on success \end{Desc}
\hypertarget{latp_8c_a8}{
\index{latp.c@{latp.c}!__errDump@{\_\-\_\-errDump}}
\index{__errDump@{\_\-\_\-errDump}!latp.c@{latp.c}}
\subsubsection[\_\-\_\-errDump]{\setlength{\rightskip}{0pt plus 5cm}\_\-\_\-err\-Dump (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{latp_8c_a8}


Dumps response buffers and response FIFO. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK on success \end{Desc}
\hypertarget{latp_8c_a4}{
\index{latp.c@{latp.c}!calcParity@{calcParity}}
\index{calcParity@{calcParity}!latp.c@{latp.c}}
\subsubsection[calcParity]{\setlength{\rightskip}{0pt plus 5cm}int calc\-Parity (unsigned int {\em n\-Words}, unsigned int $\ast$ {\em arr})}}
\label{latp_8c_a4}


Calculates the odd parity in {\em arr\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em n\-Words}]Number of unsigned ints in @ arr \item[{\em arr}]Array of unsigned ints \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]odd parity of the bits contained in @ arr. \end{Desc}
\hypertarget{latp_8c_a29}{
\index{latp.c@{latp.c}!getLATpCellBodyParity@{getLATpCellBodyParity}}
\index{getLATpCellBodyParity@{getLATpCellBodyParity}!latp.c@{latp.c}}
\subsubsection[getLATpCellBodyParity]{\setlength{\rightskip}{0pt plus 5cm}int get\-LATp\-Cell\-Body\-Parity (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short $\ast$ {\em p})}}
\label{latp_8c_a29}


Returns current LATp Cell\-Body Parity in {\em p\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em p}]pointer to hold boolean value \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]STATUS\end{Desc}
If {\em p\/} is non-zero then all out going LATp packets will have their cell body parity inverted. This is used for testing parity errors. The default value is 0. \hypertarget{latp_8c_a27}{
\index{latp.c@{latp.c}!getLATpCellHeaderParity@{getLATpCellHeaderParity}}
\index{getLATpCellHeaderParity@{getLATpCellHeaderParity}!latp.c@{latp.c}}
\subsubsection[getLATpCellHeaderParity]{\setlength{\rightskip}{0pt plus 5cm}int get\-LATp\-Cell\-Header\-Parity (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short $\ast$ {\em p})}}
\label{latp_8c_a27}


Returns the current LATp cell header parity setting in {\em p\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em p}]pointer to hold boolean value \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]STATUS\end{Desc}
If {\em p\/} is non-zero then all out going LATp packets will have their cell header parity inverted. This is used for testing parity errors. The default value is 0. \hypertarget{latp_8c_a15}{
\index{latp.c@{latp.c}!gGetAddr@{gGetAddr}}
\index{gGetAddr@{gGetAddr}!latp.c@{latp.c}}
\subsubsection[gGetAddr]{\setlength{\rightskip}{0pt plus 5cm}g\-Get\-Addr (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short $\ast$ {\em addr})}}
\label{latp_8c_a15}


Gets the source address of the LATp interface associated with {\em gh\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em addr}]pointer to storage for holding LATp address on return \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a14}{g\-Set\-Addr()} \end{Desc}
\hypertarget{latp_8c_a24}{
\index{latp.c@{latp.c}!gGetProtocol@{gGetProtocol}}
\index{gGetProtocol@{gGetProtocol}!latp.c@{latp.c}}
\subsubsection[gGetProtocol]{\setlength{\rightskip}{0pt plus 5cm}g\-Get\-Protocol (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short $\ast$ {\em proto})}}
\label{latp_8c_a24}


Gets the current LATp protocol. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em proto}]pointer to storage to hold the protocol \end{description}
\end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a23}{g\-Set\-Protocol()} \end{Desc}
\begin{Desc}
\item[Returns:]OK on success\end{Desc}
This gets the protocol field, which is applied to the cell header for all subsequent out bound packets. \hypertarget{latp_8c_a19}{
\index{latp.c@{latp.c}!gGetRXstats@{gGetRXstats}}
\index{gGetRXstats@{gGetRXstats}!latp.c@{latp.c}}
\subsubsection[gGetRXstats]{\setlength{\rightskip}{0pt plus 5cm}g\-Get\-RXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__RXstats}{LATp\_\-RXstats} $\ast$ {\em rx\-Stats})}}
\label{latp_8c_a19}


Returns the current recieve statistics. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em rx\-Stats}]pointer to storage for holding the RX stats on return \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a17}{g\-Get\-TXstats()}, \hyperlink{latp_8c_a16}{g\-Reset\-Comm\-Stats()} \end{Desc}
\hypertarget{latp_8c_a17}{
\index{latp.c@{latp.c}!gGetTXstats@{gGetTXstats}}
\index{gGetTXstats@{gGetTXstats}!latp.c@{latp.c}}
\subsubsection[gGetTXstats]{\setlength{\rightskip}{0pt plus 5cm}g\-Get\-TXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__TXstats}{LATp\_\-TXstats} $\ast$ {\em tx\-Stats})}}
\label{latp_8c_a17}


Returns the current transmission statistics. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em tx\-Stats}]pointer to storage for holding the TX stats on return \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a19}{g\-Get\-RXstats()}, \hyperlink{latp_8c_a16}{g\-Reset\-Comm\-Stats()} \end{Desc}
\hypertarget{latp_8c_a11}{
\index{latp.c@{latp.c}!gLoadPacket@{gLoadPacket}}
\index{gLoadPacket@{gLoadPacket}!latp.c@{latp.c}}
\subsubsection[gLoadPacket]{\setlength{\rightskip}{0pt plus 5cm}g\-Load\-Packet (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{struct__gResponse}{g\-Response} $\ast$ {\em rsp\-Info}, unsigned short {\em dest}, unsigned short {\em n\-Word16}, unsigned short $\ast$ {\em payload})}}
\label{latp_8c_a11}


Loads a LATp packet into the COMM board FIFO. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em rsp\-Info}]pointer to storage for response \item[{\em dest}]6 bit LAT address of destination \item[{\em n\-Word16}]length of the 16-bit wide payload vector \item[{\em payload}]pointer to an array of 16-bit words of length n\-Word16 \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a10}{send\-LATp\-Cell}\end{Desc}


Loads a LATp packet into the COMM board FIFO. Using {\em rsp\-Info\/}, {\em dest\/}, {\em source\/} it constructs a 16 bit header word for the control cell of the packet. It fills the remainder of the 128-bit control cell with data from payload (up to 14 bytes). The control cell is preceded by a 2 bit delineator and follow by a truncate bit and parity bit -- if the payload is larger than 14 bytes then additional data cells are created and injected with the appropriate delineator and suffix bits.

Caller is responsible for initializing FIFO and for initiating the playback. \hypertarget{latp_8c_a9}{
\index{latp.c@{latp.c}!gReadRsp@{gReadRsp}}
\index{gReadRsp@{gReadRsp}!latp.c@{latp.c}}
\subsubsection[gReadRsp]{\setlength{\rightskip}{0pt plus 5cm}g\-Read\-Rsp (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{struct__gResponse}{g\-Response} $\ast$ {\em rsp\-Info})}}
\label{latp_8c_a9}


Transfers data from the record FIFO to the {\em rsp\-Info\/} structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em rsp\-Info}]pointer to storage to hold response data \end{description}
\end{Desc}
After recieving the interrupt for \char`\"{}record FIFO packet ready\char`\"{} read\-Rsp() transfers the packet from the record FIFO to {\em rsp\-Info-$>$m\_\-rsp\-Buffer\/};

The routine checks bits 17 and 18 of every 9th FIFO word to determine when the last packet has been processed -- when these bits are {\bf both zero} we have reached the end of the packet chain (potentially multiple packets, if the packets are back-to-back).

Updates the LATp interface reciever statistics for packets received, cell parity errors and cell header parity errors. The response could contain multiple packets.

Coming off the response FIFO LATp cells are 9 words long. Word 1 has the cell announce and cell type bits, while word 9 has the truncate and parity error bits.

Additionally word 1 also has the cell header if the cell type is a control cell. \hypertarget{latp_8c_a16}{
\index{latp.c@{latp.c}!gResetCommStats@{gResetCommStats}}
\index{gResetCommStats@{gResetCommStats}!latp.c@{latp.c}}
\subsubsection[gResetCommStats]{\setlength{\rightskip}{0pt plus 5cm}g\-Reset\-Comm\-Stats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh})}}
\label{latp_8c_a16}


Resets the network statistics for the LATp interface associated with {\em gh\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a17}{g\-Get\-TXstats()}, \hyperlink{latp_8c_a19}{g\-Get\-RXstats()} \end{Desc}
\hypertarget{latp_8c_a13}{
\index{latp.c@{latp.c}!gSendLAM@{gSendLAM}}
\index{gSendLAM@{gSendLAM}!latp.c@{latp.c}}
\subsubsection[gSendLAM]{\setlength{\rightskip}{0pt plus 5cm}int g\-Send\-LAM (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em dest\-Addr})}}
\label{latp_8c_a13}


Sends the \char`\"{}Look At Me\char`\"{} message to the LAT node {\em dest\-Addr\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em dest\-Addr}]destination address of command \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
Sends the \char`\"{}Look At Me\char`\"{} message to the LAT node specified by {\em dest\-Addr\/}. This is used to switch the command/response wire used by the LAT node. If the LAT node decodes the \char`\"{}Look At Me\char`\"{} message on either it's A or B command channel it will switch to that channel for future commanding. \hypertarget{latp_8c_a12}{
\index{latp.c@{latp.c}!gSendPacket@{gSendPacket}}
\index{gSendPacket@{gSendPacket}!latp.c@{latp.c}}
\subsubsection[gSendPacket]{\setlength{\rightskip}{0pt plus 5cm}g\-Send\-Packet (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{struct__gResponse}{g\-Response} $\ast$ {\em rsp\-Info}, unsigned short {\em dest}, unsigned short {\em n\-Word16}, unsigned short $\ast$ {\em payload})}}
\label{latp_8c_a12}


Sends a LATp packet on the LAT network. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em rsp\-Info}]pointer to extra information required if command expects a response. \item[{\em dest}]6 bit LAT address of destination \item[{\em n\-Word16}]length of the 16-bit wide payload vector \item[{\em payload}]pointer to an array of 16-bit words of length n\-Word16 \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a10}{send\-LATp\-Cell}\end{Desc}


Sends a LATp packet on the network. Using {\em rsp\-Info\/}, {\em dest\/}, {\em source\/} it constructs a 16 bit header word for the control cell of the packet. It fills the remainder of the 128-bit control cell with data from payload (up to 14 bytes). The control cell is injected in the network preceded by a 2 bit delineator and follow by a truncate bit and parity bit -- if the payload is larger than 14 bytes then additional data cells are created and injected with the appropriate delineator and suffix bits. \hypertarget{latp_8c_a14}{
\index{latp.c@{latp.c}!gSetAddr@{gSetAddr}}
\index{gSetAddr@{gSetAddr}!latp.c@{latp.c}}
\subsubsection[gSetAddr]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-Addr (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em addr})}}
\label{latp_8c_a14}


Sets the source address of the LATp interface associated with {\em gh\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em addr}]LATp address \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a15}{g\-Get\-Addr()} \end{Desc}
\hypertarget{latp_8c_a21}{
\index{latp.c@{latp.c}!gSetLATpChnl@{gSetLATpChnl}}
\index{gSetLATpChnl@{gSetLATpChnl}!latp.c@{latp.c}}
\subsubsection[gSetLATpChnl]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-LATp\-Chnl (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned char {\em chnl})}}
\label{latp_8c_a21}


Sets the incoming LATp channel number for the board. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em chnl}]channel number \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK on success\end{Desc}
Sets the incoming LATp channel number of the COMM I/O board when running in LATp mode. Causes a read-modify-write of the COMM I/O control register. \hypertarget{latp_8c_a22}{
\index{latp.c@{latp.c}!gSetLATpMode@{gSetLATpMode}}
\index{gSetLATpMode@{gSetLATpMode}!latp.c@{latp.c}}
\subsubsection[gSetLATpMode]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-LATp\-Mode (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned char {\em mode})}}
\label{latp_8c_a22}


Sets the running mode of the board. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em mode}]boolean for LATp mode \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK on success\end{Desc}
Sets the running mode of the COMM I/O board based on the boolean value of {\em mode\/}. When {\em mode\/} is {\bf non-zero} the mode bit of the COMM I/O control register is set to 1, which puts the board in \char`\"{}LATp mode\char`\"{}. When {\em mode\/} is {\bf zero} the mode bit is cleared, which puts the board in \char`\"{}dumb record FIFO mode\char`\"{}. \hypertarget{latp_8c_a23}{
\index{latp.c@{latp.c}!gSetProtocol@{gSetProtocol}}
\index{gSetProtocol@{gSetProtocol}!latp.c@{latp.c}}
\subsubsection[gSetProtocol]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-Protocol (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em proto})}}
\label{latp_8c_a23}


Sets the protocol to use. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em proto}]2 LSB define the protocol to use \end{description}
\end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a24}{g\-Get\-Protocol()} \end{Desc}
\begin{Desc}
\item[Returns:]OK on success\end{Desc}
This sets the protocol field of the cell header for all subsequent out bound packets. \hypertarget{latp_8c_a20}{
\index{latp.c@{latp.c}!gSetRXstats@{gSetRXstats}}
\index{gSetRXstats@{gSetRXstats}!latp.c@{latp.c}}
\subsubsection[gSetRXstats]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-RXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__RXstats}{LATp\_\-RXstats} $\ast$ {\em rx\-Stats})}}
\label{latp_8c_a20}


Sets the current recieve statistics from {\em rx\-Stats\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em rx\-Stats}]pointer to RX stats to set \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a17}{g\-Get\-TXstats()}, \hyperlink{latp_8c_a16}{g\-Reset\-Comm\-Stats()} \end{Desc}
\hypertarget{latp_8c_a25}{
\index{latp.c@{latp.c}!gSetTimeout@{gSetTimeout}}
\index{gSetTimeout@{gSetTimeout}!latp.c@{latp.c}}
\subsubsection[gSetTimeout]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-Timeout (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em timeout})}}
\label{latp_8c_a25}


Sets the timeout to use for LATp interface. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em timeout}]time in sysclk ticks to wait for response \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK on success \end{Desc}
\hypertarget{latp_8c_a18}{
\index{latp.c@{latp.c}!gSetTXstats@{gSetTXstats}}
\index{gSetTXstats@{gSetTXstats}!latp.c@{latp.c}}
\subsubsection[gSetTXstats]{\setlength{\rightskip}{0pt plus 5cm}g\-Set\-TXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__TXstats}{LATp\_\-TXstats} $\ast$ {\em tx\-Stats})}}
\label{latp_8c_a18}


Sets the current transmission statistics from {\em tx\-Stats\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em tx\-Stats}]pointer to TX stats to set. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a19}{g\-Get\-RXstats()}, \hyperlink{latp_8c_a16}{g\-Reset\-Comm\-Stats()} \end{Desc}
\hypertarget{latp_8c_a6}{
\index{latp.c@{latp.c}!gWaitPacketIRQ@{gWaitPacketIRQ}}
\index{gWaitPacketIRQ@{gWaitPacketIRQ}!latp.c@{latp.c}}
\subsubsection[gWaitPacketIRQ]{\setlength{\rightskip}{0pt plus 5cm}g\-Wait\-Packet\-IRQ (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh})}}
\label{latp_8c_a6}


Blocks on the ISR semaphore waiting for LATp packet ready IRQ. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK on success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8c_a25}{g\-Set\-Timeout()}\end{Desc}
Blocks waiting for the ISR semaphore. The timeout value is set using \hyperlink{latp_8c_a25}{g\-Set\-Timeout()}. \hypertarget{latp_8c_a10}{
\index{latp.c@{latp.c}!sendLATpCell@{sendLATpCell}}
\index{sendLATpCell@{sendLATpCell}!latp.c@{latp.c}}
\subsubsection[sendLATpCell]{\setlength{\rightskip}{0pt plus 5cm}static int send\-LATp\-Cell (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{struct__LATp__Cell}{LATp\_\-Cell} $\ast$ {\em p\-Cell}, unsigned char {\em last\-Cell})\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{latp_8c_a10}


Loads a LATp cell into the playback FIFO. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \item[{\em p\-Cell}]pointer to cell to send \item[{\em last\-Cell}]boolean flag, true if this cell is the last cell of a packet. \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]OK for success \end{Desc}
\begin{Desc}
\item[See also:]\hyperlink{latp_8h_a17}{g\-Send\-Packet}\end{Desc}


Loads a 128-bit LATp cell into the GNAT playback FIFO. The cell is preceded by a 2 bit delineator and followed by a truncate bit and parity bit.

Delineator: \begin{itemize}
\item bit 1 -- always 1 when sending a cell \item bit 2 -- 1 for control cell, 0 for data cell \end{itemize}


Suffix: \begin{itemize}
\item bit 1 -- truncate bit, set if {\bf not} last cell in packet, cleared otherwise \item bit 2 -- odd parity over previous 129 bits \end{itemize}


If this cell is the last cell in the packet then two additional trailing zeros are added after the parity bit \hypertarget{latp_8c_a28}{
\index{latp.c@{latp.c}!setLATpCellBodyParity@{setLATpCellBodyParity}}
\index{setLATpCellBodyParity@{setLATpCellBodyParity}!latp.c@{latp.c}}
\subsubsection[setLATpCellBodyParity]{\setlength{\rightskip}{0pt plus 5cm}int set\-LATp\-Cell\-Body\-Parity (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em p})}}
\label{latp_8c_a28}


{\em p\/} determines if the LATp Cell\-Body Parity is inverted 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em p}]boolean value \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]STATUS\end{Desc}
If {\em p\/} is non-zero then all out going LATp packets will have their cell body parity inverted. This is used for testing parity errors. The default value is 0. \hypertarget{latp_8c_a26}{
\index{latp.c@{latp.c}!setLATpCellHeaderParity@{setLATpCellHeaderParity}}
\index{setLATpCellHeaderParity@{setLATpCellHeaderParity}!latp.c@{latp.c}}
\subsubsection[setLATpCellHeaderParity]{\setlength{\rightskip}{0pt plus 5cm}int set\-LATp\-Cell\-Header\-Parity (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em p})}}
\label{latp_8c_a26}


{\em p\/} determines if the LATp Cell\-Header Parity is inverted 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em p}]boolean value \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]STATUS\end{Desc}
If {\em p\/} is non-zero then all out going LATp packets will have their cell header parity inverted. This is used for testing parity errors. The default value is 0. \hypertarget{latp_8c_a30}{
\index{latp.c@{latp.c}!setLATpSkipRspWords@{setLATpSkipRspWords}}
\index{setLATpSkipRspWords@{setLATpSkipRspWords}!latp.c@{latp.c}}
\subsubsection[setLATpSkipRspWords]{\setlength{\rightskip}{0pt plus 5cm}int set\-LATp\-Skip\-Rsp\-Words (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em n\-Skip})}}
\label{latp_8c_a30}


{\em n\-Skip\/} controls how many FIFO words to skip before storing read back data. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]handle of device \item[{\em n\-Skip}]number of read back FIFO words to skip \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]STATUS\end{Desc}
{\bf Warning:} This is only used for testing. The default value is 0 and should never be changed in normal operation.

Setting {\em n\-Skip\/} to a non-zero value causes the read back routine to skip {\em n\-Skip\/} FIFO words (read and discard) before storing the data.

This allows us to arbitrarily fill the record FIFO with N junk words and then instruct the read back routines to skip over the N junk words before reading and storing the data. With this technique we can probe the TEM to COMM flow control based on the {\bf Almost Full Flag} of the record FIFO. \hypertarget{latp_8c_a5}{
\index{latp.c@{latp.c}!srvIntr@{srvIntr}}
\index{srvIntr@{srvIntr}!latp.c@{latp.c}}
\subsubsection[srvIntr]{\setlength{\rightskip}{0pt plus 5cm}void srv\-Intr (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh})}}
\label{latp_8c_a5}


ISR that gives the m\_\-sync\-Sem semaphore when the record FIFO has a packet ready. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gh}]gnat driver handle previously allocated \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]void \end{Desc}


\subsection{Variable Documentation}
\hypertarget{latp_8c_a3}{
\index{latp.c@{latp.c}!_LAMpayload@{\_\-LAMpayload}}
\index{_LAMpayload@{\_\-LAMpayload}!latp.c@{latp.c}}
\subsubsection[\_\-LAMpayload]{\setlength{\rightskip}{0pt plus 5cm}static unsigned short \hyperlink{latp_8c_a3}{\_\-LAMpayload}\mbox{[}$\,$\mbox{]}\hspace{0.3cm}{\tt  \mbox{[}static\mbox{]}}}}
\label{latp_8c_a3}


{\bf Initial value:}

\footnotesize\begin{verbatim} {
  0x9C3E, 
  0x07F0, 
  0x0FF8, 
  0x01FF, 
  0xC003, 
  0xFFE0, 
  0x007F, 
}
\end{verbatim}\normalsize 
Array of 16-bit words to use at paylod for Look At Me command. 

