2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
30 * documentation provides more details of the standard demo application tasks.
\r
31 * In addition to the standard demo tasks, the following tasks and tests are
\r
32 * defined and/or created within this file:
\r
34 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
35 * is permitted to access the display directly. Other tasks wishing to write a
\r
36 * message to the LCD send the message on a queue to the LCD task instead of
\r
37 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
38 * for messages - waking and displaying the messages as they arrive.
\r
40 * "Check" hook - This only executes every five seconds from the tick hook.
\r
41 * Its main function is to check that all the standard demo tasks are still
\r
42 * operational. Should any unexpected behaviour within a demo task be discovered
\r
43 * the tick hook will write an error to the LCD (via the LCD task). If all the
\r
44 * demo tasks are executing with their expected behaviour then the check task
\r
45 * writes PASS to the LCD (again via the LCD task), as described above.
\r
47 * "uIP" task - This is the task that handles the uIP stack. All TCP/IP
\r
48 * processing is performed in this task.
\r
51 /* Scheduler includes. */
\r
52 #include "FreeRTOS.h"
\r
57 /* Demo app includes. */
\r
60 #include "blocktim.h"
\r
61 #include "LCD/portlcd.h"
\r
63 #include "partest.h"
\r
64 #include "GenQTest.h"
\r
66 #include "dynamic.h"
\r
68 /* Demo application definitions. */
\r
69 #define mainQUEUE_SIZE ( 3 )
\r
70 #define mainCHECK_DELAY ( ( TickType_t ) 5000 / portTICK_PERIOD_MS )
\r
71 #define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 6 )
\r
73 /* Task priorities. */
\r
74 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
75 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
76 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
77 #define mainFLASH_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
78 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
79 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
81 /* Constants to setup the PLL. */
\r
82 #define mainPLL_MUL ( ( unsigned long ) ( 8 - 1 ) )
\r
83 #define mainPLL_DIV ( ( unsigned long ) 0x0000 )
\r
84 #define mainCPU_CLK_DIV ( ( unsigned long ) 0x0003 )
\r
85 #define mainPLL_ENABLE ( ( unsigned long ) 0x0001 )
\r
86 #define mainPLL_CONNECT ( ( ( unsigned long ) 0x0002 ) | mainPLL_ENABLE )
\r
87 #define mainPLL_FEED_BYTE1 ( ( unsigned long ) 0xaa )
\r
88 #define mainPLL_FEED_BYTE2 ( ( unsigned long ) 0x55 )
\r
89 #define mainPLL_LOCK ( ( unsigned long ) 0x4000000 )
\r
90 #define mainPLL_CONNECTED ( ( unsigned long ) 0x2000000 )
\r
91 #define mainOSC_ENABLE ( ( unsigned long ) 0x20 )
\r
92 #define mainOSC_STAT ( ( unsigned long ) 0x40 )
\r
93 #define mainOSC_SELECT ( ( unsigned long ) 0x01 )
\r
95 /* Constants to setup the MAM. */
\r
96 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
97 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
100 * The task that handles the uIP stack. All TCP/IP processing is performed in
\r
103 extern void vuIP_Task( void *pvParameters );
\r
106 * The LCD is written two by more than one task so is controlled by a
\r
107 * 'gatekeeper' task. This is the only task that is actually permitted to
\r
108 * access the LCD directly. Other tasks wanting to display a message send
\r
109 * the message to the gatekeeper.
\r
111 static void vLCDTask( void *pvParameters );
\r
113 /* Configure the hardware as required by the demo. */
\r
114 static void prvSetupHardware( void );
\r
116 /* The queue used to send messages to the LCD task. */
\r
117 QueueHandle_t xLCDQueue;
\r
119 /*-----------------------------------------------------------*/
\r
123 prvSetupHardware();
\r
125 /* Create the queue used by the LCD task. Messages for display on the LCD
\r
126 are received via this queue. */
\r
127 xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );
\r
129 /* Create the uIP task. This uses the lwIP RTOS abstraction layer.*/
\r
130 xTaskCreate( vuIP_Task, "uIP", mainBASIC_WEB_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
132 /* Start the standard demo tasks. */
\r
133 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
134 vCreateBlockTimeTasks();
\r
135 vStartLEDFlashTasks( mainFLASH_PRIORITY );
\r
136 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
137 vStartQueuePeekTasks();
\r
138 vStartDynamicPriorityTasks();
\r
140 /* Start the tasks defined within this file/specific to this demo. */
\r
141 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );
\r
143 /* Start the scheduler. */
\r
144 vTaskStartScheduler();
\r
146 /* Will only get here if there was insufficient memory to create the idle
\r
150 /*-----------------------------------------------------------*/
\r
152 void vApplicationTickHook( void )
\r
154 unsigned portBASE_TYPE uxColumn = 0;
\r
155 static xLCDMessage xMessage = { 0, "PASS" };
\r
156 static unsigned long ulTicksSinceLastDisplay = 0;
\r
157 static portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;
\r
159 /* Called from every tick interrupt. Have enough ticks passed to make it
\r
160 time to perform our health status check again? */
\r
161 ulTicksSinceLastDisplay++;
\r
162 if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )
\r
164 ulTicksSinceLastDisplay = 0;
\r
166 /* Has an error been found in any task? */
\r
168 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
170 xMessage.pcMessage = "ERROR - BLOCKQ";
\r
173 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
175 xMessage.pcMessage = "ERROR - BLOCKTIM";
\r
178 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
180 xMessage.pcMessage = "ERROR - GENQ";
\r
183 if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
185 xMessage.pcMessage = "ERROR - PEEKQ";
\r
188 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
190 xMessage.pcMessage = "ERROR - DYNAMIC";
\r
193 xMessage.xColumn++;
\r
195 /* Send the message to the LCD gatekeeper for display. */
\r
196 xHigherPriorityTaskWoken = pdFALSE;
\r
197 xQueueSendToBackFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );
\r
200 /*-----------------------------------------------------------*/
\r
202 void vLCDTask( void *pvParameters )
\r
204 xLCDMessage xMessage;
\r
206 /* Initialise the LCD and display a startup message. */
\r
210 LCD_gotoxy( 1, 1 );
\r
211 LCD_puts( "www.FreeRTOS.org" );
\r
215 /* Wait for a message to arrive that requires displaying. */
\r
216 while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );
\r
218 /* Display the message. Print each message to a different position. */
\r
220 LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );
\r
221 LCD_puts( xMessage.pcMessage );
\r
225 /*-----------------------------------------------------------*/
\r
227 static void prvSetupHardware( void )
\r
229 #ifdef RUN_FROM_RAM
\r
230 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
234 /* Disable the PLL. */
\r
236 PLLFEED = mainPLL_FEED_BYTE1;
\r
237 PLLFEED = mainPLL_FEED_BYTE2;
\r
239 /* Configure clock source. */
\r
240 SCS |= mainOSC_ENABLE;
\r
241 while( !( SCS & mainOSC_STAT ) );
\r
242 CLKSRCSEL = mainOSC_SELECT;
\r
244 /* Setup the PLL to multiply the XTAL input by 4. */
\r
245 PLLCFG = ( mainPLL_MUL | mainPLL_DIV );
\r
246 PLLFEED = mainPLL_FEED_BYTE1;
\r
247 PLLFEED = mainPLL_FEED_BYTE2;
\r
249 /* Turn on and wait for the PLL to lock... */
\r
250 PLLCON = mainPLL_ENABLE;
\r
251 PLLFEED = mainPLL_FEED_BYTE1;
\r
252 PLLFEED = mainPLL_FEED_BYTE2;
\r
253 CCLKCFG = mainCPU_CLK_DIV;
\r
254 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
256 /* Connecting the clock. */
\r
257 PLLCON = mainPLL_CONNECT;
\r
258 PLLFEED = mainPLL_FEED_BYTE1;
\r
259 PLLFEED = mainPLL_FEED_BYTE2;
\r
260 while( !( PLLSTAT & mainPLL_CONNECTED ) );
\r
263 This code is commented out as the MAM does not work on the original revision
\r
264 LPC2368 chips. If using Rev B chips then you can increase the speed though
\r
265 the use of the MAM.
\r
267 Setup and turn on the MAM. Three cycle access is used due to the fast
\r
268 PLL used. It is possible faster overall performance could be obtained by
\r
269 tuning the MAM and PLL settings.
\r
271 MAMTIM = mainMAM_TIM_3;
\r
272 MAMCR = mainMAM_MODE_FULL;
\r
275 /* Setup the led's on the MCB2300 board */
\r
276 vParTestInitialise();
\r