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