2 FreeRTOS V8.2.1 - 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 "xscutimer.h"
\r
76 #include "xscugic.h"
\r
78 #define XSCUTIMER_CLOCK_HZ ( XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2UL )
\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
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
96 /* Timer used to generate the tick interrupt. */
\r
97 static XScuTimer xTimer;
\r
99 /* The IRQ handler, which is also aliased to the name used in standalone
\r
101 void FreeRTOS_ApplicationIRQHandler( uint32_t ulICCIAR );
\r
102 void vApplicationIRQHandler( uint32_t ulICCIAR ) __attribute__ ( ( weak, alias ("FreeRTOS_ApplicationIRQHandler") ) );
\r
104 /*-----------------------------------------------------------*/
\r
106 void FreeRTOS_SetupTickInterrupt( void )
\r
108 static XScuGic xInterruptController; /* Interrupt controller instance */
\r
109 BaseType_t xStatus;
\r
110 extern void FreeRTOS_Tick_Handler( void );
\r
111 XScuTimer_Config *pxTimerConfig;
\r
112 XScuGic_Config *pxGICConfig;
\r
113 const uint8_t ucRisingEdge = 3;
\r
115 /* This function is called with the IRQ interrupt disabled, and the IRQ
\r
116 interrupt should be left disabled. It is enabled automatically when the
\r
117 scheduler is started. */
\r
119 /* Ensure XScuGic_CfgInitialize() has been called. In this demo it has
\r
120 already been called from prvSetupHardware() in main(). */
\r
121 pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
\r
122 xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
\r
123 configASSERT( xStatus == XST_SUCCESS );
\r
124 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
126 /* The priority must be the lowest possible. */
\r
127 XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );
\r
129 /* Install the FreeRTOS tick handler. */
\r
130 xStatus = XScuGic_Connect( &xInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xTimer );
\r
131 configASSERT( xStatus == XST_SUCCESS );
\r
132 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
134 /* Initialise the timer. */
\r
135 pxTimerConfig = XScuTimer_LookupConfig( XPAR_SCUTIMER_DEVICE_ID );
\r
136 xStatus = XScuTimer_CfgInitialize( &xTimer, pxTimerConfig, pxTimerConfig->BaseAddr );
\r
137 configASSERT( xStatus == XST_SUCCESS );
\r
138 ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
\r
140 /* Enable Auto reload mode. */
\r
141 XScuTimer_EnableAutoReload( &xTimer );
\r
143 /* Ensure there is no prescale. */
\r
144 XScuTimer_SetPrescaler( &xTimer, 0 );
\r
146 /* Load the timer counter register. */
\r
147 XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );
\r
149 /* Start the timer counter and then wait for it to timeout a number of
\r
151 XScuTimer_Start( &xTimer );
\r
153 /* Enable the interrupt for the xTimer in the interrupt controller. */
\r
154 XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR );
\r
156 /* Enable the interrupt in the xTimer itself. */
\r
157 FreeRTOS_ClearTickInterrupt();
\r
158 XScuTimer_EnableInterrupt( &xTimer );
\r
160 /*-----------------------------------------------------------*/
\r
162 void FreeRTOS_ClearTickInterrupt( void )
\r
164 XScuTimer_ClearInterruptStatus( &xTimer );
\r
166 /*-----------------------------------------------------------*/
\r
168 void FreeRTOS_ApplicationIRQHandler( uint32_t ulICCIAR )
\r
170 extern const XScuGic_Config XScuGic_ConfigTable[];
\r
171 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;
\r
172 uint32_t ulInterruptID;
\r
173 const XScuGic_VectorTableEntry *pxVectorEntry;
\r
175 /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value
\r
177 ulInterruptID = ulICCIAR & 0x3FFUL;
\r
178 if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )
\r
180 /* Call the function installed in the array of installed handler functions. */
\r
181 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );
\r
182 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );
\r
185 /*-----------------------------------------------------------*/
\r
187 /* This version of vApplicationAssert() is declared as a weak symbol to allow it
\r
188 to be overridden by a version implemented within the application that is using
\r
190 void vApplicationAssert( const char *pcFileName, uint32_t ulLine )
\r
192 volatile uint32_t ul = 0;
\r
193 volatile const char *pcLocalFileName = pcFileName; /* To prevent pcFileName being optimized away. */
\r
194 volatile uint32_t ulLocalLine = ulLine; /* To prevent ulLine being optimized away. */
\r
196 /* Prevent compile warnings about the following two variables being set but
\r
197 not referenced. They are intended for viewing in the debugger. */
\r
198 ( void ) pcLocalFileName;
\r
199 ( void ) ulLocalLine;
\r
201 xil_printf( "Assert failed in file %s, line %lu\r\n", pcLocalFileName, ulLocalLine );
\r
203 /* If this function is entered then a call to configASSERT() failed in the
\r
204 FreeRTOS code because of a fatal error. The pcFileName and ulLine
\r
205 parameters hold the file name and line number in that file of the assert
\r
206 that failed. Additionally, if using the debugger, the function call stack
\r
207 can be viewed to find which line failed its configASSERT() test. Finally,
\r
208 the debugger can be used to set ul to a non-zero value, then step out of
\r
209 this function to find where the assert function was entered. */
\r
210 taskENTER_CRITICAL();
\r
214 __asm volatile( "NOP" );
\r
217 taskEXIT_CRITICAL();
\r
219 /*-----------------------------------------------------------*/
\r
221 /* This default tick hook does nothing and is declared as a weak symbol to allow
\r
222 the application writer to override this default by providing their own
\r
223 implementation in the application code. */
\r
224 void vApplicationTickHook( void )
\r
227 /*-----------------------------------------------------------*/
\r
229 /* This default idle hook does nothing and is declared as a weak symbol to allow
\r
230 the application writer to override this default by providing their own
\r
231 implementation in the application code. */
\r
232 void vApplicationIdleHook( void )
\r
235 /*-----------------------------------------------------------*/
\r
237 /* This default malloc failed hook does nothing and is declared as a weak symbol
\r
238 to allow the application writer to override this default by providing their own
\r
239 implementation in the application code. */
\r
240 void vApplicationMallocFailedHook( void )
\r
242 xil_printf( "vApplicationMallocFailedHook() called\n" );
\r
244 /*-----------------------------------------------------------*/
\r
246 /* This default stack overflow hook will stop the application for executing. It
\r
247 is declared as a weak symbol to allow the application writer to override this
\r
248 default by providing their own implementation in the application code. */
\r
249 void vApplicationStackOverflowHook( TaskHandle_t xTask, char *pcTaskName )
\r
251 /* Attempt to prevent the handle and name of the task that overflowed its stack
\r
252 from being optimised away because they are not used. */
\r
253 volatile TaskHandle_t xOverflowingTaskHandle = xTask;
\r
254 volatile char *pcOverflowingTaskName = pcTaskName;
\r
256 ( void ) xOverflowingTaskHandle;
\r
257 ( void ) pcOverflowingTaskName;
\r
259 xil_printf( "HALT: Task %s overflowed its stack.", pcOverflowingTaskName );
\r
260 portDISABLE_INTERRUPTS();
\r