]> git.sur5r.net Git - freertos/blob - Demo/ARM7_LPC2129_Keil_RVDS/main.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / ARM7_LPC2129_Keil_RVDS / 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 /*\r
59  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
60  * documentation provides more details of the demo application tasks.\r
61  * \r
62  * Main.c also creates a task called "Check".  This only executes every three \r
63  * seconds but has the highest priority so is guaranteed to get processor time.  \r
64  * Its main function is to check that all the other tasks are still operational.\r
65  * Each task (other than the "flash" tasks) maintains a unique count that is \r
66  * incremented each time the task successfully completes its function.  Should \r
67  * any error occur within such a task the count is permanently halted.  The \r
68  * check task inspects the count of each task to ensure it has changed since\r
69  * the last time the check task executed.  If all the count variables have \r
70  * changed all the tasks are still executing error free, and the check task\r
71  * toggles the onboard LED.  Should any task contain an error at any time \r
72  * the LED toggle rate will change from 3 seconds to 500ms.\r
73  *\r
74  */\r
75 \r
76 /* Standard includes. */\r
77 #include <stdlib.h>\r
78 \r
79 /* Scheduler includes. */\r
80 #include "FreeRTOS.h"\r
81 #include "task.h"\r
82 \r
83 /* Demo application includes. */\r
84 #include "partest.h"\r
85 #include "flash.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 + 2 )\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 + 3 )\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         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
159         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
160         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
161         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
162         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
163         vStartDynamicPriorityTasks();\r
164 \r
165         /* Start the check task - which is defined in this file.  This is the task\r
166         that periodically checks to see that all the other tasks are executing \r
167         without error. */\r
168         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
169 \r
170         /* Now all the tasks have been started - start the scheduler.\r
171 \r
172         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
173         The processor MUST be in supervisor mode when vTaskStartScheduler is \r
174         called.  The demo applications included in the FreeRTOS.org download switch\r
175         to supervisor mode prior to main being called.  If you are not using one of\r
176         these demo application projects then ensure Supervisor mode is used here. */\r
177         vTaskStartScheduler();\r
178 \r
179         /* Should never reach here!  If you do then there was not enough heap\r
180         available for the idle task to be created. */\r
181         for( ;; );\r
182 }\r
183 /*-----------------------------------------------------------*/\r
184 \r
185 static void vErrorChecks( void *pvParameters )\r
186 {\r
187 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
188 \r
189         /* Parameters are not used. */\r
190         ( void ) pvParameters;\r
191 \r
192         /* Cycle for ever, delaying then checking all the other tasks are still\r
193         operating without error.  If an error is detected then the delay period\r
194         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
195         the on board LED flash rate will increase.\r
196 \r
197         This task runs at the highest priority. */\r
198 \r
199         for( ;; )\r
200         {\r
201                 /* The period of the delay depends on whether an error has been \r
202                 detected or not.  If an error has been detected then the period\r
203                 is reduced to increase the LED flash rate. */\r
204                 vTaskDelay( xDelayPeriod );\r
205 \r
206                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
207                 {\r
208                         /* An error has been detected in one of the tasks - flash faster. */\r
209                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
210                 }\r
211 \r
212                 /* Toggle the LED before going back to wait for the next cycle. */\r
213                 vParTestToggleLED( mainCHECK_LED );\r
214         }\r
215 }\r
216 /*-----------------------------------------------------------*/\r
217 \r
218 static void prvSetupHardware( void )\r
219 {\r
220         /* Perform the hardware setup required.  This is minimal as most of the\r
221         setup is managed by the settings in the project file. */\r
222 \r
223         /* Configure the UART1 pins.  All other pins remain at their default of 0. */\r
224         PINSEL0 |= mainTX_ENABLE;\r
225         PINSEL0 |= mainRX_ENABLE;\r
226 \r
227         /* LED pins need to be output. */\r
228         IODIR1 = mainLED_TO_OUTPUT;\r
229 \r
230         /* Setup the peripheral bus to be the same as the PLL output. */\r
231         VPBDIV = mainBUS_CLK_FULL;\r
232 }\r
233 /*-----------------------------------------------------------*/\r
234 \r
235 static portLONG prvCheckOtherTasksAreStillRunning( void )\r
236 {\r
237 portLONG lReturn = pdPASS;\r
238 \r
239         /* Check all the demo tasks (other than the flash tasks) to ensure\r
240         that they are all still running, and that none of them have detected\r
241         an error. */\r
242         if( xAreComTestTasksStillRunning() != pdPASS )\r
243         {\r
244                 lReturn = pdFAIL;\r
245         }\r
246 \r
247         if( xArePollingQueuesStillRunning() != pdTRUE )\r
248         {\r
249                 lReturn = pdFAIL;\r
250         }\r
251 \r
252         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
253         {\r
254                 lReturn = pdFAIL;\r
255         }\r
256 \r
257         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
258         {\r
259                 lReturn = pdFAIL;\r
260         }\r
261 \r
262         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
263         {\r
264                 lReturn = pdFAIL;\r
265         }\r
266 \r
267         return lReturn;\r
268 }\r
269 /*-----------------------------------------------------------*/\r
270 \r
271 \r