2 FreeRTOS V8.2.2 - Copyright (C) 2015 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 This file is part of the FreeRTOS distribution.
\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
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
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
25 ***************************************************************************
\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
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
37 ***************************************************************************
\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
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
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
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
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
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
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
70 /* FreeRTOS includes. */
\r
71 #include "FreeRTOS.h"
\r
74 /* Xilinx includes. */
\r
75 #include "xil_printf.h"
\r
76 #include "xparameters.h"
\r
78 #if defined( XPAR_XTMRCTR_NUM_INSTANCES )
\r
79 #if( XPAR_XTMRCTR_NUM_INSTANCES > 0 )
\r
80 #include "xtmrctr.h"
\r
81 /* The timer is used to generate the RTOS tick interrupt. */
\r
82 static XTmrCtr xTickTimerInstance;
\r
87 * Some FreeRTOSConfig.h settings require the application writer to provide the
\r
88 * implementation of a callback function that has a specific name, and a linker
\r
89 * error will result if the application does not provide the required function.
\r
90 * To avoid the risk of a configuration file setting resulting in a linker error
\r
91 * this file provides default implementations of each callback that might be
\r
92 * required. The default implementations are declared as weak symbols to allow
\r
93 * the application writer to override the default implementation by providing
\r
94 * their own implementation in the application itself.
\r
96 void vApplicationAssert( const char *pcFileName, uint32_t ulLine ) __attribute__((weak));
\r
97 void vApplicationTickHook( void ) __attribute__((weak));
\r
98 void vApplicationIdleHook( void ) __attribute__((weak));
\r
99 void vApplicationMallocFailedHook( void ) __attribute((weak));
\r
100 void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName ) __attribute__((weak));
\r
101 void vApplicationSetupTimerInterrupt( void ) __attribute__((weak));
\r
102 void vApplicationClearTimerInterrupt( void ) __attribute__((weak));
\r
104 /*-----------------------------------------------------------*/
\r
107 /* This version of vApplicationAssert() is declared as a weak symbol to allow it
\r
108 to be overridden by a version implemented within the application that is using
\r
110 void vApplicationAssert( const char *pcFileName, uint32_t ulLine )
\r
112 volatile uint32_t ul = 0;
\r
113 volatile const char *pcLocalFileName = pcFileName; /* To prevent pcFileName being optimized away. */
\r
114 volatile uint32_t ulLocalLine = ulLine; /* To prevent ulLine being optimized away. */
\r
116 /* Prevent compile warnings about the following two variables being set but
\r
117 not referenced. They are intended for viewing in the debugger. */
\r
118 ( void ) pcLocalFileName;
\r
119 ( void ) ulLocalLine;
\r
121 xil_printf( "Assert failed in file %s, line %lu\r\n", pcLocalFileName, ulLocalLine );
\r
123 /* If this function is entered then a call to configASSERT() failed in the
\r
124 FreeRTOS code because of a fatal error. The pcFileName and ulLine
\r
125 parameters hold the file name and line number in that file of the assert
\r
126 that failed. Additionally, if using the debugger, the function call stack
\r
127 can be viewed to find which line failed its configASSERT() test. Finally,
\r
128 the debugger can be used to set ul to a non-zero value, then step out of
\r
129 this function to find where the assert function was entered. */
\r
130 taskENTER_CRITICAL();
\r
134 __asm volatile( "NOP" );
\r
137 taskEXIT_CRITICAL();
\r
139 /*-----------------------------------------------------------*/
\r
141 /* This default tick hook does nothing and is declared as a weak symbol to allow
\r
142 the application writer to override this default by providing their own
\r
143 implementation in the application code. */
\r
144 void vApplicationTickHook( void )
\r
147 /*-----------------------------------------------------------*/
\r
149 /* This default idle hook does nothing and is declared as a weak symbol to allow
\r
150 the application writer to override this default by providing their own
\r
151 implementation in the application code. */
\r
152 void vApplicationIdleHook( void )
\r
155 /*-----------------------------------------------------------*/
\r
157 /* This default malloc failed hook does nothing and is declared as a weak symbol
\r
158 to allow the application writer to override this default by providing their own
\r
159 implementation in the application code. */
\r
160 void vApplicationMallocFailedHook( void )
\r
162 xil_printf( "vApplicationMallocFailedHook() called\n" );
\r
164 /*-----------------------------------------------------------*/
\r
166 /* This default stack overflow hook will stop the application for executing. It
\r
167 is declared as a weak symbol to allow the application writer to override this
\r
168 default by providing their own implementation in the application code. */
\r
169 void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
\r
171 /* Attempt to prevent the handle and name of the task that overflowed its stack
\r
172 from being optimised away because they are not used. */
\r
173 volatile TaskHandle_t xOverflowingTaskHandle = xTask;
\r
174 volatile char *pcOverflowingTaskName = pcTaskName;
\r
176 ( void ) xOverflowingTaskHandle;
\r
177 ( void ) pcOverflowingTaskName;
\r
179 xil_printf( "HALT: Task %s overflowed its stack.", pcOverflowingTaskName );
\r
180 portDISABLE_INTERRUPTS();
\r
183 /*-----------------------------------------------------------*/
\r
185 #if defined( XPAR_XTMRCTR_NUM_INSTANCES )
\r
186 #if( XPAR_XTMRCTR_NUM_INSTANCES > 0 )
\r
187 /* This is a default implementation of what is otherwise an application defined
\r
188 callback function used to install the tick interrupt handler. It is provided as
\r
189 an application callback because the kernel will run on lots of different
\r
190 MicroBlaze and FPGA configurations - not all of which will have the same timer
\r
191 peripherals defined or available. vApplicationSetupTimerInterrupt() is declared
\r
192 as a weak symbol, allowing the application writer to provide their own
\r
193 implementation, if this default implementation is not suitable. */
\r
194 void vApplicationSetupTimerInterrupt( void )
\r
196 portBASE_TYPE xStatus;
\r
197 const unsigned char ucTickTimerCounterNumber = ( unsigned char ) 0U;
\r
198 const unsigned char ucRunTimeStatsCounterNumber = ( unsigned char ) 1U;
\r
199 const unsigned long ulCounterValue = ( ( XPAR_TMRCTR_0_CLOCK_FREQ_HZ / configTICK_RATE_HZ ) - 1UL );
\r
200 extern void vPortTickISR( void *pvUnused );
\r
202 /* Initialise the timer/counter. */
\r
203 xStatus = XTmrCtr_Initialize( &xTickTimerInstance, XPAR_TMRCTR_0_DEVICE_ID );
\r
205 if( xStatus == XST_SUCCESS )
\r
207 /* Install the tick interrupt handler as the timer ISR.
\r
208 *NOTE* The xPortInstallInterruptHandler() API function must be used for
\r
210 xStatus = xPortInstallInterruptHandler( XPAR_INTC_0_TMRCTR_0_VEC_ID, vPortTickISR, NULL );
\r
213 if( xStatus == pdPASS )
\r
215 /* Enable the timer interrupt in the interrupt controller.
\r
216 *NOTE* The vPortEnableInterrupt() API function must be used for this
\r
218 vPortEnableInterrupt( XPAR_INTC_0_TMRCTR_0_VEC_ID );
\r
220 /* Configure the timer interrupt handler. This installs the handler
\r
221 directly, rather than through the Xilinx driver. This is done for
\r
223 XTmrCtr_SetHandler( &xTickTimerInstance, ( void * ) vPortTickISR, NULL );
\r
225 /* Set the correct period for the timer. */
\r
226 XTmrCtr_SetResetValue( &xTickTimerInstance, ucTickTimerCounterNumber, ulCounterValue );
\r
228 /* Enable the interrupts. Auto-reload mode is used to generate a
\r
229 periodic tick. Note that interrupts are disabled when this function is
\r
230 called, so interrupts will not start to be processed until the first
\r
231 task has started to run. */
\r
232 XTmrCtr_SetOptions( &xTickTimerInstance, ucTickTimerCounterNumber, ( XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION | XTC_DOWN_COUNT_OPTION ) );
\r
234 /* Start the timer. */
\r
235 XTmrCtr_Start( &xTickTimerInstance, ucTickTimerCounterNumber );
\r
240 /* The second timer is used as the time base for the run time stats.
\r
241 Auto-reload mode is used to ensure the timer does not stop. */
\r
242 XTmrCtr_SetOptions( &xTickTimerInstance, ucRunTimeStatsCounterNumber, XTC_AUTO_RELOAD_OPTION );
\r
244 /* Start the timer. */
\r
245 XTmrCtr_Start( &xTickTimerInstance, ucRunTimeStatsCounterNumber );
\r
248 /* Sanity check that the function executed as expected. */
\r
249 configASSERT( ( xStatus == pdPASS ) );
\r
251 #endif /* XPAR_XTMRCTR_NUM_INSTANCES > 0 */
\r
252 #endif /* XPAR_XTMRCTR_NUM_INSTANCES */
\r
253 /*-----------------------------------------------------------*/
\r
255 #if defined( XPAR_XTMRCTR_NUM_INSTANCES )
\r
256 #if( XPAR_XTMRCTR_NUM_INSTANCES > 0 )
\r
257 /* This is a default implementation of what is otherwise an application defined
\r
258 callback function used to clear whichever timer interrupt is used to generate
\r
259 the tick interrupt. It is provided as an application callback because the
\r
260 kernel will run on lots of different MicroBlaze and FPGA configurations - not
\r
261 all of which will have the same timer peripherals defined or available.
\r
262 vApplicationSetupTimerInterrupt() is declared as a weak symbol, allowing the
\r
263 application writer to provide their own implementation, if this default
\r
264 implementation is not suitable. */
\r
265 void vApplicationClearTimerInterrupt( void )
\r
267 unsigned long ulCSR;
\r
269 /* Clear the timer interrupt */
\r
270 ulCSR = XTmrCtr_GetControlStatusReg( XPAR_TMRCTR_0_BASEADDR, 0 );
\r
271 XTmrCtr_SetControlStatusReg( XPAR_TMRCTR_0_BASEADDR, 0, ulCSR );
\r
273 #endif /* XPAR_XTMRCTR_NUM_INSTANCES > 0 */
\r
274 #endif /* XPAR_XTMRCTR_NUM_INSTANCES */
\r