GLAST / LAT > DAQ and FSW > FSW > Doxygen Index> EFC / V4-5-0 > iefc / mv2304


Interface   Data Structures   File List   Data Fields   Globals  

EFC_time.c File Reference

Emulation routines for the WCT time and THS routines. More...

#include <time.h>
#include <EFC/EFC_time.h>
#include <EFC_time.ih>
#include <EDS/EBF_gem.h>

Classes

struct  _EFC_timeContext
 Holds the time context information. More...

Defines

#define SA_OFFSET   0x3a4fc880
 Offset between the UNIX and Spectrum-Astro time epochs.

Typedefs

typedef enum _TIME_FLAGS_S TIME_FLAGS_S
 Typedef for enum _TIME_FLAGS_S.
typedef enum _TIME_FLAGS_V TIME_FLAGS_V
 Typedef for enum _TIME_FLAGS_V.
typedef enum _TIME_FLAGS_M TIME_FLAGS_M
 Typedef for enum _TIME_FLAGS_M.
typedef struct _EFC_timeContext EFC_timeContext
 Typedef for struct _EFC_timeContext.

Enumerations

enum  _TIME_FLAGS_S {
  TIME_FLAGS_S_SIMULATED_VALUE = 1,
  TIME_FLAGS_S_SIMULATED_PPS_CPU = 1,
  TIME_FLAGS_S_SIMULATED_PPS_GEM = 1,
  TIME_FLAGS_S_NO_MESSAGE = 1,
  TIME_FLAGS_S_CNT_GPS_NO_LOCK = 12,
  TIME_FLAGS_S_IS_SOURCE_GPS = 1,
  TIME_FLAGS_S_SA_RSVD = 15
}
 Enumerates the timetone flags word, right-shift values. More...
enum  _TIME_FLAGS_V {
  TIME_FLAGS_V_SIMULATED_VALUE = 0,
  TIME_FLAGS_V_SIMULATED_PPS_CPU = 1,
  TIME_FLAGS_V_SIMULATED_PPS_GEM = 2,
  TIME_FLAGS_V_NO_MESSAGE = 3,
  TIME_FLAGS_V_CNT_GPS_NO_LOCK = 4,
  TIME_FLAGS_V_IS_SOURCE_GPS = 16,
  TIME_FLAGS_V_SA_RSVD = 17
}
 Enumerates the timetone flags word, right-shift values. More...
enum  _TIME_FLAGS_M {
  TIME_FLAGS_M_SIMULATED_VALUE = 0x1,
  TIME_FLAGS_M_SIMULATED_PPS_CPU = 0x2,
  TIME_FLAGS_M_SIMULATED_PPS_GEM = 0x4,
  TIME_FLAGS_M_NO_MESSAGE = 0x8,
  TIME_FLAGS_M_CNT_GPS_NO_LOCK = 0x0000FFF0,
  TIME_FLAGS_M_IS_SOURCE_GPS = 0x00010000,
  TIME_FLAGS_M_SA_RSVD = 0xfffe0000
}
 Enumerates the timetone flags word, in place mask values. More...

Functions

static void efc_construct (EFC_timeFlagSpec *tfs)
 Sets the time specification sequence.
static void efc_set (unsigned int seconds, unsigned int flags, unsigned int frequency)
 Sets the initial time, flags word and frequency.
static void efc_elapsedSet (unsigned int elapsed_reg, unsigned int pps_reg)
 Uses the elapsed clock tick and 1-PPS GEM registers to calculate the elapsed time since the last 1-PPS strobe.
static unsigned long long int efc_timestampGet (void)
 Returns the time since the Spectrum-Astro epoch.
static unsigned int efc_timetoneGet (unsigned int pps, unsigned int *secs, unsigned int *flags)
 Fills in the seconds and flag values of a simulated timetone message corresponding to the specified 1-PPS strobe value.
static unsigned int efc_timetonesGet (unsigned int cur_pps, unsigned int *cur_secs, unsigned int *cur_flags, unsigned int *prv_secs, unsigned int *prv_flags, unsigned int *prv_pps)
 Fills in the timetone message corresponding to cur_pps and the most recent timetone message occuring prior to cur_pps.
void EFC_timeConstruct (const EFC_timeServices *services, void *prm)
 Constructs/initializes the EFC time emulation services.
void EFC_timeSet (unsigned int seconds, unsigned int flags, unsigned int frequency)
 Sets the initial time and frequency.
unsigned int EFC_timeSecsGet (void)
 Get the current number of elapsed seconds since the Spectrum-Astro Epoch.
unsigned long long int EFC_timeTimestampGet (void)
 Get the current timestamp, i.e. the number of elapsed seconds and micro-seconds since the Spectrum-Astro Epoch.
unsigned int EFC_timeOffset (void)
 Gets the offset from standard UNIX time to Spectrum Astro time.
static __inline unsigned int complete_flags (unsigned int new_flags, unsigned int prv_flags)
 If the new flag value is not error-free (IS_SOURCE_GPS) modifies it to update the error count.

Variables

EFC_timeServices EfcTimeServices
 The list of time services needed when filling in such information in the datagrams.
static EFC_timeContext EfcTimeContext
 Captures the static context needed by the default implementation.


Detailed Description

Emulation routines for the WCT time and THS routines.

Author:
JJRussell - russell@slac.stanford.edu

   CVS $Id: EFC_time.c,v 1.3 2011/03/27 04:55:30 russell Exp $

Note:
This file should only be compiled for host platforms

Typedef Documentation

Typedef for enum _TIME_FLAGS_M.

The flags word is a 32-bit word composed of 2 16-bit words. The most significant 16 bits belong to Spectrum Astro and are copied verbatim from the timetone message. As of this writing, only the least significant bit was defined as being set when the GPS lock was lost.
Warning:
Bit 30 has been usurped to indicate an internal inconsistency when decoding the data on the ground.
The least significant 16 bits are used by flight software. The low 4 bits are flags indicating problems with the timetone receiving mechanism. Essentially there are 3 signals to consider, the 1 PPS to the GEM, the 1 PPS to the receiving event processing CPU and the timetone message itself. Three of these bits indicate that one or more of the signals was not present at the required time.
The remaining 12 bits of the flight software 16 bit value is reserved for a count of the number of consecutive pulses that do have an imperfect timetone message or reception. This allows the user to determine how long the system has been flywheeling on Spectrum-Astro's internal oscillator or, more accurately, how long it has been since the last pristine message and reception. (For example, another error is the SIU missing its 1PPS message.)

Typedef for enum _TIME_FLAGS_S.

See TIME_FLAGS_M

Typedef for enum _TIME_FLAGS_V.

See TIME_FLAGS_M


Enumeration Type Documentation

Enumerates the timetone flags word, in place mask values.

Enumerator:
TIME_FLAGS_M_SIMULATED_VALUE  The timetone value is simulated
TIME_FLAGS_M_SIMULATED_PPS_CPU  The receiving CPU did not receive a 1 PPS interrupted, so the 1 PPS was simulated by a timeout. In this case, the timetone message should be okay. This bit is really here for hardware accounting purposes. If this happens, it may indicate a faulty interrupt line to the CPU
TIME_FLAGS_M_SIMULATED_PPS_GEM  The GEM did not get the 1 PPS. This IS a serious problem. It means the CPU thought that at least 1 second has gone by, but the 7-bit index in the GEM's 1 PPS register did not advance. One should not trust the 1 PPS register.
TIME_FLAGS_M_NO_MESSAGE  The receiving CPU did not have a timetone message corresponding to the 1 PPS GEM register at the time the event arrived. This is a semi-normal situation, occuring when the event from the EBM (normally an event that occurs very near the 1-PPS time) arrives at the processing CPU before the timetone message arrives. When events are being processed on an EPU, this is just a race between the event from the EBM to the CPU and the timetone message from the SIU. Under normal conditions, a timetone message with this bit set will be followed (within a couple of events) by the real timetone message. However, the processing software, not wishing to wait an indeterminate amount of time for the real message, fabricates a timetone message, marking it with this bit
TIME_FLAGS_M_CNT_GPS_NO_LOCK  The count of consecutive timetone messages that have the GPS_NO_LOCK bit set.
TIME_FLAGS_M_IS_SOURCE_GPS  This is bit indicates the source of the time is the GPS. If not, the spacecraft lost the GPS lock and is simulating the timetone message by flywheeling off its own internal oscillator. This oscillator is very accurate, but one should exercise caution if the flywheel period lasts for a while.
TIME_FLAGS_M_SA_RSVD  Reserved for future use

Enumerates the timetone flags word, right-shift values.

Enumerator:
TIME_FLAGS_S_SIMULATED_VALUE  The timetone value is simulated
TIME_FLAGS_S_SIMULATED_PPS_CPU  The receiving CPU did not receive a 1 PPS interrupted, so the 1 PPS was simulated by a timeout. In this case, the timetone message should be okay. This bit is really here for hardware accounting purposes. If this happens, it may indicate a faulty interrupt line to the CPU
TIME_FLAGS_S_SIMULATED_PPS_GEM  The GEM did not get the 1 PPS. This IS a serious problem. It means the CPU thought that at least 1 second has gone by, but the 7-bit index in the GEM's 1 PPS register did not advance. One should not trust the 1 PPS register.
TIME_FLAGS_S_NO_MESSAGE  The receiving CPU did not have a timetone message corresponding to the 1 PPS GEM register at the time the event arrived. This is a semi-normal situation, occuring when the event from the EBM (normally an event that occurs very near the 1-PPS time) arrives at the processing CPU before the timetone message arrives. When events are being processed on an EPU, this is just a race between the event from the EBM to the CPU and the timetone message from the SIU. Under normal conditions, a timetone message with this bit set will be followed (within a couple of events) by the real timetone message. However, the processing software, not wishing to wait an indeterminate amount of time for the real message, fabricates a timetone message, marking it with this bit
TIME_FLAGS_S_CNT_GPS_NO_LOCK  The count of consecutive timetone messages that have an imperfect timetone message or reception
TIME_FLAGS_S_IS_SOURCE_GPS  This is bit indicates the source of the time is the GPS. If not, the spacecraft lost the GPS lock and is simulating the timetone message by flywheeling off its own internal oscillator. This oscillator is very accurate, but one should exercise caution if the flywheel period lasts for a while.
TIME_FLAGS_S_SA_RSVD  Reserved for future use

Enumerates the timetone flags word, right-shift values.

Enumerator:
TIME_FLAGS_V_SIMULATED_VALUE  The timetone value is simulated
TIME_FLAGS_V_SIMULATED_PPS_CPU  The receiving CPU did not receive a 1 PPS interrupted, so the 1 PPS was simulated by a timeout. In this case, the timetone message should be okay. This bit is really here for hardware accounting purposes. If this happens, it may indicate a faulty interrupt line to the CPU
TIME_FLAGS_V_SIMULATED_PPS_GEM  The GEM did not get the 1 PPS. This IS a serious problem. It means the CPU thought that at least 1 second has gone by, but the 7-bit index in the GEM's 1 PPS register did not advance. One should not trust the 1 PPS register.
TIME_FLAGS_V_NO_MESSAGE  The receiving CPU did not have a timetone message corresponding to the 1 PPS GEM register at the time the event arrived. This is a semi-normal situation, occuring when the event from the EBM (normally an event that occurs very near the 1-PPS time) arrives at the processing CPU before the timetone message arrives. When events are being processed on an EPU, this is just a race between the event from the EBM to the CPU and the timetone message from the SIU. Under normal conditions, a timetone message with this bit set will be followed (within a couple of events) by the real timetone message. However, the processing software, not wishing to wait an indeterminate amount of time for the real message, fabricates a timetone message, marking it with this bit
TIME_FLAGS_V_CNT_GPS_NO_LOCK  The count of consecutive timetone messages that have an imperfect timetone message or reception.
TIME_FLAGS_V_IS_SOURCE_GPS  This is bit indicates the source of the time is the GPS. If not, the spacecraft lost the GPS lock and is simulating the timetone message by flywheeling off its own internal oscillator. This oscillator is very accurate, but one should exercise caution if the flywheel period lasts for a while.
TIME_FLAGS_V_SA_RSVD  Reserved for future use


Function Documentation

unsigned int complete_flags ( unsigned int  new_flags,
unsigned int  prv_flags 
) [static]

If the new flag value is not error-free (IS_SOURCE_GPS) modifies it to update the error count.

Returns:
The, potentially, modified version of new_flags
Parameters:
new_flags The new flag value
prv_flags The previous flag value

References TIME_FLAGS_M_CNT_GPS_NO_LOCK, TIME_FLAGS_M_IS_SOURCE_GPS, and TIME_FLAGS_V_CNT_GPS_NO_LOCK.

Referenced by efc_elapsedSet().

static void efc_construct ( EFC_timeFlagSpec tfs  )  [static]

Sets the time specification sequence.

Parameters:
tfs Pointer to the time flag specification sequence. Maybe NULL, in which case, the flag word is always 0.

References _EFC_timeFlagSpec::cnt, _EFC_timeContext::cur_flags, _EFC_timeFlagSpec::flags, _EFC_timeContext::tfs, and _EFC_timeContext::tfs_cnt.

static void efc_elapsedSet ( unsigned int  elapsed_reg,
unsigned int  pps_reg 
) [static]

Uses the elapsed clock tick and 1-PPS GEM registers to calculate the elapsed time since the last 1-PPS strobe.

Parameters:
elapsed_reg The GEM's elapsed tick register
pps_reg The GEM's 1-PPS strobe register

References _EFC_timeFlagSpec::cnt, complete_flags(), _EFC_timeContext::cur_flags, _EFC_timeFlagSpec::flags, _EFC_timeContext::frequency, _EFC_timeFlagSpec::nxt, _EFC_timeContext::prv_flags, _EFC_timeContext::prv_idx, _EFC_timeContext::tfs, _EFC_timeContext::tfs_cnt, and _EFC_timeContext::ticks.

static void efc_set ( unsigned int  seconds,
unsigned int  flags,
unsigned int  frequency 
) [static]

Sets the initial time, flags word and frequency.

Parameters:
seconds The initial time, specified in the number of seconds since the Spectrum-Astro epoch. If specified as 0, then the time is not adjusted. If specified as -1, then the default (current time) is used.
flags The initial value of the flags word. There is no default. A reasonable value is 0, i.e. no errors.
frequency The frequency, in Hertz. If specified as 0, then the frequency will not be changed. If specified as -1, then the default (20MHz) is used.

References _EFC_timeContext::cur_flags, EFC_TIME_K_DEFAULT, _EFC_timeFlagSpec::flags, _EFC_timeContext::frequency, _EFC_timeContext::init, _EFC_timeContext::prv_flags, SA_OFFSET, _EFC_timeContext::seconds, _EFC_timeContext::tfs, and TIME_FLAGS_M_IS_SOURCE_GPS.

void EFC_timeConstruct ( const EFC_timeServices services,
void *  prm 
)

Constructs/initializes the EFC time emulation services.

Parameters:
services A pointer to the virtual functions. If NULL, the standard services are used.
prm Arbitrary user parameter passed to the constructor

References _EFC_timeServices::construct.

unsigned int EFC_timeOffset ( void   ) 

Gets the offset from standard UNIX time to Spectrum Astro time.

This value is a constant, the value of which is being hidden in this routine. The value needs to be subtracted from the standard Unix time to get the Spectrum Astro time.
Note:
Since this is a constant, it is safe to cache this value.

References SA_OFFSET.

unsigned int EFC_timeSecsGet ( void   ) 

Get the current number of elapsed seconds since the Spectrum-Astro Epoch.

Returns:
The current number of elapsed seconds since the Spectrum-Astro Epoch

References _EFC_timeServices::timestampGet.

void EFC_timeSet ( unsigned int  seconds,
unsigned int  flags,
unsigned int  frequency 
)

Sets the initial time and frequency.

Parameters:
seconds The initial time, specified in the number of seconds since the Spectrum-Astro epoch. If specified as 0, then the time is not adjusted
flags The initial value of the timetone message's flag word. There is no default value, but bit 16 (source = GPS) would be a good choice as a default (no errors).
frequency The frequency, in Hertz. If specified as 0, then the frequency will not be changed

References _EFC_timeServices::set.

static unsigned long long int efc_timestampGet ( void   )  [static]

Returns the time since the Spectrum-Astro epoch.

Returns:
The time since the Spectrum-Astro epoch as a 64-bit value with number of seconds in the upper 32 bits and the number of micro seconds in the lower 32 bits.
This function finds its primary use in providing the timestamp for the CCSDS secondary packet header.

References _EFC_time::f, _EFC_timeContext::frequency, _EFC_timeContext::seconds, _EFC_timeContext::ticks, and _EFC_time::ull.

unsigned long long int EFC_timeTimestampGet ( void   ) 

Get the current timestamp, i.e. the number of elapsed seconds and micro-seconds since the Spectrum-Astro Epoch.

Returns:
The current timestamp, i.e. the number of elapsed seconds and micro-seconds since the Spectrum-Astro Epoch.

References _EFC_timeServices::timestampGet.

static unsigned int efc_timetoneGet ( unsigned int  pps,
unsigned int *  secs,
unsigned int *  flags 
) [static]

Fills in the seconds and flag values of a simulated timetone message corresponding to the specified 1-PPS strobe value.

Returns:
Status, currently always success
Parameters:
pps The value of 1-PPS strobe register to use as a key
secs Filled in with the elapsed time, in seconds from the Spectrum-Astro epoch corresponding to the pps
flags The flag word, currently set to 0, i.e. no errors

References _EFC_timeContext::cur_flags, _EFC_timeContext::init, _EFC_timeContext::prv_flags, _EFC_timeContext::prv_idx, _EFC_timeContext::seconds, and TIME_FLAGS_M_IS_SOURCE_GPS.

Referenced by efc_timetonesGet().

static unsigned int efc_timetonesGet ( unsigned int  cur_pps,
unsigned int *  cur_secs,
unsigned int *  cur_flags,
unsigned int *  prv_secs,
unsigned int *  prv_flags,
unsigned int *  prv_pps 
) [static]

Fills in the timetone message corresponding to cur_pps and the most recent timetone message occuring prior to cur_pps.

Returns:
Status
Parameters:
cur_pps The value of the GEM's 1-PPS register to use as a key in locating the timetone messages
cur_secs Filled in with the time since the Spectrum-Astro epoch corresponding the current timetone message
cur_flags Filled in with status flags/values (see THS) corresponding the current timetone message
prv_secs Filled in with the time since the Spectrum-Astro epoch corresponding the previous timetone message
prv_flags Filled in with status flags/values (see THS) corresponding the previous timetone message
prv_pps Filled in with the value of GEM's 1-PPS register corresponding the previous timetone message

References efc_timetoneGet(), _EFC_timeContext::frequency, and _EFC_timeContext::prv_flags.


Variable Documentation

Initial value:

Captures the static context needed by the default implementation.

Initial value:

The list of time services needed when filling in such information in the datagrams.

This acts like a C++ virtual function table. It is initialized with default set of functions. These can be overriden using EFC_timeServicesConstruct.


Generated on Wed Jan 4 14:13:23 2012 by  doxygen 1.5.8