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