Index: firmware/App/Services/CommBuffers.c =================================================================== diff -u -r31c4bf94671f58375d2e1dbbbb37b37c6949e0c4 -r72f847f5a701cf0e10e8803ea6bd0ad5fab1f284 --- firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 31c4bf94671f58375d2e1dbbbb37b37c6949e0c4) +++ firmware/App/Services/CommBuffers.c (.../CommBuffers.c) (revision 72f847f5a701cf0e10e8803ea6bd0ad5fab1f284) @@ -33,7 +33,6 @@ static volatile U32 commBufferByteCount[ NUM_OF_COMM_BUFFERS ][ DOUBLE_BUFFERS ]; // for each buffer, how many bytes does it contain? (also index to next available) static volatile U32 activeDoubleBuffer[ NUM_OF_COMM_BUFFERS ]; // for each buffer, which double buffer is being fed right now? static U08 commBuffers[ NUM_OF_COMM_BUFFERS ][ DOUBLE_BUFFERS ][ COMM_BUFFER_LENGTH ]; // each is double buffered to avoid thread contention -static volatile BOOL bufferGetLock[ NUM_OF_COMM_BUFFERS ]; // prevent getter from accessing active buffer while add in progress static U32 firstBufferOverflowTimeStamp = 0; // time stamp of a prior overflow event - allows for an overflow persistence check // ********** private function prototypes ********** @@ -79,16 +78,22 @@ { S32 d,i; - activeDoubleBuffer[ buffer ] = 0; - for ( d = 0; d < DOUBLE_BUFFERS; d++ ) - { - commBufferByteCount[ buffer ][ d ] = 0; - for ( i = 0; i < COMM_BUFFER_LENGTH; i++ ) - { - commBuffers[ buffer ][ d ][ i ] = 0; - } - } - } + // thread protection for queue operations + _disable_IRQ(); + + activeDoubleBuffer[ buffer ] = 0; + for ( d = 0; d < DOUBLE_BUFFERS; d++ ) + { + commBufferByteCount[ buffer ][ d ] = 0; + for ( i = 0; i < COMM_BUFFER_LENGTH; i++ ) + { + commBuffers[ buffer ][ d ][ i ] = 0; + } + } + + // release thread protection + _enable_IRQ(); + } } /************************************************************************* @@ -119,7 +124,6 @@ // thread protection for queue operations _disable_IRQ(); - bufferGetLock[ buffer ] = TRUE; activeBuffer = activeDoubleBuffer[ buffer ]; currentActiveBufCount = commBufferByteCount[ buffer ][ activeBuffer ]; @@ -135,29 +139,25 @@ memcpy( buffPtr, data, len ); // adjust buffer count per this data add (also reserves space to add data before releasing thread protection) commBufferByteCount[ buffer ][ activeBuffer ] += len; - // release thread protection - bufferGetLock[ buffer ] = FALSE; - _enable_IRQ(); // data successfully added to buffer result = TRUE; } else // buffer too full to add this much data { -#ifdef DEBUG_ENABLED - char debugStr[50]; - sprintf( debugStr, "Buf OF:#%3d,%3d, %02X %02X %02X %02X %02X %02X %02X %02X \n", buffer, len, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] ); - sendDebugData( (U08*)debugStr, strlen(debugStr) ); - sendDebugDataToUI( (U08*)debugStr ); -#endif bufferFull = TRUE; - clearBuffer( buffer ); } // release thread protection - bufferGetLock[ buffer ] = FALSE; _enable_IRQ(); // if buffer was full, check persistence - trigger s/w fault if persists if ( TRUE == bufferFull ) { +#ifdef DEBUG_ENABLED + char debugStr[100]; + sprintf( debugStr, "Buf OF:#%3d,%3d, %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n", buffer, len, data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7] ); + sendDebugData( (U08*)debugStr, strlen(debugStr) ); + sendDebugDataToUI( (U08*)debugStr ); +#endif + clearBuffer( buffer ); // not first overflow? if ( firstBufferOverflowTimeStamp != 0 ) { @@ -328,14 +328,7 @@ U32 activeBuffer = activeDoubleBuffer[ buffer ]; U32 inactiveBuffer = GET_TOGGLE( activeBuffer, 0, 1 ); - if ( FALSE == bufferGetLock[ buffer ] ) - { - result = commBufferByteCount[ buffer ][ inactiveBuffer ] + commBufferByteCount[ buffer ][ activeBuffer ]; - } - else - { - result = commBufferByteCount[ buffer ][ inactiveBuffer ]; - } + result = commBufferByteCount[ buffer ][ inactiveBuffer ] + commBufferByteCount[ buffer ][ activeBuffer ]; } else // invalid buffer {