2 FreeRTOS V8.2.0rc1 - Copyright (C) 2014 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 >>! NOTE: The modification to the GPL is included to allow you to !<<
\r
14 >>! distribute a combined work that includes FreeRTOS without being !<<
\r
15 >>! obliged to provide the source code for proprietary components !<<
\r
16 >>! outside of the FreeRTOS kernel. !<<
\r
18 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
19 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
20 FOR A PARTICULAR PURPOSE. Full license text is available on the following
\r
21 link: http://www.freertos.org/a00114.html
\r
25 ***************************************************************************
\r
27 * Having a problem? Start by reading the FAQ "My application does *
\r
28 * not run, what could be wrong?". Have you defined configASSERT()? *
\r
30 * http://www.FreeRTOS.org/FAQHelp.html *
\r
32 ***************************************************************************
\r
34 ***************************************************************************
\r
36 * FreeRTOS provides completely free yet professionally developed, *
\r
37 * robust, strictly quality controlled, supported, and cross *
\r
38 * platform software that is more than just the market leader, it *
\r
39 * is the industry's de facto standard. *
\r
41 * Help yourself get started quickly while simultaneously helping *
\r
42 * to support the FreeRTOS project by purchasing a FreeRTOS *
\r
43 * tutorial book, reference manual, or both: *
\r
44 * http://www.FreeRTOS.org/Documentation *
\r
46 ***************************************************************************
\r
48 ***************************************************************************
\r
50 * Investing in training allows your team to be as productive as *
\r
51 * possible as early as possible, lowering your overall development *
\r
52 * cost, and enabling you to bring a more robust product to market *
\r
53 * earlier than would otherwise be possible. Richard Barry is both *
\r
54 * the architect and key author of FreeRTOS, and so also the world's *
\r
55 * leading authority on what is the world's most popular real time *
\r
56 * kernel for deeply embedded MCU designs. Obtaining your training *
\r
57 * from Richard ensures your team will gain directly from his in-depth *
\r
58 * product knowledge and years of usage experience. Contact Real Time *
\r
59 * Engineers Ltd to enquire about the FreeRTOS Masterclass, presented *
\r
60 * by Richard Barry: http://www.FreeRTOS.org/contact
\r
62 ***************************************************************************
\r
64 ***************************************************************************
\r
66 * You are receiving this top quality software for free. Please play *
\r
67 * fair and reciprocate by reporting any suspected issues and *
\r
68 * participating in the community forum: *
\r
69 * http://www.FreeRTOS.org/support *
\r
73 ***************************************************************************
\r
75 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
76 license and Real Time Engineers Ltd. contact details.
\r
78 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
79 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
80 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
82 http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
\r
83 Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.
\r
85 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
86 Integrity Systems ltd. to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
87 licenses offer ticketed support, indemnification and commercial middleware.
\r
89 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
90 engineered and independently SIL3 certified version for use in safety and
\r
91 mission critical applications that require provable dependability.
\r
96 /* ****************************************************************************
\r
97 * This project includes a lot of tasks and tests and is therefore complex.
\r
98 * If you would prefer a much simpler project to get started with then select
\r
99 * the 'low power' demo by setting configCREATE_LOW_POWER_DEMO to 1 in
\r
100 * FreeRTOSConfig.h. When configCREATE_LOW_POWER_DEMO is set to 1 main() will
\r
101 * call main_low_power() instead of main_full().
\r
102 * ****************************************************************************
\r
104 * Creates all the demo application tasks, then starts the scheduler. The web
\r
105 * documentation provides more details of the standard demo application tasks,
\r
106 * which provide no particular functionality but do provide a good example of
\r
107 * how to use the FreeRTOS API.
\r
109 * In addition to the standard demo tasks, the following tasks and tests are
\r
110 * defined and/or created within this file:
\r
112 * "Reg test" tasks - These fill the registers with known values, then
\r
113 * repeatedly check that each register still contains its expected value for
\r
114 * the lifetime of the tasks. Each task uses different values. The tasks run
\r
115 * with very low priority so get preempted very frequently. A check variable
\r
116 * is incremented on each iteration of the test loop. A register containing an
\r
117 * unexpected value is indicative of an error in the context switching
\r
118 * mechanism and will result in a branch to a null loop - which in turn will
\r
119 * prevent the check variable from incrementing any further and allow the check
\r
120 * timer (described below) to determine that an error has occurred. The nature
\r
121 * of the reg test tasks necessitates that they are written in assembly code.
\r
123 * "Check Timer" and Callback Function - The check timer period is initially
\r
124 * set to three seconds. The check timer callback function checks that all the
\r
125 * standard demo tasks are not only still executing, but are executing without
\r
126 * reporting any errors. If the check timer discovers that a task has either
\r
127 * stalled, or reported an error, then it changes its own period from the
\r
128 * initial three seconds, to just 200ms. The check timer callback function
\r
129 * also toggles LED 0 each time it is called. This provides a visual
\r
130 * indication of the system status: If the LED toggles every three seconds,
\r
131 * then no issues have been discovered. If the LED toggles every 200ms, then
\r
132 * an issue has been discovered with at least one task.
\r
134 * *NOTE 1* The CPU must be in Supervisor mode when the scheduler is started.
\r
135 * The PowerON_Reset_PC() supplied in resetprg.c with this demo has
\r
136 * Change_PSW_PM_to_UserMode() commented out to ensure this is the case.
\r
139 /* Standard includes. */
\r
140 #include <string.h>
\r
142 /* Hardware specific includes. */
\r
143 #include "iorx111.h"
\r
145 /* Kernel includes. */
\r
146 #include "FreeRTOS.h"
\r
148 #include "timers.h"
\r
149 #include "semphr.h"
\r
151 /* Standard demo includes. */
\r
152 #include "partest.h"
\r
154 #include "blocktim.h"
\r
155 #include "GenQTest.h"
\r
156 #include "recmutex.h"
\r
159 /* Variables that are incremented on each iteration of the reg test tasks are
\r
160 declared outside of the #if configCREATE_LOW_POWER_DEMO conditional compilation
\r
161 to prevent linker issues when configCREATE_LOW_POWER_DEMO is set to 1. The
\r
162 check timer inspects these variables to ensure they are still incrementing as
\r
163 expected. If a variable stops incrementing then it is likely that its associate
\r
164 task has stalled. */
\r
165 unsigned long volatile ulRegTest1CycleCount = 0UL, ulRegTest2CycleCount = 0UL;
\r
168 /* The code in this file is only built when configCREATE_LOW_POWER_DEMO is set
\r
169 to 0, otherwise the code in main_low_power.c is used. */
\r
170 #if configCREATE_LOW_POWER_DEMO == 0
\r
173 /* Values that are passed into the reg test tasks using the task parameter.
\r
174 The tasks check that the values are passed in correctly. */
\r
175 #define mainREG_TEST_1_PARAMETER ( 0x12121212UL )
\r
176 #define mainREG_TEST_2_PARAMETER ( 0x12345678UL )
\r
178 /* Priorities at which the standard demo tasks are created. */
\r
179 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
180 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
182 /* The LED toggled by the check timer. */
\r
183 #define mainCHECK_LED ( 0 )
\r
185 /* The period at which the check timer will expire, in ms, provided no errors
\r
186 have been reported by any of the standard demo tasks. ms are converted to the
\r
187 equivalent in ticks using the portTICK_PERIOD_MS constant. */
\r
188 #define mainCHECK_TIMER_PERIOD_MS ( 3000UL / portTICK_PERIOD_MS )
\r
190 /* The period at which the check timer will expire, in ms, if an error has been
\r
191 reported in one of the standard demo tasks. ms are converted to the equivalent
\r
192 in ticks using the portTICK_PERIOD_MS constant. */
\r
193 #define mainERROR_CHECK_TIMER_PERIOD_MS ( 200UL / portTICK_PERIOD_MS )
\r
195 /* A block time of zero simple means "Don't Block". */
\r
196 #define mainDONT_BLOCK ( 0UL )
\r
199 * The reg test tasks as described at the top of this file.
\r
201 static void prvRegTest1Task( void *pvParameters );
\r
202 static void prvRegTest2Task( void *pvParameters );
\r
205 * The actual implementation of the reg test functionality, which, because of
\r
206 * the direct register access, have to be in assembly.
\r
208 void vRegTest1Implementation( void );
\r
209 void vRegTest2Implementation( void );
\r
212 * The check timer callback function, as described at the top of this file.
\r
214 static void prvCheckTimerCallback( TimerHandle_t xTimer );
\r
217 /*-----------------------------------------------------------*/
\r
219 /* The check timer. This uses prvCheckTimerCallback() as its callback
\r
221 static TimerHandle_t xCheckTimer = NULL;
\r
223 /*-----------------------------------------------------------*/
\r
225 void main_full( void )
\r
227 /* Start the reg test tasks which test the context switching mechanism. */
\r
228 xTaskCreate( prvRegTest1Task, "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_1_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
229 xTaskCreate( prvRegTest2Task, "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) mainREG_TEST_2_PARAMETER, tskIDLE_PRIORITY, NULL );
\r
231 /* Create the standard demo tasks. */
\r
232 vCreateBlockTimeTasks();
\r
233 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
234 vStartRecursiveMutexTasks();
\r
236 /* The suicide tasks must be created last as they need to know how many
\r
237 tasks were running prior to their creation in order to ascertain whether
\r
238 or not the correct/expected number of tasks are running at any given time. */
\r
239 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
241 /* Create the software timer that performs the 'check' functionality,
\r
242 as described at the top of this file. */
\r
243 xCheckTimer = xTimerCreate( "CheckTimer",/* A text name, purely to help debugging. */
\r
244 ( mainCHECK_TIMER_PERIOD_MS ), /* The timer period, in this case 5000ms (5s). */
\r
245 pdTRUE, /* This is an auto-reload timer, so xAutoReload is set to pdTRUE. */
\r
246 ( void * ) 0, /* The ID is not used, so can be set to anything. */
\r
247 prvCheckTimerCallback /* The callback function that inspects the status of all the other tasks. */
\r
250 configASSERT( xCheckTimer );
\r
252 /* Start the check timer. It will actually start when the scheduler is
\r
254 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
256 /* Start the tasks running. */
\r
257 vTaskStartScheduler();
\r
259 /* If all is well execution will never reach here as the scheduler will be
\r
260 running. If this null loop is reached then it is likely there was
\r
261 insufficient FreeRTOS heap available for the idle task and/or timer task to
\r
262 be created. See http://www.freertos.org/a00111.html. */
\r
265 /*-----------------------------------------------------------*/
\r
267 static void prvCheckTimerCallback( TimerHandle_t xTimer )
\r
269 static long lChangedTimerPeriodAlready = pdFALSE, lErrorStatus = pdPASS;
\r
270 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;
\r
272 /* Remove compiler warnings about unused parameters. */
\r
275 /* Check the standard demo tasks are running without error. */
\r
276 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
278 lErrorStatus = pdFAIL;
\r
280 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
282 lErrorStatus = pdFAIL;
\r
284 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
286 lErrorStatus = pdFAIL;
\r
288 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
290 lErrorStatus = pdFAIL;
\r
293 /* Check the reg test tasks are still cycling. They will stop incrementing
\r
294 their loop counters if they encounter an error. */
\r
295 if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )
\r
297 lErrorStatus = pdFAIL;
\r
300 if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )
\r
302 lErrorStatus = pdFAIL;
\r
305 /* Remember the loop counter values this time around so they can be checked
\r
306 again the next time this callback function executes. */
\r
307 ulLastRegTest1CycleCount = ulRegTest1CycleCount;
\r
308 ulLastRegTest2CycleCount = ulRegTest2CycleCount;
\r
310 /* Toggle the check LED to give an indication of the system status. If
\r
311 the LED toggles every three seconds then everything is ok. A faster toggle
\r
312 indicates an error. */
\r
313 vParTestToggleLED( mainCHECK_LED );
\r
315 /* Was an error detected this time through the callback execution? */
\r
316 if( lErrorStatus != pdPASS )
\r
318 if( lChangedTimerPeriodAlready == pdFALSE )
\r
320 lChangedTimerPeriodAlready = pdTRUE;
\r
322 /* This call to xTimerChangePeriod() uses a zero block time.
\r
323 Functions called from inside of a timer callback function must
\r
324 *never* attempt to block. */
\r
325 xTimerChangePeriod( xCheckTimer, ( mainERROR_CHECK_TIMER_PERIOD_MS ), mainDONT_BLOCK );
\r
329 /*-----------------------------------------------------------*/
\r
331 /* This function is explained in the comments at the top of this file. */
\r
332 static void prvRegTest1Task( void *pvParameters )
\r
334 if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_1_PARAMETER )
\r
336 /* The parameter did not contain the expected value. */
\r
339 /* Stop the tick interrupt so its obvious something has gone wrong. */
\r
340 taskDISABLE_INTERRUPTS();
\r
344 /* This is an inline asm function that never returns. */
\r
345 vRegTest1Implementation();
\r
347 /*-----------------------------------------------------------*/
\r
349 /* This function is explained in the comments at the top of this file. */
\r
350 static void prvRegTest2Task( void *pvParameters )
\r
352 if( ( ( unsigned long ) pvParameters ) != mainREG_TEST_2_PARAMETER )
\r
354 /* The parameter did not contain the expected value. */
\r
357 /* Stop the tick interrupt so its obvious something has gone wrong. */
\r
358 taskDISABLE_INTERRUPTS();
\r
362 /* This is an inline asm function that never returns. */
\r
363 vRegTest2Implementation();
\r
365 /*-----------------------------------------------------------*/
\r
367 #endif /* configCREATE_LOW_POWER_DEMO */
\r