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 #56, Refactor CDS to use generic pool implementation #939

Merged
Merged
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
34 changes: 13 additions & 21 deletions fsw/cfe-core/src/es/cfe_es_api.c
Original file line number Diff line number Diff line change
@@ -1397,7 +1397,7 @@ uint32 CFE_ES_CalculateCRC(const void *DataPtr, uint32 DataLength, uint32 InputC
** Purpose: Allocate a data block for a Critical Data Store.
**
*/
int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, const char *Name)
int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, CFE_ES_CDS_Offset_t BlockSize, const char *Name)
{
int32 Status;
size_t NameLen = 0;
@@ -1406,14 +1406,17 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons
char AppName[OS_MAX_API_NAME] = {"UNKNOWN"};
char CDSName[CFE_ES_CDS_MAX_FULL_NAME_LEN] = {""};

/* Initialize output to safe value, in case this fails */
*CDSHandlePtr = CFE_ES_RESOURCEID_UNDEFINED;

/* Check to make sure calling application is legit */
Status = CFE_ES_GetAppID(&ThisAppId);

if ( Status != CFE_SUCCESS ) /* Application ID was invalid */
{
CFE_ES_WriteToSysLog("CFE_CDS:Register-Bad AppId context\n");
}
else if (CFE_ES_Global.CDSVars.MemPoolSize == 0)
else if (!CFE_ES_Global.CDSIsAvailable)
{
CFE_ES_WriteToSysLog("CFE_CDS:Register-CDS not available\n");
Status = CFE_ES_NOT_IMPLEMENTED;
@@ -1441,16 +1444,13 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons
/* of the form "AppName.Name" */
CFE_ES_FormCDSName(CDSName, Name, ThisAppId);

/* Make sure the specified size is acceptable */
if (BlockSize == 0)
{
Status = CFE_ES_CDS_INVALID_SIZE;
CFE_ES_WriteToSysLog("CFE_CDS:Register-CDS %s has size of zero\n", Name);
}
else
/* Create CDS and designate it as NOT being a Critical Table */
Status = CFE_ES_RegisterCDSEx(CDSHandlePtr, BlockSize, CDSName, false);

/* If size is unacceptable, log it */
if (Status == CFE_ES_CDS_INVALID_SIZE)
{
/* Create CDS and designate it as NOT being a Critical Table */
Status = CFE_ES_RegisterCDSEx(CDSHandlePtr, BlockSize, CDSName, false);
CFE_ES_WriteToSysLog("CFE_CDS:Register-CDS %s has invalid size (%lu)\n", Name, (unsigned long)BlockSize);
}
}
}
@@ -1479,11 +1479,7 @@ int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *CDSHandlePtr, int32 BlockSize, cons
*/
int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
{
int32 Status;

Status = CFE_ES_CDSBlockWrite(CFE_ES_Global.CDSVars.Registry[Handle].MemHandle, DataToCopy);

return Status;
return CFE_ES_CDSBlockWrite(Handle, DataToCopy);
} /* End of CFE_ES_CopyToCDS() */

/*
@@ -1494,11 +1490,7 @@ int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
*/
int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle)
{
int32 Status;

Status = CFE_ES_CDSBlockRead(RestoreToMemory, CFE_ES_Global.CDSVars.Registry[Handle].MemHandle);

return Status;
return CFE_ES_CDSBlockRead(RestoreToMemory, Handle);
} /* End of CFE_ES_RestoreFromCDS() */

/* end of file */
949 changes: 548 additions & 401 deletions fsw/cfe-core/src/es/cfe_es_cds.c

Large diffs are not rendered by default.

461 changes: 423 additions & 38 deletions fsw/cfe-core/src/es/cfe_es_cds.h

Large diffs are not rendered by default.

662 changes: 188 additions & 474 deletions fsw/cfe-core/src/es/cfe_es_cds_mempool.c

Large diffs are not rendered by default.

60 changes: 5 additions & 55 deletions fsw/cfe-core/src/es/cfe_es_cds_mempool.h
Original file line number Diff line number Diff line change
@@ -42,59 +42,13 @@
** Include Files
*/
#include "private/cfe_private.h"
#include "cfe_es_cds.h"

/*
** Macro Definitions
*/
#define CFE_ES_CDS_NUM_BLOCK_SIZES 17

/*
** Type Definitions
*/

typedef uint32 CFE_ES_CDSBlockHandle_t;

typedef struct
{
uint16 CheckBits;
uint16 AllocatedFlag;
uint32 SizeUsed;
uint32 ActualSize;
uint32 CRC;
uint32 Next;
} CFE_ES_CDSBlockDesc_t;

typedef struct
{
uint32 Top;
uint32 NumCreated;
uint32 MaxSize;
} CFE_ES_CDSBlockSizeDesc_t;
/*
** Memory Pool Type
*/
typedef struct {
uint32 Start;
uint32 Size;
uint32 End;
uint32 Current;
int32 SizeIndex;
uint16 CheckErrCntr;
uint16 RequestCntr;
osal_id_t MutexId;
uint32 MinBlockSize;
CFE_ES_CDSBlockSizeDesc_t SizeDesc[CFE_ES_CDS_NUM_BLOCK_SIZES];
} CFE_ES_CDSPool_t;

/*
* External variables
*
* Note - these globals should not be modified outside of this module,
* however the unit test code does tweak them directly in order to test specific code paths
*/
extern CFE_ES_CDSPool_t CFE_ES_CDSMemPool;
extern CFE_ES_CDSBlockDesc_t CFE_ES_CDSBlockDesc;


/*****************************************************************************/
/*
@@ -115,18 +69,14 @@ extern CFE_ES_CDSBlockDesc_t CFE_ES_CDSBlockDesc;
** \return #CFE_SUCCESS \copydoc CFE_SUCCESS
**
******************************************************************************/
int32 CFE_ES_CreateCDSPool(uint32 CDSPoolSize, uint32 StartOffset);


int32 CFE_ES_RebuildCDSPool(uint32 CDSPoolSize, uint32 StartOffset);
int32 CFE_ES_CreateCDSPool(CFE_ES_CDS_Offset_t CDSPoolSize, CFE_ES_CDS_Offset_t StartOffset);

int32 CFE_ES_GetCDSBlock(CFE_ES_CDSBlockHandle_t *BlockHandle, uint32 BlockSize);

int32 CFE_ES_PutCDSBlock(CFE_ES_CDSBlockHandle_t BlockHandle);
int32 CFE_ES_RebuildCDSPool(CFE_ES_CDS_Offset_t CDSPoolSize, CFE_ES_CDS_Offset_t StartOffset);

int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSBlockHandle_t BlockHandle, void *DataToWrite);
int32 CFE_ES_CDSBlockWrite(CFE_ES_CDSHandle_t Handle, const void *DataToWrite);

int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSBlockHandle_t BlockHandle);
int32 CFE_ES_CDSBlockRead(void *DataRead, CFE_ES_CDSHandle_t Handle);

uint32 CFE_ES_CDSReqdMinSize(uint32 MaxNumBlocksToSupport);

5 changes: 4 additions & 1 deletion fsw/cfe-core/src/es/cfe_es_global.h
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@
#include "cfe_es_perf.h"
#include "cfe_es_generic_pool.h"
#include "cfe_es_mempool.h"
#include "cfe_es_cds_mempool.h"
#include "cfe_time.h"
#include "cfe_platform_cfg.h"
#include "cfe_evs.h"
@@ -75,6 +76,7 @@
#define CFE_ES_LIBID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+2) << CFE_ES_RESOURCEID_SHIFT))
#define CFE_ES_COUNTID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+3) << CFE_ES_RESOURCEID_SHIFT))
#define CFE_ES_POOLID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+4) << CFE_ES_RESOURCEID_SHIFT))
#define CFE_ES_CDSBLOCKID_BASE (CFE_ES_RESOURCEID_MARK | ((OS_OBJECT_TYPE_USER+5) << CFE_ES_RESOURCEID_SHIFT))

/*
** Typedefs
@@ -156,7 +158,8 @@ typedef struct
/*
** Critical Data Store Management Variables
*/
CFE_ES_CDSVariables_t CDSVars;
CFE_ES_CDS_Instance_t CDSVars;
bool CDSIsAvailable; /**< \brief Whether or not the CDS service is active/valid */

/*
* Background task for handling long-running, non real time tasks
13 changes: 6 additions & 7 deletions fsw/cfe-core/src/es/cfe_es_task.c
Original file line number Diff line number Diff line change
@@ -1820,17 +1820,15 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistry_t *data)
if (Status == sizeof(CFE_FS_Header_t))
{
Status = sizeof(CFE_ES_CDSRegDumpRec_t);
RegRecPtr = CFE_ES_Global.CDSVars.Registry;
while ((RegIndex < CFE_PLATFORM_ES_CDS_MAX_NUM_ENTRIES) && (Status == sizeof(CFE_ES_CDSRegDumpRec_t)))
{
/* Make a pointer to simplify code look and to remove redundant indexing into registry */
RegRecPtr = &CFE_ES_Global.CDSVars.Registry[RegIndex];

/* Check to see if the Registry entry is empty */
if (RegRecPtr->Taken == true)
if ( CFE_ES_CDSBlockRecordIsUsed(RegRecPtr) )
{
/* Fill CDS Registry Dump Record with relevant information */
DumpRecord.Size = RegRecPtr->Size;
DumpRecord.Handle = RegRecPtr->MemHandle;
DumpRecord.Size = CFE_ES_CDSBlockRecordGetUserSize(RegRecPtr);
DumpRecord.Handle = CFE_ES_CDSBlockRecordGetID(RegRecPtr);
DumpRecord.Table = RegRecPtr->Table;
DumpRecord.ByteAlignSpare1 = 0;

@@ -1848,7 +1846,8 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistry_t *data)
}

/* Look at the next entry in the Registry */
RegIndex++;
++RegIndex;
++RegRecPtr;
}

if (Status == sizeof(CFE_ES_CDSRegDumpRec_t))
3 changes: 2 additions & 1 deletion fsw/cfe-core/src/inc/cfe_error.h
Original file line number Diff line number Diff line change
@@ -412,7 +412,8 @@ typedef int32 CFE_Status_t;
/**
* @brief CDS Invalid Size
*
* The Application is requesting a CDS Block with a size of zero.
* The Application is requesting a CDS Block or Pool with a size
* beyond the applicable limits, either too large or too small/zero.
*
*/
#define CFE_ES_CDS_INVALID_SIZE ((int32)0xc4000010)
21 changes: 18 additions & 3 deletions fsw/cfe-core/src/inc/cfe_es.h
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@
** NOTE: "+2" is for NULL Character and "." (i.e. - "AppName.CDSName") */
#define CFE_ES_CDS_MAX_FULL_NAME_LEN (CFE_MISSION_ES_CDS_MAX_NAME_LENGTH + CFE_MISSION_MAX_API_LEN + 2)

#define CFE_ES_CDS_BAD_HANDLE (CFE_ES_CDSHandle_t) 0xFFFF
#define CFE_ES_CDS_BAD_HANDLE CFE_ES_RESOURCEID_UNDEFINED
/** \} */

#define CFE_ES_NO_MUTEX 0 /**< \brief Indicates that the memory pool selection will not use a semaphore */
@@ -409,7 +409,22 @@ typedef struct CFE_ES_MemPoolStats
*
* Data type used to hold Handles of Critical Data Stores. See #CFE_ES_RegisterCDS
*/
typedef cpuaddr CFE_ES_CDSHandle_t;
typedef CFE_ES_ResourceID_t CFE_ES_CDSHandle_t;

/**
* Type used for CDS sizes and offsets.
*
* This must match the type used in the PSP CDS API, e.g.:
* CFE_PSP_GetCDSSize()
* CFE_PSP_WriteToCDS()
* CFE_PSP_ReadFromCDS()
*
* It is defined separately from the CFE_ES_MemOffset_t as the type used in
* the PSP CDS access API may be different than the ES Pool API.
*
* In either case this _must_ be an unsigned type.
*/
typedef uint32 CFE_ES_CDS_Offset_t;

/**
* \brief CDS Register Dump Record
@@ -1157,7 +1172,7 @@ void CFE_ES_ProcessAsyncEvent(void);
** \sa #CFE_ES_CopyToCDS, #CFE_ES_RestoreFromCDS
**
******************************************************************************/
CFE_Status_t CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *HandlePtr, int32 BlockSize, const char *Name);
CFE_Status_t CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t BlockSize, const char *Name);

/*****************************************************************************/
/**
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/inc/private/cfe_private.h
Original file line number Diff line number Diff line change
@@ -292,7 +292,7 @@ extern int32 CFE_TIME_CleanUpApp(CFE_ES_ResourceID_t AppId);
**
** \param[in, out] HandlePtr Pointer Application's variable that will contain the CDS Memory Block Handle. *HandlePtr is the handle of the CDS block that can be used in #CFE_ES_CopyToCDS and #CFE_ES_RestoreFromCDS.
**
** \param[in] BlockSize The number of bytes needed in the CDS.
** \param[in] UserBlockSize The number of bytes needed in the CDS.
**
** \param[in] Name Pointer to character string containing the Application's local name for
** the CDS.
@@ -303,7 +303,7 @@ extern int32 CFE_TIME_CleanUpApp(CFE_ES_ResourceID_t AppId);
** \return See return codes for #CFE_ES_RegisterCDS
**
******************************************************************************/
int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, int32 BlockSize, const char *Name, bool CriticalTbl);
int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t UserBlockSize, const char *Name, bool CriticalTbl);

/*****************************************************************************/
/**
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/tbl/cfe_tbl_internal.c
Original file line number Diff line number Diff line change
@@ -1431,7 +1431,7 @@ void CFE_TBL_FindCriticalTblInfo(CFE_TBL_CritRegRec_t **CritRegRecPtr, CFE_ES_CD

for (i=0; i<CFE_PLATFORM_TBL_MAX_CRITICAL_TABLES; i++)
{
if (CFE_TBL_TaskData.CritReg[i].CDSHandle == CDSHandleToFind)
if ( CFE_ES_ResourceID_Equal(CFE_TBL_TaskData.CritReg[i].CDSHandle, CDSHandleToFind) )
{
*CritRegRecPtr = &CFE_TBL_TaskData.CritReg[i];
break;
887 changes: 396 additions & 491 deletions fsw/cfe-core/unit-test/es_UT.c

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion fsw/cfe-core/unit-test/es_UT.h
Original file line number Diff line number Diff line change
@@ -280,7 +280,7 @@ void TestAPI(void);
** \sa #UT_SetBSPFail, #CFE_ES_RebuildCDS, #UT_SetRtnCode
** \sa #CFE_ES_InitCDSRegistry, #UT_SetCDSSize, #CFE_ES_CDS_EarlyInit
** \sa #UT_SetCDSBSPCheckValidity, #CFE_ES_ValidateCDS, #UT_SetCDSReadGoodEnd
** \sa #CFE_ES_InitializeCDS, #CFE_ES_RebuildCDS, #CFE_ES_DeleteCDS
** \sa #CFE_ES_InitCDSSignatures, #CFE_ES_RebuildCDS, #CFE_ES_DeleteCDS
**
******************************************************************************/
void TestCDS(void);
6 changes: 3 additions & 3 deletions fsw/cfe-core/unit-test/tbl_UT.c
Original file line number Diff line number Diff line change
@@ -2257,7 +2257,7 @@ void Test_CFE_TBL_Register(void)
/* a. Perform test */
for (i = 0; i < CFE_PLATFORM_TBL_MAX_CRITICAL_TABLES; i++)
{
CFE_TBL_TaskData.CritReg[i].CDSHandle = 1;
CFE_TBL_TaskData.CritReg[i].CDSHandle = CFE_ES_RESOURCEID_UNDEFINED;
}

RtnCode = CFE_TBL_Register(&TblHandle1, "UT_Table1",
@@ -4771,9 +4771,9 @@ void Test_CFE_TBL_Internal(void)

for (i = 0; i < CFE_PLATFORM_TBL_MAX_CRITICAL_TABLES; i++)
{
if (CFE_TBL_TaskData.CritReg[i].CDSHandle == RegRecPtr->CDSHandle)
if ( CFE_ES_ResourceID_Equal(CFE_TBL_TaskData.CritReg[i].CDSHandle, RegRecPtr->CDSHandle) )
{
CFE_TBL_TaskData.CritReg[i].CDSHandle = CFE_ES_CDS_BAD_HANDLE - 1;
CFE_TBL_TaskData.CritReg[i].CDSHandle = CFE_ES_RESOURCEID_RESERVED;
}
}

14 changes: 10 additions & 4 deletions fsw/cfe-core/ut-stubs/ut_es_stubs.c
Original file line number Diff line number Diff line change
@@ -71,6 +71,12 @@
*/
#define CFE_UT_ES_DEFAULT_TASKID ((CFE_ES_ResourceID_t){0x02020001})

/*
* Default value to return from calls that output a CDS ID, if the
* test case does not provide a value
*/
#define CFE_UT_ES_DEFAULT_CDSID ((CFE_ES_ResourceID_t){0x02050001})

/*
* Invalid value to output from calls as resource ID for the
* calls that return failure. If subsequently used by application code,
@@ -884,7 +890,7 @@ int32 CFE_ES_CopyToCDS(CFE_ES_CDSHandle_t Handle, void *DataToCopy)
int32 status;
uint32 CdsBufferSize;

UT_Stub_RegisterContext(UT_KEY(CFE_ES_CopyToCDS), (void*)Handle);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_ES_CopyToCDS), Handle);
UT_Stub_RegisterContext(UT_KEY(CFE_ES_CopyToCDS), DataToCopy);
status = UT_DEFAULT_IMPL(CFE_ES_CopyToCDS);

@@ -927,7 +933,7 @@ int32 CFE_ES_RestoreFromCDS(void *RestoreToMemory, CFE_ES_CDSHandle_t Handle)
uint32 CdsBufferSize;

UT_Stub_RegisterContext(UT_KEY(CFE_ES_RestoreFromCDS), RestoreToMemory);
UT_Stub_RegisterContext(UT_KEY(CFE_ES_RestoreFromCDS), (void*)Handle);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_ES_RestoreFromCDS), Handle);
status = UT_DEFAULT_IMPL(CFE_ES_RestoreFromCDS);

if (status >= 0)
@@ -976,7 +982,7 @@ int32 CFE_ES_RegisterCDSEx(CFE_ES_CDSHandle_t *HandlePtr,
{
if (UT_Stub_CopyToLocal(UT_KEY(CFE_ES_RegisterCDSEx), (uint8*)HandlePtr, sizeof(*HandlePtr)) < sizeof(*HandlePtr))
{
*HandlePtr = 1;
*HandlePtr = CFE_UT_ES_DEFAULT_CDSID;
}
}

@@ -1105,7 +1111,7 @@ bool CFE_ES_RunLoop(uint32 *ExitStatus)
return UT_DEFAULT_IMPL(CFE_ES_RunLoop) != 0;
}

int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *HandlePtr, int32 BlockSize, const char *Name)
int32 CFE_ES_RegisterCDS(CFE_ES_CDSHandle_t *HandlePtr, CFE_ES_CDS_Offset_t BlockSize, const char *Name)
{
UT_Stub_RegisterContext(UT_KEY(CFE_ES_RegisterCDS), HandlePtr);
UT_Stub_RegisterContextGenericArg(UT_KEY(CFE_ES_RegisterCDS), BlockSize);