]> begriffs open source - freertos/blob - 20080217/Demo/ARM7_AT91SAM7X256_Eclipse/RTOSDemo/main.c
Prepare Fujitsu ports for release.
[freertos] / 20080217 / Demo / ARM7_AT91SAM7X256_Eclipse / RTOSDemo / main.c
1 /*\r
2         FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.\r
3 \r
4         This file is part of the FreeRTOS.org distribution.\r
5 \r
6         FreeRTOS.org is free software; you can redistribute it and/or modify\r
7         it under the terms of the GNU General Public License as published by\r
8         the Free Software Foundation; either version 2 of the License, or\r
9         (at your option) any later version.\r
10 \r
11         FreeRTOS.org is distributed in the hope that it will be useful,\r
12         but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14         GNU General Public License for more details.\r
15 \r
16         You should have received a copy of the GNU General Public License\r
17         along with FreeRTOS.org; if not, write to the Free Software\r
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
19 \r
20         A special exception to the GPL can be applied should you wish to distribute\r
21         a combined work that includes FreeRTOS.org, without being obliged to provide\r
22         the source code for any proprietary components.  See the licensing section \r
23         of http://www.FreeRTOS.org for full details of how and when the exception\r
24         can be applied.\r
25 \r
26         ***************************************************************************\r
27 \r
28         Please ensure to read the configuration and relevant port sections of the \r
29         online documentation.\r
30 \r
31         +++ http://www.FreeRTOS.org +++\r
32         Documentation, latest information, license and contact details.  \r
33 \r
34         +++ http://www.SafeRTOS.com +++\r
35         A version that is certified for use in safety critical systems.\r
36 \r
37         +++ http://www.OpenRTOS.com +++\r
38         Commercial support, development, porting, licensing and training services.\r
39 \r
40         ***************************************************************************\r
41 */\r
42 \r
43 /*\r
44         NOTE : Tasks run in System mode and the scheduler runs in Supervisor mode.\r
45         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
46         called.  The demo applications included in the FreeRTOS.org download switch\r
47         to supervisor mode prior to main being called.  If you are not using one of\r
48         these demo application projects then ensure Supervisor mode is used.\r
49 */\r
50 \r
51 /*\r
52  * This demo includes a (basic) USB mouse driver and a WEB server.  It is\r
53  * targeted for the AT91SAM7X EK prototyping board which includes a small\r
54  * joystick to provide the mouse inputs.  The WEB interface provides some basic\r
55  * interactivity through the use of a check box to turn on and off an LED.\r
56  *\r
57  * main() creates the WEB server, USB, and a set of the standard demo tasks\r
58  * before starting the scheduler.  See the online FreeRTOS.org documentation \r
59  * for more information on the standard demo tasks.  \r
60  *\r
61  * LEDs D1 to D3 are controlled by the standard 'flash' tasks - each will \r
62  * toggle at a different fixed frequency.\r
63  *\r
64  * A tick hook function is used to monitor the standard demo tasks - with LED\r
65  * D4 being used to indicate the system status.  D4 toggling every 5 seconds\r
66  * indicates that all the standard demo tasks are executing without error.  The\r
67  * toggle rate increasing to 500ms is indicative of an error having been found\r
68  * in at least one demo task.\r
69  *\r
70  * See the online documentation page that accompanies this demo for full setup\r
71  * and usage information.\r
72  */\r
73 \r
74 /* Standard includes. */\r
75 #include <stdlib.h>\r
76 \r
77 /* Scheduler includes. */\r
78 #include "FreeRTOS.h"\r
79 #include "task.h"\r
80 \r
81 /* Demo application includes. */\r
82 #include "partest.h"\r
83 #include "USBSample.h"\r
84 #include "uip_task.h"\r
85 #include "BlockQ.h"\r
86 #include "blocktim.h"\r
87 #include "flash.h"\r
88 #include "QPeek.h"\r
89 #include "dynamic.h"\r
90 \r
91 /* Priorities for the demo application tasks. */\r
92 #define mainUIP_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
93 #define mainUSB_PRIORITY                                        ( tskIDLE_PRIORITY + 2 )\r
94 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 1 )\r
95 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
96 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY ) \r
97 \r
98 /* The task allocated to the uIP task is large to account for its use of the\r
99 sprintf() library function.  Use of a cut down printf() library would allow\r
100 the stack usage to be greatly reduced. */\r
101 #define mainUIP_TASK_STACK_SIZE         ( configMINIMAL_STACK_SIZE * 6 )\r
102 \r
103 /* The LED toggle by the tick hook should an error have been found in a task. */\r
104 #define mainERROR_LED                                           ( 3 )\r
105 \r
106 /*-----------------------------------------------------------*/\r
107 \r
108 /*\r
109  * Configure the processor for use with the Atmel demo board.  Setup is minimal\r
110  * as the low level init function (called from the startup asm file) takes care\r
111  * of most things.\r
112  */\r
113 static void prvSetupHardware( void );\r
114 \r
115 /*-----------------------------------------------------------*/\r
116 \r
117 /*\r
118  * Starts all the other tasks, then starts the scheduler.\r
119  */\r
120 int main( void )\r
121 {\r
122         /* Setup any hardware that has not already been configured by the low\r
123         level init routines. */\r
124         prvSetupHardware();\r
125 \r
126         /* Start the task that handles the TCP/IP and WEB server functionality. */\r
127     xTaskCreate( vuIP_Task, "uIP", mainUIP_TASK_STACK_SIZE, NULL, mainUIP_PRIORITY, NULL );\r
128         \r
129         /* Also start the USB demo which is just for the SAM7. */\r
130     vStartUSBTask( mainUSB_PRIORITY );\r
131         \r
132         /* Start the standard demo tasks. */\r
133         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
134     vCreateBlockTimeTasks();\r
135     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
136     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
137     vStartQueuePeekTasks();   \r
138     vStartDynamicPriorityTasks();\r
139 \r
140         /* Start the scheduler.\r
141 \r
142         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
143         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
144         called.  The demo applications included in the FreeRTOS.org download switch\r
145         to supervisor mode prior to main being called.  If you are not using one of\r
146         these demo application projects then ensure Supervisor mode is used here. */\r
147 \r
148         vTaskStartScheduler();\r
149 \r
150         /* We should never get here as control is now taken by the scheduler. */\r
151         return 0;\r
152 }\r
153 /*-----------------------------------------------------------*/\r
154 \r
155 static void prvSetupHardware( void )\r
156 {\r
157         portDISABLE_INTERRUPTS();\r
158         \r
159         /* When using the JTAG debugger the hardware is not always initialised to\r
160         the correct default state.  This line just ensures that this does not\r
161         cause all interrupts to be masked at the start. */\r
162         AT91C_BASE_AIC->AIC_EOICR = 0;\r
163         \r
164         /* Most setup is performed by the low level init function called from the\r
165         startup asm file. */\r
166 \r
167         /* Enable the peripheral clock. */\r
168     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOA;\r
169     AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_PIOB;\r
170         AT91C_BASE_PMC->PMC_PCER = 1 << AT91C_ID_EMAC;\r
171 \r
172         /* Initialise the LED outputs for use by the demo application tasks. */\r
173         vParTestInitialise();\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 void vApplicationTickHook( void )\r
178 {\r
179 static unsigned portLONG ulCallCount = 0, ulErrorFound = pdFALSE;\r
180 \r
181 /* The rate at which LED D4 will toggle if an error has been found in one or \r
182 more of the standard demo tasks. */\r
183 const unsigned portLONG ulErrorFlashRate = 500 / portTICK_RATE_MS;\r
184 \r
185 /* The rate at which LED D4 will toggle if no errors have been found in any\r
186 of the standard demo tasks. */\r
187 const unsigned portLONG ulNoErrorCheckRate = 5000 / portTICK_RATE_MS;\r
188 \r
189         ulCallCount++;\r
190 \r
191         if( ulErrorFound != pdFALSE )\r
192         {\r
193                 /* We have already found an error, so flash the LED with the appropriate\r
194                 frequency. */\r
195                 if( ulCallCount > ulErrorFlashRate )\r
196                 {\r
197                         ulCallCount = 0;\r
198                         vParTestToggleLED( mainERROR_LED );\r
199                 }\r
200         }\r
201         else\r
202         {\r
203                 if( ulCallCount > ulNoErrorCheckRate )\r
204                 {\r
205                         ulCallCount = 0;\r
206                         \r
207                         /* We have not yet found an error.  Check all the demo tasks to ensure\r
208                         this is still the case. */\r
209                         \r
210                         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
211                         {\r
212                                 ulErrorFound |= 0x01;\r
213                         }\r
214                         \r
215                         if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
216                         {\r
217                                 ulErrorFound |= 0x02;\r
218                         }\r
219         \r
220                         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
221                         {\r
222                                 ulErrorFound |= 0x04;\r
223                         }\r
224                         \r
225                         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
226                         {\r
227                                 ulErrorFound |= 0x08;\r
228                         }\r
229                         \r
230                         if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
231                         {\r
232                                 ulErrorFound |= 0x10;\r
233                         }\r
234                         \r
235                         vParTestToggleLED( mainERROR_LED );\r
236                 }\r
237         }\r
238 }\r
239 \r
240 \r
241 \r
242 \r