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