]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/main-full.c
Remove unnecessary files from the MicroBlaze http server file system creation directory.
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / main-full.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3         \r
4 \r
5     ***************************************************************************\r
6      *                                                                       *\r
7      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
8      *    Complete, revised, and edited pdf reference manuals are also       *\r
9      *    available.                                                         *\r
10      *                                                                       *\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
17      *                                                                       *\r
18      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
19      *                                                                       *\r
20      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
21      *                                                                       *\r
22     ***************************************************************************\r
23 \r
24 \r
25     This file is part of the FreeRTOS distribution.\r
26 \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
40     FreeRTOS WEB site.\r
41 \r
42     1 tab == 4 spaces!\r
43 \r
44     http://www.FreeRTOS.org - Documentation, latest information, license and\r
45     contact details.\r
46 \r
47     http://www.SafeRTOS.com - A version that is certified for use in safety\r
48     critical systems.\r
49 \r
50     http://www.OpenRTOS.com - Commercial support, development, porting,\r
51     licensing and training services.\r
52 */\r
53 \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
57  *\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
64  *\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
69  *\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
72  *\r
73  * TCP/IP ("lwIP") task - TBD _RB_\r
74  *\r
75  * "Reg test" tasks - These test the task context switch mechanism by first \r
76  * filling the MicroBlaze registers with known values, before checking that each\r
77  * register maintains the value that was written to it as the tasks are switched\r
78  * in and out.  The two register test tasks do not use the same values, and\r
79  * execute at a very low priority to ensure they are pre-empted regularly.\r
80  *\r
81  * "Check" timer - The check timer period is initially set to five seconds.  \r
82  * The check timer callback function checks that all the standard demo tasks,\r
83  * and the register check tasks, are not only still executing, but are executing\r
84  * without reporting any errors.  If the check timer discovers that a task has\r
85  * either stalled, or reported an error, then it changes its own period from\r
86  * the initial five seconds, to just 200ms.  The check timer callback function\r
87  * also toggles an LED each time it is called.  This provides a visual\r
88  * indication of the system status:  If the LED toggles every five seconds then\r
89  * no issues have been discovered.  If the LED toggles every 200ms then an issue\r
90  * has been discovered with at least one task.  The last reported issue is\r
91  * latched into the pcStatusMessage variable.\r
92  *\r
93  * This file also includes example implementations of the vApplicationTickHook(),\r
94  * vApplicationIdleHook(), vApplicationStackOverflowHook(),\r
95  * vApplicationMallocFailedHook(), vApplicationClearTimerInterrupt(), and\r
96  * vApplicationSetupTimerInterrupt() callback (hook) functions.\r
97  */\r
98 \r
99 /* Standard includes. */\r
100 #include <string.h>\r
101 #include <stdio.h>\r
102 \r
103 /* BSP includes. */\r
104 #include "xtmrctr.h"\r
105 #include "microblaze_exceptions_g.h"\r
106 \r
107 /* Kernel includes. */\r
108 #include "FreeRTOS.h"\r
109 #include "task.h"\r
110 #include "timers.h"\r
111 \r
112 /* Standard demo includes. */\r
113 #include "partest.h"\r
114 #include "flash.h"\r
115 #include "BlockQ.h"\r
116 #include "death.h"\r
117 #include "blocktim.h"\r
118 #include "semtest.h"\r
119 #include "PollQ.h"\r
120 #include "GenQTest.h"\r
121 #include "QPeek.h"\r
122 #include "recmutex.h"\r
123 #include "flop.h"\r
124 #include "dynamic.h"\r
125 #include "comtest_strings.h"\r
126 #include "TimerDemo.h"\r
127 \r
128 /* Priorities at which the various tasks are created. */\r
129 #define mainQUEUE_POLL_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
130 #define mainSEM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 1 )\r
131 #define mainBLOCK_Q_PRIORITY            ( tskIDLE_PRIORITY + 2 )\r
132 #define mainCREATOR_TASK_PRIORITY   ( tskIDLE_PRIORITY + 3 )\r
133 #define mainFLASH_TASK_PRIORITY         ( tskIDLE_PRIORITY + 1 )\r
134 #define mainuIP_TASK_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
135 #define mainCOM_TEST_PRIORITY           ( tskIDLE_PRIORITY + 2 )\r
136 #define mainINTEGER_TASK_PRIORITY   ( tskIDLE_PRIORITY )\r
137 #define mainGEN_QUEUE_TASK_PRIORITY     ( tskIDLE_PRIORITY )\r
138 #define mainFLOP_TASK_PRIORITY          ( tskIDLE_PRIORITY )\r
139 \r
140 /* The LED toggled by the check task. */\r
141 #define mainCHECK_LED                           ( 3 )\r
142 \r
143 /* The rate at which mainCHECK_LED will toggle when all the tasks are running\r
144 without error.  See the description of the check timer in the comments at the\r
145 top of this file. */\r
146 #define mainNO_ERROR_CHECK_TIMER_PERIOD         ( 5000 / portTICK_RATE_MS )\r
147 \r
148 /* The rate at which mainCHECK_LED will toggle when an error has been reported\r
149 by at least one task.  See the description of the check timer in the comments at \r
150 the top of this file. */\r
151 #define mainERROR_CHECK_TIMER_PERIOD            ( 200 / portTICK_RATE_MS )\r
152 \r
153 /* A block time of zero simply means "don't block". */
154 #define mainDONT_BLOCK                                          ( ( portTickType ) 0 )\r
155 \r
156 /* The LED used by the comtest tasks. See the comtest_strings.c file for more\r
157 information.  In this case an invalid LED number is provided as all four\r
158 available LEDs (LEDs 0 to 3) are already in use. */\r
159 #define mainCOM_TEST_LED                        ( 4 )\r
160 \r
161 /* Baud rate used by the comtest tasks.  The baud rate used is actually fixed in \r
162 UARTLite IP when the hardware was built, but the standard serial init function \r
163 required a baud rate parameter to be provided - in this case it is just \r
164 ignored. */\r
165 #define mainCOM_TEST_BAUD_RATE                          ( XPAR_RS232_UART_1_BAUDRATE )\r
166 \r
167 /* The timer test task generates a lot of timers that all use a different \r
168 period that is a multiple of the mainTIMER_TEST_PERIOD definition. */\r
169 #define mainTIMER_TEST_PERIOD                   ( 20 )\r
170 \r
171 /*-----------------------------------------------------------*/\r
172 \r
173 /*\r
174  * The register test tasks as described in the comments at the top of this file.\r
175  * The nature of the register test tasks means they have to be implemented in\r
176  * assembler.\r
177  */\r
178 extern void vRegisterTest1( void *pvParameters );\r
179 extern void vRegisterTest2( void *pvParameters );\r
180 \r
181 /*\r
182  * Defines the 'check' timer functionality as described at the top of this file.  \r
183  * This function is the callback function associated with the 'check' timer.\r
184  */\r
185 static void vCheckTimerCallback( xTimerHandle xTimer );\r
186 \r
187 /* \r
188  * Configure the interrupt controller, LED outputs and button inputs. \r
189  */\r
190 static void prvSetupHardware( void );\r
191 \r
192 /*-----------------------------------------------------------*/\r
193 \r
194 /* The check timer callback function sets pcStatusMessage to a string that\r
195 indicates the last reported error that it discovered. */\r
196 static const char *pcStatusMessage = NULL;\r
197 \r
198 /* Structures that hold the state of the various peripherals used by this demo.\r
199 These are used by the Xilinx peripheral driver API functions.  In this case,\r
200 only the timer/counter is used directly within this file. */\r
201 static XTmrCtr xTimer0Instance;\r
202 \r
203 /* The 'check' timer, as described at the top of this file. */\r
204 static xTimerHandle xCheckTimer = NULL;\r
205 \r
206 /*-----------------------------------------------------------*/\r
207 \r
208 int main( void )\r
209 {\r
210         /***************************************************************************\r
211         This project includes a lot of demo and test tasks and timers,  and is \r
212         therefore comprehensive, but complex.  If you would prefer a much simpler \r
213         project to get started with, then select the 'Blinky' build configuration \r
214         within the SDK Eclipse IDE.\r
215         ***************************************************************************/\r
216 \r
217         /* Configure the interrupt controller, LED outputs and button inputs. */\r
218         prvSetupHardware();\r
219 \r
220         /* Start the reg test tasks, as described in the comments at the top of this\r
221         file. */\r
222         xTaskCreate( vRegisterTest1, ( const signed char * const ) "RegTst1", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );\r
223         xTaskCreate( vRegisterTest2, ( const signed char * const ) "RegTst2", configMINIMAL_STACK_SIZE, ( void * ) 0, tskIDLE_PRIORITY, NULL );\r
224 \r
225         /* Create the standard demo tasks. */\r
226         vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
227         vCreateBlockTimeTasks();\r
228         vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
229         vStartPolledQueueTasks( mainQUEUE_POLL_PRIORITY );\r
230         vStartGenericQueueTasks( mainGEN_QUEUE_TASK_PRIORITY );\r
231         vStartLEDFlashTasks( mainFLASH_TASK_PRIORITY );\r
232         vStartQueuePeekTasks();\r
233         vStartRecursiveMutexTasks();\r
234         vStartComTestStringsTasks( mainCOM_TEST_PRIORITY, mainCOM_TEST_BAUD_RATE, mainCOM_TEST_LED );\r
235         vStartDynamicPriorityTasks();\r
236         vStartTimerDemoTask( mainTIMER_TEST_PERIOD );\r
237 \r
238         /* Note - the set of standard demo tasks contains two versions of\r
239         vStartMathTasks.c.  One is defined in flop.c, and uses double precision\r
240         floating point numbers and variables.  The other is defined in sp_flop.c,\r
241         and uses single precision floating point numbers and variables.  The\r
242         MicroBlaze floating point unit only handles single precision floating.\r
243         Therefore, to test the floating point hardware, sp_flop.c should be included\r
244         in this project. */\r
245         vStartMathTasks( mainFLOP_TASK_PRIORITY );\r
246 \r
247         /* The suicide tasks must be created last as they need to know how many\r
248         tasks were running prior to their creation.  This then allows them to \r
249         ascertain whether or not the correct/expected number of tasks are running at \r
250         any given time. */\r
251         vCreateSuicidalTasks( mainCREATOR_TASK_PRIORITY );\r
252 \r
253         /* Create the 'check' timer - the timer that periodically calls the\r
254         check function as described in the comments at the top of this file.  Note \r
255         that, for reasons stated in the comments within vApplicationIdleHook()\r
256         (defined in this file), the check timer is not actually started until after \r
257         the scheduler has been started. */\r
258         xCheckTimer = xTimerCreate( ( const signed char * ) "Check timer", mainNO_ERROR_CHECK_TIMER_PERIOD, pdTRUE, ( void * ) 0, vCheckTimerCallback );\r
259 \r
260         /* Start the scheduler running.  From this point on, only tasks and \r
261         interrupts will be executing. */\r
262         vTaskStartScheduler();\r
263 \r
264         /* If all is well then the following line will never be reached.  If\r
265         execution does reach here, then it is highly probably that the heap size\r
266         is too small for the idle and/or timer tasks to be created within \r
267         vTaskStartScheduler(). */\r
268         taskDISABLE_INTERRUPTS();\r
269         for( ;; );\r
270 }\r
271 /*-----------------------------------------------------------*/\r
272 \r
273 static void vCheckTimerCallback( xTimerHandle xTimer )\r
274 {\r
275 extern unsigned long ulRegTest1CycleCount, ulRegTest2CycleCount;\r
276 static volatile unsigned long ulLastRegTest1CycleCount = 0UL, ulLastRegTest2CycleCount = 0UL;\r
277 static long lErrorAlreadyLatched = pdFALSE;\r
278 portTickType xExecutionRate = mainNO_ERROR_CHECK_TIMER_PERIOD;\r
279 \r
280         /* This is the callback function used by the 'check' timer, as described\r
281         in the comments at the top of this file. */\r
282 \r
283         /* Check the standard demo tasks are running without error. */\r
284         if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
285         {\r
286                 pcStatusMessage = "Error: GenQueue";\r
287         }\r
288         else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
289         {\r
290                 pcStatusMessage = "Error: QueuePeek\r\n";\r
291         }\r
292         else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
293         {\r
294                 pcStatusMessage = "Error: BlockQueue\r\n";\r
295         }\r
296         else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
297         {\r
298                 pcStatusMessage = "Error: BlockTime\r\n";\r
299         }\r
300         else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
301         {\r
302                 pcStatusMessage = "Error: SemTest\r\n";\r
303         }\r
304         else if( xArePollingQueuesStillRunning() != pdTRUE )\r
305         {\r
306                 pcStatusMessage = "Error: PollQueue\r\n";\r
307         }\r
308         else if( xIsCreateTaskStillRunning() != pdTRUE )\r
309         {\r
310                 pcStatusMessage = "Error: Death\r\n";\r
311         }\r
312         else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
313         {\r
314                 pcStatusMessage = "Error: RecMutex\r\n";\r
315         }\r
316         else if( xAreMathsTaskStillRunning() != pdPASS )\r
317         {\r
318                 pcStatusMessage = "Error: Flop\r\n";\r
319         }\r
320         else if( xAreComTestTasksStillRunning() != pdPASS )\r
321         {\r
322                 pcStatusMessage = "Error: Comtest\r\n";\r
323         }\r
324         else if( xAreDynamicPriorityTasksStillRunning() != pdPASS )\r
325         {\r
326                 pcStatusMessage = "Error: Dynamic\r\n";\r
327         }\r
328         else if( xAreTimerDemoTasksStillRunning( xExecutionRate ) != pdTRUE )\r
329         {\r
330                 pcStatusMessage = "Error: TimerDemo";\r
331         }\r
332         else if( ulRegTest1CycleCount == ulLastRegTest1CycleCount )\r
333         {\r
334                 /* Check the reg test tasks are still cycling.  They will stop\r
335                 incrementing their loop counters if they encounter an error. */\r
336                 pcStatusMessage = "Error: RegTest1\r\n";\r
337         }\r
338         else if( ulRegTest2CycleCount == ulLastRegTest2CycleCount )\r
339         {\r
340                 pcStatusMessage = "Error: RegTest2\r\n";\r
341         }\r
342 \r
343         /* Store a local copy of the current reg test loop counters.  If these have\r
344         not incremented the next time this callback function is executed then the\r
345         reg test tasks have either stalled or discovered an error. */\r
346         ulLastRegTest1CycleCount = ulRegTest1CycleCount;\r
347         ulLastRegTest2CycleCount = ulRegTest2CycleCount;\r
348 \r
349         /* Toggle the check LED to give an indication of the system status.  If\r
350         the LED toggles every 5 seconds then everything is ok.  A faster toggle\r
351         indicates an error. */\r
352         vParTestToggleLED( mainCHECK_LED );\r
353 \r
354         if( pcStatusMessage != NULL )\r
355         {\r
356                 if( lErrorAlreadyLatched == pdFALSE )\r
357                 {\r
358                         /* An error has occurred, so change the period of the timer that\r
359                         calls this callback function.  This results in the LED toggling at\r
360                         a faster rate - giving the user visual feedback that something is not\r
361                         as it should be.  This function is called from the context of the\r
362                         timer service task so must ***not*** attempt to block while calling\r
363                         this function. */
364                         if( xTimerChangePeriod( xTimer, mainERROR_CHECK_TIMER_PERIOD, mainDONT_BLOCK ) == pdPASS )\r
365                         {\r
366                                 /* If the command to change the timer period was sent to the\r
367                                 timer command queue successfully, then latch the fact that the\r
368                                 timer period has already been changed.  This is just done to\r
369                                 prevent xTimerChangePeriod() being called on every execution of\r
370                                 this function once an error has been discovered.  */\r
371                                 lErrorAlreadyLatched = pdTRUE;\r
372                         }\r
373 \r
374                         /* Update the xExecutionRate variable too as the rate at which this\r
375                         callback is executed has to be passed into the\r
376                         xAreTimerDemoTasksStillRunning() function. */\r
377                         xExecutionRate = mainERROR_CHECK_TIMER_PERIOD;\r
378                 }\r
379         }\r
380 }\r
381 /*-----------------------------------------------------------*/\r
382 \r
383 /* This is an application defined callback function used to install the tick\r
384 interrupt handler.  It is provided as an application callback because the kernel\r
385 will run on lots of different MicroBlaze and FPGA configurations - not all of\r
386 which will have the same timer peripherals defined or available.  This example\r
387 uses the AXI Timer 0.  If that is available on your hardware platform then this\r
388 example callback implementation should not require modification.   The name of\r
389 the interrupt handler that should be installed is vPortTickISR(), which the \r
390 function below declares as an extern. */\r
391 void vApplicationSetupTimerInterrupt( void )\r
392 {\r
393 portBASE_TYPE xStatus;\r
394 const unsigned char ucTimerCounterNumber = ( unsigned char ) 0U;\r
395 const unsigned long ulCounterValue = ( ( XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );\r
396 extern void vPortTickISR( void *pvUnused );\r
397 \r
398         /* Initialise the timer/counter. */\r
399         xStatus = XTmrCtr_Initialize( &xTimer0Instance, XPAR_AXI_TIMER_0_DEVICE_ID );\r
400 \r
401         if( xStatus == XST_SUCCESS )\r
402         {\r
403                 /* Install the tick interrupt handler as the timer ISR. \r
404                 *NOTE* The xPortInstallInterruptHandler() API function must be used for\r
405                 this purpose. */\r
406                 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );\r
407         }\r
408 \r
409         if( xStatus == pdPASS )\r
410         {\r
411                 /* Enable the timer interrupt in the interrupt controller.\r
412                 *NOTE* The vPortEnableInterrupt() API function must be used for this\r
413                 purpose. */\r
414                 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );\r
415 \r
416                 /* Configure the timer interrupt handler. */\r
417                 XTmrCtr_SetHandler( &xTimer0Instance, ( void * ) vPortTickISR, NULL );\r
418 \r
419                 /* Set the correct period for the timer. */\r
420                 XTmrCtr_SetResetValue( &xTimer0Instance, ucTimerCounterNumber, ulCounterValue );\r
421 \r
422                 /* Enable the interrupts.  Auto-reload mode is used to generate a\r
423                 periodic tick.  Note that interrupts are disabled when this function is\r
424                 called, so interrupts will not start to be processed until the first\r
425                 task has started to run. */\r
426                 XTmrCtr_SetOptions( &xTimer0Instance, ucTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );\r
427 \r
428                 /* Start the timer. */\r
429                 XTmrCtr_Start( &xTimer0Instance, ucTimerCounterNumber );\r
430         }\r
431 \r
432         /* Sanity check that the function executed as expected. */\r
433         configASSERT( ( xStatus == pdPASS ) );\r
434 }\r
435 /*-----------------------------------------------------------*/\r
436 \r
437 /* This is an application defined callback function used to clear whichever\r
438 interrupt was installed by the the vApplicationSetupTimerInterrupt() callback\r
439 function - in this case the interrupt generated by the AXI timer.  It is \r
440 provided as an application callback because the kernel will run on lots of \r
441 different MicroBlaze and FPGA configurations - not all of which will have the \r
442 same timer peripherals defined or available.  This example uses the AXI Timer 0.  \r
443 If that is available on your hardware platform then this example callback \r
444 implementation should not require modification provided the example definition\r
445 of vApplicationSetupTimerInterrupt() is also not modified. */\r
446 void vApplicationClearTimerInterrupt( void )\r
447 {\r
448 unsigned long ulCSR;\r
449 \r
450         /* Clear the timer interrupt */\r
451         ulCSR = XTmrCtr_GetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0 );\r
452         XTmrCtr_SetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0, ulCSR );\r
453 }\r
454 /*-----------------------------------------------------------*/\r
455 \r
456 void vApplicationMallocFailedHook( void )\r
457 {\r
458         /* vApplicationMallocFailedHook() will only be called if\r
459         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
460         function that will get called if a call to pvPortMalloc() fails. \r
461         pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
462         semaphore is created.  It is also called by various parts of the demo\r
463         application.  If heap_1.c or heap_2.c are used, then the size of the heap\r
464         available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
465         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
466         to query the size of free heap space that remains (although it does not\r
467         provide information on how the remaining heap might be fragmented). */\r
468         taskDISABLE_INTERRUPTS();\r
469         for( ;; );\r
470 }\r
471 /*-----------------------------------------------------------*/\r
472 \r
473 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
474 {\r
475         /* vApplicationStackOverflowHook() will only be called if\r
476         configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2.  The handle and name\r
477         of the offending task will be passed into the hook function via its \r
478         parameters.  However, when a stack has overflowed, it is possible that the\r
479         parameters will have been corrupted, in which case the pxCurrentTCB variable\r
480         can be inspected directly. */\r
481         taskDISABLE_INTERRUPTS();\r
482         for( ;; );\r
483 }\r
484 /*-----------------------------------------------------------*/\r
485 \r
486 void vApplicationIdleHook( void )\r
487 {\r
488 static long lCheckTimerStarted = pdFALSE;\r
489 \r
490         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set \r
491         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle \r
492         task.  It is essential that code added to this hook function never attempts \r
493         to block in any way (for example, call xQueueReceive() with a block time \r
494         specified, or call vTaskDelay()).  If the application makes use of the \r
495         vTaskDelete() API function (as this demo application does) then it is also \r
496         important that vApplicationIdleHook() is permitted to return to its calling \r
497         function, because it is the responsibility of the idle task to clean up \r
498         memory allocated by the kernel to any task that has since been deleted. */\r
499 \r
500         /* If the check timer has not already been started, then start it now.\r
501         Normally, the xTimerStart() API function can be called immediately after the\r
502         timer is created - how this demo application includes the timer demo tasks.\r
503         The timer demo tasks, as part of their test function, deliberately fill up\r
504         the timer command queue - meaning the check timer cannot be started until\r
505         after the scheduler has been started - at which point the timer command\r
506         queue will have been drained. */\r
507         if( lCheckTimerStarted == pdFALSE )\r
508         {\r
509                 xTimerStart( xCheckTimer, mainDONT_BLOCK ); \r
510                 lCheckTimerStarted = pdTRUE;\r
511         }\r
512 }\r
513 /*-----------------------------------------------------------*/\r
514 \r
515 void vApplicationTickHook( void )\r
516 {\r
517         /* vApplicationTickHook() will only be called if configUSE_TICK_HOOK is set\r
518         to 1 in FreeRTOSConfig.h.  It executes from an interrupt context so must\r
519         not use any FreeRTOS API functions that do not end in ...FromISR(). */\r
520 \r
521         /* Call the periodic timer test, which tests the timer API functions that\r
522         can be called from an ISR. */\r
523         vTimerPeriodicISRTests();\r
524 }\r
525 /*-----------------------------------------------------------*/\r
526 \r
527 void vApplicationExceptionRegisterDump( xPortRegisterDump *xRegisterDump )\r
528 {\r
529         /* If configINSTALL_EXCEPTION_HANDLERS is set to 1 in FreeRTOSConfig.h, then \r
530         the kernel will automatically install its own exception handlers before the \r
531         kernel is started, if the application writer has not already caused them to \r
532         be installed by calling either of the vPortExceptionsInstallHandlers() \r
533         or xPortInstallInterruptHandler() API functions before that time.  The \r
534         kernels exception handler populates an xPortRegisterDump structure with\r
535         the processor state at the point that the exception was triggered - and also\r
536         includes a strings that say what the exception cause was and which task was\r
537         running at the time.  The exception handler then passes the populated\r
538         xPortRegisterDump structure into vApplicationExceptionRegisterDump() to\r
539         allow the application writer to perform any debugging that may be necessary.\r
540         However, defining vApplicationExceptionRegisterDump() within the application\r
541         itself is optional.  The kernel will use a default implementation if the\r
542         application writer chooses not to provide their own. */\r
543         for( ;; )\r
544         {\r
545                 portNOP();\r
546         }\r
547 }\r
548 /*-----------------------------------------------------------*/\r
549 \r
550 static void prvSetupHardware( void )\r
551 {\r
552         taskDISABLE_INTERRUPTS();\r
553         \r
554         /* Configure the LED outputs. */\r
555         vParTestInitialise();\r
556 \r
557         /* Tasks inherit the exception and cache configuration of the MicroBlaze\r
558         at the point that they are created. */\r
559         #if MICROBLAZE_EXCEPTIONS_ENABLED == 1\r
560                 microblaze_enable_exceptions();\r
561         #endif\r
562 \r
563         #if XPAR_MICROBLAZE_USE_ICACHE == 1\r
564                 microblaze_invalidate_icache();\r
565                 microblaze_enable_icache();\r
566         #endif\r
567 \r
568         #if XPAR_MICROBLAZE_USE_DCACHE == 1\r
569                 microblaze_invalidate_dcache();\r
570                 microblaze_enable_dcache();\r
571         #endif\r
572 \r
573 }\r
574 /*-----------------------------------------------------------*/\r
575 \r