]> git.sur5r.net Git - freertos/blob - FreeRTOS/Source/portable/GCC/PPC405_Xilinx/port.c
Replace standard types with stdint.h types.
[freertos] / FreeRTOS / Source / portable / GCC / PPC405_Xilinx / port.c
1 /*\r
2     FreeRTOS V7.6.0 - Copyright (C) 2013 Real Time Engineers Ltd. \r
3     All rights reserved\r
4 \r
5     VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
6 \r
7     ***************************************************************************\r
8      *                                                                       *\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
12      *                                                                       *\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
16      *                                                                       *\r
17      *    Thank you!                                                         *\r
18      *                                                                       *\r
19     ***************************************************************************\r
20 \r
21     This file is part of the FreeRTOS distribution.\r
22 \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
26 \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
30     >>! kernel.\r
31 \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
36 \r
37     1 tab == 4 spaces!\r
38 \r
39     ***************************************************************************\r
40      *                                                                       *\r
41      *    Having a problem?  Start by reading the FAQ "My application does   *\r
42      *    not run, what could be wrong?"                                     *\r
43      *                                                                       *\r
44      *    http://www.FreeRTOS.org/FAQHelp.html                               *\r
45      *                                                                       *\r
46     ***************************************************************************\r
47 \r
48     http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
49     license and Real Time Engineers Ltd. contact details.\r
50 \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
54 \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
58 \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
62 \r
63     1 tab == 4 spaces!\r
64 */\r
65 \r
66 /*-----------------------------------------------------------\r
67  * Implementation of functions defined in portable.h for the PPC405 port.\r
68  *----------------------------------------------------------*/\r
69 \r
70 \r
71 /* Scheduler includes. */\r
72 #include "FreeRTOS.h"\r
73 #include "task.h"\r
74 \r
75 /* Library includes. */\r
76 #include "xtime_l.h"\r
77 #include "xintc.h"\r
78 #include "xintc_i.h"\r
79 \r
80 /*-----------------------------------------------------------*/\r
81 \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
86 \r
87 #if configUSE_FPU == 1\r
88         #define portAPU_PRESENT                         ( 1UL << 25UL )\r
89         #define portFCM_FPU_PRESENT                     ( 1UL << 13UL )\r
90 #else\r
91         #define portAPU_PRESENT                         ( 0UL )\r
92         #define portFCM_FPU_PRESENT                     ( 0UL )\r
93 #endif\r
94 \r
95 #define portINITIAL_MSR         ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT )\r
96 \r
97 \r
98 extern const unsigned _SDA_BASE_;\r
99 extern const unsigned _SDA2_BASE_;\r
100 \r
101 /*-----------------------------------------------------------*/\r
102 \r
103 /*\r
104  * Setup the system timer to generate the tick interrupt.\r
105  */\r
106 static void prvSetupTimerInterrupt( void );\r
107 \r
108 /*\r
109  * The handler for the tick interrupt - defined in portasm.s.\r
110  */\r
111 extern void vPortTickISR( void );\r
112 \r
113 /*\r
114  * The handler for the yield function - defined in portasm.s.\r
115  */\r
116 extern void vPortYield( void );\r
117 \r
118 /*\r
119  * Function to start the scheduler running by starting the highest\r
120  * priority task that has thus far been created.\r
121  */\r
122 extern void vPortStartFirstTask( void );\r
123 \r
124 /*-----------------------------------------------------------*/\r
125 \r
126 /* Structure used to hold the state of the interrupt controller. */\r
127 static XIntc xInterruptController;\r
128 \r
129 /*-----------------------------------------------------------*/\r
130 \r
131 /* \r
132  * Initialise the stack of a task to look exactly as if the task had been\r
133  * interrupted.\r
134  * \r
135  * See the header file portable.h.\r
136  */\r
137 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )\r
138 {\r
139         /* Place a known value at the bottom of the stack for debugging. */\r
140         *pxTopOfStack = 0xDEADBEEF;\r
141         pxTopOfStack--;\r
142 \r
143         /* EABI stack frame. */\r
144         pxTopOfStack -= 20;     /* Previous backchain and LR, R31 to R4 inclusive. */\r
145 \r
146         /* Parameters in R13. */\r
147         *pxTopOfStack = ( StackType_t ) &_SDA_BASE_; /* address of the first small data area */\r
148         pxTopOfStack -= 10;\r
149 \r
150         /* Parameters in R3. */\r
151         *pxTopOfStack = ( StackType_t ) pvParameters;\r
152         pxTopOfStack--;\r
153 \r
154         /* Parameters in R2. */\r
155         *pxTopOfStack = ( StackType_t ) &_SDA2_BASE_;   /* address of the second small data area */\r
156         pxTopOfStack--;\r
157 \r
158         /* R1 is the stack pointer so is omitted. */\r
159 \r
160         *pxTopOfStack = 0x10000001UL;;  /* R0. */\r
161         pxTopOfStack--;\r
162         *pxTopOfStack = 0x00000000UL;   /* USPRG0. */\r
163         pxTopOfStack--;\r
164         *pxTopOfStack = 0x00000000UL;   /* CR. */\r
165         pxTopOfStack--;\r
166         *pxTopOfStack = 0x00000000UL;   /* XER. */\r
167         pxTopOfStack--;\r
168         *pxTopOfStack = 0x00000000UL;   /* CTR. */\r
169         pxTopOfStack--;\r
170         *pxTopOfStack = ( StackType_t ) vPortEndScheduler;      /* LR. */\r
171         pxTopOfStack--;\r
172         *pxTopOfStack = ( StackType_t ) pxCode; /* SRR0. */\r
173         pxTopOfStack--;\r
174         *pxTopOfStack = portINITIAL_MSR;/* SRR1. */\r
175         pxTopOfStack--;\r
176         *pxTopOfStack = ( StackType_t ) vPortEndScheduler;/* Next LR. */\r
177         pxTopOfStack--;\r
178         *pxTopOfStack = 0x00000000UL;/* Backchain. */\r
179 \r
180         return pxTopOfStack;\r
181 }\r
182 /*-----------------------------------------------------------*/\r
183 \r
184 BaseType_t xPortStartScheduler( void )\r
185 {\r
186         prvSetupTimerInterrupt();\r
187         XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );\r
188         vPortStartFirstTask();\r
189 \r
190         /* Should not get here as the tasks are now running! */\r
191         return pdFALSE;\r
192 }\r
193 /*-----------------------------------------------------------*/\r
194 \r
195 void vPortEndScheduler( void )\r
196 {\r
197         /* Not implemented. */\r
198         for( ;; );\r
199 }\r
200 /*-----------------------------------------------------------*/\r
201 \r
202 /*\r
203  * Hardware initialisation to generate the RTOS tick.   \r
204  */\r
205 static void prvSetupTimerInterrupt( void )\r
206 {\r
207 const uint32_t ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );\r
208 \r
209         XTime_PITClearInterrupt();\r
210         XTime_FITClearInterrupt();\r
211         XTime_WDTClearInterrupt();\r
212         XTime_WDTDisableInterrupt();\r
213         XTime_FITDisableInterrupt();\r
214 \r
215         XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 );\r
216 \r
217         XTime_PITEnableAutoReload();\r
218         XTime_PITSetInterval( ulInterval );\r
219         XTime_PITEnableInterrupt();\r
220 }\r
221 /*-----------------------------------------------------------*/\r
222 \r
223 void vPortISRHandler( void *pvNullDoNotUse )\r
224 {\r
225 uint32_t ulInterruptStatus, ulInterruptMask = 1UL;\r
226 BaseType_t xInterruptNumber;\r
227 XIntc_Config *pxInterruptController;\r
228 XIntc_VectorTableEntry *pxTable;\r
229 \r
230         /* Just to remove compiler warning. */\r
231         ( void ) pvNullDoNotUse;        \r
232 \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
236   \r
237         /* Which interrupts are pending? */\r
238         ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );\r
239   \r
240         for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )\r
241         {\r
242                 if( ulInterruptStatus & 0x01UL )\r
243                 {\r
244                         /* Clear the pending interrupt. */\r
245                         XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );\r
246 \r
247                         /* Call the registered handler. */\r
248                         pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );\r
249                         pxTable->Handler( pxTable->CallBackRef );\r
250                 }\r
251         \r
252                 /* Check the next interrupt. */\r
253                 ulInterruptMask <<= 0x01UL;\r
254                 ulInterruptStatus >>= 0x01UL;\r
255 \r
256                 /* Have we serviced all interrupts? */\r
257                 if( ulInterruptStatus == 0UL )\r
258                 {\r
259                         break;\r
260                 }\r
261         }\r
262 }\r
263 /*-----------------------------------------------------------*/\r
264 \r
265 void vPortSetupInterruptController( void )\r
266 {\r
267 extern void vPortISRWrapper( void );\r
268 \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
271         use. */\r
272         XExc_mDisableExceptions( XEXC_NON_CRITICAL );\r
273         XExc_Init();\r
274 \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
277         above. */\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
281 }\r
282 /*-----------------------------------------------------------*/\r
283 \r
284 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef )\r
285 {\r
286 BaseType_t xReturn = pdFAIL;\r
287 \r
288         /* This function is defined here so the scope of xInterruptController can\r
289         remain within this file. */\r
290 \r
291         if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )\r
292         {\r
293                 XIntc_Enable( &xInterruptController, ucInterruptID );\r
294                 xReturn = pdPASS;\r
295         }\r
296 \r
297         return xReturn;         \r
298 }\r