Skip to content

Commit

Permalink
Fix nasa#353, correct PSP module IDs and lookups
Browse files Browse the repository at this point in the history
Correct the CFE_PSP_Module_FindByName and CFE_PSP_Module_GetAPIEntry
lookups to use the correct length of the config data 'PspModuleList'.

The internal variable that had been used reflected the total across
two lists and thus was not a correct limit.

Rather than having these functions search both lists, this instead
keeps it to only exposing the user-specified modules in PspModuleList,
it does not expose the built-in/base modules.  This makes the change
simpler, as typically the built in modules would not be accessed
through these functions at all.
  • Loading branch information
jphickey committed Jul 28, 2022
1 parent 15c2ced commit 95258e3
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions fsw/shared/src/cfe_psp_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,53 @@
#define CFE_PSP_MODULE_INDEX_MASK 0xFFFF
#endif

static uint32 CFE_PSP_ModuleCount = 0;
/*
* Internal/base modules typically should not be the subject
* of a call to CFE_PSP_Module_FindByName or GetAPI,
* so they are assigned IDs at the END of the space,
* this makes them unique but they are otherwise not used
*
* Reserve the last 256 entries for base modules
*/
#define CFE_PSP_INTERNAL_MODULE_BASE ((CFE_PSP_MODULE_BASE | CFE_PSP_MODULE_INDEX_MASK) & ~0xFF)

static uint32 CFE_PSP_ConfigPspModuleListLength = 0;

/***************************************************
* Function Name: CFE_PSP_ModuleInitList
*
* Helper function to initialize a list of modules (not externally called)
* Returns the number of modules initialized
*/
void CFE_PSP_ModuleInitList(CFE_StaticModuleLoadEntry_t *ListPtr)
uint32_t CFE_PSP_ModuleInitList(uint32 BaseId, CFE_StaticModuleLoadEntry_t *ListPtr)
{
CFE_StaticModuleLoadEntry_t *Entry;
CFE_PSP_ModuleApi_t * ApiPtr;
uint32 ModuleCount;
uint32 ModuleId;

/*
* Call the init function for all statically linked modules
*/
Entry = ListPtr;
Entry = ListPtr;
ModuleCount = 0;
if (Entry != NULL)
{
while (Entry->Name != NULL)
{
ApiPtr = (CFE_PSP_ModuleApi_t *)Entry->Api;
ApiPtr = (CFE_PSP_ModuleApi_t *)Entry->Api;
ModuleId = BaseId + ModuleCount;
if ((uint32)ApiPtr->ModuleType != CFE_PSP_MODULE_TYPE_INVALID && ApiPtr->Init != NULL)
{
(*ApiPtr->Init)(CFE_PSP_MODULE_BASE | CFE_PSP_ModuleCount);
printf("CFE_PSP: initializing module \'%s\' with ID %08lx\n", Entry->Name, (unsigned long)ModuleId);
(*ApiPtr->Init)(ModuleId);
}
++Entry;
++CFE_PSP_ModuleCount;
++ModuleCount;
}
}

return ModuleCount;
}

/***************************************************
Expand All @@ -80,10 +98,11 @@ void CFE_PSP_ModuleInitList(CFE_StaticModuleLoadEntry_t *ListPtr)
void CFE_PSP_ModuleInit(void)
{
/* First initialize the fixed set of modules for this PSP */
CFE_PSP_ModuleInitList(CFE_PSP_BASE_MODULE_LIST);
CFE_PSP_ModuleInitList(CFE_PSP_INTERNAL_MODULE_BASE, CFE_PSP_BASE_MODULE_LIST);

/* Then initialize any user-selected extension modules */
CFE_PSP_ModuleInitList(GLOBAL_CONFIGDATA.PspModuleList);
/* Only these modules can be used with CFE_PSP_Module_GetAPIEntry or CFE_PSP_Module_FindByName */
CFE_PSP_ConfigPspModuleListLength = CFE_PSP_ModuleInitList(CFE_PSP_MODULE_BASE, GLOBAL_CONFIGDATA.PspModuleList);
}

/***************************************************
Expand All @@ -100,7 +119,7 @@ int32 CFE_PSP_Module_GetAPIEntry(uint32 PspModuleId, CFE_PSP_ModuleApi_t **API)
if ((PspModuleId & ~CFE_PSP_MODULE_INDEX_MASK) == CFE_PSP_MODULE_BASE)
{
LocalId = PspModuleId & CFE_PSP_MODULE_INDEX_MASK;
if (LocalId < CFE_PSP_ModuleCount)
if (LocalId < CFE_PSP_ConfigPspModuleListLength)
{
*API = (CFE_PSP_ModuleApi_t *)GLOBAL_CONFIGDATA.PspModuleList[LocalId].Api;
Result = CFE_PSP_SUCCESS;
Expand All @@ -124,7 +143,7 @@ int32 CFE_PSP_Module_FindByName(const char *ModuleName, uint32 *PspModuleId)
Entry = GLOBAL_CONFIGDATA.PspModuleList;
Result = CFE_PSP_INVALID_MODULE_NAME;
i = 0;
while (i < CFE_PSP_ModuleCount)
while (i < CFE_PSP_ConfigPspModuleListLength)
{
if (strcmp(Entry->Name, ModuleName) == 0)
{
Expand Down

0 comments on commit 95258e3

Please sign in to comment.