]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/WIN32-MingW/main.c
Update version number.
[freertos] / FreeRTOS / Demo / WIN32-MingW / main.c
1 /*\r
2     FreeRTOS V7.5.1 - Copyright (C) 2013 Real Time Engineers Ltd.\r
3 \r
4     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
5 \r
6     ***************************************************************************\r
7      *                                                                       *\r
8      *    FreeRTOS provides completely free yet professionally developed,    *\r
9      *    robust, strictly quality controlled, supported, and cross          *\r
10      *    platform software that has become a de facto standard.             *\r
11      *                                                                       *\r
12      *    Help yourself get started quickly and support the FreeRTOS         *\r
13      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
14      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
15      *                                                                       *\r
16      *    Thank you!                                                         *\r
17      *                                                                       *\r
18     ***************************************************************************\r
19 \r
20     This file is part of the FreeRTOS distribution.\r
21 \r
22     FreeRTOS is free software; you can redistribute it and/or modify it under\r
23     the terms of the GNU General Public License (version 2) as published by the\r
24     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
25 \r
26     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
27     >>! a combined work that includes FreeRTOS without being obliged to provide\r
28     >>! the source code for proprietary components outside of the FreeRTOS\r
29     >>! kernel.\r
30 \r
31     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
32     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
33     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
34     link: http://www.freertos.org/a00114.html\r
35 \r
36     1 tab == 4 spaces!\r
37 \r
38     ***************************************************************************\r
39      *                                                                       *\r
40      *    Having a problem?  Start by reading the FAQ "My application does   *\r
41      *    not run, what could be wrong?"                                     *\r
42      *                                                                       *\r
43      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
44      *                                                                       *\r
45     ***************************************************************************\r
46 \r
47     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
48     license and Real Time Engineers Ltd. contact details.\r
49 \r
50     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
51     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
52     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
53 \r
54     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
55     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
56     licenses offer ticketed support, indemnification and middleware.\r
57 \r
58     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
59     engineered and independently SIL3 certified version for use in safety and\r
60     mission critical applications that require provable dependability.\r
61 \r
62     1 tab == 4 spaces!\r
63 */\r
64 \r
65 /*\r
66  *******************************************************************************\r
67  * -NOTE- The Win32 port is a simulation (or is that emulation?) only!  Do not\r
68  * expect to get real time behaviour from the Win32 port or this demo\r
69  * application.  It is provided as a convenient development and demonstration\r
70  * test bed only.  This was tested using Windows XP on a dual core laptop.\r
71  *\r
72  * - READ THE WEB DOCUMENTATION FOR THIS PORT FOR MORE INFORMATION ON USING IT -\r
73  *******************************************************************************\r
74  *\r
75  * main() creates all the demo application tasks, then starts the scheduler.  \r
76  * The web documentation provides more details of the standard demo application \r
77  * tasks, which provide no particular functionality but do provide a good \r
78  * example of how to use the FreeRTOS API.\r
79  *\r
80  * In addition to the standard demo tasks, the following tasks and tests are\r
81  * defined and/or created within this file:\r
82  *\r
83  * "Check" task - This only executes every five seconds but has a high priority\r
84  * to ensure it gets processor time.  Its main function is to check that all the\r
85  * standard demo tasks are still operational.  While no errors have been\r
86  * discovered the check task will print out "OK" and the current simulated tick\r
87  * time.  If an error is discovered in the execution of a task then the check\r
88  * task will print out an appropriate error message.\r
89  *\r
90  */\r
91 \r
92 \r
93 /* Standard includes. */\r
94 #include <stdio.h>\r
95 \r
96 /* Kernel includes. */\r
97 #include <FreeRTOS.h>\r
98 #include "task.h"\r
99 #include "queue.h"\r
100 \r
101 /* Standard demo includes. */\r
102 #include "BlockQ.h"\r
103 #include "integer.h"\r
104 #include "semtest.h"\r
105 #include "PollQ.h"\r
106 #include "GenQTest.h"\r
107 #include "QPeek.h"\r
108 #include "recmutex.h"\r
109 #include "flop.h"\r
110 \r
111 /* Priorities at which the tasks are created. */\r
112 #define mainCHECK_TASK_PRIORITY         ( configMAX_PRIORITIES - 1 )\r
113 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
114 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
115 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
116 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
117 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
118 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
119 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
120 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
121 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
122 \r
123 /* Task function prototypes. */\r
124 static void prvCheckTask( void *pvParameters );\r
125 \r
126 /*-----------------------------------------------------------*/\r
127 \r
128 int main( void )\r
129 {\r
130         /* Start the check task as described at the top of this file. */\r
131         xTaskCreate( prvCheckTask, ( signed char * ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
132 \r
133         /* Create the standard demo tasks. */\r
134         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
135         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
136         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
137         vStartIntegerMathTasks( mainINTEGER_TASK_PRIORITY );\r
138         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
139         vStartQueuePeekTasks();\r
140         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
141         vStartRecursiveMutexTasks();\r
142 \r
143         /* Start the scheduler itself. */\r
144         vTaskStartScheduler();\r
145 \r
146     /* Should never get here unless there was not enough heap space to create \r
147         the idle and other system tasks. */\r
148     return 0;\r
149 }\r
150 /*-----------------------------------------------------------*/\r
151 \r
152 static void prvCheckTask( void *pvParameters )\r
153 {\r
154 portTickType xNextWakeTime;\r
155 const portTickType xCycleFrequency = 5000 / portTICK_RATE_MS;\r
156 char *pcStatusMessage = "OK";\r
157 \r
158         /* Just to remove compiler warning. */\r
159         ( void ) pvParameters;\r
160 \r
161         /* Initialise xNextWakeTime - this only needs to be done once. */\r
162         xNextWakeTime = xTaskGetTickCount();\r
163 \r
164         for( ;; )\r
165         {\r
166                 /* Place this task in the blocked state until it is time to run again. */\r
167                 vTaskDelayUntil( &xNextWakeTime, xCycleFrequency );\r
168 \r
169                 /* Check the standard demo tasks are running without error. */\r
170             if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
171             {\r
172                         pcStatusMessage = "Error: IntMath";\r
173             }   \r
174                 else if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
175                 {                       \r
176                         pcStatusMessage = "Error: GenQueue";\r
177                 }\r
178                 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
179                 {\r
180                         pcStatusMessage = "Error: QueuePeek";\r
181                 }\r
182                 else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
183                 {\r
184                         pcStatusMessage = "Error: BlockQueue";\r
185                 }\r
186             else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
187             {\r
188                         pcStatusMessage = "Error: SemTest";\r
189             }\r
190             else if( xArePollingQueuesStillRunning() != pdTRUE )\r
191             {\r
192                         pcStatusMessage = "Error: PollQueue";\r
193             }\r
194                 else if( xAreMathsTaskStillRunning() != pdPASS )\r
195                 {\r
196                         pcStatusMessage = "Error: Flop";\r
197                 }\r
198             else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
199             {\r
200                         pcStatusMessage = "Error: RecMutex";\r
201                 }\r
202 \r
203                 /* This is the only task that uses stdout so its ok to call printf() \r
204                 directly. */\r
205                 printf( "%s - %d\r\n", pcStatusMessage, ( int ) xTaskGetTickCount() );\r
206                 fflush( stdout ); /* Required by Eclipse console. */\r
207         }\r
208 }\r
209 /*-----------------------------------------------------------*/\r
210 \r
211 void vApplicationIdleHook( void )\r
212 {\r
213 const unsigned long ulMSToSleep = 5;\r
214 \r
215         /* Sleep to reduce CPU load, but don't sleep indefinitely in case there are\r
216         tasks waiting to be terminated by the idle task. */\r
217         Sleep( ulMSToSleep );\r
218 }\r
219 /*-----------------------------------------------------------*/\r
220 \r
221 void vApplicationMallocFailedHook( void )\r
222 {\r
223         /* Can be implemented if required, but probably not required in this \r
224         environment and running this demo. */\r
225 }\r
226 /*-----------------------------------------------------------*/\r
227 \r
228 void vApplicationStackOverflowHook( void )\r
229 {\r
230         /* Can be implemented if required, but not required in this \r
231         environment and running this demo. */\r
232 }\r
233 \r