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