Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -r421ffbd3887d136b66da26ee3eeb17dcd9a773b8 -r031627883dbd40abd52312d64a1a3b811478d1c3 --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 421ffbd3887d136b66da26ee3eeb17dcd9a773b8) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 031627883dbd40abd52312d64a1a3b811478d1c3) @@ -214,7 +214,7 @@ if ( ( len <= ( COMM_BUFFER_LENGTH * DOUBLE_BUFFERS ) ) && ( len <= numberOfBytesInCommBuffer( buffer ) ) ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); U32 bytesInInactiveBuffer = commBufferByteCount[ buffer ][ inactiveBuffer ]; U32 sizeOfFirstConsumption = MIN( len, bytesInInactiveBuffer ); @@ -223,7 +223,7 @@ // Will return # of bytes consumed result = sizeOfFirstConsumption; // Do we need more from active buffer? - if ( len > bytesInInactiveBuffer ) + if ( len > sizeOfFirstConsumption ) { U32 remNumOfBytes = len - sizeOfFirstConsumption; U08 *remPtr = data + sizeOfFirstConsumption; @@ -272,7 +272,7 @@ if ( ( len <= ( COMM_BUFFER_LENGTH * DOUBLE_BUFFERS ) ) && ( len <= numberOfBytesInCommBuffer( buffer ) ) ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); U32 bytesInInactiveBuffer = commBufferByteCount[ buffer ][ inactiveBuffer ]; if ( len <= bytesInInactiveBuffer ) @@ -345,7 +345,7 @@ static U32 switchDoubleBuffer( COMM_BUFFER_T buffer ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); // Ensure inactive buffer is reset before making active commBufferByteCount[ buffer ][ inactiveBuffer ] = 0; @@ -371,7 +371,7 @@ static void getDataFromInactiveBuffer( COMM_BUFFER_T buffer, U08 *data, U32 len ) { U32 activeBuffer = activeDoubleBuffer[ buffer ]; - U32 inactiveBuffer = ( activeBuffer == 0 ? 1 : 0 ); + U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); U32 bytesInInactiveBuffer = commBufferByteCount[ buffer ][ inactiveBuffer ]; // Get the requested data from inactive buffer