Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -rccfd15568f1e3d304320c2babb2fd4bcf0413304 -r959cc3f19c6d2132e0928b19d16829deef3cd969 --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision ccfd15568f1e3d304320c2babb2fd4bcf0413304) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 959cc3f19c6d2132e0928b19d16829deef3cd969) @@ -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