]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/FreeRTOS_tick_config.c
3d495516935e01a065b1d24fc461a5cce63bdc0c
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo / src / FreeRTOS_tick_config.c
1 /*\r
2     FreeRTOS V8.2.0 - Copyright (C) 2015 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     This file is part of the FreeRTOS distribution.\r
8 \r
9     FreeRTOS is free software; you can redistribute it and/or modify it under\r
10     the terms of the GNU General Public License (version 2) as published by the\r
11     Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.\r
12 \r
13         ***************************************************************************\r
14     >>!   NOTE: The modification to the GPL is included to allow you to     !<<\r
15     >>!   distribute a combined work that includes FreeRTOS without being   !<<\r
16     >>!   obliged to provide the source code for proprietary components     !<<\r
17     >>!   outside of the FreeRTOS kernel.                                   !<<\r
18         ***************************************************************************\r
19 \r
20     FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
21     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
22     FOR A PARTICULAR PURPOSE.  Full license text is available on the following\r
23     link: http://www.freertos.org/a00114.html\r
24 \r
25     ***************************************************************************\r
26      *                                                                       *\r
27      *    FreeRTOS provides completely free yet professionally developed,    *\r
28      *    robust, strictly quality controlled, supported, and cross          *\r
29      *    platform software that is more than just the market leader, it     *\r
30      *    is the industry's de facto standard.                               *\r
31      *                                                                       *\r
32      *    Help yourself get started quickly while simultaneously helping     *\r
33      *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
34      *    tutorial book, reference manual, or both:                          *\r
35      *    http://www.FreeRTOS.org/Documentation                              *\r
36      *                                                                       *\r
37     ***************************************************************************\r
38 \r
39     http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
40         the FAQ page "My application does not run, what could be wrong?".  Have you\r
41         defined configASSERT()?\r
42 \r
43         http://www.FreeRTOS.org/support - In return for receiving this top quality\r
44         embedded software for free we request you assist our global community by\r
45         participating in the support forum.\r
46 \r
47         http://www.FreeRTOS.org/training - Investing in training allows your team to\r
48         be as productive as possible as early as possible.  Now you can receive\r
49         FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
50         Ltd, and the world's leading authority on the world's leading RTOS.\r
51 \r
52     http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
53     including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
54     compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
55 \r
56     http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
57     Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
58 \r
59     http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
60     Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
61     licenses offer ticketed support, indemnification and commercial middleware.\r
62 \r
63     http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
64     engineered and independently SIL3 certified version for use in safety and\r
65     mission critical applications that require provable dependability.\r
66 \r
67     1 tab == 4 spaces!\r
68 */\r
69 \r
70 /* FreeRTOS includes. */\r
71 #include "FreeRTOS.h"\r
72 #include "Task.h"\r
73 \r
74 /* Xilinx includes. */\r
75 #include "xscutimer.h"\r
76 #include "xscugic.h"\r
77 \r
78 #define XSCUTIMER_CLOCK_HZ ( XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2UL )\r
79 \r
80 static XScuTimer xTimer;\r
81 \r
82 /*\r
83  * The application must provide a function that configures a peripheral to\r
84  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
85  * in FreeRTOSConfig.h to call the function.  This file contains a function\r
86  * that is suitable for use on the Zynq SoC.\r
87  */\r
88 void vConfigureTickInterrupt( void )\r
89 {\r
90 static XScuGic xInterruptController;    /* Interrupt controller instance */\r
91 BaseType_t xStatus;\r
92 extern void FreeRTOS_Tick_Handler( void );\r
93 XScuTimer_Config *pxTimerConfig;\r
94 XScuGic_Config *pxGICConfig;\r
95 const uint8_t ucRisingEdge = 3;\r
96 \r
97         /* This function is called with the IRQ interrupt disabled, and the IRQ\r
98         interrupt should be left disabled.  It is enabled automatically when the\r
99         scheduler is started. */\r
100 \r
101         /* Ensure XScuGic_CfgInitialize() has been called.  In this demo it has\r
102         already been called from prvSetupHardware() in main(). */\r
103         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
104         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
105         configASSERT( xStatus == XST_SUCCESS );\r
106         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
107 \r
108         /* The priority must be the lowest possible. */\r
109         XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );\r
110 \r
111         /* Install the FreeRTOS tick handler. */\r
112         xStatus = XScuGic_Connect( &xInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xTimer );\r
113         configASSERT( xStatus == XST_SUCCESS );\r
114         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
115 \r
116         /* Initialise the timer. */\r
117         pxTimerConfig = XScuTimer_LookupConfig( XPAR_SCUTIMER_DEVICE_ID );\r
118         xStatus = XScuTimer_CfgInitialize( &xTimer, pxTimerConfig, pxTimerConfig->BaseAddr );\r
119         configASSERT( xStatus == XST_SUCCESS );\r
120         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
121 \r
122         /* Enable Auto reload mode. */\r
123         XScuTimer_EnableAutoReload( &xTimer );\r
124 \r
125         /* Load the timer counter register. */\r
126         XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );\r
127 \r
128         /* Start the timer counter and then wait for it to timeout a number of\r
129         times. */\r
130         XScuTimer_Start( &xTimer );\r
131 \r
132         /* Enable the interrupt for the xTimer in the interrupt controller. */\r
133         XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR );\r
134 \r
135         /* Enable the interrupt in the xTimer itself. */\r
136         vClearTickInterrupt();\r
137         XScuTimer_EnableInterrupt( &xTimer );\r
138 }\r
139 /*-----------------------------------------------------------*/\r
140 \r
141 void vClearTickInterrupt( void )\r
142 {\r
143         XScuTimer_ClearInterruptStatus( &xTimer );\r
144 }\r
145 /*-----------------------------------------------------------*/\r
146 \r
147 void vApplicationIRQHandler( uint32_t ulICCIAR )\r
148 {\r
149 extern const XScuGic_Config XScuGic_ConfigTable[];\r
150 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
151 uint32_t ulInterruptID;\r
152 const XScuGic_VectorTableEntry *pxVectorEntry;\r
153 \r
154         /* Re-enable interrupts. */\r
155     __asm ( "cpsie i" );\r
156 \r
157         /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value\r
158         with 0x3FF. */\r
159         ulInterruptID = ulICCIAR & 0x3FFUL;\r
160         if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
161         {\r
162                 /* Call the function installed in the array of installed handler functions. */\r
163                 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
164                 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
165         }\r
166 }\r
167 \r
168 \r
169 \r