From 6e33f3d844560120d8110ec9d6a50f912b594b87 Mon Sep 17 00:00:00 2001 From: rtel Date: Sun, 29 Apr 2018 18:15:38 +0000 Subject: [PATCH] xTaskGenericNotify() now sets xYieldPending to pdTRUE even when the 'higher priority task woken' parameter is provided - making its behaviour consistent with event objects. Ensure tasks that are blocked indefinitely on a direct to task notification return their state as eBlocked, previously was returned as eSuspended - making its behaviour consistent with event objects. Fix typo in stream_buffer.c where "size_t xBytesAvailable ); PRIVILEGED_FUNCTION" had the semicolon in the wrong place. Add testing of Stream Buffers to the AbortDelay.c tests. Guard inclusion of C code when FreeRTOSConfig.h is included from an assembly file in the ARM7_LPC2129_IAR demo. Fix minor typos in the Windows demo comment blocks. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2537 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../Demo/ARM7_LPC2129_IAR/FreeRTOSConfig.h | 6 +- FreeRTOS/Demo/Common/Minimal/AbortDelay.c | 90 +++++++++++++++++-- FreeRTOS/Demo/Common/Minimal/TimerDemo.c | 1 - FreeRTOS/Demo/WIN32-MSVC/main.c | 2 +- FreeRTOS/Demo/WIN32-MSVC/main_blinky.c | 2 +- FreeRTOS/Demo/WIN32-MSVC/main_full.c | 2 +- FreeRTOS/Demo/WIN32-MingW/main_full.c | 2 +- FreeRTOS/Source/stream_buffer.c | 2 +- FreeRTOS/Source/tasks.c | 47 ++++++---- 9 files changed, 124 insertions(+), 30 deletions(-) diff --git a/FreeRTOS/Demo/ARM7_LPC2129_IAR/FreeRTOSConfig.h b/FreeRTOS/Demo/ARM7_LPC2129_IAR/FreeRTOSConfig.h index 48fdcf066..90109363a 100644 --- a/FreeRTOS/Demo/ARM7_LPC2129_IAR/FreeRTOSConfig.h +++ b/FreeRTOS/Demo/ARM7_LPC2129_IAR/FreeRTOSConfig.h @@ -29,7 +29,9 @@ #define FREERTOS_CONFIG_H /* Hardware specifics. */ -#include +#ifdef __ICCARM__ + #include +#endif /*----------------------------------------------------------- * Application specific definitions. @@ -38,7 +40,7 @@ * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE - * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. + * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. * * See http://www.freertos.org/a00110.html. *----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/Common/Minimal/AbortDelay.c b/FreeRTOS/Demo/Common/Minimal/AbortDelay.c index e18259a08..6ee9d894e 100644 --- a/FreeRTOS/Demo/Common/Minimal/AbortDelay.c +++ b/FreeRTOS/Demo/Common/Minimal/AbortDelay.c @@ -27,7 +27,9 @@ /* * This file contains some test scenarios that ensure tasks respond correctly - * to xTaskAbortDelay() calls. + * to xTaskAbortDelay() calls. It also ensures tasks return the correct state + * of eBlocked when blocked indefinitely in both the case where a task is + * blocked on an object and when a task is blocked on a notification. */ /* Standard includes. */ @@ -39,6 +41,7 @@ #include "queue.h" #include "semphr.h" #include "event_groups.h" +#include "stream_buffer.h" /* Demo includes. */ #include "AbortDelay.h" @@ -68,7 +71,8 @@ build. Remove the whole file if this is not the case. */ #define abtSEMAPHORE_TAKE_ABORTS 4 #define abtEVENT_GROUP_ABORTS 5 #define abtQUEUE_SEND_ABORTS 6 -#define abtMAX_TESTS 7 +#define abtSTREAM_BUFFER_RECEIVE 7 +#define abtMAX_TESTS 8 /*-----------------------------------------------------------*/ @@ -95,6 +99,7 @@ static void prvTestAbortingTaskDelayUntil( void ); static void prvTestAbortingSemaphoreTake( void ); static void prvTestAbortingEventGroupWait( void ); static void prvTestAbortingQueueSend( void ); +static void prvTestAbortingStreamBufferReceive( void ); /* * Checks the amount of time a task spent in the Blocked state is within the @@ -241,6 +246,10 @@ const uint32_t ulMax = 0xffffffffUL; prvTestAbortingQueueSend(); break; + case abtSTREAM_BUFFER_RECEIVE: + prvTestAbortingStreamBufferReceive(); + break; + default: /* Should not get here. */ break; @@ -417,6 +426,75 @@ EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn; } /*-----------------------------------------------------------*/ +static void prvTestAbortingStreamBufferReceive( void ) +{ +TickType_t xTimeAtStart; +StreamBufferHandle_t xStreamBuffer; +EventBits_t xReturn; +const size_t xTriggerLevelBytes = ( size_t ) 1; +uint8_t uxRxData; + + #if( configSUPPORT_STATIC_ALLOCATION == 1 ) + { + /* Defines the memory that will actually hold the streams within the + stream buffer. */ + static uint8_t ucStorageBuffer[ sizeof( configMESSAGE_BUFFER_LENGTH_TYPE ) + 1 ]; + + /* The variable used to hold the stream buffer structure. */ + StaticStreamBuffer_t xStreamBufferStruct; + + + xStreamBuffer = xStreamBufferCreateStatic( sizeof( ucStorageBuffer ), + xTriggerLevelBytes, + ucStorageBuffer, + &xStreamBufferStruct ); + } + #else + { + xStreamBuffer = xStreamBufferCreate( sizeof( uint8_t ), xTriggerLevelBytes ); + configASSERT( xStreamBuffer ); + } + #endif + + /* Note the time before the delay so the length of the delay is known. */ + xTimeAtStart = xTaskGetTickCount(); + + /* This first delay should just time out. */ + xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime ); + if( xReturn != 0x00 ) + { + xErrorOccurred = pdTRUE; + } + prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime ); + + /* Note the time before the delay so the length of the delay is known. */ + xTimeAtStart = xTaskGetTickCount(); + + /* This second delay should be aborted by the primary task half way + through xMaxBlockTime. */ + xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime ); + if( xReturn != 0x00 ) + { + xErrorOccurred = pdTRUE; + } + prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime ); + + /* Note the time before the delay so the length of the delay is known. */ + xTimeAtStart = xTaskGetTickCount(); + + /* This third delay should just time out again. */ + xReturn = xStreamBufferReceive( xStreamBuffer, &uxRxData, sizeof( uxRxData ), xMaxBlockTime ); + if( xReturn != 0x00 ) + { + xErrorOccurred = pdTRUE; + } + prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime ); + + /* Not really necessary in this case, but for completeness. */ + vStreamBufferDelete( xStreamBuffer ); +} +/*-----------------------------------------------------------*/ + static void prvTestAbortingQueueSend( void ) { TickType_t xTimeAtStart; @@ -523,8 +601,8 @@ SemaphoreHandle_t xSemaphore; xTimeAtStart = xTaskGetTickCount(); /* This second delay should be aborted by the primary task half way - through. */ - xReturn = xSemaphoreTake( xSemaphore, xMaxBlockTime ); + through xMaxBlockTime. */ + xReturn = xSemaphoreTake( xSemaphore, portMAX_DELAY ); if( xReturn != pdFALSE ) { xErrorOccurred = pdTRUE; @@ -567,8 +645,8 @@ BaseType_t xReturn; xTimeAtStart = xTaskGetTickCount(); /* This second delay should be aborted by the primary task half way - through. */ - xReturn = xTaskNotifyWait( 0, 0, NULL, xMaxBlockTime ); + through xMaxBlockTime. */ + xReturn = xTaskNotifyWait( 0, 0, NULL, portMAX_DELAY ); if( xReturn != pdFALSE ) { xErrorOccurred = pdTRUE; diff --git a/FreeRTOS/Demo/Common/Minimal/TimerDemo.c b/FreeRTOS/Demo/Common/Minimal/TimerDemo.c index 7e8121ef0..721e80bd7 100644 --- a/FreeRTOS/Demo/Common/Minimal/TimerDemo.c +++ b/FreeRTOS/Demo/Common/Minimal/TimerDemo.c @@ -218,7 +218,6 @@ static TickType_t xIterationsWithoutCounterIncrement = ( TickType_t ) 0, xLastCy { /* The tests appear to be no longer running (stalled). */ xTestStatus = pdFAIL; - configASSERT( xTestStatus ); } } else diff --git a/FreeRTOS/Demo/WIN32-MSVC/main.c b/FreeRTOS/Demo/WIN32-MSVC/main.c index a5efad53f..7692515a2 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main.c @@ -68,7 +68,7 @@ The blinky demo is implemented and described in main_blinky.c. If mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is not 1 then the comprehensive test and demo application will be built. The comprehensive test and demo application is implemented and described in main_full.c. */ -#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0 +#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1 /* This demo uses heap_5.c, and these constants define the sizes of the regions that make up the total heap. heap_5 is only used for test and example purposes diff --git a/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c b/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c index a90731f0e..cdfdbed3f 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c @@ -240,7 +240,7 @@ uint32_t ulReceivedValue; is it an expected value? Normally calling printf() from a task is not a good idea. Here there is lots of stack space and only one task is using console IO so it is ok. However, note the comments at the top of - this file about the risks of making Windows system calls (such as + this file about the risks of making Windows system calls (such as console output) from a FreeRTOS task. */ if( ulReceivedValue == mainVALUE_SENT_FROM_TASK ) { diff --git a/FreeRTOS/Demo/WIN32-MSVC/main_full.c b/FreeRTOS/Demo/WIN32-MSVC/main_full.c index 68488eb37..1d7f5c32c 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main_full.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main_full.c @@ -46,7 +46,7 @@ * in main.c. This file implements the comprehensive test and demo version. * * NOTE 3: This file only contains the source code that is specific to the - * basic demo. Generic functions, such FreeRTOS hook functions, are defined in + * full demo. Generic functions, such FreeRTOS hook functions, are defined in * main.c. ******************************************************************************* * diff --git a/FreeRTOS/Demo/WIN32-MingW/main_full.c b/FreeRTOS/Demo/WIN32-MingW/main_full.c index b8e06d184..f051af45c 100644 --- a/FreeRTOS/Demo/WIN32-MingW/main_full.c +++ b/FreeRTOS/Demo/WIN32-MingW/main_full.c @@ -46,7 +46,7 @@ * in main.c. This file implements the comprehensive test and demo version. * * NOTE 3: This file only contains the source code that is specific to the - * basic demo. Generic functions, such FreeRTOS hook functions, are defined in + * full demo. Generic functions, such FreeRTOS hook functions, are defined in * main.c. ******************************************************************************* * diff --git a/FreeRTOS/Source/stream_buffer.c b/FreeRTOS/Source/stream_buffer.c index 1f053b7dd..f26624ed8 100644 --- a/FreeRTOS/Source/stream_buffer.c +++ b/FreeRTOS/Source/stream_buffer.c @@ -200,7 +200,7 @@ static size_t prvWriteMessageToBuffer( StreamBuffer_t * const pxStreamBuffer, static size_t prvReadBytesFromBuffer( StreamBuffer_t *pxStreamBuffer, uint8_t *pucData, size_t xMaxCount, - size_t xBytesAvailable ); PRIVILEGED_FUNCTION + size_t xBytesAvailable ) PRIVILEGED_FUNCTION; /* * Called by both pxStreamBufferCreate() and pxStreamBufferCreateStatic() to diff --git a/FreeRTOS/Source/tasks.c b/FreeRTOS/Source/tasks.c index 129439cab..b6f4cccd6 100644 --- a/FreeRTOS/Source/tasks.c +++ b/FreeRTOS/Source/tasks.c @@ -1364,11 +1364,30 @@ static void prvAddNewTaskToReadyList( TCB_t *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 blocked indefinitely? */ if( listLIST_ITEM_CONTAINER( &( pxTCB->xEventListItem ) ) == NULL ) { - eReturn = eSuspended; + #if( configUSE_TASK_NOTIFICATIONS == 1 ) + { + /* The task does not appear on the vent list item of + and of the RTOS objects, but could still be in the + blocked state if it is waiting on its notification + rather than waiting on an object. */ + if( pxTCB->ucNotifyState == taskWAITING_NOTIFICATION ) + { + eReturn = eBlocked; + } + else + { + eReturn = eSuspended; + } + } + #else + { + eReturn = eSuspended; + } + #endif } else { @@ -4772,13 +4791,11 @@ TickType_t uxReturn; { *pxHigherPriorityTaskWoken = pdTRUE; } - else - { - /* Mark that a yield is pending in case the user is not - using the "xHigherPriorityTaskWoken" parameter to an ISR - safe FreeRTOS function. */ - xYieldPending = pdTRUE; - } + + /* Mark that a yield is pending in case the user is not + using the "xHigherPriorityTaskWoken" parameter to an ISR + safe FreeRTOS function. */ + xYieldPending = pdTRUE; } else { @@ -4862,13 +4879,11 @@ TickType_t uxReturn; { *pxHigherPriorityTaskWoken = pdTRUE; } - else - { - /* Mark that a yield is pending in case the user is not - using the "xHigherPriorityTaskWoken" parameter in an ISR - safe FreeRTOS function. */ - xYieldPending = pdTRUE; - } + + /* Mark that a yield is pending in case the user is not + using the "xHigherPriorityTaskWoken" parameter in an ISR + safe FreeRTOS function. */ + xYieldPending = pdTRUE; } else { -- 2.39.5