GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> THS / dev > ths / rhel5-64


Interface   Data Structures   File List   Data Fields   Globals  

THS_gem.c File Reference

Time Hack Services. More...

#include <THS/THS_msgs.h>
#include <THS_prvdefs.h>
#include <LCBD/LCBD.h>
#include <LCBD/LCBD_pci.h>
#include <LEM/defs.h>
#include <LEM/decode.h>
#include <LEM/encode.h>
#include <LEM/encode_structs.h>
#include <LEM/cli.h>
#include <PBS/PBS.h>
#include <PBS/TASK.h>
#include <PBS/TMR.h>
#include <MSG/MSG_pubdefs.h>
#include <PBI/Endianness.h>
#include <stdio.h>
#include <string.h>

Functions

WCT_time THS_gemAbsTimeEvent (int gemStrobeIn, int gemClk)
 Calculate absolute time for event from strobe and clk provided with event (20MHz clk).
unsigned int THS_timetoneFromEvent (int gemStrobeIn, int *absTimeSecs, int *flags)
 get timetone/flags from table for this event
unsigned int THS_prevTimtoneFromEvent (int gemStrobeIn, int *absTimeSecs, int *flags, int *absTimeSecsPrev, int *flagsPrev, int *gemStrobeInPrev)
 THIS IS MIS-SPELLING, it just calls THS_prevTimetoneFromEvent.
unsigned int THS_prevTimetoneFromEvent (int gemStrobeIn, int *absTimeSecs, int *flags, int *absTimeSecsPrev, int *flagsPrev, int *gemStrobeInPrev)
 get timetone/flags from table for this event and for prev entry in table
unsigned int THS_gemInit (int siu)
 Inits the TimeHackService module.
unsigned int THS_gemWait ()
 Start the TimeHackService module.
unsigned int THS_gemGetTableInfo (int count, unsigned int *gemStrobe, LSU_factors *Kgem, unsigned int *flags)
 get info from hack table
unsigned int THS_gemCalcClkDiff (unsigned int clk, unsigned int prevClk)
 calculate diff between clks assuming 25 bit clock
void THS_gemIsr (unsigned int absTimeSec, THS_GemTableFlags flags)
 interrupt routine for gem specfic time hack
unsigned int THS_gemSetWarning (unsigned int expectedClkHz, unsigned int expectedDeltaClkHz)
 Set range for gem clock warning messages.
void THS_gemSetTable (unsigned int absTimeSec, THS_GemTableFlags flags, unsigned int gemStrobeIn, LSU_factors Kgem)
 Set a single entry in the gem hack table.


Detailed Description

Time Hack Services.

Author:
Ed Bacho -- ebacho@slac.stanford.edu This module works from within THS.c to control the GEM time hack.
This module handles calculation of absolute time using the "time hack" for the clk in the GEM (GASU).

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 ("at the tone the time will be") that preceeds it. The time provided in the time tone message from the scapecraft is in microSec since 1/1/2001. Hence the clock value is adjusted each second to account for clock counter drift from GEM clock.

The basic functions provided to application programs are:

Inputs:

Outputs:


Function Documentation

WCT_time THS_gemAbsTimeEvent ( int  gemStrobeIn,
int  gemClk 
)

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

Parameters:
gemStrobeIn stobe counter from GEM from event data
gemClk clk counter from GEM from event data
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.

References THS_FSW_FLAG_NO_HACK_TABLE, and THS_gemCalcClkDiff().

unsigned int THS_gemCalcClkDiff ( unsigned int  clk,
unsigned int  prevClk 
)

calculate diff between clks assuming 25 bit clock

Parameters:
clk latest gem clk value
prevClk previous gem clock value
Returns:
difference between clk values

Referenced by THS_gemAbsTimeEvent(), and THS_stats().

unsigned int THS_gemGetTableInfo ( int  count,
unsigned int *  gemStrobe,
LSU_factors *  Kgem,
unsigned int *  flags 
)

get info from hack table

Parameters:
count count value from gemStrobe, this is a 7 bit index into table
gemStrobe gemStrobe register value for this
Kgem ptr to extrapolation constants struct to fill
flags return flags from tt message for this entry
Returns:
absolute time value at PPS in sec

Referenced by THS_stats().

unsigned int THS_gemInit ( int  siu  ) 

Inits the TimeHackService module.

Parameters:
siu 1=SIU(=commander on cmd/response), 0=EPU
Returns:
status This routine does basic init for gem specific THS and requires only a few modules to be init (PBS,MSG, ??). It is called from THS.c. Howver, it will not be fully operation till is has received timetone and PPS interrupt. THS_gemWait() can be used to wait for this state.

Referenced by THS_init().

void THS_gemIsr ( unsigned int  absTimeSec,
THS_GemTableFlags  flags 
)

interrupt routine for gem specfic time hack

Parameters:
absTimeSec absolute time at PPS from tt message
flags Spectrum Astro and FSW flags
Returns:
nothing Interrupt routine connected to 1PPS input. This should be called from ThsIsr(). This is first half of processing to put a new entry into the time table. Other half is callback form LCB routine to read gem register.

void THS_gemSetTable ( unsigned int  absTimeSec,
THS_GemTableFlags  flags,
unsigned int  gemStrobeIn,
LSU_factors  Kgem 
)

Set a single entry in the gem hack table.

Parameters:
absTimeSec 
flags combined SA and FSW flags
gemStrobeIn register read from GEM
Kgem coeffients to calc absolute time
Returns:
none On SIU, this will be called within callback from the GEM read started by the PPS interrupt. The callback will also send this info on to the EPu's
On EPUs, this will be called as the results of a message from the SIU with this information.

References _THS_GemTableFlags::ui.

Referenced by THS_slaveProcessMsg().

unsigned int THS_gemSetWarning ( unsigned int  expectedClkHz,
unsigned int  expectedDeltaClkHz 
)

Set range for gem clock warning messages.

Parameters:
expectedClkHz - expected clock in Hz, <=0 uses default of 20MHz
expectedDeltaClkHz - expected delta clk in Hz, <0 uses default of 1% of clock
Returns:
status

unsigned int THS_gemWait (  ) 

Start the TimeHackService module.

Returns:
status Wait for THS to become full operational after THS_init(). This routines requires that most of the software is operational. This includes LCB driver, 1553 driver, and time tone messages from the scapecraft enabled. Since this module requires a timeTOne message from the spacecraft it can take up to 2 sec to return.
The sequence is: THS_gemInit();

start up bunch of things including LCB driver Sw to call THS_timeTone() every second as result of message from spacecraft Hw to cause PPS interrupt every second

THS_gemWait() (this routine waits till received first THS_gemTimeTone() followed by PPS interrupt)

Referenced by THS_wait().

unsigned int THS_prevTimetoneFromEvent ( int  gemStrobeIn,
int *  absTimeSecs,
int *  flags,
int *  absTimeSecsPrev,
int *  flagsPrev,
int *  gemStrobeInPrev 
)

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

Parameters:
gemStrobeIn stobe counter from GEM from event data
absTimeSecs returns time from timetone message in secs for this event
flags returns flags from timetone message for this event, bits defines as THS_GemTableFlags
absTimeSecsPrev returns time from prev entry in table
flagsPrev returns flags from prev entry in table, bits defines as THS_GemTableFlags
gemStrobeInPrev returne gemStrobe register value from prev entry in table
Returns:
status

References THS_FSW_FLAG_NO_HACK_TABLE.

Referenced by THS_prevTimtoneFromEvent().

unsigned int THS_timetoneFromEvent ( int  gemStrobeIn,
int *  absTimeSecs,
int *  flags 
)

get timetone/flags from table for this event

Parameters:
gemStrobeIn stobe counter from GEM from event data
absTimeSecs returns time from timetone message in secs for this event
flags returns flags from timetone message for this event, bits defines as THS_GemTableFlags
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 .

References THS_FSW_FLAG_NO_HACK_TABLE.


Generated on Thu Mar 31 12:53:03 2011 by  doxygen 1.5.8