2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
67 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
68 * documentation provides more details of the standard demo application tasks.
\r
69 * In addition to the standard demo tasks, the following tasks and tests are
\r
70 * defined and/or created within this file:
\r
72 * "LCD test" task - the LCD task writes a continually repeating series of patterns
\r
73 * to the LCD display.
\r
75 * "LED test" task - This is a very simple task that just turns on user LEDs
\r
76 * 8 to 15 in turn, before turning them off again.
\r
78 * "Check task" - The check task only runs every five seconds but has the highest
\r
79 * priority so is guaranteed to get processing time. Its main job is to inspect
\r
80 * all the other standard demo tasks to ensure they are executing without error.
\r
81 * The Check task will toggle LED 0 every five seconds while no errors exist,
\r
82 * with the toggle frequency increasing to 200ms should an error be detected in
\r
85 * Both the check task and the idle task place the processor into energy saving
\r
86 * mode 1, which will be exited following each tick interrupt. The check task
\r
87 * is the highest priority task in the system, so while it is executing no other
\r
88 * task will execute. If the check task places the processor into a low power
\r
89 * mode without blocking then the energy consumption as viewed on the Energy
\r
90 * Micro Gecko board will go down noticeably as in effect no tasks will be running.
\r
91 * The check task places the processor into low power mode for two out of every
\r
92 * five seconds. The current use of low power modes is very basic. Future
\r
93 * FreeRTOS releases will aim to make significant improvements.
\r
96 /* Scheduler includes. */
\r
97 #include "FreeRTOS.h"
\r
98 #include "croutine.h"
\r
101 #include "semphr.h"
\r
103 /* Common demo application includes. */
\r
104 #include "partest.h"
\r
105 #include "GenQTest.h"
\r
107 #include "recmutex.h"
\r
108 #include "semtest.h"
\r
110 /* Demo application includes. */
\r
111 #include "lcdcontroller.h"
\r
112 #include "ledtest.h"
\r
113 #include "lcdtest.h"
\r
116 /* Task priorities. */
\r
117 #define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
118 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
119 #define mainGEN_Q_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
120 #define mainSEMAPHORE_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
121 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
123 /* A period of two seconds, adjusted to use the tick frequency. */
\r
124 #define mainTWO_SECONDS ( 2000 / portTICK_RATE_MS )
\r
126 /* The length of the delay between each cycle of the check task when an error
\r
127 has / has not been detected. */
\r
128 #define mainNO_ERROR_CHECK_FREQUENCY ( 5000 / portTICK_RATE_MS )
\r
129 #define mainERROR_CHECK_FREQUENCY ( 200 / portTICK_RATE_MS )
\r
131 /* The LED that is toggled by the check task. The rate of the toggle indicates
\r
132 whether or not an error has been found, as defined by the
\r
133 mainNO_ERROR_CHECK_FREQUENCY and mainERROR_CHECK_FREQUENCY definitions above. */
\r
134 #define mainCHECK_LED ( 0 )
\r
136 /*-----------------------------------------------------------*/
\r
139 * Configure the hardware as required by the demo.
\r
141 static void prvSetupHardware( void );
\r
144 * The check task as described at the top of this file.
\r
146 static void prvCheckTask( void *pvParameters );
\r
149 * Put the CPU into the least low power low power mode.
\r
151 static void prvLowPowerMode1( void );
\r
153 /*-----------------------------------------------------------*/
\r
157 /* Perform the necessary hardware configuration. */
\r
158 prvSetupHardware();
\r
160 /* Create the task that writes various text and patterns to the LCD. */
\r
161 xTaskCreate( vLCDTask, "LCD", configMINIMAL_STACK_SIZE, NULL, mainLCD_TASK_PRIORITY, NULL );
\r
163 /* Create a task that writes to LEDs 8 to 15. */
\r
164 xTaskCreate( vLEDTask, "LCDTask", configMINIMAL_STACK_SIZE, NULL, mainLED_TASK_PRIORITY, NULL );
\r
166 /* Create some of the standard demo tasks. These just test the port and
\r
167 demonstrate how the FreeRTOS API can be used. They do not provide any
\r
168 specific functionality. */
\r
169 vStartGenericQueueTasks( mainGEN_Q_TASK_PRIORITY );
\r
170 vStartQueuePeekTasks();
\r
171 vStartRecursiveMutexTasks();
\r
172 vStartSemaphoreTasks( mainSEMAPHORE_TASK_PRIORITY );
\r
174 /* Create the check task as described at the top of this file. */
\r
175 xTaskCreate( prvCheckTask, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
177 /* Start the scheduler. */
\r
178 vTaskStartScheduler();
\r
180 /* The scheduler should now be running the tasks so the following code should
\r
181 never be reached. If it is reached then there was insufficient heap space
\r
182 for the idle task to be created. In this case the heap size is set by
\r
183 configTOTAL_HEAP_SIZE in FreeRTOSConfig.h. */
\r
186 /*-----------------------------------------------------------*/
\r
188 void vApplicationIdleHook( void )
\r
190 /* Use the idle task to place the CPU into a low power mode. Greater power
\r
191 saving could be achieved by not including any demo tasks that never block. */
\r
192 prvLowPowerMode1();
\r
194 /*-----------------------------------------------------------*/
\r
196 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
198 /* This function will be called if a task overflows its stack, if
\r
199 configCHECK_FOR_STACK_OVERFLOW != 0. It might be that the function
\r
200 parameters have been corrupted, depending on the severity of the stack
\r
201 overflow. When this is the case pxCurrentTCB can be inspected in the
\r
202 debugger to find the offending task. */
\r
205 /*-----------------------------------------------------------*/
\r
207 static void prvCheckTask( void *pvParameters )
\r
209 portTickType xLastExecutionTime, xFrequency = mainNO_ERROR_CHECK_FREQUENCY;
\r
212 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
213 works correctly. */
\r
214 xLastExecutionTime = xTaskGetTickCount();
\r
218 /* Perform this check at a frequency that indicates whether or not an
\r
219 error has been found. */
\r
220 vTaskDelayUntil( &xLastExecutionTime, xFrequency );
\r
222 /* Check all the other tasks are running without error. */
\r
223 if( xAreGenericQueueTasksStillRunning() != pdPASS )
\r
225 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
228 if( xAreQueuePeekTasksStillRunning() != pdPASS )
\r
230 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
233 if( xAreRecursiveMutexTasksStillRunning() != pdPASS )
\r
235 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
238 if( xAreSemaphoreTasksStillRunning() != pdPASS )
\r
240 xFrequency = mainERROR_CHECK_FREQUENCY;
\r
243 /* Toggle the LED to show that the check hook function is running.
\r
244 The toggle freequency will increase if an error has been found in any
\r
246 vParTestToggleLED( mainCHECK_LED );
\r
248 /* Just loop around putting the processor into low power mode 1 for
\r
249 a while. This is the highest priority task, and this loop does not
\r
250 cause it to block, so it will remain as the running task. Each time it
\r
251 runs for the next two seconds it will simply put the processor to sleep.
\r
252 No other task will run so nothing else will happen. This periodic two
\r
253 seconds of lower power should be viewable using the Advanced Energy
\r
254 Monitor on the Energy Micro Gecko board. */
\r
255 for( lCount = 0; lCount < mainTWO_SECONDS; lCount++ )
\r
257 prvLowPowerMode1();
\r
261 /*-----------------------------------------------------------*/
\r
263 static void prvSetupHardware( void )
\r
265 /* Initialise the LEDs. */
\r
266 vParTestInitialise();
\r
268 /* Configure the LCD. */
\r
271 /*-----------------------------------------------------------*/
\r
273 static void prvLowPowerMode1( void )
\r
275 /* Clear SLEEPDEEP for EM1 */
\r
276 SCB->SCR &= ~( 1 << SCB_SCR_SLEEPDEEP_Pos );
\r