]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/Xilinx_FreeRTOS_BSP/repo/bsp/freertos822_xilinx_v1_0/src/Source/portable/GCC/ARM_CA9/portZynq7000.c
Update version number to 9.0.0rc2.
[freertos] / FreeRTOS / Demo / Xilinx_FreeRTOS_BSP / repo / bsp / freertos822_xilinx_v1_0 / src / Source / portable / GCC / ARM_CA9 / portZynq7000.c
1 /*\r
2     FreeRTOS V9.0.0rc2 - Copyright (C) 2016 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 /*\r
81  * Some FreeRTOSConfig.h settings require the application writer to provide the\r
82  * implementation of a callback function that has a specific name, and a linker\r
83  * error will result if the application does not provide the required function.\r
84  * To avoid the risk of a configuration file setting resulting in a linker error\r
85  * this file provides default implementations of each callback that might be\r
86  * required.  The default implementations are declared as weak symbols to allow\r
87  * the application writer to override the default implementation by providing\r
88  * their own implementation in the application itself.\r
89  */\r
90 void vApplicationAssert( const char *pcFileName, uint32_t ulLine ) __attribute__((weak));\r
91 void vApplicationTickHook( void ) __attribute__((weak));\r
92 void vApplicationIdleHook( void ) __attribute__((weak));\r
93 void vApplicationMallocFailedHook( void ) __attribute((weak));\r
94 void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) __attribute__((weak));\r
95 \r
96 /* Timer used to generate the tick interrupt. */\r
97 static XScuTimer xTimer;\r
98 \r
99 /* The IRQ handler, which is also aliased to the name used in standalone\r
100 projects. */\r
101 void FreeRTOS_ApplicationIRQHandler( uint32_t ulICCIAR );\r
102 void vApplicationIRQHandler( uint32_t ulICCIAR ) __attribute__ ( ( weak, alias ("FreeRTOS_ApplicationIRQHandler") ) );\r
103 \r
104 /* The function that sets up the tick is declared week to allow it to be\r
105 overridden by the application. */\r
106 void FreeRTOS_SetupTickInterrupt( void )  __attribute__ ( ( weak ) );\r
107 void FreeRTOS_ClearTickInterrupt( void )  __attribute__ ( ( weak ) );\r
108 \r
109 /* The interrupt controller used when the tick interrupt is installed is made\r
110 global so the application code can use the same object.  The object must not be\r
111 used until either it has been initialised using XScuGic_CfgInitialize(), or the\r
112 scheduler has been started. */\r
113 XScuGic xFreeRTOSInterruptController;   /* Interrupt controller instance */\r
114 /*-----------------------------------------------------------*/\r
115 \r
116 void FreeRTOS_SetupTickInterrupt( void )\r
117 {\r
118 BaseType_t xStatus;\r
119 extern void FreeRTOS_Tick_Handler( void );\r
120 XScuTimer_Config *pxTimerConfig;\r
121 XScuGic_Config *pxGICConfig;\r
122 const uint8_t ucRisingEdge = 3;\r
123 \r
124         /* This function is called with the IRQ interrupt disabled, and the IRQ\r
125         interrupt should be left disabled.  It is enabled automatically when the\r
126         scheduler is started. */\r
127 \r
128         /* Ensure XScuGic_CfgInitialize() has been called.  In this demo it has\r
129         already been called from prvSetupHardware() in main(). */\r
130         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
131         xStatus = XScuGic_CfgInitialize( &xFreeRTOSInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
132         configASSERT( xStatus == XST_SUCCESS );\r
133         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
134 \r
135         /* The priority must be the lowest possible. */\r
136         XScuGic_SetPriorityTriggerType( &xFreeRTOSInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );\r
137 \r
138         /* Install the FreeRTOS tick handler. */\r
139         xStatus = XScuGic_Connect( &xFreeRTOSInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xTimer );\r
140         configASSERT( xStatus == XST_SUCCESS );\r
141         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
142 \r
143         /* Initialise the timer. */\r
144         pxTimerConfig = XScuTimer_LookupConfig( XPAR_SCUTIMER_DEVICE_ID );\r
145         xStatus = XScuTimer_CfgInitialize( &xTimer, pxTimerConfig, pxTimerConfig->BaseAddr );\r
146         configASSERT( xStatus == XST_SUCCESS );\r
147         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
148 \r
149         /* Enable Auto reload mode. */\r
150         XScuTimer_EnableAutoReload( &xTimer );\r
151 \r
152         /* Ensure there is no prescale. */\r
153         XScuTimer_SetPrescaler( &xTimer, 0 );\r
154 \r
155         /* Load the timer counter register. */\r
156         XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );\r
157 \r
158         /* Start the timer counter and then wait for it to timeout a number of\r
159         times. */\r
160         XScuTimer_Start( &xTimer );\r
161 \r
162         /* Enable the interrupt for the xTimer in the interrupt controller. */\r
163         XScuGic_Enable( &xFreeRTOSInterruptController, XPAR_SCUTIMER_INTR );\r
164 \r
165         /* Enable the interrupt in the xTimer itself. */\r
166         FreeRTOS_ClearTickInterrupt();\r
167         XScuTimer_EnableInterrupt( &xTimer );\r
168 }\r
169 /*-----------------------------------------------------------*/\r
170 \r
171 void FreeRTOS_ClearTickInterrupt( void )\r
172 {\r
173         XScuTimer_ClearInterruptStatus( &xTimer );\r
174 }\r
175 /*-----------------------------------------------------------*/\r
176 \r
177 void FreeRTOS_ApplicationIRQHandler( uint32_t ulICCIAR )\r
178 {\r
179 extern const XScuGic_Config XScuGic_ConfigTable[];\r
180 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
181 uint32_t ulInterruptID;\r
182 const XScuGic_VectorTableEntry *pxVectorEntry;\r
183 \r
184         /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value\r
185         with 0x3FF. */\r
186         ulInterruptID = ulICCIAR & 0x3FFUL;\r
187         if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
188         {\r
189                 /* Call the function installed in the array of installed handler functions. */\r
190                 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
191                 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
192         }\r
193 }\r
194 /*-----------------------------------------------------------*/\r
195 \r
196 /* This version of vApplicationAssert() is declared as a weak symbol to allow it\r
197 to be overridden by a version implemented within the application that is using\r
198 this BSP. */\r
199 void vApplicationAssert( const char *pcFileName, uint32_t ulLine )\r
200 {\r
201 volatile uint32_t ul = 0;\r
202 volatile const char *pcLocalFileName = pcFileName; /* To prevent pcFileName being optimized away. */\r
203 volatile uint32_t ulLocalLine = ulLine; /* To prevent ulLine being optimized away. */\r
204 \r
205         /* Prevent compile warnings about the following two variables being set but\r
206         not referenced.  They are intended for viewing in the debugger. */\r
207         ( void ) pcLocalFileName;\r
208         ( void ) ulLocalLine;\r
209 \r
210         xil_printf( "Assert failed in file %s, line %lu\r\n", pcLocalFileName, ulLocalLine );\r
211 \r
212         /* If this function is entered then a call to configASSERT() failed in the\r
213         FreeRTOS code because of a fatal error.  The pcFileName and ulLine\r
214         parameters hold the file name and line number in that file of the assert\r
215         that failed.  Additionally, if using the debugger, the function call stack\r
216         can be viewed to find which line failed its configASSERT() test.  Finally,\r
217         the debugger can be used to set ul to a non-zero value, then step out of\r
218         this function to find where the assert function was entered. */\r
219         taskENTER_CRITICAL();\r
220         {\r
221                 while( ul == 0 )\r
222                 {\r
223                         __asm volatile( "NOP" );\r
224                 }\r
225         }\r
226         taskEXIT_CRITICAL();\r
227 }\r
228 /*-----------------------------------------------------------*/\r
229 \r
230 /* This default tick hook does nothing and is declared as a weak symbol to allow\r
231 the application writer to override this default by providing their own\r
232 implementation in the application code. */\r
233 void vApplicationTickHook( void )\r
234 {\r
235 }\r
236 /*-----------------------------------------------------------*/\r
237 \r
238 /* This default idle hook does nothing and is declared as a weak symbol to allow\r
239 the application writer to override this default by providing their own\r
240 implementation in the application code. */\r
241 void vApplicationIdleHook( void )\r
242 {\r
243 }\r
244 /*-----------------------------------------------------------*/\r
245 \r
246 /* This default malloc failed hook does nothing and is declared as a weak symbol\r
247 to allow the application writer to override this default by providing their own\r
248 implementation in the application code. */\r
249 void vApplicationMallocFailedHook( void )\r
250 {\r
251         xil_printf( "vApplicationMallocFailedHook() called\n" );\r
252 }\r
253 /*-----------------------------------------------------------*/\r
254 \r
255 /* This default stack overflow hook will stop the application for executing.  It\r
256 is declared as a weak symbol to allow the application writer to override this\r
257 default by providing their own implementation in the application code. */\r
258 void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )\r
259 {\r
260 /* Attempt to prevent the handle and name of the task that overflowed its stack\r
261 from being optimised away because they are not used. */\r
262 volatile TaskHandle_t xOverflowingTaskHandle = xTask;\r
263 volatile char *pcOverflowingTaskName = pcTaskName;\r
264 \r
265         ( void ) xOverflowingTaskHandle;\r
266         ( void ) pcOverflowingTaskName;\r
267 \r
268         xil_printf( "HALT: Task %s overflowed its stack.", pcOverflowingTaskName );\r
269         portDISABLE_INTERRUPTS();\r
270         for( ;; );\r
271 }\r
272 \r
273 \r
274 \r
275 \r