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