2 FreeRTOS V7.4.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 FEATURES AND PORTS ARE ADDED TO FREERTOS ALL THE TIME. PLEASE VISIT
\r
5 http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
10 * Complete, revised, and edited pdf reference manuals are also *
\r
13 * Purchasing FreeRTOS documentation will not only help you, by *
\r
14 * ensuring you get running as quickly as possible and with an *
\r
15 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
16 * the FreeRTOS project to continue with its mission of providing *
\r
17 * professional grade, cross platform, de facto standard solutions *
\r
18 * for microcontrollers - completely free of charge! *
\r
20 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
22 * Thank you for using FreeRTOS, and thank you for your support! *
\r
24 ***************************************************************************
\r
27 This file is part of the FreeRTOS distribution.
\r
29 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
30 the terms of the GNU General Public License (version 2) as published by the
\r
31 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
33 >>>>>>NOTE<<<<<< The modification to the GPL is included to allow you to
\r
34 distribute a combined work that includes FreeRTOS without being obliged to
\r
35 provide the source code for proprietary components outside of the FreeRTOS
\r
38 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
39 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
40 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
\r
41 details. You should have received a copy of the GNU General Public License
\r
42 and the FreeRTOS license exception along with FreeRTOS; if not itcan be
\r
43 viewed here: http://www.freertos.org/a00114.html and also obtained by
\r
44 writing to Real Time Engineers Ltd., contact details for whom are available
\r
45 on the FreeRTOS WEB site.
\r
49 ***************************************************************************
\r
51 * Having a problem? Start by reading the FAQ "My application does *
\r
52 * not run, what could be wrong?" *
\r
54 * http://www.FreeRTOS.org/FAQHelp.html *
\r
56 ***************************************************************************
\r
59 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
60 license and Real Time Engineers Ltd. contact details.
\r
62 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
63 including FreeRTOS+Trace - an indispensable productivity tool, and our new
\r
64 fully thread aware and reentrant UDP/IP stack.
\r
66 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
67 Integrity Systems, who sell the code with commercial support,
\r
68 indemnification and middleware, under the OpenRTOS brand.
\r
70 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
71 engineered and independently SIL3 certified version for use in safety and
\r
72 mission critical applications that require provable dependability.
\r
77 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
78 * documentation provides more details of the standard demo application tasks.
\r
79 * In addition to the standard demo tasks, the following tasks and tests are
\r
80 * defined and/or created within this file:
\r
82 * "LCD test" task - the LCD task writes a continually repeating series of patterns
\r
83 * to the LCD display.
\r
85 * "LED test" task - This is a very simple task that just turns on user LEDs
\r
86 * 8 to 15 in turn, before turning them off again.
\r
88 * "Check task" - The check task only runs every five seconds but has the highest
\r
89 * priority so is guaranteed to get processing time. Its main job is to inspect
\r
90 * all the other standard demo tasks to ensure they are executing without error.
\r
91 * The Check task will toggle LED 0 every five seconds while no errors exist,
\r
92 * with the toggle frequency increasing to 200ms should an error be detected in
\r
95 * Both the check task and the idle task place the processor into energy saving
\r
96 * mode 1, which will be exited following each tick interrupt. The check task
\r
97 * is the highest priority task in the system, so while it is executing no other
\r
98 * task will execute. If the check task places the processor into a low power
\r
99 * mode without blocking then the energy consumption as viewed on the Energy
\r
100 * Micro Gecko board will go down noticeably as in effect no tasks will be running.
\r
101 * The check task places the processor into low power mode for two out of every
\r
102 * five seconds. The current use of low power modes is very basic. Future
\r
103 * FreeRTOS releases will aim to make significant improvements.
\r
106 /* Scheduler includes. */
\r
107 #include "FreeRTOS.h"
\r
108 #include "croutine.h"
\r
111 #include "semphr.h"
\r
113 /* Common demo application includes. */
\r
114 #include "partest.h"
\r
115 #include "GenQTest.h"
\r
117 #include "recmutex.h"
\r
118 #include "semtest.h"
\r
120 /* Demo application includes. */
\r
121 #include "lcdcontroller.h"
\r
122 #include "ledtest.h"
\r
123 #include "lcdtest.h"
\r
126 /* Task priorities. */
\r
127 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
128 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
129 #define mainGEN_Q_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
130 #define mainSEMAPHORE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
131 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
133 /* A period of two seconds, adjusted to use the tick frequency. */
\r
134 #define mainTWO_SECONDS ( 2000 / portTICK_RATE_MS )
\r
136 /* The length of the delay between each cycle of the check task when an error
\r
137 has / has not been detected. */
\r
138 #define mainNO_ERROR_CHECK_FREQUENCY ( 5000 / portTICK_RATE_MS )
\r
139 #define mainERROR_CHECK_FREQUENCY ( 200 / portTICK_RATE_MS )
\r
141 /* The LED that is toggled by the check task. The rate of the toggle indicates
\r
142 whether or not an error has been found, as defined by the
\r
143 mainNO_ERROR_CHECK_FREQUENCY and mainERROR_CHECK_FREQUENCY definitions above. */
\r
144 #define mainCHECK_LED ( 0 )
\r
146 /*-----------------------------------------------------------*/
\r
149 * Configure the hardware as required by the demo.
\r
151 static void prvSetupHardware( void );
\r
154 * The check task as described at the top of this file.
\r
156 static void prvCheckTask( void *pvParameters );
\r
159 * Put the CPU into the least low power low power mode.
\r
161 static void prvLowPowerMode1( void );
\r
163 /*-----------------------------------------------------------*/
\r
167 /* Perform the necessary hardware configuration. */
\r
168 prvSetupHardware();
\r
170 /* Create the task that writes various text and patterns to the LCD. */
\r
171 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
173 /* Create a task that writes to LEDs 8 to 15. */
\r
174 xTaskCreate( vLEDTask, "LCDTask", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
\r
176 /* Create some of the standard demo tasks. These just test the port and
\r
177 demonstrate how the FreeRTOS API can be used. They do not provide any
\r
178 specific functionality. */
\r
179 vStartGenericQueueTasks( mainGEN_Q_TASK_PRIORITY );
\r
180 vStartQueuePeekTasks();
\r
181 vStartRecursiveMutexTasks();
\r
182 vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY );
\r
184 /* Create the check task as described at the top of this file. */
\r
185 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
187 /* Start the scheduler. */
\r
188 vTaskStartScheduler();
\r
190 /* The scheduler should now be running the tasks so the following code should
\r
191 never be reached. If it is reached then there was insufficient heap space
\r
192 for the idle task to be created. In this case the heap size is set by
\r
193 configTOTAL_HEAP_SIZE in FreeRTOSConfig.h. */
\r
196 /*-----------------------------------------------------------*/
\r
198 void vApplicationIdleHook( void )
\r
200 /* Use the idle task to place the CPU into a low power mode. Greater power
\r
201 saving could be achieved by not including any demo tasks that never block. */
\r
202 prvLowPowerMode1();
\r
204 /*-----------------------------------------------------------*/
\r
206 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
208 /* This function will be called if a task overflows its stack, if
\r
209 configCHECK_FOR_STACK_OVERFLOW != 0. It might be that the function
\r
210 parameters have been corrupted, depending on the severity of the stack
\r
211 overflow. When this is the case pxCurrentTCB can be inspected in the
\r
212 debugger to find the offending task. */
\r
215 /*-----------------------------------------------------------*/
\r
217 static void prvCheckTask( void *pvParameters )
\r
219 portTickType xLastExecutionTime, xFrequency = mainNO_ERROR_CHECK_FREQUENCY;
\r
222 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
223 works correctly. */
\r
224 xLastExecutionTime = xTaskGetTickCount();
\r
228 /* Perform this check at a frequency that indicates whether or not an
\r
229 error has been found. */
\r
230 vTaskDelayUntil( &xLastExecutionTime, xFrequency );
\r
232 /* Check all the other tasks are running without error. */
\r
233 if( xAreGenericQueueTasksStillRunning() != pdPASS )
\r
235 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
238 if( xAreQueuePeekTasksStillRunning() != pdPASS )
\r
240 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
243 if( xAreRecursiveMutexTasksStillRunning() != pdPASS )
\r
245 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
248 if( xAreSemaphoreTasksStillRunning() != pdPASS )
\r
250 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
253 /* Toggle the LED to show that the check hook function is running.
\r
254 The toggle freequency will increase if an error has been found in any
\r
256 vParTestToggleLED( mainCHECK_LED );
\r
258 /* Just loop around putting the processor into low power mode 1 for
\r
259 a while. This is the highest priority task, and this loop does not
\r
260 cause it to block, so it will remain as the running task. Each time it
\r
261 runs for the next two seconds it will simply put the processor to sleep.
\r
262 No other task will run so nothing else will happen. This periodic two
\r
263 seconds of lower power should be viewable using the Advanced Energy
\r
264 Monitor on the Energy Micro Gecko board. */
\r
265 for( lCount = 0; lCount < mainTWO_SECONDS; lCount++ )
\r
267 prvLowPowerMode1();
\r
271 /*-----------------------------------------------------------*/
\r
273 static void prvSetupHardware( void )
\r
275 /* Initialise the LEDs. */
\r
276 vParTestInitialise();
\r
278 /* Configure the LCD. */
\r
281 /*-----------------------------------------------------------*/
\r
283 static void prvLowPowerMode1( void )
\r
285 /* Clear SLEEPDEEP for EM1 */
\r
286 SCB->SCR &= ~( 1 << SCB_SCR_SLEEPDEEP_Pos );
\r