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