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