2 * FreeRTOS Kernel V10.2.1
\r
3 * Copyright (C) 2019 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
35 * Instead of the normal single demo application, the PIC18F demo is split
\r
36 * into several smaller programs of which this is the sixth. This enables the
\r
37 * demo's to be executed on the RAM limited PIC-devices.
\r
39 * The Demo6 project is configured for a PIC18F4620 device. Main.c starts 4
\r
40 * tasks (including the idle task). See the indicated files in the demo/common
\r
41 * directory for more information.
\r
43 * demo/common/minimal/comtest.c: Creates 2 tasks
\r
44 * ATTENTION: Comtest needs a loopback-connector on the serial port.
\r
46 * Main.c also creates a check task. This periodically checks that all the
\r
47 * other tasks are still running and have not experienced any unexpected
\r
48 * results. If all the other tasks are executing correctly an LED is flashed
\r
49 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
50 * executed, or report an error, the frequency of the LED flash will increase
\r
51 * to mainERROR_FLASH_RATE.
\r
53 * http://www.FreeRTOS.org contains important information on the use of the
\r
57 /* Scheduler include files. */
\r
58 #include <FreeRTOS.h>
\r
61 /* Demo app include files. */
\r
62 #include "partest.h"
\r
64 #include "comtest.h"
\r
66 /* The period between executions of the check task before and after an error
\r
67 has been discovered. If an error has been discovered the check task runs
\r
68 more frequently - increasing the LED flash rate. */
\r
69 #define mainNO_ERROR_CHECK_PERIOD ( ( TickType_t ) 10000 / portTICK_PERIOD_MS )
\r
70 #define mainERROR_CHECK_PERIOD ( ( TickType_t ) 1000 / portTICK_PERIOD_MS )
\r
71 #define mainCHECK_TASK_LED ( ( unsigned char ) 3 )
\r
73 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
75 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 2 )
\r
76 #define mainCOMM_TEST_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
\r
78 /* The LED that is toggled whenever a character is transmitted.
\r
79 mainCOMM_TX_RX_LED + 1 will be toggled every time a character is received. */
\r
80 #define mainCOMM_TX_RX_LED ( ( unsigned char ) 0 )
\r
82 /* Constants required for the communications. */
\r
83 #define mainBAUD_RATE ( ( unsigned long ) 57600 )
\r
86 * The task function for the "Check" task.
\r
88 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
\r
91 * Checks the unique counts of other tasks to ensure they are still operational.
\r
92 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
94 static char prvCheckOtherTasksAreStillRunning( void );
\r
96 /*-----------------------------------------------------------*/
\r
98 /* Creates the tasks, then starts the scheduler. */
\r
101 /* Initialise the required hardware. */
\r
102 vParTestInitialise();
\r
104 /* Start a few of the standard demo tasks found in the demo\common directory. */
\r
105 vAltStartComTestTasks( mainCOMM_TEST_PRIORITY, mainBAUD_RATE, mainCOMM_TX_RX_LED );
\r
107 /* Start the check task defined in this file. */
\r
108 xTaskCreate( vErrorChecks, "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
110 /* Start the scheduler. Will never return here. */
\r
111 vTaskStartScheduler();
\r
113 while(1) /* This point should never be reached. */
\r
117 /*-----------------------------------------------------------*/
\r
119 static portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
121 TickType_t xLastCheckTime;
\r
122 TickType_t xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
123 char cErrorOccurred;
\r
125 /* We need to initialise xLastCheckTime prior to the first call to
\r
126 vTaskDelayUntil(). */
\r
127 xLastCheckTime = xTaskGetTickCount();
\r
129 /* Cycle for ever, delaying then checking all the other tasks are still
\r
130 operating without error. */
\r
133 /* Wait until it is time to check the other tasks again. */
\r
134 vTaskDelayUntil( &xLastCheckTime, xDelayTime );
\r
136 /* Check all the other tasks are running, and running without ever
\r
137 having an error. */
\r
138 cErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
140 /* If an error was detected increase the frequency of the LED flash. */
\r
141 if( cErrorOccurred == pdTRUE )
\r
143 xDelayTime = mainERROR_CHECK_PERIOD;
\r
146 /* Flash the LED for visual feedback. */
\r
147 vParTestToggleLED( mainCHECK_TASK_LED );
\r
150 /*-----------------------------------------------------------*/
\r
152 static char prvCheckOtherTasksAreStillRunning( void )
\r
154 char cErrorHasOccurred = ( char ) pdFALSE;
\r
156 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
158 cErrorHasOccurred = ( char ) pdTRUE;
\r
161 return cErrorHasOccurred;
\r
163 /*-----------------------------------------------------------*/
\r