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