Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions modules/time/fsw/inc/cfe_time_internal_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,26 @@
#define CFE_PLATFORM_TIME_CFG_CLIENT CFE_PLATFORM_TIME_CFGVAL(CFG_CLIENT)
#define DEFAULT_CFE_PLATFORM_TIME_CFG_CLIENT false

/**
** \cfetimecfg Disable Local 1Hz task
**
** \par Description:
** This configuration parameter selects whether the Time task creates a
** local 1hz task to drive the 1hz state machine, or if it relies
** on an external app like the cFS Scheduler to send the 1hz state
** machine packet. This option can support specific Time mission use
** cases.
**
** \par Limits
** If set to false, the Time module will create the OSAL timer and local
** 1Hz task that drives the Time 1Hz state machine (default).
** If set to true, the Time module will exclude the OSAL timer, local 1Hz ISR
** (callback) and the Local 1Hz task. An external source such as the scheduler
** will have to send the packet to drive the 1hz state machine.
*/
#define CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ CFE_PLATFORM_TIME_CFGVAL(CFG_DISABLE_LOCAL_1HZ)
#define DEFAULT_CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ false

/**
** \cfetimecfg Local MET or Virtual MET Selection for Time Servers
**
Expand Down
26 changes: 16 additions & 10 deletions modules/time/fsw/src/cfe_time_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,6 @@ static int32 CFE_TIME_TaskInit_CreateResources(const char *LogFunction)
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

OsStatus = OS_BinSemCreate(&CFE_TIME_Global.LocalSemaphore,
CFE_TIME_SEM_ONEHZ_NAME,
CFE_TIME_SEM_VALUE,
CFE_TIME_SEM_OPTIONS);
if (OsStatus != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating local semaphore:RC=%ld\n", LogFunction, (long)OsStatus);
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

Status = CFE_ES_CreateChildTask(&CFE_TIME_Global.ToneTaskID,
CFE_TIME_TASK_TONE_NAME,
CFE_TIME_Tone1HzTask,
Expand All @@ -185,6 +175,17 @@ static int32 CFE_TIME_TaskInit_CreateResources(const char *LogFunction)
return Status;
}

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
OsStatus = OS_BinSemCreate(&CFE_TIME_Global.LocalSemaphore,
CFE_TIME_SEM_ONEHZ_NAME,
CFE_TIME_SEM_VALUE,
CFE_TIME_SEM_OPTIONS);
if (OsStatus != OS_SUCCESS)
{
CFE_ES_WriteToSysLog("%s: Error creating local semaphore:RC=%ld\n", LogFunction, (long)OsStatus);
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

Status = CFE_ES_CreateChildTask(&CFE_TIME_Global.LocalTaskID,
CFE_TIME_TASK_ONEHZ_NAME,
CFE_TIME_Local1HzTask,
Expand All @@ -197,6 +198,7 @@ static int32 CFE_TIME_TaskInit_CreateResources(const char *LogFunction)
CFE_ES_WriteToSysLog("%s: Error creating local 1Hz child task:RC=0x%08X\n", LogFunction, (unsigned int)Status);
return Status;
}
#endif

return CFE_SUCCESS;
}
Expand Down Expand Up @@ -314,6 +316,7 @@ static int32 CFE_TIME_TaskInit_SendInitEvent(const char *LogFunction)
return CFE_SUCCESS;
}

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
/*----------------------------------------------------------------
*
* Local helper function
Expand Down Expand Up @@ -353,6 +356,7 @@ static void CFE_TIME_TaskInit_Setup1HzTimer(const char *LogFunction)
CFE_ES_WriteToSysLog("%s: 1Hz OS_TimerSet failed:RC=%ld\n", LogFunction, (long)OsStatus);
}
}
#endif

/*----------------------------------------------------------------
*
Expand Down Expand Up @@ -389,7 +393,9 @@ int32 CFE_TIME_TaskInit(void)
OS_SelectTone(CFE_TIME_Global.ClockSignal);
#endif

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
CFE_TIME_TaskInit_Setup1HzTimer(__func__);
#endif

return CFE_SUCCESS;
}
Expand Down
45 changes: 24 additions & 21 deletions modules/time/fsw/src/cfe_time_tone.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,17 +943,6 @@ void CFE_TIME_ToneUpdate(void)
}
}

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TIME_Local1HzTimerCallback(osal_id_t TimerId, void *Arg)
{
CFE_TIME_Local1HzISR();
}

/*----------------------------------------------------------------
*
* Application-scope internal function
Expand Down Expand Up @@ -1130,6 +1119,15 @@ void CFE_TIME_Local1HzStateMachine(void)
/* Start Performance Monitoring */
CFE_ES_PerfLogEntry(CFE_MISSION_TIME_LOCAL1HZISR_PERF_ID);

/*
** Send "info" event if we just started flywheel mode...
*/
if (CFE_TIME_Global.AutoStartFly)
{
CFE_TIME_Global.AutoStartFly = false;
CFE_EVS_SendEvent(CFE_TIME_FLY_ON_EID, CFE_EVS_EventType_INFORMATION, "Start FLYWHEEL");
}

/* Zero out the Reference variable because we pass it into
* a function before using it
* */
Expand Down Expand Up @@ -1241,10 +1239,24 @@ void CFE_TIME_Local1HzISR(void)
{
CFE_TIME_Global.LocalIntCounter++;

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
/*
** Enable 1Hz task (we can't send a SB message from here)...
*/
OS_BinSemGive(CFE_TIME_Global.LocalSemaphore);
#endif
}

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
void CFE_TIME_Local1HzTimerCallback(osal_id_t TimerId, void *Arg)
{
CFE_TIME_Local1HzISR();
}

/*----------------------------------------------------------------
Expand Down Expand Up @@ -1274,16 +1286,6 @@ void CFE_TIME_Local1HzTask(void)
/* Start Performance Monitoring */
CFE_ES_PerfLogEntry(CFE_MISSION_TIME_LOCAL1HZTASK_PERF_ID);

/*
** Send "info" event if we just started flywheel mode...
*/
if (CFE_TIME_Global.AutoStartFly)
{
CFE_TIME_Global.AutoStartFly = false;

CFE_EVS_SendEvent(CFE_TIME_FLY_ON_EID, CFE_EVS_EventType_INFORMATION, "Start FLYWHEEL");
}

/*
** Send 1Hz timing packet...
** This used to be optional in previous CFE versions, but it is now required
Expand All @@ -1302,6 +1304,7 @@ void CFE_TIME_Local1HzTask(void)
** error in the creation of the semaphore.
*/
}
#endif

/*----------------------------------------------------------------
*
Expand Down
9 changes: 8 additions & 1 deletion modules/time/ut-coverage/time_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,9 @@ void Test_Tone(void)
*/
void Test_1Hz(void)
{
uint16 Arg;
#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
uint16 Arg;
#endif
uint16 i;
uint32 delSec = 3;
CFE_TIME_SysTime_t time1;
Expand Down Expand Up @@ -2490,6 +2492,7 @@ void Test_1Hz(void)
CFE_TIME_Tone1HzISR();
UtAssert_INT32_EQ(ut_time_CallbackCalled, 3);

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
/* Test the local 1Hz ISR */
UT_InitData();
CFE_TIME_Global.LocalIntCounter = 1;
Expand All @@ -2506,6 +2509,7 @@ void Test_1Hz(void)
UT_SetDeferredRetcode(UT_KEY(OS_BinSemTake), 2, OS_ERROR);
CFE_TIME_Local1HzTask();
UtAssert_UINT32_EQ(CFE_TIME_Global.LocalTaskCounter, 1);
#endif

/* Test the tone 1Hz task where the binary semaphore take fails on the
* second call
Expand Down Expand Up @@ -2545,6 +2549,7 @@ void Test_1Hz(void)
CFE_TIME_Tone1HzISR();
UtAssert_BOOL_FALSE(CFE_TIME_Global.IsToneGood);

#if (CFE_PLATFORM_TIME_CFG_DISABLE_LOCAL_1HZ == false)
/* Test local 1Hz interrupt when enough time has elapsed (subseconds) since
* receiving a time update to automatically change the state to flywheel
*/
Expand Down Expand Up @@ -2576,6 +2581,7 @@ void Test_1Hz(void)
UtAssert_INT32_EQ(RefState->ClockFlyState, CFE_TIME_FlywheelState_NO_FLY);

/* Test the local 1Hz task where auto start flywheel is disabled */
/* APC - need to relocate this test */
UT_InitData();
CFE_TIME_Global.LocalTaskCounter = 0;
CFE_TIME_Global.AutoStartFly = false;
Expand All @@ -2596,6 +2602,7 @@ void Test_1Hz(void)
UT_SetBSP_Time(0, 0);
CFE_TIME_Local1HzTimerCallback(OS_ObjectIdFromInteger(123), &Arg);
UtAssert_UINT32_EQ(CFE_TIME_Global.LocalIntCounter, 2);
#endif
}

/*
Expand Down
Loading