\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=119pt]{THS_8h__dep__incl}
\end{center}
\end{figure}
\subsection*{Typedefs}
\begin{CompactItemize}
\item 
\hypertarget{THS_8h_a0}{
typedef enum \hyperlink{THS_8h_a14}{\_\-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 
typedef unsigned int( \hyperlink{THS_8h_a1}{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_a14}{\_\-THS\_\-OPTION} \{ \par
\hyperlink{THS_8h_a14a2}{THS\_\-GEM\_\-HACK} =  1, 
\par
\hyperlink{THS_8h_a14a3}{THS\_\-CPU\_\-HACK} =  2, 
\par
\hyperlink{THS_8h_a14a4}{THS\_\-SIU\_\-HACK} =  4, 
\par
\hyperlink{THS_8h_a14a5}{THS\_\-GEMPPS\_\-HACK} =  8
 \}
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
unsigned int \hyperlink{THS_8h_a6}{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_a7}{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_a8}{THS\_\-timetone} (unsigned int abs\-Time\-Sec, unsigned short 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_a9}{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_a10}{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_a11}{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_a12}{THS\_\-set\-Slave\-Send} (\hyperlink{THS_8h_a1}{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_a13}{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}\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_a1}{
\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_a1}{THS\_\-Send\-Slave\-Rtn})(void $\ast$arg, void $\ast$payload, int payload\-Len)}}
\label{THS_8h_a1}


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_a14}{
\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_a14}{\_\-THS\_\-OPTION}}}
\label{THS_8h_a14}


\begin{Desc}
\item[Enumeration values: ]\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_a14a2}{
{\em THS\_\-GEM\_\-HACK}}
\label{THS_8h_a14a2}
}]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_a14a3}{
{\em THS\_\-CPU\_\-HACK}}
\label{THS_8h_a14a3}
}]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_a14a4}{
{\em THS\_\-SIU\_\-HACK}}
\label{THS_8h_a14a4}
}]this cpu is the SIU \index{THS_GEMPPS_HACK@{THS\_\-GEMPPS\_\-HACK}!THS.h@{THS.h}}\index{THS.h@{THS.h}!THS_GEMPPS_HACK@{THS\_\-GEMPPS\_\-HACK}}\item[{\em 
\hypertarget{THS_8h_a14a5}{
{\em THS\_\-GEMPPS\_\-HACK}}
\label{THS_8h_a14a5}
}]setup GEM to produce PPS (valid only on mv2304) \end{description}
\end{Desc}



\subsection{Function Documentation}
\hypertarget{THS_8h_a10}{
\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_a10}


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


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. 

Here is the call graph for this function:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=173pt]{THS_8h_a9_cgraph}
\end{center}
\end{figure}
\hypertarget{THS_8h_a11}{
\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_a11}


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


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. 

Here is the call graph for this function:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=111pt]{THS_8h_a6_cgraph}
\end{center}
\end{figure}
\hypertarget{THS_8h_a12}{
\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_a1}{THS\_\-Send\-Slave\-Rtn} {\em rtn}, void $\ast$ {\em arg}, int {\em lsm\-ID})}}
\label{THS_8h_a12}


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


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}


Here is the call graph for this function:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=155pt]{THS_8h_a13_cgraph}
\end{center}
\end{figure}
\hypertarget{THS_8h_a8}{
\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 flags})}}
\label{THS_8h_a8}


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 flags}]\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_a7}{
\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_a7}


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

Here is the call graph for this function:\begin{figure}[H]
\begin{center}
\leavevmode
\includegraphics[width=117pt]{THS_8h_a7_cgraph}
\end{center}
\end{figure}
