From db4de5c790733641bcc5c265178ec3b31104d33d Mon Sep 17 00:00:00 2001 From: richardbarry Date: Fri, 8 Nov 2013 10:11:46 +0000 Subject: [PATCH] Ensure the Win32 demo runs in co-operative mode. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@2091 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- .../DemosModifiedForLowTickRate/recmutex.c | 25 +++++++++--- FreeRTOS/Demo/WIN32-MSVC/main_blinky.c | 8 ++++ FreeRTOS/Demo/WIN32-MSVC/main_full.c | 39 ++++++++++++++----- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/FreeRTOS/Demo/WIN32-MSVC/DemosModifiedForLowTickRate/recmutex.c b/FreeRTOS/Demo/WIN32-MSVC/DemosModifiedForLowTickRate/recmutex.c index 21cfc1dd1..f065dacda 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/DemosModifiedForLowTickRate/recmutex.c +++ b/FreeRTOS/Demo/WIN32-MSVC/DemosModifiedForLowTickRate/recmutex.c @@ -137,7 +137,7 @@ static volatile unsigned portBASE_TYPE uxControllingCycles = 0, uxBlockingCycles /* Handles of the two higher priority tasks, required so they can be resumed (unsuspended). */ -static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle; +static xTaskHandle xControllingTaskHandle, xBlockingTaskHandle, xPollingTaskHandle; /*-----------------------------------------------------------*/ @@ -160,7 +160,7 @@ void vStartRecursiveMutexTasks( void ) { xTaskCreate( prvRecursiveMutexControllingTask, ( signed portCHAR * ) "Rec1Ctrl", configMINIMAL_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle ); xTaskCreate( prvRecursiveMutexBlockingTask, ( signed portCHAR * ) "Rec2Blck", configMINIMAL_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle ); - xTaskCreate( prvRecursiveMutexPollingTask, ( signed portCHAR * ) "Rec3Poll", configMINIMAL_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL ); + xTaskCreate( prvRecursiveMutexPollingTask, ( signed portCHAR * ) "Rec3Poll", configMINIMAL_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, &xPollingTaskHandle ); } } /*-----------------------------------------------------------*/ @@ -223,6 +223,10 @@ unsigned portBASE_TYPE ux; { xErrorOccurred = pdTRUE; } + + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif } /* Having given it back the same number of times as it was taken, we @@ -329,10 +333,17 @@ static void prvRecursiveMutexPollingTask( void *pvParameters ) block indefinitely when it attempts to obtain the mutex, the Controlling task will only block for a fixed period and an error will be latched if the polling task has not returned the - mutex by the time this fixed period has expired. */ + mutex by the time this fixed period has expired. */ vTaskResume( xBlockingTaskHandle ); - vTaskResume( xControllingTaskHandle ); - + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif + + vTaskResume( xControllingTaskHandle ); + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif + /* The other two tasks should now have executed and no longer be suspended. */ if( ( xBlockingIsSuspended == pdTRUE ) || ( xControllingIsSuspended == pdTRUE ) ) @@ -345,6 +356,10 @@ static void prvRecursiveMutexPollingTask( void *pvParameters ) { xErrorOccurred = pdTRUE; } + + #if configUSE_PREEMPTION == 0 + taskYIELD(); + #endif } } diff --git a/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c b/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c index 8e63dc0c8..0ebdbeaae 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main_blinky.c @@ -191,6 +191,10 @@ static void prvQueueSendTask( void *pvParameters ) portTickType xNextWakeTime; const unsigned long ulValueToSend = 100UL; + /* Remove compiler warning in the case that configASSERT() is not + defined. */ + ( void ) pvParameters; + /* Check the task parameter is as expected. */ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_SEND_PARAMETER ); @@ -218,6 +222,10 @@ static void prvQueueReceiveTask( void *pvParameters ) { unsigned long ulReceivedValue; + /* Remove compiler warning in the case that configASSERT() is not + defined. */ + ( void ) pvParameters; + /* Check the task parameter is as expected. */ configASSERT( ( ( unsigned long ) pvParameters ) == mainQUEUE_RECEIVE_PARAMETER ); diff --git a/FreeRTOS/Demo/WIN32-MSVC/main_full.c b/FreeRTOS/Demo/WIN32-MSVC/main_full.c index 91bf1e8f8..1ca3b6986 100644 --- a/FreeRTOS/Demo/WIN32-MSVC/main_full.c +++ b/FreeRTOS/Demo/WIN32-MSVC/main_full.c @@ -190,14 +190,20 @@ int main_full( void ) vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY ); vStartQueuePeekTasks(); vStartMathTasks( mainFLOP_TASK_PRIORITY ); - vStartRecursiveMutexTasks(); - vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); + vStartRecursiveMutexTasks(); vStartCountingSemaphoreTasks(); vStartDynamicPriorityTasks(); vStartQueueSetTasks(); vStartQueueOverwriteTask( mainQUEUE_OVERWRITE_PRIORITY ); xTaskCreate( prvDemoQueueSpaceFunctions, ( signed char * ) "QSpace", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL ); + #if( configUSE_PREEMPTION != 0 ) + { + /* Don't expect these tasks to pass when preemption is not used. */ + vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); + } + #endif + /* The suicide tasks must be created last as they need to know how many tasks were running prior to their creation. This then allows them to ascertain whether or not the correct/expected number of tasks are running at @@ -234,11 +240,17 @@ const portTickType xCycleFrequency = 2500 / portTICK_RATE_MS; vTaskDelayUntil( &xNextWakeTime, xCycleFrequency ); /* Check the standard demo tasks are running without error. */ - if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE ) + #if( configUSE_PREEMPTION != 0 ) { - pcStatusMessage = "Error: TimerDemo"; + /* These tasks are only created when preemption is used. */ + if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE ) + { + pcStatusMessage = "Error: TimerDemo"; + } } - else if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) + #endif + + if( xAreIntegerMathsTaskStillRunning() != pdTRUE ) { pcStatusMessage = "Error: IntMath"; } @@ -280,15 +292,15 @@ const portTickType xCycleFrequency = 2500 / portTICK_RATE_MS; } else if( xAreDynamicPriorityTasksStillRunning() != pdPASS ) { - pcStatusMessage = "Error: Dynamic\r\n"; + pcStatusMessage = "Error: Dynamic"; } else if( xAreQueueSetTasksStillRunning() != pdPASS ) { - pcStatusMessage = "Error: Queue set\r\n"; + pcStatusMessage = "Error: Queue set"; } else if( xIsQueueOverwriteTaskStillRunning() != pdPASS ) { - pcStatusMessage = "Error: Queue overwrite\r\n"; + pcStatusMessage = "Error: Queue overwrite"; } /* This is the only task that uses stdout so its ok to call printf() @@ -371,7 +383,12 @@ void vFullDemoTickHookFunction( void ) { /* Call the periodic timer test, which tests the timer API functions that can be called from an ISR. */ - vTimerPeriodicISRTests(); + #if( configUSE_PREEMPTION != 0 ) + { + /* Only created when preemption is used. */ + vTimerPeriodicISRTests(); + } + #endif /* Call the periodic queue overwrite from ISR demo. */ vQueueOverwritePeriodicISRDemo(); @@ -521,6 +538,10 @@ unsigned portBASE_TYPE uxReturn, x; /* The queue is full, start again. */ xQueueReset( xQueue ); + + #if( configUSE_PREEMPTION == 0 ) + taskYIELD(); + #endif } } -- 2.39.5