|
|
@ -56,8 +56,6 @@ extern volatile tskTCB * volatile pxCurrentTCB;
|
|
|
|
volatile unsigned portLONG ulCriticalNesting = 9999UL;
|
|
|
|
volatile unsigned portLONG ulCriticalNesting = 9999UL;
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma asm
|
|
|
|
#pragma asm
|
|
|
|
#macro SaveContext
|
|
|
|
#macro SaveContext
|
|
|
@ -104,7 +102,7 @@ volatile unsigned portLONG ulCriticalNesting = 9999UL;
|
|
|
|
ANDCCR #0xDF ;Switch to system stack
|
|
|
|
ANDCCR #0xDF ;Switch to system stack
|
|
|
|
ST R0,@-R15 ;Store PC to system stack
|
|
|
|
ST R0,@-R15 ;Store PC to system stack
|
|
|
|
|
|
|
|
|
|
|
|
ORCCR #0x20 ;Switch back to retreive the remaining context
|
|
|
|
ORCCR #0x20 ;Switch back to retrieve the remaining context
|
|
|
|
|
|
|
|
|
|
|
|
LDI #_ulCriticalNesting, R0 ;Get the address of the critical nesting counter
|
|
|
|
LDI #_ulCriticalNesting, R0 ;Get the address of the critical nesting counter
|
|
|
|
LD @R15+, R1 ;Get the saved critical nesting value
|
|
|
|
LD @R15+, R1 ;Get the saved critical nesting value
|
|
|
@ -146,14 +144,14 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
|
|
|
|
*pxTopOfStack = 0x33333333;
|
|
|
|
*pxTopOfStack = 0x33333333;
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
/* This is a redundant push to the stack, it may be required if in some implentation of the compiler
|
|
|
|
/* This is a redundant push to the stack, it may be required if
|
|
|
|
the parameter to the task is passed on to the stack rather than in R4 register*/
|
|
|
|
in some implementations of the compiler the parameter to the task
|
|
|
|
|
|
|
|
is passed on to the stack rather than in R4 register. */
|
|
|
|
*pxTopOfStack = (portSTACK_TYPE)(pvParameters);
|
|
|
|
*pxTopOfStack = (portSTACK_TYPE)(pvParameters);
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; /* RP */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00000000; /* RP */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00007777; /* R7 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00007777; /* R7 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00006666; /* R6 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00006666; /* R6 */
|
|
|
@ -161,10 +159,10 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00005555; /* R5 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00005555; /* R5 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
/* In the current implemention of the compiler the first
|
|
|
|
/* In the current implementation of the compiler the first
|
|
|
|
parameter to the task(or function) is passed via R4 parameter
|
|
|
|
parameter to the task (or function) is passed via R4 parameter
|
|
|
|
to the task, hennce the pvParameters pointer is copied in R4
|
|
|
|
to the task, hence the pvParameters pointer is copied into the R4
|
|
|
|
regsiter. See compiler manual section 4.6.2 for more information.*/
|
|
|
|
register. See compiler manual section 4.6.2 for more information. */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) (pvParameters); /* R4 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) (pvParameters); /* R4 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00003333; /* R3 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00003333; /* R3 */
|
|
|
@ -174,8 +172,7 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00001111; /* R1 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00001111; /* R1 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00000001; /* R0 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00000001; /* R0 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x0000EEEE; /* R14 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x0000EEEE; /* R14 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x0000DDDD; /* R13 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x0000DDDD; /* R13 */
|
|
|
@ -189,15 +186,14 @@ portSTACK_TYPE *pxPortInitialiseStack( portSTACK_TYPE *pxTopOfStack, pdTASK_CODE
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00009999; /* R9 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00009999; /* R9 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00008888; /* R8 */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x00008888; /* R8 */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x11110000; /* MDH */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x11110000; /* MDH */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x22220000; /* MDL */
|
|
|
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x22220000; /* MDL */
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
|
/* The task starts with its ulCriticalNesting variable set to 0, interrupts
|
|
|
|
/* The task starts with its ulCriticalNesting variable set to 0,
|
|
|
|
being enabled. */
|
|
|
|
interrupts being enabled. */
|
|
|
|
*pxTopOfStack = portNO_CRITICAL_NESTING;
|
|
|
|
*pxTopOfStack = portNO_CRITICAL_NESTING;
|
|
|
|
pxTopOfStack--;
|
|
|
|
pxTopOfStack--;
|
|
|
|
|
|
|
|
|
|
|
@ -218,18 +214,16 @@ portBASE_TYPE xPortStartScheduler( void )
|
|
|
|
prvSetupTimerInterrupt();
|
|
|
|
prvSetupTimerInterrupt();
|
|
|
|
|
|
|
|
|
|
|
|
/* Restore the context of the first task that is going to run. */
|
|
|
|
/* Restore the context of the first task that is going to run. */
|
|
|
|
#pragma asm
|
|
|
|
#pragma asm
|
|
|
|
RestoreContext
|
|
|
|
RestoreContext
|
|
|
|
#pragma endasm
|
|
|
|
#pragma endasm
|
|
|
|
|
|
|
|
|
|
|
|
/* Simulate a function call end as generated by the compiler. We will now
|
|
|
|
/* Simulate a function call end as generated by the compiler. We will now
|
|
|
|
jump to the start of the task the context of which we have just restored. */
|
|
|
|
jump to the start of the task the context of which we have just restored. */
|
|
|
|
|
|
|
|
|
|
|
|
__asm(" reti ");
|
|
|
|
__asm(" reti ");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Should not get here. */
|
|
|
|
/* Should not get here. */
|
|
|
|
return pdTRUE;
|
|
|
|
return pdFAIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
@ -240,26 +234,25 @@ void vPortEndScheduler( void )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* Setup RLT0 to generate a tick interrupt.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void prvSetupTimerInterrupt( void )
|
|
|
|
static void prvSetupTimerInterrupt( void )
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* The peripheral clock divided by 32 is used by the timer. */
|
|
|
|
/* The peripheral clock divided by 32 is used by the timer. */
|
|
|
|
const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_CLOCK_HZ / configTICK_RATE_HZ ) / 32UL ) - 1UL );
|
|
|
|
const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_CLOCK_HZ / configTICK_RATE_HZ ) / 32UL ) - 1UL );
|
|
|
|
|
|
|
|
|
|
|
|
TMCSR0_CNTE=0; /* Count Disable */
|
|
|
|
/* Setup RLT0 to generate a tick interrupt. */
|
|
|
|
TMCSR0_CSL=0x2; /* CLKP/32 */
|
|
|
|
|
|
|
|
TMCSR0_MOD=0; /* Software trigger */
|
|
|
|
TMCSR0_CNTE = 0; /* Count Disable */
|
|
|
|
TMCSR0_RELD=1; /* Reload */
|
|
|
|
TMCSR0_CSL = 0x2; /* CLKP/32 */
|
|
|
|
|
|
|
|
TMCSR0_MOD = 0; /* Software trigger */
|
|
|
|
|
|
|
|
TMCSR0_RELD = 1; /* Reload */
|
|
|
|
|
|
|
|
|
|
|
|
TMCSR0_UF=0; /* Clear underflow flag */
|
|
|
|
TMCSR0_UF = 0; /* Clear underflow flag */
|
|
|
|
TMRLR0=usReloadValue;
|
|
|
|
TMRLR0 = usReloadValue;
|
|
|
|
TMCSR0_INTE=1; /* Interrupt Enable */
|
|
|
|
TMCSR0_INTE = 1; /* Interrupt Enable */
|
|
|
|
TMCSR0_CNTE=1; /* Count Enable */
|
|
|
|
TMCSR0_CNTE = 1; /* Count Enable */
|
|
|
|
TMCSR0_TRG=1; /* Trigger */
|
|
|
|
TMCSR0_TRG = 1; /* Trigger */
|
|
|
|
|
|
|
|
|
|
|
|
PORTEN = 0x3; /* Port Enable */
|
|
|
|
PORTEN = 0x3; /* Port Enable */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
@ -268,7 +261,7 @@ const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Tick ISR for preemptive scheduler. The tick count is incremented
|
|
|
|
* Tick ISR for preemptive scheduler. The tick count is incremented
|
|
|
|
* after the context is saved. Then the context is switched if required,
|
|
|
|
* after the context is saved. Then the context is switched if required,
|
|
|
|
* at last the context of the task which is to be resume is restored.
|
|
|
|
* and last the context of the task which is to be resumed is restored.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma asm
|
|
|
|
#pragma asm
|
|
|
@ -277,9 +270,7 @@ const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_
|
|
|
|
_ReloadTimer0_IRQHandler:
|
|
|
|
_ReloadTimer0_IRQHandler:
|
|
|
|
|
|
|
|
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
SaveContext ;Save context
|
|
|
|
SaveContext ;Save context
|
|
|
|
|
|
|
|
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
LDI #0xFFFB,R1
|
|
|
|
LDI #0xFFFB,R1
|
|
|
@ -287,13 +278,10 @@ const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_
|
|
|
|
AND R1,@R0 ;Clear RLT0 interrupt flag
|
|
|
|
AND R1,@R0 ;Clear RLT0 interrupt flag
|
|
|
|
|
|
|
|
|
|
|
|
CALL32 _vTaskIncrementTick,R12 ;Increment Tick
|
|
|
|
CALL32 _vTaskIncrementTick,R12 ;Increment Tick
|
|
|
|
|
|
|
|
|
|
|
|
CALL32 _vTaskSwitchContext,R12 ;Switch context if required
|
|
|
|
CALL32 _vTaskSwitchContext,R12 ;Switch context if required
|
|
|
|
|
|
|
|
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
RestoreContext ;Restore context
|
|
|
|
RestoreContext ;Restore context
|
|
|
|
|
|
|
|
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
RETI
|
|
|
|
RETI
|
|
|
@ -316,20 +304,18 @@ const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Manual context switch. We can use a __nosavereg attribute as the context
|
|
|
|
* Manual context switch. We can use a __nosavereg attribute as the context
|
|
|
|
* would be saved by PortSAVE_CONTEXT(). The context is switched and then
|
|
|
|
* would be saved by PortSAVE_CONTEXT(). The context is switched and then
|
|
|
|
* the context of the new task is restored saved.
|
|
|
|
* the context of the new task is restored saved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
#pragma asm
|
|
|
|
#pragma asm
|
|
|
|
|
|
|
|
|
|
|
|
.global _vPortYieldDelayed
|
|
|
|
.global _vPortYieldDelayed
|
|
|
|
_vPortYieldDelayed:
|
|
|
|
_vPortYieldDelayed:
|
|
|
|
|
|
|
|
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
SaveContext ;Save context
|
|
|
|
SaveContext ;Save context
|
|
|
|
|
|
|
|
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
LDI #_dicr, R0
|
|
|
|
LDI #_dicr, R0
|
|
|
@ -338,36 +324,31 @@ const unsigned portSHORT usReloadValue = ( unsigned portSHORT ) ( ( ( configPER_
|
|
|
|
CALL32 _vTaskSwitchContext,R12 ;Switch context if required
|
|
|
|
CALL32 _vTaskSwitchContext,R12 ;Switch context if required
|
|
|
|
|
|
|
|
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
ANDCCR #0xEF ;Disable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
RestoreContext ;Restore context
|
|
|
|
RestoreContext ;Restore context
|
|
|
|
|
|
|
|
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
ORCCR #0x10 ;Re-enable Interrupts
|
|
|
|
|
|
|
|
|
|
|
|
RETI
|
|
|
|
RETI
|
|
|
|
|
|
|
|
|
|
|
|
#pragma endasm
|
|
|
|
#pragma endasm
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Manual context switch. We can use a __nosavereg attribute as the context
|
|
|
|
* Manual context switch. We can use a __nosavereg attribute as the context
|
|
|
|
* would be saved by PortSAVE_CONTEXT(). The context is switched and then
|
|
|
|
* would be saved by PortSAVE_CONTEXT(). The context is switched and then
|
|
|
|
* the context of the new task is restored saved.
|
|
|
|
* the context of the new task is restored saved.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#pragma asm
|
|
|
|
#pragma asm
|
|
|
|
|
|
|
|
|
|
|
|
.global _vPortYield
|
|
|
|
.global _vPortYield
|
|
|
|
_vPortYield:
|
|
|
|
_vPortYield:
|
|
|
|
|
|
|
|
|
|
|
|
SaveContext ;Save context
|
|
|
|
SaveContext ;Save context
|
|
|
|
|
|
|
|
|
|
|
|
CALL32 _vTaskSwitchContext,R12 ;Switch context if required
|
|
|
|
CALL32 _vTaskSwitchContext,R12 ;Switch context if required
|
|
|
|
|
|
|
|
|
|
|
|
RestoreContext ;Restore context
|
|
|
|
RestoreContext ;Restore context
|
|
|
|
|
|
|
|
|
|
|
|
RETI
|
|
|
|
RETI
|
|
|
|
|
|
|
|
|
|
|
|
#pragma endasm
|
|
|
|
#pragma endasm
|
|
|
|
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
/*-----------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
|
|
void vPortEnterCritical( void )
|
|
|
|
void vPortEnterCritical( void )
|
|
|
|