From e4a8ae174c67e019dfa3ec4b9a4d169752be05c2 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Tue, 10 Sep 2013 13:19:12 +0000 Subject: [PATCH] Add the uxQueueSpacesAvailable() API function. Move a configASSERT() call in timers.c to prevent a "condition is always true" compiler warning. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2039 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- FreeRTOS/Source/include/queue.h | 17 +++++++++++++ FreeRTOS/Source/queue.c | 44 ++++++++++++++++++++++----------- FreeRTOS/Source/timers.c | 4 ++- 3 files changed, 50 insertions(+), 15 deletions(-) diff --git a/FreeRTOS/Source/include/queue.h b/FreeRTOS/Source/include/queue.h index c0f263091..d9e5914c4 100644 --- a/FreeRTOS/Source/include/queue.h +++ b/FreeRTOS/Source/include/queue.h @@ -922,6 +922,23 @@ signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * con */ unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION; +/** + * queue. h + *
unsigned portBASE_TYPE uxQueueSpacesAvailable( const xQueueHandle xQueue );
+ * + * Return the number of free spaces available in a queue. This is equal to the + * number of items that can be sent to the queue before the queue becomes full + * if no items are removed. + * + * @param xQueue A handle to the queue being queried. + * + * @return The number of spaces available in the queue. + * + * \defgroup uxQueueMessagesWaiting uxQueueMessagesWaiting + * \ingroup QueueManagement + */ +unsigned portBASE_TYPE uxQueueSpacesAvailable( const xQueueHandle xQueue ) PRIVILEGED_FUNCTION; + /** * queue. h *
void vQueueDelete( xQueueHandle xQueue );
diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c index d5c995c44..4bbddb1ec 100644 --- a/FreeRTOS/Source/queue.c +++ b/FreeRTOS/Source/queue.c @@ -497,7 +497,7 @@ xQueueHandle xReturn = NULL; traceTAKE_MUTEX_RECURSIVE( pxMutex ); - if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */ + if( pxMutex->pxMutexHolder == ( void * ) xTaskGetCurrentTaskHandle() ) /*lint !e961 Cast is not redundant as xTaskHandle is a typedef. */ { ( pxMutex->u.uxRecursiveCallCount )++; xReturn = pdPASS; @@ -651,7 +651,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; } else { - /* Entry time was already set. */ + /* Entry time was already set. */ } } } @@ -1198,17 +1198,17 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; /* RTOS ports that support interrupt nesting have the concept of a maximum system call (or maximum API call) interrupt priority. Interrupts that are - above the maximum system call priority are keep permanently enabled, even + above the maximum system call priority are keep permanently enabled, even when the RTOS kernel is in a critical section, but cannot make any calls to - FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion failure if a FreeRTOS API function is called from an interrupt that has been assigned a priority above the configured maximum system call priority. Only FreeRTOS functions that end in FromISR can be called from interrupts - that have been assigned a priority at or (logically) below the maximum - system call interrupt priority. FreeRTOS maintains a separate interrupt - safe API to ensure interrupt entry is as fast and as simple as possible. - More information (albeit Cortex-M specific) is provided on the following + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); @@ -1274,17 +1274,17 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; /* RTOS ports that support interrupt nesting have the concept of a maximum system call (or maximum API call) interrupt priority. Interrupts that are - above the maximum system call priority are keep permanently enabled, even + above the maximum system call priority are keep permanently enabled, even when the RTOS kernel is in a critical section, but cannot make any calls to - FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h + FreeRTOS API functions. If configASSERT() is defined in FreeRTOSConfig.h then portASSERT_IF_INTERRUPT_PRIORITY_INVALID() will result in an assertion failure if a FreeRTOS API function is called from an interrupt that has been assigned a priority above the configured maximum system call priority. Only FreeRTOS functions that end in FromISR can be called from interrupts - that have been assigned a priority at or (logically) below the maximum - system call interrupt priority. FreeRTOS maintains a separate interrupt - safe API to ensure interrupt entry is as fast and as simple as possible. - More information (albeit Cortex-M specific) is provided on the following + that have been assigned a priority at or (logically) below the maximum + system call interrupt priority. FreeRTOS maintains a separate interrupt + safe API to ensure interrupt entry is as fast and as simple as possible. + More information (albeit Cortex-M specific) is provided on the following link: http://www.freertos.org/RTOS-Cortex-M3-M4.html */ portASSERT_IF_INTERRUPT_PRIORITY_INVALID(); @@ -1329,6 +1329,22 @@ unsigned portBASE_TYPE uxReturn; } /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ /*-----------------------------------------------------------*/ +unsigned portBASE_TYPE uxQueueSpacesAvailable( const xQueueHandle xQueue ) +{ +unsigned portBASE_TYPE uxReturn; +xQUEUE *pxQueue; + + pxQueue = ( xQUEUE * ) xQueue; + configASSERT( pxQueue ); + + taskENTER_CRITICAL(); + uxReturn = pxQueue->uxLength - pxQueue->uxMessagesWaiting; + taskEXIT_CRITICAL(); + + return uxReturn; +} /*lint !e818 Pointer cannot be declared const as xQueue is a typedef not pointer. */ +/*-----------------------------------------------------------*/ + unsigned portBASE_TYPE uxQueueMessagesWaitingFromISR( const xQueueHandle xQueue ) { unsigned portBASE_TYPE uxReturn; diff --git a/FreeRTOS/Source/timers.c b/FreeRTOS/Source/timers.c index 835001d55..0414604f1 100644 --- a/FreeRTOS/Source/timers.c +++ b/FreeRTOS/Source/timers.c @@ -233,7 +233,6 @@ xTIMER *pxNewTimer; if( xTimerPeriodInTicks == ( portTickType ) 0U ) { pxNewTimer = NULL; - configASSERT( ( xTimerPeriodInTicks > 0 ) ); } else { @@ -260,6 +259,9 @@ xTIMER *pxNewTimer; } } + /* 0 is not a valid value for xTimerPeriodInTicks. */ + configASSERT( ( xTimerPeriodInTicks > 0 ) ); + return ( xTimerHandle ) pxNewTimer; } /*-----------------------------------------------------------*/ -- 2.39.5