]> git.sur5r.net Git - freertos/blob - Demo/ARM7_LPC2129_Keil_RVDS/main.c
Ensure LPC1768 demos are correct prior to V5.4.0 release.
[freertos] / Demo / ARM7_LPC2129_Keil_RVDS / main.c
1 /*\r
2         FreeRTOS V5.4.0 - Copyright (C) 2003-2009 Richard Barry.\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         * Looking for a quick start?  Then check out the FreeRTOS eBook!          *\r
29         * See http://www.FreeRTOS.org/Documentation for details                   *\r
30         *                                                                         *\r
31         ***************************************************************************\r
32 \r
33         1 tab == 4 spaces!\r
34 \r
35         Please ensure to read the configuration and relevant port sections of the\r
36         online documentation.\r
37 \r
38         http://www.FreeRTOS.org - Documentation, latest information, license and\r
39         contact details.\r
40 \r
41         http://www.SafeRTOS.com - A version that is certified for use in safety\r
42         critical systems.\r
43 \r
44         http://www.OpenRTOS.com - Commercial support, development, porting,\r
45         licensing and training services.\r
46 */\r
47 \r
48 /* \r
49         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
50         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
51         called.  The demo applications included in the FreeRTOS.org download switch\r
52         to supervisor mode prior to main being called.  If you are not using one of\r
53         these demo application projects then ensure Supervisor mode is used.\r
54 */\r
55 \r
56 \r
57 /*\r
58  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
59  * documentation provides more details of the demo application tasks.\r
60  * \r
61  * Main.c also creates a task called "Check".  This only executes every three \r
62  * seconds but has the highest priority so is guaranteed to get processor time.  \r
63  * Its main function is to check that all the other tasks are still operational.\r
64  * Each task (other than the "flash" tasks) maintains a unique count that is \r
65  * incremented each time the task successfully completes its function.  Should \r
66  * any error occur within such a task the count is permanently halted.  The \r
67  * check task inspects the count of each task to ensure it has changed since\r
68  * the last time the check task executed.  If all the count variables have \r
69  * changed all the tasks are still executing error free, and the check task\r
70  * toggles the onboard LED.  Should any task contain an error at any time \r
71  * the LED toggle rate will change from 3 seconds to 500ms.\r
72  *\r
73  */\r
74 \r
75 /* Standard includes. */\r
76 #include <stdlib.h>\r
77 \r
78 /* Scheduler includes. */\r
79 #include "FreeRTOS.h"\r
80 #include "task.h"\r
81 \r
82 /* Demo application includes. */\r
83 #include "partest.h"\r
84 #include "flash.h"\r
85 #include "integer.h"\r
86 #include "comtest2.h"\r
87 #include "serial.h"\r
88 #include "PollQ.h"\r
89 #include "BlockQ.h"\r
90 #include "semtest.h"\r
91 #include "dynamic.h"\r
92 \r
93 /*-----------------------------------------------------------*/\r
94 \r
95 /* Constants to setup I/O and processor. */\r
96 #define mainTX_ENABLE           ( ( unsigned portLONG ) 0x00010000 )    /* UART1. */\r
97 #define mainRX_ENABLE           ( ( unsigned portLONG ) 0x00040000 )    /* UART1. */\r
98 #define mainBUS_CLK_FULL        ( ( unsigned portCHAR ) 0x01 )\r
99 #define mainLED_TO_OUTPUT       ( ( unsigned portLONG ) 0xff0000 )\r
100 \r
101 /* Constants for the ComTest demo application tasks. */\r
102 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 115200 )\r
103 #define mainCOM_TEST_LED                ( 3 )\r
104 \r
105 /* Priorities for the demo application tasks. */\r
106 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
107 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
108 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
109 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
110 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
111 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
112 \r
113 /* Constants used by the "check" task.  As described at the head of this file\r
114 the check task toggles an LED.  The rate at which the LED flashes is used to\r
115 indicate whether an error has been detected or not.  If the LED toggles every\r
116 3 seconds then no errors have been detected.  If the rate increases to 500ms\r
117 then an error has been detected in at least one of the demo application tasks. */\r
118 #define mainCHECK_LED                           ( 7 )\r
119 #define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
120 #define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )\r
121 \r
122 /*-----------------------------------------------------------*/\r
123 \r
124 /*\r
125  * Checks that all the demo application tasks are still executing without error\r
126  * - as described at the top of the file.\r
127  */\r
128 static portLONG prvCheckOtherTasksAreStillRunning( void );\r
129 \r
130 /*\r
131  * The task that executes at the highest priority and calls \r
132  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
133  * of the file.\r
134  */\r
135 static void vErrorChecks( void *pvParameters );\r
136 \r
137 /*\r
138  * Configure the processor for use with the Keil demo board.  This is very\r
139  * minimal as most of the setup is managed by the settings in the project\r
140  * file.\r
141  */\r
142 static void prvSetupHardware( void );\r
143 \r
144 /*-----------------------------------------------------------*/\r
145 \r
146 \r
147 \r
148 /*\r
149  * Application entry point:\r
150  * Starts all the other tasks, then starts the scheduler. \r
151  */\r
152 int main( void )\r
153 {\r
154         /* Setup the hardware for use with the Keil demo board. */\r
155         prvSetupHardware();\r
156 \r
157         /* Start the demo/test application tasks. */\r
158         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
159         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
160         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
161         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
162         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
163         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
164         vStartDynamicPriorityTasks();\r
165 \r
166         /* Start the check task - which is defined in this file.  This is the task\r
167         that periodically checks to see that all the other tasks are executing \r
168         without error. */\r
169         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
170 \r
171         /* Now all the tasks have been started - start the scheduler.\r
172 \r
173         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
174         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
175         called.  The demo applications included in the FreeRTOS.org download switch\r
176         to supervisor mode prior to main being called.  If you are not using one of\r
177         these demo application projects then ensure Supervisor mode is used here. */\r
178         vTaskStartScheduler();\r
179 \r
180         /* Should never reach here!  If you do then there was not enough heap\r
181         available for the idle task to be created. */\r
182         for( ;; );\r
183 }\r
184 /*-----------------------------------------------------------*/\r
185 \r
186 static void vErrorChecks( void *pvParameters )\r
187 {\r
188 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
189 \r
190         /* Parameters are not used. */\r
191         ( void ) pvParameters;\r
192 \r
193         /* Cycle for ever, delaying then checking all the other tasks are still\r
194         operating without error.  If an error is detected then the delay period\r
195         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
196         the on board LED flash rate will increase.\r
197 \r
198         This task runs at the highest priority. */\r
199 \r
200         for( ;; )\r
201         {\r
202                 /* The period of the delay depends on whether an error has been \r
203                 detected or not.  If an error has been detected then the period\r
204                 is reduced to increase the LED flash rate. */\r
205                 vTaskDelay( xDelayPeriod );\r
206 \r
207                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
208                 {\r
209                         /* An error has been detected in one of the tasks - flash faster. */\r
210                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
211                 }\r
212 \r
213                 /* Toggle the LED before going back to wait for the next cycle. */\r
214                 vParTestToggleLED( mainCHECK_LED );\r
215         }\r
216 }\r
217 /*-----------------------------------------------------------*/\r
218 \r
219 static void prvSetupHardware( void )\r
220 {\r
221         /* Perform the hardware setup required.  This is minimal as most of the\r
222         setup is managed by the settings in the project file. */\r
223 \r
224         /* Configure the UART1 pins.  All other pins remain at their default of 0. */\r
225         PINSEL0 |= mainTX_ENABLE;\r
226         PINSEL0 |= mainRX_ENABLE;\r
227 \r
228         /* LED pins need to be output. */\r
229         IODIR1 = mainLED_TO_OUTPUT;\r
230 \r
231         /* Setup the peripheral bus to be the same as the PLL output. */\r
232         VPBDIV = mainBUS_CLK_FULL;\r
233 }\r
234 /*-----------------------------------------------------------*/\r
235 \r
236 static portLONG prvCheckOtherTasksAreStillRunning( void )\r
237 {\r
238 portLONG lReturn = pdPASS;\r
239 \r
240         /* Check all the demo tasks (other than the flash tasks) to ensure\r
241         that they are all still running, and that none of them have detected\r
242         an error. */\r
243         if( xAreIntegerMathsTaskStillRunning() != pdPASS )\r
244         {\r
245                 lReturn = pdFAIL;\r
246         }\r
247 \r
248         if( xAreComTestTasksStillRunning() != pdPASS )\r
249         {\r
250                 lReturn = pdFAIL;\r
251         }\r
252 \r
253         if( xArePollingQueuesStillRunning() != pdTRUE )\r
254         {\r
255                 lReturn = pdFAIL;\r
256         }\r
257 \r
258         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
259         {\r
260                 lReturn = pdFAIL;\r
261         }\r
262 \r
263         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
264         {\r
265                 lReturn = pdFAIL;\r
266         }\r
267 \r
268         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
269         {\r
270                 lReturn = pdFAIL;\r
271         }\r
272 \r
273         return lReturn;\r
274 }\r
275 /*-----------------------------------------------------------*/\r
276 \r
277 \r