Skip to content

Commit

Permalink
Merge pull request #122 from jphickey/fix-115-timeref
Browse files Browse the repository at this point in the history
Fix #115, remove conditional compile on time ref
  • Loading branch information
dzbaker committed Oct 26, 2023
2 parents 05dd449 + d7f72d5 commit 4d77822
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 104 deletions.
4 changes: 2 additions & 2 deletions config/default_sc_internal_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,8 @@
* This parameter defines what type of time SC should use for sending uot its commands
*
* \par Limits:
* Must be SC_USE_CFE_TIME, SC_USE_TAI, or SC_USE_UTC */
#define SC_TIME_TO_USE SC_USE_CFE_TIME
* Must be SC_TimeRef_USE_CFE_TIME, SC_TimeRef_USE_TAI, or SC_TimeRef_USE_UTC */
#define SC_TIME_TO_USE SC_TimeRef_USE_CFE_TIME

/**
* \brief Autostart RTS ID after power on
Expand Down
23 changes: 19 additions & 4 deletions config/default_sc_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,28 @@
/**\}*/

/**
* \name constants for config parameters for which TIME to use
* Enumeration of config parameters for which time reference to use
*/
enum SC_TimeRef
{
SC_TimeRef_USE_CFE_TIME, /**< \brief Use cFE configured time */
SC_TimeRef_USE_TAI, /**< \brief Use TAI Time */
SC_TimeRef_USE_UTC, /**< \brief USE UTC Time */
SC_TimeRef_MAX
};

typedef uint8 SC_TimeRef_Enum_t;

#ifndef SC_OMIT_DEPRECATED
/**
* \name Old-style constants for config parameters for which TIME to use
* \{
*/
#define SC_USE_CFE_TIME 0 /**< \brief Use cFE configured time */
#define SC_USE_TAI 1 /**< \brief Use TAI Time */
#define SC_USE_UTC 2 /**< \brief USE UTC Time */
#define SC_USE_CFE_TIME SC_TimeRef_USE_CFE_TIME
#define SC_USE_TAI SC_TimeRef_USE_TAI
#define SC_USE_UTC SC_TimeRef_USE_UTC
/**\}*/
#endif

#define SC_INVALID_RTS_NUMBER 0 /**< \brief Invalid RTS number */

Expand Down
168 changes: 84 additions & 84 deletions docs/dox_src/cfs_sc.dox

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions fsw/src/sc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include "cfe.h"
#include "sc_app.h"
#include "sc_utils.h"
#include "sc_dispatch.h"
#include "sc_loads.h"
#include "sc_events.h"
Expand Down Expand Up @@ -151,6 +152,9 @@ CFE_Status_t SC_AppInit(void)

SC_AppData.EnableHeaderUpdate = SC_PLATFORM_ENABLE_HEADER_UPDATE;

/* assign the time ref accessor from the compile-time option */
SC_AppData.TimeRef = SC_LookupTimeAccessor(SC_TIME_TO_USE);

/* Make sure nothing is running */
SC_AppData.NextProcNumber = SC_NONE;
SC_AppData.NextCmdTime[SC_ATP] = SC_MAX_TIME;
Expand Down
16 changes: 16 additions & 0 deletions fsw/src/sc_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
#include "sc_msgdefs.h"
#include "sc_msg.h"

/**
* SC time accessor object
*
* Wrapper structure containing a method to get
* the current reference time. This reference is
* used for evaluationg all time references in ATSs
* and RTSs.
*/
typedef struct SC_TimeAccessor
{
CFE_TIME_SysTime_t (*GetTime)(void);
} SC_TimeAccessor_t;

/**
* \brief ATP Control Block Type
*/
Expand Down Expand Up @@ -330,6 +343,9 @@ typedef struct
These offsets correspond to the addresses of ATS commands located in the ATS table.
The index used is the ATS command index with values from 0 to SC_MAX_ATS_CMDS-1 */


SC_TimeAccessor_t TimeRef; /**< \brief Configured time reference */

bool EnableHeaderUpdate; /**< \brief whether to update headers in outgoing messages */

uint8 NextProcNumber; /**< \brief the next command processor number */
Expand Down
30 changes: 21 additions & 9 deletions fsw/src/sc_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@
**
**************************************************************************/

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Look up the time accessor corresponding to the chosen reference */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
SC_TimeAccessor_t SC_LookupTimeAccessor(SC_TimeRef_Enum_t TimeRef)
{
static const SC_TimeAccessor_t TIMEREF_LOOKUP[SC_TimeRef_MAX] = {[SC_TimeRef_USE_CFE_TIME] = {CFE_TIME_GetTime},
[SC_TimeRef_USE_TAI] = {CFE_TIME_GetTAI},
[SC_TimeRef_USE_UTC] = {CFE_TIME_GetUTC}};

if (TimeRef >= SC_TimeRef_MAX)
{
TimeRef = SC_TimeRef_USE_CFE_TIME;
}

return TIMEREF_LOOKUP[TimeRef];
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Get the Current time from CFE TIME */
Expand All @@ -49,15 +68,8 @@ void SC_GetCurrentTime(void)
{
CFE_TIME_SysTime_t TempTime;

/* Use SC defined time */
#if (SC_TIME_TO_USE == SC_USE_UTC)
TempTime = CFE_TIME_GetUTC();
#elif (SC_TIME_TO_USE == SC_USE_TAI)
TempTime = CFE_TIME_GetTAI();
#else
/* Use cFE configured time */
TempTime = CFE_TIME_GetTime();
#endif
/* Use SC defined time */
TempTime = SC_AppData.TimeRef.GetTime();

/* We don't care about subseconds */
SC_AppData.CurrentTime = TempTime.Seconds;
Expand Down
11 changes: 11 additions & 0 deletions fsw/src/sc_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,15 @@ bool SC_CompareAbsTime(SC_AbsTimeTag_t AbsTime1, SC_AbsTimeTag_t AbsTime2);
*/
uint16 SC_ToggleAtsIndex(void);

/**
* \brief Finds the time accessor object associated with the given time ref
*
* \par Description
* Translates the enumeration value into a time accessor
*
* \param TimeRef Selected time reference enumeration value
* \returns Time accessor object
*/
SC_TimeAccessor_t SC_LookupTimeAccessor(SC_TimeRef_Enum_t TimeRef);

#endif
8 changes: 4 additions & 4 deletions fsw/src/sc_verify.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@

#ifndef SC_TIME_TO_USE
#error SC_TIME_TO_USE must be defined!
#elif (SC_TIME_TO_USE != SC_USE_CFE_TIME)
#if (SC_TIME_TO_USE != SC_USE_TAI)
#if (SC_TIME_TO_USE != SC_USE_UTC)
#error SC_TIME_TO_USE must be either SC_USE_CFE_TIME, SC_USE_TAI or SC_USE_UTC!
#elif (SC_TIME_TO_USE != SC_TimeRef_USE_CFE_TIME)
#if (SC_TIME_TO_USE != SC_TimeRef_USE_TAI)
#if (SC_TIME_TO_USE != SC_TimeRef_USE_UTC)
#error SC_TIME_TO_USE must be either SC_TimeRef_USE_CFE_TIME, SC_TimeRef_USE_TAI or SC_TimeRef_USE_UTC!
#endif
#endif
#endif
Expand Down
26 changes: 25 additions & 1 deletion unit-test/sc_utils_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,38 @@

/* sc_utils_tests globals */

static CFE_TIME_SysTime_t UT_TimeRefFunc(void)
{
return (CFE_TIME_SysTime_t) {1234, 5678};
}

void SC_LookupTimeAccessor_Test(void)
{
union
{
SC_TimeAccessor_t Obj;
void * Addr;
} Accessor;

Accessor.Addr = NULL;
Accessor.Obj = SC_LookupTimeAccessor(SC_TimeRef_USE_TAI);
UtAssert_NOT_NULL(Accessor.Addr);

Accessor.Addr = NULL;
Accessor.Obj = SC_LookupTimeAccessor(SC_TimeRef_MAX);
UtAssert_NOT_NULL(Accessor.Addr);
}

void SC_GetCurrentTime_Test(void)
{
SC_AppData.TimeRef = (SC_TimeAccessor_t) {UT_TimeRefFunc};
SC_AppData.CurrentTime = 0;

/* Execute the function being tested */
UtAssert_VOIDCALL(SC_GetCurrentTime());

/* Verify results */
UtAssert_True(SC_AppData.CurrentTime != 0, "SC_AppData.CurrentTime != 0");
UtAssert_UINT32_EQ(SC_AppData.CurrentTime, 1234);
}

void SC_GetAtsEntryTime_Test(void)
Expand Down Expand Up @@ -95,6 +118,7 @@ void SC_ToggleAtsIndex_Test(void)

void UtTest_Setup(void)
{
UtTest_Add(SC_LookupTimeAccessor_Test, SC_Test_Setup, SC_Test_TearDown, "SC_LookupTimeAccessor_Test");
UtTest_Add(SC_GetCurrentTime_Test, SC_Test_Setup, SC_Test_TearDown, "SC_GetCurrentTime_Test");
UtTest_Add(SC_GetAtsEntryTime_Test, SC_Test_Setup, SC_Test_TearDown, "SC_GetAtsEntryTime_Test");
UtTest_Add(SC_ComputeAbsTime_Test, SC_Test_Setup, SC_Test_TearDown, "SC_ComputeAbsTime_Test");
Expand Down
16 changes: 16 additions & 0 deletions unit-test/stubs/sc_utils_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ void SC_GetCurrentTime(void)
UT_GenStub_Execute(SC_GetCurrentTime, Basic, NULL);
}

/*
* ----------------------------------------------------
* Generated stub function for SC_LookupTimeAccessor()
* ----------------------------------------------------
*/
SC_TimeAccessor_t SC_LookupTimeAccessor(SC_TimeRef_Enum_t TimeRef)
{
UT_GenStub_SetupReturnBuffer(SC_LookupTimeAccessor, SC_TimeAccessor_t);

UT_GenStub_AddParam(SC_LookupTimeAccessor, SC_TimeRef_Enum_t, TimeRef);

UT_GenStub_Execute(SC_LookupTimeAccessor, Basic, NULL);

return UT_GenStub_GetReturnValue(SC_LookupTimeAccessor, SC_TimeAccessor_t);
}

/*
* ----------------------------------------------------
* Generated stub function for SC_ToggleAtsIndex()
Expand Down

0 comments on commit 4d77822

Please sign in to comment.