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 #943, #924 and #502, improve resource ID management #946

Merged
merged 5 commits into from
Oct 21, 2020
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
750 changes: 402 additions & 348 deletions fsw/cfe-core/src/es/cfe_es_api.c

Large diffs are not rendered by default.

242 changes: 140 additions & 102 deletions fsw/cfe-core/src/es/cfe_es_apps.c

Large diffs are not rendered by default.

14 changes: 1 addition & 13 deletions fsw/cfe-core/src/es/cfe_es_apps.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,6 @@ typedef struct

} CFE_ES_AppStartParams_t;

/*
** CFE_ES_MainTaskInfo_t is a structure of information about the main
** task and child tasks in a cFE application. This structure is just used in the
** cFE_ES_AppRecord_t structure.
*/
typedef struct
{
CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */
char MainTaskName[OS_MAX_API_NAME]; /* The Application's Main Task ID */
} CFE_ES_MainTaskInfo_t;


/*
** CFE_ES_AppRecord_t is an internal structure used to keep track of
** CFE Applications that are active in the system.
Expand All @@ -106,7 +94,7 @@ typedef struct
uint32 Type; /* The type of App: CORE or EXTERNAL */
CFE_ES_AppStartParams_t StartParams; /* The start parameters for an App */
CFE_ES_ControlReq_t ControlReq; /* The Control Request Record for External cFE Apps */
CFE_ES_MainTaskInfo_t TaskInfo; /* Information about the Tasks */
CFE_ES_ResourceID_t MainTaskId; /* The Application's Main Task ID */

} CFE_ES_AppRecord_t;

Expand Down
146 changes: 55 additions & 91 deletions fsw/cfe-core/src/es/cfe_es_cds.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "cfe_es_apps.h"
#include "cfe_es_cds.h"
#include "cfe_es_global.h"
#include "cfe_es_resource.h"
#include "cfe_es_log.h"
#include "cfe_psp.h"
#include "cfe_es_cds_mempool.h"
Expand Down Expand Up @@ -74,6 +75,8 @@ int32 CFE_ES_CDS_EarlyInit(void)
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

CDS->LastCDSBlockId = CFE_ES_ResourceID_FromInteger(CFE_ES_CDSBLOCKID_BASE);

/* Get CDS size from OS BSP */
Status = CFE_PSP_GetCDSSize(&CDS->TotalSize);
if (Status != CFE_PSP_SUCCESS)
Expand Down Expand Up @@ -305,14 +308,20 @@ int32 CFE_ES_CDS_CachePreload(CFE_ES_CDS_AccessCache_t *Cache, const void *Sourc
int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t UserBlockSize, const char *Name, bool CriticalTbl)
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;
int32 Status = CFE_SUCCESS;
int32 RegUpdateStatus = CFE_SUCCESS;
int32 Status;
int32 RegUpdateStatus;
CFE_ES_CDS_RegRec_t *RegRecPtr;
CFE_ES_MemOffset_t BlockOffset;
CFE_ES_MemOffset_t OldBlockSize;
CFE_ES_MemOffset_t NewBlockSize;
bool IsNewEntry = false;
bool IsNewOffset = false;
CFE_ES_ResourceID_t PendingBlockId;
bool IsNewEntry;
bool IsNewOffset;

Status = CFE_SUCCESS;
RegUpdateStatus = CFE_SUCCESS;
IsNewEntry = false;
IsNewOffset = false;

if (UserBlockSize == 0 || UserBlockSize > CDS_ABS_MAX_BLOCK_SIZE)
{
Expand All @@ -324,21 +333,38 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us
/* trying to register CDSs at the same location at the same time */
CFE_ES_LockCDS();

/* Check for duplicate CDS name */
RegRecPtr = CFE_ES_FindCDSInRegistry(Name);

/* If not found then make a new entry */
if (RegRecPtr == NULL)
/*
* Check for an existing entry with the same name.
*/
RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(Name);
if (RegRecPtr != NULL)
{
RegRecPtr = CFE_ES_AllocateNewCDSRegistryEntry();
IsNewEntry = true;
/* in CDS a duplicate name is not necessarily an error, we
* may reuse/resize the existing entry */
PendingBlockId = CFE_ES_CDSBlockRecordGetID(RegRecPtr);
}

if (RegRecPtr == NULL)
else
{
Status = CFE_ES_CDS_REGISTRY_FULL;
/* scan for a free slot */
PendingBlockId = CFE_ES_FindNextAvailableId(CDS->LastCDSBlockId, CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByID(PendingBlockId);

if (RegRecPtr != NULL)
{
/* Fully clear the entry, just in case of stale data */
memset(RegRecPtr, 0, sizeof(*RegRecPtr));
CDS->LastCDSBlockId = PendingBlockId;
IsNewEntry = true;
Status = CFE_SUCCESS;
}
else
{
Status = CFE_ES_NO_RESOURCE_IDS_AVAILABLE;
PendingBlockId = CFE_ES_RESOURCEID_UNDEFINED;
}
}
else

if (RegRecPtr != NULL)
{
/* Account for the extra header which will be added */
NewBlockSize = UserBlockSize;
Expand Down Expand Up @@ -378,43 +404,24 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us
}
}

if (IsNewEntry)
if (Status == CFE_SUCCESS && IsNewEntry)
{
if (Status == CFE_SUCCESS)
{
/* Save flag indicating whether it is a Critical Table or not */
RegRecPtr->Table = CriticalTbl;
/* Save flag indicating whether it is a Critical Table or not */
RegRecPtr->Table = CriticalTbl;

/* Save CDS Name in Registry */
strncpy(RegRecPtr->Name, Name, sizeof(RegRecPtr->Name)-1);
RegRecPtr->Name[sizeof(RegRecPtr->Name)-1] = 0;
}
else
{
/* On failure set it free */
CFE_ES_CDSBlockRecordSetFree(RegRecPtr);
}
/* Save CDS Name in Registry */
strncpy(RegRecPtr->Name, Name, sizeof(RegRecPtr->Name)-1);
RegRecPtr->Name[sizeof(RegRecPtr->Name)-1] = 0;
CFE_ES_CDSBlockRecordSetUsed(RegRecPtr, PendingBlockId);
}

if (IsNewOffset || IsNewEntry)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link #1929

if (Status == CFE_SUCCESS && (IsNewOffset || IsNewEntry))
{
/* If we succeeded at creating a CDS, save updated registry in the CDS */
RegUpdateStatus = CFE_ES_UpdateCDSRegistry();
}
}

/*
* Export handle to caller before unlock
*/
if (Status == CFE_SUCCESS)
{
*HandlePtr = CFE_ES_CDSBlockRecordGetID(RegRecPtr);
}
else
{
*HandlePtr = CFE_ES_RESOURCEID_UNDEFINED;
}

/* Unlock Registry for update */
CFE_ES_UnlockCDS();

Expand Down Expand Up @@ -446,6 +453,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t Us
Status = CFE_ES_CDS_ALREADY_EXISTS;
}

*HandlePtr = PendingBlockId;

return (Status);

Expand Down Expand Up @@ -732,12 +740,12 @@ int32 CFE_ES_UnlockCDS(void)

/*******************************************************************
**
** CFE_ES_FindCDSInRegistry
** CFE_ES_LocateCDSBlockRecordByName
**
** NOTE: For complete prolog information, see 'cfe_es_cds.h'
********************************************************************/

CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName)
CFE_ES_CDS_RegRec_t *CFE_ES_LocateCDSBlockRecordByName(const char *CDSName)
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;
CFE_ES_CDS_RegRec_t *CDSRegRecPtr;
Expand Down Expand Up @@ -768,51 +776,7 @@ CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName)
}

return CDSRegRecPtr;
} /* End of CFE_ES_FindCDSInRegistry() */


/*******************************************************************
**
** CFE_ES_FindFreeCDSRegistryEntry
**
** NOTE: For complete prolog information, see 'cfe_es_cds.h'
********************************************************************/

CFE_ES_CDS_RegRec_t *CFE_ES_AllocateNewCDSRegistryEntry()
{
CFE_ES_CDS_Instance_t *CDS = &CFE_ES_Global.CDSVars;
CFE_ES_CDS_RegRec_t *CDSRegRecPtr;
uint32 NumReg;

CDSRegRecPtr = CDS->Registry;
NumReg = CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES;
while (true)
{
if (NumReg == 0)
{
CDSRegRecPtr = NULL; /* not found */
break;
}

if (!CFE_ES_CDSBlockRecordIsUsed(CDSRegRecPtr))
{
/* Wipe it, just in case of stale data */
memset(CDSRegRecPtr, 0, sizeof(*CDSRegRecPtr));

/* Set the ID which marks it as used */
CFE_ES_CDSBlockRecordSetUsed(CDSRegRecPtr,
CFE_ES_ResourceID_FromInteger(
(CDSRegRecPtr - CDS->Registry)
+ CFE_ES_CDSBLOCKID_BASE));
break;
}

++CDSRegRecPtr;
--NumReg;
}

return CDSRegRecPtr;
} /* End of CFE_ES_FindFreeCDSRegistryEntry() */
} /* End of CFE_ES_LocateCDSBlockRecordByName() */


/*******************************************************************
Expand Down Expand Up @@ -889,7 +853,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices)
CFE_ES_LockCDS();

/* Find CDS name in registry */
RegRecPtr = CFE_ES_FindCDSInRegistry(CDSName);
RegRecPtr = CFE_ES_LocateCDSBlockRecordByName(CDSName);

/* Check to see if CDS is already in the registry */
if (RegRecPtr != NULL)
Expand Down Expand Up @@ -952,7 +916,7 @@ int32 CFE_ES_DeleteCDS(const char *CDSName, bool CalledByTblServices)
}
else /* Error - CDS not in registry */
{
Status = CFE_ES_CDS_NOT_FOUND_ERR;
Status = CFE_ES_ERR_NAME_NOT_FOUND;
}

/* Unlock Registry for future updates */
Expand Down
22 changes: 4 additions & 18 deletions fsw/cfe-core/src/es/cfe_es_cds.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ typedef struct
osal_id_t GenMutex; /**< \brief Mutex that controls access to CDS and registry */
CFE_ES_CDS_Offset_t TotalSize; /**< \brief Total size of the CDS as reported by BSP */
CFE_ES_CDS_Offset_t DataSize; /**< \brief Size of actual user data pool */
CFE_ES_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 @@ -274,7 +275,7 @@ int32 CFE_ES_CDS_CachePreload(CFE_ES_CDS_AccessCache_t *Cache, const void *Sourc
* @param[in] BlockID the ID/handle of the CDS block to retrieve
* @param[out] Idx Output buffer to store the index
* @returns #CFE_SUCCESS if conversion successful. @copydoc CFE_SUCCESS
* #CFE_ES_RESOURCE_ID_INVALID if block ID is outside valid range
* #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);

Expand Down Expand Up @@ -505,7 +506,7 @@ void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceI

/*****************************************************************************/
/**
** \brief Returns the Registry Index for the specified CDS Name
** \brief Returns the Registry Record for the specified CDS Name
**
** \par Description
** Locates given CDS Name in the CDS Registry and
Expand All @@ -520,22 +521,7 @@ void CFE_ES_FormCDSName(char *FullCDSName, const char *CDSName, CFE_ES_ResourceI
** \retval NULL if not found, Non null entry pointer on success
**
******************************************************************************/
CFE_ES_CDS_RegRec_t *CFE_ES_FindCDSInRegistry(const char *CDSName);

/*****************************************************************************/
/**
** \brief Locates a free slot in the CDS Registry and configures it for new use.
**
** \par Description
** Locates a free slot in the CDS Registry, assigns an ID,
** and marks the entry as used.
**
** \par Assumptions, External Events, and Notes:
** Note: This function assumes the registry has been locked.
**
** \retval NULL if registry full, Non null entry pointer on success
******************************************************************************/
CFE_ES_CDS_RegRec_t *CFE_ES_AllocateNewCDSRegistryEntry(void);
CFE_ES_CDS_RegRec_t *CFE_ES_LocateCDSBlockRecordByName(const char *CDSName);

/*****************************************************************************/
/**
Expand Down
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/es/cfe_es_cds_mempool.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSHandle_t Handle, const void *DataToWrite)
}
else
{
Status = CFE_ES_RESOURCE_ID_INVALID;
Status = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}

CFE_ES_UnlockCDS();
Expand Down Expand Up @@ -379,7 +379,7 @@ int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle)
}
else
{
Status = CFE_ES_RESOURCE_ID_INVALID;
Status = CFE_ES_ERR_RESOURCEID_NOT_VALID;
}

CFE_ES_UnlockCDS();
Expand Down
1 change: 1 addition & 0 deletions fsw/cfe-core/src/es/cfe_es_erlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "cfe_es.h"
#include "cfe_es_apps.h"
#include "cfe_es_global.h"
#include "cfe_es_resource.h"
#include "cfe_es_log.h"
#include "cfe_es_task.h"
#include "cfe_psp.h"
Expand Down
Loading