\hypertarget{gAENV_8c}{
\section{g\-AENV.c File Reference}
\label{gAENV_8c}\index{gAENV.c@{gAENV.c}}
}
Implements command/response for the AEM's \char`\"{}Environmental Monitor\char`\"{}.  


{\tt \#include \char`\"{}ga\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}g\-AEM\_\-p.h\char`\"{}}\par
{\tt \#include \char`\"{}GAEM/g\-AENV.h\char`\"{}}\par
{\tt \#include $<$string.h$>$}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
void \hyperlink{gAENV_8c_a0}{pack\-Payload\-AENV} (\hyperlink{struct__gaem}{gaem\-Handle} ga, unsigned int cmd\-Header, unsigned int local\-AD, unsigned long long value, unsigned int $\ast$payload)
\begin{CompactList}\small\item\em Packs the cmd\-Header, local\-LATp\-AD and value into the 96-bit payload. \item\end{CompactList}\item 
int \hyperlink{gAENV_8c_a1}{\_\-\_\-aenv\-Cmd\-Load} (\hyperlink{struct__gaem}{gaem\-Handle} ga, unsigned short func, unsigned short reg, unsigned long long value)
\begin{CompactList}\small\item\em Generic routine for sending response-less commands. \item\end{CompactList}\item 
int \hyperlink{gAENV_8c_a2}{g\-AENVload} (\hyperlink{struct__gaem}{gaem\-Handle} ga, unsigned short reg, unsigned long long value)
\begin{CompactList}\small\item\em Loads a register with value. \item\end{CompactList}\item 
int \hyperlink{gAENV_8c_a3}{g\-AENVread} (\hyperlink{struct__gaem}{gaem\-Handle} ga, unsigned short reg, unsigned long long $\ast$value)
\begin{CompactList}\small\item\em Reads a register specified by {\em reg\/} and stores result in {\em value\/}. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Implements command/response for the AEM's \char`\"{}Environmental Monitor\char`\"{}. 

\begin{Desc}
\item[Author:]Curt Brune -- \href{mailto:curt@slac.stanford.edu}{\tt curt@slac.stanford.edu} \end{Desc}
Currently only the Virtual AEM is supported. The fidelity of the emulation is quite low.

Command Fidelity ======= =============================== dataless Succeed, but no effect on electronics

register writes Succeed, but no effect on electronics

register reads Succeed, but always return 0 -- timeout for non-existent registers.

Note: All the registers are 64-bits wide.

\subsection{Function Documentation}
\hypertarget{gAENV_8c_a1}{
\index{gAENV.c@{g\-AENV.c}!__aenvCmdLoad@{\_\-\_\-aenvCmdLoad}}
\index{__aenvCmdLoad@{\_\-\_\-aenvCmdLoad}!gAENV.c@{g\-AENV.c}}
\subsubsection[\_\-\_\-aenvCmdLoad]{\setlength{\rightskip}{0pt plus 5cm}int \_\-\_\-aenv\-Cmd\-Load (\hyperlink{struct__gaem}{gaem\-Handle} {\em ga}, unsigned short {\em func}, unsigned short {\em reg}, unsigned long long {\em value})}}
\label{gAENV_8c_a1}


Generic routine for sending response-less commands. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ga}]gaem\-Handle for AEM \item[{\em func}]command/response function code \item[{\em reg}]register of AEM to load \item[{\em value}]32-bit value to load into AEM register \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
Common subroutine for sending dataless commands and loading AENV on board registers registers. The {\em func\/} parameter indicates a \char`\"{}dataless\char`\"{} or \char`\"{}load\char`\"{} command.

For dataless commands {\em reg\/} is interpreted as the \char`\"{}opcode\char`\"{} of the dataless command and {\em value\/} is ignored.

For load commands {\em reg\/} is the AENV register to load with {\em value\/}. \hypertarget{gAENV_8c_a2}{
\index{gAENV.c@{g\-AENV.c}!gAENVload@{gAENVload}}
\index{gAENVload@{gAENVload}!gAENV.c@{g\-AENV.c}}
\subsubsection[gAENVload]{\setlength{\rightskip}{0pt plus 5cm}int g\-AENVload (\hyperlink{struct__gaem}{gaem\-Handle} {\em ga}, unsigned short {\em reg}, unsigned long long {\em value})}}
\label{gAENV_8c_a2}


Loads a register with value. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ga}]gaem\-Handle for AEM \item[{\em reg}]register of AEM to load \item[{\em value}]64-bit value to load into AENV register \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
The value written to AENV registers is ignored, but the act of writing initiates the ADC acquisition cycle.

In the VAEM no action is taken. \hypertarget{gAENV_8c_a3}{
\index{gAENV.c@{g\-AENV.c}!gAENVread@{gAENVread}}
\index{gAENVread@{gAENVread}!gAENV.c@{g\-AENV.c}}
\subsubsection[gAENVread]{\setlength{\rightskip}{0pt plus 5cm}int g\-AENVread (\hyperlink{struct__gaem}{gaem\-Handle} {\em ga}, unsigned short {\em reg}, unsigned long long $\ast$ {\em value})}}
\label{gAENV_8c_a3}


Reads a register specified by {\em reg\/} and stores result in {\em value\/}. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ga}]gaem\-Handle for AEM \item[{\em reg}]register of AEM to load \item[{\em value}]pointer to 64-bit value to store register read result \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]G\_\-OK on success\end{Desc}
Returns the 4 ADC values associated with {\em reg\/} in the AEM Environmental Monitor.

In the VAEM this function always returns a value of 0. \hypertarget{gAENV_8c_a0}{
\index{gAENV.c@{g\-AENV.c}!packPayloadAENV@{packPayloadAENV}}
\index{packPayloadAENV@{packPayloadAENV}!gAENV.c@{g\-AENV.c}}
\subsubsection[packPayloadAENV]{\setlength{\rightskip}{0pt plus 5cm}void pack\-Payload\-AENV (\hyperlink{struct__gaem}{gaem\-Handle} {\em ga}, unsigned int {\em cmd\-Header}, unsigned int {\em local\-AD}, unsigned long long {\em value}, unsigned int $\ast$ {\em payload})}}
\label{gAENV_8c_a0}


Packs the cmd\-Header, local\-LATp\-AD and value into the 96-bit payload. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em ga}]gaem\-Handle for AEM \item[{\em cmd\-Header}]32-bit command header word \item[{\em local\-AD}]32-bit local access descriptor word \item[{\em value}]64-bit value to load into AENV register \item[{\em payload}]pointer to 96-bits of pre-allocated storage \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]void\end{Desc}
Packs the bits of {\em cmd\-Header\/}, {\em local\-AD\/} and {\em value\/} into the 96-bits pointed to by {\em payload\/}. The packing is specific to local \char`\"{}on board\char`\"{} registers for the AEM Environmental Monitor. 