Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1181, global variable cleanup #1254

Merged
merged 1 commit into from
Mar 29, 2021
Merged
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
11 changes: 6 additions & 5 deletions modules/es/fsw/src/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ int32 CFE_ES_GetResetType(uint32 *ResetSubtypePtr)
{
if (ResetSubtypePtr != NULL)
{
*ResetSubtypePtr = CFE_ES_ResetDataPtr->ResetVars.ResetSubtype;
*ResetSubtypePtr = CFE_ES_Global.ResetDataPtr->ResetVars.ResetSubtype;
}

return (CFE_ES_ResetDataPtr->ResetVars.ResetType);
return (CFE_ES_Global.ResetDataPtr->ResetVars.ResetType);

} /* End of CFE_ES_GetResetType() */

Expand All @@ -68,13 +68,14 @@ int32 CFE_ES_ResetCFE(uint32 ResetType)
/*
** Increment the processor reset count
*/
CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount++;
CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount++;

/*
** Before doing a Processor reset, check to see
** if the maximum number has been exceeded
*/
if (CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount > CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount)
if (CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount >
CFE_ES_Global.ResetDataPtr->ResetVars.MaxProcessorResetCount)
{
CFE_ES_WriteToSysLog("POWER ON RESET due to max proc resets (Commanded).\n");

Expand All @@ -96,7 +97,7 @@ int32 CFE_ES_ResetCFE(uint32 ResetType)
/*
** Update the reset variables
*/
CFE_ES_ResetDataPtr->ResetVars.ES_CausedReset = true;
CFE_ES_Global.ResetDataPtr->ResetVars.ES_CausedReset = true;

/*
** Log the reset in the ER Log
Expand Down
5 changes: 3 additions & 2 deletions modules/es/fsw/src/cfe_es_apps.c
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,8 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg)
/*
* If the command count changes, then a scan becomes due immediately.
*/
if (State->LastScanCommandCount == CFE_ES_TaskData.CommandCounter && State->BackgroundScanTimer > ElapsedTime)
if (State->LastScanCommandCount == CFE_ES_Global.TaskData.CommandCounter &&
State->BackgroundScanTimer > ElapsedTime)
{
/* no action at this time, background scan is not due yet */
State->BackgroundScanTimer -= ElapsedTime;
Expand All @@ -1008,7 +1009,7 @@ bool CFE_ES_RunAppTableScan(uint32 ElapsedTime, void *Arg)
*/
NumAppTimeouts = 0;
State->BackgroundScanTimer = CFE_PLATFORM_ES_APP_SCAN_RATE;
State->LastScanCommandCount = CFE_ES_TaskData.CommandCounter;
State->LastScanCommandCount = CFE_ES_Global.TaskData.CommandCounter;
State->PendingAppStateChanges = 0;

/*
Expand Down
4 changes: 2 additions & 2 deletions modules/es/fsw/src/cfe_es_backgroundtask.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ typedef struct
const CFE_ES_BackgroundJobEntry_t CFE_ES_BACKGROUND_JOB_TABLE[] = {
{/* ES app table background scan */
.RunFunc = CFE_ES_RunAppTableScan,
.JobArg = &CFE_ES_TaskData.BackgroundAppScanState,
.JobArg = &CFE_ES_Global.BackgroundAppScanState,
.ActivePeriod = CFE_PLATFORM_ES_APP_SCAN_RATE / 4,
.IdlePeriod = CFE_PLATFORM_ES_APP_SCAN_RATE},
{/* Performance Log Data Dump to file */
.RunFunc = CFE_ES_RunPerfLogDump,
.JobArg = &CFE_ES_TaskData.BackgroundPerfDumpState,
.JobArg = &CFE_ES_Global.BackgroundPerfDumpState,
.ActivePeriod = CFE_PLATFORM_ES_PERF_CHILD_MS_DELAY,
.IdlePeriod = CFE_PLATFORM_ES_PERF_CHILD_MS_DELAY * 1000},
{/* Check for exceptions stored in the PSP */
Expand Down
38 changes: 19 additions & 19 deletions modules/es/fsw/src/cfe_es_erlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,25 @@ int32 CFE_ES_WriteToERLogWithContext(CFE_ES_LogEntryType_Enum_t EntryType, uint3
/*
** Try to clean up an invalid ER log index variable.
*/
if (CFE_ES_ResetDataPtr->ERLogIndex >= CFE_PLATFORM_ES_ER_LOG_ENTRIES)
if (CFE_ES_Global.ResetDataPtr->ERLogIndex >= CFE_PLATFORM_ES_ER_LOG_ENTRIES)
{
CFE_ES_ResetDataPtr->ERLogIndex = 0;
CFE_ES_Global.ResetDataPtr->ERLogIndex = 0;
}
LogIdx = CFE_ES_ResetDataPtr->ERLogIndex;
LogIdx = CFE_ES_Global.ResetDataPtr->ERLogIndex;

/*
** Now that the Local Index variable is set, increment the index for the next entry.
*/
CFE_ES_ResetDataPtr->ERLogIndex++;
if (CFE_ES_ResetDataPtr->ERLogIndex >= CFE_PLATFORM_ES_ER_LOG_ENTRIES)
CFE_ES_Global.ResetDataPtr->ERLogIndex++;
if (CFE_ES_Global.ResetDataPtr->ERLogIndex >= CFE_PLATFORM_ES_ER_LOG_ENTRIES)
{
CFE_ES_ResetDataPtr->ERLogIndex = 0;
CFE_ES_Global.ResetDataPtr->ERLogIndex = 0;
}

/*
** Clear out the log entry we are about to use.
*/
EntryPtr = &CFE_ES_ResetDataPtr->ERLog[LogIdx];
EntryPtr = &CFE_ES_Global.ResetDataPtr->ERLog[LogIdx];
memset(EntryPtr, 0, sizeof(*EntryPtr));

/*
Expand All @@ -111,9 +111,9 @@ int32 CFE_ES_WriteToERLogWithContext(CFE_ES_LogEntryType_Enum_t EntryType, uint3
EntryPtr->BaseInfo.LogEntryType = EntryType;
EntryPtr->BaseInfo.ResetType = ResetType;
EntryPtr->BaseInfo.ResetSubtype = ResetSubtype;
EntryPtr->BaseInfo.BootSource = CFE_ES_ResetDataPtr->ResetVars.BootSource;
EntryPtr->BaseInfo.ProcessorResetCount = CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount;
EntryPtr->BaseInfo.MaxProcessorResetCount = CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount;
EntryPtr->BaseInfo.BootSource = CFE_ES_Global.ResetDataPtr->ResetVars.BootSource;
EntryPtr->BaseInfo.ProcessorResetCount = CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount;
EntryPtr->BaseInfo.MaxProcessorResetCount = CFE_ES_Global.ResetDataPtr->ResetVars.MaxProcessorResetCount;

/*
** Copy the ES Reset variables to the log (before they are modified by the log entry).
Expand All @@ -140,7 +140,7 @@ int32 CFE_ES_WriteToERLogWithContext(CFE_ES_LogEntryType_Enum_t EntryType, uint3
/*
** Increment the number of ER log entries made
*/
CFE_ES_ResetDataPtr->ERLogEntries++;
CFE_ES_Global.ResetDataPtr->ERLogEntries++;

/*
* Shared data update is complete
Expand Down Expand Up @@ -188,7 +188,7 @@ bool CFE_ES_BackgroundERLogFileDataGetter(void *Meta, uint32 RecordNum, void **B

if (RecordNum < CFE_PLATFORM_ES_ER_LOG_ENTRIES)
{
EntryPtr = &CFE_ES_ResetDataPtr->ERLog[RecordNum];
EntryPtr = &CFE_ES_Global.ResetDataPtr->ERLog[RecordNum];

/* First wipe the buffer before re-use */
memset(FileBufferPtr, 0, sizeof(*FileBufferPtr));
Expand Down Expand Up @@ -367,25 +367,25 @@ bool CFE_ES_RunExceptionScan(uint32 ElapsedTime, void *Arg)
*/
if (ResetType == 0)
{
if (CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount >=
CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount)
if (CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount >=
CFE_ES_Global.ResetDataPtr->ResetVars.MaxProcessorResetCount)
{
CFE_ES_WriteToSysLog("Maximum Processor Reset count reached (%u)",
(unsigned int)CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount);
(unsigned int)CFE_ES_Global.ResetDataPtr->ResetVars.MaxProcessorResetCount);

ResetType = CFE_PSP_RST_TYPE_POWERON;
}
else
{
CFE_ES_WriteToSysLog("Processor Reset count not reached (%u/%u)",
(unsigned int)CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount,
(unsigned int)CFE_ES_ResetDataPtr->ResetVars.MaxProcessorResetCount);
(unsigned int)CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount,
(unsigned int)CFE_ES_Global.ResetDataPtr->ResetVars.MaxProcessorResetCount);

/*
** Update the reset variables
*/
CFE_ES_ResetDataPtr->ResetVars.ProcessorResetCount++;
CFE_ES_ResetDataPtr->ResetVars.ES_CausedReset = true;
CFE_ES_Global.ResetDataPtr->ResetVars.ProcessorResetCount++;
CFE_ES_Global.ResetDataPtr->ResetVars.ES_CausedReset = true;

ResetType = CFE_PSP_RST_TYPE_PROCESSOR;
}
Expand Down
86 changes: 81 additions & 5 deletions modules/es/fsw/src/cfe_es_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
** Includes
*/
#include "common_types.h"
#include "cfe_es_msg.h"
#include "cfe_es_api_typedefs.h"

#include "cfe_es_erlog_typedef.h"
Expand Down Expand Up @@ -71,6 +72,61 @@ typedef struct
uint32 NumJobsRunning; /**< Current Number of active jobs (updated by background task) */
} CFE_ES_BackgroundTaskState_t;

/*
* Background log dump state structure
*
* This structure is stored in global memory and keeps the state
* of the log dump from one iteration to the next.
*
* NOTE: This is used for log structures which are expected to be small
* enough so such that it is not necessary to throttle the file write or
* spread it over time.
*
* Therefore, the only thing necessary to be stored is whether there
* is a pending write request, and the data file name.
*
* Larger log files, such as the Perf log, must implement a state machine
* with a dedicated state data structure.
*/
typedef struct
{
CFE_FS_FileWriteMetaData_t FileWrite; /**< FS state data - must be first */
CFE_ES_ERLog_FileEntry_t EntryBuffer; /**< Temp holding area for record to write */
} CFE_ES_BackgroundLogDumpGlobal_t;

/*
** Type definition (ES task global data)
*/
typedef struct
{
/*
** ES Task command interface counters
*/
uint8 CommandCounter;
uint8 CommandErrorCounter;

/*
** ES Task housekeeping telemetry
*/
CFE_ES_HousekeepingTlm_t HkPacket;

/*
** Single application telemetry
*/
CFE_ES_OneAppTlm_t OneAppPacket;

/*
** Memory statistics telemetry
*/
CFE_ES_MemStatsTlm_t MemStatsPacket;

/*
** ES Task operational data (not reported in housekeeping)
*/
CFE_SB_PipeId_t CmdPipe;

} CFE_ES_TaskData_t;

/*
** Executive Services Global Memory Data
** This is the regular global data that is not preserved on a
Expand Down Expand Up @@ -143,18 +199,38 @@ typedef struct
CFE_ResourceId_t LastMemPoolId;
CFE_ES_MemPoolRecord_t MemPoolTable[CFE_PLATFORM_ES_MAX_MEMORY_POOLS];

/*
** ES Task initialization data (not reported in housekeeping)
*/
CFE_ES_BackgroundLogDumpGlobal_t BackgroundERLogDumpState;

/*
* Persistent state data associated with performance log data file writes
*/
CFE_ES_PerfDumpGlobal_t BackgroundPerfDumpState;

/*
* Persistent state data associated with background app table scans
*/
CFE_ES_AppTableScanState_t BackgroundAppScanState;

/*
* Task global data (formerly a separate global).
*/
CFE_ES_TaskData_t TaskData;

/*
* Pointer to the Reset data that is preserved on a processor reset
*/
CFE_ES_ResetData_t *ResetDataPtr;

} CFE_ES_Global_t;

/*
** The Executive Services Global Data declaration
*/
extern CFE_ES_Global_t CFE_ES_Global;

/*
** The Executive Services Nonvolatile Data declaration
*/
extern CFE_ES_ResetData_t *CFE_ES_ResetDataPtr;

/*
** Functions used to lock/unlock shared data
*/
Expand Down
Loading