From: richardbarry Date: Wed, 27 Jul 2011 14:16:24 +0000 (+0000) Subject: Add test/demonstration calls to xTaskGetIdleTaskHandle(), xTimerGetTimerTaskHandle... X-Git-Tag: V7.0.2~96 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d42623c440f0c169c03009d9b66339f09c6972de;p=freertos Add test/demonstration calls to xTaskGetIdleTaskHandle(), xTimerGetTimerTaskHandle, pcTaskGetTaskName() and vQueueDelete() functions to the Win32 demo project. git-svn-id: https://svn.code.sf.net/p/freertos/code/trunk@1514 1d2547de-c912-0410-9cb9-b8ca96c0e9e2 --- diff --git a/Demo/WIN32-MSVC/FreeRTOSConfig.h b/Demo/WIN32-MSVC/FreeRTOSConfig.h index d946a0766..a8e04ae6e 100644 --- a/Demo/WIN32-MSVC/FreeRTOSConfig.h +++ b/Demo/WIN32-MSVC/FreeRTOSConfig.h @@ -111,6 +111,8 @@ to exclude the API function. */ #define INCLUDE_vTaskDelay 1 #define INCLUDE_uxTaskGetStackHighWaterMark 1 #define INCLUDE_xTaskGetSchedulerState 1 +#define INCLUDE_xTimerGetTimerTaskHandle 1 +#define INCLUDE_xTaskGetIdleTaskHandle 1 extern void vAssertCalled( void ); #define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled() diff --git a/Demo/WIN32-MSVC/WIN32.suo b/Demo/WIN32-MSVC/WIN32.suo index 6f3cdfbcd..481e87bf0 100644 Binary files a/Demo/WIN32-MSVC/WIN32.suo and b/Demo/WIN32-MSVC/WIN32.suo differ diff --git a/Demo/WIN32-MSVC/main.c b/Demo/WIN32-MSVC/main.c index 3ff9e4d76..6aa0e3270 100644 --- a/Demo/WIN32-MSVC/main.c +++ b/Demo/WIN32-MSVC/main.c @@ -86,6 +86,8 @@ #include #include "task.h" #include "queue.h" +#include "timers.h" +#include "semphr.h" /* Standard demo includes. */ #include "BlockQ.h" @@ -116,6 +118,13 @@ /* Task function prototypes. */ static void prvCheckTask( void *pvParameters ); +/* The variable into which error messages are latched. */ +static char *pcStatusMessage = "OK"; + +/* This semaphore is created purely to test using the vSemaphoreDelete() API +function. It has no other purpose. */ +static xSemaphoreHandle xSemaphoreToDelete = NULL; + /*-----------------------------------------------------------*/ int main( void ) @@ -135,6 +144,10 @@ int main( void ) vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); vStartCountingSemaphoreTasks(); + /* Create the semaphore that will be deleted in the idle task hook. This + is done purely to test the use of vSemaphoreDelete(). */ + xSemaphoreToDelete = xSemaphoreCreateMutex(); + /* Start the scheduler itself. */ vTaskStartScheduler(); @@ -148,7 +161,6 @@ static void prvCheckTask( void *pvParameters ) { portTickType xNextWakeTime; const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS; -char *pcStatusMessage = "OK"; /* Just to remove compiler warning. */ ( void ) pvParameters; @@ -213,10 +225,41 @@ char *pcStatusMessage = "OK"; void vApplicationIdleHook( void ) { const unsigned long ulMSToSleep = 5; +xTaskHandle xIdleTaskHandle, xTimerTaskHandle; +signed char *pcTaskName; /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are tasks waiting to be terminated by the idle task. */ Sleep( ulMSToSleep ); + + /* Demonstrate the use of the xTimerGetTimerTaskHandle() and + xTaskGetIdleTaskHandle() functions. */ + xIdleTaskHandle = xTaskGetIdleTaskHandle(); + xTimerTaskHandle = xTimerGetTimerTaskHandle(); + + /* This is the idle hook, so the current task handle should equal the + returned idle task handle. */ + if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle ) + { + pcStatusMessage = "Error: Returned idle task handle was incorrect"; + } + + /* Check the timer task handle was returned correctly. */ + pcTaskName = pcTaskGetTaskName( xTimerTaskHandle ); + if( strcmp( pcTaskName, "Tmr Svc" ) != 0 ) + { + pcStatusMessage = "Error: Returned timer task handle was incorrect"; + } + + /* If xSemaphoreToDelete has not already been deleted, then delete it now. + This is done purely to demonstrate the use of, and test, the + vSemaphoreDelete() macro. Care must be taken not to delete a semaphore + that has tasks blocked on it. */ + if( xSemaphoreToDelete != NULL ) + { + vSemaphoreDelete( xSemaphoreToDelete ); + xSemaphoreToDelete = NULL; + } } /*-----------------------------------------------------------*/