]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/ARM7_LPC2368_Eclipse/RTOSDemo/main.c
Update version number ready for version 9 release candidate 1.
[freertos] / FreeRTOS / Demo / ARM7_LPC2368_Eclipse / RTOSDemo / main.c
1 /*\r
2     FreeRTOS V9.0.0rc1 - Copyright (C) 2016 Real Time Engineers Ltd.\r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.\r
12 \r
13     ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18     ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40     the FAQ page "My application does not run, what could be wrong?".  Have you\r
41     defined configASSERT()?\r
42 \r
43     http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44     embedded software for free we request you assist our global community by\r
45     participating in the support forum.\r
46 \r
47     http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48     be as productive as possible as early as possible.  Now you can receive\r
49     FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50     Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /*\r
71  * Creates all the demo application tasks, then starts the scheduler.  The WEB\r
72  * documentation provides more details of the standard demo application tasks.\r
73  * In addition to the standard demo tasks, the following tasks and tests are\r
74  * defined and/or created within this file:\r
75  *\r
76  * "LCD" task - the LCD task is a 'gatekeeper' task.  It is the only task that\r
77  * is permitted to access the display directly.  Other tasks wishing to write a\r
78  * message to the LCD send the message on a queue to the LCD task instead of\r
79  * accessing the LCD themselves.  The LCD task just blocks on the queue waiting\r
80  * for messages - waking and displaying the messages as they arrive.\r
81  *\r
82  * "Check" hook -  This only executes every five seconds from the tick hook.\r
83  * Its main function is to check that all the standard demo tasks are still\r
84  * operational.  Should any unexpected behaviour within a demo task be discovered\r
85  * the tick hook will write an error to the LCD (via the LCD task).  If all the\r
86  * demo tasks are executing with their expected behaviour then the check task\r
87  * writes PASS to the LCD (again via the LCD task), as described above.\r
88  *\r
89  * "uIP" task -  This is the task that handles the uIP stack.  All TCP/IP\r
90  * processing is performed in this task.\r
91  */\r
92 \r
93 /* Scheduler includes. */\r
94 #include "FreeRTOS.h"\r
95 #include "task.h"\r
96 #include "queue.h"\r
97 #include "semphr.h"\r
98 \r
99 /* Demo app includes. */\r
100 #include "BlockQ.h"\r
101 #include "death.h"\r
102 #include "blocktim.h"\r
103 #include "LCD/portlcd.h"\r
104 #include "flash.h"\r
105 #include "partest.h"\r
106 #include "GenQTest.h"\r
107 #include "QPeek.h"\r
108 #include "dynamic.h"\r
109 \r
110 /* Demo application definitions. */\r
111 #define mainQUEUE_SIZE                                          ( 3 )\r
112 #define mainCHECK_DELAY                                         ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )\r
113 #define mainBASIC_WEB_STACK_SIZE            ( configMINIMAL_STACK_SIZE * 6 )\r
114 \r
115 /* Task priorities. */\r
116 #define mainQUEUE_POLL_PRIORITY                         ( tskIDLE_PRIORITY + 2 )\r
117 #define mainCHECK_TASK_PRIORITY                         ( tskIDLE_PRIORITY + 3 )\r
118 #define mainBLOCK_Q_PRIORITY                            ( tskIDLE_PRIORITY + 2 )\r
119 #define mainFLASH_PRIORITY                  ( tskIDLE_PRIORITY + 2 )\r
120 #define mainCREATOR_TASK_PRIORITY           ( tskIDLE_PRIORITY + 3 )\r
121 #define mainGEN_QUEUE_TASK_PRIORITY                     ( tskIDLE_PRIORITY )\r
122 \r
123 /* Constants to setup the PLL. */\r
124 #define mainPLL_MUL                     ( ( unsigned long ) ( 8 - 1 ) )\r
125 #define mainPLL_DIV                     ( ( unsigned long ) 0x0000 )\r
126 #define mainCPU_CLK_DIV         ( ( unsigned long ) 0x0003 )\r
127 #define mainPLL_ENABLE          ( ( unsigned long ) 0x0001 )\r
128 #define mainPLL_CONNECT         ( ( ( unsigned long ) 0x0002 ) | mainPLL_ENABLE )\r
129 #define mainPLL_FEED_BYTE1      ( ( unsigned long ) 0xaa )\r
130 #define mainPLL_FEED_BYTE2      ( ( unsigned long ) 0x55 )\r
131 #define mainPLL_LOCK            ( ( unsigned long ) 0x4000000 )\r
132 #define mainPLL_CONNECTED       ( ( unsigned long ) 0x2000000 )\r
133 #define mainOSC_ENABLE          ( ( unsigned long ) 0x20 )\r
134 #define mainOSC_STAT            ( ( unsigned long ) 0x40 )\r
135 #define mainOSC_SELECT          ( ( unsigned long ) 0x01 )\r
136 \r
137 /* Constants to setup the MAM. */\r
138 #define mainMAM_TIM_3           ( ( unsigned char ) 0x03 )\r
139 #define mainMAM_MODE_FULL       ( ( unsigned char ) 0x02 )\r
140 \r
141 /*\r
142  * The task that handles the uIP stack.  All TCP/IP processing is performed in\r
143  * this task.\r
144  */\r
145 extern void vuIP_Task( void *pvParameters );\r
146 \r
147 /*\r
148  * The LCD is written two by more than one task so is controlled by a\r
149  * 'gatekeeper' task.  This is the only task that is actually permitted to\r
150  * access the LCD directly.  Other tasks wanting to display a message send\r
151  * the message to the gatekeeper.\r
152  */\r
153 static void vLCDTask( void *pvParameters );\r
154 \r
155 /* Configure the hardware as required by the demo. */\r
156 static void prvSetupHardware( void );\r
157 \r
158 /* The queue used to send messages to the LCD task. */\r
159 QueueHandle_t xLCDQueue;\r
160 \r
161 /*-----------------------------------------------------------*/\r
162 \r
163 int main( void )\r
164 {\r
165         prvSetupHardware();\r
166 \r
167         /* Create the queue used by the LCD task.  Messages for display on the LCD\r
168         are received via this queue. */\r
169         xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );\r
170 \r
171         /* Create the uIP task.  This uses the lwIP RTOS abstraction layer.*/\r
172     xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
173 \r
174         /* Start the standard demo tasks. */\r
175         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
176     vCreateBlockTimeTasks();\r
177     vStartLEDFlashTasks( mainFLASH_PRIORITY );\r
178     vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
179     vStartQueuePeekTasks();\r
180     vStartDynamicPriorityTasks();\r
181 \r
182         /* Start the tasks defined within this file/specific to this demo. */\r
183         xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
184 \r
185         /* Start the scheduler. */\r
186         vTaskStartScheduler();\r
187 \r
188     /* Will only get here if there was insufficient memory to create the idle\r
189     task. */\r
190         return 0;\r
191 }\r
192 /*-----------------------------------------------------------*/\r
193 \r
194 void vApplicationTickHook( void )\r
195 {\r
196 unsigned portBASE_TYPE uxColumn = 0;\r
197 static xLCDMessage xMessage = { 0, "PASS" };\r
198 static unsigned long ulTicksSinceLastDisplay = 0;\r
199 static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
200 \r
201         /* Called from every tick interrupt.  Have enough ticks passed to make it\r
202         time to perform our health status check again? */\r
203         ulTicksSinceLastDisplay++;\r
204         if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )\r
205         {\r
206                 ulTicksSinceLastDisplay = 0;\r
207 \r
208                 /* Has an error been found in any task? */\r
209 \r
210         if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
211                 {\r
212                         xMessage.pcMessage = "ERROR - BLOCKQ";\r
213                 }\r
214 \r
215                 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
216                 {\r
217                         xMessage.pcMessage = "ERROR - BLOCKTIM";\r
218                 }\r
219 \r
220                 if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
221                 {\r
222                         xMessage.pcMessage = "ERROR - GENQ";\r
223                 }\r
224 \r
225                 if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
226                 {\r
227                         xMessage.pcMessage = "ERROR - PEEKQ";\r
228                 }\r
229 \r
230                 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )\r
231                 {\r
232                         xMessage.pcMessage = "ERROR - DYNAMIC";\r
233                 }\r
234 \r
235         xMessage.xColumn++;\r
236 \r
237                 /* Send the message to the LCD gatekeeper for display. */\r
238                 xHigherPriorityTaskWoken = pdFALSE;\r
239                 xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
240         }\r
241 }\r
242 /*-----------------------------------------------------------*/\r
243 \r
244 void vLCDTask( void *pvParameters )\r
245 {\r
246 xLCDMessage xMessage;\r
247 \r
248         /* Initialise the LCD and display a startup message. */\r
249         LCD_init();\r
250         LCD_cur_off();\r
251     LCD_cls();\r
252     LCD_gotoxy( 1, 1 );\r
253     LCD_puts( "www.FreeRTOS.org" );\r
254 \r
255         for( ;; )\r
256         {\r
257                 /* Wait for a message to arrive that requires displaying. */\r
258                 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
259 \r
260                 /* Display the message.  Print each message to a different position. */\r
261                 LCD_cls();\r
262                 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );\r
263                 LCD_puts( xMessage.pcMessage );\r
264         }\r
265 \r
266 }\r
267 /*-----------------------------------------------------------*/\r
268 \r
269 static void prvSetupHardware( void )\r
270 {\r
271         #ifdef RUN_FROM_RAM\r
272                 /* Remap the interrupt vectors to RAM if we are are running from RAM. */\r
273                 SCB_MEMMAP = 2;\r
274         #endif\r
275 \r
276         /* Disable the PLL. */\r
277         PLLCON = 0;\r
278         PLLFEED = mainPLL_FEED_BYTE1;\r
279         PLLFEED = mainPLL_FEED_BYTE2;\r
280 \r
281         /* Configure clock source. */\r
282         SCS |= mainOSC_ENABLE;\r
283         while( !( SCS & mainOSC_STAT ) );\r
284         CLKSRCSEL = mainOSC_SELECT;\r
285 \r
286         /* Setup the PLL to multiply the XTAL input by 4. */\r
287         PLLCFG = ( mainPLL_MUL | mainPLL_DIV );\r
288         PLLFEED = mainPLL_FEED_BYTE1;\r
289         PLLFEED = mainPLL_FEED_BYTE2;\r
290 \r
291         /* Turn on and wait for the PLL to lock... */\r
292         PLLCON = mainPLL_ENABLE;\r
293         PLLFEED = mainPLL_FEED_BYTE1;\r
294         PLLFEED = mainPLL_FEED_BYTE2;\r
295         CCLKCFG = mainCPU_CLK_DIV;\r
296         while( !( PLLSTAT & mainPLL_LOCK ) );\r
297 \r
298         /* Connecting the clock. */\r
299         PLLCON = mainPLL_CONNECT;\r
300         PLLFEED = mainPLL_FEED_BYTE1;\r
301         PLLFEED = mainPLL_FEED_BYTE2;\r
302         while( !( PLLSTAT & mainPLL_CONNECTED ) );\r
303 \r
304         /*\r
305         This code is commented out as the MAM does not work on the original revision\r
306         LPC2368 chips.  If using Rev B chips then you can increase the speed though\r
307         the use of the MAM.\r
308 \r
309         Setup and turn on the MAM.  Three cycle access is used due to the fast\r
310         PLL used.  It is possible faster overall performance could be obtained by\r
311         tuning the MAM and PLL settings.\r
312         MAMCR = 0;\r
313         MAMTIM = mainMAM_TIM_3;\r
314         MAMCR = mainMAM_MODE_FULL;\r
315         */\r
316 \r
317         /* Setup the led's on the MCB2300 board */\r
318         vParTestInitialise();\r
319 }\r
320 \r
321 \r
322 \r
323 \r
324 \r
325 \r
326 \r