Skip to content

Commit

Permalink
Fix #2174, Move CRC types and convert to enum
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Nov 5, 2022
1 parent 7a220ae commit 561957f
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 51 deletions.
14 changes: 3 additions & 11 deletions cmake/sample_defs/sample_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,15 +258,6 @@
*/
#define CFE_MISSION_EVS_MAX_MESSAGE_LENGTH 122

/** \name Checksum/CRC algorithm identifiers */
/** \{ */
#define CFE_MISSION_ES_CRC_8 1 /**< \brief CRC ( 8 bit additive - returns 32 bit total) (Currently not implemented) */
#define CFE_MISSION_ES_CRC_16 2 /**< \brief CRC (16 bit additive - returns 32 bit total) */
#define CFE_MISSION_ES_CRC_32 \
3 /**< \brief CRC (32 bit additive - returns 32 bit total) (Currently not implemented) \
*/
/** \} */

/**
** \cfeescfg Mission Default CRC algorithm
**
Expand All @@ -276,9 +267,10 @@
** Table Image data integrity values.
**
** \par Limits
** Currently only CFE_MISSION_ES_CRC_16 is supported (see #CFE_MISSION_ES_CRC_16)
** Currently only CFE_ES_CrcType_CRC_16 is supported (see brief in CFE_ES_CrcType_Enum
** definition in cfe_es_api_typedefs.h)
*/
#define CFE_MISSION_ES_DEFAULT_CRC CFE_MISSION_ES_CRC_16
#define CFE_MISSION_ES_DEFAULT_CRC CFE_ES_CrcType_CRC_16

/**
** \cfetblcfg Maximum Table Name Length
Expand Down
16 changes: 10 additions & 6 deletions docs/cFE Application Developers Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1303,14 +1303,18 @@ TypeCRC identifies which of the standard CRC polynomials to be used. Currently,
there are the following types available:
```
CFE_MISSION_ES_CRC_8 – an 8-bit additive checksum calculation that returns a 32-bit value
CFE_MISSION_ES_CRC_16 – a 16-bit additive checksum calculation that returns a 32-bit value
CFE_MISSION_ES_CRC_32 – a 32-bit additive checksum calculation that returns a 32-bit value
CFE_MISSION_ES_DEFAULT_CRC – the mission specified default CRC calculation
CFE_ES_CrcType_CRC_8 – an 8-bit additive checksum calculation that returns a 32-bit value
CFE_ES_CrcType_CRC_16 – a 16-bit additive checksum calculation that returns a 32-bit value
CFE_ES_CrcType_CRC_32 – a 32-bit additive checksum calculation that returns a 32-bit value
CFE_MISSION_ES_DEFAULT_CRC – the mission specified default CRC calculation (currently
this is set to CFE_ES_CrcType_CRC_16 in sample_mission_cfg.h)
```
Unless there is a specific interface with a specified CRC calculation,
Applications must use the CFE_MISSION_ES_DEFAULT_CRC type.
Unless there is a specific interface with a specified CRC calculation, applications
must use the CFE_MISSION_ES_DEFAULT_CRC type.
Currently only CFE_ES_CrcType_CRC_16 is supported. CFE_ES_CrcType_CRC_8 and CFE_ES_CrcType_CRC_32 are yet
to be implemented.
## 5.11 File System Functions
Expand Down
21 changes: 13 additions & 8 deletions modules/cfe_testcase/src/es_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,32 +28,37 @@
*/

#include "cfe_test.h"
#include "cfe_es_api_typedefs.h"

void TestCalculateCRC(void)
{
const char *Data = "Random Stuff";
uint32 inputCrc = 345353;
uint32 Result;
const char * Data = "Random Stuff";
uint32 inputCrc = 345353;
uint32 Result;
CFE_ES_CrcType_Enum_t TypeCrc = CFE_ES_CrcType_CRC_16;

UtPrintf("Testing: CFE_ES_CalculateCRC");

/* CRC is implementation specific, functional just checks that a result is produced and reports */
UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, CFE_MISSION_ES_DEFAULT_CRC));
UtAssert_MIR("Confirm mission default CRC of \"%s\" is %lu", Data, (unsigned long)Result);

UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), inputCrc, CFE_MISSION_ES_CRC_16));
UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), inputCrc, TypeCrc));
UtAssert_MIR("Confirm CRC16 of \"%s\" with input CRC of %lu is %lu", Data, (unsigned long)inputCrc,
(unsigned long)Result);

UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, CFE_MISSION_ES_CRC_8));
TypeCrc = CFE_ES_CrcType_CRC_8;
UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, TypeCrc));
UtAssert_MIR("Confirm CRC8 of \"%s\" is %lu", Data, (unsigned long)Result);

UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, CFE_MISSION_ES_CRC_32));
TypeCrc = CFE_ES_CrcType_CRC_32;
UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, TypeCrc));
UtAssert_MIR("Confirm CRC32 of \"%s\" is %lu", Data, (unsigned long)Result);

/* NULL input or 0 size returns input crc */
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(NULL, sizeof(Data), inputCrc, CFE_MISSION_ES_CRC_16), inputCrc);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(Data, 0, inputCrc, CFE_MISSION_ES_CRC_16), inputCrc);
TypeCrc = CFE_ES_CrcType_CRC_16;
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(NULL, sizeof(Data), inputCrc, TypeCrc), inputCrc);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(Data, 0, inputCrc, TypeCrc), inputCrc);
}

void TestWriteToSysLog(void)
Expand Down
6 changes: 3 additions & 3 deletions modules/core_api/fsw/inc/cfe_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,13 +999,13 @@ CFE_Status_t CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...) OS_PRINTF(1, 2
** a single value. Nominally, the user should set this value to zero.
**
** \param[in] TypeCRC One of the following CRC algorithm selections:
** \arg \c CFE_MISSION_ES_CRC_8 - (Not currently implemented)
** \arg \c CFE_MISSION_ES_CRC_16 - CRC-16/ARC <BR>
** \arg \c CFE_ES_CrcType_CRC_8 - (Not currently implemented)
** \arg \c CFE_ES_CrcType_CRC_16 - CRC-16/ARC <BR>
** Polynomial: 0x8005 <BR>
** Initialization: 0x0000 <BR>
** Reflect Input/Output: true <BR>
** XorOut: 0x0000
** \arg \c CFE_MISSION_ES_CRC_32 - (not currently implemented)
** \arg \c CFE_ES_CrcType_CRC_32 - (not currently implemented)
**
** \return The result of the CRC calculation on the specified memory block.
** If the TypeCRC is unimplemented will return 0.
Expand Down
12 changes: 12 additions & 0 deletions modules/core_api/fsw/inc/cfe_es_api_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ typedef CFE_ES_TaskEntryFuncPtr_t CFE_ES_ChildTaskMainFuncPtr_t;
*/
typedef void *CFE_ES_StackPointer_t; /* aka osal_stackptr_t in proposed OSAL change */

/**
* \brief Checksum/CRC algorithm identifiers
*
* Currently only CFE_ES_CrcType_CRC_16 is supported.
*/
typedef enum CFE_ES_CrcType_Enum
{
CFE_ES_CrcType_CRC_8 = 1, /**< \brief CRC ( 8 bit additive - returns 32 bit total) (Currently not implemented) */
CFE_ES_CrcType_CRC_16, /**< \brief CRC (16 bit additive - returns 32 bit total) */
CFE_ES_CrcType_CRC_32 /**< \brief CRC (32 bit additive - returns 32 bit total) (Currently not implemented) */
} CFE_ES_CrcType_Enum_t;

/**
* \brief Pool Alignment
*
Expand Down
8 changes: 4 additions & 4 deletions modules/es/fsw/src/cfe_es_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1571,7 +1571,7 @@ CFE_Status_t CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...)
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
uint32 CFE_ES_CalculateCRC(const void *DataPtr, size_t DataLength, uint32 InputCRC, uint32 TypeCRC)
uint32 CFE_ES_CalculateCRC(const void *DataPtr, size_t DataLength, uint32 InputCRC, CFE_ES_CrcType_Enum_t TypeCRC)
{
uint32 i;
int16 Index;
Expand Down Expand Up @@ -1610,11 +1610,11 @@ uint32 CFE_ES_CalculateCRC(const void *DataPtr, size_t DataLength, uint32 InputC

switch (TypeCRC)
{
case CFE_MISSION_ES_CRC_32:
case CFE_ES_CrcType_CRC_32:
CFE_ES_WriteToSysLog("%s: Calculate CRC32 not Implemented\n", __func__);
break;

case CFE_MISSION_ES_CRC_16:
case CFE_ES_CrcType_CRC_16:
Crc = (int16)(0xFFFF & InputCRC);
BufPtr = (const uint8 *)DataPtr;

Expand All @@ -1631,7 +1631,7 @@ uint32 CFE_ES_CalculateCRC(const void *DataPtr, size_t DataLength, uint32 InputC
}
break;

case CFE_MISSION_ES_CRC_8:
case CFE_ES_CrcType_CRC_8:
CFE_ES_WriteToSysLog("%s: Calculate CRC8 not Implemented\n", __func__);
break;

Expand Down
43 changes: 24 additions & 19 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -3929,20 +3929,21 @@ void TestPerf(void)

void TestAPI(void)
{
osal_id_t TestObjId;
char AppName[OS_MAX_API_NAME + 12];
char SysLogBuf[CFE_TIME_PRINTED_STRING_SIZE + 20];
uint32 SysLogBufSize;
uint32 StackBuf[8];
uint8 Data[12];
uint32 ResetType;
CFE_ES_AppId_t AppId;
CFE_ES_TaskId_t TaskId;
uint32 RunStatus;
CFE_ES_TaskInfo_t TaskInfo;
CFE_ES_AppInfo_t AppInfo;
CFE_ES_AppRecord_t * UtAppRecPtr;
CFE_ES_TaskRecord_t *UtTaskRecPtr;
osal_id_t TestObjId;
char AppName[OS_MAX_API_NAME + 12];
char SysLogBuf[CFE_TIME_PRINTED_STRING_SIZE + 20];
uint32 SysLogBufSize;
uint32 StackBuf[8];
uint8 Data[12];
uint32 ResetType;
CFE_ES_AppId_t AppId;
CFE_ES_TaskId_t TaskId;
uint32 RunStatus;
CFE_ES_TaskInfo_t TaskInfo;
CFE_ES_AppInfo_t AppInfo;
CFE_ES_AppRecord_t * UtAppRecPtr;
CFE_ES_TaskRecord_t * UtTaskRecPtr;
CFE_ES_CrcType_Enum_t TypeCrc;

UtPrintf("Begin Test API");

Expand Down Expand Up @@ -4384,29 +4385,33 @@ void TestAPI(void)
/* Test calculating a CRC on a range of memory using CRC type 8
* NOTE: This capability is not currently implemented in cFE
*/
TypeCrc = CFE_ES_CrcType_CRC_8;
memset(Data, 1, sizeof(Data));
ES_ResetUnitTest();
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, CFE_MISSION_ES_CRC_8), 0);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, TypeCrc), 0);

/* Test calculating a CRC on a range of memory using CRC type 16 */
TypeCrc = CFE_ES_CrcType_CRC_16;
ES_ResetUnitTest();
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, CFE_MISSION_ES_CRC_16), 2688);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, TypeCrc), 2688);

/* Test calculating a CRC on a range of memory using CRC type 32
* NOTE: This capability is not currently implemented in cFE
*/
TypeCrc = CFE_ES_CrcType_CRC_32;
ES_ResetUnitTest();
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, CFE_MISSION_ES_CRC_32), 0);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, TypeCrc), 0);

/* Test calculating a CRC on a range of memory using an invalid CRC type
*/
ES_ResetUnitTest();
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 12, 345353, -1), 0);

/* Test NULL and zero size */
TypeCrc = CFE_ES_CrcType_CRC_16;
ES_ResetUnitTest();
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(NULL, 12, 345353, CFE_MISSION_ES_CRC_16), 345353);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 0, 345353, CFE_MISSION_ES_CRC_16), 345353);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(NULL, 12, 345353, TypeCrc), 345353);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 0, 345353, TypeCrc), 345353);

/* Test shared mutex take with a take error */
ES_ResetUnitTest();
Expand Down

0 comments on commit 561957f

Please sign in to comment.