2 FreeRTOS V7.1.1 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
68 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
69 * documentation provides more details of the standard demo application tasks.
\r
70 * In addition to the standard demo tasks, the following tasks and tests are
\r
71 * defined and/or created within this file:
\r
73 * "Fast Interrupt Test" - A high frequency periodic interrupt is generated
\r
74 * using a free running timer to demonstrate the use of the
\r
75 * configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt
\r
76 * service routine measures the number of processor clocks that occur between
\r
77 * each interrupt - and in so doing measures the jitter in the interrupt
\r
78 * timing. The maximum measured jitter time is latched in the usMaxJitter
\r
79 * variable, and displayed on the LCD by the 'Check' as described below.
\r
80 * The fast interrupt is configured and handled in the timer_test.c source
\r
83 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
84 * is permitted to access the LCD directly. Other tasks wishing to write a
\r
85 * message to the LCD send the message on a queue to the LCD task instead of
\r
86 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
87 * for messages - waking and displaying the messages as they arrive. The LCD
\r
88 * task is defined in lcd.c.
\r
90 * "Check" task - This only executes every three seconds but has the highest
\r
91 * priority so is guaranteed to get processor time. Its main function is to
\r
92 * check that all the standard demo tasks are still operational. Should any
\r
93 * unexpected behaviour within a demo task be discovered the 'check' task will
\r
94 * write "FAIL #n" to the LCD (via the LCD task). If all the demo tasks are
\r
95 * executing with their expected behaviour then the check task writes the max
\r
96 * jitter time to the LCD (again via the LCD task), as described above.
\r
99 /* Standard includes. */
\r
102 /* Scheduler includes. */
\r
103 #include "FreeRTOS.h"
\r
106 #include "croutine.h"
\r
108 /* Demo application includes. */
\r
109 #include "BlockQ.h"
\r
110 #include "crflash.h"
\r
111 #include "blocktim.h"
\r
112 #include "integer.h"
\r
113 #include "comtest2.h"
\r
114 #include "partest.h"
\r
116 #include "timertest.h"
\r
118 /* Demo task priorities. */
\r
119 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
120 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
121 #define mainCOM_TEST_PRIORITY ( 2 )
\r
123 /* The check task may require a bit more stack as it calls sprintf(). */
\r
124 #define mainCHECK_TAKS_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
126 /* The execution period of the check task. */
\r
127 #define mainCHECK_TASK_PERIOD ( ( portTickType ) 3000 / portTICK_RATE_MS )
\r
129 /* The number of flash co-routines to create. */
\r
130 #define mainNUM_FLASH_COROUTINES ( 5 )
\r
132 /* Baud rate used by the comtest tasks. */
\r
133 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
135 /* The LED used by the comtest tasks. mainCOM_TEST_LED + 1 is also used.
\r
136 See the comtest.c file for more information. */
\r
137 #define mainCOM_TEST_LED ( 6 )
\r
139 /* The frequency at which the "fast interrupt test" interrupt will occur. */
\r
140 #define mainTEST_INTERRUPT_FREQUENCY ( 20000 )
\r
142 /* The number of processor clocks we expect to occur between each "fast
\r
143 interrupt test" interrupt. */
\r
144 #define mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ( configCPU_CLOCK_HZ / mainTEST_INTERRUPT_FREQUENCY )
\r
146 /* The number of nano seconds between each processor clock. */
\r
147 #define mainNS_PER_CLOCK ( ( unsigned short ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
149 /* Dimension the buffer used to hold the value of the maximum jitter time when
\r
150 it is converted to a string. */
\r
151 #define mainMAX_STRING_LENGTH ( 20 )
\r
153 /*-----------------------------------------------------------*/
\r
156 * The check task as described at the top of this file.
\r
158 static void vCheckTask( void *pvParameters );
\r
161 * Setup the processor ready for the demo.
\r
163 static void prvSetupHardware( void );
\r
165 /*-----------------------------------------------------------*/
\r
167 /* The queue used to send messages to the LCD task. */
\r
168 static xQueueHandle xLCDQueue;
\r
170 /*-----------------------------------------------------------*/
\r
173 * Create the demo tasks then start the scheduler.
\r
177 /* Configure any hardware required for this demo. */
\r
178 prvSetupHardware();
\r
180 /* Create the standard demo tasks. */
\r
181 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
182 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
183 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
184 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
185 vCreateBlockTimeTasks();
\r
187 /* Create the test tasks defined within this file. */
\r
188 xTaskCreate( vCheckTask, ( signed char * ) "Check", mainCHECK_TAKS_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
190 /* Start the task that will control the LCD. This returns the handle
\r
191 to the queue used to write text out to the task. */
\r
192 xLCDQueue = xStartLCDTask();
\r
194 /* Start the high frequency interrupt test. */
\r
195 vSetupTimerTest( mainTEST_INTERRUPT_FREQUENCY );
\r
197 /* Finally start the scheduler. */
\r
198 vTaskStartScheduler();
\r
200 /* Will only reach here if there is insufficient heap available to start
\r
204 /*-----------------------------------------------------------*/
\r
206 static void prvSetupHardware( void )
\r
208 vParTestInitialise();
\r
210 /*-----------------------------------------------------------*/
\r
212 static void vCheckTask( void *pvParameters )
\r
214 /* Used to wake the task at the correct frequency. */
\r
215 portTickType xLastExecutionTime;
\r
217 /* The maximum jitter time measured by the fast interrupt test. */
\r
218 extern unsigned short usMaxJitter ;
\r
220 /* Buffer into which the maximum jitter time is written as a string. */
\r
221 static char cStringBuffer[ mainMAX_STRING_LENGTH ];
\r
223 /* The message that is sent on the queue to the LCD task. The first
\r
224 parameter is the minimum time (in ticks) that the message should be
\r
225 left on the LCD without being overwritten. The second parameter is a pointer
\r
226 to the message to display itself. */
\r
227 xLCDMessage xMessage = { 0, cStringBuffer };
\r
229 /* Set to pdTRUE should an error be detected in any of the standard demo tasks. */
\r
230 unsigned short usErrorDetected = pdFALSE;
\r
232 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
233 works correctly. */
\r
234 xLastExecutionTime = xTaskGetTickCount();
\r
238 /* Wait until it is time for the next cycle. */
\r
239 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_PERIOD );
\r
241 /* Has an error been found in any of the standard demo tasks? */
\r
243 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
245 usErrorDetected = pdTRUE;
\r
246 sprintf( cStringBuffer, "FAIL #1" );
\r
249 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
251 usErrorDetected = pdTRUE;
\r
252 sprintf( cStringBuffer, "FAIL #2" );
\r
255 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
257 usErrorDetected = pdTRUE;
\r
258 sprintf( cStringBuffer, "FAIL #3" );
\r
261 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
263 usErrorDetected = pdTRUE;
\r
264 sprintf( cStringBuffer, "FAIL #4" );
\r
267 if( usErrorDetected == pdFALSE )
\r
269 /* No errors have been discovered, so display the maximum jitter
\r
270 timer discovered by the "fast interrupt test". */
\r
271 sprintf( cStringBuffer, "%dns max jitter", ( short ) ( usMaxJitter - mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ) * mainNS_PER_CLOCK );
\r
274 /* Send the message to the LCD gatekeeper for display. */
\r
275 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
278 /*-----------------------------------------------------------*/
\r
280 void vApplicationIdleHook( void )
\r
282 /* Schedule the co-routines from within the idle task hook. */
\r
283 vCoRoutineSchedule();
\r
285 /*-----------------------------------------------------------*/
\r