Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 1 | /*
|
Richard Barry | e262d95 | 2010-02-25 13:41:09 +0000 | [diff] [blame] | 2 | FreeRTOS V6.0.3 - Copyright (C) 2010 Real Time Engineers Ltd.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 3 |
|
Richard Barry | 26bf0da | 2009-10-13 11:05:41 +0000 | [diff] [blame] | 4 | ***************************************************************************
|
| 5 | * *
|
| 6 | * If you are: *
|
| 7 | * *
|
| 8 | * + New to FreeRTOS, *
|
| 9 | * + Wanting to learn FreeRTOS or multitasking in general quickly *
|
| 10 | * + Looking for basic training, *
|
| 11 | * + Wanting to improve your FreeRTOS skills and productivity *
|
| 12 | * *
|
| 13 | * then take a look at the FreeRTOS eBook *
|
| 14 | * *
|
| 15 | * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
|
| 16 | * http://www.FreeRTOS.org/Documentation *
|
| 17 | * *
|
| 18 | * A pdf reference manual is also available. Both are usually delivered *
|
| 19 | * to your inbox within 20 minutes to two hours when purchased between 8am *
|
| 20 | * and 8pm GMT (although please allow up to 24 hours in case of *
|
| 21 | * exceptional circumstances). Thank you for your support! *
|
| 22 | * *
|
| 23 | ***************************************************************************
|
| 24 |
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 25 | This file is part of the FreeRTOS distribution.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 26 |
|
Richard Barry | 26bf0da | 2009-10-13 11:05:41 +0000 | [diff] [blame] | 27 | FreeRTOS is free software; you can redistribute it and/or modify it under
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 28 | the terms of the GNU General Public License (version 2) as published by the
|
Richard Barry | 26bf0da | 2009-10-13 11:05:41 +0000 | [diff] [blame] | 29 | Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
|
| 30 | ***NOTE*** The exception to the GPL is included to allow you to distribute
|
| 31 | a combined work that includes FreeRTOS without being obliged to provide the
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 32 | source code for proprietary components outside of the FreeRTOS kernel.
|
Richard Barry | 26bf0da | 2009-10-13 11:05:41 +0000 | [diff] [blame] | 33 | FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 34 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
| 35 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
Richard Barry | 26bf0da | 2009-10-13 11:05:41 +0000 | [diff] [blame] | 36 | more details. You should have received a copy of the GNU General Public
|
| 37 | License and the FreeRTOS license exception along with FreeRTOS; if not it
|
| 38 | can be viewed here: http://www.freertos.org/a00114.html and also obtained
|
| 39 | by writing to Richard Barry, contact details for whom are available on the
|
| 40 | FreeRTOS WEB site.
|
Richard Barry | 2f40ad7 | 2009-03-14 19:20:12 +0000 | [diff] [blame] | 41 |
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 42 | 1 tab == 4 spaces!
|
Richard Barry | 0a6d59a | 2007-04-01 20:47:49 +0000 | [diff] [blame] | 43 |
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 44 | http://www.FreeRTOS.org - Documentation, latest information, license and
|
| 45 | contact details.
|
Richard Barry | c86dcf7 | 2008-02-03 19:45:58 +0000 | [diff] [blame] | 46 |
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 47 | http://www.SafeRTOS.com - A version that is certified for use in safety
|
| 48 | critical systems.
|
Richard Barry | c86dcf7 | 2008-02-03 19:45:58 +0000 | [diff] [blame] | 49 |
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 50 | http://www.OpenRTOS.com - Commercial support, development, porting,
|
| 51 | licensing and training services.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 52 | */
|
| 53 |
|
| 54 | /*
|
| 55 | * Instead of the normal single demo application, the PIC18F demo is split
|
| 56 | * into several smaller programs of which this is the second. This enables the
|
| 57 | * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
|
| 58 | * devices require a more costly development platform and are not so readily
|
| 59 | * available.
|
| 60 | *
|
| 61 | * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
|
| 62 | * 5 tasks (including the idle task).
|
| 63 | *
|
| 64 | * The first, second and third tasks do nothing but flash an LED. This gives
|
| 65 | * visual feedback that everything is executing as expected. One task flashes
|
| 66 | * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
|
| 67 | * and the last every 999ms.
|
| 68 | *
|
| 69 | * The last task runs at the idle priority. It repeatedly performs a 32bit
|
| 70 | * calculation and checks it's result against the expected value. This checks
|
| 71 | * that the temporary storage utilised by the compiler to hold intermediate
|
| 72 | * results does not get corrupted when the task gets switched in and out.
|
| 73 | * should the calculation ever provide an incorrect result the final LED is
|
| 74 | * turned on.
|
| 75 | *
|
| 76 | * On entry to main() an 'X' is transmitted. Monitoring the serial port using a
|
| 77 | * dumb terminal allows for verification that the device is not continuously
|
| 78 | * being reset (no more than one 'X' should be transmitted).
|
| 79 | *
|
| 80 | * http://www.FreeRTOS.org contains important information on the use of the
|
| 81 | * PIC18F port.
|
| 82 | */
|
| 83 |
|
| 84 | /*
|
| 85 | Changes from V2.0.0
|
| 86 |
|
| 87 | + Delay periods are now specified using variables and constants of
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 88 | portTickType rather than unsigned long.
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 89 | */
|
| 90 |
|
| 91 | /* Scheduler include files. */
|
| 92 | #include "FreeRTOS.h"
|
| 93 | #include "task.h"
|
| 94 |
|
| 95 | /* Demo app include files. */
|
| 96 | #include "flash.h"
|
| 97 | #include "partest.h"
|
| 98 | #include "serial.h"
|
| 99 |
|
| 100 | /* Priority definitions for the LED tasks. Other tasks just use the idle
|
| 101 | priority. */
|
| 102 | #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
|
| 103 |
|
| 104 | /* The LED that is lit when should the calculation fail. */
|
| 105 | #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
|
| 106 |
|
| 107 | /* Constants required for the communications. Only one character is ever
|
| 108 | transmitted. */
|
| 109 | #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
|
| 110 | #define mainNO_BLOCK ( ( portTickType ) 0 )
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 111 | #define mainBAUD_RATE ( ( unsigned long ) 9600 )
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 112 |
|
| 113 | /*
|
| 114 | * The task that performs the 32 bit calculation at the idle priority.
|
| 115 | */
|
| 116 | static void vCalculationTask( void *pvParameters );
|
| 117 |
|
| 118 | /*-----------------------------------------------------------*/
|
| 119 |
|
| 120 | /* Creates the tasks, then starts the scheduler. */
|
| 121 | void main( void )
|
| 122 | {
|
| 123 | /* Initialise the required hardware. */
|
| 124 | vParTestInitialise();
|
| 125 | vPortInitialiseBlocks();
|
| 126 |
|
| 127 | /* Send a character so we have some visible feedback of a reset. */
|
| 128 | xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
|
| 129 | xSerialPutChar( NULL, 'X', mainNO_BLOCK );
|
| 130 |
|
| 131 | /* Start the standard LED flash tasks as defined in demo/common/minimal. */
|
| 132 | vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
|
| 133 |
|
| 134 | /* Start the check task defined in this file. */
|
Richard Barry | 9468e36 | 2009-10-05 11:10:48 +0000 | [diff] [blame] | 135 | xTaskCreate( vCalculationTask, ( const char * const ) "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
|
Richard Barry | b6df57c | 2006-05-02 09:39:15 +0000 | [diff] [blame] | 136 |
|
| 137 | /* Start the scheduler. */
|
| 138 | vTaskStartScheduler();
|
| 139 | }
|
| 140 | /*-----------------------------------------------------------*/
|
| 141 |
|
| 142 | static void vCalculationTask( void *pvParameters )
|
| 143 | {
|
| 144 | volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
|
| 145 |
|
| 146 | /* Continuously perform a calculation. If the calculation result is ever
|
| 147 | incorrect turn the LED on. */
|
| 148 | for( ;; )
|
| 149 | {
|
| 150 | /* A good optimising compiler would just remove all this! */
|
| 151 | ulCalculatedValue = 1234UL;
|
| 152 | ulCalculatedValue *= 99UL;
|
| 153 |
|
| 154 | if( ulCalculatedValue != 122166UL )
|
| 155 | {
|
| 156 | vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
|
| 157 | }
|
| 158 |
|
| 159 | ulCalculatedValue *= 9876UL;
|
| 160 |
|
| 161 | if( ulCalculatedValue != 1206511416UL )
|
| 162 | {
|
| 163 | vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
|
| 164 | }
|
| 165 |
|
| 166 | ulCalculatedValue /= 15UL;
|
| 167 |
|
| 168 | if( ulCalculatedValue != 80434094UL )
|
| 169 | {
|
| 170 | vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
|
| 171 | }
|
| 172 |
|
| 173 | ulCalculatedValue += 918273UL;
|
| 174 |
|
| 175 | if( ulCalculatedValue != 81352367UL )
|
| 176 | {
|
| 177 | vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
|
| 178 | }
|
| 179 | }
|
| 180 | }
|
| 181 | /*-----------------------------------------------------------*/
|
| 182 |
|