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