2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
72 * documentation provides more details of the standard demo application tasks.
\r
73 * In addition to the standard demo tasks, the following tasks and tests are
\r
74 * defined and/or created within this file:
\r
76 * "Fast Interrupt Test" - A high frequency periodic interrupt is generated
\r
77 * using a free running timer to demonstrate the use of the
\r
78 * configKERNEL_INTERRUPT_PRIORITY configuration constant. The interrupt
\r
79 * service routine measures the number of processor clocks that occur between
\r
80 * each interrupt - and in so doing measures the jitter in the interrupt
\r
81 * timing. The maximum measured jitter time is latched in the usMaxJitter
\r
82 * variable, and displayed on the LCD by the 'Check' as described below.
\r
83 * The fast interrupt is configured and handled in the timer_test.c source
\r
86 * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that
\r
87 * is permitted to access the LCD directly. Other tasks wishing to write a
\r
88 * message to the LCD send the message on a queue to the LCD task instead of
\r
89 * accessing the LCD themselves. The LCD task just blocks on the queue waiting
\r
90 * for messages - waking and displaying the messages as they arrive. The LCD
\r
91 * task is defined in lcd.c.
\r
93 * "Check" task - This only executes every three seconds but has the highest
\r
94 * priority so is guaranteed to get processor time. Its main function is to
\r
95 * check that all the standard demo tasks are still operational. Should any
\r
96 * unexpected behaviour within a demo task be discovered the 'check' task will
\r
97 * write "FAIL #n" to the LCD (via the LCD task). If all the demo tasks are
\r
98 * executing with their expected behaviour then the check task writes the max
\r
99 * jitter time to the LCD (again via the LCD task), as described above.
\r
102 /* Standard includes. */
\r
105 /* Scheduler includes. */
\r
106 #include "FreeRTOS.h"
\r
109 #include "croutine.h"
\r
111 /* Demo application includes. */
\r
112 #include "BlockQ.h"
\r
113 #include "crflash.h"
\r
114 #include "blocktim.h"
\r
115 #include "integer.h"
\r
116 #include "comtest2.h"
\r
117 #include "partest.h"
\r
119 #include "timertest.h"
\r
121 /* Demo task priorities. */
\r
122 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
123 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
124 #define mainCOM_TEST_PRIORITY ( 2 )
\r
126 /* The check task may require a bit more stack as it calls sprintf(). */
\r
127 #define mainCHECK_TAKS_STACK_SIZE ( configMINIMAL_STACK_SIZE * 2 )
\r
129 /* The execution period of the check task. */
\r
130 #define mainCHECK_TASK_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
132 /* The number of flash co-routines to create. */
\r
133 #define mainNUM_FLASH_COROUTINES ( 5 )
\r
135 /* Baud rate used by the comtest tasks. */
\r
136 #define mainCOM_TEST_BAUD_RATE ( 19200 )
\r
138 /* The LED used by the comtest tasks. mainCOM_TEST_LED + 1 is also used.
\r
139 See the comtest.c file for more information. */
\r
140 #define mainCOM_TEST_LED ( 6 )
\r
142 /* The frequency at which the "fast interrupt test" interrupt will occur. */
\r
143 #define mainTEST_INTERRUPT_FREQUENCY ( 20000 )
\r
145 /* The number of processor clocks we expect to occur between each "fast
\r
146 interrupt test" interrupt. */
\r
147 #define mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ( configCPU_CLOCK_HZ / mainTEST_INTERRUPT_FREQUENCY )
\r
149 /* The number of nano seconds between each processor clock. */
\r
150 #define mainNS_PER_CLOCK ( ( unsigned short ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )
\r
152 /* Dimension the buffer used to hold the value of the maximum jitter time when
\r
153 it is converted to a string. */
\r
154 #define mainMAX_STRING_LENGTH ( 20 )
\r
156 /*-----------------------------------------------------------*/
\r
159 * The check task as described at the top of this file.
\r
161 static void vCheckTask( void *pvParameters );
\r
164 * Setup the processor ready for the demo.
\r
166 static void prvSetupHardware( void );
\r
168 /* Prototypes for the standard FreeRTOS callback/hook functions implemented
\r
169 within this file. */
\r
170 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );
\r
172 /*-----------------------------------------------------------*/
\r
174 /* The queue used to send messages to the LCD task. */
\r
175 static QueueHandle_t xLCDQueue;
\r
177 /*-----------------------------------------------------------*/
\r
180 * Create the demo tasks then start the scheduler.
\r
184 /* Configure any hardware required for this demo. */
\r
185 prvSetupHardware();
\r
187 /* Create the standard demo tasks. */
\r
188 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
189 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
190 vStartFlashCoRoutines( mainNUM_FLASH_COROUTINES );
\r
191 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
192 vCreateBlockTimeTasks();
\r
194 /* Create the test tasks defined within this file. */
\r
195 xTaskCreate( vCheckTask, "Check", mainCHECK_TAKS_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
197 /* Start the task that will control the LCD. This returns the handle
\r
198 to the queue used to write text out to the task. */
\r
199 xLCDQueue = xStartLCDTask();
\r
201 /* Start the high frequency interrupt test. */
\r
202 vSetupTimerTest( mainTEST_INTERRUPT_FREQUENCY );
\r
204 /* Finally start the scheduler. */
\r
205 vTaskStartScheduler();
\r
207 /* Will only reach here if there is insufficient heap available to start
\r
211 /*-----------------------------------------------------------*/
\r
213 static void prvSetupHardware( void )
\r
215 vParTestInitialise();
\r
217 /*-----------------------------------------------------------*/
\r
219 static void vCheckTask( void *pvParameters )
\r
221 /* Used to wake the task at the correct frequency. */
\r
222 TickType_t xLastExecutionTime;
\r
224 /* The maximum jitter time measured by the fast interrupt test. */
\r
225 extern unsigned short usMaxJitter ;
\r
227 /* Buffer into which the maximum jitter time is written as a string. */
\r
228 static char cStringBuffer[ mainMAX_STRING_LENGTH ];
\r
230 /* The message that is sent on the queue to the LCD task. The first
\r
231 parameter is the minimum time (in ticks) that the message should be
\r
232 left on the LCD without being overwritten. The second parameter is a pointer
\r
233 to the message to display itself. */
\r
234 xLCDMessage xMessage = { 0, cStringBuffer };
\r
236 /* Set to pdTRUE should an error be detected in any of the standard demo tasks. */
\r
237 unsigned short usErrorDetected = pdFALSE;
\r
239 /* Remove compiler warnings. */
\r
240 ( void ) pvParameters;
\r
242 /* Initialise xLastExecutionTime so the first call to vTaskDelayUntil()
\r
243 works correctly. */
\r
244 xLastExecutionTime = xTaskGetTickCount();
\r
248 /* Wait until it is time for the next cycle. */
\r
249 vTaskDelayUntil( &xLastExecutionTime, mainCHECK_TASK_PERIOD );
\r
251 /* Has an error been found in any of the standard demo tasks? */
\r
253 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
255 usErrorDetected = pdTRUE;
\r
256 sprintf( cStringBuffer, "FAIL #1" );
\r
259 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
261 usErrorDetected = pdTRUE;
\r
262 sprintf( cStringBuffer, "FAIL #2" );
\r
265 if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
267 usErrorDetected = pdTRUE;
\r
268 sprintf( cStringBuffer, "FAIL #3" );
\r
271 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
273 usErrorDetected = pdTRUE;
\r
274 sprintf( cStringBuffer, "FAIL #4" );
\r
277 if( usErrorDetected == pdFALSE )
\r
279 /* No errors have been discovered, so display the maximum jitter
\r
280 timer discovered by the "fast interrupt test". */
\r
281 sprintf( cStringBuffer, "%dns max jitter", ( short ) ( usMaxJitter - mainEXPECTED_CLOCKS_BETWEEN_INTERRUPTS ) * mainNS_PER_CLOCK );
\r
284 /* Send the message to the LCD gatekeeper for display. */
\r
285 xQueueSend( xLCDQueue, &xMessage, portMAX_DELAY );
\r
288 /*-----------------------------------------------------------*/
\r
290 void vApplicationIdleHook( void )
\r
292 /* Schedule the co-routines from within the idle task hook. */
\r
293 vCoRoutineSchedule();
\r
295 /*-----------------------------------------------------------*/
\r
297 void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
\r
299 ( void ) pcTaskName;
\r
302 /* Run time stack overflow checking is performed if
\r
303 configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
\r
304 function is called if a stack overflow is detected. */
\r
305 taskDISABLE_INTERRUPTS();
\r