From 7852cea90372936f7141ea0eb20b81a92d6af379 Mon Sep 17 00:00:00 2001 From: richardbarry Date: Tue, 3 Jul 2012 11:16:52 +0000 Subject: [PATCH] Add in a couple of extra list macros for use with FreeRTOS+UDP. Allow the ISR safe queue send and receive functions to set the higher priority task woken pointer to NULL. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1753 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- Source/include/list.h | 18 +++++++++++++++++- Source/include/queue.h | 4 ++-- Source/queue.c | 18 +++++++++++------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/Source/include/list.h b/Source/include/list.h index 8a9f2bf19..c36de5737 100644 --- a/Source/include/list.h +++ b/Source/include/list.h @@ -139,6 +139,15 @@ typedef struct xLIST */ #define listSET_LIST_ITEM_OWNER( pxListItem, pxOwner ) ( pxListItem )->pvOwner = ( void * ) ( pxOwner ) +/* + * Access macro to get the owner of a list item. The owner of a list item + * is the object (usually a TCB) that contains the list item. + * + * \page listSET_LIST_ITEM_OWNER listSET_LIST_ITEM_OWNER + * \ingroup LinkedList + */ +#define listGET_LIST_ITEM_OWNER( pxListItem ) ( pxListItem )->pvOwner + /* * Access macro to set the value of the list item. In most cases the value is * used to sort the list in descending order. @@ -149,7 +158,7 @@ typedef struct xLIST #define listSET_LIST_ITEM_VALUE( pxListItem, xValue ) ( pxListItem )->xItemValue = ( xValue ) /* - * Access macro the retrieve the value of the list item. The value can + * Access macro to retrieve the value of the list item. The value can * represent anything - for example a the priority of a task, or the time at * which a task should be unblocked. * @@ -244,6 +253,13 @@ xList * const pxConstList = ( pxList ); \ */ #define listIS_CONTAINED_WITHIN( pxList, pxListItem ) ( ( pxListItem )->pvContainer == ( void * ) ( pxList ) ) +/* + * This provides a crude means of knowing if a list has been initialised, as + * pxList->xListEnd.xItemValue is set to portMAX_DELAY by the vListInitialise() + * function. + */ +#define listLIST_IS_INITIALISED( pxList ) ( ( pxList )->xListEnd.xItemValue == portMAX_DELAY ) + /* * Must be called before a list is used! This initialises all the members * of the list structure and inserts the xListEnd item into the list as a diff --git a/Source/include/queue.h b/Source/include/queue.h index 6225196ff..4574895f3 100644 --- a/Source/include/queue.h +++ b/Source/include/queue.h @@ -1187,10 +1187,10 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR * \ingroup QueueManagement */ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ); +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ); /* - * Utilities to query queue that are safe to use from an ISR. These utilities + * Utilities to query queues that are safe to use from an ISR. These utilities * should be used only from witin an ISR, or within a critical section. */ signed portBASE_TYPE xQueueIsQueueEmptyFromISR( const xQueueHandle pxQueue ); diff --git a/Source/queue.c b/Source/queue.c index 5faea1d2d..a546dcc08 100644 --- a/Source/queue.c +++ b/Source/queue.c @@ -157,12 +157,12 @@ typedef xQUEUE * xQueueHandle; * functions are documented in the API header file. */ xQueueHandle xQueueGenericCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize, unsigned char ucQueueType ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueueGenericSend( xQueueHandle pxQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; unsigned portBASE_TYPE uxQueueMessagesWaiting( const xQueueHandle pxQueue ) PRIVILEGED_FUNCTION; void vQueueDelete( xQueueHandle xQueue ) PRIVILEGED_FUNCTION; signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle pxQueue, const void * const pvItemToQueue, signed portBASE_TYPE *pxHigherPriorityTaskWoken, portBASE_TYPE xCopyPosition ) PRIVILEGED_FUNCTION; signed portBASE_TYPE xQueueGenericReceive( xQueueHandle pxQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) PRIVILEGED_FUNCTION; -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; xQueueHandle xQueueCreateMutex( unsigned char ucQueueType ) PRIVILEGED_FUNCTION; xQueueHandle xQueueCreateCountingSemaphore( unsigned portBASE_TYPE uxCountValue, unsigned portBASE_TYPE uxInitialCount ) PRIVILEGED_FUNCTION; portBASE_TYPE xQueueTakeMutexRecursive( xQueueHandle xMutex, portTickType xBlockTime ) PRIVILEGED_FUNCTION; @@ -905,7 +905,6 @@ signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; configASSERT( pxQueue ); - configASSERT( pxHigherPriorityTaskWoken ); configASSERT( !( ( pvItemToQueue == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); /* Similar to xQueueGenericSend, except we don't block if there is no room @@ -931,7 +930,10 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; { /* The task waiting has a higher priority so record that a context switch is required. */ - *pxHigherPriorityTaskWoken = pdTRUE; + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } } } } @@ -1105,13 +1107,12 @@ signed char *pcOriginalReadPosition; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxTaskWoken ) +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle pxQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) { signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; configASSERT( pxQueue ); - configASSERT( pxTaskWoken ); configASSERT( !( ( pvBuffer == NULL ) && ( pxQueue->uxItemSize != ( unsigned portBASE_TYPE ) 0U ) ) ); uxSavedInterruptStatus = portSET_INTERRUPT_MASK_FROM_ISR(); @@ -1135,7 +1136,10 @@ unsigned portBASE_TYPE uxSavedInterruptStatus; { /* The task waiting has a higher priority than us so force a context switch. */ - *pxTaskWoken = pdTRUE; + if( pxHigherPriorityTaskWoken != NULL ) + { + *pxHigherPriorityTaskWoken = pdTRUE; + } } } } -- 2.39.5