]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/main.c
Update version number to 8.1.2 after moving the defaulting of configUSE_PORT_OPTIMISE...
[freertos] / FreeRTOS / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / main.c
1 /*\r
2     FreeRTOS V8.1.2 - Copyright (C) 2014 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     ***************************************************************************\r
8      *                                                                       *\r
9      *    FreeRTOS provides completely free yet professionally developed,    *\r
10      *    robust, strictly quality controlled, supported, and cross          *\r
11      *    platform software that has become a de facto standard.             *\r
12      *                                                                       *\r
13      *    Help yourself get started quickly and support the FreeRTOS         *\r
14      *    project by purchasing a FreeRTOS tutorial book, reference          *\r
15      *    manual, or both from: http://www.FreeRTOS.org/Documentation        *\r
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \r
23     FreeRTOS is free software; you can redistribute it and/or modify it under\r
24     the terms of the GNU General Public License (version 2) as published by the\r
25     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
26 \r
27     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
28     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
29     >>!   obliged to provide the source code for proprietary components     !<<\r
30     >>!   outside of the FreeRTOS kernel.                                   !<<\r
31 \r
32     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
33     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
34     FOR A PARTICULAR PURPOSE.  Full license text is available from the following\r
35     link: http://www.freertos.org/a00114.html\r
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \r
51     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
52     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
53     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
54 \r
55     http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
56     Integrity Systems to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
57     licenses offer ticketed support, indemnification and middleware.\r
58 \r
59     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
60     engineered and independently SIL3 certified version for use in safety and\r
61     mission critical applications that require provable dependability.\r
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*\r
67         NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.\r
68         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
69         called.  The demo applications included in the FreeRTOS.org download switch\r
70         to supervisor mode prior to main being called.  If you are not using one of\r
71         these demo application projects then ensure Supervisor mode is used.\r
72 */\r
73 \r
74 /*\r
75  * This demo includes a (basic) USB mouse driver and a WEB server.  It is\r
76  * targeted for the AT91SAM7X EK prototyping board which includes a small\r
77  * joystick to provide the mouse inputs.  The WEB interface provides some basic\r
78  * interactivity through the use of a check box to turn on and off an LED.\r
79  *\r
80  * main() creates the WEB server, USB, and a set of the standard demo tasks\r
81  * before starting the scheduler.  See the online FreeRTOS.org documentation \r
82  * for more information on the standard demo tasks.  \r
83  *\r
84  * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will \r
85  * toggle at a different fixed frequency.\r
86  *\r
87  * A tick hook function is used to monitor the standard demo tasks - with LED\r
88  * D4 being used to indicate the system status.  D4 toggling every 5 seconds\r
89  * indicates that all the standard demo tasks are executing without error.  The\r
90  * toggle rate increasing to 500ms is indicative of an error having been found\r
91  * in at least one demo task.\r
92  *\r
93  * See the online documentation page that accompanies this demo for full setup\r
94  * and usage information.\r
95  */\r
96 \r
97 /* Standard includes. */\r
98 #include <stdlib.h>\r
99 \r
100 /* Scheduler includes. */\r
101 #include "FreeRTOS.h"\r
102 #include "task.h"\r
103 \r
104 /* Demo application includes. */\r
105 #include "partest.h"\r
106 #include "USBSample.h"\r
107 #include "uIP_Task.h"\r
108 #include "BlockQ.h"\r
109 #include "blocktim.h"\r
110 #include "flash.h"\r
111 #include "QPeek.h"\r
112 #include "dynamic.h"\r
113 \r
114 /* Priorities for the demo application tasks. */\r
115 #define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
116 #define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
117 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
118 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
119 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) \r
120 \r
121 /* The task allocated to the uIP task is large to account for its use of the\r
122 sprintf() library function.  Use of a cut down printf() library would allow\r
123 the stack usage to be greatly reduced. */\r
124 #define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )\r
125 \r
126 /* The LED toggle by the tick hook should an error have been found in a task. */\r
127 #define mainERROR_LED                                           ( 3 )\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 /*\r
132  * Configure the processor for use with the Atmel demo board.  Setup is minimal\r
133  * as the low level init function (called from the startup asm file) takes care\r
134  * of most things.\r
135  */\r
136 static void prvSetupHardware( void );\r
137 \r
138 /*-----------------------------------------------------------*/\r
139 \r
140 /*\r
141  * Starts all the other tasks, then starts the scheduler.\r
142  */\r
143 int main( void )\r
144 {\r
145         /* Setup any hardware that has not already been configured by the low\r
146         level init routines. */\r
147         prvSetupHardware();\r
148 \r
149         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
150     xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
151         \r
152         /* Also start the USB demo which is just for the SAM7. */\r
153     vStartUSBTask( mainUSB_PRIORITY );\r
154         \r
155         /* Start the standard demo tasks. */\r
156         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
157     vCreateBlockTimeTasks();\r
158     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
159     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
160     vStartQueuePeekTasks();   \r
161     vStartDynamicPriorityTasks();\r
162 \r
163         /* Start the scheduler.\r
164 \r
165         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
166         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
167         called.  The demo applications included in the FreeRTOS.org download switch\r
168         to supervisor mode prior to main being called.  If you are not using one of\r
169         these demo application projects then ensure Supervisor mode is used here. */\r
170 \r
171         vTaskStartScheduler();\r
172 \r
173         /* We should never get here as control is now taken by the scheduler. */\r
174         return 0;\r
175 }\r
176 /*-----------------------------------------------------------*/\r
177 \r
178 static void prvSetupHardware( void )\r
179 {\r
180         portDISABLE_INTERRUPTS();\r
181         \r
182         /* When using the JTAG debugger the hardware is not always initialised to\r
183         the correct default state.  This line just ensures that this does not\r
184         cause all interrupts to be masked at the start. */\r
185         AT91C_BASE_AIC->AIC_EOICR = 0;\r
186         \r
187         /* Most setup is performed by the low level init function called from the\r
188         startup asm file. */\r
189 \r
190         /* Enable the peripheral clock. */\r
191     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;\r
192     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;\r
193         AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;\r
194 \r
195         /* Initialise the LED outputs for use by the demo application tasks. */\r
196         vParTestInitialise();\r
197 }\r
198 /*-----------------------------------------------------------*/\r
199 \r
200 void vApplicationTickHook( void )\r
201 {\r
202 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;\r
203 \r
204 /* The rate at which LED D4 will toggle if an error has been found in one or \r
205 more of the standard demo tasks. */\r
206 const unsigned long ulErrorFlashRate = 500 / portTICK_PERIOD_MS;\r
207 \r
208 /* The rate at which LED D4 will toggle if no errors have been found in any\r
209 of the standard demo tasks. */\r
210 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_PERIOD_MS;\r
211 \r
212         ulCallCount++;\r
213 \r
214         if( ulErrorFound != pdFALSE )\r
215         {\r
216                 /* We have already found an error, so flash the LED with the appropriate\r
217                 frequency. */\r
218                 if( ulCallCount > ulErrorFlashRate )\r
219                 {\r
220                         ulCallCount = 0;\r
221                         vParTestToggleLED( mainERROR_LED );\r
222                 }\r
223         }\r
224         else\r
225         {\r
226                 if( ulCallCount > ulNoErrorCheckRate )\r
227                 {\r
228                         ulCallCount = 0;\r
229                         \r
230                         /* We have not yet found an error.  Check all the demo tasks to ensure\r
231                         this is still the case. */\r
232                         \r
233                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
234                         {\r
235                                 ulErrorFound |= 0x01;\r
236                         }\r
237                         \r
238                         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
239                         {\r
240                                 ulErrorFound |= 0x02;\r
241                         }\r
242         \r
243                         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
244                         {\r
245                                 ulErrorFound |= 0x04;\r
246                         }\r
247                         \r
248                         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
249                         {\r
250                                 ulErrorFound |= 0x08;\r
251                         }\r
252                         \r
253                         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
254                         {\r
255                                 ulErrorFound |= 0x10;\r
256                         }\r
257                         \r
258                         vParTestToggleLED( mainERROR_LED );\r
259                 }\r
260         }\r
261 }\r
262 \r
263 \r
264 \r
265 \r