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. */
100 /* Scheduler includes. */
101 #include "FreeRTOS.h"
104 /* Demo application includes. */
108 #include "comtest2.h"
111 /* Constants required for hardware setup. */
112 #define mainALL_BITS_OUTPUT ( ( unsigned char ) 0xff )
113 #define mainMAX_FREQUENCY ( ( unsigned char ) 121 )
115 /* Constants that define the LED's used by the various tasks. [in this case
116 the '*' characters on the LCD represent LED's] */
117 #define mainCHECK_LED ( 4 )
118 #define mainCOM_TEST_LED ( 10 )
120 /* Demo task priorities. */
121 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
122 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
123 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
124 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
126 /* Baud rate used by the COM test tasks. */
127 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 19200 )
129 /* The frequency at which the 'Check' tasks executes. See the comments at the
130 top of the page. When the system is operating error free the 'Check' task
131 toggles an LED every three seconds. If an error is discovered in any task the
132 rate is increased to 500 milliseconds. [in this case the '*' characters on the
133 LCD represent LED's]*/
134 #define mainNO_ERROR_CHECK_DELAY ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
135 #define mainERROR_CHECK_DELAY ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
138 * The function that implements the Check task. See the comments at the head
139 * of the page for implementation details.
141 static void vErrorChecks( void *pvParameters );
144 * Called by the Check task. Returns pdPASS if all the other tasks are found
145 * to be operating without error - otherwise returns pdFAIL.
147 static short prvCheckOtherTasksAreStillRunning( void );
150 * Perform the hardware setup required by the ES449 in order to run the demo
153 static void prvSetupHardware( void );
155 /* Used to detect the idle hook function stalling. */
156 static volatile unsigned long ulIdleLoops = 0UL;
158 /*-----------------------------------------------------------*/
161 * Start the demo application tasks - then start the real time scheduler.
165 /* Setup the hardware ready for the demo. */
167 vParTestInitialise();
169 /* Start the standard demo application tasks. */
170 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
171 vStartIntegerMathTasks( tskIDLE_PRIORITY );
172 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED - 1 );
173 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
175 /* Start the 'Check' task which is defined in this file. */
176 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
178 /* Start the scheduler. */
179 vTaskStartScheduler();
181 /* As the scheduler has been started the demo applications tasks will be
182 executing and we should never get here! */
185 /*-----------------------------------------------------------*/
187 static void vErrorChecks( void *pvParameters )
189 static volatile unsigned long ulDummyVariable = 3UL;
190 TickType_t xDelayPeriod = mainNO_ERROR_CHECK_DELAY;
192 /* Cycle for ever, delaying then checking all the other tasks are still
193 operating without error. */
196 /* Wait until it is time to check again. The time we wait here depends
197 on whether an error has been detected or not. When an error is
198 detected the time is shortened resulting in a faster LED flash rate. */
199 vTaskDelay( xDelayPeriod );
201 /* Perform a bit of 32bit maths to ensure the registers used by the
202 integer tasks get some exercise outside of the integer tasks
203 themselves. The result here is not important we are just deliberately
204 changing registers used by other tasks to ensure that their context
205 switch is operating as required. - see the demo application
206 documentation for more info. */
207 ulDummyVariable *= 3UL;
209 /* See if the other tasks are all ok. */
210 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
212 /* An error occurred in one of the tasks so shorten the delay
213 period - which has the effect of increasing the frequency of the
215 xDelayPeriod = mainERROR_CHECK_DELAY;
219 vParTestToggleLED( mainCHECK_LED );
222 /*-----------------------------------------------------------*/
224 static short prvCheckOtherTasksAreStillRunning( void )
226 static short sNoErrorFound = pdTRUE;
227 static unsigned long ulLastIdleLoops = 0UL;
229 /* The demo tasks maintain a count that increments every cycle of the task
230 provided that the task has never encountered an error. This function
231 checks the counts maintained by the tasks to ensure they are still being
232 incremented. A count remaining at the same value between calls therefore
233 indicates that an error has been detected. Only tasks that do not flash
234 an LED are checked. */
236 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
238 sNoErrorFound = pdFALSE;
241 if( xAreComTestTasksStillRunning() != pdTRUE )
243 sNoErrorFound = pdFALSE;
246 if( xArePollingQueuesStillRunning() != pdTRUE )
248 sNoErrorFound = pdFALSE;
251 if( ulLastIdleLoops == ulIdleLoops )
253 sNoErrorFound = pdFALSE;
256 ulLastIdleLoops = ulIdleLoops;
258 return sNoErrorFound;
260 /*-----------------------------------------------------------*/
262 static void prvSetupHardware( void )
264 /* Stop the watchdog. */
265 WDTCTL = WDTPW + WDTHOLD;
267 /* Setup DCO+ for ( xtal * D * (N + 1) ) operation. */
268 FLL_CTL0 |= DCOPLUS + XCAP18PF;
270 /* X2 DCO frequency, 8MHz nominal DCO */
273 /* (121+1) x 32768 x 2 = 7.99 Mhz */
274 SCFQCTL = mainMAX_FREQUENCY;
276 /* Setup the IO as per the SoftBaugh demo for the same target hardware. */
283 /*-----------------------------------------------------------*/
285 void vApplicationIdleHook( void );
286 void vApplicationIdleHook( void )
288 /* Simple put the CPU into lowpower mode. */
289 _BIS_SR( LPM3_bits );
292 /*-----------------------------------------------------------*/