2 FreeRTOS V9.0.0rc2 - Copyright (C) 2016 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 /* 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
116 void FreeRTOS_SetupTickInterrupt( void )
\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
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
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
135 /* The priority must be the lowest possible. */
\r
136 XScuGic_SetPriorityTriggerType( &xFreeRTOSInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );
\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
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
149 /* Enable Auto reload mode. */
\r
150 XScuTimer_EnableAutoReload( &xTimer );
\r
152 /* Ensure there is no prescale. */
\r
153 XScuTimer_SetPrescaler( &xTimer, 0 );
\r
155 /* Load the timer counter register. */
\r
156 XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );
\r
158 /* Start the timer counter and then wait for it to timeout a number of
\r
160 XScuTimer_Start( &xTimer );
\r
162 /* Enable the interrupt for the xTimer in the interrupt controller. */
\r
163 XScuGic_Enable( &xFreeRTOSInterruptController, XPAR_SCUTIMER_INTR );
\r
165 /* Enable the interrupt in the xTimer itself. */
\r
166 FreeRTOS_ClearTickInterrupt();
\r
167 XScuTimer_EnableInterrupt( &xTimer );
\r
169 /*-----------------------------------------------------------*/
\r
171 void FreeRTOS_ClearTickInterrupt( void )
\r
173 XScuTimer_ClearInterruptStatus( &xTimer );
\r
175 /*-----------------------------------------------------------*/
\r
177 void FreeRTOS_ApplicationIRQHandler( uint32_t ulICCIAR )
\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
184 /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value
\r
186 ulInterruptID = ulICCIAR & 0x3FFUL;
\r
187 if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )
\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
194 /*-----------------------------------------------------------*/
\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
199 void vApplicationAssert( const char *pcFileName, uint32_t ulLine )
\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
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
210 xil_printf( "Assert failed in file %s, line %lu\r\n", pcLocalFileName, ulLocalLine );
\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
223 __asm volatile( "NOP" );
\r
226 taskEXIT_CRITICAL();
\r
228 /*-----------------------------------------------------------*/
\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
236 /*-----------------------------------------------------------*/
\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
244 /*-----------------------------------------------------------*/
\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
251 xil_printf( "vApplicationMallocFailedHook() called\n" );
\r
253 /*-----------------------------------------------------------*/
\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
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
265 ( void ) xOverflowingTaskHandle;
\r
266 ( void ) pcOverflowingTaskName;
\r
268 xil_printf( "HALT: Task %s overflowed its stack.", pcOverflowingTaskName );
\r
269 portDISABLE_INTERRUPTS();
\r