]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM9_AT91SAM9XE_IAR/main.c
Change version numbers ready for V8.0.0 release candidate 1 tag.
[freertos] / FreeRTOS / Demo / ARM9_AT91SAM9XE_IAR / main.c
1 /*\r
2     FreeRTOS V8.0.0:rc1 - Copyright (C) 2014 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>! NOTE: The modification to the GPL is included to allow you to distribute\r
28     >>! a combined work that includes FreeRTOS without being obliged to provide\r
29     >>! the source code for proprietary components outside of the FreeRTOS\r
30     >>! kernel.\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*\r
67  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
68  * documentation provides more details of the standard demo application tasks.\r
69  *\r
70  * A "Check" task is created in addition to the standard demo tasks.    This\r
71  * only executes every three seconds but has a high priority to ensure it gets\r
72  * processor time.  Its main function is to check that all the standard demo\r
73  * tasks are still operational.  If everything is running as expected then the\r
74  * check task will toggle an LED every 3 seconds.  An error being discovered in\r
75  * any task will cause the toggle rate to increase to 500ms.\r
76  *\r
77  */\r
78 \r
79 /* FreeRTOS includes. */\r
80 #include "FreeRTOS.h"\r
81 #include "task.h"\r
82 \r
83 /* Standard demo includes. */\r
84 #include "BlockQ.h"\r
85 #include "blocktim.h"\r
86 #include "countsem.h"\r
87 #include "death.h"\r
88 #include "dynamic.h"\r
89 #include "GenQTest.h"\r
90 #include "integer.h"\r
91 #include "PollQ.h"\r
92 #include "QPeek.h"\r
93 #include "recmutex.h"\r
94 #include "semtest.h"\r
95 #include "ParTest.h"\r
96 #include "comtest2.h"\r
97 \r
98 /* Standard includes. */\r
99 #include <stdio.h>\r
100 \r
101 /* Atmel library includes. */\r
102 #include <pio/pio.h>\r
103 \r
104 /* Priorities for the demo application tasks. */\r
105 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
106 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 0 )\r
107 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
108 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 0 )\r
109 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
110 #define mainCREATOR_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
111 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
112 \r
113 /* The period of the check task both in and out of the presense of an error. */\r
114 #define mainNO_ERROR_PERIOD                     ( 5000 / portTICK_RATE_MS )\r
115 #define mainERROR_PERIOD                        ( 500 / portTICK_RATE_MS );\r
116 \r
117 /* Constants used by the ComTest task. */\r
118 #define mainCOM_TEST_BAUD_RATE          ( 38400 )\r
119 #define mainCOM_TEST_LED                        ( LED_DS1 )\r
120 \r
121 /*-----------------------------------------------------------*/\r
122 \r
123 /* Simple hardware setup required by the demo. */\r
124 static void prvSetupHardware( void );\r
125 \r
126 /* The check task as described at the top of this file. */\r
127 static void prvCheckTask( void *pvParameters );\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 int main()\r
131 {\r
132         /* Perform any hardware setup necessary to run the demo. */\r
133         prvSetupHardware();\r
134         \r
135         /* First create the 'standard demo' tasks.  These exist just to to\r
136         demonstrate API functions being used and test the kernel port.  More\r
137         information is provided on the FreeRTOS.org WEB site. */\r
138         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
139         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
140         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
141         vStartDynamicPriorityTasks();\r
142         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
143         vCreateBlockTimeTasks();\r
144         vStartCountingSemaphoreTasks();\r
145         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
146         vStartQueuePeekTasks();\r
147         vStartRecursiveMutexTasks();\r
148         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
149         \r
150         /* Create the check task - this is the task that checks all the other tasks\r
151         are executing as expected and without reporting any errors. */\r
152         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
153         \r
154         /* The death demo tasks must be started last as the sanity checks performed\r
155         require knowledge of the number of other tasks in the system. */\r
156         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
157         \r
158         /* Start the scheduler.  From this point on the execution will be under\r
159         the control of the kernel. */\r
160         vTaskStartScheduler();\r
161         \r
162         /* Will only get here if there was insufficient heap availale for the\r
163         idle task to be created. */\r
164         for( ;; );\r
165 }\r
166 /*-----------------------------------------------------------*/\r
167 \r
168 static void prvCheckTask( void * pvParameters )\r
169 {\r
170 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;\r
171 static volatile unsigned long ulErrorCode = 0UL;\r
172 \r
173         /* Just to remove the compiler warning. */\r
174         ( void ) pvParameters;\r
175 \r
176         /* Initialise xNextWakeTime prior to its first use.  From this point on\r
177         the value of the variable is handled automatically by the kernel. */\r
178         xNextWakeTime = xTaskGetTickCount();\r
179         \r
180         for( ;; )\r
181         {\r
182                 /* Delay until it is time for this task to execute again. */\r
183                 vTaskDelayUntil( &xNextWakeTime, xPeriod );\r
184                 \r
185                 /* Check all the other tasks in the system - latch any reported errors\r
186                 into the ulErrorCode variable. */\r
187                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
188                 {\r
189                         ulErrorCode |= 0x01UL;\r
190                 }\r
191 \r
192                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
193                 {\r
194                         ulErrorCode |= 0x02UL;\r
195                 }\r
196 \r
197                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
198                 {\r
199                         ulErrorCode |= 0x04UL;\r
200                 }\r
201 \r
202                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
203                 {\r
204                         ulErrorCode |= 0x08UL;\r
205                 }\r
206 \r
207                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
208                 {\r
209                         ulErrorCode |= 0x10UL;\r
210                 }\r
211 \r
212                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
213                 {\r
214                         ulErrorCode |= 0x20UL;\r
215                 }\r
216 \r
217                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
218                 {\r
219                         ulErrorCode |= 0x40UL;\r
220                 }\r
221 \r
222                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
223                 {\r
224                         ulErrorCode |= 0x80UL;\r
225                 }\r
226 \r
227                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
228                 {\r
229                         ulErrorCode |= 0x100UL;\r
230                 }\r
231 \r
232                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
233                 {\r
234                         ulErrorCode |= 0x200UL;\r
235                 }\r
236 \r
237                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
238                 {\r
239                         ulErrorCode |= 0x400UL;\r
240                 }\r
241                 \r
242                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
243                 {\r
244                         ulErrorCode |= 0x800UL;\r
245                 }\r
246                 \r
247                 /* Reduce the block period and in so doing increase the frequency at\r
248                 which this task executes if any errors have been latched.  The increased\r
249                 frequency causes the LED toggle rate to increase and so gives some\r
250                 visual feedback that an error has occurred. */\r
251                 if( ulErrorCode != 0x00 )\r
252                 {\r
253                         xPeriod = mainERROR_PERIOD;\r
254                 }\r
255                 \r
256                 /* Finally toggle the LED. */\r
257                 vParTestToggleLED( LED_POWER );\r
258         }\r
259 }\r
260 /*-----------------------------------------------------------*/\r
261 \r
262 static void prvSetupHardware( void )\r
263 {\r
264 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };\r
265 \r
266         /* Setup the LED outputs. */\r
267         vParTestInitialise();\r
268         \r
269         /* Setup the pins for the UART. */\r
270         PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );  \r
271 }\r