]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/HCS12_GCC_banked/main.c
Update version numbers in preparation for V8.2.0 release candidate 1.
[freertos] / FreeRTOS / Demo / HCS12_GCC_banked / main.c
1 \r
2 /*\r
3     FreeRTOS V8.2.0rc1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
4     All rights reserved\r
5 \r
6     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
7 \r
8     This file is part of the FreeRTOS distribution.\r
9 \r
10     FreeRTOS is free software; you can redistribute it and/or modify it under\r
11     the terms of the GNU General Public License (version 2) as published by the\r
12     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
13 \r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18 \r
19     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
20     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
21     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
22     link: http://www.freertos.org/a00114.html\r
23 \r
24     1 tab == 4 spaces!\r
25 \r
26     ***************************************************************************\r
27      *                                                                       *\r
28      *    Having a problem?  Start by reading the FAQ "My application does   *\r
29      *    not run, what could be wrong?".  Have you defined configASSERT()?  *\r
30      *                                                                       *\r
31      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
32      *                                                                       *\r
33     ***************************************************************************\r
34 \r
35     ***************************************************************************\r
36      *                                                                       *\r
37      *    FreeRTOS provides completely free yet professionally developed,    *\r
38      *    robust, strictly quality controlled, supported, and cross          *\r
39      *    platform software that is more than just the market leader, it     *\r
40      *    is the industry's de facto standard.                               *\r
41      *                                                                       *\r
42      *    Help yourself get started quickly while simultaneously helping     *\r
43      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
44      *    tutorial book, reference manual, or both:                          *\r
45      *    http://www.FreeRTOS.org/Documentation                              *\r
46      *                                                                       *\r
47     ***************************************************************************\r
48 \r
49     ***************************************************************************\r
50      *                                                                       *\r
51      *   Investing in training allows your team to be as productive as       *\r
52      *   possible as early as possible, lowering your overall development    *\r
53      *   cost, and enabling you to bring a more robust product to market     *\r
54      *   earlier than would otherwise be possible.  Richard Barry is both    *\r
55      *   the architect and key author of FreeRTOS, and so also the world's   *\r
56      *   leading authority on what is the world's most popular real time     *\r
57      *   kernel for deeply embedded MCU designs.  Obtaining your training    *\r
58      *   from Richard ensures your team will gain directly from his in-depth *\r
59      *   product knowledge and years of usage experience.  Contact Real Time *\r
60      *   Engineers Ltd to enquire about the FreeRTOS Masterclass, presented  *\r
61      *   by Richard Barry:  http://www.FreeRTOS.org/contact\r
62      *                                                                       *\r
63     ***************************************************************************\r
64 \r
65     ***************************************************************************\r
66      *                                                                       *\r
67      *    You are receiving this top quality software for free.  Please play *\r
68      *    fair and reciprocate by reporting any suspected issues and         *\r
69      *    participating in the community forum:                              *\r
70      *    http://www.FreeRTOS.org/support                                    *\r
71      *                                                                       *\r
72      *    Thank you!                                                         *\r
73      *                                                                       *\r
74     ***************************************************************************\r
75 \r
76     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
77     license and Real Time Engineers Ltd. contact details.\r
78 \r
79     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
80     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
81     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
82 \r
83     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
84     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
85 \r
86     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
87     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
88     licenses offer ticketed support, indemnification and commercial middleware.\r
89 \r
90     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
91     engineered and independently SIL3 certified version for use in safety and\r
92     mission critical applications that require provable dependability.\r
93 \r
94     1 tab == 4 spaces!\r
95 */\r
96 \r
97 \r
98 /*\r
99  *\r
100  * main() creates all the demo application tasks, then starts the scheduler.\r
101  * The WEB      documentation provides more details of the demo application tasks.\r
102  *\r
103  * main.c also creates a task called "Check".  This only executes every three \r
104  * seconds but has the highest priority so is guaranteed to get processor time.  \r
105  * Its main function is to check that all the other tasks are still operational.\r
106  * Each task (other than the "flash" tasks) maintains a unique count that is \r
107  * incremented each time the task successfully completes its function.  Should \r
108  * any error occur within such a task the count is permanently halted.  The \r
109  * check task inspects the count of each task to ensure it has changed since\r
110  * the last time the check task executed.  If all the count variables have \r
111  * changed all the tasks are still executing error free, and the check task\r
112  * toggles the onboard LED.  Should any task contain an error at any time \r
113  * the LED toggle rate will change from 3 seconds to 500ms.\r
114  *\r
115  * This file also includes the functionality implemented within the \r
116  * standard demo application file integer.c.  This is done to demonstrate the\r
117  * use of an idle hook.  See the documentation within integer.c for the \r
118  * rationale of the integer task functionality.\r
119  * */\r
120 \r
121 /* Kernel includes. */\r
122 #include "FreeRTOS.h"\r
123 #include "task.h"\r
124 #include "queue.h"\r
125 \r
126 #include "cpu.h"\r
127 \r
128 /* special prototypes for memory-banked functions */\r
129 void vStartPolledQueueTasks( unsigned portBASE_TYPE uxPriority );\r
130 portBASE_TYPE xArePollingQueuesStillRunning( void );\r
131 \r
132 /* Demo application includes. */\r
133 #include "flash.h"\r
134 #include "PollQ.h"\r
135 #include "dynamic.h"\r
136 #include "partest.h"\r
137 #include "comtest2.h"\r
138 #include "BlockQ.h"\r
139 #include "integer.h"\r
140 #include "death.h"\r
141 \r
142 \r
143 /*-----------------------------------------------------------\r
144         Definitions.\r
145 -----------------------------------------------------------*/\r
146 \r
147 /* Priorities assigned to demo application tasks. */\r
148 #define mainFLASH_PRIORITY                      ( tskIDLE_PRIORITY + 2 )\r
149 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
150 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
151 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
152 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
153 #define mainDEATH_PRIORITY                      ( tskIDLE_PRIORITY + 1 )\r
154 \r
155 /* LED that is toggled by the check task.  The check task periodically checks\r
156 that all the other tasks are operating without error.  If no errors are found\r
157 the LED is toggled with mainCHECK_PERIOD frequency.  If an error is found \r
158 then the toggle rate increases to mainERROR_CHECK_PERIOD. */\r
159 #define mainCHECK_TASK_LED                      ( 7 )\r
160 #define mainCHECK_PERIOD                        ( ( TickType_t ) 3000 / portTICK_PERIOD_MS  )\r
161 #define mainERROR_CHECK_PERIOD          ( ( TickType_t ) 500 / portTICK_PERIOD_MS )\r
162 \r
163 /* The constants used in the idle task calculation. */\r
164 #define intgCONST1                              ( ( long ) 123 )\r
165 #define intgCONST2                              ( ( long ) 234567 )\r
166 #define intgCONST3                              ( ( long ) -3 )\r
167 #define intgCONST4                              ( ( long ) 7 )\r
168 #define intgEXPECTED_ANSWER             ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )\r
169 \r
170 \r
171 /* Baud rate used by the serial port tasks (ComTest tasks).\r
172 IMPORTANT:  The function COM0_SetBaudRateValue() which is generated by the\r
173 Processor Expert is used to set the baud rate.  As configured in the FreeRTOS\r
174 download this value must be one of the following:\r
175 \r
176 0 to configure for 38400 baud.\r
177 1 to configure for 19200 baud.\r
178 2 to configure for 9600 baud.\r
179 3 to configure for 4800 baud. */\r
180 #define mainCOM_TEST_BAUD_RATE                  ( ( unsigned long ) 2 )\r
181 \r
182 /* LED used by the serial port tasks.  This is toggled on each character Tx,\r
183 and mainCOM_TEST_LED + 1 is toggles on each character Rx. */\r
184 #define mainCOM_TEST_LED                                ( 3 )\r
185 \r
186 /*-----------------------------------------------------------\r
187         Local functions prototypes.\r
188 -----------------------------------------------------------*/\r
189 \r
190 /*\r
191  * The 'Check' task function.  See the explanation at the top of the file.\r
192  */\r
193 static void ATTR_BANK1 vErrorChecks( void* pvParameters );\r
194 \r
195 /*\r
196  * The idle task hook - in which the integer task is implemented.  See the\r
197  * explanation at the top of the file.\r
198  */\r
199 void ATTR_BANK0 vApplicationIdleHook( void );\r
200 \r
201 /*\r
202  * Checks the unique counts of other tasks to ensure they are still operational.\r
203  */\r
204 static long ATTR_BANK0 prvCheckOtherTasksAreStillRunning( void );\r
205 \r
206 \r
207 \r
208 /*-----------------------------------------------------------\r
209         Local variables.\r
210 -----------------------------------------------------------*/\r
211 \r
212 /* A few tasks are defined within this file.  This flag is used to indicate\r
213 their status.  If an error is detected in one of the locally defined tasks then\r
214 this flag is set to pdTRUE. */\r
215 portBASE_TYPE xLocalError = pdFALSE;\r
216 \r
217 \r
218 /*-----------------------------------------------------------*/\r
219 \r
220 /* This is called from startup. */\r
221 int ATTR_BANK0 main ( void )\r
222 {\r
223         /* Start some of the standard demo tasks. */\r
224         vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
225         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
226         vStartDynamicPriorityTasks();\r
227         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
228         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
229         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
230         \r
231         /* Start the locally defined tasks.  There is also a task implemented as\r
232         the idle hook. */\r
233         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
234         \r
235         /* Must be the last demo created. */\r
236         vCreateSuicidalTasks( mainDEATH_PRIORITY );\r
237 \r
238         /* All the tasks have been created - start the scheduler. */\r
239         vTaskStartScheduler();\r
240         \r
241         /* Should not reach here! */\r
242         for( ;; );\r
243         return 0;\r
244 }\r
245 /*-----------------------------------------------------------*/\r
246 \r
247 static void vErrorChecks( void *pvParameters )\r
248 {\r
249 TickType_t xDelayPeriod = mainCHECK_PERIOD;\r
250 TickType_t xLastWakeTime;\r
251 \r
252         /* Initialise xLastWakeTime to ensure the first call to vTaskDelayUntil()\r
253         functions correctly. */\r
254         xLastWakeTime = xTaskGetTickCount();\r
255 \r
256         for( ;; )\r
257         {\r
258                 /* Delay until it is time to execute again.  The delay period is \r
259                 shorter following an error. */\r
260                 vTaskDelayUntil( &xLastWakeTime, xDelayPeriod );\r
261 \r
262                 /* Check all the demo application tasks are executing without \r
263                 error. If an error is found the delay period is shortened - this\r
264                 has the effect of increasing the flash rate of the 'check' task\r
265                 LED. */\r
266                 if( prvCheckOtherTasksAreStillRunning() == pdFAIL )\r
267                 {\r
268                         /* An error has been detected in one of the tasks - flash faster. */\r
269                         xDelayPeriod = mainERROR_CHECK_PERIOD;\r
270                 }\r
271 \r
272                 /* Toggle the LED each cycle round. */\r
273                 vParTestToggleLED( mainCHECK_TASK_LED );\r
274         }\r
275 }\r
276 /*-----------------------------------------------------------*/\r
277 \r
278 static long prvCheckOtherTasksAreStillRunning( void )\r
279 {\r
280 portBASE_TYPE xAllTasksPassed = pdPASS;\r
281 \r
282         if( xArePollingQueuesStillRunning() != pdTRUE )\r
283         {\r
284                 xAllTasksPassed = pdFAIL;\r
285         }\r
286 \r
287         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
288         {\r
289                 xAllTasksPassed = pdFAIL;\r
290         }\r
291 \r
292         if( xAreComTestTasksStillRunning() != pdTRUE )\r
293         {\r
294                 xAllTasksPassed = pdFALSE;\r
295         }\r
296 \r
297         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
298         {\r
299                 xAllTasksPassed = pdFALSE;\r
300         }\r
301         \r
302         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
303         {\r
304                 xAllTasksPassed = pdFALSE;\r
305         }       \r
306 \r
307     if( xIsCreateTaskStillRunning() != pdTRUE )\r
308     {\r
309         xAllTasksPassed = pdFALSE;\r
310     }\r
311 \r
312         /* Also check the status flag for the tasks defined within this function. */\r
313         if( xLocalError != pdFALSE )\r
314         {\r
315                 xAllTasksPassed = pdFAIL;\r
316         }\r
317         \r
318         return xAllTasksPassed;\r
319 }\r
320 /*-----------------------------------------------------------*/\r
321 \r
322 void vApplicationIdleHook( void )\r
323 {\r
324 /* This variable is effectively set to a constant so it is made volatile to\r
325 ensure the compiler does not just get rid of it. */\r
326 volatile long lValue;\r
327 \r
328         /* Keep performing a calculation and checking the result against a constant. */\r
329 \r
330         /* Perform the calculation.  This will store partial value in\r
331         registers, resulting in a good test of the context switch mechanism. */\r
332         lValue = intgCONST1;\r
333         lValue += intgCONST2;\r
334         lValue *= intgCONST3;\r
335         lValue /= intgCONST4;\r
336 \r
337         /* Did we perform the calculation correctly with no corruption? */\r
338         if( lValue != intgEXPECTED_ANSWER )\r
339         {\r
340                 /* Error! */\r
341                 portENTER_CRITICAL();\r
342                         xLocalError = pdTRUE;\r
343                 portEXIT_CRITICAL();\r
344         }\r
345 \r
346         /* Yield in case cooperative scheduling is being used. */\r
347         #if configUSE_PREEMPTION == 0\r
348         {\r
349                 taskYIELD();\r
350         }\r
351         #endif          \r
352 }\r
353 /*-----------------------------------------------------------*/\r
354 \r