2 * FreeRTOS Kernel V10.0.1
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
29 * Instead of the normal single demo application, the PIC18F demo is split
\r
30 * into several smaller programs of which this is the second. This enables the
\r
31 * demo's to be executed on the RAM limited 40 pin devices. The 64 and 80 pin
\r
32 * devices require a more costly development platform and are not so readily
\r
35 * The RTOSDemo2 project is configured for a PIC18F452 device. Main2.c starts
\r
36 * 5 tasks (including the idle task).
\r
38 * The first, second and third tasks do nothing but flash an LED. This gives
\r
39 * visual feedback that everything is executing as expected. One task flashes
\r
40 * an LED every 333ms (i.e. on and off every 333/2 ms), then next every 666ms
\r
41 * and the last every 999ms.
\r
43 * The last task runs at the idle priority. It repeatedly performs a 32bit
\r
44 * calculation and checks it's result against the expected value. This checks
\r
45 * that the temporary storage utilised by the compiler to hold intermediate
\r
46 * results does not get corrupted when the task gets switched in and out.
\r
47 * should the calculation ever provide an incorrect result the final LED is
\r
50 * On entry to main() an 'X' is transmitted. Monitoring the serial port using a
\r
51 * dumb terminal allows for verification that the device is not continuously
\r
52 * being reset (no more than one 'X' should be transmitted).
\r
54 * http://www.FreeRTOS.org contains important information on the use of the
\r
61 + Delay periods are now specified using variables and constants of
\r
62 TickType_t rather than unsigned long.
\r
65 /* Scheduler include files. */
\r
66 #include "FreeRTOS.h"
\r
69 /* Demo app include files. */
\r
71 #include "partest.h"
\r
74 /* Priority definitions for the LED tasks. Other tasks just use the idle
\r
76 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned portBASE_TYPE ) 1 )
\r
78 /* The LED that is lit when should the calculation fail. */
\r
79 #define mainCHECK_TASK_LED ( ( unsigned portBASE_TYPE ) 3 )
\r
81 /* Constants required for the communications. Only one character is ever
\r
83 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned portBASE_TYPE ) 5 )
\r
84 #define mainNO_BLOCK ( ( TickType_t ) 0 )
\r
85 #define mainBAUD_RATE ( ( unsigned long ) 9600 )
\r
88 * The task that performs the 32 bit calculation at the idle priority.
\r
90 static void vCalculationTask( void *pvParameters );
\r
92 /*-----------------------------------------------------------*/
\r
94 /* Creates the tasks, then starts the scheduler. */
\r
97 /* Initialise the required hardware. */
\r
98 vParTestInitialise();
\r
99 vPortInitialiseBlocks();
\r
101 /* Send a character so we have some visible feedback of a reset. */
\r
102 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
103 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
105 /* Start the standard LED flash tasks as defined in demo/common/minimal. */
\r
106 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
108 /* Start the check task defined in this file. */
\r
109 xTaskCreate( vCalculationTask, "Check", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL );
\r
111 /* Start the scheduler. */
\r
112 vTaskStartScheduler();
\r
114 /*-----------------------------------------------------------*/
\r
116 static void vCalculationTask( void *pvParameters )
\r
118 volatile unsigned long ulCalculatedValue; /* Volatile to ensure optimisation is minimal. */
\r
120 /* Continuously perform a calculation. If the calculation result is ever
\r
121 incorrect turn the LED on. */
\r
124 /* A good optimising compiler would just remove all this! */
\r
125 ulCalculatedValue = 1234UL;
\r
126 ulCalculatedValue *= 99UL;
\r
128 if( ulCalculatedValue != 122166UL )
\r
130 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
133 ulCalculatedValue *= 9876UL;
\r
135 if( ulCalculatedValue != 1206511416UL )
\r
137 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
140 ulCalculatedValue /= 15UL;
\r
142 if( ulCalculatedValue != 80434094UL )
\r
144 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
147 ulCalculatedValue += 918273UL;
\r
149 if( ulCalculatedValue != 81352367UL )
\r
151 vParTestSetLED( mainCHECK_TASK_LED, pdTRUE );
\r
155 /*-----------------------------------------------------------*/
\r