]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/FreeRTOS_tick_config.c
Update version number in preparation for maintenance release.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo / src / FreeRTOS_tick_config.c
1 /*\r
2     FreeRTOS V9.0.1 - Copyright (C) 2017 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 XScuGic xInterruptController;   /* Interrupt controller instance */\r
82 \r
83 /*\r
84  * The application must provide a function that configures a peripheral to\r
85  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
86  * in FreeRTOSConfig.h to call the function.  This file contains a function\r
87  * that is suitable for use on the Zynq SoC.\r
88  */\r
89 void vConfigureTickInterrupt( void )\r
90 {\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         /* Ensure there is no prescale. */\r
126         XScuTimer_SetPrescaler( &xTimer, 0 );\r
127 \r
128         /* Load the timer counter register. */\r
129         XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );\r
130 \r
131         /* Start the timer counter and then wait for it to timeout a number of\r
132         times. */\r
133         XScuTimer_Start( &xTimer );\r
134 \r
135         /* Enable the interrupt for the xTimer in the interrupt controller. */\r
136         XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR );\r
137 \r
138         /* Enable the interrupt in the xTimer itself. */\r
139         vClearTickInterrupt();\r
140         XScuTimer_EnableInterrupt( &xTimer );\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 void vClearTickInterrupt( void )\r
145 {\r
146         XScuTimer_ClearInterruptStatus( &xTimer );\r
147 }\r
148 /*-----------------------------------------------------------*/\r
149 \r
150 /* This is the callback function which is called by the FreeRTOS Cortex-A port\r
151 layer in response to an interrupt.  If the function is called\r
152 vApplicationFPUSafeIRQHandler() then it is called after the floating point\r
153 registers have been saved.  If the function is called vApplicationIRQHandler()\r
154 then it will be called without first having saved the FPU registers.  See\r
155 http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html for\r
156 more information */\r
157 void vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR )\r
158 {\r
159 extern const XScuGic_Config XScuGic_ConfigTable[];\r
160 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
161 uint32_t ulInterruptID;\r
162 const XScuGic_VectorTableEntry *pxVectorEntry;\r
163 \r
164         /* Re-enable interrupts. */\r
165         __asm ( "cpsie i" );\r
166 \r
167         /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value\r
168         with 0x3FF. */\r
169         ulInterruptID = ulICCIAR & 0x3FFUL;\r
170         if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
171         {\r
172                 /* Call the function installed in the array of installed handler functions. */\r
173                 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
174                 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
175         }\r
176 }\r
177 \r
178 \r
179 \r