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 Dec 1, 2022
1 parent 7a220ae commit ed4722b
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 37 deletions.
21 changes: 12 additions & 9 deletions cmake/sample_defs/sample_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,14 +258,16 @@
*/
#define CFE_MISSION_EVS_MAX_MESSAGE_LENGTH 122

#ifndef CFE_OMIT_DEPRECATED_6_8
/* These names have been converted to an enum in cfe_es_api_typedefs.h */

/** \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) \
*/
/** \} */

#define CFE_MISSION_ES_CRC_8 CFE_ES_CrcType_CRC_8 /* 1 */
#define CFE_MISSION_ES_CRC_16 CFE_ES_CrcType_CRC_16 /* 2 */
#define CFE_MISSION_ES_CRC_32 CFE_ES_CrcType_CRC_32 /* 3 */

#endif

/**
** \cfeescfg Mission Default CRC algorithm
Expand All @@ -276,9 +278,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
20 changes: 12 additions & 8 deletions docs/cFE Application Developers Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1293,24 +1293,28 @@ an API for a CRC calculation that can be used by all Applications on a mission.
This function looks like the following:

```c
uint32 CFE_ES_CalculateCRC(void *pData, uint32 DataLength, uint32 InputCRC, uint32 TypeCRC);
uint32 CFE_ES_CalculateCRC(const void *DataPtr, size_t DataLength, uint32 InputCRC, CFE_ES_CrcType_Enum_t TypeCRC);
```
where pData points to the first byte of an array of bytes that are to have
where DataPtr points to the first byte of an array of bytes that are to have
the CRC calculated on, DataLength specifies the number of sequential bytes to
include in the calculation, InputCRC is the initial value of the CRC and
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
10 changes: 5 additions & 5 deletions modules/cfe_testcase/src/es_misc_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ void TestCalculateCRC(void)
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, CFE_ES_CrcType_CRC_16));
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));
UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, CFE_ES_CrcType_CRC_8));
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));
UtAssert_VOIDCALL(Result = CFE_ES_CalculateCRC(Data, sizeof(Data), 0, CFE_ES_CrcType_CRC_32));
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);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(NULL, sizeof(Data), inputCrc, CFE_ES_CrcType_CRC_16), inputCrc);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(Data, 0, inputCrc, CFE_ES_CrcType_CRC_16), inputCrc);
}

void TestWriteToSysLog(void)
Expand Down
8 changes: 4 additions & 4 deletions modules/core_api/fsw/inc/cfe_es.h
Original file line number Diff line number Diff line change
Expand Up @@ -999,20 +999,20 @@ 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.
** If DataPtr is null or DataLength is 0, will return InputCRC
**
******************************************************************************/
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);

/*****************************************************************************/
/**
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) (Not currently implemented) */
CFE_ES_CrcType_CRC_16 = 2, /**< \brief CRC (16 bit additive - returns 32 bit total) */
CFE_ES_CrcType_CRC_32 = 3 /**< \brief CRC (32 bit additive - returns 32 bit total) (Not currently implemented) */
} CFE_ES_CrcType_Enum_t;

/**
* \brief Pool Alignment
*
Expand Down
4 changes: 2 additions & 2 deletions modules/core_api/ut-stubs/src/cfe_es_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ void CFE_ES_BackgroundWakeup(void)
* Generated stub function for CFE_ES_CalculateCRC()
* ----------------------------------------------------
*/
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)
{
UT_GenStub_SetupReturnBuffer(CFE_ES_CalculateCRC, uint32);

UT_GenStub_AddParam(CFE_ES_CalculateCRC, const void *, DataPtr);
UT_GenStub_AddParam(CFE_ES_CalculateCRC, size_t, DataLength);
UT_GenStub_AddParam(CFE_ES_CalculateCRC, uint32, InputCRC);
UT_GenStub_AddParam(CFE_ES_CalculateCRC, uint32, TypeCRC);
UT_GenStub_AddParam(CFE_ES_CalculateCRC, CFE_ES_CrcType_Enum_t, TypeCRC);

UT_GenStub_Execute(CFE_ES_CalculateCRC, Basic, NULL);

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
10 changes: 5 additions & 5 deletions modules/es/ut-coverage/es_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -4386,17 +4386,17 @@ void TestAPI(void)
*/
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, CFE_ES_CrcType_CRC_8), 0);

/* Test calculating a CRC on a range of memory using CRC type 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, CFE_ES_CrcType_CRC_16), 2688);

/* Test calculating a CRC on a range of memory using CRC type 32
* NOTE: This capability is not currently implemented in cFE
*/
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, CFE_ES_CrcType_CRC_32), 0);

/* Test calculating a CRC on a range of memory using an invalid CRC type
*/
Expand All @@ -4405,8 +4405,8 @@ void TestAPI(void)

/* Test NULL and zero size */
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, CFE_ES_CrcType_CRC_16), 345353);
UtAssert_UINT32_EQ(CFE_ES_CalculateCRC(&Data, 0, 345353, CFE_ES_CrcType_CRC_16), 345353);

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

0 comments on commit ed4722b

Please sign in to comment.