2 FreeRTOS V7.5.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
4 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
6 ***************************************************************************
\r
8 * FreeRTOS provides completely free yet professionally developed, *
\r
9 * robust, strictly quality controlled, supported, and cross *
\r
10 * platform software that has become a de facto standard. *
\r
12 * Help yourself get started quickly and support the FreeRTOS *
\r
13 * project by purchasing a FreeRTOS tutorial book, reference *
\r
14 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
18 ***************************************************************************
\r
20 This file is part of the FreeRTOS distribution.
\r
22 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
23 the terms of the GNU General Public License (version 2) as published by the
\r
24 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
26 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
27 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
28 >>! the source code for proprietary components outside of the FreeRTOS
\r
31 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
32 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
33 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
34 link: http://www.freertos.org/a00114.html
\r
38 ***************************************************************************
\r
40 * Having a problem? Start by reading the FAQ "My application does *
\r
41 * not run, what could be wrong?" *
\r
43 * http://www.FreeRTOS.org/FAQHelp.html *
\r
45 ***************************************************************************
\r
47 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
48 license and Real Time Engineers Ltd. contact details.
\r
50 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
51 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
52 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
54 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
55 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
56 licenses offer ticketed support, indemnification and middleware.
\r
58 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
59 engineered and independently SIL3 certified version for use in safety and
\r
60 mission critical applications that require provable dependability.
\r
65 /* ****************************************************************************
\r
66 * main-blinky.c is included when the "Blinky" build configuration is used.
\r
67 * main-full.c is included when the "Full" build configuration is used.
\r
69 * main-full.c creates a lot of demo and test tasks and timers, and is
\r
70 * therefore very comprehensive but also complex. If you would prefer a much
\r
71 * simpler project to get started with, then select the 'Blinky' build
\r
72 * configuration within the SDK Eclipse IDE. See the documentation page for
\r
73 * this demo on the http://www.FreeRTOS.org web site for more information.
\r
74 * ****************************************************************************
\r
76 * main() creates all the demo application tasks and timers, then starts the
\r
77 * scheduler. The web documentation provides more details of the standard demo
\r
78 * application tasks, which provide no particular functionality, but do provide
\r
79 * a good example of how to use the FreeRTOS API.
\r
81 * In addition to the standard demo tasks, the following tasks and tests are
\r
82 * defined and/or created within this file:
\r
84 * TCP/IP ("lwIP") task - lwIP is used to create a basic web server. The web
\r
85 * server uses server side includes (SSI) to generate tables of task statistics,
\r
86 * and run time statistics (run time statistics show how much processing time
\r
87 * each task has consumed). See
\r
88 * http://www.FreeRTOS.org/Free-RTOS-for-Xilinx-MicroBlaze-on-Spartan-6-FPGA.html
\r
89 * for details on setting up and using the embedded web server.
\r
91 * "Reg test" tasks - These test the task context switch mechanism by first
\r
92 * filling the MicroBlaze registers with known values, before checking that each
\r
93 * register maintains the value that was written to it as the tasks are switched
\r
94 * in and out. The two register test tasks do not use the same values, and
\r
95 * execute at a very low priority, to ensure they are pre-empted regularly.
\r
97 * "Check" timer - The check timer period is initially set to five seconds.
\r
98 * The check timer callback function checks that all the standard demo tasks,
\r
99 * and the register check tasks, are not only still executing, but are executing
\r
100 * without reporting any errors. If the check timer discovers that a task has
\r
101 * either stalled, or reported an error, then it changes its own period from
\r
102 * the initial five seconds, to just 200ms. The check timer callback function
\r
103 * also toggles an LED each time it is called. This provides a visual
\r
104 * indication of the system status: If the LED toggles every five seconds then
\r
105 * no issues have been discovered. If the LED toggles every 200ms then an issue
\r
106 * has been discovered with at least one task. The last reported issue is
\r
107 * latched into the pcStatusMessage variable, and can also be viewed at the
\r
108 * bottom of the pages served by the embedded web server.
\r
110 * ***NOTE*** This demo uses the standard comtest tasks, which has special
\r
111 * hardware requirements. See
\r
112 * http://www.FreeRTOS.org/Free-RTOS-for-Xilinx-MicroBlaze-on-Spartan-6-FPGA.html
\r
113 * for more information.
\r
115 * This file also includes example implementations of the
\r
116 * vApplicationIdleHook(), vApplicationStackOverflowHook(),
\r
117 * vApplicationMallocFailedHook(), vApplicationClearTimerInterrupt(), and
\r
118 * vApplicationSetupTimerInterrupt() callback (hook) functions.
\r
121 /* Standard includes. */
\r
122 #include <string.h>
\r
125 /* BSP includes. */
\r
126 #include "xtmrctr.h"
\r
127 #include "microblaze_exceptions_g.h"
\r
129 /* Kernel includes. */
\r
130 #include "FreeRTOS.h"
\r
132 #include "timers.h"
\r
134 /* Standard demo includes. */
\r
135 #include "partest.h"
\r
137 #include "BlockQ.h"
\r
139 #include "blocktim.h"
\r
140 #include "semtest.h"
\r
142 #include "GenQTest.h"
\r
144 #include "recmutex.h"
\r
146 #include "dynamic.h"
\r
147 #include "comtest_strings.h"
\r
148 #include "TimerDemo.h"
\r
150 /* lwIP includes. */
\r
151 #include "lwip/tcpip.h"
\r
154 /* Priorities at which the various tasks are created. */
\r
155 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
156 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
157 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
158 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
159 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
160 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
161 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
162 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
163 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
165 /* The LED toggled by the check task. */
\r
166 #define mainCHECK_LED ( 3 )
\r
168 /* The rate at which mainCHECK_LED will toggle when all the tasks are running
\r
169 without error. See the description of the check timer in the comments at the
\r
170 top of this file. */
\r
171 #define mainNO_ERROR_CHECK_TIMER_PERIOD ( 5000 / portTICK_RATE_MS )
\r
173 /* The rate at which mainCHECK_LED will toggle when an error has been reported
\r
174 by at least one task. See the description of the check timer in the comments at
\r
175 the top of this file. */
\r
176 #define mainERROR_CHECK_TIMER_PERIOD ( 200 / portTICK_RATE_MS )
\r
178 /* A block time of zero simply means "don't block". */
\r
179 #define mainDONT_BLOCK ( ( portTickType ) 0 )
\r
181 /* The LED used by the comtest tasks. See the comtest_strings.c file for more
\r
182 information. In this case an invalid LED number is provided as all four
\r
183 available LEDs (LEDs 0 to 3) are already in use. */
\r
184 #define mainCOM_TEST_LED ( 4 )
\r
186 /* Baud rate used by the comtest tasks. The baud rate used is actually fixed in
\r
187 UARTLite IP when the hardware was built, but the standard serial init function
\r
188 required a baud rate parameter to be provided - in this case it is just
\r
190 #define mainCOM_TEST_BAUD_RATE ( XPAR_RS232_UART_1_BAUDRATE )
\r
192 /* The timer test task generates a lot of timers that all use a different
\r
193 period that is a multiple of the mainTIMER_TEST_PERIOD definition. */
\r
194 #define mainTIMER_TEST_PERIOD ( 20 )
\r
196 /*-----------------------------------------------------------*/
\r
199 * The register test tasks as described in the comments at the top of this file.
\r
200 * The nature of the register test tasks means they have to be implemented in
\r
203 extern void vRegisterTest1( void *pvParameters );
\r
204 extern void vRegisterTest2( void *pvParameters );
\r
207 * Defines the 'check' timer functionality as described at the top of this file.
\r
208 * This function is the callback function associated with the 'check' timer.
\r
210 static void vCheckTimerCallback( xTimerHandle xTimer );
\r
213 * Configure the interrupt controller, LED outputs and button inputs.
\r
215 static void prvSetupHardware( void );
\r
217 /* Defined in lwIPApps.c. */
\r
218 extern void lwIPAppsInit( void *pvArguments );
\r
220 /*-----------------------------------------------------------*/
\r
222 /* The check timer callback function sets pcStatusMessage to a string that
\r
223 indicates the last reported error that it discovered. */
\r
224 static const char *pcStatusMessage = NULL;
\r
226 /* Structures that hold the state of the various peripherals used by this demo.
\r
227 These are used by the Xilinx peripheral driver API functions. In this case,
\r
228 only the timer/counter is used directly within this file. */
\r
229 static XTmrCtr xTimer0Instance;
\r
231 /* The 'check' timer, as described at the top of this file. */
\r
232 static xTimerHandle xCheckTimer = NULL;
\r
234 /* Used in the run time stats calculations. */
\r
235 static unsigned long ulClocksPer10thOfAMilliSecond = 0UL;
\r
237 /* Constants used to set up the AXI timer to generate ticks. */
\r
238 static const unsigned char ucTimerCounterNumber = ( unsigned char ) 0U;
\r
239 static const unsigned long ulCounterReloadValue = ( ( XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );
\r
241 /*-----------------------------------------------------------*/
\r
245 /***************************************************************************
\r
246 This project includes a lot of demo and test tasks and timers, and is
\r
247 therefore comprehensive, but complex. If you would prefer a much simpler
\r
248 project to get started with, then select the 'Blinky' build configuration
\r
249 within the SDK Eclipse IDE.
\r
250 ***************************************************************************/
\r
252 /* Configure the interrupt controller, LED outputs and button inputs. */
\r
253 prvSetupHardware();
\r
255 /* This call creates the TCP/IP thread. */
\r
256 tcpip_init( lwIPAppsInit, NULL );
\r
258 /* Start the reg test tasks, as described in the comments at the top of this
\r
260 xTaskCreate( vRegisterTest1, ( const signed char * const ) "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );
\r
261 xTaskCreate( vRegisterTest2, ( const signed char * const ) "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );
\r
263 /* Create the standard demo tasks. */
\r
264 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
265 vCreateBlockTimeTasks();
\r
266 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
267 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
268 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
269 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
270 vStartQueuePeekTasks();
\r
271 vStartRecursiveMutexTasks();
\r
272 vStartComTestStringsTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
273 vStartDynamicPriorityTasks();
\r
274 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
276 /* Note - the set of standard demo tasks contains two versions of
\r
277 vStartMathTasks.c. One is defined in flop.c, and uses double precision
\r
278 floating point numbers and variables. The other is defined in sp_flop.c,
\r
279 and uses single precision floating point numbers and variables. The
\r
280 MicroBlaze floating point unit only handles single precision floating.
\r
281 Therefore, to test the floating point hardware, sp_flop.c should be included
\r
282 in this project. */
\r
283 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
285 /* The suicide tasks must be created last as they need to know how many
\r
286 tasks were running prior to their creation. This then allows them to
\r
287 ascertain whether or not the correct/expected number of tasks are running at
\r
289 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
291 /* Create the 'check' timer - the timer that periodically calls the
\r
292 check function as described in the comments at the top of this file. Note
\r
293 that, for reasons stated in the comments within vApplicationIdleHook()
\r
294 (defined in this file), the check timer is not actually started until after
\r
295 the scheduler has been started. */
\r
296 xCheckTimer = xTimerCreate( ( const signed char * ) "Check timer", mainNO_ERROR_CHECK_TIMER_PERIOD, pdTRUE, ( void * ) 0, vCheckTimerCallback );
\r
298 /* Start the scheduler running. From this point on, only tasks and
\r
299 interrupts will be executing. */
\r
300 vTaskStartScheduler();
\r
302 /* If all is well then the following line will never be reached. If
\r
303 execution does reach here, then it is highly probably that the heap size
\r
304 is too small for the idle and/or timer tasks to be created within
\r
305 vTaskStartScheduler(). */
\r
306 taskDISABLE_INTERRUPTS();
\r
309 /*-----------------------------------------------------------*/
\r
311 static void vCheckTimerCallback( xTimerHandle xTimer )
\r
313 extern unsigned long ulRegTest1CycleCount, ulRegTest2CycleCount;
\r
314 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;
\r
315 static long lErrorAlreadyLatched = pdFALSE;
\r
316 portTickType xExecutionRate = mainNO_ERROR_CHECK_TIMER_PERIOD;
\r
318 /* This is the callback function used by the 'check' timer, as described
\r
319 in the comments at the top of this file. */
\r
321 /* Don't overwrite any errors that have already been latched. */
\r
322 if( pcStatusMessage == NULL )
\r
324 /* Check the standard demo tasks are running without error. */
\r
325 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
327 pcStatusMessage = "Error: GenQueue";
\r
329 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
331 pcStatusMessage = "Error: QueuePeek\r\n";
\r
333 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
335 pcStatusMessage = "Error: BlockQueue\r\n";
\r
337 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
339 pcStatusMessage = "Error: BlockTime\r\n";
\r
341 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
343 pcStatusMessage = "Error: SemTest\r\n";
\r
345 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
347 pcStatusMessage = "Error: PollQueue\r\n";
\r
349 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
351 pcStatusMessage = "Error: Death\r\n";
\r
353 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
355 pcStatusMessage = "Error: RecMutex\r\n";
\r
357 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
359 pcStatusMessage = "Error: Flop\r\n";
\r
361 else if( xAreComTestTasksStillRunning() != pdPASS )
\r
363 pcStatusMessage = "Error: Comtest\r\n";
\r
365 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
367 pcStatusMessage = "Error: Dynamic\r\n";
\r
369 else if( xAreTimerDemoTasksStillRunning( xExecutionRate ) != pdTRUE )
\r
371 pcStatusMessage = "Error: TimerDemo";
\r
373 else if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )
\r
375 /* Check the reg test tasks are still cycling. They will stop
\r
376 incrementing their loop counters if they encounter an error. */
\r
377 pcStatusMessage = "Error: RegTest1\r\n";
\r
379 else if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )
\r
381 pcStatusMessage = "Error: RegTest2\r\n";
\r
385 /* Store a local copy of the current reg test loop counters. If these have
\r
386 not incremented the next time this callback function is executed then the
\r
387 reg test tasks have either stalled or discovered an error. */
\r
388 ulLastRegTest1CycleCount = ulRegTest1CycleCount;
\r
389 ulLastRegTest2CycleCount = ulRegTest2CycleCount;
\r
391 /* Toggle the check LED to give an indication of the system status. If
\r
392 the LED toggles every 5 seconds then everything is ok. A faster toggle
\r
393 indicates an error. */
\r
394 vParTestToggleLED( mainCHECK_LED );
\r
396 if( pcStatusMessage != NULL )
\r
398 if( lErrorAlreadyLatched == pdFALSE )
\r
400 /* An error has occurred, so change the period of the timer that
\r
401 calls this callback function. This results in the LED toggling at
\r
402 a faster rate - giving the user visual feedback that something is not
\r
403 as it should be. This function is called from the context of the
\r
404 timer service task so must ***not*** attempt to block while calling
\r
406 if( xTimerChangePeriod( xTimer, mainERROR_CHECK_TIMER_PERIOD, mainDONT_BLOCK ) == pdPASS )
\r
408 /* If the command to change the timer period was sent to the
\r
409 timer command queue successfully, then latch the fact that the
\r
410 timer period has already been changed. This is just done to
\r
411 prevent xTimerChangePeriod() being called on every execution of
\r
412 this function once an error has been discovered. */
\r
413 lErrorAlreadyLatched = pdTRUE;
\r
416 /* Update the xExecutionRate variable too as the rate at which this
\r
417 callback is executed has to be passed into the
\r
418 xAreTimerDemoTasksStillRunning() function. */
\r
419 xExecutionRate = mainERROR_CHECK_TIMER_PERIOD;
\r
423 /*-----------------------------------------------------------*/
\r
425 /* This is an application defined callback function used to install the tick
\r
426 interrupt handler. It is provided as an application callback because the kernel
\r
427 will run on lots of different MicroBlaze and FPGA configurations - not all of
\r
428 which will have the same timer peripherals defined or available. This example
\r
429 uses the AXI Timer 0. If that is available on your hardware platform then this
\r
430 example callback implementation should not require modification. The name of
\r
431 the interrupt handler that should be installed is vPortTickISR(), which the
\r
432 function below declares as an extern. */
\r
433 void vApplicationSetupTimerInterrupt( void )
\r
435 portBASE_TYPE xStatus;
\r
436 extern void vPortTickISR( void *pvUnused );
\r
438 /* Initialise the timer/counter. */
\r
439 xStatus = XTmrCtr_Initialize( &xTimer0Instance, XPAR_AXI_TIMER_0_DEVICE_ID );
\r
441 if( xStatus == XST_SUCCESS )
\r
443 /* Install the tick interrupt handler as the timer ISR.
\r
444 *NOTE* The xPortInstallInterruptHandler() API function must be used for
\r
446 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );
\r
449 if( xStatus == pdPASS )
\r
451 /* Enable the timer interrupt in the interrupt controller.
\r
452 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
454 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
\r
456 /* Configure the timer interrupt handler. */
\r
457 XTmrCtr_SetHandler( &xTimer0Instance, ( void * ) vPortTickISR, NULL );
\r
459 /* Set the correct period for the timer. */
\r
460 XTmrCtr_SetResetValue( &xTimer0Instance, ucTimerCounterNumber, ulCounterReloadValue );
\r
462 /* Enable the interrupts. Auto-reload mode is used to generate a
\r
463 periodic tick. Note that interrupts are disabled when this function is
\r
464 called, so interrupts will not start to be processed until the first
\r
465 task has started to run. */
\r
466 XTmrCtr_SetOptions( &xTimer0Instance, ucTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );
\r
468 /* Start the timer. */
\r
469 XTmrCtr_Start( &xTimer0Instance, ucTimerCounterNumber );
\r
472 /* Sanity check that the function executed as expected. */
\r
473 configASSERT( ( xStatus == pdPASS ) );
\r
475 /*-----------------------------------------------------------*/
\r
477 /* This is an application defined callback function used to clear whichever
\r
478 interrupt was installed by the the vApplicationSetupTimerInterrupt() callback
\r
479 function - in this case the interrupt generated by the AXI timer. It is
\r
480 provided as an application callback because the kernel will run on lots of
\r
481 different MicroBlaze and FPGA configurations - not all of which will have the
\r
482 same timer peripherals defined or available. This example uses the AXI Timer 0.
\r
483 If that is available on your hardware platform then this example callback
\r
484 implementation should not require modification provided the example definition
\r
485 of vApplicationSetupTimerInterrupt() is also not modified. */
\r
486 void vApplicationClearTimerInterrupt( void )
\r
488 unsigned long ulCSR;
\r
490 /* Clear the timer interrupt */
\r
491 ulCSR = XTmrCtr_GetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0 );
\r
492 XTmrCtr_SetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0, ulCSR );
\r
494 /*-----------------------------------------------------------*/
\r
496 void vApplicationMallocFailedHook( void )
\r
498 /* vApplicationMallocFailedHook() will only be called if
\r
499 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
500 function that will get called if a call to pvPortMalloc() fails.
\r
501 pvPortMalloc() is called internally by the kernel whenever a task, queue or
\r
502 semaphore is created. It is also called by various parts of the demo
\r
503 application. If heap_1.c or heap_2.c are used, then the size of the heap
\r
504 available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
505 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
506 to query the size of free heap space that remains (although it does not
\r
507 provide information on how the remaining heap might be fragmented). */
\r
508 taskDISABLE_INTERRUPTS();
\r
511 /*-----------------------------------------------------------*/
\r
513 void vApplicationStackOverflowHook( xTaskHandle pxTask, signed char *pcTaskName )
\r
515 ( void ) pcTaskName;
\r
518 /* vApplicationStackOverflowHook() will only be called if
\r
519 configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2. The handle and name
\r
520 of the offending task will be passed into the hook function via its
\r
521 parameters. However, when a stack has overflowed, it is possible that the
\r
522 parameters will have been corrupted, in which case the pxCurrentTCB variable
\r
523 can be inspected directly. */
\r
524 taskDISABLE_INTERRUPTS();
\r
527 /*-----------------------------------------------------------*/
\r
529 void vApplicationIdleHook( void )
\r
531 static long lCheckTimerStarted = pdFALSE;
\r
533 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
534 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
535 task. It is essential that code added to this hook function never attempts
\r
536 to block in any way (for example, call xQueueReceive() with a block time
\r
537 specified, or call vTaskDelay()). If the application makes use of the
\r
538 vTaskDelete() API function (as this demo application does) then it is also
\r
539 important that vApplicationIdleHook() is permitted to return to its calling
\r
540 function, because it is the responsibility of the idle task to clean up
\r
541 memory allocated by the kernel to any task that has since been deleted. */
\r
543 /* If the check timer has not already been started, then start it now.
\r
544 Normally, the xTimerStart() API function can be called immediately after the
\r
545 timer is created - how this demo application includes the timer demo tasks.
\r
546 The timer demo tasks, as part of their test function, deliberately fill up
\r
547 the timer command queue - meaning the check timer cannot be started until
\r
548 after the scheduler has been started - at which point the timer command
\r
549 queue will have been drained. */
\r
550 if( lCheckTimerStarted == pdFALSE )
\r
552 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
553 lCheckTimerStarted = pdTRUE;
\r
556 /*-----------------------------------------------------------*/
\r
558 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump )
\r
560 ( void ) xRegisterDump;
\r
562 /* If configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h, then
\r
563 the kernel will automatically install its own exception handlers before the
\r
564 kernel is started, if the application writer has not already caused them to
\r
565 be installed by calling either of the vPortExceptionsInstallHandlers()
\r
566 or xPortInstallInterruptHandler() API functions before that time. The
\r
567 kernels exception handler populates an xPortRegisterDump structure with
\r
568 the processor state at the point that the exception was triggered - and also
\r
569 includes a strings that say what the exception cause was and which task was
\r
570 running at the time. The exception handler then passes the populated
\r
571 xPortRegisterDump structure into vApplicationExceptionRegisterDump() to
\r
572 allow the application writer to perform any debugging that may be necessary.
\r
573 However, defining vApplicationExceptionRegisterDump() within the application
\r
574 itself is optional. The kernel will use a default implementation if the
\r
575 application writer chooses not to provide their own. */
\r
581 /*-----------------------------------------------------------*/
\r
583 static void prvSetupHardware( void )
\r
585 taskDISABLE_INTERRUPTS();
\r
587 /* Configure the LED outputs. */
\r
588 vParTestInitialise();
\r
590 /* Tasks inherit the exception and cache configuration of the MicroBlaze
\r
591 at the point that they are created. */
\r
592 #if MICROBLAZE_EXCEPTIONS_ENABLED == 1
\r
593 microblaze_enable_exceptions();
\r
596 #if XPAR_MICROBLAZE_USE_ICACHE == 1
\r
597 microblaze_invalidate_icache();
\r
598 microblaze_enable_icache();
\r
601 #if XPAR_MICROBLAZE_USE_DCACHE == 1
\r
602 microblaze_invalidate_dcache();
\r
603 microblaze_enable_dcache();
\r
607 /*-----------------------------------------------------------*/
\r
609 void vMainConfigureTimerForRunTimeStats( void )
\r
611 /* How many times does the counter counter increment in 10ms? */
\r
612 ulClocksPer10thOfAMilliSecond = XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ / 10000UL;
\r
614 /*-----------------------------------------------------------*/
\r
616 unsigned long ulMainGetRunTimeCounterValue( void )
\r
618 unsigned long ulTimerCounts1, ulTimerCounts2, ulTickCount, ulReturn;
\r
620 /* NOTE: This can get called from a yield, in which case interrupts are
\r
621 disabled, or from a tick ISR, in which case the effect is the same as if
\r
622 interrupts were disabled. In either case, it is going to run atomically. */
\r
624 /* The timer is in down count mode. How many clocks have passed since it
\r
625 was last reloaded? */
\r
626 ulTimerCounts1 = ulCounterReloadValue - XTmrCtr_GetValue( &xTimer0Instance, ucTimerCounterNumber );
\r
628 /* How many times has it overflowed? */
\r
629 ulTickCount = xTaskGetTickCountFromISR();
\r
631 /* If this is being called from a yield, has the counter overflowed since
\r
632 it was read? If that is the case then ulTickCounts will need incrementing
\r
633 again as it will not yet have been incremented from the tick interrupt. */
\r
634 ulTimerCounts2 = ulCounterReloadValue - XTmrCtr_GetValue( &xTimer0Instance, ucTimerCounterNumber );
\r
635 if( ulTimerCounts2 < ulTimerCounts1 )
\r
637 /* There is a tick interrupt pending but the tick count not yet
\r
641 /* Use the second timer reading. */
\r
642 ulTimerCounts1 = ulTimerCounts2;
\r
645 /* Convert the tick count into tenths of a millisecond. THIS ASSUMES
\r
646 configTICK_RATE_HZ is 1000! */
\r
647 ulReturn = ( ulTickCount * 10UL );
\r
649 /* Add on the number of tenths of a millisecond that have passed since the
\r
650 tick count last got updated. */
\r
651 ulReturn += ( ulTimerCounts1 / ulClocksPer10thOfAMilliSecond );
\r
653 /* Some crude rounding. */
\r
654 if( ( ulTimerCounts1 % ulClocksPer10thOfAMilliSecond ) > ( ulClocksPer10thOfAMilliSecond >> 1UL ) )
\r
661 /*-----------------------------------------------------------*/
\r
663 char *pcMainGetTaskStatusMessage( void )
\r
667 if( pcStatusMessage == NULL )
\r
669 pcReturn = ( char * ) "OK";
\r
673 pcReturn = ( char * ) pcStatusMessage;
\r