]> git.sur5r.net Git - freertos/blob - Demo/WIN32-MSVC/main.c
Remove unused definitions from the Win32 demo main.c file.
[freertos] / Demo / WIN32-MSVC / main.c
1 /*\r
2     FreeRTOS V6.1.0 - Copyright (C) 2010 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS books - available as PDF or paperback  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public\r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /*\r
55  *******************************************************************************\r
56  * -NOTE- The Win32 port is a simulation (or is that emulation?) only!  Do not\r
57  * expect to get real time behaviour from the Win32 port or this demo\r
58  * application.  It is provided as a convenient development and demonstration\r
59  * test bed only.  Also, at the time of writing, a method of deleting theads \r
60  * has not been implemented, although doing so would be trivial so this\r
61  * functionality might be added in at a later date.  At present, calling \r
62  * vTaskDelete() will delete the real time task from FreeRTOS but not the Win32\r
63  * thread in which the task was executing.  DO NOT CALL vTaskDelete() when using \r
64  * the Win32 port!  This was tested using Windows XP on a dual core laptop.\r
65  *\r
66  * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
67  *******************************************************************************\r
68  *\r
69  * main() creates all the demo application tasks, then starts the scheduler.  \r
70  * The web documentation provides more details of the standard demo application \r
71  * tasks, which provide no particular functionality but do provide a good \r
72  * example of how to use the FreeRTOS API.\r
73  *\r
74  * In addition to the standard demo tasks, the following tasks and tests are\r
75  * defined and/or created within this file:\r
76  *\r
77  * "Check" task - This only executes every five seconds but has a high priority\r
78  * to ensure it gets processor time.  Its main function is to check that all the\r
79  * standard demo tasks are still operational.  While no errors have been\r
80  * discovered the check task will print out "OK" and the current simulated tick\r
81  * time.  If an error is discovered in the execution of a task then the check\r
82  * task will print out an appropriate error message.\r
83  *\r
84  */\r
85 \r
86 \r
87 /* Standard includes. */\r
88 #include <stdio.h>\r
89 \r
90 /* Kernel includes. */\r
91 #include <FreeRTOS.h>\r
92 #include "task.h"\r
93 #include "queue.h"\r
94 \r
95 /* Standard demo includes. */\r
96 #include "partest.h"\r
97 #include "BlockQ.h"\r
98 #include "death.h"\r
99 #include "integer.h"\r
100 #include "semtest.h"\r
101 #include "PollQ.h"\r
102 #include "GenQTest.h"\r
103 #include "QPeek.h"\r
104 #include "recmutex.h"\r
105 #include "flop.h"\r
106 \r
107 /* Priorities at which the tasks are created. */\r
108 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
109 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
110 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
111 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
112 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
113 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
114 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
115 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
116 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
117 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
118 \r
119 /* Task function prototypes. */\r
120 static void prvCheckTask( void *pvParameters );\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 int main( void )\r
125 {\r
126         /* Start the check task as described at the top of this file. */\r
127         xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
128 \r
129         /* Create the standard demo tasks. */\r
130         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
131         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
132         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
133         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
134         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
135         vStartQueuePeekTasks();\r
136         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
137         vStartRecursiveMutexTasks();\r
138 \r
139         /* Start the scheduler itself. */\r
140         vTaskStartScheduler();\r
141 \r
142     /* Should never get here unless there was not enough heap space to create \r
143         the idle and other system tasks. */\r
144     return 0;\r
145 }\r
146 /*-----------------------------------------------------------*/\r
147 \r
148 static void prvCheckTask( void *pvParameters )\r
149 {\r
150 portTickType xNextWakeTime;\r
151 const portTickType xCycleFrequency = 5000 / portTICK_RATE_MS;\r
152 char *pcStatusMessage = "OK";\r
153 \r
154         /* Just to remove compiler warning. */\r
155         ( void ) pvParameters;\r
156 \r
157         /* Initialise xNextWakeTime - this only needs to be done once. */\r
158         xNextWakeTime = xTaskGetTickCount();\r
159 \r
160         for( ;; )\r
161         {\r
162                 /* Place this task in the blocked state until it is time to run again. */\r
163                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
164 \r
165                 /* Check the standard demo tasks are running without error. */\r
166             if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
167             {\r
168                         pcStatusMessage = "Error: IntMath";\r
169             }   \r
170                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
171                 {                       \r
172                         pcStatusMessage = "Error: GenQueue";\r
173                 }\r
174                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
175                 {\r
176                         pcStatusMessage = "Error: QueuePeek";\r
177                 }\r
178                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
179                 {\r
180                         pcStatusMessage = "Error: BlockQueue";\r
181                 }\r
182             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
183             {\r
184                         pcStatusMessage = "Error: SemTest";\r
185             }\r
186             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
187             {\r
188                         pcStatusMessage = "Error: PollQueue";\r
189             }\r
190                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
191                 {\r
192                         pcStatusMessage = "Error: Flop";\r
193                 }\r
194             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
195             {\r
196                         pcStatusMessage = "Error: RecMutex";\r
197                 }\r
198 \r
199                 /* This is the only task that uses stdout so its ok to call printf() \r
200                 directly. */\r
201                 printf( "%s - %d\r\n", pcStatusMessage, xTaskGetTickCount() );\r
202         }\r
203 }\r
204 /*-----------------------------------------------------------*/\r
205 \r
206 void vApplicationIdleHook( void )\r
207 {\r
208         /* Sleep to reduce CPU load, but don't sleep indefinitely if not using \r
209         preemption as as nothing will cause     a task switch. */\r
210         #if( configUSE_PREEMPTION != 0 )\r
211         {\r
212                 SleepEx( INFINITE, TRUE );\r
213         }\r
214         #else\r
215         {\r
216                 const unsigned long ulMSToSleep = 5;\r
217 \r
218                 SleepEx( ulMSToSleep, TRUE );\r
219         }\r
220         #endif\r
221 }\r
222 /*-----------------------------------------------------------*/\r
223 \r
224 void vApplicationMallocFailedHook( void )\r
225 {\r
226         /* Can be implemented if required, but probably not required in this \r
227         environment and running this demo. */\r
228 }\r
229 /*-----------------------------------------------------------*/\r
230 \r
231 void vApplicationStackOverflowHook( void )\r
232 {\r
233         /* Can be implemented if required, but not required in this \r
234         environment and running this demo. */\r
235 }\r
236 \r