@ -1,5 +1,5 @@
/*
FreeRTOS V7 .5 .3 - Copyright ( C ) 2013 Real Time Engineers Ltd .
FreeRTOS V7 .5 .3 - Copyright ( C ) 2013 Real Time Engineers Ltd .
All rights reserved
VISIT http : //www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
@ -91,23 +91,67 @@
the first task is being restored . */
# define portINITIAL_SR ( portIE_BIT | portEXL_BIT )
/*
By default port . c generates its tick interrupt from TIMER1 . The user can
override this behaviour by :
1 : Providing their own implementation of vApplicationSetupTickTimerInterrupt ( ) ,
which is the function that configures the timer . The function is defined
as a weak symbol in this file so if the same function name is used in the
application code then the version in the application code will be linked
into the application in preference to the version defined in this file .
2 : Define configTICK_INTERRUPT_VECTOR to the vector number of the timer used
to generate the tick interrupt . For example , when timer 1 is used then
configTICK_INTERRUPT_VECTOR is set to _TIMER_1_VECTOR .
configTICK_INTERRUPT_VECTOR should be defined in FreeRTOSConfig . h .
3 : Define configCLEAR_TICK_TIMER_INTERRUPT ( ) to clear the interrupt in the
timer used to generate the tick interrupt . For example , when timer 1 is
used configCLEAR_TICK_TIMER_INTERRUPT ( ) is defined to
IFS0CLR = _IFS0_T1IF_MASK .
*/
# ifndef configTICK_INTERRUPT_VECTOR
# define configTICK_INTERRUPT_VECTOR _TIMER_1_VECTOR
# define configCLEAR_TICK_TIMER_INTERRUPT() IFS0CLR = _IFS0_T1IF_MASK
# else
# ifndef configCLEAR_TICK_TIMER_INTERRUPT
# error If configTICK_INTERRUPT_VECTOR is defined in application code then configCLEAR_TICK_TIMER_INTERRUPT must also be defined in application code.
# endif
# endif
/* Records the interrupt nesting depth. This starts at one as it will be
decremented to 0 when the first task starts . */
volatile unsigned portBASE_TYPE uxInterruptNesting = 0x01 ;
/* Let the user override the pre-loading of the initial RA with the address of
prvTaskExitError ( ) in case is messes up unwinding of the stack in the
debugger - in which case configTASK_RETURN_ADDRESS can be defined as 0 ( NULL ) . */
# ifdef configTASK_RETURN_ADDRESS
# define portTASK_RETURN_ADDRESS configTASK_RETURN_ADDRESS
# else
# define portTASK_RETURN_ADDRESS prvTaskExitError
# endif
/* Stores the task stack pointer when a switch is made to use the system stack. */
unsigned portBASE_TYPE uxSavedTaskStackPointer = 0 ;
/* Set configCHECK_FOR_STACK_OVERFLOW to 3 to add ISR stack checking to task
stack checking . A problem in the ISR stack will trigger an assert , not call the
stack overflow hook function ( because the stack overflow hook is specific to a
task stack , not the ISR stack ) . */
# if( configCHECK_FOR_STACK_OVERFLOW > 2 )
/* Don't use 0xa5 as the stack fill bytes as that is used by the kernerl for
the task stacks , and so will legitimately appear in many positions within
the ISR stack . */
# define portISR_STACK_FILL_BYTE 0xee
static const unsigned char ucExpectedStackBytes [ ] = {
portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , \
portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , \
portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , \
portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , \
portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE , portISR_STACK_FILL_BYTE } ; \
# define portCHECK_ISR_STACK() configASSERT( ( memcmp( ( void * ) xISRStack, ( void * ) ucExpectedStackBytes, sizeof( ucExpectedStackBytes ) ) == 0 ) )
# else
/* Define the function away. */
# define portCHECK_ISR_STACK()
# endif /* configCHECK_FOR_STACK_OVERFLOW > 2 */
/* The stack used by interrupt service routines that cause a context switch. */
portSTACK_TYPE xISRStack [ configISR_STACK_SIZE ] = { 0 } ;
/*-----------------------------------------------------------*/
/* The top of stack value ensures there is enough space to store 6 registers on
the callers stack , as some functions seem to want to do this . */
const portSTACK_TYPE * const xISRStackTop = & ( xISRStack [ configISR_STACK_SIZE - 7 ] ) ;
/*
* Place the prototype here to ensure the interrupt vector is correctly installed .
@ -125,6 +169,27 @@ extern void __attribute__( (interrupt(ipl1), vector( configTICK_INTERRUPT_VECTOR
*/
void __attribute__ ( ( interrupt ( ipl1 ) , vector ( _CORE_SOFTWARE_0_VECTOR ) ) ) vPortYieldISR ( void ) ;
/*
* Used to catch tasks that attempt to return from their implementing function .
*/
static void prvTaskExitError ( void ) ;
/*-----------------------------------------------------------*/
/* Records the interrupt nesting depth. This is initialised to one as it is
decremented to 0 when the first task starts . */
volatile unsigned portBASE_TYPE uxInterruptNesting = 0x01 ;
/* Stores the task stack pointer when a switch is made to use the system stack. */
unsigned portBASE_TYPE uxSavedTaskStackPointer = 0 ;
/* The stack used by interrupt service routines that cause a context switch. */
portSTACK_TYPE xISRStack [ configISR_STACK_SIZE ] = { 0 } ;
/* The top of stack value ensures there is enough space to store 6 registers on
the callers stack , as some functions seem to want to do this . */
const portSTACK_TYPE * const xISRStackTop = & ( xISRStack [ configISR_STACK_SIZE - 7 ] ) ;
/*-----------------------------------------------------------*/
/*
@ -144,25 +209,36 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
* pxTopOfStack = ( portSTACK_TYPE ) _CP0_GET_CAUSE ( ) ;
pxTopOfStack - - ;
* pxTopOfStack = ( portSTACK_TYPE ) portINITIAL_SR ; /* CP0_STATUS */
* pxTopOfStack = ( portSTACK_TYPE ) portINITIAL_SR ; /* CP0_STATUS */
pxTopOfStack - - ;
* pxTopOfStack = ( portSTACK_TYPE ) pxCode ; /* CP0_EPC */
pxTopOfStack - - ;
* pxTopOfStack = ( portSTACK_TYPE ) NULL ; /* ra */
* pxTopOfStack = ( portSTACK_TYPE ) portTASK_RETURN_ADDRESS ; /* ra */
pxTopOfStack - = 15 ;
* pxTopOfStack = ( portSTACK_TYPE ) pvParameters ; /* Parameters to pass in */
pxTopOfStack - = 14 ;
* pxTopOfStack = ( portSTACK_TYPE ) 0x00000000 ; /* critical nesting level - no longer used. */
pxTopOfStack - - ;
* pxTopOfStack = ( portSTACK_TYPE ) pvParameters ; /* Parameters to pass in. */
pxTopOfStack - = 15 ;
return pxTopOfStack ;
}
/*-----------------------------------------------------------*/
static void prvTaskExitError ( void )
{
/* A function that implements a task must not exit or attempt to return to
its caller as there is nothing to return to . If a task wants to exit it
should instead call vTaskDelete ( NULL ) .
Artificially force an assert ( ) to be triggered if configASSERT ( ) is
defined , then stop here so application writers can catch the error . */
configASSERT ( uxSavedTaskStackPointer = = 0UL ) ;
portDISABLE_INTERRUPTS ( ) ;
for ( ; ; ) ;
}
/*-----------------------------------------------------------*/
/*
* Setup a timer for a regular tick . This function uses peripheral timer 1.
* The function is declared weak so an application writer can use a different
@ -206,6 +282,13 @@ portBASE_TYPE xPortStartScheduler( void )
extern void vPortStartFirstTask ( void ) ;
extern void * pxCurrentTCB ;
# if ( configCHECK_FOR_STACK_OVERFLOW > 2 )
{
/* Fill the ISR stack to make it easy to asses how much is being used. */
memset ( ( void * ) xISRStack , portISR_STACK_FILL_BYTE , sizeof ( xISRStack ) ) ;
}
# endif /* configCHECK_FOR_STACK_OVERFLOW > 2 */
/* Clear the software interrupt flag. */
IFS0CLR = _IFS0_CS0IF_MASK ;
@ -226,7 +309,12 @@ extern void *pxCurrentTCB;
uxSavedTaskStackPointer = * ( unsigned portBASE_TYPE * ) pxCurrentTCB ;
vPortStartFirstTask ( ) ;
/* Should never get here as the tasks will now be executing. */
/* Should never get here as the tasks will now be executing! Call the task
exit error function to prevent compiler warnings about a static function
not being called in the case that the application writer overrides this
functionality by defining configTASK_RETURN_ADDRESS . */
prvTaskExitError ( ) ;
return pdFALSE ;
}
/*-----------------------------------------------------------*/
@ -245,8 +333,11 @@ unsigned portBASE_TYPE uxSavedStatus;
}
vPortClearInterruptMaskFromISR ( uxSavedStatus ) ;
/* Clear timer 1 interrupt. */
IFS0CLR = _IFS0_T1IF_MASK ;
/* Look for the ISR stack getting near or past its limit. */
portCHECK_ISR_STACK ( ) ;
/* Clear timer interrupt. */
configCLEAR_TICK_TIMER_INTERRUPT ( ) ;
}
/*-----------------------------------------------------------*/
@ -254,7 +345,7 @@ unsigned portBASE_TYPE uxPortSetInterruptMaskFromISR( void )
{
unsigned portBASE_TYPE uxSavedStatusRegister ;
asm volatile ( " di " ) ;
__builtin_disable_interrupts ( ) ;
uxSavedStatusRegister = _CP0_GET_STATUS ( ) | 0x01 ;
/* This clears the IPL bits, then sets them to
configMAX_SYSCALL_INTERRUPT_PRIORITY . This function should not be called