2 * FreeRTOS Kernel V10.1.1
\r
3 * Copyright (C) 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\r
5 * Permission is hereby granted, free of charge, to any person obtaining a copy of
\r
6 * this software and associated documentation files (the "Software"), to deal in
\r
7 * the Software without restriction, including without limitation the rights to
\r
8 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
\r
9 * the Software, and to permit persons to whom the Software is furnished to do so,
\r
10 * subject to the following conditions:
\r
12 * The above copyright notice and this permission notice shall be included in all
\r
13 * copies or substantial portions of the Software.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /*-----------------------------------------------------------
\r
29 * Implementation of functions defined in portable.h for the PPC405 port.
\r
30 *----------------------------------------------------------*/
\r
33 /* Scheduler includes. */
\r
34 #include "FreeRTOS.h"
\r
37 /* Library includes. */
\r
38 #include "xtime_l.h"
\r
40 #include "xintc_i.h"
\r
42 /*-----------------------------------------------------------*/
\r
44 /* Definitions to set the initial MSR of each task. */
\r
45 #define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 17UL )
\r
46 #define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL )
\r
47 #define portMACHINE_CHECK_ENABLE ( 1UL << 12UL )
\r
49 #if configUSE_FPU == 1
\r
50 #define portAPU_PRESENT ( 1UL << 25UL )
\r
51 #define portFCM_FPU_PRESENT ( 1UL << 13UL )
\r
53 #define portAPU_PRESENT ( 0UL )
\r
54 #define portFCM_FPU_PRESENT ( 0UL )
\r
57 #define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE | portAPU_PRESENT | portFCM_FPU_PRESENT )
\r
60 extern const unsigned _SDA_BASE_;
\r
61 extern const unsigned _SDA2_BASE_;
\r
63 /*-----------------------------------------------------------*/
\r
66 * Setup the system timer to generate the tick interrupt.
\r
68 static void prvSetupTimerInterrupt( void );
\r
71 * The handler for the tick interrupt - defined in portasm.s.
\r
73 extern void vPortTickISR( void );
\r
76 * The handler for the yield function - defined in portasm.s.
\r
78 extern void vPortYield( void );
\r
81 * Function to start the scheduler running by starting the highest
\r
82 * priority task that has thus far been created.
\r
84 extern void vPortStartFirstTask( void );
\r
86 /*-----------------------------------------------------------*/
\r
88 /* Structure used to hold the state of the interrupt controller. */
\r
89 static XIntc xInterruptController;
\r
91 /*-----------------------------------------------------------*/
\r
94 * Initialise the stack of a task to look exactly as if the task had been
\r
97 * See the header file portable.h.
\r
99 StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t pxCode, void *pvParameters )
\r
101 /* Place a known value at the bottom of the stack for debugging. */
\r
102 *pxTopOfStack = 0xDEADBEEF;
\r
105 /* EABI stack frame. */
\r
106 pxTopOfStack -= 20; /* Previous backchain and LR, R31 to R4 inclusive. */
\r
108 /* Parameters in R13. */
\r
109 *pxTopOfStack = ( StackType_t ) &_SDA_BASE_; /* address of the first small data area */
\r
110 pxTopOfStack -= 10;
\r
112 /* Parameters in R3. */
\r
113 *pxTopOfStack = ( StackType_t ) pvParameters;
\r
116 /* Parameters in R2. */
\r
117 *pxTopOfStack = ( StackType_t ) &_SDA2_BASE_; /* address of the second small data area */
\r
120 /* R1 is the stack pointer so is omitted. */
\r
122 *pxTopOfStack = 0x10000001UL;; /* R0. */
\r
124 *pxTopOfStack = 0x00000000UL; /* USPRG0. */
\r
126 *pxTopOfStack = 0x00000000UL; /* CR. */
\r
128 *pxTopOfStack = 0x00000000UL; /* XER. */
\r
130 *pxTopOfStack = 0x00000000UL; /* CTR. */
\r
132 *pxTopOfStack = ( StackType_t ) vPortEndScheduler; /* LR. */
\r
134 *pxTopOfStack = ( StackType_t ) pxCode; /* SRR0. */
\r
136 *pxTopOfStack = portINITIAL_MSR;/* SRR1. */
\r
138 *pxTopOfStack = ( StackType_t ) vPortEndScheduler;/* Next LR. */
\r
140 *pxTopOfStack = 0x00000000UL;/* Backchain. */
\r
142 return pxTopOfStack;
\r
144 /*-----------------------------------------------------------*/
\r
146 BaseType_t xPortStartScheduler( void )
\r
148 prvSetupTimerInterrupt();
\r
149 XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
\r
150 vPortStartFirstTask();
\r
152 /* Should not get here as the tasks are now running! */
\r
155 /*-----------------------------------------------------------*/
\r
157 void vPortEndScheduler( void )
\r
159 /* Not implemented. */
\r
162 /*-----------------------------------------------------------*/
\r
165 * Hardware initialisation to generate the RTOS tick.
\r
167 static void prvSetupTimerInterrupt( void )
\r
169 const uint32_t ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
\r
171 XTime_PITClearInterrupt();
\r
172 XTime_FITClearInterrupt();
\r
173 XTime_WDTClearInterrupt();
\r
174 XTime_WDTDisableInterrupt();
\r
175 XTime_FITDisableInterrupt();
\r
177 XExc_RegisterHandler( XEXC_ID_PIT_INT, ( XExceptionHandler ) vPortTickISR, ( void * ) 0 );
\r
179 XTime_PITEnableAutoReload();
\r
180 XTime_PITSetInterval( ulInterval );
\r
181 XTime_PITEnableInterrupt();
\r
183 /*-----------------------------------------------------------*/
\r
185 void vPortISRHandler( void *pvNullDoNotUse )
\r
187 uint32_t ulInterruptStatus, ulInterruptMask = 1UL;
\r
188 BaseType_t xInterruptNumber;
\r
189 XIntc_Config *pxInterruptController;
\r
190 XIntc_VectorTableEntry *pxTable;
\r
192 /* Just to remove compiler warning. */
\r
193 ( void ) pvNullDoNotUse;
\r
195 /* Get the configuration by using the device ID - in this case it is
\r
196 assumed that only one interrupt controller is being used. */
\r
197 pxInterruptController = &XIntc_ConfigTable[ XPAR_XPS_INTC_0_DEVICE_ID ];
\r
199 /* Which interrupts are pending? */
\r
200 ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );
\r
202 for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )
\r
204 if( ulInterruptStatus & 0x01UL )
\r
206 /* Clear the pending interrupt. */
\r
207 XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );
\r
209 /* Call the registered handler. */
\r
210 pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );
\r
211 pxTable->Handler( pxTable->CallBackRef );
\r
214 /* Check the next interrupt. */
\r
215 ulInterruptMask <<= 0x01UL;
\r
216 ulInterruptStatus >>= 0x01UL;
\r
218 /* Have we serviced all interrupts? */
\r
219 if( ulInterruptStatus == 0UL )
\r
225 /*-----------------------------------------------------------*/
\r
227 void vPortSetupInterruptController( void )
\r
229 extern void vPortISRWrapper( void );
\r
231 /* Perform all library calls necessary to initialise the exception table
\r
232 and interrupt controller. This assumes only one interrupt controller is in
\r
234 XExc_mDisableExceptions( XEXC_NON_CRITICAL );
\r
237 /* The library functions save the context - we then jump to a wrapper to
\r
238 save the stack into the TCB. The wrapper then calls the handler defined
\r
240 XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL );
\r
241 XIntc_Initialize( &xInterruptController, XPAR_XPS_INTC_0_DEVICE_ID );
\r
242 XIntc_Start( &xInterruptController, XIN_REAL_MODE );
\r
244 /*-----------------------------------------------------------*/
\r
246 BaseType_t xPortInstallInterruptHandler( uint8_t ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef )
\r
248 BaseType_t xReturn = pdFAIL;
\r
250 /* This function is defined here so the scope of xInterruptController can
\r
251 remain within this file. */
\r
253 if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )
\r
255 XIntc_Enable( &xInterruptController, ucInterruptID );
\r