]> git.sur5r.net Git - freertos/blobdiff - Demo/WIN32-MSVC/main.c
Move the MSVC/lwIP code into the main line.
[freertos] / Demo / WIN32-MSVC / main.c
index 70c51bb874c6433ffe2557f289155dfc46a6b56f..6aa0e3270dad056b209e28578e86af7a3eae820b 100644 (file)
@@ -1,38 +1,38 @@
 /*\r
-    FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
+    FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+       \r
 \r
     ***************************************************************************\r
-    *                                                                         *\r
-    * If you are:                                                             *\r
-    *                                                                         *\r
-    *    + New to FreeRTOS,                                                   *\r
-    *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
-    *    + Looking for basic training,                                        *\r
-    *    + Wanting to improve your FreeRTOS skills and productivity           *\r
-    *                                                                         *\r
-    * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
-    *                                                                         *\r
-    *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
-    *                  http://www.FreeRTOS.org/Documentation                  *\r
-    *                                                                         *\r
-    * A pdf reference manual is also available.  Both are usually delivered   *\r
-    * to your inbox within 20 minutes to two hours when purchased between 8am *\r
-    * and 8pm GMT (although please allow up to 24 hours in case of            *\r
-    * exceptional circumstances).  Thank you for your support!                *\r
-    *                                                                         *\r
+     *                                                                       *\r
+     *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
+     *    Complete, revised, and edited pdf reference manuals are also       *\r
+     *    available.                                                         *\r
+     *                                                                       *\r
+     *    Purchasing FreeRTOS documentation will not only help you, by       *\r
+     *    ensuring you get running as quickly as possible and with an        *\r
+     *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
+     *    the FreeRTOS project to continue with its mission of providing     *\r
+     *    professional grade, cross platform, de facto standard solutions    *\r
+     *    for microcontrollers - completely free of charge!                  *\r
+     *                                                                       *\r
+     *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
+     *                                                                       *\r
+     *    Thank you for using FreeRTOS, and thank you for your support!      *\r
+     *                                                                       *\r
     ***************************************************************************\r
 \r
+\r
     This file is part of the FreeRTOS distribution.\r
 \r
     FreeRTOS is free software; you can redistribute it and/or modify it under\r
     the terms of the GNU General Public License (version 2) as published by the\r
     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
-    ***NOTE*** The exception to the GPL is included to allow you to distribute\r
-    a combined work that includes FreeRTOS without being obliged to provide the\r
-    source code for proprietary components outside of the FreeRTOS kernel.\r
-    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
-    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
-    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
+    >>>NOTE<<< The modification to the GPL is included to allow you to\r
+    distribute a combined work that includes FreeRTOS without being obliged to\r
+    provide the source code for proprietary components outside of the FreeRTOS\r
+    kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
+    WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
     more details. You should have received a copy of the GNU General Public\r
     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
  * -NOTE- The Win32 port is a simulation (or is that emulation?) only!  Do not\r
  * expect to get real time behaviour from the Win32 port or this demo\r
  * application.  It is provided as a convenient development and demonstration\r
- * test bed only.  Also, at the time of writing, a method of deleting theads \r
- * has not been implemented, although doing so would be trivial so this\r
- * functionality might be added in at a later date.  At present, calling \r
- * vTaskDelete() will delete the real time task from FreeRTOS but not the Win32\r
- * thread in which the task was executing.  DO NOT CALL vTaskDelete() when using \r
- * the Win32 port!  This was tested using Windows XP on a dual core laptop.\r
+ * test bed only.  This was tested using Windows XP on a dual core laptop.\r
  *\r
  * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
  *******************************************************************************\r
 #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 "partest.h"\r
 #include "BlockQ.h"\r
-#include "death.h"\r
 #include "integer.h"\r
 #include "semtest.h"\r
 #include "PollQ.h"\r
 #include "QPeek.h"\r
 #include "recmutex.h"\r
 #include "flop.h"\r
+#include "TimerDemo.h"\r
+#include "countsem.h"\r
 \r
 /* Priorities at which the tasks are created. */\r
 #define mainCHECK_TASK_PRIORITY                ( configMAX_PRIORITIES - 1 )\r
 #define mainGEN_QUEUE_TASK_PRIORITY    ( tskIDLE_PRIORITY )\r
 #define mainFLOP_TASK_PRIORITY         ( tskIDLE_PRIORITY )\r
 \r
+#define mainTIMER_TEST_PERIOD                  ( 50 )\r
+\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() API\r
+function.  It has no other purpose. */\r
+static xSemaphoreHandle xSemaphoreToDelete = NULL;\r
+\r
 /*-----------------------------------------------------------*/\r
 \r
 int main( void )\r
@@ -135,6 +141,12 @@ int main( void )
        vStartQueuePeekTasks();\r
        vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
        vStartRecursiveMutexTasks();\r
+       vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
+       vStartCountingSemaphoreTasks();\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
+       xSemaphoreToDelete = xSemaphoreCreateMutex();\r
 \r
        /* Start the scheduler itself. */\r
        vTaskStartScheduler();\r
@@ -148,8 +160,7 @@ int main( void )
 static void prvCheckTask( void *pvParameters )\r
 {\r
 portTickType xNextWakeTime;\r
-const portTickType xCycleFrequency = 5000 / portTICK_RATE_MS;\r
-char *pcStatusMessage = "OK";\r
+const portTickType xCycleFrequency = 1000 / portTICK_RATE_MS;\r
 \r
        /* Just to remove compiler warning. */\r
        ( void ) pvParameters;\r
@@ -163,7 +174,11 @@ char *pcStatusMessage = "OK";
                vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
 \r
                /* Check the standard demo tasks are running without error. */\r
-           if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
+               if( xAreTimerDemoTasksStillRunning( xCycleFrequency ) != pdTRUE )\r
+               {\r
+                       pcStatusMessage = "Error: TimerDemo";\r
+               }\r
+           else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
            {\r
                        pcStatusMessage = "Error: IntMath";\r
            }   \r
@@ -195,6 +210,10 @@ char *pcStatusMessage = "OK";
            {\r
                        pcStatusMessage = "Error: RecMutex";\r
                }\r
+               else if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
+               {\r
+                       pcStatusMessage = "Error: CountSem";\r
+               }\r
 \r
                /* This is the only task that uses stdout so its ok to call printf() \r
                directly. */\r
@@ -205,19 +224,42 @@ char *pcStatusMessage = "OK";
 \r
 void vApplicationIdleHook( void )\r
 {\r
-       /* Sleep to reduce CPU load, but don't sleep indefinitely if not using \r
-       preemption as as nothing will cause     a task switch. */\r
-       #if( configUSE_PREEMPTION != 0 )\r
+const unsigned long ulMSToSleep = 5;\r
+xTaskHandle xIdleTaskHandle, xTimerTaskHandle;\r
+signed char *pcTaskName;\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 xTimerGetTimerTaskHandle() and \r
+       xTaskGetIdleTaskHandle() functions. */\r
+       xIdleTaskHandle = xTaskGetIdleTaskHandle();\r
+       xTimerTaskHandle = xTimerGetTimerTaskHandle();\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
-               SleepEx( INFINITE, TRUE );\r
+               pcStatusMessage = "Error:  Returned idle task handle was incorrect";\r
        }\r
-       #else\r
+\r
+       /* Check the timer task handle was returned correctly. */\r
+       pcTaskName = pcTaskGetTaskName( xTimerTaskHandle );\r
+       if( strcmp( pcTaskName, "Tmr Svc" ) != 0 )\r
        {\r
-               const unsigned long ulMSToSleep = 5;\r
+               pcStatusMessage = "Error:  Returned timer task handle was incorrect";\r
+       }\r
 \r
-               SleepEx( ulMSToSleep, TRUE );\r
+       /* If xSemaphoreToDelete 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( xSemaphoreToDelete != NULL )\r
+       {\r
+               vSemaphoreDelete( xSemaphoreToDelete );\r
+               xSemaphoreToDelete = NULL;\r
        }\r
-       #endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -233,4 +275,19 @@ void vApplicationStackOverflowHook( void )
        /* Can be implemented if required, but not required in this \r
        environment and running this demo. */\r
 }\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationTickHook( void )\r
+{\r
+       /* Call the periodic timer test, which tests the timer API functions that\r
+       can be called from an ISR. */\r
+       vTimerPeriodicISRTests();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vAssertCalled( void )\r
+{\r
+       taskDISABLE_INTERRUPTS();\r
+       for( ;; );\r
+}\r
 \r