Hi ! I have an initial state as shown in the figure above ! My task implementation is shown in the code below ! configUSE_PREEMPTION
is 1
.
#define TEMP_STR_LEN 9
static portTASK_FUNCTION( vBlockingQueueProducer, pvParameters )
{
uint16_t usValue = 0;
xBlockingQueueParameters * pxQueueParameters;
short sErrorEverOccurred = pdFALSE;
// Sid - 2022.02.23
char *tasknamestr = pcTaskGetName( NULL );
char tempstr[TEMP_STR_LEN];
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
for( ; ; )
{
if( xQueueSend( pxQueueParameters->xQueue, ( void * ) &usValue, pxQueueParameters->xBlockTime ) != pdPASS )
{
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:FTS\n", tasknamestr); // Sid - FTS = Failed To Send
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
sErrorEverOccurred = pdTRUE;
}
else
{
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:%3d\n", tasknamestr, usValue);// Sid - Print the value that was successfully sent
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
/* We have successfully posted a message, so increment the variable
* used to check we are still running. */
if( sErrorEverOccurred == pdFALSE )
{
( *pxQueueParameters->psCheckVariable )++;
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:EEF\n", tasknamestr); // Sid - EEF = Error Ever occured is False
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
}
/* Increment the variable we are going to post next time round. The
* consumer will expect the numbers to follow in numerical order. */
++usValue;
#if configUSE_PREEMPTION == 0
taskYIELD();
#endif
}
}
}
/*-----------------------------------------------------------*/
static portTASK_FUNCTION( vBlockingQueueConsumer, pvParameters )
{
uint16_t usData, usExpectedValue = 0;
xBlockingQueueParameters * pxQueueParameters;
short sErrorEverOccurred = pdFALSE;
// Sid - 2022.02.23
char *tasknamestr = pcTaskGetName( NULL );
char tempstr[TEMP_STR_LEN];
pxQueueParameters = ( xBlockingQueueParameters * ) pvParameters;
for( ; ; )
{
if( xQueueReceive( pxQueueParameters->xQueue, &usData, pxQueueParameters->xBlockTime ) == pdPASS )
{
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:%3d\n", tasknamestr, usData); // Sid - Print the data that was successfully received
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
if( usData != usExpectedValue )
{
/* Catch-up. */
usExpectedValue = usData;
sErrorEverOccurred = pdTRUE;
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:DNE\n", tasknamestr); // Sid - DNE = Data is Not Expected value
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
}
else
{
/* We have successfully received a message, so increment the
* variable used to check we are still running. */
if( sErrorEverOccurred == pdFALSE )
{
( *pxQueueParameters->psCheckVariable )++;
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:EEF\n", tasknamestr); // Sid - EEF = Error Ever occured is False
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
}
/* Increment the value we expect to remove from the queue next time
* round. */
++usExpectedValue;
}
#if configUSE_PREEMPTION == 0
{
if( pxQueueParameters->xBlockTime == 0 )
{
taskYIELD();
}
}
#endif
}
else
{
// Sid - 2022.02.24
portENTER_CRITICAL();
sprintf((char *) tempstr, "%s:FTR\n", tasknamestr); // Sid - FTR = Failed To Receive
uart_printf((BYTE *) tempstr, TEMP_STR_LEN);
portEXIT_CRITICAL();
}
}
}
The initial part of my output is shown below:
QP4: 0
QP4:EEF
QC1: 0 ..........| ---> Consumer task
QC1:EEF ..........|
QP4: 1
QP4:EEF
QP5: 0
QP5:EEF
QC6: 0
QC6:EEF
QP2: 0 ..........| ---> Producer task
QP2:EEF ..........|
QC1: 1
QC1:EEF
QC3: 0
QC3:EEF
QP4: 2
QP4:EEF
It looks like:
-
A Consumer task (QC1) occurs before the respective Producer task (QP2).
-
The Consumer task’s
xQueueReceive()
succeeds &0
is removed from the queue that is shared by QC1 & QP2 ! How did this happen ? The shared queue should be empty when accessed by QC1, right ?
Hope someone can make sense of this ! Thanks in advance !