2 FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry.
\r
4 This file is part of the FreeRTOS.org distribution.
\r
6 FreeRTOS.org is free software; you can redistribute it and/or modify
\r
7 it under the terms of the GNU General Public License as published by
\r
8 the Free Software Foundation; either version 2 of the License, or
\r
9 (at your option) any later version.
\r
11 FreeRTOS.org is distributed in the hope that it will be useful,
\r
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
14 GNU General Public License for more details.
\r
16 You should have received a copy of the GNU General Public License
\r
17 along with FreeRTOS.org; if not, write to the Free Software
\r
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
20 A special exception to the GPL can be applied should you wish to distribute
\r
21 a combined work that includes FreeRTOS.org, without being obliged to provide
\r
22 the source code for any proprietary components. See the licensing section
\r
23 of http://www.FreeRTOS.org for full details of how and when the exception
\r
26 ***************************************************************************
\r
28 Please ensure to read the configuration and relevant port sections of the
\r
29 online documentation.
\r
31 +++ http://www.FreeRTOS.org +++
\r
32 Documentation, latest information, license and contact details.
\r
34 +++ http://www.SafeRTOS.com +++
\r
35 A version that is certified for use in safety critical systems.
\r
37 +++ http://www.OpenRTOS.com +++
\r
38 Commercial support, development, porting, licensing and training services.
\r
40 ***************************************************************************
\r
43 /*-----------------------------------------------------------
\r
44 * Implementation of functions defined in portable.h for the MicroBlaze port.
\r
45 *----------------------------------------------------------*/
\r
48 /* Scheduler includes. */
\r
49 #include "FreeRTOS.h"
\r
52 /* Library includes. */
\r
53 #include "xexception_l.h"
\r
54 #include "xtime_l.h"
\r
56 /* Standard includes. */
\r
59 /*-----------------------------------------------------------*/
\r
61 #define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 14UL )
\r
62 #define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 16UL )
\r
63 #define portMACHINE_CHECK_ENABLE ( 1UL << 19UL )
\r
64 #define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE )
\r
69 static void prvSetupTimerInterrupt( void );
\r
70 extern void vStartFirstTask( void );
\r
71 /*-----------------------------------------------------------*/
\r
73 static void prvTickISR( void );
\r
74 extern void vPortYield( void );
\r
77 * Initialise the stack of a task to look exactly as if a call to
\r
78 * portSAVE_CONTEXT had been made.
\r
80 * See the header file portable.h.
\r
82 portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE pxCode, void *pvParameters )
\r
84 /* Place a known value at the bottom of the stack for debugging. */
\r
85 *pxTopOfStack = 0xDEADBEEF;
\r
88 /* EABI stack frame. */
\r
89 *pxTopOfStack = 0x31313131UL; /* R31. */
\r
91 *pxTopOfStack = 0x30303030UL; /* R30. */
\r
93 *pxTopOfStack = 0x29292929UL; /* R29. */
\r
95 *pxTopOfStack = 0x28282828UL; /* R28. */
\r
97 *pxTopOfStack = 0x27272727UL; /* R27. */
\r
99 *pxTopOfStack = 0x26262626UL; /* R26. */
\r
101 *pxTopOfStack = 0x25252525UL; /* R25. */
\r
103 *pxTopOfStack = 0x24242424UL; /* R24. */
\r
105 *pxTopOfStack = 0x23232323UL; /* R23. */
\r
107 *pxTopOfStack = 0x22222222UL; /* R22. */
\r
109 *pxTopOfStack = 0x21212121UL; /* R21. */
\r
111 *pxTopOfStack = 0x20202020UL; /* R20. */
\r
113 *pxTopOfStack = 0x19191919UL; /* R19. */
\r
115 *pxTopOfStack = 0x18181818UL; /* R18. */
\r
117 *pxTopOfStack = 0x17171717UL; /* R17. */
\r
119 *pxTopOfStack = 0x16161616UL; /* R16. */
\r
121 *pxTopOfStack = 0x15151515UL; /* R15. */
\r
123 *pxTopOfStack = 0x14141414UL; /* R14. */
\r
125 *pxTopOfStack = 0x13131313UL; /* R13. */
\r
127 *pxTopOfStack = 0x12121212UL; /* R12. */
\r
129 *pxTopOfStack = 0x11111111UL; /* R11. */
\r
131 *pxTopOfStack = 0x10101010UL; /* R10. */
\r
133 *pxTopOfStack = 0x09090909UL; /* R9. */
\r
135 *pxTopOfStack = 0x08080808UL; /* R8. */
\r
137 *pxTopOfStack = 0x07070707UL; /* R7. */
\r
139 *pxTopOfStack = 0x06060606UL; /* R6. */
\r
141 *pxTopOfStack = 0x05050505UL; /* R5. */
\r
143 *pxTopOfStack = 0x04040404UL; /* R4. */
\r
145 *pxTopOfStack = ( portSTACK_TYPE ) pvParameters;
\r
147 *pxTopOfStack = 0x02020202UL; /* R2. */
\r
149 *pxTopOfStack = 0x10000001UL;; /* R0. */
\r
151 *pxTopOfStack = 0x00000000UL; /* USPRG0. */
\r
153 *pxTopOfStack = 0x00000000UL; /* CR. */
\r
155 *pxTopOfStack = 0x00000000UL; /* XER. */
\r
157 *pxTopOfStack = 0x00000000UL; /* CTR. */
\r
159 *pxTopOfStack = ( portSTACK_TYPE ) vStartFirstTask; /* LR. */
\r
161 *pxTopOfStack = ( portSTACK_TYPE ) pxCode; /* SRR0. */
\r
163 *pxTopOfStack = portINITIAL_MSR;/* SRR1. */
\r
165 *pxTopOfStack = 0x00000000UL;/* Next LR. */
\r
167 *pxTopOfStack = portINITIAL_MSR;/* Backchain. */
\r
170 return pxTopOfStack;
\r
172 /*-----------------------------------------------------------*/
\r
174 portBASE_TYPE xPortStartScheduler( void )
\r
176 extern void *pxCurrentTCB;
\r
179 XExc_mDisableExceptions( XEXC_NON_CRITICAL ) ;
\r
181 // prvSetupTimerInterrupt();
\r
182 XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
\r
183 XExc_mEnableExceptions( XEXC_NON_CRITICAL ) ;
\r
187 /* Should not get here as the tasks are now running! */
\r
190 /*-----------------------------------------------------------*/
\r
192 void vPortEndScheduler( void )
\r
194 /* Not implemented. */
\r
196 /*-----------------------------------------------------------*/
\r
199 * Hardware initialisation to generate the RTOS tick.
\r
201 static void prvSetupTimerInterrupt( void )
\r
203 const unsigned portLONG ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
\r
205 XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) prvTickISR, ( void * ) 0 );
\r
207 XTime_PITEnableAutoReload();
\r
208 XTime_PITSetInterval( ulInterval );
\r
209 XTime_PITEnableInterrupt();
\r
211 /*-----------------------------------------------------------*/
\r
213 static void prvTickISR( void )
\r
215 static unsigned portLONG ulTicks = 0;
\r
218 if( ulTicks >= 1000 )
\r
220 vParTestToggleLED( 0 );
\r
223 XTime_PITClearInterrupt();
\r
225 #if configUSE_PREEMPTION == 1
\r
228 /*-----------------------------------------------------------*/
\r