]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM9_AT91SAM9XE_IAR/main.c
19ba96b0dd7c0027d725d17bf368c6cf2c3c5c09
[freertos] / FreeRTOS / Demo / ARM9_AT91SAM9XE_IAR / main.c
1 /*\r
2     FreeRTOS V7.1.1 - Copyright (C) 2012 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     ***************************************************************************\r
45      *                                                                       *\r
46      *    Having a problem?  Start by reading the FAQ "My application does   *\r
47      *    not run, what could be wrong?                                      *\r
48      *                                                                       *\r
49      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
50      *                                                                       *\r
51     ***************************************************************************\r
52 \r
53     \r
54     http://www.FreeRTOS.org - Documentation, training, latest information, \r
55     license and contact details.\r
56     \r
57     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
58     including FreeRTOS+Trace - an indispensable productivity tool.\r
59 \r
60     Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell \r
61     the code with commercial support, indemnification, and middleware, under \r
62     the OpenRTOS brand: http://www.OpenRTOS.com.  High Integrity Systems also\r
63     provide a safety engineered and independently SIL3 certified version under \r
64     the SafeRTOS brand: http://www.SafeRTOS.com.\r
65 */\r
66 \r
67 /*\r
68  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
69  * documentation provides more details of the standard demo application tasks.\r
70  *\r
71  * A "Check" task is created in addition to the standard demo tasks.    This\r
72  * only executes every three seconds but has a high priority to ensure it gets\r
73  * processor time.  Its main function is to check that all the standard demo\r
74  * tasks are still operational.  If everything is running as expected then the\r
75  * check task will toggle an LED every 3 seconds.  An error being discovered in\r
76  * any task will cause the toggle rate to increase to 500ms.\r
77  *\r
78  */\r
79 \r
80 /* FreeRTOS includes. */\r
81 #include "FreeRTOS.h"\r
82 #include "task.h"\r
83 \r
84 /* Standard demo includes. */\r
85 #include "BlockQ.h"\r
86 #include "blocktim.h"\r
87 #include "countsem.h"\r
88 #include "death.h"\r
89 #include "dynamic.h"\r
90 #include "GenQTest.h"\r
91 #include "integer.h"\r
92 #include "PollQ.h"\r
93 #include "QPeek.h"\r
94 #include "recmutex.h"\r
95 #include "semtest.h"\r
96 #include "ParTest.h"\r
97 #include "comtest2.h"\r
98 \r
99 /* Standard includes. */\r
100 #include <stdio.h>\r
101 \r
102 /* Atmel library includes. */\r
103 #include <pio/pio.h>\r
104 \r
105 /* Priorities for the demo application tasks. */\r
106 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
107 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 0 )\r
108 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
109 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 0 )\r
110 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
111 #define mainCREATOR_TASK_PRIORITY       ( tskIDLE_PRIORITY + 3 )\r
112 #define mainGENERIC_QUEUE_PRIORITY      ( tskIDLE_PRIORITY )\r
113 \r
114 /* The period of the check task both in and out of the presense of an error. */\r
115 #define mainNO_ERROR_PERIOD                     ( 5000 / portTICK_RATE_MS )\r
116 #define mainERROR_PERIOD                        ( 500 / portTICK_RATE_MS );\r
117 \r
118 /* Constants used by the ComTest task. */\r
119 #define mainCOM_TEST_BAUD_RATE          ( 38400 )\r
120 #define mainCOM_TEST_LED                        ( LED_DS1 )\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /* Simple hardware setup required by the demo. */\r
125 static void prvSetupHardware( void );\r
126 \r
127 /* The check task as described at the top of this file. */\r
128 static void prvCheckTask( void *pvParameters );\r
129 \r
130 /*-----------------------------------------------------------*/\r
131 int main()\r
132 {\r
133         /* Perform any hardware setup necessary to run the demo. */\r
134         prvSetupHardware();\r
135         \r
136         /* First create the 'standard demo' tasks.  These exist just to to\r
137         demonstrate API functions being used and test the kernel port.  More\r
138         information is provided on the FreeRTOS.org WEB site. */\r
139         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
140         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
141         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
142         vStartDynamicPriorityTasks();\r
143         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
144         vCreateBlockTimeTasks();\r
145         vStartCountingSemaphoreTasks();\r
146         vStartGenericQueueTasks( tskIDLE_PRIORITY );\r
147         vStartQueuePeekTasks();\r
148         vStartRecursiveMutexTasks();\r
149         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
150         \r
151         /* Create the check task - this is the task that checks all the other tasks\r
152         are executing as expected and without reporting any errors. */\r
153         xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL );\r
154         \r
155         /* The death demo tasks must be started last as the sanity checks performed\r
156         require knowledge of the number of other tasks in the system. */\r
157         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
158         \r
159         /* Start the scheduler.  From this point on the execution will be under\r
160         the control of the kernel. */\r
161         vTaskStartScheduler();\r
162         \r
163         /* Will only get here if there was insufficient heap availale for the\r
164         idle task to be created. */\r
165         for( ;; );\r
166 }\r
167 /*-----------------------------------------------------------*/\r
168 \r
169 static void prvCheckTask( void * pvParameters )\r
170 {\r
171 portTickType xNextWakeTime, xPeriod = mainNO_ERROR_PERIOD;\r
172 static volatile unsigned long ulErrorCode = 0UL;\r
173 \r
174         /* Just to remove the compiler warning. */\r
175         ( void ) pvParameters;\r
176 \r
177         /* Initialise xNextWakeTime prior to its first use.  From this point on\r
178         the value of the variable is handled automatically by the kernel. */\r
179         xNextWakeTime = xTaskGetTickCount();\r
180         \r
181         for( ;; )\r
182         {\r
183                 /* Delay until it is time for this task to execute again. */\r
184                 vTaskDelayUntil( &xNextWakeTime, xPeriod );\r
185                 \r
186                 /* Check all the other tasks in the system - latch any reported errors\r
187                 into the ulErrorCode variable. */\r
188                 if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
189                 {\r
190                         ulErrorCode |= 0x01UL;\r
191                 }\r
192 \r
193                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
194                 {\r
195                         ulErrorCode |= 0x02UL;\r
196                 }\r
197 \r
198                 if( xAreCountingSemaphoreTasksStillRunning() != pdTRUE )\r
199                 {\r
200                         ulErrorCode |= 0x04UL;\r
201                 }\r
202 \r
203                 if( xIsCreateTaskStillRunning() != pdTRUE )\r
204                 {\r
205                         ulErrorCode |= 0x08UL;\r
206                 }\r
207 \r
208                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
209                 {\r
210                         ulErrorCode |= 0x10UL;\r
211                 }\r
212 \r
213                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
214                 {\r
215                         ulErrorCode |= 0x20UL;\r
216                 }\r
217 \r
218                 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
219                 {\r
220                         ulErrorCode |= 0x40UL;\r
221                 }\r
222 \r
223                 if( xArePollingQueuesStillRunning() != pdTRUE )\r
224                 {\r
225                         ulErrorCode |= 0x80UL;\r
226                 }\r
227 \r
228                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
229                 {\r
230                         ulErrorCode |= 0x100UL;\r
231                 }\r
232 \r
233                 if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
234                 {\r
235                         ulErrorCode |= 0x200UL;\r
236                 }\r
237 \r
238                 if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
239                 {\r
240                         ulErrorCode |= 0x400UL;\r
241                 }\r
242                 \r
243                 if( xAreComTestTasksStillRunning() != pdTRUE )\r
244                 {\r
245                         ulErrorCode |= 0x800UL;\r
246                 }\r
247                 \r
248                 /* Reduce the block period and in so doing increase the frequency at\r
249                 which this task executes if any errors have been latched.  The increased\r
250                 frequency causes the LED toggle rate to increase and so gives some\r
251                 visual feedback that an error has occurred. */\r
252                 if( ulErrorCode != 0x00 )\r
253                 {\r
254                         xPeriod = mainERROR_PERIOD;\r
255                 }\r
256                 \r
257                 /* Finally toggle the LED. */\r
258                 vParTestToggleLED( LED_POWER );\r
259         }\r
260 }\r
261 /*-----------------------------------------------------------*/\r
262 \r
263 static void prvSetupHardware( void )\r
264 {\r
265 const Pin xPins[] = { PIN_USART0_RXD, PIN_USART0_TXD };\r
266 \r
267         /* Setup the LED outputs. */\r
268         vParTestInitialise();\r
269         \r
270         /* Setup the pins for the UART. */\r
271         PIO_Configure( xPins, PIO_LISTSIZE( xPins ) );  \r
272 }\r