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