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


{\tt \#include $<$LSF/LSF\_\-statsHdr.h$>$}\par
{\tt \#include $<$PBS/WCT.h$>$}\par
{\tt \#include $<$PBI/Endianness.h$>$}\par
\subsection*{Classes}
\begin{CompactItemize}
\item 
struct \hyperlink{struct__THS__GemTableFlagsBf}{\_\-THS\_\-GemTableFlagsBf}
\begin{CompactList}\small\item\em Structure to map out the bit fields time hack flags stored as 32 bits in gemTable. \item\end{CompactList}\item 
struct \hyperlink{union__THS__GemTableFlags}{\_\-THS\_\-GemTableFlags}
\begin{CompactList}\small\item\em Union for different access of 32 bit flags in gemTable. \item\end{CompactList}\end{CompactItemize}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{THS_8h_86afb8c378399352143b16f5fc91e0e8}{
typedef enum \hyperlink{THS_8h_c8f92c522bc729ff05895f29dd234d2e}{\_\-THS\_\-OPTION} \hyperlink{THS_8h_86afb8c378399352143b16f5fc91e0e8}{THS\_\-OPTION}}
\label{THS_8h_86afb8c378399352143b16f5fc91e0e8}

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

\begin{CompactList}\small\item\em Masks for FSW flags in gem table. \item\end{CompactList}\item 
\hypertarget{THS_8h_6ee324331021ed20c44dcd110345f2d0}{
typedef struct \hyperlink{struct__THS__GemTableFlagsBf}{\_\-THS\_\-GemTableFlagsBf} \hyperlink{THS_8h_6ee324331021ed20c44dcd110345f2d0}{THS\_\-GemTableFlagsBf}}
\label{THS_8h_6ee324331021ed20c44dcd110345f2d0}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{struct__THS__GemTableFlagsBf}{\_\-THS\_\-GemTableFlagsBf}. \item\end{CompactList}\item 
\hypertarget{THS_8h_0755e02bc8b322e98ae4a381191ef7fe}{
typedef union \hyperlink{union__THS__GemTableFlags}{\_\-THS\_\-GemTableFlags} \hyperlink{THS_8h_0755e02bc8b322e98ae4a381191ef7fe}{THS\_\-GemTableFlags}}
\label{THS_8h_0755e02bc8b322e98ae4a381191ef7fe}

\begin{CompactList}\small\item\em Typedef for struct \hyperlink{union__THS__GemTableFlags}{\_\-THS\_\-GemTableFlags}. \item\end{CompactList}\item 
typedef unsigned int( \hyperlink{THS_8h_08a270711b7a13fb61a9653dcf8fa734}{THS\_\-SendSlaveRtn} )(void $\ast$lsmArg, short lsmID, short thsId, int nid, void $\ast$payload, int payloadLen, void $\ast$payloadFreeRtn, void $\ast$payloadFreeRtnArg)
\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_c8f92c522bc729ff05895f29dd234d2e}{\_\-THS\_\-OPTION} \{ \par
\hyperlink{THS_8h_c8f92c522bc729ff05895f29dd234d2e430020d8c187d8c0b190829596ff97b0}{THS\_\-GEM\_\-HACK} =  1, 
\par
\hyperlink{THS_8h_c8f92c522bc729ff05895f29dd234d2eb31ba28fd17abd3f2b51693a4e67d4e5}{THS\_\-CPU\_\-HACK} =  2, 
\par
\hyperlink{THS_8h_c8f92c522bc729ff05895f29dd234d2ebb8e16e4884e014896e08a368c47d529}{THS\_\-SIU\_\-HACK} =  4
 \}
\item 
enum \hyperlink{THS_8h_316322d001105b30b27258733d5982c3}{\_\-THS\_\-FSW\_\-FLAGS} \{ \par
\hyperlink{THS_8h_316322d001105b30b27258733d5982c3c7f5861d301e17d6ceb50c21a1a37e86}{THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM} =  1, 
\par
\hyperlink{THS_8h_316322d001105b30b27258733d5982c33fc827a9c6501a95fdcd3a41b467b91c}{THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM} =  2, 
\par
\hyperlink{THS_8h_316322d001105b30b27258733d5982c3022a0269799a908f74a5a814c248a1df}{THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM} =  4, 
\par
\hyperlink{THS_8h_316322d001105b30b27258733d5982c3a882ebf79e8adee68e380f04194bae4c}{THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE} =  8
 \}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
unsigned int \hyperlink{THS_8h_fee2d448fb4959febe78485c62ba3247}{THS\_\-init} (int optionMask)
\begin{CompactList}\small\item\em Inits the TimeHackService module. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_6c9b87c2a594325a7770483aebbc376a}{THS\_\-simulatedPPS} (void)
\begin{CompactList}\small\item\em Return the state of the pulse-per-second simulation. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_d5dec5a54dfaf6161ebf47bf12d0ea8d}{THS\_\-simulatedTT} (void)
\begin{CompactList}\small\item\em Return the state of the timetone simulation. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_4b801a1f8fc468fd5f1f8fb2c3fb67ee}{THS\_\-wait} ()
\begin{CompactList}\small\item\em Wait for TimeHackService module to be fully operational. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_74d3678b7bf6f28e8871dc67b7e0fe52}{THS\_\-timetone} (unsigned int absTimeSec, unsigned short saFlags)
\begin{CompactList}\small\item\em Provide absTime for next entry in table (on next PPS). \item\end{CompactList}\item 
WCT\_\-time \hyperlink{THS_8h_30b26a6a2d040658bf223e2bd76f93dd}{THS\_\-gemAbsTimeEvent} (int gemStrobeIn, int gemClk)
\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_2caa41528c6144e6500887e2fba9eda6}{THS\_\-timetoneFromEvent} (int gemStrobeIn, int $\ast$absTimeSecs, 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_05431632b9c64202b2924dd863ed6a18}{THS\_\-prevTimetoneFromEvent} (int gemStrobeIn, int $\ast$absTimeSecs, int $\ast$flags, int $\ast$absTimeSecsPrev, int $\ast$flagsPrev, int $\ast$gemStrobeInPrev)
\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_82b6f9283a6d32ac60fe14ecc65aaf26}{
unsigned int \hyperlink{THS_8h_82b6f9283a6d32ac60fe14ecc65aaf26}{THS\_\-prevTimtoneFromEvent} (int gemStrobeIn, int $\ast$absTimeSecs, int $\ast$flags, int $\ast$absTimeSecsPrev, int $\ast$flagsPrev, int $\ast$gemStrobeInPrev)}
\label{THS_8h_82b6f9283a6d32ac60fe14ecc65aaf26}

\begin{CompactList}\small\item\em THIS IS MIS-SPELLING, it just calls THS\_\-prevTimetoneFromEvent. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_7b0ba32a5f915239ce98356c16ba98ea}{THS\_\-cpuSetWarning} (unsigned int expectedClkHz, unsigned int expectedDeltaClkHz)
\begin{CompactList}\small\item\em Set range for cpu clock warning messages. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_abf4da696a635ec6d54b392e9841dbd4}{THS\_\-gemSetWarning} (unsigned int expectedClkHz, unsigned int expectedDeltaClkHz)
\begin{CompactList}\small\item\em Set range for gem clock warning messages. \item\end{CompactList}\item 
void \hyperlink{THS_8h_2af9f421a5521535c03a81e0b22c772b}{THS\_\-setPpsWarnEvery} (unsigned int warnPpsEvery)
\begin{CompactList}\small\item\em Set how often get warning when no PPS. \item\end{CompactList}\item 
void \hyperlink{THS_8h_7bc48f8201390f05b3a7704ee70dad33}{THS\_\-setTimetoneWarnEvery} (unsigned int \_\-warnTimetoneEvery)
\begin{CompactList}\small\item\em Set how often get warning when no timetone. \item\end{CompactList}\item 
void \hyperlink{THS_8h_69f2e714c9dede5880a2526ab371b95e}{THS\_\-setSlaveSend} (\hyperlink{THS_8h_08a270711b7a13fb61a9653dcf8fa734}{THS\_\-SendSlaveRtn} rtn, void $\ast$arg, int lsmId)
\begin{CompactList}\small\item\em stash away routine (from LCM) to send msg to EPU \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_991719838cf8691f8893ce0ccd50fa3b}{THS\_\-slaveProcessMsg} (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_54ae5e4a93554a58f9ade65b5d420cc6}{THS\_\-setGemUpdateMsgs} (int maxMsgs)
\begin{CompactList}\small\item\em set size of memory pool for gemUpdate msgs, must be called before THS\_\-init \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_a6fe34b2bc7d098e1a6b388733723b5e}{THS\_\-lsfStatFirstEvt} (LSF\_\-statsHdr $\ast$statsHdr, unsigned long long seq, unsigned int gemClock, unsigned int gemStrobe)
\begin{CompactList}\small\item\em Sets first event parms within LSF\_\-statsHdr. \item\end{CompactList}\item 
void \hyperlink{THS_8h_90c32c63d0c6e3346419559e02cda231}{THS\_\-lsfStatIncEvt} (LSF\_\-statsHdr $\ast$statsHdr, int increment)
\begin{CompactList}\small\item\em Increment event counter in LSF\_\-statsHdr structure. \item\end{CompactList}\item 
unsigned int \hyperlink{THS_8h_329ae5981db724174d7a31fab26f629a}{THS\_\-lsfStatLastEvt} (LSF\_\-statsHdr $\ast$statsHdr, unsigned long long seq, unsigned int gemClock, unsigned int gemStrobe)
\begin{CompactList}\small\item\em Sets last event parms within LSF\_\-statsHdr. \item\end{CompactList}\item 
void \hyperlink{THS_8h_6fcb110e1ceee29cd70a7394a55cfcc7}{THS\_\-lsfStatClear} (LSF\_\-statsHdr $\ast$statsHdr)
\begin{CompactList}\small\item\em Clear the LSF\_\-statsHdr 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} 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 microSec since 1/1/2001.\end{Desc}
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 mSec before pulse) giving next absTime\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_08a270711b7a13fb61a9653dcf8fa734}{
\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$ {\bf THS\_\-SendSlaveRtn})(void $\ast$arg, void $\ast$payload, int payloadLen)}}
\label{THS_8h_08a270711b7a13fb61a9653dcf8fa734}


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 payloadLen}]- length of buffer \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none 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) \end{Desc}


\subsection{Enumeration Type Documentation}
\hypertarget{THS_8h_316322d001105b30b27258733d5982c3}{
\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 {\bf \_\-THS\_\-FSW\_\-FLAGS}}}
\label{THS_8h_316322d001105b30b27258733d5982c3}


\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_316322d001105b30b27258733d5982c3c7f5861d301e17d6ceb50c21a1a37e86}{
THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM}
\label{THS_8h_316322d001105b30b27258733d5982c3c7f5861d301e17d6ceb50c21a1a37e86}
}]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_316322d001105b30b27258733d5982c33fc827a9c6501a95fdcd3a41b467b91c}{
THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM}
\label{THS_8h_316322d001105b30b27258733d5982c33fc827a9c6501a95fdcd3a41b467b91c}
}]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_316322d001105b30b27258733d5982c3022a0269799a908f74a5a814c248a1df}{
THS\_\-FSW\_\-FLAG\_\-GEM\_\-PPS\_\-SIM}
\label{THS_8h_316322d001105b30b27258733d5982c3022a0269799a908f74a5a814c248a1df}
}]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_316322d001105b30b27258733d5982c3a882ebf79e8adee68e380f04194bae4c}{
THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE}
\label{THS_8h_316322d001105b30b27258733d5982c3a882ebf79e8adee68e380f04194bae4c}
}]These values did not come from HackTable \end{description}
\end{Desc}

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


\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_c8f92c522bc729ff05895f29dd234d2e430020d8c187d8c0b190829596ff97b0}{
THS\_\-GEM\_\-HACK}
\label{THS_8h_c8f92c522bc729ff05895f29dd234d2e430020d8c187d8c0b190829596ff97b0}
}]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_c8f92c522bc729ff05895f29dd234d2eb31ba28fd17abd3f2b51693a4e67d4e5}{
THS\_\-CPU\_\-HACK}
\label{THS_8h_c8f92c522bc729ff05895f29dd234d2eb31ba28fd17abd3f2b51693a4e67d4e5}
}]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_c8f92c522bc729ff05895f29dd234d2ebb8e16e4884e014896e08a368c47d529}{
THS\_\-SIU\_\-HACK}
\label{THS_8h_c8f92c522bc729ff05895f29dd234d2ebb8e16e4884e014896e08a368c47d529}
}]this cpu is the SIU \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{THS_8h_7b0ba32a5f915239ce98356c16ba98ea}{
\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\_\-cpuSetWarning (unsigned int {\em expectedClkHz}, \/  unsigned int {\em expectedDeltaClkHz})}}
\label{THS_8h_7b0ba32a5f915239ce98356c16ba98ea}


Set range for cpu clock warning messages. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em expectedClkHz}]- expected clock in Hz, $<$=0 uses default, (16.6MHz on mv2304, 8.3MHz on Rad750) \item[{\em expectedDeltaClkHz}]- 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_30b26a6a2d040658bf223e2bd76f93dd}{
\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\_\-gemAbsTimeEvent (int {\em gemStrobeIn}, \/  int {\em gemClk})}}
\label{THS_8h_30b26a6a2d040658bf223e2bd76f93dd}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gemStrobeIn}]stobe counter from GEM from event data \item[{\em gemClk}]clk counter from GEM from event data \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]64b value of number of nanoSec since 1/1/2001 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. \end{Desc}


References THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE, and THS\_\-gemCalcClkDiff().\hypertarget{THS_8h_abf4da696a635ec6d54b392e9841dbd4}{
\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\_\-gemSetWarning (unsigned int {\em expectedClkHz}, \/  unsigned int {\em expectedDeltaClkHz})}}
\label{THS_8h_abf4da696a635ec6d54b392e9841dbd4}


Set range for gem clock warning messages. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em expectedClkHz}]- expected clock in Hz, $<$=0 uses default of 20MHz \item[{\em expectedDeltaClkHz}]- 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_fee2d448fb4959febe78485c62ba3247}{
\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_fee2d448fb4959febe78485c62ba3247}


Inits the TimeHackService module. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em mask}]time hack options, 1=CPU time hack, 2=Gem Time Hack, 4=CpuIsSiu \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status 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. \end{Desc}


References THS\_\-CPU\_\-HACK, THS\_\-cpuInit(), THS\_\-GEM\_\-HACK, THS\_\-gemInit(), and THS\_\-SIU\_\-HACK.\hypertarget{THS_8h_6fcb110e1ceee29cd70a7394a55cfcc7}{
\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\_\-lsfStatClear (LSF\_\-statsHdr $\ast$ {\em statsHdr})}}
\label{THS_8h_6fcb110e1ceee29cd70a7394a55cfcc7}


Clear the LSF\_\-statsHdr structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em statsHdr}]pointer to LSF\_\-statsHdr structure to fill in\end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]nothing \end{Desc}
\hypertarget{THS_8h_a6fe34b2bc7d098e1a6b388733723b5e}{
\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\_\-lsfStatFirstEvt (LSF\_\-statsHdr $\ast$ {\em statsHdr}, \/  unsigned long long {\em seq}, \/  unsigned int {\em gemClock}, \/  unsigned int {\em gemStrobe})}}
\label{THS_8h_a6fe34b2bc7d098e1a6b388733723b5e}


Sets first event parms within LSF\_\-statsHdr. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em statsHdr}]pointer to LSF\_\-statsHdr structure to fill in \item[{\em seq}]extended seqence number of the event \item[{\em gemClock}]evt clock register read from GEM contributor of event \item[{\em gemStrobe}]evt PPS cock register read from GEM contributor of event \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status This is convenient routine to fill in event info that is stored in a LSF\_\-statsHdr structure within an LSF packet for eventual output as science data on the SSR. \end{Desc}


References THS\_\-prevTimtoneFromEvent().\hypertarget{THS_8h_90c32c63d0c6e3346419559e02cda231}{
\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\_\-lsfStatIncEvt (LSF\_\-statsHdr $\ast$ {\em statsHdr}, \/  int {\em increment})}}
\label{THS_8h_90c32c63d0c6e3346419559e02cda231}


Increment event counter in LSF\_\-statsHdr structure. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em statsHdr}]pointer to LSF\_\-statsHdr structure to fill in \item[{\em increment}]number of events to increase evt count by \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]nothing This is convenient routine to increment the event counter within LSF\_\-statsHdr structure. Note that this in the number of events seen by the callback, the raw events rather than the number of prescaled events. \end{Desc}
\hypertarget{THS_8h_329ae5981db724174d7a31fab26f629a}{
\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\_\-lsfStatLastEvt (LSF\_\-statsHdr $\ast$ {\em statsHdr}, \/  unsigned long long {\em seq}, \/  unsigned int {\em gemClock}, \/  unsigned int {\em gemStrobe})}}
\label{THS_8h_329ae5981db724174d7a31fab26f629a}


Sets last event parms within LSF\_\-statsHdr. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em statsHdr}]pointer to LSF\_\-statsHdr structure to fill in \item[{\em seq}]extended seqence number of the event \item[{\em gemClock}]evt clock register read from GEM contributor of event \item[{\em gemStrobe}]evt PPS cock register read from GEM contributor of event \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status This is convenient routine to fill in event info that is stored in a LSF\_\-statsHdr structure within an LSF packet for eventual output as science data on the SSR. \end{Desc}


References THS\_\-prevTimtoneFromEvent().\hypertarget{THS_8h_05431632b9c64202b2924dd863ed6a18}{
\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\_\-prevTimetoneFromEvent (int {\em gemStrobeIn}, \/  int $\ast$ {\em absTimeSecs}, \/  int $\ast$ {\em flags}, \/  int $\ast$ {\em absTimeSecsPrev}, \/  int $\ast$ {\em flagsPrev}, \/  int $\ast$ {\em gemStrobeInPrev})}}
\label{THS_8h_05431632b9c64202b2924dd863ed6a18}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gemStrobeIn}]stobe counter from GEM from event data \item[{\em absTimeSecs}]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\_\-GemTableFlags \item[{\em absTimeSecsPrev}]returns time from prev entry in table \item[{\em flagsPrev}]returns flags from prev entry in table, bits defines as THS\_\-GemTableFlags \item[{\em gemStrobeInPrev}]returne gemStrobe register value from prev entry in table \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status \end{Desc}


References THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE.

Referenced by THS\_\-prevTimtoneFromEvent().\hypertarget{THS_8h_54ae5e4a93554a58f9ade65b5d420cc6}{
\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\_\-setGemUpdateMsgs (int {\em maxMsgs})}}
\label{THS_8h_54ae5e4a93554a58f9ade65b5d420cc6}


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

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em maxMsgs}]number of gem table update messages in memory pool \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none \end{Desc}
\hypertarget{THS_8h_2af9f421a5521535c03a81e0b22c772b}{
\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\_\-setPpsWarnEvery (unsigned int {\em warnPpsEvery})}}
\label{THS_8h_2af9f421a5521535c03a81e0b22c772b}


Set how often get warning when no PPS. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em warnPpsEvery}]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_69f2e714c9dede5880a2526ab371b95e}{
\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\_\-setSlaveSend ({\bf THS\_\-SendSlaveRtn} {\em rtn}, \/  void $\ast$ {\em arg}, \/  int {\em lsmID})}}
\label{THS_8h_69f2e714c9dede5880a2526ab371b95e}


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 lsmID}]- 2nd arg passed into rtn \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]none Given routine should be called as: (rtn)(arg, lsmId, int nid, void $\ast$payload, int payloadLen, void$\ast$ payloadFreeRtn, void $\ast$payloadFreeRtnArg); \end{Desc}
\hypertarget{THS_8h_7bc48f8201390f05b3a7704ee70dad33}{
\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\_\-setTimetoneWarnEvery (unsigned int {\em warnTimetoneEvery})}}
\label{THS_8h_7bc48f8201390f05b3a7704ee70dad33}


Set how often get warning when no timetone. 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em warnTimetoneEvery}]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_6c9b87c2a594325a7770483aebbc376a}{
\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\_\-simulatedPPS (void)}}
\label{THS_8h_6c9b87c2a594325a7770483aebbc376a}


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_d5dec5a54dfaf6161ebf47bf12d0ea8d}{
\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\_\-simulatedTT (void)}}
\label{THS_8h_d5dec5a54dfaf6161ebf47bf12d0ea8d}


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_991719838cf8691f8893ce0ccd50fa3b}{
\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\_\-slaveProcessMsg (int {\em func}, \/  void $\ast$ {\em payload}, \/  unsigned int {\em len})}}
\label{THS_8h_991719838cf8691f8893ce0ccd50fa3b}


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}


References THS\_\-FSW\_\-FLAG\_\-CPU\_\-PPS\_\-SIM, THS\_\-FSW\_\-FLAG\_\-TT\_\-SIM, THS\_\-gemSetTable(), and THS\_\-timetone().\hypertarget{THS_8h_74d3678b7bf6f28e8871dc67b7e0fe52}{
\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 absTimeSec}, \/  unsigned short {\em saFlags})}}
\label{THS_8h_74d3678b7bf6f28e8871dc67b7e0fe52}


Provide absTime for next entry in table (on next PPS). 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em absTimeSec}]- absolute time for next PPS pulse in secs since 1/1/2001 \item[{\em saFlags}]- flags from Spectrum Astro (i.e. in Magic 7 telecommand) \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status This routine provides the absolute time for next PPS. This should come from the spacecrasft once a sec approx 500-800 milliSec before PPS. \end{Desc}


Referenced by THS\_\-slaveProcessMsg().\hypertarget{THS_8h_2caa41528c6144e6500887e2fba9eda6}{
\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\_\-timetoneFromEvent (int {\em gemStrobeIn}, \/  int $\ast$ {\em absTimeSecs}, \/  int $\ast$ {\em flags})}}
\label{THS_8h_2caa41528c6144e6500887e2fba9eda6}


get timetone/flags from table for this event 

\begin{Desc}
\item[Parameters:]
\begin{description}
\item[{\em gemStrobeIn}]stobe counter from GEM from event data \item[{\em absTimeSecs}]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\_\-GemTableFlags \end{description}
\end{Desc}
\begin{Desc}
\item[Returns:]status Routines to get absTIme and flag from table entry associated with given gemStrobe 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 . \end{Desc}


References THS\_\-FSW\_\-FLAG\_\-NO\_\-HACK\_\-TABLE.\hypertarget{THS_8h_4b801a1f8fc468fd5f1f8fb2c3fb67ee}{
\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_4b801a1f8fc468fd5f1f8fb2c3fb67ee}


Wait for TimeHackService module to be fully operational. 

\begin{Desc}
\item[Returns:]status 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 timeTone 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.\end{Desc}
The sequence is: \hyperlink{THS_8h_fee2d448fb4959febe78485c62ba3247}{THS\_\-init()};

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

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

References THS\_\-CPU\_\-HACK, THS\_\-cpuWait(), THS\_\-GEM\_\-HACK, and THS\_\-gemWait().