2 FreeRTOS V7.5.1 - 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
66 * THIS DEMO APPLICATION REQUIRES A LOOPBACK CONNECTOR TO BE FITTED TO THE PIC
\r
67 * USART PORT - connect pin 2 to pin 3 on J2.
\r
69 * Instead of the normal single demo application, the PIC18F demo is split
\r
70 * into several smaller programs of which this is the third. This enables the
\r
71 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
72 * devices require a more costly development platform and are not so readily
\r
75 * The RTOSDemo3 project is configured for a PIC18F452 device. Main3.c starts
\r
76 * 5 tasks (including the idle task).
\r
78 * The first task repeatedly transmits a string of characters on the PIC USART
\r
79 * port. The second task receives the characters, checking that the correct
\r
80 * sequence is maintained (i.e. what is transmitted is identical to that
\r
81 * received). Each transmitted and each received character causes an LED to
\r
82 * flash. See demo/common/minimal/comtest. c for more information.
\r
84 * The third task continuously performs a 32 bit calculation. This is a good
\r
85 * test of the context switch mechanism as the 8 bit architecture requires
\r
86 * the use of several file registers to perform the 32 bit operations. See
\r
87 * demo/common/minimal/integer. c for more information.
\r
89 * The third task is the check task. This periodically checks that the other
\r
90 * tasks are still running and have not experienced any errors. If no errors
\r
91 * have been reported by either the comms or integer tasks an LED is flashed
\r
92 * with a frequency mainNO_ERROR_CHECK_PERIOD. If an error is discovered the
\r
93 * frequency is increased to mainERROR_FLASH_RATE.
\r
95 * The check task also provides a visual indication of a system reset by
\r
96 * flashing the one remaining LED (mainRESET_LED) when it starts. After
\r
97 * this initial flash mainRESET_LED should remain off.
\r
99 * http://www.FreeRTOS.org contains important information on the use of the
\r
104 Changes from V2.0.0
\r
106 + Delay periods are now specified using variables and constants of
\r
107 portTickType rather than unsigned long.
\r
110 /* Scheduler include files. */
\r
111 #include "FreeRTOS.h"
\r
114 /* Demo app include files. */
\r
115 #include "partest.h"
\r
116 #include "serial.h"
\r
117 #include "comtest.h"
\r
118 #include "integer.h"
\r
120 /* Priority definitions for the LED tasks. Other tasks just use the idle
\r
122 #define mainCOMM_TEST_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 2 )
\r
123 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 3 )
\r
125 /* The period between executions of the check task before and after an error
\r
126 has been discovered. If an error has been discovered the check task runs
\r
127 more frequently - increasing the LED flash rate. */
\r
128 #define mainNO_ERROR_CHECK_PERIOD ( ( portTickType ) 1000 / portTICK_RATE_MS )
\r
129 #define mainERROR_CHECK_PERIOD ( ( portTickType ) 100 / portTICK_RATE_MS )
\r
131 /* The period for which mainRESET_LED remain on every reset. */
\r
132 #define mainRESET_LED_PERIOD ( ( portTickType ) 500 / portTICK_RATE_MS )
\r
134 /* The LED that is toggled whenever a character is transmitted.
\r
135 mainCOMM_TX_RX_LED + 1 will be toggled every time a character is received. */
\r
136 #define mainCOMM_TX_RX_LED ( ( unsigned portBASE_TYPE ) 2 )
\r
138 /* The LED that is flashed by the check task at a rate that indicates the
\r
140 #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 1 )
\r
142 /* The LED that is flashed once upon every reset. */
\r
143 #define mainRESET_LED ( ( unsigned portBASE_TYPE ) 0 )
\r
145 /* Constants required for the communications. */
\r
146 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
\r
147 #define mainBAUD_RATE ( ( unsigned long ) 57600 )
\r
148 /*-----------------------------------------------------------*/
\r
151 * Task function which periodically checks the other tasks for errors. Flashes
\r
152 * an LED at a rate that indicates whether an error has ever been detected.
\r
154 static void vErrorChecks( void *pvParameters );
\r
156 /*-----------------------------------------------------------*/
\r
158 /* Creates the tasks, then starts the scheduler. */
\r
161 /* Initialise the required hardware. */
\r
162 vParTestInitialise();
\r
164 /* Initialise the block memory allocator. */
\r
165 vPortInitialiseBlocks();
\r
167 /* Start the standard comtest tasks as defined in demo/common/minimal. */
\r
168 vAltStartComTestTasks( mainCOMM_TEST_PRIORITY, mainBAUD_RATE, mainCOMM_TX_RX_LED );
\r
170 /* Start the standard 32bit calculation task as defined in
\r
171 demo/common/minimal. */
\r
172 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
174 /* Start the check task defined in this file. */
\r
175 xTaskCreate( vErrorChecks, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
177 /* Start the scheduler. This will never return. */
\r
178 vTaskStartScheduler();
\r
180 /*-----------------------------------------------------------*/
\r
182 static void vErrorChecks( void *pvParameters )
\r
184 portTickType xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
185 volatile unsigned long ulDummy = 3UL;
\r
187 /* Toggle the LED so we can see when a reset occurs. */
\r
188 vParTestSetLED( mainRESET_LED, pdTRUE );
\r
189 vTaskDelay( mainRESET_LED_PERIOD );
\r
190 vParTestSetLED( mainRESET_LED, pdFALSE );
\r
192 /* Cycle for ever, delaying then checking all the other tasks are still
\r
193 operating without error. */
\r
196 /* Wait until it is time to check the other tasks. */
\r
197 vTaskDelay( xDelayTime );
\r
199 /* Perform an integer calculation - just to ensure the registers
\r
200 get used. The result is not important. */
\r
203 /* Check all the other tasks are running, and running without ever
\r
204 having an error. The delay period is lowered if an error is reported,
\r
205 causing the LED to flash at a higher rate. */
\r
206 if( xAreIntegerMathsTaskStillRunning() == pdFALSE )
\r
208 xDelayTime = mainERROR_CHECK_PERIOD;
\r
211 if( xAreComTestTasksStillRunning() == pdFALSE )
\r
213 xDelayTime = mainERROR_CHECK_PERIOD;
\r
216 /* Flash the LED for visual feedback. The rate of the flash will
\r
217 indicate the health of the system. */
\r
218 vParTestToggleLED( mainCHECK_TASK_LED );
\r
221 /*-----------------------------------------------------------*/
\r