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