]> git.sur5r.net Git - freertos/blob - Demo/ARM7_LPC2129_Keil_RVDS/main.c
Update Cortex M3 ports to ensure 8 byte alignment.
[freertos] / Demo / ARM7_LPC2129_Keil_RVDS / main.c
1 /*\r
2     FreeRTOS V6.0.1 - Copyright (C) 2009 Real Time Engineers Ltd.\r
3 \r
4     ***************************************************************************\r
5     *                                                                         *\r
6     * If you are:                                                             *\r
7     *                                                                         *\r
8     *    + New to FreeRTOS,                                                   *\r
9     *    + Wanting to learn FreeRTOS or multitasking in general quickly       *\r
10     *    + Looking for basic training,                                        *\r
11     *    + Wanting to improve your FreeRTOS skills and productivity           *\r
12     *                                                                         *\r
13     * then take a look at the FreeRTOS eBook                                  *\r
14     *                                                                         *\r
15     *        "Using the FreeRTOS Real Time Kernel - a Practical Guide"        *\r
16     *                  http://www.FreeRTOS.org/Documentation                  *\r
17     *                                                                         *\r
18     * A pdf reference manual is also available.  Both are usually delivered   *\r
19     * to your inbox within 20 minutes to two hours when purchased between 8am *\r
20     * and 8pm GMT (although please allow up to 24 hours in case of            *\r
21     * exceptional circumstances).  Thank you for your support!                *\r
22     *                                                                         *\r
23     ***************************************************************************\r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \r
27     FreeRTOS is free software; you can redistribute it and/or modify it under\r
28     the terms of the GNU General Public License (version 2) as published by the\r
29     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
30     ***NOTE*** The exception to the GPL is included to allow you to distribute\r
31     a combined work that includes FreeRTOS without being obliged to provide the\r
32     source code for proprietary components outside of the FreeRTOS kernel.\r
33     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT\r
34     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or\r
35     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
36     more details. You should have received a copy of the GNU General Public \r
37     License and the FreeRTOS license exception along with FreeRTOS; if not it \r
38     can be viewed here: http://www.freertos.org/a00114.html and also obtained \r
39     by writing to Richard Barry, contact details for whom are available on the\r
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \r
54 /* \r
55         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
56         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
57         called.  The demo applications included in the FreeRTOS.org download switch\r
58         to supervisor mode prior to main being called.  If you are not using one of\r
59         these demo application projects then ensure Supervisor mode is used.\r
60 */\r
61 \r
62 \r
63 /*\r
64  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
65  * documentation provides more details of the demo application tasks.\r
66  * \r
67  * Main.c also creates a task called "Check".  This only executes every three \r
68  * seconds but has the highest priority so is guaranteed to get processor time.  \r
69  * Its main function is to check that all the other tasks are still operational.\r
70  * Each task (other than the "flash" tasks) maintains a unique count that is \r
71  * incremented each time the task successfully completes its function.  Should \r
72  * any error occur within such a task the count is permanently halted.  The \r
73  * check task inspects the count of each task to ensure it has changed since\r
74  * the last time the check task executed.  If all the count variables have \r
75  * changed all the tasks are still executing error free, and the check task\r
76  * toggles the onboard LED.  Should any task contain an error at any time \r
77  * the LED toggle rate will change from 3 seconds to 500ms.\r
78  *\r
79  */\r
80 \r
81 /* Standard includes. */\r
82 #include <stdlib.h>\r
83 \r
84 /* Scheduler includes. */\r
85 #include "FreeRTOS.h"\r
86 #include "task.h"\r
87 \r
88 /* Demo application includes. */\r
89 #include "partest.h"\r
90 #include "flash.h"\r
91 #include "comtest2.h"\r
92 #include "serial.h"\r
93 #include "PollQ.h"\r
94 #include "BlockQ.h"\r
95 #include "semtest.h"\r
96 #include "dynamic.h"\r
97 \r
98 /*-----------------------------------------------------------*/\r
99 \r
100 /* Constants to setup I/O and processor. */\r
101 #define mainTX_ENABLE           ( ( unsigned portLONG ) 0x00010000 )    /* UART1. */\r
102 #define mainRX_ENABLE           ( ( unsigned portLONG ) 0x00040000 )    /* UART1. */\r
103 #define mainBUS_CLK_FULL        ( ( unsigned portCHAR ) 0x01 )\r
104 #define mainLED_TO_OUTPUT       ( ( unsigned portLONG ) 0xff0000 )\r
105 \r
106 /* Constants for the ComTest demo application tasks. */\r
107 #define mainCOM_TEST_BAUD_RATE  ( ( unsigned portLONG ) 115200 )\r
108 #define mainCOM_TEST_LED                ( 3 )\r
109 \r
110 /* Priorities for the demo application tasks. */\r
111 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
112 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
113 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
114 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
115 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
116 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 3 )\r
117 \r
118 /* Constants used by the "check" task.  As described at the head of this file\r
119 the check task toggles an LED.  The rate at which the LED flashes is used to\r
120 indicate whether an error has been detected or not.  If the LED toggles every\r
121 3 seconds then no errors have been detected.  If the rate increases to 500ms\r
122 then an error has been detected in at least one of the demo application tasks. */\r
123 #define mainCHECK_LED                           ( 7 )\r
124 #define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
125 #define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )\r
126 \r
127 /*-----------------------------------------------------------*/\r
128 \r
129 /*\r
130  * Checks that all the demo application tasks are still executing without error\r
131  * - as described at the top of the file.\r
132  */\r
133 static portLONG prvCheckOtherTasksAreStillRunning( void );\r
134 \r
135 /*\r
136  * The task that executes at the highest priority and calls \r
137  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
138  * of the file.\r
139  */\r
140 static void vErrorChecks( void *pvParameters );\r
141 \r
142 /*\r
143  * Configure the processor for use with the Keil demo board.  This is very\r
144  * minimal as most of the setup is managed by the settings in the project\r
145  * file.\r
146  */\r
147 static void prvSetupHardware( void );\r
148 \r
149 /*-----------------------------------------------------------*/\r
150 \r
151 \r
152 \r
153 /*\r
154  * Application entry point:\r
155  * Starts all the other tasks, then starts the scheduler. \r
156  */\r
157 int main( void )\r
158 {\r
159         /* Setup the hardware for use with the Keil demo board. */\r
160         prvSetupHardware();\r
161 \r
162         /* Start the demo/test application tasks. */\r
163         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
164         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
165         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
166         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
167         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
168         vStartDynamicPriorityTasks();\r
169 \r
170         /* Start the check task - which is defined in this file.  This is the task\r
171         that periodically checks to see that all the other tasks are executing \r
172         without error. */\r
173         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
174 \r
175         /* Now all the tasks have been started - start the scheduler.\r
176 \r
177         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
178         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
179         called.  The demo applications included in the FreeRTOS.org download switch\r
180         to supervisor mode prior to main being called.  If you are not using one of\r
181         these demo application projects then ensure Supervisor mode is used here. */\r
182         vTaskStartScheduler();\r
183 \r
184         /* Should never reach here!  If you do then there was not enough heap\r
185         available for the idle task to be created. */\r
186         for( ;; );\r
187 }\r
188 /*-----------------------------------------------------------*/\r
189 \r
190 static void vErrorChecks( void *pvParameters )\r
191 {\r
192 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
193 \r
194         /* Parameters are not used. */\r
195         ( void ) pvParameters;\r
196 \r
197         /* Cycle for ever, delaying then checking all the other tasks are still\r
198         operating without error.  If an error is detected then the delay period\r
199         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
200         the on board LED flash rate will increase.\r
201 \r
202         This task runs at the highest priority. */\r
203 \r
204         for( ;; )\r
205         {\r
206                 /* The period of the delay depends on whether an error has been \r
207                 detected or not.  If an error has been detected then the period\r
208                 is reduced to increase the LED flash rate. */\r
209                 vTaskDelay( xDelayPeriod );\r
210 \r
211                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
212                 {\r
213                         /* An error has been detected in one of the tasks - flash faster. */\r
214                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
215                 }\r
216 \r
217                 /* Toggle the LED before going back to wait for the next cycle. */\r
218                 vParTestToggleLED( mainCHECK_LED );\r
219         }\r
220 }\r
221 /*-----------------------------------------------------------*/\r
222 \r
223 static void prvSetupHardware( void )\r
224 {\r
225         /* Perform the hardware setup required.  This is minimal as most of the\r
226         setup is managed by the settings in the project file. */\r
227 \r
228         /* Configure the UART1 pins.  All other pins remain at their default of 0. */\r
229         PINSEL0 |= mainTX_ENABLE;\r
230         PINSEL0 |= mainRX_ENABLE;\r
231 \r
232         /* LED pins need to be output. */\r
233         IODIR1 = mainLED_TO_OUTPUT;\r
234 \r
235         /* Setup the peripheral bus to be the same as the PLL output. */\r
236         VPBDIV = mainBUS_CLK_FULL;\r
237 }\r
238 /*-----------------------------------------------------------*/\r
239 \r
240 static portLONG prvCheckOtherTasksAreStillRunning( void )\r
241 {\r
242 portLONG lReturn = pdPASS;\r
243 \r
244         /* Check all the demo tasks (other than the flash tasks) to ensure\r
245         that they are all still running, and that none of them have detected\r
246         an error. */\r
247         if( xAreComTestTasksStillRunning() != pdPASS )\r
248         {\r
249                 lReturn = pdFAIL;\r
250         }\r
251 \r
252         if( xArePollingQueuesStillRunning() != pdTRUE )\r
253         {\r
254                 lReturn = pdFAIL;\r
255         }\r
256 \r
257         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
258         {\r
259                 lReturn = pdFAIL;\r
260         }\r
261 \r
262         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
263         {\r
264                 lReturn = pdFAIL;\r
265         }\r
266 \r
267         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
268         {\r
269                 lReturn = pdFAIL;\r
270         }\r
271 \r
272         return lReturn;\r
273 }\r
274 /*-----------------------------------------------------------*/\r
275 \r
276 \r