GLAST/LAT > DAQ and FSW > FSW > Doxygen Index > THS / V1-4-1

Constituent: ths     Tag: sun-gcc


Interface   Data Structures   File List   Data Fields   Globals  

THS_gem.c File Reference

Time Hack Services. More...

#include "PBS/PBS.h"
#include "PBS/TASK.h"
#include "PBS/TMR.h"
#include "PBI/Endianness.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 "MSG/MSG_pubdefs.h"
#include "THS/THS_msgs.h"
#include "THS_prvdefs.h"
#include <stdio.h>
#include <string.h>

Include dependency graph for THS_gem.c:


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.
void THS_lsfStatClear (LSF_statsHdr *statsHdr)
 Clear the LSF_statsHdr structure.
unsigned int THS_lsfStatFirstEvt (LSF_statsHdr *statsHdr, unsigned long long seq, unsigned int gemClock, unsigned int gemStrobe)
 Sets first event parms within LSF_statsHdr.
void THS_lsfStatIncEvt (LSF_statsHdr *statsHdr, int increment)
 Increment event counter in LSF_statsHdr structure.
unsigned int THS_lsfStatLastEvt (LSF_statsHdr *statsHdr, unsigned long long seq, unsigned int gemClock, unsigned int gemStrobe)
 Sets last event parms within LSF_statsHdr.

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.

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

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

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.

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.

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)

void THS_lsfStatClear LSF_statsHdr *  statsHdr  ) 
 

Clear the LSF_statsHdr structure.

Parameters:
statsHdr pointer to LSF_statsHdr structure to fill in
Returns:
nothing

unsigned int THS_lsfStatFirstEvt LSF_statsHdr *  statsHdr,
unsigned long long  seq,
unsigned int  gemClock,
unsigned int  gemStrobe
 

Sets first event parms within LSF_statsHdr.

Parameters:
statsHdr pointer to LSF_statsHdr structure to fill in
seq extended seqence number of the event
gemClock evt clock register read from GEM contributor of event
gemStrobe evt PPS cock register read from GEM contributor of event
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.

void THS_lsfStatIncEvt LSF_statsHdr *  statsHdr,
int  increment
 

Increment event counter in LSF_statsHdr structure.

Parameters:
statsHdr pointer to LSF_statsHdr structure to fill in
increment number of events to increase evt count by
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.

unsigned int THS_lsfStatLastEvt LSF_statsHdr *  statsHdr,
unsigned long long  seq,
unsigned int  gemClock,
unsigned int  gemStrobe
 

Sets last event parms within LSF_statsHdr.

Parameters:
statsHdr pointer to LSF_statsHdr structure to fill in
seq extended seqence number of the event
gemClock evt clock register read from GEM contributor of event
gemStrobe evt PPS cock register read from GEM contributor of event
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.

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

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 .


Generated on Tue Nov 29 20:28:38 2005 by  doxygen 1.4.4