Skip to content

Commit

Permalink
Fix nasa#1108, split resource id functions into module
Browse files Browse the repository at this point in the history
Move all functions, macros, types, and other definitions
related to resource IDs and generic resource management into
a separate module, like CFE MSG and SBR, etc.

Notably this allows a mission to elect "strict" implementations
of these objects, where every ID type is unique, and assigning
between them (or uint32) results in a compiler error.
  • Loading branch information
jphickey committed Jan 27, 2021
1 parent 4374482 commit 9ea38b6
Show file tree
Hide file tree
Showing 75 changed files with 2,242 additions and 1,357 deletions.
1 change: 1 addition & 0 deletions cmake/mission_defaults.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(MISSION_CORE_MODULES
"psp"
"msg"
"sbr"
"resourceid"
)

# The "MISSION_GLOBAL_APPLIST" is a set of apps/libs that will be built
Expand Down
180 changes: 89 additions & 91 deletions fsw/cfe-core/src/es/cfe_es_api.c

Large diffs are not rendered by default.

130 changes: 66 additions & 64 deletions fsw/cfe-core/src/es/cfe_es_apps.c

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions fsw/cfe-core/src/es/cfe_es_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ typedef struct
*/
typedef struct
{
CFE_ES_ResourceID_t AppId; /* The actual AppID of this entry, or undefined */
CFE_ES_AppId_t AppId; /* The actual AppID of this entry, or undefined */
CFE_ES_AppState_Enum_t AppState; /* Is the app running, or stopped, or waiting? */
CFE_ES_AppType_Enum_t Type; /* The type of App: CORE or EXTERNAL */
CFE_ES_AppStartParams_t StartParams; /* The start parameters for an App */
CFE_ES_ModuleLoadStatus_t ModuleInfo; /* Runtime module information */
CFE_ES_ControlReq_t ControlReq; /* The Control Request Record for External cFE Apps */
CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */
CFE_ES_TaskId_t MainTaskId; /* The Application's Main Task ID */

} CFE_ES_AppRecord_t;

Expand All @@ -146,8 +146,8 @@ typedef struct
*/
typedef struct
{
CFE_ES_ResourceID_t TaskId; /* The actual TaskID of this entry, or undefined */
CFE_ES_ResourceID_t AppId; /* The parent Application's App ID */
CFE_ES_TaskId_t TaskId; /* The actual TaskID of this entry, or undefined */
CFE_ES_AppId_t AppId; /* The parent Application's App ID */
uint32 ExecutionCounter; /* The execution counter for the Child task */
char TaskName[OS_MAX_API_NAME]; /* Task Name */

Expand All @@ -160,7 +160,7 @@ typedef struct
*/
typedef struct
{
CFE_ES_ResourceID_t LibId; /* The actual LibID of this entry, or undefined */
CFE_ES_LibId_t LibId; /* The actual LibID of this entry, or undefined */
CFE_ES_ModuleLoadParams_t BasicInfo; /* Basic (static) information about the module */
CFE_ES_ModuleLoadStatus_t ModuleInfo; /* Runtime information about the module */
} CFE_ES_LibRecord_t;
Expand Down Expand Up @@ -198,7 +198,7 @@ int32 CFE_ES_ParseFileEntry(const char **TokenList, uint32 NumTokens);
** This only loads the code and looks up relevent runtime information.
** It does not start any tasks.
*/
int32 CFE_ES_LoadModule(CFE_ES_ResourceID_t ResourceId, const CFE_ES_ModuleLoadParams_t* LoadParams, CFE_ES_ModuleLoadStatus_t *LoadStatus);
int32 CFE_ES_LoadModule(CFE_ResourceId_t ResourceId, const CFE_ES_ModuleLoadParams_t* LoadParams, CFE_ES_ModuleLoadStatus_t *LoadStatus);

/*
** Internal function to determine the entry point of an app.
Expand All @@ -217,13 +217,13 @@ void CFE_ES_AppEntryPoint(void);
/*
** Internal function to start the main task of an app.
*/
int32 CFE_ES_StartAppTask(const CFE_ES_AppStartParams_t* StartParams, CFE_ES_ResourceID_t RefAppId, CFE_ES_ResourceID_t *TaskIdPtr);
int32 CFE_ES_StartAppTask(const CFE_ES_AppStartParams_t* StartParams, CFE_ES_AppId_t RefAppId, CFE_ES_TaskId_t *TaskIdPtr);

/*
** Internal function to create/start a new cFE app
** based on the parameters passed in
*/
int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr,
int32 CFE_ES_AppCreate(CFE_ES_AppId_t *ApplicationIdPtr,
const char *FileName,
const char *EntryPointName,
const char *AppName,
Expand All @@ -233,7 +233,7 @@ int32 CFE_ES_AppCreate(CFE_ES_ResourceID_t *ApplicationIdPtr,
/*
** Internal function to load a a new cFE shared Library
*/
int32 CFE_ES_LoadLibrary(CFE_ES_ResourceID_t *LibraryIdPtr,
int32 CFE_ES_LoadLibrary(CFE_ES_LibId_t *LibraryIdPtr,
const char *FileName,
const char *EntryPointName,
const char *LibName);
Expand Down Expand Up @@ -267,17 +267,17 @@ bool CFE_ES_RunERLogDump(uint32 ElapsedTime, void *Arg);
/*
** Perform the requested control action for an application
*/
void CFE_ES_ProcessControlRequest(CFE_ES_ResourceID_t AppId);
void CFE_ES_ProcessControlRequest(CFE_ES_AppId_t AppId);

/*
** Clean up all app resources and delete it
*/
int32 CFE_ES_CleanUpApp(CFE_ES_ResourceID_t AppId);
int32 CFE_ES_CleanUpApp(CFE_ES_AppId_t AppId);

/*
** Clean up all Task resources and detete the task
*/
int32 CFE_ES_CleanupTaskResources(CFE_ES_ResourceID_t TaskId);
int32 CFE_ES_CleanupTaskResources(CFE_ES_TaskId_t TaskId);


/*
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/es/cfe_es_backgroundtask.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ void CFE_ES_BackgroundCleanup(void)
CFE_ES_DeleteChildTask(CFE_ES_Global.BackgroundTask.TaskID);
OS_BinSemDelete(CFE_ES_Global.BackgroundTask.WorkSem);

CFE_ES_Global.BackgroundTask.TaskID = CFE_ES_RESOURCEID_UNDEFINED;
CFE_ES_Global.BackgroundTask.TaskID = CFE_ES_TASKID_UNDEFINED;
CFE_ES_Global.BackgroundTask.WorkSem = OS_OBJECT_ID_UNDEFINED;
}

Expand Down
34 changes: 17 additions & 17 deletions fsw/cfe-core/src/es/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ int32 CFE_ES_CDS_EarlyInit(void)
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

CDS->LastCDSBlockId = CFE_ES_ResourceID_FromInteger(CFE_ES_CDSBLOCKID_BASE);
CDS->LastCDSBlockId = CFE_ResourceId_FromInteger(CFE_ES_CDSBLOCKID_BASE);

/* Get CDS size from PSP. Note that the PSP interface
* uses "uint32" for size here. */
Expand Down Expand Up @@ -161,24 +161,24 @@ int32 CFE_ES_CDS_EarlyInit(void)
* NOTE: For complete prolog information, see 'cfe_es_cds.h'
*/
/*******************************************************************/
int32 CFE_ES_CDSBlockID_ToIndex(CFE_ES_ResourceID_t BlockID, uint32 *Idx)
int32 CFE_ES_CDSHandle_ToIndex(CFE_ES_CDSHandle_t BlockID, uint32 *Idx)
{
return CFE_ES_ResourceID_ToIndex(
CFE_ES_ResourceID_ToInteger(BlockID) - CFE_ES_CDSBLOCKID_BASE,
return CFE_ResourceId_ToIndex(CFE_RESOURCEID_UNWRAP(BlockID),
CFE_ES_CDSBLOCKID_BASE,
CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES,
Idx);
}

/*---------------------------------------------------------------------------------------
* Function: CFE_ES_CheckCDSBlockIdSlotUsed
* Function: CFE_ES_CheckCDSHandleSlotUsed
*
* Purpose: Helper function, Aids in allocating a new ID by checking if
* a given ID is available. Must be called while locked.
*---------------------------------------------------------------------------------------
*/
bool CFE_ES_CheckCDSBlockIdSlotUsed(CFE_ES_ResourceID_t CheckId)
bool CFE_ES_CheckCDSHandleSlotUsed(CFE_ResourceId_t CheckId)
{
return CFE_ES_CDSBlockRecordIsUsed(CFE_ES_LocateCDSBlockRecordByID(CheckId));
return CFE_ES_CDSBlockRecordIsUsed(CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHANDLE_C(CheckId)));
}

/*******************************************************************/
Expand All @@ -188,13 +188,13 @@ bool CFE_ES_CheckCDSBlockIdSlotUsed(CFE_ES_ResourceID_t CheckId)
* NOTE: For complete prolog information, see 'cfe_es_cds.h'
*/
/*******************************************************************/
CFE_ES_CDS_RegRec_t* CFE_ES_LocateCDSBlockRecordByID(CFE_ES_ResourceID_t BlockID)
CFE_ES_CDS_RegRec_t* CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHandle_t BlockID)
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;
CFE_ES_CDS_RegRec_t *CDSRegRecPtr;
uint32 Idx;

if (CFE_ES_CDSBlockID_ToIndex(BlockID, &Idx) == CFE_SUCCESS)
if (CFE_ES_CDSHandle_ToIndex(BlockID, &Idx) == CFE_SUCCESS)
{
CDSRegRecPtr = &CDS->Registry[Idx];
}
Expand Down Expand Up @@ -327,7 +327,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, size_t UserBlockSize,
size_t BlockOffset;
size_t OldBlockSize;
size_t NewBlockSize;
CFE_ES_ResourceID_t PendingBlockId;
CFE_ResourceId_t PendingBlockId;
bool IsNewEntry;
bool IsNewOffset;

Expand All @@ -354,13 +354,13 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, size_t UserBlockSize,
{
/* in CDS a duplicate name is not necessarily an error, we
* may reuse/resize the existing entry */
PendingBlockId = CFE_ES_CDSBlockRecordGetID(RegRecPtr);
PendingBlockId = CFE_RESOURCEID_UNWRAP(CFE_ES_CDSBlockRecordGetID(RegRecPtr));
}
else
{
/* scan for a free slot */
PendingBlockId = CFE_ES_FindNextAvailableId(CDS->LastCDSBlockId, CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES, CFE_ES_CheckCDSBlockIdSlotUsed);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByID(PendingBlockId);
PendingBlockId = CFE_ResourceId_FindNext(CDS->LastCDSBlockId, CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES, CFE_ES_CheckCDSHandleSlotUsed);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHANDLE_C(PendingBlockId));

if (RegRecPtr != NULL)
{
Expand All @@ -373,7 +373,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, size_t UserBlockSize,
else
{
Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE;
PendingBlockId = CFE_ES_RESOURCEID_UNDEFINED;
PendingBlockId = CFE_RESOURCEID_UNDEFINED;
}
}

Expand Down Expand Up @@ -466,7 +466,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, size_t UserBlockSize,
Status = CFE_ES_CDS_ALREADY_EXISTS;
}

*HandlePtr = PendingBlockId;
*HandlePtr = CFE_ES_CDSHANDLE_C(PendingBlockId);

return (Status);

Expand Down Expand Up @@ -677,7 +677,7 @@ int32 CFE_ES_UpdateCDSRegistry(void)
** NOTE: For complete prolog information, see 'cfe_es_cds.h'
********************************************************************/

void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceID_t ThisAppId)
void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_AppId_t ThisAppId)
{
char AppName[OS_MAX_API_NAME];

Expand Down Expand Up @@ -854,7 +854,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices)
int32 Status;
CFE_ES_CDS_RegRec_t *RegRecPtr;
char OwnerName[OS_MAX_API_NAME];
CFE_ES_ResourceID_t AppId;
CFE_ES_AppId_t AppId;
uint32 i;
char LogMessage[CFE_ES_MAX_SYSLOG_MSG_SIZE];
size_t OldBlockSize;
Expand Down
28 changes: 14 additions & 14 deletions fsw/cfe-core/src/es/cfe_es_cds.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ typedef struct
* which has a CRC, and therefore the actual user data size is
* less than this.
*/
CFE_ES_ResourceID_t BlockID; /**< Abstract ID associated with this CDS block */
CFE_ES_CDSHandle_t BlockID; /**< Abstract ID associated with this CDS block */
size_t BlockOffset; /**< Start offset of the block in CDS memory */
size_t BlockSize; /**< Size, in bytes, of the CDS memory block */
char Name[CFE_MISSION_ES_CDS_MAX_FULL_NAME_LEN];
Expand Down Expand Up @@ -173,7 +173,7 @@ typedef struct
osal_id_t GenMutex; /**< \brief Mutex that controls access to CDS and registry */
size_t TotalSize; /**< \brief Total size of the CDS as reported by BSP */
size_t DataSize; /**< \brief Size of actual user data pool */
CFE_ES_ResourceID_t LastCDSBlockId; /**< \brief Last issued CDS block ID */
CFE_ResourceId_t LastCDSBlockId; /**< \brief Last issued CDS block ID */
CFE_ES_CDS_RegRec_t Registry[CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES]; /**< \brief CDS Registry (Local Copy) */
} CFE_ES_CDS_Instance_t;

Expand Down Expand Up @@ -280,7 +280,7 @@ int32 CFE_ES_CDS_CachePreload(CFE_ES_CDS_AccessCache_t *Cache, const void *Sourc
* @returns #CFE_SUCCESS if conversion successful. @copydoc CFE_SUCCESS
* #CFE_ES_ERR_RESOURCEID_NOT_VALID if block ID is outside valid range
*/
int32 CFE_ES_CDSBlockID_ToIndex(CFE_ES_ResourceID_t BlockID, uint32 *Idx);
int32 CFE_ES_CDSHandle_ToIndex(CFE_ES_CDSHandle_t BlockID, uint32 *Idx);

/**
* @brief Get a registry record within the CDS, given a block ID/handle
Expand All @@ -295,7 +295,7 @@ int32 CFE_ES_CDSBlockID_ToIndex(CFE_ES_ResourceID_t BlockID, uint32 *Idx);
* @param[in] BlockID the ID/handle of the CDS block to retrieve
* @returns Pointer to registry record, or NULL if ID/handle invalid.
*/
CFE_ES_CDS_RegRec_t* CFE_ES_LocateCDSBlockRecordByID(CFE_ES_ResourceID_t BlockID);
CFE_ES_CDS_RegRec_t* CFE_ES_LocateCDSBlockRecordByID(CFE_ES_CDSHandle_t BlockID);

/**
* @brief Check if a Memory Pool record is in use or free/empty
Expand All @@ -310,7 +310,7 @@ CFE_ES_CDS_RegRec_t* CFE_ES_LocateCDSBlockRecordByID(CFE_ES_ResourceID_t BlockID
*/
static inline bool CFE_ES_CDSBlockRecordIsUsed(const CFE_ES_CDS_RegRec_t *CDSBlockRecPtr)
{
return CFE_ES_ResourceID_IsDefined(CDSBlockRecPtr->BlockID);
return CFE_RESOURCEID_TEST_DEFINED(CDSBlockRecPtr->BlockID);
}

/**
Expand All @@ -321,7 +321,7 @@ static inline bool CFE_ES_CDSBlockRecordIsUsed(const CFE_ES_CDS_RegRec_t *CDSBlo
* @param[in] CDSBlockRecPtr pointer to Pool table entry
* @returns BlockID of entry
*/
static inline CFE_ES_ResourceID_t CFE_ES_CDSBlockRecordGetID(const CFE_ES_CDS_RegRec_t *CDSBlockRecPtr)
static inline CFE_ES_CDSHandle_t CFE_ES_CDSBlockRecordGetID(const CFE_ES_CDS_RegRec_t *CDSBlockRecPtr)
{
return (CDSBlockRecPtr->BlockID);
}
Expand All @@ -335,9 +335,9 @@ static inline CFE_ES_ResourceID_t CFE_ES_CDSBlockRecordGetID(const CFE_ES_CDS_Re
* @param[in] CDSBlockRecPtr pointer to Pool table entry
* @param[in] BlockID the Pool ID of this entry
*/
static inline void CFE_ES_CDSBlockRecordSetUsed(CFE_ES_CDS_RegRec_t *CDSBlockRecPtr, CFE_ES_ResourceID_t BlockID)
static inline void CFE_ES_CDSBlockRecordSetUsed(CFE_ES_CDS_RegRec_t *CDSBlockRecPtr, CFE_ResourceId_t PendingId)
{
CDSBlockRecPtr->BlockID = BlockID;
CDSBlockRecPtr->BlockID = CFE_ES_CDSHANDLE_C(PendingId);
}

/**
Expand All @@ -350,7 +350,7 @@ static inline void CFE_ES_CDSBlockRecordSetUsed(CFE_ES_CDS_RegRec_t *CDSBlockRec
*/
static inline void CFE_ES_CDSBlockRecordSetFree(CFE_ES_CDS_RegRec_t *CDSBlockRecPtr)
{
CDSBlockRecPtr->BlockID = CFE_ES_RESOURCEID_UNDEFINED;
CDSBlockRecPtr->BlockID = CFE_ES_CDS_BAD_HANDLE;
}

/**
Expand All @@ -366,9 +366,9 @@ static inline void CFE_ES_CDSBlockRecordSetFree(CFE_ES_CDS_RegRec_t *CDSBlockRec
* @param[in] BlockID expected block ID
* @returns true if the entry matches the given block ID
*/
static inline bool CFE_ES_CDSBlockRecordIsMatch(const CFE_ES_CDS_RegRec_t *CDSBlockRecPtr, CFE_ES_ResourceID_t BlockID)
static inline bool CFE_ES_CDSBlockRecordIsMatch(const CFE_ES_CDS_RegRec_t *CDSBlockRecPtr, CFE_ES_CDSHandle_t BlockID)
{
return (CDSBlockRecPtr != NULL && CFE_ES_ResourceID_Equal(CDSBlockRecPtr->BlockID, BlockID));
return (CDSBlockRecPtr != NULL && CFE_RESOURCEID_TEST_EQUAL(CDSBlockRecPtr->BlockID, BlockID));
}

/**
Expand Down Expand Up @@ -396,15 +396,15 @@ static inline size_t CFE_ES_CDSBlockRecordGetUserSize(const CFE_ES_CDS_RegRec_t
*
* Checks if a table slot is available for a potential new ID
* This is a helper function intended to be used with
* CFE_ES_FindNextAvailableID() for allocating new IDs
* CFE_ResourceId_FindNext() for allocating new IDs
*
* As this dereferences fields within the record, global data must be
* locked prior to invoking this function.
*
* @param[in] CheckId pending/candidate Block ID to check
* @returns true if the table slot for the ID is occupied, false if available
*/
bool CFE_ES_CheckCDSBlockIdSlotUsed(CFE_ES_ResourceID_t CheckId);
bool CFE_ES_CheckCDSHandleSlotUsed(CFE_ResourceId_t CheckId);

/*****************************************************************************/
/**
Expand Down Expand Up @@ -519,7 +519,7 @@ int32 CFE_ES_UpdateCDSRegistry(void);
**
**
******************************************************************************/
void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceID_t ThisAppId);
void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_AppId_t ThisAppId);

/*****************************************************************************/
/**
Expand Down
6 changes: 3 additions & 3 deletions fsw/cfe-core/src/es/cfe_es_erlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
*/
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 CFE_ES_WriteToERLogWithContext( CFE_ES_LogEntryType_Enum_t EntryType, uint32 ResetType, uint32 ResetSubtype,
const char *Description, CFE_ES_ResourceID_t AppId, uint32 PspContextId)
const char *Description, CFE_ES_AppId_t AppId, uint32 PspContextId)
{
uint32 LogIdx;
CFE_ES_ERLog_MetaData_t *EntryPtr;
Expand Down Expand Up @@ -176,7 +176,7 @@ int32 CFE_ES_WriteToERLog( CFE_ES_LogEntryType_Enum_t EntryType, uint32 Reset
{
/* passing 0xFFFFFFFF as the appid avoids confusion with actual appid 0 */
return CFE_ES_WriteToERLogWithContext(EntryType, ResetType, ResetSubtype,
Description, CFE_ES_RESOURCEID_UNDEFINED, CFE_ES_ERLOG_NO_CONTEXT);
Description, CFE_ES_APPID_UNDEFINED, CFE_ES_ERLOG_NO_CONTEXT);

} /* End of CFE_ES_WriteToERLog() */

Expand Down Expand Up @@ -359,7 +359,7 @@ bool CFE_ES_RunExceptionScan(uint32 ElapsedTime, void *Arg)
*/
if (OS_ObjectIdDefined(ExceptionTaskID))
{
Status = CFE_ES_GetTaskInfo( &EsTaskInfo, CFE_ES_ResourceID_FromOSAL(ExceptionTaskID) );
Status = CFE_ES_GetTaskInfo( &EsTaskInfo, CFE_ES_TaskId_FromOSAL(ExceptionTaskID) );

/*
* The App ID was found, now see if the ExceptionAction is set for a reset
Expand Down
Loading

0 comments on commit 9ea38b6

Please sign in to comment.