2 FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /* ****************************************************************************
\r
55 * main-blinky.c is included when the "Blinky" build configuration is used.
\r
56 * main-full.c is included when the "Full" build configuration is used.
\r
58 * main-full.c creates a lot of demo and test tasks and timers, and is
\r
59 * therefore very comprehensive but also complex. If you would prefer a much
\r
60 * simpler project to get started with, then select the 'Blinky' build
\r
61 * configuration within the SDK Eclipse IDE. See the documentation page for
\r
62 * this demo on the http://www.FreeRTOS.org web site for more information.
\r
63 * ****************************************************************************
\r
65 * main() creates all the demo application tasks and timers, then starts the
\r
66 * scheduler. The web documentation provides more details of the standard demo
\r
67 * application tasks, which provide no particular functionality, but do provide
\r
68 * a good example of how to use the FreeRTOS API.
\r
70 * In addition to the standard demo tasks, the following tasks and tests are
\r
71 * defined and/or created within this file:
\r
73 * TCP/IP ("lwIP") task - lwIP is used to create a basic web server. The web
\r
74 * server uses server side includes (SSI) to generate tables of task statistics,
\r
75 * and run time statistics (run time statistics show how much processing time
\r
76 * each task has consumed). See
\r
77 * http://www.FreeRTOS.org/Free-RTOS-for-Xilinx-MicroBlaze-on-Spartan-6-FPGA.html
\r
78 * for details on setting up and using the embedded web server.
\r
80 * "Reg test" tasks - These test the task context switch mechanism by first
\r
81 * filling the MicroBlaze registers with known values, before checking that each
\r
82 * register maintains the value that was written to it as the tasks are switched
\r
83 * in and out. The two register test tasks do not use the same values, and
\r
84 * execute at a very low priority, to ensure they are pre-empted regularly.
\r
86 * "Check" timer - The check timer period is initially set to five seconds.
\r
87 * The check timer callback function checks that all the standard demo tasks,
\r
88 * and the register check tasks, are not only still executing, but are executing
\r
89 * without reporting any errors. If the check timer discovers that a task has
\r
90 * either stalled, or reported an error, then it changes its own period from
\r
91 * the initial five seconds, to just 200ms. The check timer callback function
\r
92 * also toggles an LED each time it is called. This provides a visual
\r
93 * indication of the system status: If the LED toggles every five seconds then
\r
94 * no issues have been discovered. If the LED toggles every 200ms then an issue
\r
95 * has been discovered with at least one task. The last reported issue is
\r
96 * latched into the pcStatusMessage variable, and can also be viewed at the
\r
97 * bottom of the pages served by the embedded web server.
\r
99 * ***NOTE*** This demo uses the standard comtest tasks, which has special
\r
100 * hardware requirements. See
\r
101 * http://www.FreeRTOS.org/Free-RTOS-for-Xilinx-MicroBlaze-on-Spartan-6-FPGA.html
\r
102 * for more information.
\r
104 * This file also includes example implementations of the
\r
105 * vApplicationIdleHook(), vApplicationStackOverflowHook(),
\r
106 * vApplicationMallocFailedHook(), vApplicationClearTimerInterrupt(), and
\r
107 * vApplicationSetupTimerInterrupt() callback (hook) functions.
\r
110 /* Standard includes. */
\r
111 #include <string.h>
\r
114 /* BSP includes. */
\r
115 #include "xtmrctr.h"
\r
116 #include "microblaze_exceptions_g.h"
\r
118 /* Kernel includes. */
\r
119 #include "FreeRTOS.h"
\r
121 #include "timers.h"
\r
123 /* Standard demo includes. */
\r
124 #include "partest.h"
\r
126 #include "BlockQ.h"
\r
128 #include "blocktim.h"
\r
129 #include "semtest.h"
\r
131 #include "GenQTest.h"
\r
133 #include "recmutex.h"
\r
135 #include "dynamic.h"
\r
136 #include "comtest_strings.h"
\r
137 #include "TimerDemo.h"
\r
139 /* lwIP includes. */
\r
140 #include "lwip/tcpip.h"
\r
143 /* Priorities at which the various tasks are created. */
\r
144 #define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
145 #define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
146 #define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
147 #define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )
\r
148 #define mainFLASH_TASK_PRIORITY ( tskIDLE_PRIORITY + 1 )
\r
149 #define mainCOM_TEST_PRIORITY ( tskIDLE_PRIORITY + 2 )
\r
150 #define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
151 #define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
152 #define mainFLOP_TASK_PRIORITY ( tskIDLE_PRIORITY )
\r
154 /* The LED toggled by the check task. */
\r
155 #define mainCHECK_LED ( 3 )
\r
157 /* The rate at which mainCHECK_LED will toggle when all the tasks are running
\r
158 without error. See the description of the check timer in the comments at the
\r
159 top of this file. */
\r
160 #define mainNO_ERROR_CHECK_TIMER_PERIOD ( 5000 / portTICK_RATE_MS )
\r
162 /* The rate at which mainCHECK_LED will toggle when an error has been reported
\r
163 by at least one task. See the description of the check timer in the comments at
\r
164 the top of this file. */
\r
165 #define mainERROR_CHECK_TIMER_PERIOD ( 200 / portTICK_RATE_MS )
\r
167 /* A block time of zero simply means "don't block". */
168 #define mainDONT_BLOCK ( ( portTickType ) 0 )
\r
170 /* The LED used by the comtest tasks. See the comtest_strings.c file for more
\r
171 information. In this case an invalid LED number is provided as all four
\r
172 available LEDs (LEDs 0 to 3) are already in use. */
\r
173 #define mainCOM_TEST_LED ( 4 )
\r
175 /* Baud rate used by the comtest tasks. The baud rate used is actually fixed in
\r
176 UARTLite IP when the hardware was built, but the standard serial init function
\r
177 required a baud rate parameter to be provided - in this case it is just
\r
179 #define mainCOM_TEST_BAUD_RATE ( XPAR_RS232_UART_1_BAUDRATE )
\r
181 /* The timer test task generates a lot of timers that all use a different
\r
182 period that is a multiple of the mainTIMER_TEST_PERIOD definition. */
\r
183 #define mainTIMER_TEST_PERIOD ( 20 )
\r
185 /*-----------------------------------------------------------*/
\r
188 * The register test tasks as described in the comments at the top of this file.
\r
189 * The nature of the register test tasks means they have to be implemented in
\r
192 extern void vRegisterTest1( void *pvParameters );
\r
193 extern void vRegisterTest2( void *pvParameters );
\r
196 * Defines the 'check' timer functionality as described at the top of this file.
\r
197 * This function is the callback function associated with the 'check' timer.
\r
199 static void vCheckTimerCallback( xTimerHandle xTimer );
\r
202 * Configure the interrupt controller, LED outputs and button inputs.
\r
204 static void prvSetupHardware( void );
\r
206 /* Defined in lwIPApps.c. */
\r
207 extern void lwIPAppsInit( void *pvArguments );
\r
209 /*-----------------------------------------------------------*/
\r
211 /* The check timer callback function sets pcStatusMessage to a string that
\r
212 indicates the last reported error that it discovered. */
\r
213 static const char *pcStatusMessage = NULL;
\r
215 /* Structures that hold the state of the various peripherals used by this demo.
\r
216 These are used by the Xilinx peripheral driver API functions. In this case,
\r
217 only the timer/counter is used directly within this file. */
\r
218 static XTmrCtr xTimer0Instance;
\r
220 /* The 'check' timer, as described at the top of this file. */
\r
221 static xTimerHandle xCheckTimer = NULL;
\r
223 /* Used in the run time stats calculations. */
\r
224 static unsigned long ulClocksPer10thOfAMilliSecond = 0UL;
\r
226 /* Constants used to set up the AXI timer to generate ticks. */
\r
227 static const unsigned char ucTimerCounterNumber = ( unsigned char ) 0U;
\r
228 static const unsigned long ulCounterReloadValue = ( ( XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );
\r
230 /*-----------------------------------------------------------*/
\r
234 /***************************************************************************
\r
235 This project includes a lot of demo and test tasks and timers, and is
\r
236 therefore comprehensive, but complex. If you would prefer a much simpler
\r
237 project to get started with, then select the 'Blinky' build configuration
\r
238 within the SDK Eclipse IDE.
\r
239 ***************************************************************************/
\r
241 /* Configure the interrupt controller, LED outputs and button inputs. */
\r
242 prvSetupHardware();
\r
244 /* This call creates the TCP/IP thread. */
\r
245 tcpip_init( lwIPAppsInit, NULL );
\r
247 /* Start the reg test tasks, as described in the comments at the top of this
\r
249 xTaskCreate( vRegisterTest1, ( const signed char * const ) "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );
\r
250 xTaskCreate( vRegisterTest2, ( const signed char * const ) "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );
\r
252 /* Create the standard demo tasks. */
\r
253 vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );
\r
254 vCreateBlockTimeTasks();
\r
255 vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );
\r
256 vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );
\r
257 vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );
\r
258 vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );
\r
259 vStartQueuePeekTasks();
\r
260 vStartRecursiveMutexTasks();
\r
261 vStartComTestStringsTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );
\r
262 vStartDynamicPriorityTasks();
\r
263 vStartTimerDemoTask( mainTIMER_TEST_PERIOD );
\r
265 /* Note - the set of standard demo tasks contains two versions of
\r
266 vStartMathTasks.c. One is defined in flop.c, and uses double precision
\r
267 floating point numbers and variables. The other is defined in sp_flop.c,
\r
268 and uses single precision floating point numbers and variables. The
\r
269 MicroBlaze floating point unit only handles single precision floating.
\r
270 Therefore, to test the floating point hardware, sp_flop.c should be included
\r
271 in this project. */
\r
272 vStartMathTasks( mainFLOP_TASK_PRIORITY );
\r
274 /* The suicide tasks must be created last as they need to know how many
\r
275 tasks were running prior to their creation. This then allows them to
\r
276 ascertain whether or not the correct/expected number of tasks are running at
\r
278 vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );
\r
280 /* Create the 'check' timer - the timer that periodically calls the
\r
281 check function as described in the comments at the top of this file. Note
\r
282 that, for reasons stated in the comments within vApplicationIdleHook()
\r
283 (defined in this file), the check timer is not actually started until after
\r
284 the scheduler has been started. */
\r
285 xCheckTimer = xTimerCreate( ( const signed char * ) "Check timer", mainNO_ERROR_CHECK_TIMER_PERIOD, pdTRUE, ( void * ) 0, vCheckTimerCallback );
\r
287 /* Start the scheduler running. From this point on, only tasks and
\r
288 interrupts will be executing. */
\r
289 vTaskStartScheduler();
\r
291 /* If all is well then the following line will never be reached. If
\r
292 execution does reach here, then it is highly probably that the heap size
\r
293 is too small for the idle and/or timer tasks to be created within
\r
294 vTaskStartScheduler(). */
\r
295 taskDISABLE_INTERRUPTS();
\r
298 /*-----------------------------------------------------------*/
\r
300 static void vCheckTimerCallback( xTimerHandle xTimer )
\r
302 extern unsigned long ulRegTest1CycleCount, ulRegTest2CycleCount;
\r
303 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;
\r
304 static long lErrorAlreadyLatched = pdFALSE;
\r
305 portTickType xExecutionRate = mainNO_ERROR_CHECK_TIMER_PERIOD;
\r
307 /* This is the callback function used by the 'check' timer, as described
\r
308 in the comments at the top of this file. */
\r
310 /* Don't overwrite any errors that have already been latched. */
\r
311 if( pcStatusMessage == NULL )
\r
313 /* Check the standard demo tasks are running without error. */
\r
314 if( xAreGenericQueueTasksStillRunning() != pdTRUE )
\r
316 pcStatusMessage = "Error: GenQueue";
\r
318 else if( xAreQueuePeekTasksStillRunning() != pdTRUE )
\r
320 pcStatusMessage = "Error: QueuePeek\r\n";
\r
322 else if( xAreBlockingQueuesStillRunning() != pdTRUE )
\r
324 pcStatusMessage = "Error: BlockQueue\r\n";
\r
326 else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )
\r
328 pcStatusMessage = "Error: BlockTime\r\n";
\r
330 else if( xAreSemaphoreTasksStillRunning() != pdTRUE )
\r
332 pcStatusMessage = "Error: SemTest\r\n";
\r
334 else if( xArePollingQueuesStillRunning() != pdTRUE )
\r
336 pcStatusMessage = "Error: PollQueue\r\n";
\r
338 else if( xIsCreateTaskStillRunning() != pdTRUE )
\r
340 pcStatusMessage = "Error: Death\r\n";
\r
342 else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )
\r
344 pcStatusMessage = "Error: RecMutex\r\n";
\r
346 else if( xAreMathsTaskStillRunning() != pdPASS )
\r
348 pcStatusMessage = "Error: Flop\r\n";
\r
350 else if( xAreComTestTasksStillRunning() != pdPASS )
\r
352 pcStatusMessage = "Error: Comtest\r\n";
\r
354 else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )
\r
356 pcStatusMessage = "Error: Dynamic\r\n";
\r
358 else if( xAreTimerDemoTasksStillRunning( xExecutionRate ) != pdTRUE )
\r
360 pcStatusMessage = "Error: TimerDemo";
\r
362 else if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )
\r
364 /* Check the reg test tasks are still cycling. They will stop
\r
365 incrementing their loop counters if they encounter an error. */
\r
366 pcStatusMessage = "Error: RegTest1\r\n";
\r
368 else if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )
\r
370 pcStatusMessage = "Error: RegTest2\r\n";
\r
374 /* Store a local copy of the current reg test loop counters. If these have
\r
375 not incremented the next time this callback function is executed then the
\r
376 reg test tasks have either stalled or discovered an error. */
\r
377 ulLastRegTest1CycleCount = ulRegTest1CycleCount;
\r
378 ulLastRegTest2CycleCount = ulRegTest2CycleCount;
\r
380 /* Toggle the check LED to give an indication of the system status. If
\r
381 the LED toggles every 5 seconds then everything is ok. A faster toggle
\r
382 indicates an error. */
\r
383 vParTestToggleLED( mainCHECK_LED );
\r
385 if( pcStatusMessage != NULL )
\r
387 if( lErrorAlreadyLatched == pdFALSE )
\r
389 /* An error has occurred, so change the period of the timer that
\r
390 calls this callback function. This results in the LED toggling at
\r
391 a faster rate - giving the user visual feedback that something is not
\r
392 as it should be. This function is called from the context of the
\r
393 timer service task so must ***not*** attempt to block while calling
\r
395 if( xTimerChangePeriod( xTimer, mainERROR_CHECK_TIMER_PERIOD, mainDONT_BLOCK ) == pdPASS )
\r
397 /* If the command to change the timer period was sent to the
\r
398 timer command queue successfully, then latch the fact that the
\r
399 timer period has already been changed. This is just done to
\r
400 prevent xTimerChangePeriod() being called on every execution of
\r
401 this function once an error has been discovered. */
\r
402 lErrorAlreadyLatched = pdTRUE;
\r
405 /* Update the xExecutionRate variable too as the rate at which this
\r
406 callback is executed has to be passed into the
\r
407 xAreTimerDemoTasksStillRunning() function. */
\r
408 xExecutionRate = mainERROR_CHECK_TIMER_PERIOD;
\r
412 /*-----------------------------------------------------------*/
\r
414 /* This is an application defined callback function used to install the tick
\r
415 interrupt handler. It is provided as an application callback because the kernel
\r
416 will run on lots of different MicroBlaze and FPGA configurations - not all of
\r
417 which will have the same timer peripherals defined or available. This example
\r
418 uses the AXI Timer 0. If that is available on your hardware platform then this
\r
419 example callback implementation should not require modification. The name of
\r
420 the interrupt handler that should be installed is vPortTickISR(), which the
\r
421 function below declares as an extern. */
\r
422 void vApplicationSetupTimerInterrupt( void )
\r
424 portBASE_TYPE xStatus;
\r
425 extern void vPortTickISR( void *pvUnused );
\r
427 /* Initialise the timer/counter. */
\r
428 xStatus = XTmrCtr_Initialize( &xTimer0Instance, XPAR_AXI_TIMER_0_DEVICE_ID );
\r
430 if( xStatus == XST_SUCCESS )
\r
432 /* Install the tick interrupt handler as the timer ISR.
\r
433 *NOTE* The xPortInstallInterruptHandler() API function must be used for
\r
435 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );
\r
438 if( xStatus == pdPASS )
\r
440 /* Enable the timer interrupt in the interrupt controller.
\r
441 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
443 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
\r
445 /* Configure the timer interrupt handler. */
\r
446 XTmrCtr_SetHandler( &xTimer0Instance, ( void * ) vPortTickISR, NULL );
\r
448 /* Set the correct period for the timer. */
\r
449 XTmrCtr_SetResetValue( &xTimer0Instance, ucTimerCounterNumber, ulCounterReloadValue );
\r
451 /* Enable the interrupts. Auto-reload mode is used to generate a
\r
452 periodic tick. Note that interrupts are disabled when this function is
\r
453 called, so interrupts will not start to be processed until the first
\r
454 task has started to run. */
\r
455 XTmrCtr_SetOptions( &xTimer0Instance, ucTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );
\r
457 /* Start the timer. */
\r
458 XTmrCtr_Start( &xTimer0Instance, ucTimerCounterNumber );
\r
461 /* Sanity check that the function executed as expected. */
\r
462 configASSERT( ( xStatus == pdPASS ) );
\r
464 /*-----------------------------------------------------------*/
\r
466 /* This is an application defined callback function used to clear whichever
\r
467 interrupt was installed by the the vApplicationSetupTimerInterrupt() callback
\r
468 function - in this case the interrupt generated by the AXI timer. It is
\r
469 provided as an application callback because the kernel will run on lots of
\r
470 different MicroBlaze and FPGA configurations - not all of which will have the
\r
471 same timer peripherals defined or available. This example uses the AXI Timer 0.
\r
472 If that is available on your hardware platform then this example callback
\r
473 implementation should not require modification provided the example definition
\r
474 of vApplicationSetupTimerInterrupt() is also not modified. */
\r
475 void vApplicationClearTimerInterrupt( void )
\r
477 unsigned long ulCSR;
\r
479 /* Clear the timer interrupt */
\r
480 ulCSR = XTmrCtr_GetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0 );
\r
481 XTmrCtr_SetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0, ulCSR );
\r
483 /*-----------------------------------------------------------*/
\r
485 void vApplicationMallocFailedHook( void )
\r
487 /* vApplicationMallocFailedHook() will only be called if
\r
488 configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
\r
489 function that will get called if a call to pvPortMalloc() fails.
\r
490 pvPortMalloc() is called internally by the kernel whenever a task, queue or
\r
491 semaphore is created. It is also called by various parts of the demo
\r
492 application. If heap_1.c or heap_2.c are used, then the size of the heap
\r
493 available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
\r
494 FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
\r
495 to query the size of free heap space that remains (although it does not
\r
496 provide information on how the remaining heap might be fragmented). */
\r
497 taskDISABLE_INTERRUPTS();
\r
500 /*-----------------------------------------------------------*/
\r
502 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )
\r
504 ( void ) pcTaskName;
\r
507 /* vApplicationStackOverflowHook() will only be called if
\r
508 configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2. The handle and name
\r
509 of the offending task will be passed into the hook function via its
\r
510 parameters. However, when a stack has overflowed, it is possible that the
\r
511 parameters will have been corrupted, in which case the pxCurrentTCB variable
\r
512 can be inspected directly. */
\r
513 taskDISABLE_INTERRUPTS();
\r
516 /*-----------------------------------------------------------*/
\r
518 void vApplicationIdleHook( void )
\r
520 static long lCheckTimerStarted = pdFALSE;
\r
522 /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
\r
523 to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
\r
524 task. It is essential that code added to this hook function never attempts
\r
525 to block in any way (for example, call xQueueReceive() with a block time
\r
526 specified, or call vTaskDelay()). If the application makes use of the
\r
527 vTaskDelete() API function (as this demo application does) then it is also
\r
528 important that vApplicationIdleHook() is permitted to return to its calling
\r
529 function, because it is the responsibility of the idle task to clean up
\r
530 memory allocated by the kernel to any task that has since been deleted. */
\r
532 /* If the check timer has not already been started, then start it now.
\r
533 Normally, the xTimerStart() API function can be called immediately after the
\r
534 timer is created - how this demo application includes the timer demo tasks.
\r
535 The timer demo tasks, as part of their test function, deliberately fill up
\r
536 the timer command queue - meaning the check timer cannot be started until
\r
537 after the scheduler has been started - at which point the timer command
\r
538 queue will have been drained. */
\r
539 if( lCheckTimerStarted == pdFALSE )
\r
541 xTimerStart( xCheckTimer, mainDONT_BLOCK );
\r
542 lCheckTimerStarted = pdTRUE;
\r
545 /*-----------------------------------------------------------*/
\r
547 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump )
\r
549 ( void ) xRegisterDump;
\r
551 /* If configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h, then
\r
552 the kernel will automatically install its own exception handlers before the
\r
553 kernel is started, if the application writer has not already caused them to
\r
554 be installed by calling either of the vPortExceptionsInstallHandlers()
\r
555 or xPortInstallInterruptHandler() API functions before that time. The
\r
556 kernels exception handler populates an xPortRegisterDump structure with
\r
557 the processor state at the point that the exception was triggered - and also
\r
558 includes a strings that say what the exception cause was and which task was
\r
559 running at the time. The exception handler then passes the populated
\r
560 xPortRegisterDump structure into vApplicationExceptionRegisterDump() to
\r
561 allow the application writer to perform any debugging that may be necessary.
\r
562 However, defining vApplicationExceptionRegisterDump() within the application
\r
563 itself is optional. The kernel will use a default implementation if the
\r
564 application writer chooses not to provide their own. */
\r
570 /*-----------------------------------------------------------*/
\r
572 static void prvSetupHardware( void )
\r
574 taskDISABLE_INTERRUPTS();
\r
576 /* Configure the LED outputs. */
\r
577 vParTestInitialise();
\r
579 /* Tasks inherit the exception and cache configuration of the MicroBlaze
\r
580 at the point that they are created. */
\r
581 #if MICROBLAZE_EXCEPTIONS_ENABLED == 1
\r
582 microblaze_enable_exceptions();
\r
585 #if XPAR_MICROBLAZE_USE_ICACHE == 1
\r
586 microblaze_invalidate_icache();
\r
587 microblaze_enable_icache();
\r
590 #if XPAR_MICROBLAZE_USE_DCACHE == 1
\r
591 microblaze_invalidate_dcache();
\r
592 microblaze_enable_dcache();
\r
596 /*-----------------------------------------------------------*/
\r
598 void vMainConfigureTimerForRunTimeStats( void )
\r
600 /* How many times does the counter counter increment in 10ms? */
\r
601 ulClocksPer10thOfAMilliSecond = XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ / 10000UL;
\r
603 /*-----------------------------------------------------------*/
\r
605 unsigned long ulMainGetRunTimeCounterValue( void )
\r
607 unsigned long ulTimerCounts1, ulTimerCounts2, ulTickCount, ulReturn;
\r
609 /* NOTE: This can get called from a yield, in which case interrupts are
\r
610 disabled, or from a tick ISR, in which case the effect is the same as if
\r
611 interrupts were disabled. In either case, it is going to run atomically. */
\r
613 /* The timer is in down count mode. How many clocks have passed since it
\r
614 was last reloaded? */
\r
615 ulTimerCounts1 = ulCounterReloadValue - XTmrCtr_GetValue( &xTimer0Instance, ucTimerCounterNumber );
\r
617 /* How many times has it overflowed? */
\r
618 ulTickCount = xTaskGetTickCountFromISR();
\r
620 /* If this is being called from a yield, has the counter overflowed since
\r
621 it was read? If that is the case then ulTickCounts will need incrementing
\r
622 again as it will not yet have been incremented from the tick interrupt. */
623 ulTimerCounts2 = ulCounterReloadValue - XTmrCtr_GetValue( &xTimer0Instance, ucTimerCounterNumber );
\r
624 if( ulTimerCounts2 < ulTimerCounts1 )
\r
626 /* There is a tick interrupt pending but the tick count not yet
\r
630 /* Use the second timer reading. */
\r
631 ulTimerCounts1 = ulTimerCounts2;
\r
634 /* Convert the tick count into tenths of a millisecond. THIS ASSUMES
\r
635 configTICK_RATE_HZ is 1000! */
\r
636 ulReturn = ( ulTickCount * 10UL );
\r
638 /* Add on the number of tenths of a millisecond that have passed since the
\r
639 tick count last got updated. */
\r
640 ulReturn += ( ulTimerCounts1 / ulClocksPer10thOfAMilliSecond );
\r
642 /* Some crude rounding. */
\r
643 if( ( ulTimerCounts1 % ulClocksPer10thOfAMilliSecond ) > ( ulClocksPer10thOfAMilliSecond >> 1UL ) )
\r
650 /*-----------------------------------------------------------*/
\r
652 char *pcMainGetTaskStatusMessage( void )
\r
656 if( pcStatusMessage == NULL )
\r
658 pcReturn = ( char * ) "OK";
\r
662 pcReturn = ( char * ) pcStatusMessage;
\r