From: richardbarry Date: Thu, 7 Nov 2013 14:58:14 +0000 (+0000) Subject: Change behaviour when configUSE_PREEMPTION is 0 (preemption is turned off). See... X-Git-Tag: V7.6.0~19 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1e0e58c7f0780741ed0e9d41d1bb844ac4abe335;p=freertos Change behaviour when configUSE_PREEMPTION is 0 (preemption is turned off). See the change history in the next release for details. Remove an erroneous const in the prototype of queue receive/peek functions. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2088 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/FreeRTOS/Source/include/queue.h b/FreeRTOS/Source/include/queue.h index 16ae19c36..b5fac2b7d 100644 --- a/FreeRTOS/Source/include/queue.h +++ b/FreeRTOS/Source/include/queue.h @@ -714,7 +714,7 @@ signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const * \defgroup xQueuePeekFromISR xQueuePeekFromISR * \ingroup QueueManagement */ -signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION; /** * queue. h @@ -906,7 +906,7 @@ signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const * \defgroup xQueueReceive xQueueReceive * \ingroup QueueManagement */ -signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek ) PRIVILEGED_FUNCTION; /** * queue. h @@ -1421,7 +1421,7 @@ signed portBASE_TYPE xQueueGenericSendFromISR( xQueueHandle xQueue, const void * * \defgroup xQueueReceiveFromISR xQueueReceiveFromISR * \ingroup QueueManagement */ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) PRIVILEGED_FUNCTION; /* * Utilities to query queues that are safe to use from an ISR. These utilities diff --git a/FreeRTOS/Source/queue.c b/FreeRTOS/Source/queue.c index 21977a75c..0622eee13 100644 --- a/FreeRTOS/Source/queue.c +++ b/FreeRTOS/Source/queue.c @@ -1,5 +1,5 @@ /* - FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. + FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. All rights reserved VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. @@ -110,6 +110,13 @@ zero. */ #define queueSEMAPHORE_QUEUE_ITEM_LENGTH ( ( unsigned portBASE_TYPE ) 0 ) #define queueMUTEX_GIVE_BLOCK_TIME ( ( portTickType ) 0U ) +#if( configUSE_PREEMPTION == 0 ) + /* If the cooperative scheduler is being used then a yield should not be + performed just because a higher priority task has been woken. */ + #define queueYIELD_IF_USING_PREEMPTION() +#else + #define queueYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() +#endif /* * Definition of the queue used by the scheduler. @@ -205,7 +212,7 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port /* * Copies an item out of a queue. */ -static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer ) PRIVILEGED_FUNCTION; +static void prvCopyDataFromQueue( xQUEUE * const pxQueue, void * const pvBuffer ) PRIVILEGED_FUNCTION; #if ( configUSE_QUEUE_SETS == 1 ) /* @@ -255,14 +262,14 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; { /* If there are tasks blocked waiting to read from the queue, then the tasks will remain blocked as after this function exits the queue - will still be empty. If there are tasks blocked waiting to write to + will still be empty. If there are tasks blocked waiting to write to the queue, then one should be unblocked as after this function exits it will be possible to write to it. */ if( listLIST_IS_EMPTY( &( pxQueue->xTasksWaitingToSend ) ) == pdFALSE ) { if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE ) { - portYIELD_WITHIN_API(); + queueYIELD_IF_USING_PREEMPTION(); } } } @@ -586,7 +593,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; /* The queue is a member of a queue set, and posting to the queue set caused a higher priority task to unblock. A context switch is required. */ - portYIELD_WITHIN_API(); + queueYIELD_IF_USING_PREEMPTION(); } } else @@ -601,7 +608,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; our own so yield immediately. Yes it is ok to do this from within the critical section - the kernel takes care of that. */ - portYIELD_WITHIN_API(); + queueYIELD_IF_USING_PREEMPTION(); } } } @@ -618,7 +625,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; our own so yield immediately. Yes it is ok to do this from within the critical section - the kernel takes care of that. */ - portYIELD_WITHIN_API(); + queueYIELD_IF_USING_PREEMPTION(); } } } @@ -1033,7 +1040,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) +signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeeking ) { signed portBASE_TYPE xEntryTimeSet = pdFALSE; xTimeOutType xTimeOut; @@ -1083,7 +1090,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; { if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToSend ) ) == pdTRUE ) { - portYIELD_WITHIN_API(); + queueYIELD_IF_USING_PREEMPTION(); } } } @@ -1104,7 +1111,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; if( xTaskRemoveFromEventList( &( pxQueue->xTasksWaitingToReceive ) ) != pdFALSE ) { /* The task waiting has a higher priority than this task. */ - portYIELD_WITHIN_API(); + queueYIELD_IF_USING_PREEMPTION(); } } } @@ -1188,7 +1195,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, const void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) +signed portBASE_TYPE xQueueReceiveFromISR( xQueueHandle xQueue, void * const pvBuffer, signed portBASE_TYPE *pxHigherPriorityTaskWoken ) { signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; @@ -1263,7 +1270,7 @@ xQUEUE * const pxQueue = ( xQUEUE * ) xQueue; } /*-----------------------------------------------------------*/ -signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, const void * const pvBuffer ) +signed portBASE_TYPE xQueuePeekFromISR( xQueueHandle xQueue, void * const pvBuffer ) { signed portBASE_TYPE xReturn; unsigned portBASE_TYPE uxSavedInterruptStatus; @@ -1455,7 +1462,7 @@ static void prvCopyDataToQueue( xQUEUE *pxQueue, const void *pvItemToQueue, port } /*-----------------------------------------------------------*/ -static void prvCopyDataFromQueue( xQUEUE * const pxQueue, const void * const pvBuffer ) +static void prvCopyDataFromQueue( xQUEUE * const pxQueue, void * const pvBuffer ) { if( pxQueue->uxQueueType != queueQUEUE_IS_MUTEX ) { @@ -2082,3 +2089,14 @@ signed portBASE_TYPE xReturn; #endif /* configUSE_QUEUE_SETS */ + + + + + + + + + + + diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 768c13358..dfb1bcce8 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -1,5 +1,5 @@ /* - FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. + FreeRTOS V7.5.3 - Copyright (C) 2013 Real Time Engineers Ltd. All rights reserved VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION. @@ -104,6 +104,14 @@ privileged Vs unprivileged linkage and placement. */ */ #define tskIDLE_STACK_SIZE configMINIMAL_STACK_SIZE +#if( configUSE_PREEMPTION == 0 ) + /* If the cooperative scheduler is being used then a yield should not be + performed just because a higher priority task has been woken. */ + #define taskYIELD_IF_USING_PREEMPTION() +#else + #define taskYIELD_IF_USING_PREEMPTION() portYIELD_WITHIN_API() +#endif + /* * Task control block. A task control block (TCB) is allocated for each task, * and stores task state information, including a pointer to the task's context @@ -621,7 +629,7 @@ tskTCB * pxNewTCB; then it should run now. */ if( pxCurrentTCB->uxPriority < uxPriority ) { - portYIELD_WITHIN_API(); + taskYIELD_IF_USING_PREEMPTION(); } } } @@ -844,7 +852,7 @@ tskTCB * pxNewTCB; else if( pxStateList == &xSuspendedTaskList ) { /* The task being queried is referenced from the suspended - list. Is it genuinely suspended or is it block + list. Is it genuinely suspended or is it block indefinitely? */ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ) { @@ -1019,7 +1027,7 @@ tskTCB * pxNewTCB; if( xYieldRequired == pdTRUE ) { - portYIELD_WITHIN_API(); + taskYIELD_IF_USING_PREEMPTION(); } /* Remove compiler warning about unused variables when the port @@ -1155,9 +1163,10 @@ tskTCB * pxNewTCB; /* We may have just resumed a higher priority task. */ if( pxTCB->uxPriority >= pxCurrentTCB->uxPriority ) { - /* This yield may not cause the task just resumed to run, but - will leave the lists in the correct state for the next yield. */ - portYIELD_WITHIN_API(); + /* This yield may not cause the task just resumed to run, + but will leave the lists in the correct state for the + next yield. */ + taskYIELD_IF_USING_PREEMPTION(); } } } @@ -1407,8 +1416,12 @@ portBASE_TYPE xAlreadyYielded = pdFALSE; if( xYieldPending == pdTRUE ) { - xAlreadyYielded = pdTRUE; - portYIELD_WITHIN_API(); + #if( configUSE_PREEMPTION != 0 ) + { + xAlreadyYielded = pdTRUE; + } + #endif + taskYIELD_IF_USING_PREEMPTION(); } } } @@ -1694,7 +1707,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE; } } #endif /* ( ( configUSE_PREEMPTION == 1 ) && ( configUSE_TIME_SLICING == 1 ) ) */ - + #if ( configUSE_TICK_HOOK == 1 ) { /* Guard against the tick hook being called when the pended tick @@ -1704,7 +1717,7 @@ portBASE_TYPE xSwitchRequired = pdFALSE; vApplicationTickHook(); } } - #endif /* configUSE_TICK_HOOK */ + #endif /* configUSE_TICK_HOOK */ } else {