Comment ready for release.

This commit is contained in:
Richard Barry 2008-03-06 20:55:49 +00:00
parent f39424feee
commit bf5cd55c55
3 changed files with 131 additions and 227 deletions

View file

@ -1,5 +1,5 @@
/* /*
FreeRTOS.org V4.7.1 - Copyright (C) 2003-2008 Richard Barry. FreeRTOS.org V4.7.2 - Copyright (C) 2003-2008 Richard Barry.
This file is part of the FreeRTOS.org distribution. This file is part of the FreeRTOS.org distribution.
@ -54,28 +54,47 @@
#include "xintc.h" #include "xintc.h"
#include "xintc_i.h" #include "xintc_i.h"
/* Standard includes. */ /*-----------------------------------------------------------*/
#include <string.h>
/* Definitions to set the initial MSR of each task. */
#define portCRITICAL_INTERRUPT_ENABLE ( 1UL << 17UL )
#define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL )
#define portMACHINE_CHECK_ENABLE ( 1UL << 12UL )
#define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE )
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
#define portCRITICAL_INTERRUPT_ENABLE ( 0UL << 17UL )
#define portEXTERNAL_INTERRUPT_ENABLE ( 1UL << 15UL )
#define portMACHINE_CHECK_ENABLE ( 0UL << 12UL )
#define portINITIAL_MSR ( portCRITICAL_INTERRUPT_ENABLE | portEXTERNAL_INTERRUPT_ENABLE | portMACHINE_CHECK_ENABLE )
/* /*
* Setup the system timer to generate the tick interrupt.
*/ */
static void prvSetupTimerInterrupt( void ); static void prvSetupTimerInterrupt( void );
extern void vPortTickISR( void );
extern void vPortYield( void );
extern void vPortStartFirstTask( void );
static XIntc xInterruptController;
/* /*
* Initialise the stack of a task to look exactly as if a call to * The handler for the tick interrupt - defined in portasm.s.
* portSAVE_CONTEXT had been made. */
extern void vPortTickISR( void );
/*
* The handler for the yield function - defined in portasm.s.
*/
extern void vPortYield( void );
/*
* Function to start the scheduler running by starting the highest
* priority task that has thus far been created.
*/
extern void vPortStartFirstTask( void );
/*-----------------------------------------------------------*/
/* Structure used to hold the state of the interrupt controller. */
static XIntc xInterruptController;
/*-----------------------------------------------------------*/
/*
* Initialise the stack of a task to look exactly as if the task had been
* interrupted.
* *
* See the header file portable.h. * See the header file portable.h.
*/ */
@ -165,7 +184,6 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
*pxTopOfStack = ( portSTACK_TYPE ) vPortStartFirstTask;/* Next LR. */ *pxTopOfStack = ( portSTACK_TYPE ) vPortStartFirstTask;/* Next LR. */
pxTopOfStack--; pxTopOfStack--;
*pxTopOfStack = 0x00000000UL;;/* Backchain. */ *pxTopOfStack = 0x00000000UL;;/* Backchain. */
// pxTopOfStack--;
return pxTopOfStack; return pxTopOfStack;
} }
@ -173,14 +191,8 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
portBASE_TYPE xPortStartScheduler( void ) portBASE_TYPE xPortStartScheduler( void )
{ {
extern void *pxCurrentTCB;
prvSetupTimerInterrupt(); prvSetupTimerInterrupt();
XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 ); XExc_RegisterHandler( XEXC_ID_SYSTEM_CALL, ( XExceptionHandler ) vPortYield, ( void * ) 0 );
// XExc_mEnableExceptions( XEXC_NON_CRITICAL );
vPortStartFirstTask(); vPortStartFirstTask();
/* Should not get here as the tasks are now running! */ /* Should not get here as the tasks are now running! */
@ -197,7 +209,6 @@ void vPortEndScheduler( void )
/* /*
* Hardware initialisation to generate the RTOS tick. * Hardware initialisation to generate the RTOS tick.
*/ */
static void prvTickISR( void );
static void prvSetupTimerInterrupt( void ) static void prvSetupTimerInterrupt( void )
{ {
const unsigned portLONG ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL ); const unsigned portLONG ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ ) - 1UL );
@ -216,65 +227,39 @@ const unsigned portLONG ulInterval = ( ( configCPU_CLOCK_HZ / configTICK_RATE_HZ
} }
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
static void prvTickISR( void )
{
static unsigned portLONG ulTicks = 0;
ulTicks++;
if( ulTicks >= 1000 )
{
vParTestToggleLED( 0 );
ulTicks = 0;
}
XTime_PITClearInterrupt();
}
/*-----------------------------------------------------------*/
void vPortISRHandler( void *vNullDoNotUse ) void vPortISRHandler( void *vNullDoNotUse )
{ {
Xuint32 IntrStatus; unsigned portLONG ulInterruptStatus, ulInterruptMask = 1UL;
Xuint32 IntrMask = 1; portBASE_TYPE xInterruptNumber;
int IntrNumber; XIntc_Config *pxInterruptController;
//extern XIntc xInterruptController; XIntc_VectorTableEntry *pxTable;
XIntc_Config *CfgPtr;// = xInterruptController.CfgPtr;
/* Get the configuration data using the device ID */ /* Get the configuration by using the device ID - in this case it is
//CfgPtr = &XIntc_ConfigTable[(Xuint32)DeviceId]; assumed that only one interrupt controller is being used. */
CfgPtr = &XIntc_ConfigTable[(Xuint32)XPAR_OPB_INTC_0_DEVICE_ID]; pxInterruptController = &XIntc_ConfigTable[ XPAR_OPB_INTC_0_DEVICE_ID ];
/* Get the interrupts that are waiting to be serviced */ /* Which interrupts are pending? */
IntrStatus = XIntc_mGetIntrStatus(CfgPtr->BaseAddress); ulInterruptStatus = XIntc_mGetIntrStatus( pxInterruptController->BaseAddress );
/* Service each interrupt that is active and enabled by checking each for( xInterruptNumber = 0; xInterruptNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS; xInterruptNumber++ )
* bit in the register from LSB to MSB which corresponds to an interrupt
* intput signal
*/
for (IntrNumber = 0; IntrNumber < XPAR_INTC_MAX_NUM_INTR_INPUTS;
IntrNumber++)
{ {
if (IntrStatus & 1) if( ulInterruptStatus & 0x01UL )
{ {
XIntc_VectorTableEntry *TablePtr; /* Call the registered handler. */
pxTable = &( pxInterruptController->HandlerTable[ xInterruptNumber ] );
pxTable->Handler( pxTable->CallBackRef );
/* The interrupt is active and enabled, call the interrupt /* Clear the pending interrupt. */
* handler that was setup with the specified parameter XIntc_mAckIntr( pxInterruptController->BaseAddress, ulInterruptMask );
*/
TablePtr = &(CfgPtr->HandlerTable[IntrNumber]);
TablePtr->Handler(TablePtr->CallBackRef);
/* Clear the interrupt. */
XIntc_mAckIntr(CfgPtr->BaseAddress, IntrMask);
break; break;
} }
/* Move to the next interrupt to check */ /* Check the next interrupt. */
IntrMask <<= 1; ulInterruptMask <<= 0x01UL;
IntrStatus >>= 1; ulInterruptStatus >>= 0x01UL;
/* If there are no other bits set indicating that all interrupts /* Have we serviced all interrupts? */
* have been serviced, then exit the loop if( ulInterruptStatus == 0UL )
*/
if (IntrStatus == 0)
{ {
break; break;
} }
@ -286,8 +271,15 @@ void vPortSetupInterruptController( void )
{ {
extern void vPortISRWrapper( void ); extern void vPortISRWrapper( void );
/* Perform all library calls necessary to initialise the exception table
and interrupt controller. This assumes only one interrupt controller is in
use. */
XExc_mDisableExceptions( XEXC_NON_CRITICAL ); XExc_mDisableExceptions( XEXC_NON_CRITICAL );
XExc_Init(); XExc_Init();
/* The library functions save the context - we then jump to a wrapper to
save the stack into the TCB. The wrapper then calls the handler defined
above. */
XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL ); XExc_RegisterHandler( XEXC_ID_NON_CRITICAL_INT, ( XExceptionHandler ) vPortISRWrapper, NULL );
XIntc_Initialize( &xInterruptController, XPAR_OPB_INTC_0_DEVICE_ID ); XIntc_Initialize( &xInterruptController, XPAR_OPB_INTC_0_DEVICE_ID );
XIntc_Start( &xInterruptController, XIN_REAL_MODE ); XIntc_Start( &xInterruptController, XIN_REAL_MODE );
@ -298,6 +290,9 @@ portBASE_TYPE xPortInstallInterruptHandler( unsigned portCHAR ucInterruptID, XIn
{ {
portBASE_TYPE xReturn = pdFAIL; portBASE_TYPE xReturn = pdFAIL;
/* This function is defined here so the scope of xInterruptController can
remain within this file. */
if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) ) if( XST_SUCCESS == XIntc_Connect( &xInterruptController, ucInterruptID, pxHandler, pvCallBackRef ) )
{ {
XIntc_Enable( &xInterruptController, ucInterruptID ); XIntc_Enable( &xInterruptController, ucInterruptID );

View file

@ -10,18 +10,6 @@
.global vPortTickISR .global vPortTickISR
.global vPortISRWrapper .global vPortISRWrapper
.set portCONTEXT_SIZE, 156
.set portR0_OFFSET, 152
.set portGPR_OFFSET, 32
.set portCR_OFFSET, 28
.set portXER_OFFSET, 24
.set portLR_OFFSET, 16
.set portCTR_OFFSET, 16
.set portUSPRG0_OFFSET, 12
.set portSRR0_OFFSET, 8
.set portSRR1_OFFSET, 4
.set BChainField, 0 .set BChainField, 0
.set NextLRField, BChainField + 4 .set NextLRField, BChainField + 4
.set MSRField, NextLRField + 4 .set MSRField, NextLRField + 4
@ -37,68 +25,7 @@
.set IFrameSize, r3r31Field + ( ( 31 - 3 ) + 1 ) * 4 .set IFrameSize, r3r31Field + ( ( 31 - 3 ) + 1 ) * 4
.macro portRESTORE_CONTEXT .macro portSAVE_STACK_POINTER_AND_LR
# Get the address of the TCB.
xor R0, R0, R0
addis SP, R0, pxCurrentTCB@ha
lwz SP, pxCurrentTCB@l( SP )
# Get the task stack pointer from the TCB.
lwz SP, 0( SP )
# Pop the special purpose registers
lwz R0, portSRR1_OFFSET( SP )
mtspr SRR1, R0
lwz R0, portSRR0_OFFSET( SP )
mtspr SRR0, R0
lwz R0, portUSPRG0_OFFSET( SP )
mtspr 256, R0 #USPRG0
lwz R0, portCTR_OFFSET( SP )
mtspr CTR, R0
lwz R0, portLR_OFFSET( SP )
mtspr LR, R0
lwz R0, portXER_OFFSET( SP )
mtspr XER, R0
lwz R0, portCR_OFFSET( SP )
mtcr R0
# Pop GPRs
lmw R2, portGPR_OFFSET( SP )
# Finally pop R0 and correct the stack pointer
lwz R0, portR0_OFFSET( SP )
addi R1, R1, portCONTEXT_SIZE
# Start the task running
rfi
.endm
.macro portSAVE_CONTEXT
# Make room on the stack.
subi R1, R1, portCONTEXT_SIZE
# Push R0, then the GPRs
stw R0, portR0_OFFSET( SP )
stm R2, portGPR_OFFSET( SP )
# Push the SFRs
mfcr R0
stw R0, portCR_OFFSET( SP )
mfspr R0, XER
stw R0, portXER_OFFSET( SP )
mfspr R0, LR
stw R0, portLR_OFFSET( SP )
mfspr R0, CTR
stw R0, portCTR_OFFSET( SP )
mfspr R0, 256 #USPRG0
stw R0, portUSPRG0_OFFSET( SP )
mfspr R0, SRR0
stw R0, portSRR0_OFFSET( SP )
mfspr R0, SRR1
stw R0, portSRR1_OFFSET( SP )
# Get the address of the TCB. # Get the address of the TCB.
xor R0, R0, R0 xor R0, R0, R0
@ -108,10 +35,36 @@
# Store the stack pointer into the TCB # Store the stack pointer into the TCB
stw SP, 0( R2 ) stw SP, 0( R2 )
# Save the link register
stwu R1, -24( R1 )
mflr R0
stw R31, 20( R1 )
stw R0, 28( R1 )
mr R31, r1
.endm
.macro portRESTORE_STACK_POINTER_AND_LR
# Restore the link register
lwz R11, 0( R1 )
lwz R0, 4( R11 )
mtlr R0
lwz R31, -4( R11 )
mr R1, R11
# Get the address of the TCB.
xor R0, R0, R0
addis SP, R0, pxCurrentTCB@ha
lwz SP, pxCurrentTCB@l( R1 )
# Get the task stack pointer from the TCB.
lwz SP, 0( SP )
.endm .endm
.macro int_epilogue vPortStartFirstTask:
# Get the address of the TCB. # Get the address of the TCB.
xor R0, R0, R0 xor R0, R0, R0
@ -159,68 +112,21 @@
# Remove frame from stack # Remove frame from stack
addi R1,R1,IFrameSize addi R1,R1,IFrameSize
.endm # Return into the first task
.macro portENTER_SWITCHING_ISR
# Get the address of the TCB.
xor R0, R0, R0
addis R2, R0, pxCurrentTCB@ha
lwz R2, pxCurrentTCB@l( R2 )
# Store the stack pointer into the TCB
stw SP, 0( R2 )
# Save the link register
stwu R1, -24( R1 )
mflr R0
stw R31, 20( R1 )
stw R0, 28( R1 )
mr R31, r1
.endm
.macro portEXIT_SWITCHING_ISR
# Restore the link register
lwz R11, 0( R1 )
lwz R0, 4( R11 )
mtlr R0
lwz R31, -4( R11 )
mr R1, R11
# Get the address of the TCB.
xor R0, R0, R0
addis SP, R0, pxCurrentTCB@ha
lwz SP, pxCurrentTCB@l( R1 )
# Get the task stack pointer from the TCB.
lwz SP, 0( SP )
.endm
vPortStartFirstTask:
int_epilogue
rfi rfi
#vPortStartFirstTask:
# portRESTORE_CONTEXT
# rfi
vPortYield: vPortYield:
portENTER_SWITCHING_ISR portSAVE_STACK_POINTER_AND_LR
bl vTaskSwitchContext bl vTaskSwitchContext
portEXIT_SWITCHING_ISR portRESTORE_STACK_POINTER_AND_LR
blr blr
vPortTickISR: vPortTickISR:
portENTER_SWITCHING_ISR portSAVE_STACK_POINTER_AND_LR
bl vTaskIncrementTick bl vTaskIncrementTick
#if configUSE_PREEMPTION == 1 #if configUSE_PREEMPTION == 1
bl vTaskSwitchContext bl vTaskSwitchContext
@ -230,12 +136,12 @@ vPortTickISR:
lis R0, 2048 lis R0, 2048
mttsr R0 mttsr R0
portEXIT_SWITCHING_ISR portRESTORE_STACK_POINTER_AND_LR
blr blr
vPortISRWrapper: vPortISRWrapper:
portENTER_SWITCHING_ISR portSAVE_STACK_POINTER_AND_LR
bl vPortISRHandler bl vPortISRHandler
portEXIT_SWITCHING_ISR portRESTORE_STACK_POINTER_AND_LR
blr blr

View file

@ -77,6 +77,8 @@ extern "C" {
#endif #endif
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* This port uses the critical nesting count from the TCB rather than
maintaining a separate value and then saving this value in the task stack. */
#define portCRITICAL_NESTING_IN_TCB 1 #define portCRITICAL_NESTING_IN_TCB 1
/* Interrupt control macros. */ /* Interrupt control macros. */
@ -97,6 +99,7 @@ void vTaskExitCritical( void );
void vPortYield( void ); void vPortYield( void );
#define portYIELD() asm volatile ( "SC \n\t NOP" ) #define portYIELD() asm volatile ( "SC \n\t NOP" )
#define portYIELD_FROM_ISR() vTaskSwitchContext() #define portYIELD_FROM_ISR() vTaskSwitchContext()
/*-----------------------------------------------------------*/ /*-----------------------------------------------------------*/
/* Hardware specifics. */ /* Hardware specifics. */
@ -110,7 +113,7 @@ void vPortYield( void );
#define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION_PROTO( vFunction, pvParameters ) void vFunction( void *pvParameters )
#define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters ) #define portTASK_FUNCTION( vFunction, pvParameters ) void vFunction( void *pvParameters )
/* Port specific initialisation function. */ /* Port specific interrupt handling functions. */
void vPortSetupInterruptController( void ); void vPortSetupInterruptController( void );
portBASE_TYPE xPortInstallInterruptHandler( unsigned portCHAR ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef ); portBASE_TYPE xPortInstallInterruptHandler( unsigned portCHAR ucInterruptID, XInterruptHandler pxHandler, void *pvCallBackRef );