Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -r94a190522ce398399c7b93c59f788d7666ec0060 -r2b60564ac818a6692b714dfd9920d2e2fcf0937d --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 94a190522ce398399c7b93c59f788d7666ec0060) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 2b60564ac818a6692b714dfd9920d2e2fcf0937d) @@ -210,7 +210,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 ); @@ -219,7 +219,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; @@ -267,7 +267,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 ) @@ -338,7 +338,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; @@ -364,7 +364,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