X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=Demo%2FWIN32-MSVC%2Fmain.c;h=f067143e18b250a23f0987c96c0077060d2db6fb;hb=1e29c3a095310fe360325ef6fbb5c9cd9af709da;hp=3ff9e4d7634c7b51573fe8e2c9306c3239ae7f4f;hpb=a2f9ef937b63d9ffbf33143b66611a97bfcb4c26;p=freertos diff --git a/Demo/WIN32-MSVC/main.c b/Demo/WIN32-MSVC/main.c index 3ff9e4d76..f067143e1 100644 --- a/Demo/WIN32-MSVC/main.c +++ b/Demo/WIN32-MSVC/main.c @@ -1,5 +1,5 @@ /* - FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd. + FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd. *************************************************************************** @@ -86,6 +86,8 @@ #include #include "task.h" #include "queue.h" +#include "timers.h" +#include "semphr.h" /* Standard demo includes. */ #include "BlockQ.h" @@ -98,6 +100,8 @@ #include "flop.h" #include "TimerDemo.h" #include "countsem.h" +#include "death.h" +#include "dynamic.h" /* Priorities at which the tasks are created. */ #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 1 ) @@ -116,6 +120,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() and +semaphore tracing API functions. It has no other purpose. */ +static xSemaphoreHandle xMutexToDelete = NULL; + /*-----------------------------------------------------------*/ int main( void ) @@ -134,6 +145,17 @@ int main( void ) vStartRecursiveMutexTasks(); vStartTimerDemoTask( mainTIMER_TEST_PERIOD ); vStartCountingSemaphoreTasks(); + vStartDynamicPriorityTasks(); + + /* 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 + any given time. */ + vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY ); + + /* Create the semaphore that will be deleted in the idle task hook. This + is done purely to test the use of vSemaphoreDelete(). */ + xMutexToDelete = xSemaphoreCreateMutex(); /* Start the scheduler itself. */ vTaskStartScheduler(); @@ -148,7 +170,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; @@ -202,6 +223,14 @@ char *pcStatusMessage = "OK"; { pcStatusMessage = "Error: CountSem"; } + else if( xIsCreateTaskStillRunning() != pdTRUE ) + { + pcStatusMessage = "Error: Death"; + } + else if( xAreDynamicPriorityTasksStillRunning() != pdPASS ) + { + pcStatusMessage = "Error: Dynamic\r\n"; + } /* This is the only task that uses stdout so its ok to call printf() directly. */ @@ -213,10 +242,63 @@ char *pcStatusMessage = "OK"; void vApplicationIdleHook( void ) { const unsigned long ulMSToSleep = 5; +xTaskHandle xIdleTaskHandle, xTimerTaskHandle; +signed char *pcTaskName; +const unsigned char ucConstQueueNumber = 0xaaU, ucConstTaskNumber = 0x55U; + +/* These three functions are only meant for use by trace code, and not for +direct use from application code, hence their prototypes are not in queue.h. */ +extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber ); +extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue ); +extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue ); +extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle ); +extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask ); /* 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 xTimerGetTimerDaemonTaskHandle() and + xTaskGetIdleTaskHandle() functions. Also try using the function that sets + the task number. */ + xIdleTaskHandle = xTaskGetIdleTaskHandle(); + xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle(); + vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber ); + configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber ); + + /* 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 xMutexToDelete 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( xMutexToDelete != NULL ) + { + /* Before deleting the semaphore, test the function used to set its + number. This would normally only be done from trace software, rather + than application code. */ + vQueueSetQueueNumber( xMutexToDelete, ucConstQueueNumber ); + + /* Before deleting the semaphore, test the functions used to get its + type and number. Again, these would normally only be done from trace + software, rather than application code. */ + configASSERT( ucQueueGetQueueNumber( xMutexToDelete ) == ucConstQueueNumber ); + configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX ); + vSemaphoreDelete( xMutexToDelete ); + xMutexToDelete = NULL; + } } /*-----------------------------------------------------------*/