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