\hypertarget{THS_8h}{
\section{THS.h File Reference}
\label{THS_8h}\index{THS.h@{THS.h}}
}
Public defs for Time Hack Services. 

{\tt \#include \char`\"{}LSF/LSF\_\-stats\-Hdr.h\char`\"{}}\par


Include dependency graph for THS.h:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=119pt]{THS_8h__incl}
\end{center}
\end{figure}


This graph shows which files directly or indirectly include this file:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=159pt]{THS_8h__dep__incl}
\end{center}
\end{figure}
\subsection*{Data Structures}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__THS__GemTableFlagsBf}{\_\-THS\_\-Gem\-Table\-Flags\-Bf}
\begin{CompactList}\small\item\em Structure to map out the bit fields time hack flags stored as 32 bits in gem\-Table. \item\end{CompactList}\item 
struct \hyperlink{union__THS__GemTableFlags}{\_\-THS\_\-Gem\-Table\-Flags}
\begin{CompactList}\small\item\em Union for different access of 32 bit flags in gem\-Table. \item\end{CompactList}\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{THS_8h_a0}{
typedef enum \hyperlink{THS_8h_a32}{\_\-THS\_\-OPTION} \hyperlink{THS_8h_a0}{THS\_\-OPTION}}
\label{THS_8h_a0}

\begin{CompactList}\small\item\em Masks for option mask into THS\_\-init. \item\end{CompactList}\item 
\hypertarget{THS_8h_a1}{
typedef enum \hyperlink{THS_8h_a33}{\_\-THS\_\-FSW\_\-FLAGS} \hyperlink{THS_8h_a1}{THS\_\-THS\_\-FSW\_\-FLAGS}}
\label{THS_8h_a1}

\begin{CompactList}\small\item\em Masks for FSW flags in gem table. \item\end{CompactList}\item 
\hypertarget{THS_8h_a2}{
typedef \hyperlink{struct__THS__GemTableFlagsBf}{\_\-THS\_\-Gem\-Table\-Flags\-Bf} \hyperlink{THS_8h_a2}{THS\_\-Gem\-Table\-Flags\-Bf}}
\label{THS_8h_a2}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{struct__THS__GemTableFlagsBf}{\_\-THS\_\-Gem\-Table\-Flags\-Bf}. \item\end{CompactList}\item 
\hypertarget{THS_8h_a3}{
typedef \hyperlink{union__THS__GemTableFlags}{\_\-THS\_\-Gem\-Table\-Flags} \hyperlink{THS_8h_a3}{THS\_\-Gem\-Table\-Flags}}
\label{THS_8h_a3}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{union__THS__GemTableFlags}{\_\-THS\_\-Gem\-Table\-Flags}. \item\end{CompactList}\item 
typedef unsigned int( \hyperlink{THS_8h_a4}{THS\_\-Send\-Slave\-Rtn} )(void $\ast$lsm\-Arg, short lsm\-ID, short ths\-Id, int nid, void $\ast$payload, int payload\-Len, void $\ast$payload\-Free\-Rtn, void $\ast$payload\-Free\-Rtn\-Arg)
\begin{CompactList}\small\item\em stash away routine (from LCM) to send msg to EPU \item\end{CompactList}\end{CompactItemize}
\subsection*{Enumerations}
\begin{CompactItemize}
\item 
enum \hyperlink{THS_8h_a32}{\_\-THS\_\-OPTION} \{ \par
\hyperlink{THS_8h_a32a5}{THS\_\-GEM\_\-HACK} =  1, 
\par
\hyperlink{THS_8h_a32a6}{THS\_\-CPU\_\-HACK} =  2, 
\par
\hyperlink{THS_8h_a32a7}{THS\_\-SIU\_\-HACK} =  4
 \}
\item 
enum \hyperlink{THS_8h_a33}{\_\-THS\_\-FSW\_\-FLAGS} \{ \par
\hyperlink{THS_8h_a33a8}{THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM} =  1, 
\par
\hyperlink{THS_8h_a33a9}{THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM} =  2, 
\par
\hyperlink{THS_8h_a33a10}{THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM} =  4, 
\par
\hyperlink{THS_8h_a33a11}{THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE} =  8
 \}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
unsigned int \hyperlink{THS_8h_a12}{THS\_\-init} (int option\-Mask)
\begin{CompactList}\small\item\em Inits the Time\-Hack\-Service module. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a13}{THS\_\-simulated\-PPS} (void)
\begin{CompactList}\small\item\em Return the state of the pulse-per-second simulation. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a14}{THS\_\-simulated\-TT} (void)
\begin{CompactList}\small\item\em Return the state of the timetone simulation. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a15}{THS\_\-wait} ()
\begin{CompactList}\small\item\em Wait for Time\-Hack\-Service module to be fully operational. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a16}{THS\_\-timetone} (unsigned int abs\-Time\-Sec, unsigned short sa\-Flags)
\begin{CompactList}\small\item\em Provide abs\-Time for next entry in table (on next PPS). \item\end{CompactList}\item 
WCT\_\-time \hyperlink{THS_8h_a17}{THS\_\-gem\-Abs\-Time\-Event} (int gem\-Strobe\-In, int gem\-Clk)
\begin{CompactList}\small\item\em Calculate absolute time for event from strobe and clk provided with event (20MHz clk). \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a18}{THS\_\-timetone\-From\-Event} (int gem\-Strobe\-In, int $\ast$abs\-Time\-Secs, int $\ast$flag)
\begin{CompactList}\small\item\em get timetone/flags from table for this event \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a19}{THS\_\-prev\-Timetone\-From\-Event} (int gem\-Strobe\-In, int $\ast$abs\-Time\-Secs, int $\ast$flags, int $\ast$abs\-Time\-Secs\-Prev, int $\ast$flags\-Prev, int $\ast$gem\-Strobe\-In\-Prev)
\begin{CompactList}\small\item\em get timetone/flags from table for this event and for prev entry in table \item\end{CompactList}\item 
\hypertarget{THS_8h_a20}{
unsigned int \hyperlink{THS_8h_a20}{THS\_\-prev\-Timtone\-From\-Event} (int gem\-Strobe\-In, int $\ast$abs\-Time\-Secs, int $\ast$flags, int $\ast$abs\-Time\-Secs\-Prev, int $\ast$flags\-Prev, int $\ast$gem\-Strobe\-In\-Prev)}
\label{THS_8h_a20}

\begin{CompactList}\small\item\em THIS IS MIS-SPELLING, it just calls THS\_\-prev\-Timetone\-From\-Event. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a21}{THS\_\-cpu\-Set\-Warning} (unsigned int expected\-Clk\-Hz, unsigned int expected\-Delta\-Clk\-Hz)
\begin{CompactList}\small\item\em Set range for cpu clock warning messages. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a22}{THS\_\-gem\-Set\-Warning} (unsigned int expected\-Clk\-Hz, unsigned int expected\-Delta\-Clk\-Hz)
\begin{CompactList}\small\item\em Set range for gem clock warning messages. \item\end{CompactList}\item 
void \hyperlink{THS_8h_a23}{THS\_\-set\-Pps\-Warn\-Every} (unsigned int warn\-Pps\-Every)
\begin{CompactList}\small\item\em Set how often get warning when no PPS. \item\end{CompactList}\item 
void \hyperlink{THS_8h_a24}{THS\_\-set\-Timetone\-Warn\-Every} (unsigned int \_\-warn\-Timetone\-Every)
\begin{CompactList}\small\item\em Set how often get warning when no timetone. \item\end{CompactList}\item 
void \hyperlink{THS_8h_a25}{THS\_\-set\-Slave\-Send} (\hyperlink{THS_8h_a4}{THS\_\-Send\-Slave\-Rtn} rtn, void $\ast$arg, int lsm\-Id)
\begin{CompactList}\small\item\em stash away routine (from LCM) to send msg to EPU \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a26}{THS\_\-slave\-Process\-Msg} (int func, void $\ast$payload, unsigned int len)
\begin{CompactList}\small\item\em routine called from ITC dispatch in LSM to process each message it receives (this routine is run on EPU when it receives message) \item\end{CompactList}\item 
void \hyperlink{THS_8h_a27}{THS\_\-set\-Gem\-Update\-Msgs} (int max\-Msgs)
\begin{CompactList}\small\item\em set size of memory pool for gem\-Update msgs, must be called before THS\_\-init \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a28}{THS\_\-lsf\-Stat\-First\-Evt} (LSF\_\-stats\-Hdr $\ast$stats\-Hdr, unsigned long long seq, unsigned int gem\-Clock, unsigned int gem\-Strobe)
\begin{CompactList}\small\item\em Sets first event parms within LSF\_\-stats\-Hdr. \item\end{CompactList}\item 
void \hyperlink{THS_8h_a29}{THS\_\-lsf\-Stat\-Inc\-Evt} (LSF\_\-stats\-Hdr $\ast$stats\-Hdr, int increment)
\begin{CompactList}\small\item\em Increment event counter in LSF\_\-stats\-Hdr structure. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a30}{THS\_\-lsf\-Stat\-Last\-Evt} (LSF\_\-stats\-Hdr $\ast$stats\-Hdr, unsigned long long seq, unsigned int gem\-Clock, unsigned int gem\-Strobe)
\begin{CompactList}\small\item\em Sets last event parms within LSF\_\-stats\-Hdr. \item\end{CompactList}\item 
void \hyperlink{THS_8h_a31}{THS\_\-lsf\-Stat\-Clear} (LSF\_\-stats\-Hdr $\ast$stats\-Hdr)
\begin{CompactList}\small\item\em Clear the LSF\_\-stats\-Hdr structure. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}
Public defs for Time Hack Services. 

\begin{Desc}
\item[Author:]Ed Bacho -- \href{mailto:ebacho@slac.stanford.edu}{\tt ebacho@slac.stanford.edu}\end{Desc}
This module handles calculation of absolute time using the \char`\"{}time hack\char`\"{}. The absolute (or true) time is provided once a second through a combination of a 1PPS (1 pulse per sec) hardware pulse and a time tone message (\char`\"{}at the tone the time will be\char`\"{}) that preceeds it. The time provided in the time tone message from the scapecraft is in micro\-Sec since 1/1/2001.

This file has routines for adjusting the time on the CPU clock by using the WCT\_\-set/get routines, therefore one can only get the current time thru WCT\_\-get(). THese are based on a sub-multiple of the CPU's 33 MHz PCI clock.

The determination of the absolute time from event and LCB times is handled in other time hack files.

This module only truely works on the Rad750 which has the PPS input thru the PID registers. The mv2304 version starts up a task to simulate the PPS but it should therefore show no drift (since its locked with the clock)

Inputs:\begin{itemize}
\item time tone message every sec (500-800 m\-Sec before pulse) giving next abs\-Time\item HW 1PPS pulse every sec from GASU (although originates from spacecraft)\end{itemize}


Output:\begin{itemize}
\item can obtain corrected absolute time thru WCT\_\-get()\end{itemize}


\subsection{Typedef Documentation}
\hypertarget{THS_8h_a4}{
\index{THS.h@{THS.h}!THS_SendSlaveRtn@{THS\_\-SendSlaveRtn}}
\index{THS_SendSlaveRtn@{THS\_\-SendSlaveRtn}!THS.h@{THS.h}}
\subsubsection[THS\_\-SendSlaveRtn]{\setlength{\rightskip}{0pt plus 5cm}void($\ast$ \hyperlink{THS_8h_a4}{THS\_\-Send\-Slave\-Rtn})(void $\ast$arg, void $\ast$payload, int payload\-Len)}}
\label{THS_8h_a4}


stash away routine (from LCM) to send msg to EPU 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em arg}]- given arg to be included with call \item[{\em payload}]- buffer with message to send \item[{\em payload\-Len}]- length of buffer \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
This is routine used by THS to send messages between SIU and EPU. It must be passed down from module above that knows how to do this (most likly LSM using ITC calls)

\subsection{Enumeration Type Documentation}
\hypertarget{THS_8h_a33}{
\index{THS.h@{THS.h}!_THS_FSW_FLAGS@{\_\-THS\_\-FSW\_\-FLAGS}}
\index{_THS_FSW_FLAGS@{\_\-THS\_\-FSW\_\-FLAGS}!THS.h@{THS.h}}
\subsubsection[\_\-THS\_\-FSW\_\-FLAGS]{\setlength{\rightskip}{0pt plus 5cm}enum \hyperlink{THS_8h_a33}{\_\-THS\_\-FSW\_\-FLAGS}}}
\label{THS_8h_a33}


\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{THS_FSW_FLAG_TT_SIM@{THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_FSW_FLAG_TT_SIM@{THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM}}\item[{\em 
\hypertarget{THS_8h_a33a8}{
THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM}
\label{THS_8h_a33a8}
}]Timtone value is simulated \index{THS_FSW_FLAG_CPU_PPS_SIM@{THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_FSW_FLAG_CPU_PPS_SIM@{THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM}}\item[{\em 
\hypertarget{THS_8h_a33a9}{
THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM}
\label{THS_8h_a33a9}
}]no PPS interrupt, PPS simulated, might not be accurate \index{THS_FSW_FLAG_GEM_PPS_SIM@{THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_FSW_FLAG_GEM_PPS_SIM@{THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM}}\item[{\em 
\hypertarget{THS_8h_a33a10}{
THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM}
\label{THS_8h_a33a10}
}]GEM did not get PPS, need to calc new GEM stobe val \index{THS_FSW_FLAG_NO_HACK_TABLE@{THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_FSW_FLAG_NO_HACK_TABLE@{THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE}}\item[{\em 
\hypertarget{THS_8h_a33a11}{
THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE}
\label{THS_8h_a33a11}
}]These values did not come from Hack\-Table \end{description}
\end{Desc}

\hypertarget{THS_8h_a32}{
\index{THS.h@{THS.h}!_THS_OPTION@{\_\-THS\_\-OPTION}}
\index{_THS_OPTION@{\_\-THS\_\-OPTION}!THS.h@{THS.h}}
\subsubsection[\_\-THS\_\-OPTION]{\setlength{\rightskip}{0pt plus 5cm}enum \hyperlink{THS_8h_a32}{\_\-THS\_\-OPTION}}}
\label{THS_8h_a32}


\begin{Desc}
\item[Enumerator: ]\par
\begin{description}
\index{THS_GEM_HACK@{THS\_\-GEM\_\-HACK}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_GEM_HACK@{THS\_\-GEM\_\-HACK}}\item[{\em 
\hypertarget{THS_8h_a32a5}{
THS\_\-GEM\_\-HACK}
\label{THS_8h_a32a5}
}]enable time hack for gem clock (20 MHz) \index{THS_CPU_HACK@{THS\_\-CPU\_\-HACK}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_CPU_HACK@{THS\_\-CPU\_\-HACK}}\item[{\em 
\hypertarget{THS_8h_a32a6}{
THS\_\-CPU\_\-HACK}
\label{THS_8h_a32a6}
}]enable time hack for cpu clock (33/4 MHz) \index{THS_SIU_HACK@{THS\_\-SIU\_\-HACK}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_SIU_HACK@{THS\_\-SIU\_\-HACK}}\item[{\em 
\hypertarget{THS_8h_a32a7}{
THS\_\-SIU\_\-HACK}
\label{THS_8h_a32a7}
}]this cpu is the SIU \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{THS_8h_a21}{
\index{THS.h@{THS.h}!THS_cpuSetWarning@{THS\_\-cpuSetWarning}}
\index{THS_cpuSetWarning@{THS\_\-cpuSetWarning}!THS.h@{THS.h}}
\subsubsection[THS\_\-cpuSetWarning]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-cpu\-Set\-Warning (unsigned int {\em expected\-Clk\-Hz}, unsigned int {\em expected\-Delta\-Clk\-Hz})}}
\label{THS_8h_a21}


Set range for cpu clock warning messages. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em expected\-Clk\-Hz}]- expected clock in Hz, $<$=0 uses default, (16.6MHz on mv2304, 8.3MHz on Rad750) \item[{\em expected\-Delta\-Clk\-Hz}]- expected delta clk in Hz, $<$0 uses default of 2\% of clock \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
\hypertarget{THS_8h_a17}{
\index{THS.h@{THS.h}!THS_gemAbsTimeEvent@{THS\_\-gemAbsTimeEvent}}
\index{THS_gemAbsTimeEvent@{THS\_\-gemAbsTimeEvent}!THS.h@{THS.h}}
\subsubsection[THS\_\-gemAbsTimeEvent]{\setlength{\rightskip}{0pt plus 5cm}WCT\_\-time THS\_\-gem\-Abs\-Time\-Event (int {\em gem\-Strobe\-In}, int {\em gem\-Clk})}}
\label{THS_8h_a17}


Calculate absolute time for event from strobe and clk provided with event (20MHz clk). 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gem\-Strobe\-In}]stobe counter from GEM from event data \item[{\em gem\-Clk}]clk counter from GEM from event data \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]64b value of number of nano\-Sec since 1/1/2001\end{Desc}
This routine takes the stobe and clk values from the GEM (part of event data) and converts it to an absolute time. Since this value is calulated through a table saved for the last N secs, it is only valid for the last N secs else will error and retun 0.\hypertarget{THS_8h_a22}{
\index{THS.h@{THS.h}!THS_gemSetWarning@{THS\_\-gemSetWarning}}
\index{THS_gemSetWarning@{THS\_\-gemSetWarning}!THS.h@{THS.h}}
\subsubsection[THS\_\-gemSetWarning]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-gem\-Set\-Warning (unsigned int {\em expected\-Clk\-Hz}, unsigned int {\em expected\-Delta\-Clk\-Hz})}}
\label{THS_8h_a22}


Set range for gem clock warning messages. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em expected\-Clk\-Hz}]- expected clock in Hz, $<$=0 uses default of 20MHz \item[{\em expected\-Delta\-Clk\-Hz}]- expected delta clk in Hz, $<$0 uses default of 1\% of clock \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
\hypertarget{THS_8h_a12}{
\index{THS.h@{THS.h}!THS_init@{THS\_\-init}}
\index{THS_init@{THS\_\-init}!THS.h@{THS.h}}
\subsubsection[THS\_\-init]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-init (int {\em mask})}}
\label{THS_8h_a12}


Inits the Time\-Hack\-Service module. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mask}]time hack options, 1=CPU time hack, 2=Gem Time Hack, 4=Cpu\-Is\-Siu \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
This routine does basic init for THS and requires a few modules to be init (PBS,MSG, ??). It setup the Pid TImers for the PPS interrupt and prepares to handle timeones. Howver, it takes several seconds for time hack to be operational and THS\_\-start() can be used to determine if it is operational.\hypertarget{THS_8h_a31}{
\index{THS.h@{THS.h}!THS_lsfStatClear@{THS\_\-lsfStatClear}}
\index{THS_lsfStatClear@{THS\_\-lsfStatClear}!THS.h@{THS.h}}
\subsubsection[THS\_\-lsfStatClear]{\setlength{\rightskip}{0pt plus 5cm}void THS\_\-lsf\-Stat\-Clear (LSF\_\-stats\-Hdr $\ast$ {\em stats\-Hdr})}}
\label{THS_8h_a31}


Clear the LSF\_\-stats\-Hdr structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stats\-Hdr}]pointer to LSF\_\-stats\-Hdr structure to fill in \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]nothing\end{Desc}
\hypertarget{THS_8h_a28}{
\index{THS.h@{THS.h}!THS_lsfStatFirstEvt@{THS\_\-lsfStatFirstEvt}}
\index{THS_lsfStatFirstEvt@{THS\_\-lsfStatFirstEvt}!THS.h@{THS.h}}
\subsubsection[THS\_\-lsfStatFirstEvt]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-lsf\-Stat\-First\-Evt (LSF\_\-stats\-Hdr $\ast$ {\em stats\-Hdr}, unsigned long long {\em seq}, unsigned int {\em gem\-Clock}, unsigned int {\em gem\-Strobe})}}
\label{THS_8h_a28}


Sets first event parms within LSF\_\-stats\-Hdr. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stats\-Hdr}]pointer to LSF\_\-stats\-Hdr structure to fill in \item[{\em seq}]extended seqence number of the event \item[{\em gem\-Clock}]evt clock register read from GEM contributor of event \item[{\em gem\-Strobe}]evt PPS cock register read from GEM contributor of event \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
This is convenient routine to fill in event info that is stored in a LSF\_\-stats\-Hdr structure within an LSF packet for eventual output as science data on the SSR.\hypertarget{THS_8h_a29}{
\index{THS.h@{THS.h}!THS_lsfStatIncEvt@{THS\_\-lsfStatIncEvt}}
\index{THS_lsfStatIncEvt@{THS\_\-lsfStatIncEvt}!THS.h@{THS.h}}
\subsubsection[THS\_\-lsfStatIncEvt]{\setlength{\rightskip}{0pt plus 5cm}void THS\_\-lsf\-Stat\-Inc\-Evt (LSF\_\-stats\-Hdr $\ast$ {\em stats\-Hdr}, int {\em increment})}}
\label{THS_8h_a29}


Increment event counter in LSF\_\-stats\-Hdr structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stats\-Hdr}]pointer to LSF\_\-stats\-Hdr structure to fill in \item[{\em increment}]number of events to increase evt count by \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]nothing\end{Desc}
This is convenient routine to increment the event counter within LSF\_\-stats\-Hdr structure. Note that this in the number of events seen by the callback, the raw events rather than the number of prescaled events.\hypertarget{THS_8h_a30}{
\index{THS.h@{THS.h}!THS_lsfStatLastEvt@{THS\_\-lsfStatLastEvt}}
\index{THS_lsfStatLastEvt@{THS\_\-lsfStatLastEvt}!THS.h@{THS.h}}
\subsubsection[THS\_\-lsfStatLastEvt]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-lsf\-Stat\-Last\-Evt (LSF\_\-stats\-Hdr $\ast$ {\em stats\-Hdr}, unsigned long long {\em seq}, unsigned int {\em gem\-Clock}, unsigned int {\em gem\-Strobe})}}
\label{THS_8h_a30}


Sets last event parms within LSF\_\-stats\-Hdr. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em stats\-Hdr}]pointer to LSF\_\-stats\-Hdr structure to fill in \item[{\em seq}]extended seqence number of the event \item[{\em gem\-Clock}]evt clock register read from GEM contributor of event \item[{\em gem\-Strobe}]evt PPS cock register read from GEM contributor of event \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
This is convenient routine to fill in event info that is stored in a LSF\_\-stats\-Hdr structure within an LSF packet for eventual output as science data on the SSR.\hypertarget{THS_8h_a19}{
\index{THS.h@{THS.h}!THS_prevTimetoneFromEvent@{THS\_\-prevTimetoneFromEvent}}
\index{THS_prevTimetoneFromEvent@{THS\_\-prevTimetoneFromEvent}!THS.h@{THS.h}}
\subsubsection[THS\_\-prevTimetoneFromEvent]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-prev\-Timetone\-From\-Event (int {\em gem\-Strobe\-In}, int $\ast$ {\em abs\-Time\-Secs}, int $\ast$ {\em flags}, int $\ast$ {\em abs\-Time\-Secs\-Prev}, int $\ast$ {\em flags\-Prev}, int $\ast$ {\em gem\-Strobe\-In\-Prev})}}
\label{THS_8h_a19}


get timetone/flags from table for this event and for prev entry in table 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gem\-Strobe\-In}]stobe counter from GEM from event data \item[{\em abs\-Time\-Secs}]returns time from timetone message in secs for this event \item[{\em flags}]returns flags from timetone message for this event, bits defines as THS\_\-Gem\-Table\-Flags \item[{\em abs\-Time\-Secs\-Prev}]returns time from prev entry in table \item[{\em flags\-Prev}]returns flags from prev entry in table, bits defines as THS\_\-Gem\-Table\-Flags \item[{\em gem\-Strobe\-In\-Prev}]returne gem\-Strobe register value from prev entry in table \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
\hypertarget{THS_8h_a27}{
\index{THS.h@{THS.h}!THS_setGemUpdateMsgs@{THS\_\-setGemUpdateMsgs}}
\index{THS_setGemUpdateMsgs@{THS\_\-setGemUpdateMsgs}!THS.h@{THS.h}}
\subsubsection[THS\_\-setGemUpdateMsgs]{\setlength{\rightskip}{0pt plus 5cm}void THS\_\-set\-Gem\-Update\-Msgs (int {\em max\-Msgs})}}
\label{THS_8h_a27}


set size of memory pool for gem\-Update msgs, must be called before THS\_\-init 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em max\-Msgs}]number of gem table update messages in memory pool \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
\hypertarget{THS_8h_a23}{
\index{THS.h@{THS.h}!THS_setPpsWarnEvery@{THS\_\-setPpsWarnEvery}}
\index{THS_setPpsWarnEvery@{THS\_\-setPpsWarnEvery}!THS.h@{THS.h}}
\subsubsection[THS\_\-setPpsWarnEvery]{\setlength{\rightskip}{0pt plus 5cm}void THS\_\-set\-Pps\-Warn\-Every (unsigned int {\em warn\-Pps\-Every})}}
\label{THS_8h_a23}


Set how often get warning when no PPS. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em warn\-Pps\-Every}]0=warn once when no pps detect, n=warn every N sec \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
\hypertarget{THS_8h_a25}{
\index{THS.h@{THS.h}!THS_setSlaveSend@{THS\_\-setSlaveSend}}
\index{THS_setSlaveSend@{THS\_\-setSlaveSend}!THS.h@{THS.h}}
\subsubsection[THS\_\-setSlaveSend]{\setlength{\rightskip}{0pt plus 5cm}void THS\_\-set\-Slave\-Send (\hyperlink{THS_8h_a4}{THS\_\-Send\-Slave\-Rtn} {\em rtn}, void $\ast$ {\em arg}, int {\em lsm\-ID})}}
\label{THS_8h_a25}


stash away routine (from LCM) to send msg to EPU 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em rtn}]- pointer to function to use to send off message to EPU \item[{\em arg}]- 1st arg passed into rtn \item[{\em lsm\-ID}]- 2nd arg passed into rtn \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
Given routine should be called as: (rtn)(arg, lsm\-Id, int nid, void $\ast$payload, int payload\-Len, void$\ast$ payload\-Free\-Rtn, void $\ast$payload\-Free\-Rtn\-Arg);\hypertarget{THS_8h_a24}{
\index{THS.h@{THS.h}!THS_setTimetoneWarnEvery@{THS\_\-setTimetoneWarnEvery}}
\index{THS_setTimetoneWarnEvery@{THS\_\-setTimetoneWarnEvery}!THS.h@{THS.h}}
\subsubsection[THS\_\-setTimetoneWarnEvery]{\setlength{\rightskip}{0pt plus 5cm}void THS\_\-set\-Timetone\-Warn\-Every (unsigned int {\em warn\-Timetone\-Every})}}
\label{THS_8h_a24}


Set how often get warning when no timetone. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em warn\-Timetone\-Every}]0=warn once when no tt detect, n=warn every N sec \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
\hypertarget{THS_8h_a13}{
\index{THS.h@{THS.h}!THS_simulatedPPS@{THS\_\-simulatedPPS}}
\index{THS_simulatedPPS@{THS\_\-simulatedPPS}!THS.h@{THS.h}}
\subsubsection[THS\_\-simulatedPPS]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-simulated\-PPS (void)}}
\label{THS_8h_a13}


Return the state of the pulse-per-second simulation. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Pulse-per-second is not being simulated \item[{\em 1}]Pulse-per-second is being simulated\end{description}
\end{Desc}
\hypertarget{THS_8h_a14}{
\index{THS.h@{THS.h}!THS_simulatedTT@{THS\_\-simulatedTT}}
\index{THS_simulatedTT@{THS\_\-simulatedTT}!THS.h@{THS.h}}
\subsubsection[THS\_\-simulatedTT]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-simulated\-TT (void)}}
\label{THS_8h_a14}


Return the state of the timetone simulation. 

\begin{Desc}
\item[Return values:]
\begin{description}
\item[{\em 0}]Timetone is not being simulated \item[{\em 1}]Timetone is being simulated\end{description}
\end{Desc}
\hypertarget{THS_8h_a26}{
\index{THS.h@{THS.h}!THS_slaveProcessMsg@{THS\_\-slaveProcessMsg}}
\index{THS_slaveProcessMsg@{THS\_\-slaveProcessMsg}!THS.h@{THS.h}}
\subsubsection[THS\_\-slaveProcessMsg]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-slave\-Process\-Msg (int {\em func}, void $\ast$ {\em payload}, unsigned int {\em len})}}
\label{THS_8h_a26}


routine called from ITC dispatch in LSM to process each message it receives (this routine is run on EPU when it receives message) 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em func}]func code for message \item[{\em payload}]- buffer with received message \item[{\em len}]- length of given buffer \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none\end{Desc}
\hypertarget{THS_8h_a16}{
\index{THS.h@{THS.h}!THS_timetone@{THS\_\-timetone}}
\index{THS_timetone@{THS\_\-timetone}!THS.h@{THS.h}}
\subsubsection[THS\_\-timetone]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-timetone (unsigned int {\em abs\-Time\-Sec}, unsigned short {\em sa\-Flags})}}
\label{THS_8h_a16}


Provide abs\-Time for next entry in table (on next PPS). 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em abs\-Time\-Sec}]- absolute time for next PPS pulse in secs since 1/1/2001 \item[{\em sa\-Flags}]- flags from Spectrum Astro (i.e. in Magic 7 telecommand) \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
This routine provides the absolute time for next PPS. This should come from the spacecrasft once a sec approx 500-800 milli\-Sec before PPS.\hypertarget{THS_8h_a18}{
\index{THS.h@{THS.h}!THS_timetoneFromEvent@{THS\_\-timetoneFromEvent}}
\index{THS_timetoneFromEvent@{THS\_\-timetoneFromEvent}!THS.h@{THS.h}}
\subsubsection[THS\_\-timetoneFromEvent]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-timetone\-From\-Event (int {\em gem\-Strobe\-In}, int $\ast$ {\em abs\-Time\-Secs}, int $\ast$ {\em flags})}}
\label{THS_8h_a18}


get timetone/flags from table for this event 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gem\-Strobe\-In}]stobe counter from GEM from event data \item[{\em abs\-Time\-Secs}]returns time from timetone message in secs for this event \item[{\em flags}]returns flags from timetone message for this event, bits defines as THS\_\-Gem\-Table\-Flags \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status\end{Desc}
Routines to get abs\-TIme and flag from table entry associated with given gem\-Strobe value from an event. Since this value is calulated through a table saved for the last N secs, it is only valid for the last N secs else will return error .\hypertarget{THS_8h_a15}{
\index{THS.h@{THS.h}!THS_wait@{THS\_\-wait}}
\index{THS_wait@{THS\_\-wait}!THS.h@{THS.h}}
\subsubsection[THS\_\-wait]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-wait ()}}
\label{THS_8h_a15}


Wait for Time\-Hack\-Service module to be fully operational. 

\begin{Desc}
\item[Returns:]status\end{Desc}
Since time hack requires a number of subsystems to be operating. These includes LCB driver, 1553 driver, and time tone messages from the scapecraft. Since this module requires two time\-Tone message from the spacecraft it might take 2 seconds before it is operational. THe routine does a slow poll waiting for the THS to be operational.

The sequence is: \hyperlink{THS_8h_a12}{THS\_\-init()};

start up bunch of things including Sw to call THS\_\-time\-Tone() every second as result of message from spacecraft Hw to cause PPS interrupt every second

\hyperlink{THS_8h_a15}{THS\_\-wait()} (this routine waits till receives two THS\_\-time\-Tone() followed by PPS interrupt)