2 FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\r
9 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
10 the terms of the GNU General Public License (version 2) as published by the
\r
11 Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.
\r
13 ***************************************************************************
\r
14 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
15 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
16 >>! obliged to provide the source code for proprietary components !<<
\r
17 >>! outside of the FreeRTOS kernel. !<<
\r
18 ***************************************************************************
\r
20 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
21 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
22 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
23 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * FreeRTOS provides completely free yet professionally developed, *
\r
28 * robust, strictly quality controlled, supported, and cross *
\r
29 * platform software that is more than just the market leader, it *
\r
30 * is the industry's de facto standard. *
\r
32 * Help yourself get started quickly while simultaneously helping *
\r
33 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
34 * tutorial book, reference manual, or both: *
\r
35 * http://www.FreeRTOS.org/Documentation *
\r
37 ***************************************************************************
\r
39 http://www.FreeRTOS.org/FAQHelp.html - Having a problem? Start by reading
\r
40 the FAQ page "My application does not run, what could be wrong?". Have you
\r
41 defined configASSERT()?
\r
43 http://www.FreeRTOS.org/support - In return for receiving this top quality
\r
44 embedded software for free we request you assist our global community by
\r
45 participating in the support forum.
\r
47 http://www.FreeRTOS.org/training - Investing in training allows your team to
\r
48 be as productive as possible as early as possible. Now you can receive
\r
49 FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers
\r
50 Ltd, and the world's leading authority on the world's leading RTOS.
\r
52 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
53 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
54 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
56 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
57 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
59 http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
\r
60 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
61 licenses offer ticketed support, indemnification and commercial middleware.
\r
63 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
64 engineered and independently SIL3 certified version for use in safety and
\r
65 mission critical applications that require provable dependability.
\r
72 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
73 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
74 called. The demo applications included in the FreeRTOS.org download switch
\r
75 to supervisor mode prior to main being called. If you are not using one of
\r
76 these demo application projects then ensure Supervisor mode is used.
\r
81 * Creates all the demo application tasks, then starts the scheduler. The WEB
\r
82 * documentation provides more details of the demo application tasks.
\r
84 * Main.c also creates a task called "Check". This only executes every three
\r
85 * seconds but has the highest priority so is guaranteed to get processor time.
\r
86 * Its main function is to check that all the other tasks are still operational.
\r
87 * Each task (other than the "flash" tasks) maintains a unique count that is
\r
88 * incremented each time the task successfully completes its function. Should
\r
89 * any error occur within such a task the count is permanently halted. The
\r
90 * check task inspects the count of each task to ensure it has changed since
\r
91 * the last time the check task executed. If all the count variables have
\r
92 * changed all the tasks are still executing error free, and the check task
\r
93 * toggles the onboard LED. Should any task contain an error at any time
\r
94 * the LED toggle rate will change from 3 seconds to 500ms.
\r
98 /* Standard includes. */
\r
101 /* Scheduler includes. */
\r
102 #include "FreeRTOS.h"
\r
105 /* Demo application includes. */
\r
107 #include "integer.h"
\r
109 #include "BlockQ.h"
\r
110 #include "semtest.h"
\r
111 #include "dynamic.h"
\r
112 #include "partest.h"
\r
113 #include "comtest2.h"
\r
115 /* Priorities for the demo application tasks. */
\r
116 #define mainLED_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
117 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
118 #define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 4 )
\r
119 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
120 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
121 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
123 /* Constants required by the 'Check' task. */
\r
124 #define mainNO_ERROR_FLASH_PERIOD ( ( TickType_t ) 3000 / portTICK_PERIOD_MS )
\r
125 #define mainERROR_FLASH_PERIOD ( ( TickType_t ) 500 / portTICK_PERIOD_MS )
\r
126 #define mainCHECK_TASK_LED ( 7 )
\r
128 /* Constants for the ComTest tasks. */
\r
129 #define mainCOM_TEST_BAUD_RATE ( ( unsigned long ) 115200 )
\r
130 #define mainCOM_TEST_LED ( 4 )
\r
131 #define mainTX_ENABLE ( ( unsigned long ) 0x0001 )
\r
132 #define mainRX_ENABLE ( ( unsigned long ) 0x0004 )
\r
134 /* Constants to setup the PLL. */
\r
135 #define mainPLL_MUL_5 ( ( unsigned char ) 0x0004 )
\r
136 #define mainPLL_DIV_1 ( ( unsigned char ) 0x0000 )
\r
137 #define mainPLL_ENABLE ( ( unsigned char ) 0x0001 )
\r
138 #define mainPLL_CONNECT ( ( unsigned char ) 0x0003 )
\r
139 #define mainPLL_FEED_BYTE1 ( ( unsigned char ) 0xaa )
\r
140 #define mainPLL_FEED_BYTE2 ( ( unsigned char ) 0x55 )
\r
141 #define mainPLL_LOCK ( ( unsigned long ) 0x0400 )
\r
143 /* Constants to setup the MAM. */
\r
144 #define mainMAM_TIM_3 ( ( unsigned char ) 0x03 )
\r
145 #define mainMAM_MODE_FULL ( ( unsigned char ) 0x02 )
\r
147 /* Constants to setup the peripheral bus. */
\r
148 #define mainBUS_CLK_FULL ( ( unsigned char ) 0x01 )
\r
150 /* And finally, constant to setup the port for the LED's. */
\r
151 #define mainLED_TO_OUTPUT ( ( unsigned long ) 0xff0000 )
\r
154 * The task that executes at the highest priority and calls
\r
155 * prvCheckOtherTasksAreStillRunning(). See the description at the top
\r
158 static void vErrorChecks( void *pvParameters );
\r
161 * Configures the processor for use with this demo.
\r
163 static void prvSetupHardware( void );
\r
166 * Checks that all the demo application tasks are still executing without error
\r
167 * - as described at the top of the file.
\r
169 static long prvCheckOtherTasksAreStillRunning( void );
\r
172 /*-----------------------------------------------------------*/
\r
175 * Starts all the other tasks, then starts the scheduler.
\r
179 /* Setup the processor. */
\r
180 prvSetupHardware();
\r
182 /* Start all the standard demo application tasks. */
\r
183 vStartIntegerMathTasks( tskIDLE_PRIORITY );
\r
184 vStartLEDFlashTasks( mainLED_TASK_PRIORITY );
\r
185 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
186 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
187 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
188 vStartDynamicPriorityTasks();
\r
189 vAltStartComTestTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
191 /* Start the check task - which is defined in this file. */
\r
192 xTaskCreate( vErrorChecks, "Check", configMINIMAL_STACK_SIZE, NULL, mainCHECK_TASK_PRIORITY, NULL );
\r
194 /* Start the scheduler.
\r
196 NOTE : Tasks run in system mode and the scheduler runs in Supervisor mode.
\r
197 The processor MUST be in supervisor mode when vTaskStartScheduler is
\r
198 called. The demo applications included in the FreeRTOS.org download switch
\r
199 to supervisor mode prior to main being called. If you are not using one of
\r
200 these demo application projects then ensure Supervisor mode is used here.
\r
202 vTaskStartScheduler();
\r
204 /* We should never get here as control is now taken by the scheduler. */
\r
207 /*-----------------------------------------------------------*/
\r
209 static void prvSetupHardware( void )
\r
211 /* Setup the PLL to multiply the XTAL input by 5. */
\r
212 PLLCFG = ( mainPLL_MUL_5 | mainPLL_DIV_1 );
\r
214 /* Activate the PLL by turning it on then feeding the correct sequence of
\r
216 PLLCON = mainPLL_ENABLE;
\r
217 PLLFEED = mainPLL_FEED_BYTE1;
\r
218 PLLFEED = mainPLL_FEED_BYTE2;
\r
220 /* Wait for the PLL to lock... */
\r
221 while( !( PLLSTAT & mainPLL_LOCK ) );
\r
223 /* ...before connecting it using the feed sequence again. */
\r
224 PLLCON = mainPLL_CONNECT;
\r
225 PLLFEED = mainPLL_FEED_BYTE1;
\r
226 PLLFEED = mainPLL_FEED_BYTE2;
\r
228 /* Setup and turn on the MAM. Three cycle access is used due to the fast
\r
229 PLL used. It is possible faster overall performance could be obtained by
\r
230 tuning the MAM and PLL settings. */
\r
231 MAMTIM = mainMAM_TIM_3;
\r
232 MAMCR = mainMAM_MODE_FULL;
\r
234 /* Setup the peripheral bus to be the same as the PLL output. */
\r
235 APBDIV = mainBUS_CLK_FULL;
\r
237 /* Configure the RS2332 pins. All other pins remain at their default of 0. */
\r
238 PINSEL0 |= mainTX_ENABLE;
\r
239 PINSEL0 |= mainRX_ENABLE;
\r
241 /* LED pins need to be output. */
\r
242 IO1DIR = mainLED_TO_OUTPUT;
\r
244 /* Setup the peripheral bus to be the same as the PLL output. */
\r
245 APBDIV = mainBUS_CLK_FULL;
\r
247 /*-----------------------------------------------------------*/
\r
249 static void vErrorChecks( void *pvParameters )
\r
251 TickType_t xDelayPeriod = mainNO_ERROR_FLASH_PERIOD;
\r
253 /* The parameters are not used in this task. */
\r
254 ( void ) pvParameters;
\r
256 /* Cycle for ever, delaying then checking all the other tasks are still
\r
257 operating without error. If an error is detected then the delay period
\r
258 is decreased from mainNO_ERROR_FLASH_PERIOD to mainERROR_FLASH_PERIOD so
\r
259 the on board LED flash rate will increase. */
\r
263 /* Delay until it is time to execute again. */
\r
264 vTaskDelay( xDelayPeriod );
\r
266 /* Check all the standard demo application tasks are executing without
\r
268 if( prvCheckOtherTasksAreStillRunning() != pdPASS )
\r
270 /* An error has been detected in one of the tasks - flash faster. */
\r
271 xDelayPeriod = mainERROR_FLASH_PERIOD;
\r
274 vParTestToggleLED( mainCHECK_TASK_LED );
\r
277 /*-----------------------------------------------------------*/
\r
279 static long prvCheckOtherTasksAreStillRunning( void )
\r
281 long lReturn = ( long ) pdPASS;
\r
283 /* Check all the demo tasks (other than the flash tasks) to ensure
\r
284 that they are all still running, and that none of them have detected
\r
287 if( xAreIntegerMathsTaskStillRunning() != pdTRUE )
\r
289 lReturn = ( long ) pdFAIL;
\r
292 if( xArePollingQueuesStillRunning() != pdTRUE )
\r
294 lReturn = ( long ) pdFAIL;
\r
297 if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
299 lReturn = ( long ) pdFAIL;
\r
302 if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
304 lReturn = ( long ) pdFAIL;
\r
307 if( xAreComTestTasksStillRunning() != pdTRUE )
\r
309 lReturn = ( long ) pdFAIL;
\r
312 if( xAreDynamicPriorityTasksStillRunning() != pdTRUE )
\r
314 lReturn = ( long ) pdFAIL;
\r
319 /*-----------------------------------------------------------*/
\r