]> git.sur5r.net Git - freertos/blob - Source/portable/GCC/PPC405_Xilinx/port.c
Remove compiler warnings.
[freertos] / Source / portable / GCC / PPC405_Xilinx / port.c
1 /*
2         FreeRTOS.org V5.0.0 - Copyright (C) 2003-2008 Richard Barry.
3
4         This file is part of the FreeRTOS.org distribution.
5
6         FreeRTOS.org is free software; you can redistribute it and/or modify
7         it under the terms of the GNU General Public License as published by
8         the Free Software Foundation; either version 2 of the License, or
9         (at your option) any later version.
10
11         FreeRTOS.org is distributed in the hope that it will be useful,
12         but WITHOUT ANY WARRANTY; without even the implied warranty of
13         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14         GNU General Public License for more details.
15
16         You should have received a copy of the GNU General Public License
17         along with FreeRTOS.org; if not, write to the Free Software
18         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
20         A special exception to the GPL can be applied should you wish to distribute
21         a combined work that includes FreeRTOS.org, without being obliged to provide
22         the source code for any proprietary components.  See the licensing section 
23         of http://www.FreeRTOS.org for full details of how and when the exception
24         can be applied.
25
26     ***************************************************************************
27     ***************************************************************************
28     *                                                                         *
29     * SAVE TIME AND MONEY!  We can port FreeRTOS.org to your own hardware,    *
30     * and even write all or part of your application on your behalf.          *
31     * See http://www.OpenRTOS.com for details of the services we provide to   *
32     * expedite your project.                                                  *
33     *                                                                         *
34     ***************************************************************************
35     ***************************************************************************
36
37         Please ensure to read the configuration and relevant port sections of the
38         online documentation.
39
40         http://www.FreeRTOS.org - Documentation, latest information, license and 
41         contact details.
42
43         http://www.SafeRTOS.com - A version that is certified for use in safety 
44         critical systems.
45
46         http://www.OpenRTOS.com - Commercial support, development, porting, 
47         licensing and training services.
48 */
49
50 /*-----------------------------------------------------------
51  * Implementation of functions defined in portable.h for the PPC405 port.
52  *----------------------------------------------------------*/
53
54
55 /* Scheduler includes. */
56 #include "FreeRTOS.h"
57 #include "task.h"
58
59 /* Library includes. */
60 #include "xtime_l.h"
61 #include "xintc.h"
62 #include "xintc_i.h"
63
64 /*-----------------------------------------------------------*/
65
66 /* Definitions to set the initial MSR of each task. */
67 #define portCRITICAL_INTERRUPT_ENABLE   ( 1UL << 17UL )
68 #define portEXTERNAL_INTERRUPT_ENABLE   ( 1UL << 15UL )
69 #define portMACHINE_CHECK_ENABLE                ( 1UL << 12UL )
70
71 #if configUSE_FPU == 1
72         #define portAPU_PRESENT                         ( 1UL << 25UL )
73         #define portFCM_FPU_PRESENT                     ( 1UL << 13UL )
74 #else
75         #define portAPU_PRESENT                         ( 0UL )
76         #define portFCM_FPU_PRESENT                     ( 0UL )
77 #endif
78
79 #define portINITIAL_MSR         ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT )
80
81 /*-----------------------------------------------------------*/
82
83 /*
84  * Setup the system timer to generate the tick interrupt.
85  */
86 static void prvSetupTimerInterrupt( void );
87
88 /*
89  * The handler for the tick interrupt - defined in portasm.s.
90  */
91 extern void vPortTickISR( void );
92
93 /*
94  * The handler for the yield function - defined in portasm.s.
95  */
96 extern void vPortYield( void );
97
98 /*
99  * Function to start the scheduler running by starting the highest
100  * priority task that has thus far been created.
101  */
102 extern void vPortStartFirstTask( void );
103
104 /*-----------------------------------------------------------*/
105
106 /* Structure used to hold the state of the interrupt controller. */
107 static XIntc xInterruptController;
108
109 /*-----------------------------------------------------------*/
110
111 /* 
112  * Initialise the stack of a task to look exactly as if the task had been
113  * interrupted.
114  * 
115  * See the header file portable.h.
116  */
117 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
118 {
119         /* Place a known value at the bottom of the stack for debugging. */
120         *pxTopOfStack = 0xDEADBEEF;
121         pxTopOfStack--;
122
123         /* EABI stack frame. */
124         pxTopOfStack -= 30;     /* Previous backchain and LR, R31 to R4 inclusive. */
125
126         /* Parameters in R3. */
127         *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
128         pxTopOfStack--;
129         *pxTopOfStack = 0x02020202UL;   /* R2. */
130         pxTopOfStack--;
131
132         /* R1 is the stack pointer so is omitted. */
133
134         *pxTopOfStack = 0x10000001UL;;  /* R0. */
135         pxTopOfStack--;
136         *pxTopOfStack = 0x00000000UL;   /* USPRG0. */
137         pxTopOfStack--;
138         *pxTopOfStack = 0x00000000UL;   /* CR. */
139         pxTopOfStack--;
140         *pxTopOfStack = 0x00000000UL;   /* XER. */
141         pxTopOfStack--;
142         *pxTopOfStack = 0x00000000UL;   /* CTR. */
143         pxTopOfStack--;
144         *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler;   /* LR. */
145         pxTopOfStack--;
146         *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* SRR0. */
147         pxTopOfStack--;
148         *pxTopOfStack = portINITIAL_MSR;/* SRR1. */
149         pxTopOfStack--;
150         *pxTopOfStack = ( portSTACK_TYPE ) vPortEndScheduler;/* Next LR. */
151         pxTopOfStack--;
152         *pxTopOfStack = 0x00000000UL;/* Backchain. */
153
154         return pxTopOfStack;
155 }
156 /*-----------------------------------------------------------*/
157
158 portBASE_TYPE xPortStartScheduler( void )
159 {
160         prvSetupTimerInterrupt();
161         XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
162         vPortStartFirstTask();
163
164         /* Should not get here as the tasks are now running! */
165         return pdFALSE;
166 }
167 /*-----------------------------------------------------------*/
168
169 void vPortEndScheduler( void )
170 {
171         /* Not implemented. */
172         for( ;; );
173 }
174 /*-----------------------------------------------------------*/
175
176 /*
177  * Hardware initialisation to generate the RTOS tick.   
178  */
179 static void prvSetupTimerInterrupt( void )
180 {
181 const unsigned portLONG ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
182
183         XTime_PITClearInterrupt();
184         XTime_FITClearInterrupt();
185         XTime_WDTClearInterrupt();
186         XTime_WDTDisableInterrupt();
187         XTime_FITDisableInterrupt();
188
189         XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 );
190
191         XTime_PITEnableAutoReload();
192         XTime_PITSetInterval( ulInterval );
193         XTime_PITEnableInterrupt();
194 }
195 /*-----------------------------------------------------------*/
196
197 void vPortISRHandler( void *pvNullDoNotUse )
198 {
199 unsigned portLONG ulInterruptStatus, ulInterruptMask = 1UL;
200 portBASE_TYPE xInterruptNumber;
201 XIntc_Config *pxInterruptController;
202 XIntc_VectorTableEntry *pxTable;
203 \r
204         /* Just to remove compiler warning. */
205         ( void ) pvNullDoNotUse;        \r
206
207         /* Get the configuration by using the device ID - in this case it is
208         assumed that only one interrupt controller is being used. */
209         pxInterruptController = &XIntc_ConfigTable[ XPAR_XPS_INTC_0_DEVICE_ID ];
210   
211         /* Which interrupts are pending? */
212         ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );
213   
214         for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )
215         {
216                 if( ulInterruptStatus & 0x01UL )
217                 {
218                         /* Clear the pending interrupt. */
219                         XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );
220
221                         /* Call the registered handler. */
222                         pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );
223                         pxTable->Handler( pxTable->CallBackRef );
224                 }
225         
226                 /* Check the next interrupt. */
227                 ulInterruptMask <<= 0x01UL;
228                 ulInterruptStatus >>= 0x01UL;
229
230                 /* Have we serviced all interrupts? */
231                 if( ulInterruptStatus == 0UL )
232                 {
233                         break;
234                 }
235         }
236 }
237 /*-----------------------------------------------------------*/
238
239 void vPortSetupInterruptController( void )
240 {
241 extern void vPortISRWrapper( void );
242
243         /* Perform all library calls necessary to initialise the exception table
244         and interrupt controller.  This assumes only one interrupt controller is in
245         use. */
246         XExc_mDisableExceptions( XEXC_NON_CRITICAL );
247         XExc_Init();
248
249         /* The library functions save the context - we then jump to a wrapper to
250         save the stack into the TCB.  The wrapper then calls the handler defined
251         above. */
252         XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL );
253         XIntc_Initialize( &xInterruptController, XPAR_XPS_INTC_0_DEVICE_ID );
254         XIntc_Start( &xInterruptController, XIN_REAL_MODE );
255 }
256 /*-----------------------------------------------------------*/
257
258 portBASE_TYPE xPortInstallInterruptHandler( unsigned portCHAR ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef )
259 {
260 portBASE_TYPE xReturn = pdFAIL;
261
262         /* This function is defined here so the scope of xInterruptController can
263         remain within this file. */
264
265         if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )
266         {
267                 XIntc_Enable( &xInterruptController, ucInterruptID );
268                 xReturn = pdPASS;
269         }
270
271         return xReturn;         
272 }