]> git.sur5r.net Git - freertos/blobdiff - Demo/WIN32-MSVC/main.c
Add a few lines to the RX ports that allow the vector to be installed when the FreeRT...
[freertos] / Demo / WIN32-MSVC / main.c
index 3ff9e4d7634c7b51573fe8e2c9306c3239ae7f4f..f067143e18b250a23f0987c96c0077060d2db6fb 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-    FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+    FreeRTOS V7.1.0 - Copyright (C) 2011 Real Time Engineers Ltd.\r
        \r
 \r
     ***************************************************************************\r
@@ -86,6 +86,8 @@
 #include <FreeRTOS.h>\r
 #include "task.h"\r
 #include "queue.h"\r
+#include "timers.h"\r
+#include "semphr.h"\r
 \r
 /* Standard demo includes. */\r
 #include "BlockQ.h"\r
 #include "flop.h"\r
 #include "TimerDemo.h"\r
 #include "countsem.h"\r
+#include "death.h"\r
+#include "dynamic.h"\r
 \r
 /* Priorities at which the tasks are created. */\r
 #define mainCHECK_TASK_PRIORITY                ( configMAX_PRIORITIES - 1 )\r
 /* Task function prototypes. */\r
 static void prvCheckTask( void *pvParameters );\r
 \r
+/* The variable into which error messages are latched. */\r
+static char *pcStatusMessage = "OK";\r
+\r
+/* This semaphore is created purely to test using the vSemaphoreDelete() and\r
+semaphore tracing API functions.  It has no other purpose. */\r
+static xSemaphoreHandle xMutexToDelete = NULL;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 int main( void )\r
@@ -134,6 +145,17 @@ int main( void )
        vStartRecursiveMutexTasks();\r
        vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
        vStartCountingSemaphoreTasks();\r
+       vStartDynamicPriorityTasks();\r
+\r
+       /* The suicide tasks must be created last as they need to know how many\r
+       tasks were running prior to their creation.  This then allows them to \r
+       ascertain whether or not the correct/expected number of tasks are running at \r
+       any given time. */\r
+       vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
+\r
+       /* Create the semaphore that will be deleted in the idle task hook.  This\r
+       is done purely to test the use of vSemaphoreDelete(). */\r
+       xMutexToDelete = xSemaphoreCreateMutex();\r
 \r
        /* Start the scheduler itself. */\r
        vTaskStartScheduler();\r
@@ -148,7 +170,6 @@ static void prvCheckTask( void *pvParameters )
 {\r
 portTickType xNextWakeTime;\r
 const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;\r
-char *pcStatusMessage = "OK";\r
 \r
        /* Just to remove compiler warning. */\r
        ( void ) pvParameters;\r
@@ -202,6 +223,14 @@ char *pcStatusMessage = "OK";
                {\r
                        pcStatusMessage = "Error: CountSem";\r
                }\r
+               else if( xIsCreateTaskStillRunning() != pdTRUE )\r
+               {\r
+                       pcStatusMessage = "Error: Death";\r
+               }\r
+               else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
+               {\r
+                       pcStatusMessage = "Error: Dynamic\r\n";\r
+               }\r
 \r
                /* This is the only task that uses stdout so its ok to call printf() \r
                directly. */\r
@@ -213,10 +242,63 @@ char *pcStatusMessage = "OK";
 void vApplicationIdleHook( void )\r
 {\r
 const unsigned long ulMSToSleep = 5;\r
+xTaskHandle xIdleTaskHandle, xTimerTaskHandle;\r
+signed char *pcTaskName;\r
+const unsigned char ucConstQueueNumber = 0xaaU, ucConstTaskNumber = 0x55U;\r
+\r
+/* These three functions are only meant for use by trace code, and not for\r
+direct use from application code, hence their prototypes are not in queue.h. */\r
+extern void vQueueSetQueueNumber( xQueueHandle pxQueue, unsigned char ucQueueNumber );\r
+extern unsigned char ucQueueGetQueueNumber( xQueueHandle pxQueue );\r
+extern unsigned char ucQueueGetQueueType( xQueueHandle pxQueue );\r
+extern void vTaskSetTaskNumber( xTaskHandle xTask, unsigned portBASE_TYPE uxHandle );\r
+extern unsigned portBASE_TYPE uxTaskGetTaskNumber( xTaskHandle xTask );\r
 \r
        /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
        tasks waiting to be terminated by the idle task. */\r
        Sleep( ulMSToSleep );\r
+\r
+       /* Demonstrate the use of the xTimerGetTimerDaemonTaskHandle() and \r
+       xTaskGetIdleTaskHandle() functions.  Also try using the function that sets\r
+       the task number. */\r
+       xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
+       xTimerTaskHandle = xTimerGetTimerDaemonTaskHandle();\r
+       vTaskSetTaskNumber( xIdleTaskHandle, ( unsigned long ) ucConstTaskNumber );\r
+       configASSERT( uxTaskGetTaskNumber( xIdleTaskHandle ) == ucConstTaskNumber );\r
+\r
+       /* This is the idle hook, so the current task handle should equal the \r
+       returned idle task handle. */\r
+       if( xTaskGetCurrentTaskHandle() != xIdleTaskHandle )\r
+       {\r
+               pcStatusMessage = "Error:  Returned idle task handle was incorrect";\r
+       }\r
+\r
+       /* Check the timer task handle was returned correctly. */\r
+       pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );\r
+       if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
+       {\r
+               pcStatusMessage = "Error:  Returned timer task handle was incorrect";\r
+       }\r
+\r
+       /* If xMutexToDelete has not already been deleted, then delete it now.\r
+       This is done purely to demonstrate the use of, and test, the \r
+       vSemaphoreDelete() macro.  Care must be taken not to delete a semaphore\r
+       that has tasks blocked on it. */\r
+       if( xMutexToDelete != NULL )\r
+       {\r
+               /* Before deleting the semaphore, test the function used to set its\r
+               number.  This would normally only be done from trace software, rather\r
+               than application code. */\r
+               vQueueSetQueueNumber( xMutexToDelete, ucConstQueueNumber );\r
+\r
+               /* Before deleting the semaphore, test the functions used to get its\r
+               type and number.  Again, these would normally only be done from trace\r
+               software, rather than application code. */\r
+               configASSERT( ucQueueGetQueueNumber( xMutexToDelete ) == ucConstQueueNumber );\r
+               configASSERT( ucQueueGetQueueType( xMutexToDelete ) == queueQUEUE_TYPE_MUTEX );\r
+               vSemaphoreDelete( xMutexToDelete );\r
+               xMutexToDelete = NULL;\r
+       }\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r