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
31 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
32 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
33 called. The demo applications included in the FreeRTOS.org download switch
\r
34 to supervisor mode prior to main being called. If you are not using one of
\r
35 these demo application projects then ensure Supervisor mode is used.
\r
40 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
41 * documentation provides more details of the demo application tasks.
\r
43 * Main.c also creates a task called "Check". This only executes every three
\r
44 * seconds but has the highest priority so is guaranteed to get processor time.
\r
45 * Its main function is to check that all the other tasks are still operational.
\r
46 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
47 * incremented each time the task successfully completes its function. Should
\r
48 * any error occur within such a task the count is permanently halted. The
\r
49 * check task inspects the count of each task to ensure it has changed since
\r
50 * the last time the check task executed. If all the count variables have
\r
51 * changed all the tasks are still executing error free, and the check task
\r
52 * toggles the onboard LED. Should any task contain an error at any time
\r
53 * the LED toggle rate will change from 3 seconds to 500ms.
\r
57 /* Standard includes. */
\r
60 /* Scheduler includes. */
\r
61 #include "FreeRTOS.h"
\r
64 /* Demo application includes. */
\r
66 #include "integer.h"
\r
69 #include "semtest.h"
\r
70 #include "dynamic.h"
\r
71 #include "partest.h"
\r
72 #include "comtest2.h"
\r
74 /* Priorities for the demo application tasks. */
\r
75 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
76 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
77 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
78 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
79 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
80 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
82 /* Constants required by the 'Check' task. */
\r
83 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
84 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
85 #define mainCHECK_TASK_LED ( 7 )
\r
87 /* Constants for the ComTest tasks. */
\r
88 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
89 #define mainCOM_TEST_LED ( 4 )
\r
90 #define mainTX_ENABLE ( ( unsigned long ) 0x0001 )
\r
91 #define mainRX_ENABLE ( ( unsigned long ) 0x0004 )
\r
93 /* Constants to setup the PLL. */
\r
94 #define mainPLL_MUL_5 ( ( unsigned char ) 0x0004 )
\r
95 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
96 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
97 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
98 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
99 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
100 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
102 /* Constants to setup the MAM. */
\r
103 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
104 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
106 /* Constants to setup the peripheral bus. */
\r
107 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
109 /* And finally, constant to setup the port for the LED's. */
\r
110 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
113 * The task that executes at the highest priority and calls
\r
114 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
117 static void vErrorChecks( void *pvParameters );
\r
120 * Configures the processor for use with this demo.
\r
122 static void prvSetupHardware( void );
\r
125 * Checks that all the demo application tasks are still executing without error
\r
126 * - as described at the top of the file.
\r
128 static long prvCheckOtherTasksAreStillRunning( void );
\r
131 /*-----------------------------------------------------------*/
\r
134 * Starts all the other tasks, then starts the scheduler.
\r
138 /* Setup the processor. */
\r
139 prvSetupHardware();
\r
141 /* Start all the standard demo application tasks. */
\r
142 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
143 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
144 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
145 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
146 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
147 vStartDynamicPriorityTasks();
\r
148 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
150 /* Start the check task - which is defined in this file. */
\r
151 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
153 /* Start the scheduler.
\r
155 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
156 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
157 called. The demo applications included in the FreeRTOS.org download switch
\r
158 to supervisor mode prior to main being called. If you are not using one of
\r
159 these demo application projects then ensure Supervisor mode is used here.
\r
161 vTaskStartScheduler();
\r
163 /* We should never get here as control is now taken by the scheduler. */
\r
166 /*-----------------------------------------------------------*/
\r
168 static void prvSetupHardware( void )
\r
170 /* Setup the PLL to multiply the XTAL input by 5. */
\r
171 PLLCFG = ( mainPLL_MUL_5 | mainPLL_DIV_1 );
\r
173 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
175 PLLCON = mainPLL_ENABLE;
\r
176 PLLFEED = mainPLL_FEED_BYTE1;
\r
177 PLLFEED = mainPLL_FEED_BYTE2;
\r
179 /* Wait for the PLL to lock... */
\r
180 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
182 /* ...before connecting it using the feed sequence again. */
\r
183 PLLCON = mainPLL_CONNECT;
\r
184 PLLFEED = mainPLL_FEED_BYTE1;
\r
185 PLLFEED = mainPLL_FEED_BYTE2;
\r
187 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
188 PLL used. It is possible faster overall performance could be obtained by
\r
189 tuning the MAM and PLL settings. */
\r
190 MAMTIM = mainMAM_TIM_3;
\r
191 MAMCR = mainMAM_MODE_FULL;
\r
193 /* Setup the peripheral bus to be the same as the PLL output. */
\r
194 APBDIV = mainBUS_CLK_FULL;
\r
196 /* Configure the RS2332 pins. All other pins remain at their default of 0. */
\r
197 PINSEL0 |= mainTX_ENABLE;
\r
198 PINSEL0 |= mainRX_ENABLE;
\r
200 /* LED pins need to be output. */
\r
201 IO1DIR = mainLED_TO_OUTPUT;
\r
203 /* Setup the peripheral bus to be the same as the PLL output. */
\r
204 APBDIV = mainBUS_CLK_FULL;
\r
206 /*-----------------------------------------------------------*/
\r
208 static void vErrorChecks( void *pvParameters )
\r
210 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
212 /* The parameters are not used in this task. */
\r
213 ( void ) pvParameters;
\r
215 /* Cycle for ever, delaying then checking all the other tasks are still
\r
216 operating without error. If an error is detected then the delay period
\r
217 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
218 the on board LED flash rate will increase. */
\r
222 /* Delay until it is time to execute again. */
\r
223 vTaskDelay( xDelayPeriod );
\r
225 /* Check all the standard demo application tasks are executing without
\r
227 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
229 /* An error has been detected in one of the tasks - flash faster. */
\r
230 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
233 vParTestToggleLED( mainCHECK_TASK_LED );
\r
236 /*-----------------------------------------------------------*/
\r
238 static long prvCheckOtherTasksAreStillRunning( void )
\r
240 long lReturn = ( long ) pdPASS;
\r
242 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
243 that they are all still running, and that none of them have detected
\r
246 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
248 lReturn = ( long ) pdFAIL;
\r
251 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
253 lReturn = ( long ) pdFAIL;
\r
256 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
258 lReturn = ( long ) pdFAIL;
\r
261 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
263 lReturn = ( long ) pdFAIL;
\r
266 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
268 lReturn = ( long ) pdFAIL;
\r
271 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
273 lReturn = ( long ) pdFAIL;
\r
278 /*-----------------------------------------------------------*/
\r