Kernel changes:

Minor change to xQueueGenericReceive() to catch the extreme case of data being placed into a queue between a task timing out and leaving the xQueueGenericReceive() function.
Added xSemaphoreGetCount() macro.


Demo app changes:
Updated countsem.c to test the new xSemaphoreGetCount() macro.
pull/4/head
Richard Barry 9 years ago
parent f81575dcee
commit b832d5801f

@ -193,6 +193,8 @@ UBaseType_t ux;
/* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */ /* We should be able to 'take' the semaphore countMAX_COUNT_VALUE times. */
for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ ) for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
{ {
configASSERT( xSemaphoreGetCount( xSemaphore ) == ( countMAX_COUNT_VALUE - ux ) );
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS ) if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) != pdPASS )
{ {
/* We expected to be able to take the semaphore. */ /* We expected to be able to take the semaphore. */
@ -208,6 +210,7 @@ UBaseType_t ux;
/* If the semaphore count is zero then we should not be able to 'take' /* If the semaphore count is zero then we should not be able to 'take'
the semaphore. */ the semaphore. */
configASSERT( xSemaphoreGetCount( xSemaphore ) == 0 );
if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS ) if( xSemaphoreTake( xSemaphore, countDONT_BLOCK ) == pdPASS )
{ {
xErrorDetected = pdTRUE; xErrorDetected = pdTRUE;
@ -229,6 +232,8 @@ UBaseType_t ux;
/* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */ /* We should be able to 'give' the semaphore countMAX_COUNT_VALUE times. */
for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ ) for( ux = 0; ux < countMAX_COUNT_VALUE; ux++ )
{ {
configASSERT( xSemaphoreGetCount( xSemaphore ) == ux );
if( xSemaphoreGive( xSemaphore ) != pdPASS ) if( xSemaphoreGive( xSemaphore ) != pdPASS )
{ {
/* We expected to be able to take the semaphore. */ /* We expected to be able to take the semaphore. */

@ -776,6 +776,10 @@ extern "C" {
#define configSUPPORT_STATIC_ALLOCATION 0 #define configSUPPORT_STATIC_ALLOCATION 0
#endif #endif
#if( ( configUSE_RECURSIVE_MUTEXES == 1 ) && ( configUSE_MUTEXES != 1 ) )
#error configUSE_MUTEXES must be set to 1 to use recursive mutexes
#endif
#if( portTICK_TYPE_IS_ATOMIC == 0 ) #if( portTICK_TYPE_IS_ATOMIC == 0 )
/* Either variables of tick type cannot be read atomically, or /* Either variables of tick type cannot be read atomically, or
portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when portTICK_TYPE_IS_ATOMIC was not set - map the critical sections used when

@ -839,6 +839,18 @@ typedef QueueHandle_t SemaphoreHandle_t;
*/ */
#define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) ) #define xSemaphoreGetMutexHolder( xSemaphore ) xQueueGetMutexHolder( ( xSemaphore ) )
/**
* semphr.h
* <pre>TaskHandle_t xSemaphoreGetCount( SemaphoreHandle_t xMutex );</pre>
*
* If the semaphore is a counting semaphore then xSemaphoreGetCount() returns
* its current count value. If the semaphore is a binary semaphore then
* xSemaphoreGetCount() returns 1 if the semaphore is available, and 0 if the
* semaphore is not available.
*
*/
#define xSemaphoreGetCount( xSemaphore ) uxQueueMessagesWaiting( ( QueueHandle_t ) ( xSemaphore ) )
#endif /* SEMAPHORE_H */ #endif /* SEMAPHORE_H */

@ -797,8 +797,6 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
prvUnlockQueue( pxQueue ); prvUnlockQueue( pxQueue );
( void ) xTaskResumeAll(); ( void ) xTaskResumeAll();
/* Return to the original privilege level before exiting the
function. */
traceQUEUE_SEND_FAILED( pxQueue ); traceQUEUE_SEND_FAILED( pxQueue );
return errQUEUE_FULL; return errQUEUE_FULL;
} }
@ -1385,7 +1383,7 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
taskENTER_CRITICAL(); taskENTER_CRITICAL();
{ {
/* Is there data in the queue now? To be running the calling task /* Is there data in the queue now? To be running the calling task
must be the highest priority task wanting to access the queue. */ must be the highest priority task wanting to access the queue. */
if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 ) if( pxQueue->uxMessagesWaiting > ( UBaseType_t ) 0 )
{ {
/* Remember the read position in case the queue is only being /* Remember the read position in case the queue is only being
@ -1541,8 +1539,16 @@ Queue_t * const pxQueue = ( Queue_t * ) xQueue;
{ {
prvUnlockQueue( pxQueue ); prvUnlockQueue( pxQueue );
( void ) xTaskResumeAll(); ( void ) xTaskResumeAll();
traceQUEUE_RECEIVE_FAILED( pxQueue );
return errQUEUE_EMPTY; if( prvIsQueueEmpty( pxQueue ) != pdFALSE )
{
traceQUEUE_RECEIVE_FAILED( pxQueue );
return errQUEUE_EMPTY;
}
else
{
mtCOVERAGE_TEST_MARKER();
}
} }
} }
} }

@ -2732,9 +2732,13 @@ static portTASK_FUNCTION( prvIdleTask, pvParameters )
/* Stop warnings. */ /* Stop warnings. */
( void ) pvParameters; ( void ) pvParameters;
/** THIS IS THE RTOS IDLE TASK - WHICH IS CREATED AUTOMATICALLY WHEN THE
SCHEDULER IS STARTED. **/
for( ;; ) for( ;; )
{ {
/* See if any tasks have been deleted. */ /* See if any tasks have deleted themselves - if so then the idle task
is responsible for freeing the deleted task's TCB and stack. */
prvCheckTasksWaitingTermination(); prvCheckTasksWaitingTermination();
#if ( configUSE_PREEMPTION == 0 ) #if ( configUSE_PREEMPTION == 0 )
@ -3029,7 +3033,7 @@ UBaseType_t x;
the calling task. */ the calling task. */
pxTCB = prvGetTCBFromHandle( xTaskToModify ); pxTCB = prvGetTCBFromHandle( xTaskToModify );
vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 ); vPortStoreTaskMPUSettings( &( pxTCB->xMPUSettings ), xRegions, NULL, 0 );
} }
#endif /* portUSING_MPU_WRAPPERS */ #endif /* portUSING_MPU_WRAPPERS */
@ -3069,6 +3073,9 @@ UBaseType_t uxPriority;
static void prvCheckTasksWaitingTermination( void ) static void prvCheckTasksWaitingTermination( void )
{ {
/** THIS FUNCTION IS CALLED FROM THE RTOS IDLE TASK **/
#if ( INCLUDE_vTaskDelete == 1 ) #if ( INCLUDE_vTaskDelete == 1 )
{ {
BaseType_t xListIsEmpty; BaseType_t xListIsEmpty;

Loading…
Cancel
Save