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 "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 /* 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
109 /*-----------------------------------------------------------*/
\r
111 void FreeRTOS_SetupTickInterrupt( void )
\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
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
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
131 /* The priority must be the lowest possible. */
\r
132 XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );
\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
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
145 /* Enable Auto reload mode. */
\r
146 XScuTimer_EnableAutoReload( &xTimer );
\r
148 /* Ensure there is no prescale. */
\r
149 XScuTimer_SetPrescaler( &xTimer, 0 );
\r
151 /* Load the timer counter register. */
\r
152 XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );
\r
154 /* Start the timer counter and then wait for it to timeout a number of
\r
156 XScuTimer_Start( &xTimer );
\r
158 /* Enable the interrupt for the xTimer in the interrupt controller. */
\r
159 XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR );
\r
161 /* Enable the interrupt in the xTimer itself. */
\r
162 FreeRTOS_ClearTickInterrupt();
\r
163 XScuTimer_EnableInterrupt( &xTimer );
\r
165 /*-----------------------------------------------------------*/
\r
167 void FreeRTOS_ClearTickInterrupt( void )
\r
169 XScuTimer_ClearInterruptStatus( &xTimer );
\r
171 /*-----------------------------------------------------------*/
\r
173 void FreeRTOS_ApplicationIRQHandler( uint32_t ulICCIAR )
\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
180 /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value
\r
182 ulInterruptID = ulICCIAR & 0x3FFUL;
\r
183 if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )
\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
190 /*-----------------------------------------------------------*/
\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
195 void vApplicationAssert( const char *pcFileName, uint32_t ulLine )
\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
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
206 xil_printf( "Assert failed in file %s, line %lu\r\n", pcLocalFileName, ulLocalLine );
\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
219 __asm volatile( "NOP" );
\r
222 taskEXIT_CRITICAL();
\r
224 /*-----------------------------------------------------------*/
\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
232 /*-----------------------------------------------------------*/
\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
240 /*-----------------------------------------------------------*/
\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
247 xil_printf( "vApplicationMallocFailedHook() called\n" );
\r
249 /*-----------------------------------------------------------*/
\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
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
261 ( void ) xOverflowingTaskHandle;
\r
262 ( void ) pcOverflowingTaskName;
\r
264 xil_printf( "HALT: Task %s overflowed its stack.", pcOverflowingTaskName );
\r
265 portDISABLE_INTERRUPTS();
\r