2 * FreeRTOS Kernel V10.3.0
\r
3 * Copyright (C) 2020 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 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
30 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
31 called. The demo applications included in the FreeRTOS.org download switch
\r
32 to supervisor mode prior to main being called. If you are not using one of
\r
33 these demo application projects then ensure Supervisor mode is used.
\r
38 * Program entry point.
\r
40 * main() is responsible for setting up the microcontroller peripherals, then
\r
41 * starting the demo application tasks. Once the tasks have been created the
\r
42 * scheduler is started and main() should never complete.
\r
44 * The demo creates the three standard 'flash' tasks to provide some visual
\r
45 * feedback that the system and scheduler are still operating correctly.
\r
47 * The HTTP server task operates at the highest priority so will always preempt
\r
48 * the flash or idle task on TCP/IP events.
\r
51 /* Standard includes. */
\r
54 /* Scheduler include files. */
\r
55 #include "FreeRTOS.h"
\r
59 /* Application includes. */
\r
61 #include "HTTP_Serv.h"
\r
63 #include "partest.h"
\r
64 #include "dynamic.h"
\r
65 #include "semtest.h"
\r
68 #include "integer.h"
\r
70 /*-----------------------------------------------------------*/
\r
72 /* Constants to setup the PLL. */
\r
73 #define mainPLL_MUL_4 ( ( unsigned char ) 0x0003 )
\r
74 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
75 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
76 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
77 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
78 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
79 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
81 /* Constants to setup the MAM. */
\r
82 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
83 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
85 /* Constants to setup the peripheral bus. */
\r
86 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
88 /* Constants to setup I/O and processor. */
\r
89 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
90 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
91 #define mainJTAG_PORT ( ( unsigned long ) 0x3E0000UL )
\r
93 /* Priorities for the demo application tasks. */
\r
94 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
95 #define mainHTTP_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
96 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
97 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
98 #define mainERROR_CHECK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
100 /* Flash rates of the on board LED to indicate the health of the system. */
\r
101 #define mainNO_ERROR_DELAY ( 3000 )
\r
102 #define mainERROR_DELAY ( 500 )
\r
103 #define mainON_BOARD_LED_BIT ( ( unsigned long ) 0x80 )
\r
105 /*-----------------------------------------------------------*/
\r
108 * The Olimex demo board has a single built in LED. This function simply
\r
109 * toggles its state.
\r
111 void prvToggleOnBoardLED( void );
\r
114 * Configure the processor for use with the Olimex demo board.
\r
116 static void prvSetupHardware( void );
\r
119 * Simply check for errors and toggle the onboard LED.
\r
121 static void prvErrorChecks( void *pvParameters );
\r
124 * Return true if the demo tasks are executing without error - otherwise
\r
127 static void prvMainCheckOtherTasksAreStillRunning( void );
\r
128 /*-----------------------------------------------------------*/
\r
130 /* Flag set by prvMainCheckOtherTasksAreStillExecuting(). */
\r
131 long lErrorInTask = pdFALSE;
\r
134 * Application entry point:
\r
135 * Starts all the other tasks, then starts the scheduler.
\r
139 /* Setup the hardware for use with the Olimex demo board. */
\r
140 prvSetupHardware();
\r
142 /* Start the standard flash tasks so the WEB server is not the only thing
\r
144 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
145 vStartSemaphoreTasks( tskIDLE_PRIORITY );
\r
146 vStartDynamicPriorityTasks();
\r
147 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
148 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
149 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
151 /* Start the WEB server task and the error check task. */
\r
152 xTaskCreate( vHTTPServerTask, "HTTP", configMINIMAL_STACK_SIZE, NULL, mainHTTP_TASK_PRIORITY, NULL );
\r
153 xTaskCreate( prvErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainERROR_CHECK_PRIORITY, NULL );
\r
155 /* Now all the tasks have been started - start the scheduler.
\r
157 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
158 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
159 called. The demo applications included in the FreeRTOS.org download switch
\r
160 to supervisor mode prior to main being called. If you are not using one of
\r
161 these demo application projects then ensure Supervisor mode is used. */
\r
162 vTaskStartScheduler();
\r
164 /* Should never reach here! */
\r
167 /*-----------------------------------------------------------*/
\r
169 static void prvSetupHardware( void )
\r
171 #ifdef RUN_FROM_RAM
\r
172 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
\r
176 /* Set all GPIO to output other than the P0.14 (BSL), and the JTAG pins.
\r
177 The JTAG pins are left as input as I'm not sure what will happen if the
\r
178 Wiggler is connected after powerup - not that it would be a good idea to
\r
180 GPIO_IODIR = ~( mainJTAG_PORT );
\r
182 /* Setup the PLL to multiply the XTAL input by 4. */
\r
183 SCB_PLLCFG = ( mainPLL_MUL_4 | mainPLL_DIV_1 );
\r
185 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
187 SCB_PLLCON = mainPLL_ENABLE;
\r
188 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
189 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
191 /* Wait for the PLL to lock... */
\r
192 while( !( SCB_PLLSTAT & mainPLL_LOCK ) );
\r
194 /* ...before connecting it using the feed sequence again. */
\r
195 SCB_PLLCON = mainPLL_CONNECT;
\r
196 SCB_PLLFEED = mainPLL_FEED_BYTE1;
\r
197 SCB_PLLFEED = mainPLL_FEED_BYTE2;
\r
199 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
200 PLL used. It is possible faster overall performance could be obtained by
\r
201 tuning the MAM and PLL settings. */
\r
202 MAM_TIM = mainMAM_TIM_3;
\r
203 MAM_CR = mainMAM_MODE_FULL;
\r
205 /* Setup the peripheral bus to be the same as the PLL output. */
\r
206 SCB_VPBDIV = mainBUS_CLK_FULL;
\r
208 /* Initialise the i2c peripheral. */
\r
211 /* Initialise the LED's used by the flash tasks. */
\r
212 vParTestInitialise();
\r
214 /*-----------------------------------------------------------*/
\r
216 static void prvMainCheckOtherTasksAreStillRunning( void )
\r
218 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
219 that they are all still running, and that none of them have detected
\r
222 /* This function is called from more than one task. */
\r
223 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
225 lErrorInTask = pdTRUE;
\r
228 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
230 lErrorInTask = pdTRUE;
\r
233 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
235 lErrorInTask = pdTRUE;
\r
238 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
240 lErrorInTask = pdTRUE;
\r
243 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
245 lErrorInTask = pdTRUE;
\r
248 /*-----------------------------------------------------------*/
\r
250 void prvToggleOnBoardLED( void )
\r
252 unsigned long ulState;
\r
254 ulState = GPIO0_IOPIN;
\r
255 if( ulState & mainON_BOARD_LED_BIT )
\r
257 GPIO_IOCLR = mainON_BOARD_LED_BIT;
\r
261 GPIO_IOSET = mainON_BOARD_LED_BIT;
\r
264 /*-----------------------------------------------------------*/
\r
266 static void prvErrorChecks( void *pvParameters )
\r
268 TickType_t xDelay = mainNO_ERROR_DELAY;
\r
270 /* The parameters are not used. */
\r
271 ( void ) pvParameters;
\r
275 /* How long we delay depends on whether an error has been detected
\r
276 or not. Therefore the flash rate of the on board LED indicates
\r
277 whether or not an error has occurred. */
\r
278 vTaskDelay( xDelay );
\r
280 /* Update the lErrorInTask flag. */
\r
281 prvMainCheckOtherTasksAreStillRunning();
\r
285 /* An error has been found so reduce the delay period and in so
\r
286 doing speed up the flash rate of the on board LED. */
\r
287 xDelay = mainERROR_DELAY;
\r
290 prvToggleOnBoardLED();
\r