\hypertarget{latp_8h}{
\section{latp.h File Reference}
\label{latp_8h}\index{latp.h@{latp.h}}
}
Defines public structs and methods of the LATp protocol.  


\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{struct____BFcellHeader}{\_\-\_\-BFcell\-Header}
\begin{CompactList}\small\item\em layout of a control cell header \item\end{CompactList}\item 
union \hyperlink{union____cellHeader}{\_\-\_\-cell\-Header}
\begin{CompactList}\small\item\em union for 16-bit control cell header \item\end{CompactList}\item 
struct \hyperlink{struct__BFrspErr}{\_\-BFrsp\-Err}
\begin{CompactList}\small\item\em Contains error info regarding LATp responses. \item\end{CompactList}\item 
union \hyperlink{union__generic__Cell}{\_\-generic\_\-Cell}
\begin{CompactList}\small\item\em union for 128-bit LATp cell -- either control or data cell. \item\end{CompactList}\item 
struct \hyperlink{struct__gResponse}{\_\-g\-Response}
\begin{CompactList}\small\item\em Contains info for LATp responses. \item\end{CompactList}\item 
struct \hyperlink{struct__LATp__Cell}{\_\-LATp\_\-Cell}
\begin{CompactList}\small\item\em LATp cell structure. \item\end{CompactList}\item 
struct \hyperlink{struct__LATp__ControlCell}{\_\-LATp\_\-Control\-Cell}
\begin{CompactList}\small\item\em layout of a 128-bit LATp control cell. \item\end{CompactList}\item 
struct \hyperlink{struct__LATp__DataCell}{\_\-LATp\_\-Data\-Cell}
\begin{CompactList}\small\item\em layout of a 128-bit LATp data cell. \item\end{CompactList}\item 
union \hyperlink{union__LATp__RXstats}{\_\-LATp\_\-RXstats}
\begin{CompactList}\small\item\em Union for 16-bit LATp receiver statistics word. \item\end{CompactList}\item 
struct \hyperlink{struct__LATp__RXstatsBF}{\_\-LATp\_\-RXstats\-BF}
\begin{CompactList}\small\item\em Structure that defines the LATp receiver statistics word. \item\end{CompactList}\item 
union \hyperlink{union__LATp__TXstats}{\_\-LATp\_\-TXstats}
\begin{CompactList}\small\item\em Union for 16-bit LATp transmitter statistics word. \item\end{CompactList}\item 
struct \hyperlink{struct__LATp__TXstatsBF}{\_\-LATp\_\-TXstats\-BF}
\begin{CompactList}\small\item\em Structure that defines the LATp transmitter statistics word. \item\end{CompactList}\item 
union \hyperlink{union__rspErr}{\_\-rsp\-Err}
\begin{CompactList}\small\item\em union for 32-bit response error flags \item\end{CompactList}\end{CompactItemize}
\subsection*{Defines}
\begin{CompactItemize}
\item 
\hypertarget{latp_8h_a0}{
\#define \hyperlink{latp_8h_a0}{WAIT\_\-FOREVER}\ (0)}
\label{latp_8h_a0}

\begin{CompactList}\small\item\em Defined for local host compilation. \item\end{CompactList}\item 
\hypertarget{latp_8h_a1}{
\#define \hyperlink{latp_8h_a1}{MAX\_\-EVENT\_\-SIZE}\ (4096)}
\label{latp_8h_a1}

\begin{CompactList}\small\item\em Maximum event size in bytes. \item\end{CompactList}\item 
\hypertarget{latp_8h_a2}{
\#define \hyperlink{latp_8h_a2}{LATP\_\-CELL\_\-SIZE\_\-BYTES}\ (sizeof(\hyperlink{struct__LATp__DataCell}{LATp\_\-Data\-Cell}))}
\label{latp_8h_a2}

\begin{CompactList}\small\item\em Size of LATp cell in bytes. \item\end{CompactList}\item 
\hypertarget{latp_8h_a3}{
\#define \hyperlink{latp_8h_a3}{ODD\_\-PARITY}(p)\ ($\sim$(BITCOUNT(p)) \& 0x1)}
\label{latp_8h_a3}

\begin{CompactList}\small\item\em Computes odd parity of 32-bit argument. \item\end{CompactList}\item 
\hypertarget{latp_8h_a4}{
\#define \hyperlink{latp_8h_a4}{EVEN\_\-PARITY}(p)\ ((BITCOUNT(p)) \& 0x1)}
\label{latp_8h_a4}

\begin{CompactList}\small\item\em Computes even parity of 32-bit argument. \item\end{CompactList}\item 
\#define \hyperlink{latp_8h_a5}{BITCOUNT}(x)\ (((BX\_\-(x)+(BX\_\-(x)$>$$>$4)) \& 0x0F0F0F0F) \% 255)
\begin{CompactList}\small\item\em Computes the number of bits set (1) in 32-but argument. \item\end{CompactList}\item 
\#define \hyperlink{latp_8h_a6}{BX\_\-}(x)
\begin{CompactList}\small\item\em Replaces each 4-bit sequence in arg by the number of bits in sequence. \item\end{CompactList}\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{latp_8h_a7}{
typedef \hyperlink{union__LATp__TXstats}{\_\-LATp\_\-TXstats} \hyperlink{latp_8h_a7}{LATp\_\-TXstats}}
\label{latp_8h_a7}

\begin{CompactList}\small\item\em typedef for union \hyperlink{union__LATp__TXstats}{\_\-LATp\_\-TXstats} \item\end{CompactList}\item 
\hypertarget{latp_8h_a8}{
typedef \hyperlink{union__LATp__RXstats}{\_\-LATp\_\-RXstats} \hyperlink{latp_8h_a8}{LATp\_\-RXstats}}
\label{latp_8h_a8}

\begin{CompactList}\small\item\em typedef for union \hyperlink{union__LATp__RXstats}{\_\-LATp\_\-RXstats} \item\end{CompactList}\item 
\hypertarget{latp_8h_a9}{
typedef \hyperlink{union__rspErr}{\_\-rsp\-Err} \hyperlink{latp_8h_a9}{rsp\-Err}}
\label{latp_8h_a9}

\begin{CompactList}\small\item\em typedef for union \hyperlink{union__rspErr}{\_\-rsp\-Err} \item\end{CompactList}\item 
\hypertarget{latp_8h_a10}{
typedef \hyperlink{struct__gResponse}{\_\-g\-Response} \hyperlink{latp_8h_a10}{g\-Response}}
\label{latp_8h_a10}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{struct__gResponse}{\_\-g\-Response}. \item\end{CompactList}\item 
\hypertarget{latp_8h_a11}{
typedef \hyperlink{union____cellHeader}{\_\-\_\-cell\-Header} \hyperlink{latp_8h_a11}{cell\-Header}}
\label{latp_8h_a11}

\begin{CompactList}\small\item\em typedef for union \_\-cell\-Header \item\end{CompactList}\item 
\hypertarget{latp_8h_a12}{
typedef \hyperlink{struct__LATp__ControlCell}{\_\-LATp\_\-Control\-Cell} \hyperlink{latp_8h_a12}{LATp\_\-Control\-Cell}}
\label{latp_8h_a12}

\begin{CompactList}\small\item\em typedef for struct \hyperlink{struct__LATp__ControlCell}{\_\-LATp\_\-Control\-Cell} \item\end{CompactList}\item 
\hypertarget{latp_8h_a13}{
typedef \hyperlink{struct__LATp__DataCell}{\_\-LATp\_\-Data\-Cell} \hyperlink{latp_8h_a13}{LATp\_\-Data\-Cell}}
\label{latp_8h_a13}

\begin{CompactList}\small\item\em typedef for struct \hyperlink{struct__LATp__DataCell}{\_\-LATp\_\-Data\-Cell} \item\end{CompactList}\item 
\hypertarget{latp_8h_a14}{
typedef enum \hyperlink{latp_8h_a40}{\_\-Cell\-Type} \hyperlink{latp_8h_a14}{Cell\-Type}}
\label{latp_8h_a14}

\begin{CompactList}\small\item\em typedef of enum \_\-Cell\-Type \item\end{CompactList}\end{CompactItemize}
\subsection*{Enumerations}
\begin{CompactItemize}
\item 
enum \hyperlink{latp_8h_a40}{\_\-Cell\-Type} \{ \par
{\bf data\-Cell} =  0, 
\par
{\bf ctrl\-Cell} =  1
 \}
\begin{CompactList}\small\item\em Enumeration of cell types: control or data. \item\end{CompactList}\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
int \hyperlink{latp_8h_a17}{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_8h_a18}{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_8h_a19}{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_8h_a20}{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_8h_a21}{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_8h_a22}{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_8h_a23}{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_8h_a24}{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_8h_a25}{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_8h_a26}{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_8h_a27}{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_8h_a28}{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_8h_a29}{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_8h_a30}{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_8h_a31}{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_8h_a32}{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_8h_a33}{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_8h_a34}{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_8h_a35}{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_8h_a36}{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_8h_a37}{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_8h_a38}{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}\item 
int \hyperlink{latp_8h_a39}{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}\end{CompactItemize}


\subsection{Detailed Description}
Defines public structs and methods of the LATp protocol. 

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


\subsection{Define Documentation}
\hypertarget{latp_8h_a5}{
\index{latp.h@{latp.h}!BITCOUNT@{BITCOUNT}}
\index{BITCOUNT@{BITCOUNT}!latp.h@{latp.h}}
\subsubsection[BITCOUNT]{\setlength{\rightskip}{0pt plus 5cm}\#define BITCOUNT(x)\ (((BX\_\-(x)+(BX\_\-(x)$>$$>$4)) \& 0x0F0F0F0F) \% 255)}}
\label{latp_8h_a5}


Computes the number of bits set (1) in 32-but argument. 

\begin{Desc}
\item[See also:]\hyperlink{latp_8h_a6}{BX\_\-}\end{Desc}
Macros to compute a bit value from a bit number, bit number from bit value, and the bit count (number of bits on) for 32-bit quantities. The results are compile-time constants if the arguments are.

The definition of BITCOUNT is based on an algorithm condensed from one extracted from a graph coloring register allocator which manipulates bitvectors. It was inspired by an analogous algorithm for counting bits in 36 bit words in MIT's HAKMEM, designed by Chris Smith, and written by Jane Hoffman. The original conversion to a form suitable for C on a VAX was by Brad Merrill; that code was fixed and re-written by Jerry Leichter. It assumes a 32-bit word. Note that the argument is evaluated multiple times, so should not have side-effects. A full explanation of the algorithm is too long to include here; in summary, \hyperlink{latp_8h_a6}{BX\_\-(x)} replaces each 4-bit sequence in x by the number of bits in that sequence (which will, of course, fit in 4 bits). BITCOUNT folds the 4-bit sequences into 8-bit sequences. The 8-bit sequences are then added up by recognizing that they can be viewed as a base 256 number, and the sum of the digits of a base b number is the same mod b-1 as the number mod b-1.

The original implementation produce results in groups of 3, then 6 bits. While natural on a PDP-10's 36-bit word, this requires special case handling of the sign bit on a VAX, since the top 3-bit sequence is really only 2 bits long. \hypertarget{latp_8h_a6}{
\index{latp.h@{latp.h}!BX_@{BX\_\-}}
\index{BX_@{BX\_\-}!latp.h@{latp.h}}
\subsubsection[BX\_\-]{\setlength{\rightskip}{0pt plus 5cm}\#define BX\_\-(x)}}
\label{latp_8h_a6}


{\bf Value:}

\footnotesize\begin{verbatim}((x) - (((x)>>1)&0x77777777)                    \
                             - (((x)>>2)&0x33333333)                    \
                             - (((x)>>3)&0x11111111))
\end{verbatim}\normalsize 
Replaces each 4-bit sequence in arg by the number of bits in sequence. 

\begin{Desc}
\item[See also:]\hyperlink{latp_8h_a5}{BITCOUNT}\end{Desc}
Replaces each 4-bit sequence in 32-bit argument by the number of bits in that sequence (which will, of course, fit in 4 bits). 

\subsection{Function Documentation}
\hypertarget{latp_8h_a39}{
\index{latp.h@{latp.h}!calcParity@{calcParity}}
\index{calcParity@{calcParity}!latp.h@{latp.h}}
\subsubsection[calcParity]{\setlength{\rightskip}{0pt plus 5cm}int calc\-Parity (unsigned int {\em n\-Words}, unsigned int $\ast$ {\em arr})}}
\label{latp_8h_a39}


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_8h_a37}{
\index{latp.h@{latp.h}!getLATpCellBodyParity@{getLATpCellBodyParity}}
\index{getLATpCellBodyParity@{getLATpCellBodyParity}!latp.h@{latp.h}}
\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_8h_a37}


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_8h_a35}{
\index{latp.h@{latp.h}!getLATpCellHeaderParity@{getLATpCellHeaderParity}}
\index{getLATpCellHeaderParity@{getLATpCellHeaderParity}!latp.h@{latp.h}}
\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_8h_a35}


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_8h_a21}{
\index{latp.h@{latp.h}!gGetAddr@{gGetAddr}}
\index{gGetAddr@{gGetAddr}!latp.h@{latp.h}}
\subsubsection[gGetAddr]{\setlength{\rightskip}{0pt plus 5cm}int g\-Get\-Addr (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short $\ast$ {\em addr})}}
\label{latp_8h_a21}


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_8h_a30}{
\index{latp.h@{latp.h}!gGetProtocol@{gGetProtocol}}
\index{gGetProtocol@{gGetProtocol}!latp.h@{latp.h}}
\subsubsection[gGetProtocol]{\setlength{\rightskip}{0pt plus 5cm}int g\-Get\-Protocol (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short $\ast$ {\em proto})}}
\label{latp_8h_a30}


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_8h_a25}{
\index{latp.h@{latp.h}!gGetRXstats@{gGetRXstats}}
\index{gGetRXstats@{gGetRXstats}!latp.h@{latp.h}}
\subsubsection[gGetRXstats]{\setlength{\rightskip}{0pt plus 5cm}int g\-Get\-RXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__RXstats}{LATp\_\-RXstats} $\ast$ {\em rx\-Stats})}}
\label{latp_8h_a25}


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_8h_a23}{
\index{latp.h@{latp.h}!gGetTXstats@{gGetTXstats}}
\index{gGetTXstats@{gGetTXstats}!latp.h@{latp.h}}
\subsubsection[gGetTXstats]{\setlength{\rightskip}{0pt plus 5cm}int g\-Get\-TXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__TXstats}{LATp\_\-TXstats} $\ast$ {\em tx\-Stats})}}
\label{latp_8h_a23}


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_8h_a18}{
\index{latp.h@{latp.h}!gLoadPacket@{gLoadPacket}}
\index{gLoadPacket@{gLoadPacket}!latp.h@{latp.h}}
\subsubsection[gLoadPacket]{\setlength{\rightskip}{0pt plus 5cm}int 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_8h_a18}


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_8h_a32}{
\index{latp.h@{latp.h}!gReadRsp@{gReadRsp}}
\index{gReadRsp@{gReadRsp}!latp.h@{latp.h}}
\subsubsection[gReadRsp]{\setlength{\rightskip}{0pt plus 5cm}int g\-Read\-Rsp (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{struct__gResponse}{g\-Response} $\ast$ {\em rsp\-Info})}}
\label{latp_8h_a32}


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_8h_a22}{
\index{latp.h@{latp.h}!gResetCommStats@{gResetCommStats}}
\index{gResetCommStats@{gResetCommStats}!latp.h@{latp.h}}
\subsubsection[gResetCommStats]{\setlength{\rightskip}{0pt plus 5cm}int g\-Reset\-Comm\-Stats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh})}}
\label{latp_8h_a22}


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_8h_a19}{
\index{latp.h@{latp.h}!gSendLAM@{gSendLAM}}
\index{gSendLAM@{gSendLAM}!latp.h@{latp.h}}
\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_8h_a19}


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_8h_a17}{
\index{latp.h@{latp.h}!gSendPacket@{gSendPacket}}
\index{gSendPacket@{gSendPacket}!latp.h@{latp.h}}
\subsubsection[gSendPacket]{\setlength{\rightskip}{0pt plus 5cm}int 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_8h_a17}


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_8h_a20}{
\index{latp.h@{latp.h}!gSetAddr@{gSetAddr}}
\index{gSetAddr@{gSetAddr}!latp.h@{latp.h}}
\subsubsection[gSetAddr]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-Addr (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em addr})}}
\label{latp_8h_a20}


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_8h_a27}{
\index{latp.h@{latp.h}!gSetLATpChnl@{gSetLATpChnl}}
\index{gSetLATpChnl@{gSetLATpChnl}!latp.h@{latp.h}}
\subsubsection[gSetLATpChnl]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-LATp\-Chnl (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned char {\em chnl})}}
\label{latp_8h_a27}


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_8h_a28}{
\index{latp.h@{latp.h}!gSetLATpMode@{gSetLATpMode}}
\index{gSetLATpMode@{gSetLATpMode}!latp.h@{latp.h}}
\subsubsection[gSetLATpMode]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-LATp\-Mode (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned char {\em mode})}}
\label{latp_8h_a28}


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_8h_a29}{
\index{latp.h@{latp.h}!gSetProtocol@{gSetProtocol}}
\index{gSetProtocol@{gSetProtocol}!latp.h@{latp.h}}
\subsubsection[gSetProtocol]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-Protocol (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em proto})}}
\label{latp_8h_a29}


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_8h_a26}{
\index{latp.h@{latp.h}!gSetRXstats@{gSetRXstats}}
\index{gSetRXstats@{gSetRXstats}!latp.h@{latp.h}}
\subsubsection[gSetRXstats]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-RXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__RXstats}{LATp\_\-RXstats} $\ast$ {\em rx\-Stats})}}
\label{latp_8h_a26}


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_8h_a31}{
\index{latp.h@{latp.h}!gSetTimeout@{gSetTimeout}}
\index{gSetTimeout@{gSetTimeout}!latp.h@{latp.h}}
\subsubsection[gSetTimeout]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-Timeout (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, unsigned short {\em timeout})}}
\label{latp_8h_a31}


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_8h_a24}{
\index{latp.h@{latp.h}!gSetTXstats@{gSetTXstats}}
\index{gSetTXstats@{gSetTXstats}!latp.h@{latp.h}}
\subsubsection[gSetTXstats]{\setlength{\rightskip}{0pt plus 5cm}int g\-Set\-TXstats (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh}, \hyperlink{union__LATp__TXstats}{LATp\_\-TXstats} $\ast$ {\em tx\-Stats})}}
\label{latp_8h_a24}


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_8h_a33}{
\index{latp.h@{latp.h}!gWaitPacketIRQ@{gWaitPacketIRQ}}
\index{gWaitPacketIRQ@{gWaitPacketIRQ}!latp.h@{latp.h}}
\subsubsection[gWaitPacketIRQ]{\setlength{\rightskip}{0pt plus 5cm}int g\-Wait\-Packet\-IRQ (\hyperlink{struct__gnat}{gnat\-Handle} {\em gh})}}
\label{latp_8h_a33}


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_8h_a36}{
\index{latp.h@{latp.h}!setLATpCellBodyParity@{setLATpCellBodyParity}}
\index{setLATpCellBodyParity@{setLATpCellBodyParity}!latp.h@{latp.h}}
\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_8h_a36}


{\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_8h_a34}{
\index{latp.h@{latp.h}!setLATpCellHeaderParity@{setLATpCellHeaderParity}}
\index{setLATpCellHeaderParity@{setLATpCellHeaderParity}!latp.h@{latp.h}}
\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_8h_a34}


{\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_8h_a38}{
\index{latp.h@{latp.h}!setLATpSkipRspWords@{setLATpSkipRspWords}}
\index{setLATpSkipRspWords@{setLATpSkipRspWords}!latp.h@{latp.h}}
\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_8h_a38}


{\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. 