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