Skip to content

Commit

Permalink
Fix nasa#1514, Use XOR to swap between ping-pong buffers (style change
Browse files Browse the repository at this point in the history
only)
  • Loading branch information
thnkslprpt committed May 25, 2023
1 parent b429d91 commit 283aa6c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/tbl/fsw/src/cfe_tbl_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,12 +1156,12 @@ CFE_Status_t CFE_TBL_Validate(CFE_TBL_Handle_t TblHandle)
{
/* Call the Application's Validation function for the Inactive Buffer */
Status =
(RegRecPtr->ValidationFuncPtr)(RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr);
(RegRecPtr->ValidationFuncPtr)(RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr);

/* Allow buffer to be activated after passing validation */
if (Status == CFE_SUCCESS)
{
RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].Validated = true;
RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].Validated = true;
}
}
else
Expand Down
4 changes: 2 additions & 2 deletions modules/tbl/fsw/src/cfe_tbl_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ int32 CFE_TBL_GetWorkingBuffer(CFE_TBL_LoadBuff_t **WorkingBufferPtr, CFE_TBL_Re
{
if (RegRecPtr->DoubleBuffered)
{
*WorkingBufferPtr = &RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)];
*WorkingBufferPtr = &RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)];
}
else
{
Expand Down Expand Up @@ -684,7 +684,7 @@ int32 CFE_TBL_GetWorkingBuffer(CFE_TBL_LoadBuff_t **WorkingBufferPtr, CFE_TBL_Re
if (RegRecPtr->DoubleBuffered)
{
/* Determine the index of the Inactive Buffer Pointer */
InactiveBufferIndex = 1 - RegRecPtr->ActiveBufferIndex;
InactiveBufferIndex = RegRecPtr->ActiveBufferIndex ^ 1;

/* Scan the access descriptor table to determine if anyone is still using the inactive buffer */
AccessIterator = RegRecPtr->HeadOfAccessList;
Expand Down
8 changes: 4 additions & 4 deletions modules/tbl/fsw/src/cfe_tbl_task_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ void CFE_TBL_GetTblRegData(void)
{
/* For a double buffered table, the inactive is the other allocated buffer */
CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr =
CFE_ES_MEMADDRESS_C(RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr);
CFE_ES_MEMADDRESS_C(RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr);
}
else
{
Expand Down Expand Up @@ -564,7 +564,7 @@ int32 CFE_TBL_DumpCmd(const CFE_TBL_DumpCmd_t *data)
/* If this is a double buffered table, locating the inactive buffer is trivial */
if (RegRecPtr->DoubleBuffered)
{
DumpDataAddr = RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr;
DumpDataAddr = RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr;
}
else
{
Expand Down Expand Up @@ -826,7 +826,7 @@ int32 CFE_TBL_ValidateCmd(const CFE_TBL_ValidateCmd_t *data)
/* If this is a double buffered table, locating the inactive buffer is trivial */
if (RegRecPtr->DoubleBuffered)
{
ValidationDataPtr = RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr;
ValidationDataPtr = RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr;
}
else
{
Expand Down Expand Up @@ -965,7 +965,7 @@ int32 CFE_TBL_ActivateCmd(const CFE_TBL_ActivateCmd_t *data)
/* Determine if the inactive buffer has been successfully validated or not */
if (RegRecPtr->DoubleBuffered)
{
ValidationStatus = RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].Validated;
ValidationStatus = RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].Validated;
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions modules/tbl/ut-coverage/tbl_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ void Test_CFE_TBL_ValidateCmd(void)
UT_InitData();
ValidateCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_INACTIVE;
CFE_TBL_Global.Registry[0].DoubleBuffered = true;
CFE_TBL_Global.Registry[0].Buffers[1 - CFE_TBL_Global.Registry[0].ActiveBufferIndex].BufferPtr = BuffPtr;
CFE_TBL_Global.Registry[0].Buffers[CFE_TBL_Global.Registry[0].ActiveBufferIndex ^ 1].BufferPtr = BuffPtr;
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
CFE_TBL_Global.Registry[0].ValidationFuncPtr = ValFuncPtr;
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
Expand Down Expand Up @@ -1096,7 +1096,7 @@ void Test_CFE_TBL_DumpCmd(void)
UT_InitData();
DumpCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_INACTIVE;
CFE_TBL_Global.Registry[2].DoubleBuffered = true;
CFE_TBL_Global.Registry[2].Buffers[(1 - CFE_TBL_Global.Registry[2].ActiveBufferIndex)].BufferPtr = BuffPtr;
CFE_TBL_Global.Registry[2].Buffers[(CFE_TBL_Global.Registry[2].ActiveBufferIndex ^ 1)].BufferPtr = BuffPtr;
CFE_TBL_Global.Registry[2].DumpControlIndex = CFE_TBL_NO_DUMP_PENDING + 1;
UtAssert_INT32_EQ(CFE_TBL_DumpCmd(&DumpCmd), CFE_TBL_INC_ERR_CTR);

Expand Down

0 comments on commit 283aa6c

Please sign in to comment.