2 FreeRTOS V6.1.1 - Copyright (C) 2011 Real Time Engineers Ltd.
\r
4 ***************************************************************************
\r
8 * + New to FreeRTOS, *
\r
9 * + Wanting to learn FreeRTOS or multitasking in general quickly *
\r
10 * + Looking for basic training, *
\r
11 * + Wanting to improve your FreeRTOS skills and productivity *
\r
13 * then take a look at the FreeRTOS books - available as PDF or paperback *
\r
15 * "Using the FreeRTOS Real Time Kernel - a Practical Guide" *
\r
16 * http://www.FreeRTOS.org/Documentation *
\r
18 * A pdf reference manual is also available. Both are usually delivered *
\r
19 * to your inbox within 20 minutes to two hours when purchased between 8am *
\r
20 * and 8pm GMT (although please allow up to 24 hours in case of *
\r
21 * exceptional circumstances). Thank you for your support! *
\r
23 ***************************************************************************
\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 exception to the GPL is included to allow you to distribute
\r
31 a combined work that includes FreeRTOS without being obliged to provide the
\r
32 source code for proprietary components outside of the FreeRTOS kernel.
\r
33 FreeRTOS is distributed in the hope that it will be useful, but WITHOUT
\r
34 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
\r
35 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 http://www.FreeRTOS.org - Documentation, latest information, license and
\r
47 http://www.SafeRTOS.com - A version that is certified for use in safety
\r
50 http://www.OpenRTOS.com - Commercial support, development, porting,
\r
51 licensing and training services.
\r
54 /*-----------------------------------------------------------
\r
55 * Implementation of functions defined in portable.h for the PPC405 port.
\r
56 *----------------------------------------------------------*/
\r
59 /* Scheduler includes. */
\r
60 #include "FreeRTOS.h"
\r
63 /* Library includes. */
\r
64 #include "xtime_l.h"
\r
66 #include "xintc_i.h"
\r
68 /*-----------------------------------------------------------*/
\r
70 /* Definitions to set the initial MSR of each task. */
\r
71 #define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 17UL )
\r
72 #define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL )
\r
73 #define portMACHINE_CHECK_ENABLE ( 1UL << 12UL )
\r
75 #if configUSE_FPU == 1
\r
76 #define portAPU_PRESENT ( 1UL << 25UL )
\r
77 #define portFCM_FPU_PRESENT ( 1UL << 13UL )
\r
79 #define portAPU_PRESENT ( 0UL )
\r
80 #define portFCM_FPU_PRESENT ( 0UL )
\r
83 #define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT )
\r
86 extern const unsigned _SDA_BASE_;
\r
87 extern const unsigned _SDA2_BASE_;
\r
89 /*-----------------------------------------------------------*/
\r
92 * Setup the system timer to generate the tick interrupt.
\r
94 static void prvSetupTimerInterrupt( void );
\r
97 * The handler for the tick interrupt - defined in portasm.s.
\r
99 extern void vPortTickISR( void );
\r
102 * The handler for the yield function - defined in portasm.s.
\r
104 extern void vPortYield( void );
\r
107 * Function to start the scheduler running by starting the highest
\r
108 * priority task that has thus far been created.
\r
110 extern void vPortStartFirstTask( void );
\r
112 /*-----------------------------------------------------------*/
\r
114 /* Structure used to hold the state of the interrupt controller. */
\r
115 static XIntc xInterruptController;
\r
117 /*-----------------------------------------------------------*/
\r
120 * Initialise the stack of a task to look exactly as if the task had been
\r
123 * See the header file portable.h.
\r
125 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
127 /* Place a known value at the bottom of the stack for debugging. */
\r
128 *pxTopOfStack = 0xDEADBEEF;
\r
131 /* EABI stack frame. */
\r
132 pxTopOfStack -= 20; /* Previous backchain and LR, R31 to R4 inclusive. */
\r
134 /* Parameters in R13. */
\r
135 *pxTopOfStack = ( portSTACK_TYPE ) &_SDA_BASE_; /* address of the first small data area */
\r
136 pxTopOfStack -= 10;
\r
138 /* Parameters in R3. */
\r
139 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
\r
142 /* Parameters in R2. */
\r
143 *pxTopOfStack = ( portSTACK_TYPE ) &_SDA2_BASE_; /* address of the second small data area */
\r
146 /* R1 is the stack pointer so is omitted. */
\r
148 *pxTopOfStack = 0x10000001UL;; /* R0. */
\r
150 *pxTopOfStack = 0x00000000UL; /* USPRG0. */
\r
152 *pxTopOfStack = 0x00000000UL; /* CR. */
\r
154 *pxTopOfStack = 0x00000000UL; /* XER. */
\r
156 *pxTopOfStack = 0x00000000UL; /* CTR. */
\r
158 *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler; /* LR. */
\r
160 *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* SRR0. */
\r
162 *pxTopOfStack = portINITIAL_MSR;/* SRR1. */
\r
164 *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler;/* Next LR. */
\r
166 *pxTopOfStack = 0x00000000UL;/* Backchain. */
\r
168 return pxTopOfStack;
\r
170 /*-----------------------------------------------------------*/
\r
172 portBASE_TYPE xPortStartScheduler( void )
\r
174 prvSetupTimerInterrupt();
\r
175 XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
\r
176 vPortStartFirstTask();
\r
178 /* Should not get here as the tasks are now running! */
\r
181 /*-----------------------------------------------------------*/
\r
183 void vPortEndScheduler( void )
\r
185 /* Not implemented. */
\r
188 /*-----------------------------------------------------------*/
\r
191 * Hardware initialisation to generate the RTOS tick.
\r
193 static void prvSetupTimerInterrupt( void )
\r
195 const unsigned long ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
\r
197 XTime_PITClearInterrupt();
\r
198 XTime_FITClearInterrupt();
\r
199 XTime_WDTClearInterrupt();
\r
200 XTime_WDTDisableInterrupt();
\r
201 XTime_FITDisableInterrupt();
\r
203 XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 );
\r
205 XTime_PITEnableAutoReload();
\r
206 XTime_PITSetInterval( ulInterval );
\r
207 XTime_PITEnableInterrupt();
\r
209 /*-----------------------------------------------------------*/
\r
211 void vPortISRHandler( void *pvNullDoNotUse )
\r
213 unsigned long ulInterruptStatus, ulInterruptMask = 1UL;
\r
214 portBASE_TYPE xInterruptNumber;
\r
215 XIntc_Config *pxInterruptController;
\r
216 XIntc_VectorTableEntry *pxTable;
\r
218 /* Just to remove compiler warning. */
\r
219 ( void ) pvNullDoNotUse;
\r
221 /* Get the configuration by using the device ID - in this case it is
\r
222 assumed that only one interrupt controller is being used. */
\r
223 pxInterruptController = &XIntc_ConfigTable[ XPAR_XPS_INTC_0_DEVICE_ID ];
\r
225 /* Which interrupts are pending? */
\r
226 ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );
\r
228 for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )
\r
230 if( ulInterruptStatus & 0x01UL )
\r
232 /* Clear the pending interrupt. */
\r
233 XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );
\r
235 /* Call the registered handler. */
\r
236 pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );
\r
237 pxTable->Handler( pxTable->CallBackRef );
\r
240 /* Check the next interrupt. */
\r
241 ulInterruptMask <<= 0x01UL;
\r
242 ulInterruptStatus >>= 0x01UL;
\r
244 /* Have we serviced all interrupts? */
\r
245 if( ulInterruptStatus == 0UL )
\r
251 /*-----------------------------------------------------------*/
\r
253 void vPortSetupInterruptController( void )
\r
255 extern void vPortISRWrapper( void );
\r
257 /* Perform all library calls necessary to initialise the exception table
\r
258 and interrupt controller. This assumes only one interrupt controller is in
\r
260 XExc_mDisableExceptions( XEXC_NON_CRITICAL );
\r
263 /* The library functions save the context - we then jump to a wrapper to
\r
264 save the stack into the TCB. The wrapper then calls the handler defined
\r
266 XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL );
\r
267 XIntc_Initialize( &xInterruptController, XPAR_XPS_INTC_0_DEVICE_ID );
\r
268 XIntc_Start( &xInterruptController, XIN_REAL_MODE );
\r
270 /*-----------------------------------------------------------*/
\r
272 portBASE_TYPE xPortInstallInterruptHandler( unsigned char ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef )
\r
274 portBASE_TYPE xReturn = pdFAIL;
\r
276 /* This function is defined here so the scope of xInterruptController can
\r
277 remain within this file. */
\r
279 if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )
\r
281 XIntc_Enable( &xInterruptController, ucInterruptID );
\r