2 * FreeRTOS Kernel V10.0.0
\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. If you wish to use our Amazon
\r
14 * FreeRTOS name, please do so in a fair use way that does not cause confusion.
\r
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
36 * Instead of the normal single demo application, the PIC18F demo is split
\r
37 * into several smaller programs of which this is the second. This enables the
\r
38 * demo's to be executed on the RAM limited PIC-devices.
\r
40 * The Demo2 project is configured for a PIC18F4620 device. Main.c starts 12
\r
41 * tasks (including the idle task). See the indicated files in the demo/common
\r
42 * directory for more information.
\r
44 * demo/common/minimal/integer.c: Creates 1 task
\r
45 * demo/common/minimal/PollQ.c: Creates 2 tasks
\r
46 * demo/common/minimal/semtest.c: Creates 4 tasks
\r
47 * demo/common/minimal/flash.c: Creates 3 tasks
\r
49 * Main.c also creates a check task. This periodically checks that all the
\r
50 * other tasks are still running and have not experienced any unexpected
\r
51 * results. If all the other tasks are executing correctly an LED is flashed
\r
52 * once every mainCHECK_PERIOD milliseconds. If any of the tasks have not
\r
53 * executed, or report an error, the frequency of the LED flash will increase
\r
54 * to mainERROR_FLASH_RATE.
\r
56 * On entry to main an 'X' is transmitted. Monitoring the serial port using a
\r
57 * dumb terminal allows for verification that the device is not continuously
\r
58 * being reset (no more than one 'X' should be transmitted).
\r
60 * http://www.FreeRTOS.org contains important information on the use of the
\r
64 /* Scheduler include files. */
\r
65 #include <FreeRTOS.h>
\r
68 /* Demo app include files. */
\r
69 #include "integer.h"
\r
71 #include "semtest.h"
\r
73 #include "partest.h"
\r
76 /* The period between executions of the check task before and after an error
\r
77 has been discovered. If an error has been discovered the check task runs
\r
78 more frequently - increasing the LED flash rate. */
\r
79 #define mainNO_ERROR_CHECK_PERIOD ( ( TickType_t ) 10000 / portTICK_PERIOD_MS )
\r
80 #define mainERROR_CHECK_PERIOD ( ( TickType_t ) 1000 / portTICK_PERIOD_MS )
\r
81 #define mainCHECK_TASK_LED ( ( unsigned char ) 3 )
\r
83 /* Priority definitions for some of the tasks. Other tasks just use the idle
\r
85 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 3 )
\r
86 #define mainLED_FLASH_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 2 )
\r
87 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
\r
88 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 1 )
\r
89 #define mainINTEGER_PRIORITY ( tskIDLE_PRIORITY + ( unsigned char ) 0 )
\r
91 /* Constants required for the communications. Only one character is ever
\r
93 #define mainCOMMS_QUEUE_LENGTH ( ( unsigned char ) 5 )
\r
94 #define mainNO_BLOCK ( ( TickType_t ) 0 )
\r
95 #define mainBAUD_RATE ( ( unsigned long ) 57600 )
\r
98 * The task function for the "Check" task.
\r
100 static portTASK_FUNCTION_PROTO( vErrorChecks, pvParameters );
\r
103 * Checks the unique counts of other tasks to ensure they are still operational.
\r
104 * Returns pdTRUE if an error is detected, otherwise pdFALSE.
\r
106 static char prvCheckOtherTasksAreStillRunning( void );
\r
108 /*-----------------------------------------------------------*/
\r
110 /* Creates the tasks, then starts the scheduler. */
\r
113 /* Initialise the required hardware. */
\r
114 vParTestInitialise();
\r
116 /* Send a character so we have some visible feedback of a reset. */
\r
117 xSerialPortInitMinimal( mainBAUD_RATE, mainCOMMS_QUEUE_LENGTH );
\r
118 xSerialPutChar( NULL, 'X', mainNO_BLOCK );
\r
120 /* Start a few of the standard demo tasks found in the demo\common directory. */
\r
121 vStartIntegerMathTasks( mainINTEGER_PRIORITY);
\r
122 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
123 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
124 vStartLEDFlashTasks( mainLED_FLASH_PRIORITY );
\r
126 /* Start the check task defined in this file. */
\r
127 xTaskCreate( vErrorChecks, "Check", portMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
129 /* Start the scheduler. Will never return here. */
\r
130 vTaskStartScheduler();
\r
132 while(1) /* This point should never be reached. */
\r
136 /*-----------------------------------------------------------*/
\r
138 static portTASK_FUNCTION( vErrorChecks, pvParameters )
\r
140 TickType_t xLastCheckTime;
\r
141 TickType_t xDelayTime = mainNO_ERROR_CHECK_PERIOD;
\r
142 char cErrorOccurred;
\r
144 /* We need to initialise xLastCheckTime prior to the first call to
\r
145 vTaskDelayUntil(). */
\r
146 xLastCheckTime = xTaskGetTickCount();
\r
148 /* Cycle for ever, delaying then checking all the other tasks are still
\r
149 operating without error. */
\r
152 /* Wait until it is time to check the other tasks again. */
\r
153 vTaskDelayUntil( &xLastCheckTime, xDelayTime );
\r
155 /* Check all the other tasks are running, and running without ever
\r
156 having an error. */
\r
157 cErrorOccurred = prvCheckOtherTasksAreStillRunning();
\r
159 /* If an error was detected increase the frequency of the LED flash. */
\r
160 if( cErrorOccurred == pdTRUE )
\r
162 xDelayTime = mainERROR_CHECK_PERIOD;
\r
165 /* Flash the LED for visual feedback. */
\r
166 vParTestToggleLED( mainCHECK_TASK_LED );
\r
169 /*-----------------------------------------------------------*/
\r
171 static char prvCheckOtherTasksAreStillRunning( void )
\r
173 char cErrorHasOccurred = ( char ) pdFALSE;
\r
175 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
177 cErrorHasOccurred = ( char ) pdTRUE;
\r
180 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
182 cErrorHasOccurred = ( char ) pdTRUE;
\r
185 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
187 cErrorHasOccurred = ( char ) pdTRUE;
\r
190 return cErrorHasOccurred;
\r
192 /*-----------------------------------------------------------*/
\r