]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/main.c
Update version number ready for V8.2.1 release.
[freertos] / FreeRTOS / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / main.c
1 /*\r
2     FreeRTOS V8.2.1 - Copyright (C) 2015 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         NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.\r
72         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
73         called.  The demo applications included in the FreeRTOS.org download switch\r
74         to supervisor mode prior to main being called.  If you are not using one of\r
75         these demo application projects then ensure Supervisor mode is used.\r
76 */\r
77 \r
78 /*\r
79  * This demo includes a (basic) USB mouse driver and a WEB server.  It is\r
80  * targeted for the AT91SAM7X EK prototyping board which includes a small\r
81  * joystick to provide the mouse inputs.  The WEB interface provides some basic\r
82  * interactivity through the use of a check box to turn on and off an LED.\r
83  *\r
84  * main() creates the WEB server, USB, and a set of the standard demo tasks\r
85  * before starting the scheduler.  See the online FreeRTOS.org documentation \r
86  * for more information on the standard demo tasks.  \r
87  *\r
88  * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will \r
89  * toggle at a different fixed frequency.\r
90  *\r
91  * A tick hook function is used to monitor the standard demo tasks - with LED\r
92  * D4 being used to indicate the system status.  D4 toggling every 5 seconds\r
93  * indicates that all the standard demo tasks are executing without error.  The\r
94  * toggle rate increasing to 500ms is indicative of an error having been found\r
95  * in at least one demo task.\r
96  *\r
97  * See the online documentation page that accompanies this demo for full setup\r
98  * and usage information.\r
99  */\r
100 \r
101 /* Standard includes. */\r
102 #include <stdlib.h>\r
103 \r
104 /* Scheduler includes. */\r
105 #include "FreeRTOS.h"\r
106 #include "task.h"\r
107 \r
108 /* Demo application includes. */\r
109 #include "partest.h"\r
110 #include "USBSample.h"\r
111 #include "uIP_Task.h"\r
112 #include "BlockQ.h"\r
113 #include "blocktim.h"\r
114 #include "flash.h"\r
115 #include "QPeek.h"\r
116 #include "dynamic.h"\r
117 \r
118 /* Priorities for the demo application tasks. */\r
119 #define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
120 #define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
121 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
122 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
123 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) \r
124 \r
125 /* The task allocated to the uIP task is large to account for its use of the\r
126 sprintf() library function.  Use of a cut down printf() library would allow\r
127 the stack usage to be greatly reduced. */\r
128 #define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )\r
129 \r
130 /* The LED toggle by the tick hook should an error have been found in a task. */\r
131 #define mainERROR_LED                                           ( 3 )\r
132 \r
133 /*-----------------------------------------------------------*/\r
134 \r
135 /*\r
136  * Configure the processor for use with the Atmel demo board.  Setup is minimal\r
137  * as the low level init function (called from the startup asm file) takes care\r
138  * of most things.\r
139  */\r
140 static void prvSetupHardware( void );\r
141 \r
142 /*-----------------------------------------------------------*/\r
143 \r
144 /*\r
145  * Starts all the other tasks, then starts the scheduler.\r
146  */\r
147 int main( void )\r
148 {\r
149         /* Setup any hardware that has not already been configured by the low\r
150         level init routines. */\r
151         prvSetupHardware();\r
152 \r
153         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
154     xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
155         \r
156         /* Also start the USB demo which is just for the SAM7. */\r
157     vStartUSBTask( mainUSB_PRIORITY );\r
158         \r
159         /* Start the standard demo tasks. */\r
160         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
161     vCreateBlockTimeTasks();\r
162     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
163     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
164     vStartQueuePeekTasks();   \r
165     vStartDynamicPriorityTasks();\r
166 \r
167         /* Start the scheduler.\r
168 \r
169         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
170         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
171         called.  The demo applications included in the FreeRTOS.org download switch\r
172         to supervisor mode prior to main being called.  If you are not using one of\r
173         these demo application projects then ensure Supervisor mode is used here. */\r
174 \r
175         vTaskStartScheduler();\r
176 \r
177         /* We should never get here as control is now taken by the scheduler. */\r
178         return 0;\r
179 }\r
180 /*-----------------------------------------------------------*/\r
181 \r
182 static void prvSetupHardware( void )\r
183 {\r
184         portDISABLE_INTERRUPTS();\r
185         \r
186         /* When using the JTAG debugger the hardware is not always initialised to\r
187         the correct default state.  This line just ensures that this does not\r
188         cause all interrupts to be masked at the start. */\r
189         AT91C_BASE_AIC->AIC_EOICR = 0;\r
190         \r
191         /* Most setup is performed by the low level init function called from the\r
192         startup asm file. */\r
193 \r
194         /* Enable the peripheral clock. */\r
195     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;\r
196     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;\r
197         AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;\r
198 \r
199         /* Initialise the LED outputs for use by the demo application tasks. */\r
200         vParTestInitialise();\r
201 }\r
202 /*-----------------------------------------------------------*/\r
203 \r
204 void vApplicationTickHook( void )\r
205 {\r
206 static unsigned long ulCallCount = 0, ulErrorFound = pdFALSE;\r
207 \r
208 /* The rate at which LED D4 will toggle if an error has been found in one or \r
209 more of the standard demo tasks. */\r
210 const unsigned long ulErrorFlashRate = 500 / portTICK_PERIOD_MS;\r
211 \r
212 /* The rate at which LED D4 will toggle if no errors have been found in any\r
213 of the standard demo tasks. */\r
214 const unsigned long ulNoErrorCheckRate = 5000 / portTICK_PERIOD_MS;\r
215 \r
216         ulCallCount++;\r
217 \r
218         if( ulErrorFound != pdFALSE )\r
219         {\r
220                 /* We have already found an error, so flash the LED with the appropriate\r
221                 frequency. */\r
222                 if( ulCallCount > ulErrorFlashRate )\r
223                 {\r
224                         ulCallCount = 0;\r
225                         vParTestToggleLED( mainERROR_LED );\r
226                 }\r
227         }\r
228         else\r
229         {\r
230                 if( ulCallCount > ulNoErrorCheckRate )\r
231                 {\r
232                         ulCallCount = 0;\r
233                         \r
234                         /* We have not yet found an error.  Check all the demo tasks to ensure\r
235                         this is still the case. */\r
236                         \r
237                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
238                         {\r
239                                 ulErrorFound |= 0x01;\r
240                         }\r
241                         \r
242                         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
243                         {\r
244                                 ulErrorFound |= 0x02;\r
245                         }\r
246         \r
247                         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
248                         {\r
249                                 ulErrorFound |= 0x04;\r
250                         }\r
251                         \r
252                         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
253                         {\r
254                                 ulErrorFound |= 0x08;\r
255                         }\r
256                         \r
257                         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
258                         {\r
259                                 ulErrorFound |= 0x10;\r
260                         }\r
261                         \r
262                         vParTestToggleLED( mainERROR_LED );\r
263                 }\r
264         }\r
265 }\r
266 \r
267 \r
268 \r
269 \r