Skip to content

Commit 283aa6c

Browse files
committed
Fix #1514, Use XOR to swap between ping-pong buffers (style change
only)
1 parent b429d91 commit 283aa6c

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

modules/tbl/fsw/src/cfe_tbl_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,12 +1156,12 @@ CFE_Status_t CFE_TBL_Validate(CFE_TBL_Handle_t TblHandle)
11561156
{
11571157
/* Call the Application's Validation function for the Inactive Buffer */
11581158
Status =
1159-
(RegRecPtr->ValidationFuncPtr)(RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr);
1159+
(RegRecPtr->ValidationFuncPtr)(RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr);
11601160

11611161
/* Allow buffer to be activated after passing validation */
11621162
if (Status == CFE_SUCCESS)
11631163
{
1164-
RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].Validated = true;
1164+
RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].Validated = true;
11651165
}
11661166
}
11671167
else

modules/tbl/fsw/src/cfe_tbl_internal.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ int32 CFE_TBL_GetWorkingBuffer(CFE_TBL_LoadBuff_t **WorkingBufferPtr, CFE_TBL_Re
653653
{
654654
if (RegRecPtr->DoubleBuffered)
655655
{
656-
*WorkingBufferPtr = &RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)];
656+
*WorkingBufferPtr = &RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)];
657657
}
658658
else
659659
{
@@ -684,7 +684,7 @@ int32 CFE_TBL_GetWorkingBuffer(CFE_TBL_LoadBuff_t **WorkingBufferPtr, CFE_TBL_Re
684684
if (RegRecPtr->DoubleBuffered)
685685
{
686686
/* Determine the index of the Inactive Buffer Pointer */
687-
InactiveBufferIndex = 1 - RegRecPtr->ActiveBufferIndex;
687+
InactiveBufferIndex = RegRecPtr->ActiveBufferIndex ^ 1;
688688

689689
/* Scan the access descriptor table to determine if anyone is still using the inactive buffer */
690690
AccessIterator = RegRecPtr->HeadOfAccessList;

modules/tbl/fsw/src/cfe_tbl_task_cmds.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ void CFE_TBL_GetTblRegData(void)
264264
{
265265
/* For a double buffered table, the inactive is the other allocated buffer */
266266
CFE_TBL_Global.TblRegPacket.Payload.InactiveBufferAddr =
267-
CFE_ES_MEMADDRESS_C(RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr);
267+
CFE_ES_MEMADDRESS_C(RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr);
268268
}
269269
else
270270
{
@@ -564,7 +564,7 @@ int32 CFE_TBL_DumpCmd(const CFE_TBL_DumpCmd_t *data)
564564
/* If this is a double buffered table, locating the inactive buffer is trivial */
565565
if (RegRecPtr->DoubleBuffered)
566566
{
567-
DumpDataAddr = RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr;
567+
DumpDataAddr = RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr;
568568
}
569569
else
570570
{
@@ -826,7 +826,7 @@ int32 CFE_TBL_ValidateCmd(const CFE_TBL_ValidateCmd_t *data)
826826
/* If this is a double buffered table, locating the inactive buffer is trivial */
827827
if (RegRecPtr->DoubleBuffered)
828828
{
829-
ValidationDataPtr = RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].BufferPtr;
829+
ValidationDataPtr = RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].BufferPtr;
830830
}
831831
else
832832
{
@@ -965,7 +965,7 @@ int32 CFE_TBL_ActivateCmd(const CFE_TBL_ActivateCmd_t *data)
965965
/* Determine if the inactive buffer has been successfully validated or not */
966966
if (RegRecPtr->DoubleBuffered)
967967
{
968-
ValidationStatus = RegRecPtr->Buffers[(1U - RegRecPtr->ActiveBufferIndex)].Validated;
968+
ValidationStatus = RegRecPtr->Buffers[(RegRecPtr->ActiveBufferIndex ^ 1)].Validated;
969969
}
970970
else
971971
{

modules/tbl/ut-coverage/tbl_UT.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ void Test_CFE_TBL_ValidateCmd(void)
712712
UT_InitData();
713713
ValidateCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_INACTIVE;
714714
CFE_TBL_Global.Registry[0].DoubleBuffered = true;
715-
CFE_TBL_Global.Registry[0].Buffers[1 - CFE_TBL_Global.Registry[0].ActiveBufferIndex].BufferPtr = BuffPtr;
715+
CFE_TBL_Global.Registry[0].Buffers[CFE_TBL_Global.Registry[0].ActiveBufferIndex ^ 1].BufferPtr = BuffPtr;
716716
CFE_TBL_Global.ValidationResults[0].State = CFE_TBL_VALIDATION_FREE;
717717
CFE_TBL_Global.Registry[0].ValidationFuncPtr = ValFuncPtr;
718718
UtAssert_INT32_EQ(CFE_TBL_ValidateCmd(&ValidateCmd), CFE_TBL_INC_CMD_CTR);
@@ -1096,7 +1096,7 @@ void Test_CFE_TBL_DumpCmd(void)
10961096
UT_InitData();
10971097
DumpCmd.Payload.ActiveTableFlag = CFE_TBL_BufferSelect_INACTIVE;
10981098
CFE_TBL_Global.Registry[2].DoubleBuffered = true;
1099-
CFE_TBL_Global.Registry[2].Buffers[(1 - CFE_TBL_Global.Registry[2].ActiveBufferIndex)].BufferPtr = BuffPtr;
1099+
CFE_TBL_Global.Registry[2].Buffers[(CFE_TBL_Global.Registry[2].ActiveBufferIndex ^ 1)].BufferPtr = BuffPtr;
11001100
CFE_TBL_Global.Registry[2].DumpControlIndex = CFE_TBL_NO_DUMP_PENDING + 1;
11011101
UtAssert_INT32_EQ(CFE_TBL_DumpCmd(&DumpCmd), CFE_TBL_INC_ERR_CTR);
11021102

0 commit comments

Comments
 (0)