]> git.sur5r.net Git - freertos/blob - Demo/MicroBlaze_Spartan-6_EthernetLite/SDKProjects/RTOSDemoSource/main-blinky.c
Remove unnecessary files from the MicroBlaze http server file system creation directory.
[freertos] / Demo / MicroBlaze_Spartan-6_EthernetLite / SDKProjects / RTOSDemoSource / main-blinky.c
1 /*\r
2     FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
3 \r
4 \r
5         FreeRTOS supports many tools and architectures. V7.0.0 is sponsored by:\r
6         Atollic AB - Atollic provides professional embedded systems development\r
7         tools for C/C++ development, code analysis and test automation.\r
8         See http://www.atollic.com\r
9 \r
10 \r
11     ***************************************************************************\r
12      *                                                                       *\r
13      *    FreeRTOS tutorial books are available in pdf and paperback.        *\r
14      *    Complete, revised, and edited pdf reference manuals are also       *\r
15      *    available.                                                         *\r
16      *                                                                       *\r
17      *    Purchasing FreeRTOS documentation will not only help you, by       *\r
18      *    ensuring you get running as quickly as possible and with an        *\r
19      *    in-depth knowledge of how to use FreeRTOS, it will also help       *\r
20      *    the FreeRTOS project to continue with its mission of providing     *\r
21      *    professional grade, cross platform, de facto standard solutions    *\r
22      *    for microcontrollers - completely free of charge!                  *\r
23      *                                                                       *\r
24      *    >>> See http://www.FreeRTOS.org/Documentation for details. <<<     *\r
25      *                                                                       *\r
26      *    Thank you for using FreeRTOS, and thank you for your support!      *\r
27      *                                                                       *\r
28     ***************************************************************************\r
29 \r
30 \r
31     This file is part of the FreeRTOS distribution.\r
32 \r
33     FreeRTOS is free software; you can redistribute it and/or modify it under\r
34     the terms of the GNU General Public License (version 2) as published by the\r
35     Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
36     >>>NOTE<<< The modification to the GPL is included to allow you to\r
37     distribute a combined work that includes FreeRTOS without being obliged to\r
38     provide the source code for proprietary components outside of the FreeRTOS\r
39     kernel.  FreeRTOS is distributed in the hope that it will be useful, but\r
40     WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
41     or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for\r
42     more details. You should have received a copy of the GNU General Public\r
43     License and the FreeRTOS license exception along with FreeRTOS; if not it\r
44     can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
45     by writing to Richard Barry, contact details for whom are available on the\r
46     FreeRTOS WEB site.\r
47 \r
48     1 tab == 4 spaces!\r
49 \r
50     http://www.FreeRTOS.org - Documentation, latest information, license and\r
51     contact details.\r
52 \r
53     http://www.SafeRTOS.com - A version that is certified for use in safety\r
54     critical systems.\r
55 \r
56     http://www.OpenRTOS.com - Commercial support, development, porting,\r
57     licensing and training services.\r
58 */\r
59 \r
60 /*\r
61  * main-blinky.c is included when the "Blinky" build configuration is used.\r
62  * main-full.c is included when the "Full" build configuration is used.\r
63  *\r
64  * main-blinky.c (this file) defines a very simple demo that creates two tasks,\r
65  * one queue, and one timer.  It also demonstrates how MicroBlaze interrupts\r
66  * can interact with FreeRTOS tasks/timers.\r
67  *\r
68  * This simple demo project was developed and tested on the Spartan-6 SP605 \r
69  * development board, using the hardware configuration found in the hardware\r
70  * project that is already included in the Eclipse project.\r
71  *\r
72  * The idle hook function:\r
73  * The idle hook function demonstrates how to query the amount of FreeRTOS heap\r
74  * space that is remaining (see vApplicationIdleHook() defined in this file).\r
75  *\r
76  * The main() Function:\r
77  * main() creates one software timer, one queue, and two tasks.  It then starts\r
78  * the scheduler.\r
79  *\r
80  * The Queue Send Task:\r
81  * The queue send task is implemented by the prvQueueSendTask() function in\r
82  * this file.  prvQueueSendTask() sits in a loop that causes it to repeatedly\r
83  * block for 200 milliseconds, before sending the value 100 to the queue that\r
84  * was created within main().  Once the value is sent, the task loops back\r
85  * around to block for another 200 milliseconds.\r
86  *\r
87  * The Queue Receive Task:\r
88  * The queue receive task is implemented by the prvQueueReceiveTask() function\r
89  * in this file.  prvQueueReceiveTask() sits in a loop that causes it to\r
90  * repeatedly attempt to read data from the queue that was created within\r
91  * main().  When data is received, the task checks the value of the data, and\r
92  * if the value equals the expected 100, toggles an LED.  The 'block time' \r
93  * parameter passed to the queue receive function specifies that the task\r
94  * should be held in the Blocked state indefinitely to wait for data to be\r
95  * available on the queue.  The queue receive task will only leave the Blocked\r
96  * state when the queue send task writes to the queue.  As the queue send task\r
97  * writes to the queue every 200 milliseconds, the queue receive task leaves\r
98  * the Blocked state every 200 milliseconds, and therefore toggles the LED\r
99  * every 200 milliseconds.\r
100  *\r
101  * The LED Software Timer and the Button Interrupt:\r
102  * The user buttons are configured to generate an interrupt each time one is\r
103  * pressed.  The interrupt service routine switches an LED on, and resets the\r
104  * LED software timer.  The LED timer has a 5000 millisecond (5 second) period,\r
105  * and uses a callback function that is defined to just turn the LED off again.\r
106  * Therefore, pressing the user button will turn the LED on, and the LED will\r
107  * remain on until a full five seconds pass without the button being pressed.\r
108  */\r
109 \r
110 /* Kernel includes. */\r
111 #include "FreeRTOS.h"\r
112 #include "task.h"\r
113 #include "queue.h"\r
114 #include "timers.h"\r
115 \r
116 /* BSP includes. */\r
117 #include "xtmrctr.h"\r
118 #include "xgpio.h"\r
119 \r
120 /* Priorities at which the tasks are created. */\r
121 #define mainQUEUE_RECEIVE_TASK_PRIORITY         ( tskIDLE_PRIORITY + 2 )\r
122 #define mainQUEUE_SEND_TASK_PRIORITY            ( tskIDLE_PRIORITY + 1 )\r
123 \r
124 /* The rate at which data is sent to the queue, specified in milliseconds, and\r
125 converted to ticks using the portTICK_RATE_MS constant. */\r
126 #define mainQUEUE_SEND_FREQUENCY_MS                     ( 200 / portTICK_RATE_MS )\r
127 \r
128 /* The number of items the queue can hold.  This is 1 as the receive task\r
129 will remove items as they are added because it has the higher priority, meaning \r
130 the send task should always find the queue empty. */\r
131 #define mainQUEUE_LENGTH                                        ( 1 )\r
132 \r
133 /* The LED toggled by the queue receive task. */\r
134 #define mainTASK_CONTROLLED_LED                         0x01UL\r
135 \r
136 /* The LED turned on by the button interrupt, and turned off by the LED timer. */\r
137 #define mainTIMER_CONTROLLED_LED                        0x02UL\r
138 \r
139 /* A block time of 0 simply means, "don't block". */\r
140 #define mainDONT_BLOCK                                          ( portTickType ) 0\r
141 \r
142 /*-----------------------------------------------------------*/\r
143 \r
144 /*\r
145  * Setup the NVIC, LED outputs, and button inputs.\r
146  */\r
147 static void prvSetupHardware( void );\r
148 \r
149 /*\r
150  * The tasks as described in the comments at the top of this file.\r
151  */\r
152 static void prvQueueReceiveTask( void *pvParameters );\r
153 static void prvQueueSendTask( void *pvParameters );\r
154 \r
155 /*\r
156  * The LED timer callback function.  This does nothing but switch off the\r
157  * LED defined by the mainTIMER_CONTROLLED_LED constant.\r
158  */\r
159 static void vLEDTimerCallback( xTimerHandle xTimer );\r
160 \r
161 /* \r
162  * The handler executed each time a button interrupt is generated.  This ensures\r
163  * the LED defined by mainTIMER_CONTROLLED_LED is on, and resets the timer so\r
164  * the timer will not turn the LED off for a full 5 seconds after the button\r
165  * interrupt occurred.\r
166  */\r
167 static void prvButtonInputInterruptHandler( void *pvUnused );\r
168 \r
169 /*-----------------------------------------------------------*/\r
170 \r
171 /* The queue used by the queue send and queue receive tasks. */\r
172 static xQueueHandle xQueue = NULL;\r
173 \r
174 /* The LED software timer.  This uses vLEDTimerCallback() as its callback\r
175 function. */\r
176 static xTimerHandle xLEDTimer = NULL;\r
177 \r
178 /* Maintains the current LED output state. */\r
179 static volatile unsigned char ucGPIOState = 0U;\r
180 \r
181 /*-----------------------------------------------------------*/\r
182 \r
183 /* Structures that hold the state of the various peripherals used by this demo.\r
184 These are used by the Xilinx peripheral driver API functions. */\r
185 static XTmrCtr xTimer0Instance;\r
186 static XGpio xOutputGPIOInstance, xInputGPIOInstance;\r
187 \r
188 /* Constants required by the Xilinx peripheral driver API functions that are\r
189 relevant to the particular hardware set up. */\r
190 static const unsigned long ulGPIOOutputChannel = 1UL, ulGPIOInputChannel = 1UL;\r
191 \r
192 /*-----------------------------------------------------------*/\r
193 \r
194 int main( void )\r
195 {\r
196         /* *************************************************************************\r
197         This is a very simple project suitable for getting started with FreeRTOS.  \r
198         If you would prefer a more complex project that demonstrates a lot more \r
199         features and tests, then select the 'Full' build configuration within the \r
200         SDK Eclipse IDE. \r
201         ***************************************************************************/\r
202 \r
203         /* Configure the interrupt controller, LED outputs and button inputs. */\r
204         prvSetupHardware();\r
205 \r
206         /* Create the queue used by the queue send and queue receive tasks as\r
207         described in the comments at the top of this file. */\r
208         xQueue = xQueueCreate( mainQUEUE_LENGTH, sizeof( unsigned long ) );\r
209 \r
210         /* Sanity check that the queue was created. */\r
211         configASSERT( xQueue );\r
212 \r
213         /* Start the two tasks as described in the comments at the top of this \r
214         file. */\r
215         xTaskCreate( prvQueueReceiveTask, ( signed char * ) "Rx", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_RECEIVE_TASK_PRIORITY, NULL );\r
216         xTaskCreate( prvQueueSendTask, ( signed char * ) "TX", configMINIMAL_STACK_SIZE, NULL, mainQUEUE_SEND_TASK_PRIORITY, NULL );\r
217 \r
218         /* Create the software timer that is responsible for turning off the LED\r
219         if the button is not pushed within 5000ms, as described at the top of\r
220         this file.  The timer is not actually started until a button interrupt is\r
221         pushed, as it is not until that point that the LED is turned on. */\r
222         xLEDTimer = xTimerCreate(       ( const signed char * ) "LEDTimer", /* A text name, purely to help debugging. */\r
223                                                                 ( 5000 / portTICK_RATE_MS ),            /* The timer period, in this case 5000ms (5s). */\r
224                                                                 pdFALSE,                                                        /* This is a one shot timer, so xAutoReload is set to pdFALSE. */\r
225                                                                 ( void * ) 0,                                           /* The ID is not used, so can be set to anything. */\r
226                                                                 vLEDTimerCallback                                       /* The callback function that switches the LED off. */\r
227                                                         );\r
228 \r
229         /* Start the tasks and timer running. */\r
230         vTaskStartScheduler();\r
231 \r
232         /* If all is well, the scheduler will now be running, and the following line\r
233         will never be reached.  If the following line does execute, then there was\r
234         insufficient FreeRTOS heap memory available for the idle and/or timer tasks\r
235         to be created.  See the memory management section on the FreeRTOS web site\r
236         for more details. */\r
237         for( ;; );\r
238 }\r
239 /*-----------------------------------------------------------*/\r
240 \r
241 /* The callback is executed when the LED timer expires. */\r
242 static void vLEDTimerCallback( xTimerHandle xTimer )\r
243 {\r
244         /* The timer has expired - so no button pushes have occurred in the last\r
245         five seconds - turn the LED off.  NOTE - accessing the LED port should use\r
246         a critical section because it is accessed from multiple tasks, and the\r
247         button interrupt - in this trivial case, for simplicity, the critical\r
248         section is omitted. */\r
249         ucGPIOState &= ~mainTIMER_CONTROLLED_LED;\r
250         XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );\r
251 }\r
252 /*-----------------------------------------------------------*/\r
253 \r
254 /* The ISR is executed when the user button is pushed. */\r
255 static void prvButtonInputInterruptHandler( void *pvUnused )\r
256 {\r
257 long lHigherPriorityTaskWoken = pdFALSE;\r
258 \r
259         /* The button was pushed, so ensure the LED is on before resetting the\r
260         LED timer.  The LED timer will turn the LED off if the button is not\r
261         pushed within 5000ms. */\r
262         ucGPIOState |= mainTIMER_CONTROLLED_LED;\r
263         XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );\r
264 \r
265         /* Ensure only the ISR safe reset API function is used, as this is executed\r
266         in an interrupt context. */\r
267         xTimerResetFromISR( xLEDTimer, &lHigherPriorityTaskWoken );\r
268 \r
269         /* Clear the interrupt before leaving. */\r
270         XGpio_InterruptClear( &xInputGPIOInstance, ulGPIOInputChannel );\r
271 \r
272         /* If calling xTimerResetFromISR() caused a task (in this case the timer\r
273         service/daemon task) to unblock, and the unblocked task has a priority\r
274         higher than or equal to the task that was interrupted, then\r
275         lHigherPriorityTaskWoken will now be set to pdTRUE, and calling\r
276         portEND_SWITCHING_ISR() will ensure the unblocked task runs next. */\r
277         portYIELD_FROM_ISR( lHigherPriorityTaskWoken );\r
278 }\r
279 /*-----------------------------------------------------------*/\r
280 \r
281 static void prvQueueSendTask( void *pvParameters )\r
282 {\r
283 portTickType xNextWakeTime;\r
284 const unsigned long ulValueToSend = 100UL;\r
285 \r
286         /* Initialise xNextWakeTime - this only needs to be done once. */\r
287         xNextWakeTime = xTaskGetTickCount();\r
288 \r
289         for( ;; )\r
290         {\r
291                 /* Place this task in the blocked state until it is time to run again.\r
292                 The block time is specified in ticks, the constant used converts ticks\r
293                 to ms.  While in the Blocked state this task will not consume any CPU\r
294                 time. */\r
295                 vTaskDelayUntil( &xNextWakeTime, mainQUEUE_SEND_FREQUENCY_MS );\r
296 \r
297                 /* Send to the queue - causing the queue receive task to unblock and\r
298                 toggle an LED.  0 is used as the block time so the sending operation\r
299                 will not block - it shouldn't need to block as the queue should always\r
300                 be empty at this point in the code. */\r
301                 xQueueSend( xQueue, &ulValueToSend, mainDONT_BLOCK );\r
302         }\r
303 }\r
304 /*-----------------------------------------------------------*/\r
305 \r
306 static void prvQueueReceiveTask( void *pvParameters )\r
307 {\r
308 unsigned long ulReceivedValue;\r
309 \r
310         for( ;; )\r
311         {\r
312                 /* Wait until something arrives in the queue - this task will block\r
313                 indefinitely provided INCLUDE_vTaskSuspend is set to 1 in\r
314                 FreeRTOSConfig.h. */\r
315                 xQueueReceive( xQueue, &ulReceivedValue, portMAX_DELAY );\r
316 \r
317                 /*  To get here something must have been received from the queue, but\r
318                 is it the expected value?  If it is, toggle the green LED. */\r
319                 if( ulReceivedValue == 100UL )\r
320                 {\r
321                         /* NOTE - accessing the LED port should use a critical section\r
322                         because it is accessed from multiple tasks, and the button interrupt\r
323                         - in this trivial case, for simplicity, the critical section is\r
324                         omitted. */\r
325                         if( ( ucGPIOState & mainTASK_CONTROLLED_LED ) != 0 )\r
326                         {\r
327                                 ucGPIOState &= ~mainTASK_CONTROLLED_LED;\r
328                         }\r
329                         else\r
330                         {\r
331                                 ucGPIOState |= mainTASK_CONTROLLED_LED;\r
332                         }\r
333 \r
334                         XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );\r
335                 }\r
336         }\r
337 }\r
338 /*-----------------------------------------------------------*/\r
339 \r
340 static void prvSetupHardware( void )\r
341 {\r
342 portBASE_TYPE xStatus;\r
343 const unsigned char ucSetToOutput = 0U;\r
344 \r
345         /* Initialize the GPIO for the LEDs. */\r
346         xStatus = XGpio_Initialize( &xOutputGPIOInstance, XPAR_LEDS_4BITS_DEVICE_ID );\r
347         if( xStatus == XST_SUCCESS )\r
348         {\r
349                 /* All bits on this channel are going to be outputs (LEDs). */\r
350                 XGpio_SetDataDirection( &xOutputGPIOInstance, ulGPIOOutputChannel, ucSetToOutput );\r
351 \r
352                 /* Start with all LEDs off. */\r
353                 ucGPIOState = 0U;\r
354                 XGpio_DiscreteWrite( &xOutputGPIOInstance, ulGPIOOutputChannel, ucGPIOState );\r
355         }\r
356 \r
357         /* Initialise the GPIO for the button inputs. */\r
358         if( xStatus == XST_SUCCESS )\r
359         {\r
360                 xStatus = XGpio_Initialize( &xInputGPIOInstance, XPAR_PUSH_BUTTONS_4BITS_DEVICE_ID );\r
361         }\r
362 \r
363         if( xStatus == XST_SUCCESS )\r
364         {\r
365                 /* Install the handler defined in this task for the button input. \r
366                 *NOTE* The FreeRTOS defined xPortInstallInterruptHandler() API function\r
367                 must be used for this purpose. */\r
368                 xStatus = xPortInstallInterruptHandler( XPAR_MICROBLAZE_0_INTC_PUSH_BUTTONS_4BITS_IP2INTC_IRPT_INTR, prvButtonInputInterruptHandler, NULL );\r
369 \r
370                 if( xStatus == pdPASS )\r
371                 {\r
372                         /* Set buttons to input. */\r
373                         XGpio_SetDataDirection( &xInputGPIOInstance, ulGPIOInputChannel, ~( ucSetToOutput ) );\r
374                         \r
375                         /* Enable the button input interrupts in the interrupt controller.\r
376                         *NOTE* The vPortEnableInterrupt() API function must be used for this\r
377                         purpose. */\r
378                         vPortEnableInterrupt( XPAR_MICROBLAZE_0_INTC_PUSH_BUTTONS_4BITS_IP2INTC_IRPT_INTR );\r
379 \r
380                         /* Enable GPIO channel interrupts. */\r
381                         XGpio_InterruptEnable( &xInputGPIOInstance, ulGPIOInputChannel );\r
382                         XGpio_InterruptGlobalEnable( &xInputGPIOInstance );\r
383                 }\r
384         }\r
385 \r
386         configASSERT( ( xStatus == pdPASS ) );\r
387 }\r
388 /*-----------------------------------------------------------*/\r
389 \r
390 void vApplicationMallocFailedHook( void )\r
391 {\r
392         /* vApplicationMallocFailedHook() will only be called if\r
393         configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h.  It is a hook\r
394         function that will get called if a call to pvPortMalloc() fails. \r
395         pvPortMalloc() is called internally by the kernel whenever a task, queue or\r
396         semaphore is created.  It is also called by various parts of the demo\r
397         application.  If heap_1.c or heap_2.c are used, then the size of the heap\r
398         available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in\r
399         FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used\r
400         to query the size of free heap space that remains (although it does not\r
401         provide information on how the remaining heap might be fragmented). */\r
402         taskDISABLE_INTERRUPTS();\r
403         for( ;; );\r
404 }\r
405 /*-----------------------------------------------------------*/\r
406 \r
407 void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed char *pcTaskName )\r
408 {\r
409         ( void ) pcTaskName;\r
410         ( void ) pxTask;\r
411 \r
412         /* vApplicationStackOverflowHook() will only be called if\r
413         configCHECK_FOR_STACK_OVERFLOW is set to either 1 or 2.  The handle and name\r
414         of the offending task will be passed into the hook function via its \r
415         parameters.  However, when a stack has overflowed, it is possible that the\r
416         parameters will have been corrupted, in which case the pxCurrentTCB variable\r
417         can be inspected directly. */\r
418         taskDISABLE_INTERRUPTS();\r
419         for( ;; );\r
420 }\r
421 /*-----------------------------------------------------------*/\r
422 \r
423 void vApplicationIdleHook( void )\r
424 {\r
425 volatile size_t xFreeHeapSpace;\r
426 \r
427         /* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set \r
428         to 1 in FreeRTOSConfig.h.  It will be called on each iteration of the idle \r
429         task.  It is essential that code added to this hook function never attempts \r
430         to block in any way (for example, call xQueueReceive() with a block time \r
431         specified, or call vTaskDelay()).  If the application makes use of the \r
432         vTaskDelete() API function (as this demo application does) then it is also \r
433         important that vApplicationIdleHook() is permitted to return to its calling \r
434         function, because it is the responsibility of the idle task to clean up \r
435         memory allocated by the kernel to any task that has since been deleted. */\r
436 \r
437         /* This implementation of vApplicationIdleHook() simply demonstrates how\r
438         the xPortGetFreeHeapSize() function can be used. */\r
439         xFreeHeapSpace = xPortGetFreeHeapSize();\r
440 \r
441         if( xFreeHeapSpace > 100 )\r
442         {\r
443                 /* By now, the kernel has allocated everything it is going to, so\r
444                 if there is a lot of heap remaining unallocated then\r
445                 the value of configTOTAL_HEAP_SIZE in FreeRTOSConfig.h can be\r
446                 reduced accordingly. */\r
447         }\r
448 }\r
449 /*-----------------------------------------------------------*/\r
450 \r
451 void vApplicationTickHook( void )\r
452 {\r
453         /* vApplicationTickHook() will only be called if configUSE_TICK_HOOK is set\r
454         to 1 in FreeRTOSConfig.h.  It executes from an interrupt context so must\r
455         not use any FreeRTOS API functions that do not end in ...FromISR().\r
456 \r
457         This simple blinky demo does not use the tick hook, but a tick hook is\r
458         required to be defined as the blinky and full demos share a\r
459         FreeRTOSConfig.h header file. */
460 }\r
461 /*-----------------------------------------------------------*/\r
462 \r
463 /* This is an application defined callback function used to install the tick\r
464 interrupt handler.  It is provided as an application callback because the kernel\r
465 will run on lots of different MicroBlaze and FPGA configurations - not all of\r
466 which will have the same timer peripherals defined or available.  This example\r
467 uses the AXI Timer 0.  If that is available on your hardware platform then this\r
468 example callback implementation should not require modification.   The name of\r
469 the interrupt handler that should be installed is vPortTickISR(), which the \r
470 function below declares as an extern. */\r
471 void vApplicationSetupTimerInterrupt( void )\r
472 {\r
473 portBASE_TYPE xStatus;\r
474 const unsigned char ucTimerCounterNumber = ( unsigned char ) 0U;\r
475 const unsigned long ulCounterValue = ( ( XPAR_AXI_TIMER_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );\r
476 extern void vPortTickISR( void *pvUnused );\r
477 \r
478         /* Initialise the timer/counter. */\r
479         xStatus = XTmrCtr_Initialize( &xTimer0Instance, XPAR_AXI_TIMER_0_DEVICE_ID );\r
480 \r
481         if( xStatus == XST_SUCCESS )\r
482         {\r
483                 /* Install the tick interrupt handler as the timer ISR. \r
484                 *NOTE* The xPortInstallInterruptHandler() API function must be used for\r
485                 this purpose. */\r
486                 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );\r
487         }\r
488 \r
489         if( xStatus == pdPASS )\r
490         {\r
491                 /* Enable the timer interrupt in the interrupt controller.\r
492                 *NOTE* The vPortEnableInterrupt() API function must be used for this\r
493                 purpose. */\r
494                 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );\r
495 \r
496                 /* Configure the timer interrupt handler. */\r
497                 XTmrCtr_SetHandler( &xTimer0Instance, ( void * ) vPortTickISR, NULL );\r
498 \r
499                 /* Set the correct period for the timer. */\r
500                 XTmrCtr_SetResetValue( &xTimer0Instance, ucTimerCounterNumber, ulCounterValue );\r
501 \r
502                 /* Enable the interrupts.  Auto-reload mode is used to generate a\r
503                 periodic tick.  Note that interrupts are disabled when this function is\r
504                 called, so interrupts will not start to be processed until the first\r
505                 task has started to run. */\r
506                 XTmrCtr_SetOptions( &xTimer0Instance, ucTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );\r
507 \r
508                 /* Start the timer. */\r
509                 XTmrCtr_Start( &xTimer0Instance, ucTimerCounterNumber );\r
510         }\r
511 \r
512         /* Sanity check that the function executed as expected. */\r
513         configASSERT( ( xStatus == pdPASS ) );\r
514 }\r
515 /*-----------------------------------------------------------*/\r
516 \r
517 /* This is an application defined callback function used to clear whichever\r
518 interrupt was installed by the the vApplicationSetupTimerInterrupt() callback\r
519 function - in this case the interrupt generated by the AXI timer.  It is \r
520 provided as an application callback because the kernel will run on lots of \r
521 different MicroBlaze and FPGA configurations - not all of which will have the \r
522 same timer peripherals defined or available.  This example uses the AXI Timer 0.  \r
523 If that is available on your hardware platform then this example callback \r
524 implementation should not require modification provided the example definition\r
525 of vApplicationSetupTimerInterrupt() is also not modified. */\r
526 void vApplicationClearTimerInterrupt( void )\r
527 {\r
528 unsigned long ulCSR;\r
529 \r
530         /* Clear the timer interrupt */\r
531         ulCSR = XTmrCtr_GetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0 );\r
532         XTmrCtr_SetControlStatusReg( XPAR_AXI_TIMER_0_BASEADDR, 0, ulCSR );\r
533 }\r
534 /*-----------------------------------------------------------*/\r
535 \r