]> git.sur5r.net Git - freertos/blob - Demo/ARM7_LPC2129_IAR/main.c
Remove unnecessary use of portLONG, portCHAR and portSHORT.
[freertos] / Demo / ARM7_LPC2129_IAR / 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 /*\r
51         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
52         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
53         called.  The demo applications included in the FreeRTOS.org download switch\r
54         to supervisor mode prior to main being called.  If you are not using one of\r
55         these demo application projects then ensure Supervisor mode is used.\r
56 */\r
57 \r
58 \r
59 /*\r
60  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
61  * documentation provides more details of the demo application tasks.\r
62  *\r
63  * Main.c also creates a task called "Check".  This only executes every three\r
64  * seconds but has the highest priority so is guaranteed to get processor time.\r
65  * Its main function is to check that all the other tasks are still operational.\r
66  * Each task (other than the "flash" tasks) maintains a unique count that is\r
67  * incremented each time the task successfully completes its function.  Should\r
68  * any error occur within such a task the count is permanently halted.  The\r
69  * check task inspects the count of each task to ensure it has changed since\r
70  * the last time the check task executed.  If all the count variables have\r
71  * changed all the tasks are still executing error free, and the check task\r
72  * toggles the onboard LED.  Should any task contain an error at any time\r
73  * the LED toggle rate will change from 3 seconds to 500ms.\r
74  *\r
75  */\r
76 \r
77 /* Standard includes. */\r
78 #include <stdlib.h>\r
79 \r
80 /* Scheduler includes. */\r
81 #include "FreeRTOS.h"\r
82 #include "task.h"\r
83 \r
84 /* Demo application includes. */\r
85 #include "flash.h"\r
86 #include "integer.h"\r
87 #include "PollQ.h"\r
88 #include "BlockQ.h"\r
89 #include "semtest.h"\r
90 #include "dynamic.h"\r
91 #include "partest.h"\r
92 #include "comtest2.h"\r
93 \r
94 /* Priorities for the demo application tasks. */\r
95 #define mainLED_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
96 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
97 #define mainCHECK_TASK_PRIORITY         ( tskIDLE_PRIORITY + 4 )\r
98 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
99 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
100 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
101 \r
102 /* Constants required by the 'Check' task. */\r
103 #define mainNO_ERROR_FLASH_PERIOD       ( ( portTickType ) 3000 / portTICK_RATE_MS  )\r
104 #define mainERROR_FLASH_PERIOD          ( ( portTickType ) 500 / portTICK_RATE_MS  )\r
105 #define mainCHECK_TASK_LED                      ( 7 )\r
106 \r
107 /* Constants for the ComTest tasks. */\r
108 #define mainCOM_TEST_BAUD_RATE          ( ( unsigned long ) 115200 )\r
109 #define mainCOM_TEST_LED                        ( 4 )\r
110 #define mainTX_ENABLE                           ( ( unsigned long ) 0x0001 )\r
111 #define mainRX_ENABLE                           ( ( unsigned long ) 0x0004 )\r
112 \r
113 /* Constants to setup the PLL. */\r
114 #define mainPLL_MUL_5                           ( ( unsigned char ) 0x0004 )\r
115 #define mainPLL_DIV_1                           ( ( unsigned char ) 0x0000 )\r
116 #define mainPLL_ENABLE                          ( ( unsigned char ) 0x0001 )\r
117 #define mainPLL_CONNECT                         ( ( unsigned char ) 0x0003 )\r
118 #define mainPLL_FEED_BYTE1                      ( ( unsigned char ) 0xaa )\r
119 #define mainPLL_FEED_BYTE2                      ( ( unsigned char ) 0x55 )\r
120 #define mainPLL_LOCK                            ( ( unsigned long ) 0x0400 )\r
121 \r
122 /* Constants to setup the MAM. */\r
123 #define mainMAM_TIM_3                           ( ( unsigned char ) 0x03 )\r
124 #define mainMAM_MODE_FULL                       ( ( unsigned char ) 0x02 )\r
125 \r
126 /* Constants to setup the peripheral bus. */\r
127 #define mainBUS_CLK_FULL                        ( ( unsigned char ) 0x01 )\r
128 \r
129 /* And finally, constant to setup the port for the LED's. */\r
130 #define mainLED_TO_OUTPUT                       ( ( unsigned long ) 0xff0000 )\r
131 \r
132 /*\r
133  * The task that executes at the highest priority and calls\r
134  * prvCheckOtherTasksAreStillRunning().  See the description at the top\r
135  * of the file.\r
136  */\r
137 static void vErrorChecks( void *pvParameters );\r
138 \r
139 /*\r
140  * Configures the processor for use with this demo.\r
141  */\r
142 static void prvSetupHardware( void );\r
143 \r
144 /*\r
145  * Checks that all the demo application tasks are still executing without error\r
146  * - as described at the top of the file.\r
147  */\r
148 static long prvCheckOtherTasksAreStillRunning( void );\r
149 \r
150 \r
151 /*-----------------------------------------------------------*/\r
152 \r
153 /*\r
154  * Starts all the other tasks, then starts the scheduler.\r
155  */\r
156 void main( void )\r
157 {\r
158         /* Setup the processor. */\r
159         prvSetupHardware();\r
160 \r
161         /* Start all the standard demo application tasks. */\r
162         vStartIntegerMathTasks( tskIDLE_PRIORITY );\r
163         vStartLEDFlashTasks( mainLED_TASK_PRIORITY );\r
164         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
165         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
166         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
167         vStartDynamicPriorityTasks();\r
168         vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
169                 \r
170         /* Start the check task - which is defined in this file. */\r
171         xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );\r
172 \r
173         /* Start the scheduler.\r
174 \r
175         NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.\r
176         The processor MUST be in supervisor mode when vTaskStartScheduler is\r
177         called.  The demo applications included in the FreeRTOS.org download switch\r
178         to supervisor mode prior to main being called.  If you are not using one of\r
179         these demo application projects then ensure Supervisor mode is used here.\r
180         */\r
181         vTaskStartScheduler();\r
182 \r
183         /* We should never get here as control is now taken by the scheduler. */\r
184         return;\r
185 }\r
186 /*-----------------------------------------------------------*/\r
187 \r
188 static void prvSetupHardware( void )\r
189 {\r
190         /* Setup the PLL to multiply the XTAL input by 5. */\r
191         PLLCFG = ( mainPLL_MUL_5 | mainPLL_DIV_1 );\r
192 \r
193         /* Activate the PLL by turning it on then feeding the correct sequence of\r
194         bytes. */\r
195         PLLCON = mainPLL_ENABLE;\r
196         PLLFEED = mainPLL_FEED_BYTE1;\r
197         PLLFEED = mainPLL_FEED_BYTE2;\r
198 \r
199         /* Wait for the PLL to lock... */\r
200         while( !( PLLSTAT & mainPLL_LOCK ) );\r
201 \r
202         /* ...before connecting it using the feed sequence again. */\r
203         PLLCON = mainPLL_CONNECT;\r
204         PLLFEED = mainPLL_FEED_BYTE1;\r
205         PLLFEED = mainPLL_FEED_BYTE2;\r
206 \r
207         /* Setup and turn on the MAM.  Three cycle access is used due to the fast\r
208         PLL used.  It is possible faster overall performance could be obtained by\r
209         tuning the MAM and PLL settings. */\r
210         MAMTIM = mainMAM_TIM_3;\r
211         MAMCR = mainMAM_MODE_FULL;\r
212 \r
213         /* Setup the peripheral bus to be the same as the PLL output. */\r
214         APBDIV = mainBUS_CLK_FULL;\r
215         \r
216         /* Configure the RS2332 pins.  All other pins remain at their default of 0. */\r
217         PINSEL0 |= mainTX_ENABLE;\r
218         PINSEL0 |= mainRX_ENABLE;\r
219 \r
220         /* LED pins need to be output. */\r
221         IO1DIR = mainLED_TO_OUTPUT;\r
222 \r
223         /* Setup the peripheral bus to be the same as the PLL output. */\r
224         APBDIV = mainBUS_CLK_FULL;\r
225 }\r
226 /*-----------------------------------------------------------*/\r
227 \r
228 static void vErrorChecks( void *pvParameters )\r
229 {\r
230 portTickType xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;\r
231 \r
232         /* The parameters are not used in this task. */\r
233         ( void ) pvParameters;\r
234 \r
235         /* Cycle for ever, delaying then checking all the other tasks are still\r
236         operating without error.  If an error is detected then the delay period\r
237         is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so\r
238         the on board LED flash rate will increase. */\r
239 \r
240         for( ;; )\r
241         {\r
242                 /* Delay until it is time to execute again. */\r
243                 vTaskDelay( xDelayPeriod );\r
244         \r
245                 /* Check all the standard demo application tasks are executing without\r
246                 error. */\r
247                 if( prvCheckOtherTasksAreStillRunning() != pdPASS )\r
248                 {\r
249                         /* An error has been detected in one of the tasks - flash faster. */\r
250                         xDelayPeriod = mainERROR_FLASH_PERIOD;\r
251                 }\r
252                 \r
253                 vParTestToggleLED( mainCHECK_TASK_LED );\r
254         }\r
255 }\r
256 /*-----------------------------------------------------------*/\r
257 \r
258 static long prvCheckOtherTasksAreStillRunning( void )\r
259 {\r
260 long lReturn = ( long ) pdPASS;\r
261 \r
262         /* Check all the demo tasks (other than the flash tasks) to ensure\r
263         that they are all still running, and that none of them have detected\r
264         an error. */\r
265 \r
266         if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
267         {\r
268                 lReturn = ( long ) pdFAIL;\r
269         }\r
270 \r
271         if( xArePollingQueuesStillRunning() != pdTRUE )\r
272         {\r
273                 lReturn = ( long ) pdFAIL;\r
274         }\r
275 \r
276         if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
277         {\r
278                 lReturn = ( long ) pdFAIL;\r
279         }\r
280 \r
281         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
282         {\r
283                 lReturn = ( long ) pdFAIL;\r
284         }\r
285 \r
286         if( xAreComTestTasksStillRunning() != pdTRUE )\r
287         {\r
288                 lReturn = ( long ) pdFAIL;\r
289         }\r
290 \r
291         if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
292         {\r
293                 lReturn = ( long ) pdFAIL;\r
294         }\r
295 \r
296         return lReturn;\r
297 }\r
298 /*-----------------------------------------------------------*/\r
299 \r
300 \r