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