2 FreeRTOS V7.2.0 - Copyright (C) 2012 Real Time Engineers Ltd.
\r
5 ***************************************************************************
\r
7 * FreeRTOS tutorial books are available in pdf and paperback. *
\r
8 * Complete, revised, and edited pdf reference manuals are also *
\r
11 * Purchasing FreeRTOS documentation will not only help you, by *
\r
12 * ensuring you get running as quickly as possible and with an *
\r
13 * in-depth knowledge of how to use FreeRTOS, it will also help *
\r
14 * the FreeRTOS project to continue with its mission of providing *
\r
15 * professional grade, cross platform, de facto standard solutions *
\r
16 * for microcontrollers - completely free of charge! *
\r
18 * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *
\r
20 * Thank you for using FreeRTOS, and thank you for your support! *
\r
22 ***************************************************************************
\r
25 This file is part of the FreeRTOS distribution.
\r
27 FreeRTOS is free software; you can redistribute it and/or modify it under
\r
28 the terms of the GNU General Public License (version 2) as published by the
\r
29 Free Software Foundation AND MODIFIED BY the FreeRTOS exception.
\r
30 >>>NOTE<<< The modification to the GPL is included to allow you to
\r
31 distribute a combined work that includes FreeRTOS without being obliged to
\r
32 provide the source code for proprietary components outside of the FreeRTOS
\r
33 kernel. FreeRTOS is distributed in the hope that it will be useful, but
\r
34 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
35 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
\r
36 more details. You should have received a copy of the GNU General Public
\r
37 License and the FreeRTOS license exception along with FreeRTOS; if not it
\r
38 can be viewed here: http://www.freertos.org/a00114.html and also obtained
\r
39 by writing to Richard Barry, contact details for whom are available on the
\r
44 ***************************************************************************
\r
46 * Having a problem? Start by reading the FAQ "My application does *
\r
47 * not run, what could be wrong? *
\r
49 * http://www.FreeRTOS.org/FAQHelp.html *
\r
51 ***************************************************************************
\r
54 http://www.FreeRTOS.org - Documentation, training, latest information,
\r
55 license and contact details.
\r
57 http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
\r
58 including FreeRTOS+Trace - an indispensable productivity tool.
\r
60 Real Time Engineers ltd license FreeRTOS to High Integrity Systems, who sell
\r
61 the code with commercial support, indemnification, and middleware, under
\r
62 the OpenRTOS brand: http://www.OpenRTOS.com. High Integrity Systems also
\r
63 provide a safety engineered and independently SIL3 certified version under
\r
64 the SafeRTOS brand: http://www.SafeRTOS.com.
\r
67 /*-----------------------------------------------------------
\r
68 * Implementation of functions defined in portable.h for the PPC405 port.
\r
69 *----------------------------------------------------------*/
\r
72 /* Scheduler includes. */
\r
73 #include "FreeRTOS.h"
\r
76 /* Library includes. */
\r
77 #include "xtime_l.h"
\r
79 #include "xintc_i.h"
\r
81 /*-----------------------------------------------------------*/
\r
83 /* Definitions to set the initial MSR of each task. */
\r
84 #define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 17UL )
\r
85 #define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL )
\r
86 #define portMACHINE_CHECK_ENABLE ( 1UL << 12UL )
\r
88 #if configUSE_FPU == 1
\r
89 #define portAPU_PRESENT ( 1UL << 25UL )
\r
90 #define portFCM_FPU_PRESENT ( 1UL << 13UL )
\r
92 #define portAPU_PRESENT ( 0UL )
\r
93 #define portFCM_FPU_PRESENT ( 0UL )
\r
96 #define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT )
\r
99 extern const unsigned _SDA_BASE_;
\r
100 extern const unsigned _SDA2_BASE_;
\r
102 /*-----------------------------------------------------------*/
\r
105 * Setup the system timer to generate the tick interrupt.
\r
107 static void prvSetupTimerInterrupt( void );
\r
110 * The handler for the tick interrupt - defined in portasm.s.
\r
112 extern void vPortTickISR( void );
\r
115 * The handler for the yield function - defined in portasm.s.
\r
117 extern void vPortYield( void );
\r
120 * Function to start the scheduler running by starting the highest
\r
121 * priority task that has thus far been created.
\r
123 extern void vPortStartFirstTask( void );
\r
125 /*-----------------------------------------------------------*/
\r
127 /* Structure used to hold the state of the interrupt controller. */
\r
128 static XIntc xInterruptController;
\r
130 /*-----------------------------------------------------------*/
\r
133 * Initialise the stack of a task to look exactly as if the task had been
\r
136 * See the header file portable.h.
\r
138 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
140 /* Place a known value at the bottom of the stack for debugging. */
\r
141 *pxTopOfStack = 0xDEADBEEF;
\r
144 /* EABI stack frame. */
\r
145 pxTopOfStack -= 20; /* Previous backchain and LR, R31 to R4 inclusive. */
\r
147 /* Parameters in R13. */
\r
148 *pxTopOfStack = ( portSTACK_TYPE ) &_SDA_BASE_; /* address of the first small data area */
\r
149 pxTopOfStack -= 10;
\r
151 /* Parameters in R3. */
\r
152 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
\r
155 /* Parameters in R2. */
\r
156 *pxTopOfStack = ( portSTACK_TYPE ) &_SDA2_BASE_; /* address of the second small data area */
\r
159 /* R1 is the stack pointer so is omitted. */
\r
161 *pxTopOfStack = 0x10000001UL;; /* R0. */
\r
163 *pxTopOfStack = 0x00000000UL; /* USPRG0. */
\r
165 *pxTopOfStack = 0x00000000UL; /* CR. */
\r
167 *pxTopOfStack = 0x00000000UL; /* XER. */
\r
169 *pxTopOfStack = 0x00000000UL; /* CTR. */
\r
171 *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler; /* LR. */
\r
173 *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* SRR0. */
\r
175 *pxTopOfStack = portINITIAL_MSR;/* SRR1. */
\r
177 *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler;/* Next LR. */
\r
179 *pxTopOfStack = 0x00000000UL;/* Backchain. */
\r
181 return pxTopOfStack;
\r
183 /*-----------------------------------------------------------*/
\r
185 portBASE_TYPE xPortStartScheduler( void )
\r
187 prvSetupTimerInterrupt();
\r
188 XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
\r
189 vPortStartFirstTask();
\r
191 /* Should not get here as the tasks are now running! */
\r
194 /*-----------------------------------------------------------*/
\r
196 void vPortEndScheduler( void )
\r
198 /* Not implemented. */
\r
201 /*-----------------------------------------------------------*/
\r
204 * Hardware initialisation to generate the RTOS tick.
\r
206 static void prvSetupTimerInterrupt( void )
\r
208 const unsigned long ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
\r
210 XTime_PITClearInterrupt();
\r
211 XTime_FITClearInterrupt();
\r
212 XTime_WDTClearInterrupt();
\r
213 XTime_WDTDisableInterrupt();
\r
214 XTime_FITDisableInterrupt();
\r
216 XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 );
\r
218 XTime_PITEnableAutoReload();
\r
219 XTime_PITSetInterval( ulInterval );
\r
220 XTime_PITEnableInterrupt();
\r
222 /*-----------------------------------------------------------*/
\r
224 void vPortISRHandler( void *pvNullDoNotUse )
\r
226 unsigned long ulInterruptStatus, ulInterruptMask = 1UL;
\r
227 portBASE_TYPE xInterruptNumber;
\r
228 XIntc_Config *pxInterruptController;
\r
229 XIntc_VectorTableEntry *pxTable;
\r
231 /* Just to remove compiler warning. */
\r
232 ( void ) pvNullDoNotUse;
\r
234 /* Get the configuration by using the device ID - in this case it is
\r
235 assumed that only one interrupt controller is being used. */
\r
236 pxInterruptController = &XIntc_ConfigTable[ XPAR_XPS_INTC_0_DEVICE_ID ];
\r
238 /* Which interrupts are pending? */
\r
239 ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );
\r
241 for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )
\r
243 if( ulInterruptStatus & 0x01UL )
\r
245 /* Clear the pending interrupt. */
\r
246 XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );
\r
248 /* Call the registered handler. */
\r
249 pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );
\r
250 pxTable->Handler( pxTable->CallBackRef );
\r
253 /* Check the next interrupt. */
\r
254 ulInterruptMask <<= 0x01UL;
\r
255 ulInterruptStatus >>= 0x01UL;
\r
257 /* Have we serviced all interrupts? */
\r
258 if( ulInterruptStatus == 0UL )
\r
264 /*-----------------------------------------------------------*/
\r
266 void vPortSetupInterruptController( void )
\r
268 extern void vPortISRWrapper( void );
\r
270 /* Perform all library calls necessary to initialise the exception table
\r
271 and interrupt controller. This assumes only one interrupt controller is in
\r
273 XExc_mDisableExceptions( XEXC_NON_CRITICAL );
\r
276 /* The library functions save the context - we then jump to a wrapper to
\r
277 save the stack into the TCB. The wrapper then calls the handler defined
\r
279 XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL );
\r
280 XIntc_Initialize( &xInterruptController, XPAR_XPS_INTC_0_DEVICE_ID );
\r
281 XIntc_Start( &xInterruptController, XIN_REAL_MODE );
\r
283 /*-----------------------------------------------------------*/
\r
285 portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef )
\r
287 portBASE_TYPE xReturn = pdFAIL;
\r
289 /* This function is defined here so the scope of xInterruptController can
\r
290 remain within this file. */
\r
292 if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )
\r
294 XIntc_Enable( &xInterruptController, ucInterruptID );
\r