2 FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd.
\r
5 VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
\r
7 ***************************************************************************
\r
9 * FreeRTOS provides completely free yet professionally developed, *
\r
10 * robust, strictly quality controlled, supported, and cross *
\r
11 * platform software that has become a de facto standard. *
\r
13 * Help yourself get started quickly and support the FreeRTOS *
\r
14 * project by purchasing a FreeRTOS tutorial book, reference *
\r
15 * manual, or both from: http://www.FreeRTOS.org/Documentation *
\r
19 ***************************************************************************
\r
21 This file is part of the FreeRTOS distribution.
\r
23 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
24 the terms of the GNU General Public License (version 2) as published by the
\r
25 Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
\r
27 >>! NOTE: The modification to the GPL is included to allow you to distribute
\r
28 >>! a combined work that includes FreeRTOS without being obliged to provide
\r
29 >>! the source code for proprietary components outside of the FreeRTOS
\r
32 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
\r
33 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
\r
34 FOR A PARTICULAR PURPOSE. Full license text is available from the following
\r
35 link: http://www.freertos.org/a00114.html
\r
39 ***************************************************************************
\r
41 * Having a problem? Start by reading the FAQ "My application does *
\r
42 * not run, what could be wrong?" *
\r
44 * http://www.FreeRTOS.org/FAQHelp.html *
\r
46 ***************************************************************************
\r
48 http://www.FreeRTOS.org - Documentation, books, training, latest versions,
\r
49 license and Real Time Engineers Ltd. contact details.
\r
51 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
52 including FreeRTOS+Trace - an indispensable productivity tool, a DOS
\r
53 compatible FAT file system, and our tiny thread aware UDP/IP stack.
\r
55 http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
\r
56 Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
\r
57 licenses offer ticketed support, indemnification and middleware.
\r
59 http://www.SafeRTOS.com - High Integrity Systems also provide a safety
\r
60 engineered and independently SIL3 certified version for use in safety and
\r
61 mission critical applications that require provable dependability.
\r
66 /*-----------------------------------------------------------
\r
67 * Implementation of functions defined in portable.h for the PPC440 port.
\r
68 *----------------------------------------------------------*/
\r
71 /* Scheduler includes. */
\r
72 #include "FreeRTOS.h"
\r
75 /* Library includes. */
\r
76 #include "xtime_l.h"
\r
78 #include "xintc_i.h"
\r
80 /*-----------------------------------------------------------*/
\r
82 /* Definitions to set the initial MSR of each task. */
\r
83 #define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 17UL )
\r
84 #define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL )
\r
85 #define portMACHINE_CHECK_ENABLE ( 1UL << 12UL )
\r
87 #if configUSE_FPU == 1
\r
88 #define portAPU_PRESENT ( 1UL << 25UL )
\r
89 #define portFCM_FPU_PRESENT ( 1UL << 13UL )
\r
91 #define portAPU_PRESENT ( 0UL )
\r
92 #define portFCM_FPU_PRESENT ( 0UL )
\r
95 #define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT )
\r
98 extern const unsigned _SDA_BASE_;
\r
99 extern const unsigned _SDA2_BASE_;
\r
101 /*-----------------------------------------------------------*/
\r
104 * Setup the system timer to generate the tick interrupt.
\r
106 static void prvSetupTimerInterrupt( void );
\r
109 * The handler for the tick interrupt - defined in portasm.s.
\r
111 extern void vPortTickISR( void );
\r
114 * The handler for the yield function - defined in portasm.s.
\r
116 extern void vPortYield( void );
\r
119 * Function to start the scheduler running by starting the highest
\r
120 * priority task that has thus far been created.
\r
122 extern void vPortStartFirstTask( void );
\r
124 /*-----------------------------------------------------------*/
\r
126 /* Structure used to hold the state of the interrupt controller. */
\r
127 static XIntc xInterruptController;
\r
129 /*-----------------------------------------------------------*/
\r
132 * Initialise the stack of a task to look exactly as if the task had been
\r
135 * See the header file portable.h.
\r
137 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
139 /* Place a known value at the bottom of the stack for debugging. */
\r
140 *pxTopOfStack = 0xDEADBEEF;
\r
143 /* EABI stack frame. */
\r
144 pxTopOfStack -= 20; /* Previous backchain and LR, R31 to R4 inclusive. */
\r
146 /* Parameters in R13. */
\r
147 *pxTopOfStack = ( StackType_t ) &_SDA_BASE_; /* address of the first small data area */
\r
148 pxTopOfStack -= 10;
\r
150 /* Parameters in R3. */
\r
151 *pxTopOfStack = ( StackType_t ) pvParameters;
\r
154 /* Parameters in R2. */
\r
155 *pxTopOfStack = ( StackType_t ) &_SDA2_BASE_; /* address of the second small data area */
\r
158 /* R1 is the stack pointer so is omitted. */
\r
160 *pxTopOfStack = 0x10000001UL;; /* R0. */
\r
162 *pxTopOfStack = 0x00000000UL; /* USPRG0. */
\r
164 *pxTopOfStack = 0x00000000UL; /* CR. */
\r
166 *pxTopOfStack = 0x00000000UL; /* XER. */
\r
168 *pxTopOfStack = 0x00000000UL; /* CTR. */
\r
170 *pxTopOfStack = ( StackType_t ) vPortEndScheduler; /* LR. */
\r
172 *pxTopOfStack = ( StackType_t ) pxCode; /* SRR0. */
\r
174 *pxTopOfStack = portINITIAL_MSR;/* SRR1. */
\r
176 *pxTopOfStack = ( StackType_t ) vPortEndScheduler;/* Next LR. */
\r
178 *pxTopOfStack = 0x00000000UL;/* Backchain. */
\r
180 return pxTopOfStack;
\r
182 /*-----------------------------------------------------------*/
\r
184 BaseType_t xPortStartScheduler( void )
\r
186 prvSetupTimerInterrupt();
\r
187 XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
\r
188 vPortStartFirstTask();
\r
190 /* Should not get here as the tasks are now running! */
\r
193 /*-----------------------------------------------------------*/
\r
195 void vPortEndScheduler( void )
\r
197 /* Not implemented. */
\r
200 /*-----------------------------------------------------------*/
\r
203 * Hardware initialisation to generate the RTOS tick.
\r
205 static void prvSetupTimerInterrupt( void )
\r
207 const uint32_t ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
\r
209 XTime_DECClearInterrupt();
\r
210 XTime_FITClearInterrupt();
\r
211 XTime_WDTClearInterrupt();
\r
212 XTime_WDTDisableInterrupt();
\r
213 XTime_FITDisableInterrupt();
\r
215 XExc_RegisterHandler( XEXC_ID_DEC_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 );
\r
217 XTime_DECEnableAutoReload();
\r
218 XTime_DECSetInterval( ulInterval );
\r
219 XTime_DECEnableInterrupt();
\r
221 /*-----------------------------------------------------------*/
\r
223 void vPortISRHandler( void *pvNullDoNotUse )
\r
225 uint32_t ulInterruptStatus, ulInterruptMask = 1UL;
\r
226 BaseType_t xInterruptNumber;
\r
227 XIntc_Config *pxInterruptController;
\r
228 XIntc_VectorTableEntry *pxTable;
\r
230 /* Just to remove compiler warning. */
\r
231 ( void ) pvNullDoNotUse;
\r
233 /* Get the configuration by using the device ID - in this case it is
\r
234 assumed that only one interrupt controller is being used. */
\r
235 pxInterruptController = &XIntc_ConfigTable[ XPAR_XPS_INTC_0_DEVICE_ID ];
\r
237 /* Which interrupts are pending? */
\r
238 ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );
\r
240 for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )
\r
242 if( ulInterruptStatus & 0x01UL )
\r
244 /* Clear the pending interrupt. */
\r
245 XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );
\r
247 /* Call the registered handler. */
\r
248 pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );
\r
249 pxTable->Handler( pxTable->CallBackRef );
\r
252 /* Check the next interrupt. */
\r
253 ulInterruptMask <<= 0x01UL;
\r
254 ulInterruptStatus >>= 0x01UL;
\r
256 /* Have we serviced all interrupts? */
\r
257 if( ulInterruptStatus == 0UL )
\r
263 /*-----------------------------------------------------------*/
\r
265 void vPortSetupInterruptController( void )
\r
267 extern void vPortISRWrapper( void );
\r
269 /* Perform all library calls necessary to initialise the exception table
\r
270 and interrupt controller. This assumes only one interrupt controller is in
\r
272 XExc_mDisableExceptions( XEXC_NON_CRITICAL );
\r
275 /* The library functions save the context - we then jump to a wrapper to
\r
276 save the stack into the TCB. The wrapper then calls the handler defined
\r
278 XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL );
\r
279 XIntc_Initialize( &xInterruptController, XPAR_XPS_INTC_0_DEVICE_ID );
\r
280 XIntc_Start( &xInterruptController, XIN_REAL_MODE );
\r
282 /*-----------------------------------------------------------*/
\r
284 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef )
\r
286 BaseType_t xReturn = pdFAIL;
\r
288 /* This function is defined here so the scope of xInterruptController can
\r
289 remain within this file. */
\r
291 if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )
\r
293 XIntc_Enable( &xInterruptController, ucInterruptID );
\r