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