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