]> git.sur5r.net Git - freertos/blob - Demo/ARM9_AT91SAM9XE_IAR/main.c
Prepare for V5.3.1 release.
[freertos] / Demo / ARM9_AT91SAM9XE_IAR / main.c
1 /*\r
2         FreeRTOS.org V5.3.1 - Copyright (C) 2003-2009 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify it\r
7         under the terms of the GNU General Public License (version 2) as published\r
8         by the Free Software Foundation and modified by the FreeRTOS exception.\r
9         **NOTE** The exception to the GPL is included to allow you to distribute a\r
10         combined work that includes FreeRTOS.org without being obliged to provide\r
11         the source code for any proprietary components.  Alternative commercial\r
12         license and support terms are also available upon request.  See the \r
13         licensing section of http://www.FreeRTOS.org for full details.\r
14 \r
15         FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
16         ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
17         FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
18         more details.\r
19 \r
20         You should have received a copy of the GNU General Public License along\r
21         with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59\r
22         Temple Place, Suite 330, Boston, MA  02111-1307  USA.\r
23 \r
24 \r
25         ***************************************************************************\r
26         *                                                                         *\r
27         * Get the FreeRTOS eBook!  See http://www.FreeRTOS.org/Documentation      *\r
28         *                                                                         *\r
29         * This is a concise, step by step, 'hands on' guide that describes both   *\r
30         * general multitasking concepts and FreeRTOS specifics. It presents and   *\r
31         * explains numerous examples that are written using the FreeRTOS API.     *\r
32         * Full source code for all the examples is provided in an accompanying    *\r
33         * .zip file.                                                              *\r
34         *                                                                         *\r
35         ***************************************************************************\r
36 \r
37         1 tab == 4 spaces!\r
38 \r
39         Please ensure to read the configuration and relevant port sections of the\r
40         online documentation.\r
41 \r
42         http://www.FreeRTOS.org - Documentation, latest information, license and\r
43         contact details.\r
44 \r
45         http://www.SafeRTOS.com - A version that is certified for use in safety\r
46         critical systems.\r
47 \r
48         http://www.OpenRTOS.com - Commercial support, development, porting,\r
49         licensing and training services.\r
50 */\r
51 \r
52 /*\r
53  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
54  * documentation provides more details of the standard demo application tasks.\r
55  *\r
56  * A "Check" task is created in addition to the standard demo tasks.    This\r
57  * only executes every three seconds but has a high priority to ensure it gets\r
58  * processor time.  Its main function is to check that all the standard demo\r
59  * tasks are still operational.  If everything is running as expected then the\r
60  * check task will toggle an LED every 3 seconds.  An error being discovered in\r
61  * any task will cause the toggle rate to increase to 500ms.\r
62  *\r
63  */\r
64 \r
65 /* FreeRTOS includes. */\r
66 #include "FreeRTOS.h"\r
67 #include "task.h"\r
68 \r
69 /* Standard demo includes. */\r
70 #include "BlockQ.h"\r
71 #include "blocktim.h"\r
72 #include "countsem.h"\r
73 #include "death.h"\r
74 #include "dynamic.h"\r
75 #include "GenQTest.h"\r
76 #include "integer.h"\r
77 #include "PollQ.h"\r
78 #include "QPeek.h"\r
79 #include "recmutex.h"\r
80 #include "semtest.h"\r
81 #include "ParTest.h"\r
82 #include "comtest2.h"\r
83 \r
84 /* Standard includes. */\r
85 #include <stdio.h>\r
86 \r
87 /* Atmel library includes. */\r
88 #include <pio/pio.h>\r
89 \r
90 /* Priorities for the demo application tasks. */\r
91 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
92 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 0 )\r
93 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
94 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 0 )\r
95 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
96 #define mainCREATOR_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
97 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
98 \r
99 /* The period of the check task both in and out of the presense of an error. */\r
100 #define mainNO_ERROR_PERIOD                     ( 5000 / portTICK_RATE_MS )\r
101 #define mainERROR_PERIOD                        ( 500 / portTICK_RATE_MS );\r
102 \r
103 /* Constants used by the ComTest task. */\r
104 #define mainCOM_TEST_BAUD_RATE          ( 38400 )\r
105 #define mainCOM_TEST_LED                        ( LED_DS1 )\r
106 \r
107 /*-----------------------------------------------------------*/\r
108 \r
109 /* Simple hardware setup required by the demo. */\r
110 static void prvSetupHardware( void );\r
111 \r
112 /* The check task as described at the top of this file. */\r
113 static void prvCheckTask( void *pvParameters );\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 int main()\r
117 {\r
118         /* Perform any hardware setup necessary to run the demo. */\r
119         prvSetupHardware();\r
120         \r
121         /* First create the 'standard demo' tasks.  These exist just to to\r
122         demonstrate API functions being used and test the kernel port.  More\r
123         information is provided on the FreeRTOS.org WEB site. */\r
124         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
125         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
126         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
127         vStartDynamicPriorityTasks();\r
128         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
129         vCreateBlockTimeTasks();\r
130         vStartCountingSemaphoreTasks();\r
131         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
132         vStartQueuePeekTasks();\r
133         vStartRecursiveMutexTasks();\r
134         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
135         \r
136         /* Create the check task - this is the task that checks all the other tasks\r
137         are executing as expected and without reporting any errors. */\r
138         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
139         \r
140         /* The death demo tasks must be started last as the sanity checks performed\r
141         require knowledge of the number of other tasks in the system. */\r
142         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
143         \r
144         /* Start the scheduler.  From this point on the execution will be under\r
145         the control of the kernel. */\r
146         vTaskStartScheduler();\r
147         \r
148         /* Will only get here if there was insufficient heap availale for the\r
149         idle task to be created. */\r
150         for( ;; );\r
151 }\r
152 /*-----------------------------------------------------------*/\r
153 \r
154 static void prvCheckTask( void * pvParameters )\r
155 {\r
156 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;\r
157 static volatile unsigned portLONG ulErrorCode = 0UL;\r
158 \r
159         /* Just to remove the compiler warning. */\r
160         ( void ) pvParameters;\r
161 \r
162         /* Initialise xNextWakeTime prior to its first use.  From this point on\r
163         the value of the variable is handled automatically by the kernel. */\r
164         xNextWakeTime = xTaskGetTickCount();\r
165         \r
166         for( ;; )\r
167         {\r
168                 /* Delay until it is time for this task to execute again. */\r
169                 vTaskDelayUntil( &xNextWakeTime, xPeriod );\r
170                 \r
171                 /* Check all the other tasks in the system - latch any reported errors\r
172                 into the ulErrorCode variable. */\r
173                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
174                 {\r
175                         ulErrorCode |= 0x01UL;\r
176                 }\r
177 \r
178                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
179                 {\r
180                         ulErrorCode |= 0x02UL;\r
181                 }\r
182 \r
183                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
184                 {\r
185                         ulErrorCode |= 0x04UL;\r
186                 }\r
187 \r
188                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
189                 {\r
190                         ulErrorCode |= 0x08UL;\r
191                 }\r
192 \r
193                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
194                 {\r
195                         ulErrorCode |= 0x10UL;\r
196                 }\r
197 \r
198                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
199                 {\r
200                         ulErrorCode |= 0x20UL;\r
201                 }\r
202 \r
203                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
204                 {\r
205                         ulErrorCode |= 0x40UL;\r
206                 }\r
207 \r
208                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
209                 {\r
210                         ulErrorCode |= 0x80UL;\r
211                 }\r
212 \r
213                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
214                 {\r
215                         ulErrorCode |= 0x100UL;\r
216                 }\r
217 \r
218                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
219                 {\r
220                         ulErrorCode |= 0x200UL;\r
221                 }\r
222 \r
223                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
224                 {\r
225                         ulErrorCode |= 0x400UL;\r
226                 }\r
227                 \r
228                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
229                 {\r
230                         ulErrorCode |= 0x800UL;\r
231                 }\r
232                 \r
233                 /* Reduce the block period and in so doing increase the frequency at\r
234                 which this task executes if any errors have been latched.  The increased\r
235                 frequency causes the LED toggle rate to increase and so gives some\r
236                 visual feedback that an error has occurred. */\r
237                 if( ulErrorCode != 0x00 )\r
238                 {\r
239                         xPeriod = mainERROR_PERIOD;\r
240                 }\r
241                 \r
242                 /* Finally toggle the LED. */\r
243                 vParTestToggleLED( LED_POWER );\r
244         }\r
245 }\r
246 /*-----------------------------------------------------------*/\r
247 \r
248 static void prvSetupHardware( void )\r
249 {\r
250 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };\r
251 \r
252         /* Setup the LED outputs. */\r
253         vParTestInitialise();\r
254         \r
255         /* Setup the pins for the UART. */\r
256         PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );  \r
257 }\r