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
70 /* ****************************************************************************
\r
71 * This project includes a lot of tasks and tests and is therefore complex.
\r
72 * If you would prefer a much simpler project to get started with then select
\r
73 * the 'low power' demo by setting configCREATE_LOW_POWER_DEMO to 1 in
\r
74 * FreeRTOSConfig.h. When configCREATE_LOW_POWER_DEMO is set to 1 main() will
\r
75 * call main_low_power() instead of main_full().
\r
76 * ****************************************************************************
\r
78 * Creates all the demo application tasks, then starts the scheduler. The web
\r
79 * documentation provides more details of the standard demo application tasks,
\r
80 * which provide no particular functionality but do provide a good example of
\r
81 * how to use the FreeRTOS API.
\r
83 * In addition to the standard demo tasks, the following tasks and tests are
\r
84 * defined and/or created within this file:
\r
86 * "Reg test" tasks - These fill the registers with known values, then
\r
87 * repeatedly check that each register still contains its expected value for
\r
88 * the lifetime of the tasks. Each task uses different values. The tasks run
\r
89 * with very low priority so get preempted very frequently. A check variable
\r
90 * is incremented on each iteration of the test loop. A register containing an
\r
91 * unexpected value is indicative of an error in the context switching
\r
92 * mechanism and will result in a branch to a null loop - which in turn will
\r
93 * prevent the check variable from incrementing any further and allow the check
\r
94 * timer (described below) to determine that an error has occurred. The nature
\r
95 * of the reg test tasks necessitates that they are written in assembly code.
\r
97 * "Check Timer" and Callback Function - The check timer period is initially
\r
98 * set to three seconds. The check timer callback function checks that all the
\r
99 * standard demo tasks are not only still executing, but are executing without
\r
100 * reporting any errors. If the check timer discovers that a task has either
\r
101 * stalled, or reported an error, then it changes its own period from the
\r
102 * initial three seconds, to just 200ms. The check timer callback function
\r
103 * also toggles LED 0 each time it is called. This provides a visual
\r
104 * indication of the system status: If the LED toggles every three seconds,
\r
105 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
106 * an issue has been discovered with at least one task.
\r
108 * *NOTE 1* The CPU must be in Supervisor mode when the scheduler is started.
\r
109 * The PowerON_Reset_PC() supplied in resetprg.c with this demo has
\r
110 * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.
\r
113 /* Standard includes. */
\r
114 #include <string.h>
\r
116 /* Hardware specific includes. */
\r
117 #include "iorx111.h"
\r
119 /* Kernel includes. */
\r
120 #include "FreeRTOS.h"
\r
122 #include "timers.h"
\r
123 #include "semphr.h"
\r
125 /* Standard demo includes. */
\r
126 #include "partest.h"
\r
128 #include "blocktim.h"
\r
129 #include "GenQTest.h"
\r
130 #include "recmutex.h"
\r
133 /* Variables that are incremented on each iteration of the reg test tasks are
\r
134 declared outside of the #if configCREATE_LOW_POWER_DEMO conditional compilation
\r
135 to prevent linker issues when configCREATE_LOW_POWER_DEMO is set to 1. The
\r
136 check timer inspects these variables to ensure they are still incrementing as
\r
137 expected. If a variable stops incrementing then it is likely that its associate
\r
138 task has stalled. */
\r
139 unsigned long volatile ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;
\r
142 /* The code in this file is only built when configCREATE_LOW_POWER_DEMO is set
\r
143 to 0, otherwise the code in main_low_power.c is used. */
\r
144 #if configCREATE_LOW_POWER_DEMO == 0
\r
147 /* Values that are passed into the reg test tasks using the task parameter.
\r
148 The tasks check that the values are passed in correctly. */
\r
149 #define mainREG_TEST_1_PARAMETER ( 0x12121212UL )
\r
150 #define mainREG_TEST_2_PARAMETER ( 0x12345678UL )
\r
152 /* Priorities at which the standard demo tasks are created. */
\r
153 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
154 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
156 /* The LED toggled by the check timer. */
\r
157 #define mainCHECK_LED ( 0 )
\r
159 /* The period at which the check timer will expire, in ms, provided no errors
\r
160 have been reported by any of the standard demo tasks. ms are converted to the
\r
161 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
162 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
164 /* The period at which the check timer will expire, in ms, if an error has been
\r
165 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
166 in ticks using the portTICK_PERIOD_MS constant. */
\r
167 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
169 /* A block time of zero simple means "Don't Block". */
\r
170 #define mainDONT_BLOCK ( 0UL )
\r
173 * The reg test tasks as described at the top of this file.
\r
175 static void prvRegTest1Task( void *pvParameters );
\r
176 static void prvRegTest2Task( void *pvParameters );
\r
179 * The actual implementation of the reg test functionality, which, because of
\r
180 * the direct register access, have to be in assembly.
\r
182 void vRegTest1Implementation( void );
\r
183 void vRegTest2Implementation( void );
\r
186 * The check timer callback function, as described at the top of this file.
\r
188 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
191 /*-----------------------------------------------------------*/
\r
193 /* The check timer. This uses prvCheckTimerCallback() as its callback
\r
195 static TimerHandle_t xCheckTimer = NULL;
\r
197 /*-----------------------------------------------------------*/
\r
199 void main_full( void )
\r
201 /* Start the reg test tasks which test the context switching mechanism. */
\r
202 xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
203 xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
205 /* Create the standard demo tasks. */
\r
206 vCreateBlockTimeTasks();
\r
207 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
208 vStartRecursiveMutexTasks();
\r
210 /* The suicide tasks must be created last as they need to know how many
\r
211 tasks were running prior to their creation in order to ascertain whether
\r
212 or not the correct/expected number of tasks are running at any given time. */
\r
213 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
215 /* Create the software timer that performs the 'check' functionality,
\r
216 as described at the top of this file. */
\r
217 xCheckTimer = xTimerCreate( "CheckTimer",/* A text name, purely to help debugging. */
\r
218 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 5000ms (5s). */
\r
219 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
220 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
221 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
224 configASSERT( xCheckTimer );
\r
226 /* Start the check timer. It will actually start when the scheduler is
\r
228 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
230 /* Start the tasks running. */
\r
231 vTaskStartScheduler();
\r
233 /* If all is well execution will never reach here as the scheduler will be
\r
234 running. If this null loop is reached then it is likely there was
\r
235 insufficient FreeRTOS heap available for the idle task and/or timer task to
\r
236 be created. See http://www.freertos.org/a00111.html. */
\r
239 /*-----------------------------------------------------------*/
\r
241 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
243 static long lChangedTimerPeriodAlready = pdFALSE, lErrorStatus = pdPASS;
\r
244 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;
\r
246 /* Remove compiler warnings about unused parameters. */
\r
249 /* Check the standard demo tasks are running without error. */
\r
250 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
252 lErrorStatus = pdFAIL;
\r
254 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
256 lErrorStatus = pdFAIL;
\r
258 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
260 lErrorStatus = pdFAIL;
\r
262 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
264 lErrorStatus = pdFAIL;
\r
267 /* Check the reg test tasks are still cycling. They will stop incrementing
\r
268 their loop counters if they encounter an error. */
\r
269 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )
\r
271 lErrorStatus = pdFAIL;
\r
274 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )
\r
276 lErrorStatus = pdFAIL;
\r
279 /* Remember the loop counter values this time around so they can be checked
\r
280 again the next time this callback function executes. */
\r
281 ulLastRegTest1CycleCount = ulRegTest1CycleCount;
\r
282 ulLastRegTest2CycleCount = ulRegTest2CycleCount;
\r
284 /* Toggle the check LED to give an indication of the system status. If
\r
285 the LED toggles every three seconds then everything is ok. A faster toggle
\r
286 indicates an error. */
\r
287 vParTestToggleLED( mainCHECK_LED );
\r
289 /* Was an error detected this time through the callback execution? */
\r
290 if( lErrorStatus != pdPASS )
\r
292 if( lChangedTimerPeriodAlready == pdFALSE )
\r
294 lChangedTimerPeriodAlready = pdTRUE;
\r
296 /* This call to xTimerChangePeriod() uses a zero block time.
\r
297 Functions called from inside of a timer callback function must
\r
298 *never* attempt to block. */
\r
299 xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
303 /*-----------------------------------------------------------*/
\r
305 /* This function is explained in the comments at the top of this file. */
\r
306 static void prvRegTest1Task( void *pvParameters )
\r
308 if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )
\r
310 /* The parameter did not contain the expected value. */
\r
313 /* Stop the tick interrupt so its obvious something has gone wrong. */
\r
314 taskDISABLE_INTERRUPTS();
\r
318 /* This is an inline asm function that never returns. */
\r
319 vRegTest1Implementation();
\r
321 /*-----------------------------------------------------------*/
\r
323 /* This function is explained in the comments at the top of this file. */
\r
324 static void prvRegTest2Task( void *pvParameters )
\r
326 if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )
\r
328 /* The parameter did not contain the expected value. */
\r
331 /* Stop the tick interrupt so its obvious something has gone wrong. */
\r
332 taskDISABLE_INTERRUPTS();
\r
336 /* This is an inline asm function that never returns. */
\r
337 vRegTest2Implementation();
\r
339 /*-----------------------------------------------------------*/
\r
341 #endif /* configCREATE_LOW_POWER_DEMO */
\r