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



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_a24}{\_\-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_a25}{\_\-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_a24}{\_\-THS\_\-OPTION} \{ \par
\hyperlink{THS_8h_a24a5}{THS\_\-GEM\_\-HACK} =  1, 
\par
\hyperlink{THS_8h_a24a6}{THS\_\-CPU\_\-HACK} =  2, 
\par
\hyperlink{THS_8h_a24a7}{THS\_\-SIU\_\-HACK} =  4
 \}
\item 
enum \hyperlink{THS_8h_a25}{\_\-THS\_\-FSW\_\-FLAGS} \{ \par
\hyperlink{THS_8h_a25a8}{THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM} =  1, 
\par
\hyperlink{THS_8h_a25a9}{THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM} =  2, 
\par
\hyperlink{THS_8h_a25a10}{THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM} =  4
 \}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
unsigned int \hyperlink{THS_8h_a11}{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_a12}{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_a13}{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_a14}{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_a15}{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_a16}{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)
\begin{CompactList}\small\item\em get timetone/flags from table for this event and for prev entry in table \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a17}{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_a18}{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_a19}{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_a20}{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_a21}{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_a22}{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_a23}{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}\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_a25}{
\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_a25}{\_\-THS\_\-FSW\_\-FLAGS}}}
\label{THS_8h_a25}


\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_a25a8}{
THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM}
\label{THS_8h_a25a8}
}]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_a25a9}{
THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM}
\label{THS_8h_a25a9}
}]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_a25a10}{
THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM}
\label{THS_8h_a25a10}
}]GEM did not get PPS, need to calc new GEM stobe val \end{description}
\end{Desc}

\hypertarget{THS_8h_a24}{
\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_a24}{\_\-THS\_\-OPTION}}}
\label{THS_8h_a24}


\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_a24a5}{
THS\_\-GEM\_\-HACK}
\label{THS_8h_a24a5}
}]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_a24a6}{
THS\_\-CPU\_\-HACK}
\label{THS_8h_a24a6}
}]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_a24a7}{
THS\_\-SIU\_\-HACK}
\label{THS_8h_a24a7}
}]this cpu is the SIU \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{THS_8h_a17}{
\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_a17}


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_a14}{
\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_a14}


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_a18}{
\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_a18}


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_a11}{
\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_a11}


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_a16}{
\index{THS.h@{THS.h}!THS_prevTimtoneFromEvent@{THS\_\-prevTimtoneFromEvent}}
\index{THS_prevTimtoneFromEvent@{THS\_\-prevTimtoneFromEvent}!THS.h@{THS.h}}
\subsubsection[THS\_\-prevTimtoneFromEvent]{\setlength{\rightskip}{0pt plus 5cm}unsigned int THS\_\-prev\-Timtone\-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_a16}


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_a23}{
\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_a23}


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_a19}{
\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_a19}


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_a21}{
\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_a21}


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_a20}{
\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_a20}


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_a22}{
\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_a22}


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_a13}{
\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_a13}


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_a15}{
\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_a15}


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_a12}{
\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_a12}


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_a11}{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_a12}{THS\_\-wait()} (this routine waits till receives two THS\_\-time\-Tone() followed by PPS interrupt)