2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
7 This file is part of the FreeRTOS distribution.
9 FreeRTOS is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License (version 2) as published by the
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
13 ***************************************************************************
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
15 >>! distribute a combined work that includes FreeRTOS without being !<<
16 >>! obliged to provide the source code for proprietary components !<<
17 >>! outside of the FreeRTOS kernel. !<<
18 ***************************************************************************
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
23 link: http://www.freertos.org/a00114.html
25 ***************************************************************************
27 * FreeRTOS provides completely free yet professionally developed, *
28 * robust, strictly quality controlled, supported, and cross *
29 * platform software that is more than just the market leader, it *
30 * is the industry's de facto standard. *
32 * Help yourself get started quickly while simultaneously helping *
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
34 * tutorial book, reference manual, or both: *
35 * http://www.FreeRTOS.org/Documentation *
37 ***************************************************************************
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
40 the FAQ page "My application does not run, what could be wrong?". Have you
41 defined configASSERT()?
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
44 embedded software for free we request you assist our global community by
45 participating in the support forum.
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
48 be as productive as possible as early as possible. Now you can receive
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
50 Ltd, and the world's leading authority on the world's leading RTOS.
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
61 licenses offer ticketed support, indemnification and commercial middleware.
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
64 engineered and independently SIL3 certified version for use in safety and
65 mission critical applications that require provable dependability.
71 * Creates all the demo application tasks, then starts the scheduler. The WEB
72 * documentation provides more details of the demo application tasks.
74 * This demo is configured to execute on the ES449 prototyping board from
75 * SoftBaugh. The ES449 has a built in LCD display and a single built in user
76 * LED. Therefore, in place of flashing an LED, the 'flash' and 'check' tasks
77 * toggle '*' characters on the LCD. The left most '*' represents LED 0, the
80 * Main. c also creates a task called 'Check'. This only executes every three
81 * seconds but has the highest priority so is guaranteed to get processor time.
82 * Its main function is to check that all the other tasks are still operational.
83 * Each task that does not flash an LED maintains a unique count that is
84 * incremented each time the task successfully completes its function. Should
85 * any error occur within such a task the count is permanently halted. The
86 * 'check' task inspects the count of each task to ensure it has changed since
87 * the last time the check task executed. If all the count variables have
88 * changed all the tasks are still executing error free, and the check task
89 * toggles an LED with a three second period. Should any task contain an error
90 * at any time the LED toggle rate will increase to 500ms.
92 * Please read the documentation for the MSP430 port available on
93 * http://www.FreeRTOS.org.
96 /* Standard includes. */
99 /* Scheduler includes. */
100 #include "FreeRTOS.h"
103 /* Demo application includes. */
107 #include "comtest2.h"
110 /* Constants required for hardware setup. */
111 #define mainALL_BITS_OUTPUT ( ( unsigned char ) 0xff )
112 #define mainMAX_FREQUENCY ( ( unsigned char ) 121 )
114 /* Constants that define the LED's used by the various tasks. [in this case
115 the '*' characters on the LCD represent LED's] */
116 #define mainCHECK_LED ( 4 )
117 #define mainCOM_TEST_LED ( 10 )
119 /* Demo task priorities. */
120 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
121 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
122 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
123 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
125 /* Baud rate used by the COM test tasks. */
126 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
128 /* The frequency at which the 'Check' tasks executes. See the comments at the
129 top of the page. When the system is operating error free the 'Check' task
130 toggles an LED every three seconds. If an error is discovered in any task the
131 rate is increased to 500 milliseconds. [in this case the '*' characters on the
132 LCD represent LED's]*/
133 #define mainNO_ERROR_CHECK_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
134 #define mainERROR_CHECK_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
136 /* The constants used in the calculation. */
137 #define intgCONST1 ( ( long ) 123 )
138 #define intgCONST2 ( ( long ) 234567 )
139 #define intgCONST3 ( ( long ) -3 )
140 #define intgCONST4 ( ( long ) 7 )
141 #define intgEXPECTED_ANSWER ( ( ( intgCONST1 + intgCONST2 ) * intgCONST3 ) / intgCONST4 )
144 * The function that implements the Check task. See the comments at the head
145 * of the page for implementation details.
147 static void vErrorChecks( void *pvParameters );
150 * Called by the Check task. Returns pdPASS if all the other tasks are found
151 * to be operating without error - otherwise returns pdFAIL.
153 static short prvCheckOtherTasksAreStillRunning( void );
156 * Perform the hardware setup required by the ES449 in order to run the demo
159 static void prvSetupHardware( void );
162 portBASE_TYPE xLocalError = pdFALSE;
163 volatile unsigned long ulIdleLoops = 0UL;
165 /*-----------------------------------------------------------*/
168 * Start the demo application tasks - then start the real time scheduler.
172 /* Setup the hardware ready for the demo. */
174 vParTestInitialise();
176 /* Start the standard demo application tasks. */
177 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
178 vStartIntegerMathTasks( tskIDLE_PRIORITY );
179 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
180 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
182 /* Start the 'Check' task which is defined in this file. */
183 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
185 /* Start the scheduler. */
186 vTaskStartScheduler();
188 /* As the scheduler has been started the demo applications tasks will be
189 executing and we should never get here! */
192 /*-----------------------------------------------------------*/
194 static portTASK_FUNCTION( vErrorChecks, pvParameters )
196 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
198 /* Cycle for ever, delaying then checking all the other tasks are still
199 operating without error. */
202 /* Wait until it is time to check again. The time we wait here depends
203 on whether an error has been detected or not. When an error is
204 detected the time is shortened resulting in a faster LED flash rate. */
205 vTaskDelay( xDelayPeriod );
207 /* See if the other tasks are all ok. */
208 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
210 /* An error occurred in one of the tasks so shorten the delay
211 period - which has the effect of increasing the frequency of the
213 xDelayPeriod = mainERROR_CHECK_DELAY;
217 vParTestToggleLED( mainCHECK_LED );
220 /*-----------------------------------------------------------*/
222 static short prvCheckOtherTasksAreStillRunning( void )
224 static short sNoErrorFound = pdTRUE;
225 static unsigned long ulLastIdleLoopCount = 0UL;
227 /* The demo tasks maintain a count that increments every cycle of the task
228 provided that the task has never encountered an error. This function
229 checks the counts maintained by the tasks to ensure they are still being
230 incremented. A count remaining at the same value between calls therefore
231 indicates that an error has been detected. Only tasks that do not flash
232 an LED are checked. */
234 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
236 sNoErrorFound = pdFALSE;
239 if( xAreComTestTasksStillRunning() != pdTRUE )
241 sNoErrorFound = pdFALSE;
244 if( xArePollingQueuesStillRunning() != pdTRUE )
246 sNoErrorFound = pdFALSE;
249 if( xLocalError == pdTRUE )
251 sNoErrorFound = pdFALSE;
254 if( ulIdleLoops == ulLastIdleLoopCount )
256 sNoErrorFound = pdFALSE;
260 ulLastIdleLoopCount = ulIdleLoops;
263 return sNoErrorFound;
265 /*-----------------------------------------------------------*/
267 static void prvSetupHardware( void )
269 /* Stop the watchdog. */
270 WDTCTL = WDTPW + WDTHOLD;
272 /* Setup DCO+ for ( xtal * D * (N + 1) ) operation. */
273 FLL_CTL0 |= DCOPLUS + XCAP18PF;
275 /* X2 DCO frequency, 8MHz nominal DCO */
278 /* (121+1) x 32768 x 2 = 7.99 Mhz */
279 SCFQCTL = mainMAX_FREQUENCY;
281 /* Setup the IO. This is just copied from the demo supplied by SoftBaugh
282 for the ES449 demo board. */
289 /*-----------------------------------------------------------*/
291 /* The idle hook is just a copy of the standard integer maths tasks. See
292 Demo/Common/integer.c for rationale. */
294 void vApplicationIdleHook( void ) __toplevel
296 /* These variables are all effectively set to constants so they are volatile to
297 ensure the compiler does not just get rid of them. */
298 volatile long lValue;
299 volatile signed portBASE_TYPE *pxTaskHasExecuted;
301 /* Keep performing a calculation and checking the result against a constant. */
304 /* Perform the calculation. This will store partial value in
305 registers, resulting in a good test of the context switch mechanism. */
307 lValue += intgCONST2;
309 /* Yield in case cooperative scheduling is being used. */
310 #if configUSE_PREEMPTION == 0
316 /* Finish off the calculation. */
317 lValue *= intgCONST3;
318 lValue /= intgCONST4;
320 /* If the calculation is found to be incorrect we stop setting the
321 TaskHasExecuted variable so the check task can see an error has
323 if( lValue != intgEXPECTED_ANSWER ) /*lint !e774 volatile used to prevent this being optimised out. */
325 /* Don't bother with mutual exclusion - it is only read from the
326 check task and never written. */
327 xLocalError = pdTRUE;
329 /* Yield in case cooperative scheduling is being used. */
330 #if configUSE_PREEMPTION == 0
338 /* Place the processor into low power mode. */