mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-19 21:11:57 -04:00
Tidy up and comment.
This commit is contained in:
parent
bfd67da1e7
commit
c1a2e601a6
|
@ -39,29 +39,28 @@
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; portSAVE_CONTEXT MACRO
|
; portSAVE_CONTEXT MACRO
|
||||||
; Saves the context of the remaining general purpose registers, CS and ES
|
; Saves the context of the general purpose registers, CS and ES (only in far
|
||||||
; (only in far memory mode) registers
|
; memory mode) registers the usCriticalNesting Value and the Stack Pointer
|
||||||
; the usCriticalNesting Value and the Stack Pointer
|
|
||||||
; of the active Task onto the task stack
|
; of the active Task onto the task stack
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
portSAVE_CONTEXT MACRO
|
portSAVE_CONTEXT MACRO
|
||||||
|
|
||||||
PUSH AX ; save AX Register to stack
|
PUSH AX ; Save AX Register to stack.
|
||||||
PUSH HL
|
PUSH HL
|
||||||
#if configMEMORY_MODE == 1
|
#if configMEMORY_MODE == 1
|
||||||
MOV A, CS ; save CS register
|
MOV A, CS ; Save CS register.
|
||||||
XCH A, X
|
XCH A, X
|
||||||
MOV A, ES ; save ES register
|
MOV A, ES ; Save ES register.
|
||||||
PUSH AX
|
PUSH AX
|
||||||
#else
|
#else
|
||||||
MOV A, CS ; save CS register
|
MOV A, CS ; Save CS register.
|
||||||
PUSH AX
|
PUSH AX
|
||||||
#endif
|
#endif
|
||||||
PUSH DE ; save the remaining general purpose registers
|
PUSH DE ; Save the remaining general purpose registers.
|
||||||
PUSH BC
|
PUSH BC
|
||||||
MOVW AX, usCriticalNesting ; save the usCriticalNesting value
|
MOVW AX, usCriticalNesting ; Save the usCriticalNesting value.
|
||||||
PUSH AX
|
PUSH AX
|
||||||
MOVW AX, pxCurrentTCB ; save the Stack pointer
|
MOVW AX, pxCurrentTCB ; Save the Stack pointer.
|
||||||
MOVW HL, AX
|
MOVW HL, AX
|
||||||
MOVW AX, SP
|
MOVW AX, SP
|
||||||
MOVW [HL], AX
|
MOVW [HL], AX
|
||||||
|
@ -70,30 +69,29 @@ portSAVE_CONTEXT MACRO
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; portRESTORE_CONTEXT MACRO
|
; portRESTORE_CONTEXT MACRO
|
||||||
; Restores the context of the Stack Pointer, usCriticalNesting
|
; Restores the task Stack Pointer then use this to restore usCriticalNesting,
|
||||||
; value, general purpose registers and the CS and ES (only in far memory mode)
|
; general purpose registers and the CS and ES (only in far memory mode)
|
||||||
; of the selected task from the task stack
|
; of the selected task from the task stack
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
|
||||||
portRESTORE_CONTEXT MACRO
|
portRESTORE_CONTEXT MACRO
|
||||||
MOVW AX, pxCurrentTCB ; restore the Stack pointer
|
MOVW AX, pxCurrentTCB ; Restore the Stack pointer.
|
||||||
MOVW HL, AX
|
MOVW HL, AX
|
||||||
MOVW AX, [HL]
|
MOVW AX, [HL]
|
||||||
MOVW SP, AX
|
MOVW SP, AX
|
||||||
POP AX ; restore usCriticalNesting value
|
POP AX ; Restore usCriticalNesting value.
|
||||||
MOVW usCriticalNesting, AX
|
MOVW usCriticalNesting, AX
|
||||||
POP BC ; restore the necessary general purpose registers
|
POP BC ; Restore the necessary general purpose registers.
|
||||||
POP DE
|
POP DE
|
||||||
#if configMEMORY_MODE == 1
|
#if configMEMORY_MODE == 1
|
||||||
POP AX ; restore the ES register
|
POP AX ; Restore the ES register.
|
||||||
MOV ES, A
|
MOV ES, A
|
||||||
XCH A, X ; restore the CS register
|
XCH A, X ; Restore the CS register.
|
||||||
MOV CS, A
|
MOV CS, A
|
||||||
#else
|
#else
|
||||||
POP AX
|
POP AX
|
||||||
MOV CS, A ; restore CS register
|
MOV CS, A ; Restore CS register.
|
||||||
#endif
|
#endif
|
||||||
POP HL ; restore general purpose register HL
|
POP HL ; Restore general purpose register HL.
|
||||||
POP AX ; restore AX
|
POP AX ; Restore AX.
|
||||||
ENDM
|
ENDM
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
|
|
@ -54,20 +54,22 @@
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
|
||||||
|
/* The critical nesting value is initialised to a non zero value to ensure
|
||||||
|
interrupts don't accidentally become enabled before the scheduler is started. */
|
||||||
#define portINITIAL_CRITICAL_NESTING (( unsigned portSHORT ) 10)
|
#define portINITIAL_CRITICAL_NESTING (( unsigned portSHORT ) 10)
|
||||||
|
|
||||||
/* default Initialization of the PSW for the task:
|
/* Initial PSW value allocated to a newly created task.
|
||||||
* 1100011000000000
|
* 1100011000000000
|
||||||
* ||||||||-------------- Fill byte
|
* ||||||||-------------- Fill byte
|
||||||
* |||||||--------------- Cary Flag cleared
|
* |||||||--------------- Carry Flag cleared
|
||||||
* |||||----------------- In-service priority Flags set to low level
|
* |||||----------------- In-service priority Flags set to low level
|
||||||
* ||||------------------ Register bank Select 0 Flag cleared
|
* ||||------------------ Register bank Select 0 Flag cleared
|
||||||
* |||------------------- Auxiliary Cary Flag cleared
|
* |||------------------- Auxiliary Carry Flag cleared
|
||||||
* ||-------------------- Register bank Select 1 Flag cleared
|
* ||-------------------- Register bank Select 1 Flag cleared
|
||||||
* |--------------------- Zero Flag set
|
* |--------------------- Zero Flag set
|
||||||
* ---------------------- Global Interrupt Flag set (enabled)
|
* ---------------------- Global Interrupt Flag set (enabled)
|
||||||
*/
|
*/
|
||||||
#define portPSW (0xc6000000UL)
|
#define portPSW (0xc6UL)
|
||||||
|
|
||||||
/* We require the address of the pxCurrentTCB variable, but don't want to know
|
/* We require the address of the pxCurrentTCB variable, but don't want to know
|
||||||
any details of its type. */
|
any details of its type. */
|
||||||
|
@ -112,36 +114,39 @@ unsigned long *pulLocal;
|
||||||
|
|
||||||
#if configMEMORY_MODE == 1
|
#if configMEMORY_MODE == 1
|
||||||
{
|
{
|
||||||
/* Parameters are passed in on the stack. */
|
/* Parameters are passed in on the stack, and written using a 32bit value
|
||||||
|
hence a space is left for the second two bytes. */
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
|
/* Write in the parameter value. */
|
||||||
pulLocal = ( unsigned long * ) pxTopOfStack;
|
pulLocal = ( unsigned long * ) pxTopOfStack;
|
||||||
*pulLocal = ( unsigned long ) pvParameters;
|
*pulLocal = ( unsigned long ) pvParameters;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
/* Dummy values on the stack because there normaly the return address
|
/* These values are just spacers. The return address of the function
|
||||||
of the funtion is written. */
|
would normally be written here. */
|
||||||
*pxTopOfStack = ( portSTACK_TYPE ) 0xcdcd;
|
*pxTopOfStack = ( portSTACK_TYPE ) 0xcdcd;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
*pxTopOfStack = ( portSTACK_TYPE ) 0xcdcd;
|
*pxTopOfStack = ( portSTACK_TYPE ) 0xcdcd;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
/* Initial PSW value. */
|
/* The start address / PSW value is also written in as a 32bit value,
|
||||||
// *pxTopOfStack = portPSW;
|
so leave a space for the second two bytes. */
|
||||||
|
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
|
|
||||||
/* Task function start address. */
|
/* Task function start address combined with the PSW. */
|
||||||
pulLocal = ( unsigned long * ) pxTopOfStack;
|
pulLocal = ( unsigned long * ) pxTopOfStack;
|
||||||
*pulLocal = ( ( ( unsigned long ) pxCode ) | portPSW );
|
*pulLocal = ( ( ( unsigned long ) pxCode ) | ( portPSW << 24UL ) );
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
/* Next general purpose register AX. */
|
/* An initial value for the AX register. */
|
||||||
*pxTopOfStack = ( portSTACK_TYPE ) 0x1111;
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x1111;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
{
|
{
|
||||||
|
TBD
|
||||||
|
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
/* Task function start address. */
|
/* Task function start address. */
|
||||||
|
@ -159,7 +164,7 @@ unsigned long *pulLocal;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* HL. */
|
/* An initial value for the HL register. */
|
||||||
*pxTopOfStack = ( portSTACK_TYPE ) 0x2222;
|
*pxTopOfStack = ( portSTACK_TYPE ) 0x2222;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
|
@ -172,12 +177,13 @@ unsigned long *pulLocal;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
*pxTopOfStack = ( portSTACK_TYPE ) 0xBCBC;
|
*pxTopOfStack = ( portSTACK_TYPE ) 0xBCBC;
|
||||||
pxTopOfStack--;
|
pxTopOfStack--;
|
||||||
|
|
||||||
|
/* Finally the critical section nesting count is set to zero when the task
|
||||||
|
first starts. */
|
||||||
*pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;
|
*pxTopOfStack = ( portSTACK_TYPE ) portNO_CRITICAL_SECTION_NESTING;
|
||||||
|
|
||||||
/*
|
/* Return a pointer to the top of the stack we have generated so this can
|
||||||
* Return a pointer to the top of the stack we have generated so this can
|
be stored in the task control block for the task. */
|
||||||
* be stored in the task control block for the task.
|
|
||||||
*/
|
|
||||||
return pxTopOfStack;
|
return pxTopOfStack;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
@ -198,17 +204,15 @@ portBASE_TYPE xPortStartScheduler( void )
|
||||||
|
|
||||||
void vPortEndScheduler( void )
|
void vPortEndScheduler( void )
|
||||||
{
|
{
|
||||||
/* It is unlikely that the 78K0R/Kx3 port will get stopped. If required simply
|
/* It is unlikely that the 78K0R port will get stopped. If required simply
|
||||||
disable the tick interrupt here. */
|
disable the tick interrupt here. */
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
/*
|
|
||||||
* Hardware initialisation to generate the RTOS tick. This uses Channel 5 of
|
|
||||||
* the Timer Array Unit (TAU). Any other Channel could also be used.
|
|
||||||
*/
|
|
||||||
static void prvSetupTimerInterrupt( void )
|
static void prvSetupTimerInterrupt( void )
|
||||||
{
|
{
|
||||||
|
/* Setup channel 5 of the TAU to generate the tick interrupt. */
|
||||||
|
|
||||||
/* First the Timer Array Unit has to be enabled. */
|
/* First the Timer Array Unit has to be enabled. */
|
||||||
TAU0EN = 1;
|
TAU0EN = 1;
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,6 @@
|
||||||
|
|
||||||
; Functions implemented in this file
|
; Functions implemented in this file
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
|
||||||
PUBLIC vPortYield
|
PUBLIC vPortYield
|
||||||
PUBLIC vPortStart
|
PUBLIC vPortStart
|
||||||
|
|
||||||
|
@ -63,7 +62,9 @@ MD_INTTM05 SYMBOL "MD_INTTM05"
|
||||||
|
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; Port Yield function to check for a Task switch in the cooperative mode
|
; Yield to another task. Implemented as a software interrupt. The return
|
||||||
|
; address and PSW will have been saved to the stack automatically before
|
||||||
|
; this code runs.
|
||||||
;
|
;
|
||||||
; Input: NONE
|
; Input: NONE
|
||||||
;
|
;
|
||||||
|
@ -75,9 +76,9 @@ MD_INTTM05 SYMBOL "MD_INTTM05"
|
||||||
RSEG CODE:CODE
|
RSEG CODE:CODE
|
||||||
vPortYield:
|
vPortYield:
|
||||||
portSAVE_CONTEXT ; Save the context of the current task.
|
portSAVE_CONTEXT ; Save the context of the current task.
|
||||||
call vTaskSwitchContext ; Call the scheduler.
|
call vTaskSwitchContext ; Call the scheduler to select the next task.
|
||||||
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
portRESTORE_CONTEXT ; Restore the context of the next task to run.
|
||||||
RETB
|
retb
|
||||||
|
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
|
@ -93,8 +94,8 @@ vPortYield:
|
||||||
RSEG CODE:CODE
|
RSEG CODE:CODE
|
||||||
vPortStart:
|
vPortStart:
|
||||||
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
||||||
; POP PSW ; restore active task PSW
|
reti ; An interrupt stack frame is used so the task
|
||||||
reti ; ... scheduler decided should run.
|
; is started using a RETI instruction.
|
||||||
|
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
; Perform the necessary steps of the Tick Count Increment and Task Switch
|
; Perform the necessary steps of the Tick Count Increment and Task Switch
|
||||||
|
@ -107,42 +108,31 @@ vPortStart:
|
||||||
; Output: NONE
|
; Output: NONE
|
||||||
;
|
;
|
||||||
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
||||||
#if configUSE_PREEMPTION == 1
|
|
||||||
|
|
||||||
MD_INTTM05:
|
MD_INTTM05:
|
||||||
|
|
||||||
portSAVE_CONTEXT ; Save the context of the current task.
|
portSAVE_CONTEXT ; Save the context of the current task.
|
||||||
call vTaskIncrementTick ; Call the timer tick function.
|
call vTaskIncrementTick ; Call the timer tick function.
|
||||||
call vTaskSwitchContext ; Call the scheduler.
|
#if configUSE_PREEMPTION == 1
|
||||||
portRESTORE_CONTEXT ; Restore the context of whichever task the ...
|
call vTaskSwitchContext ; Call the scheduler to select the next task.
|
||||||
RETI
|
|
||||||
#else
|
|
||||||
|
|
||||||
MD_INTTM05:
|
|
||||||
PUSH AX ; save necessary general purpose register...
|
|
||||||
PUSH HL ; ...used by the ISR
|
|
||||||
MOVW AX, CS ; save CS register
|
|
||||||
PUSH AX
|
|
||||||
CALL vTaskIncrementTick ; Call the timer tick function.
|
|
||||||
POP AX
|
|
||||||
MOVW CS, AX ; restore CS register
|
|
||||||
POP HL ; restore used general purpose registers
|
|
||||||
POP AX
|
|
||||||
RETI
|
|
||||||
#endif
|
#endif
|
||||||
|
portRESTORE_CONTEXT ; Restore the context of the next task to run.
|
||||||
|
reti
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
REQUIRE ?CL78K0R_V2_L00
|
REQUIRE ?CL78K0R_V2_L00
|
||||||
COMMON INTVEC:CODE:ROOT(1) ; set ISR location to the Interrupt vector table
|
COMMON INTVEC:CODE:ROOT(1) ; Set ISR location to the Interrupt vector table.
|
||||||
ORG 68
|
ORG 68
|
||||||
`??MD_INTTM05??INTVEC 68`:
|
`??MD_INTTM05??INTVEC 68`:
|
||||||
DW MD_INTTM05
|
DW MD_INTTM05
|
||||||
|
|
||||||
COMMON INTVEC:CODE:ROOT(1) ; set ISR location to the Interrupt vector table
|
COMMON INTVEC:CODE:ROOT(1) ; Set ISR location to the Interrupt vector table.
|
||||||
ORG 126
|
ORG 126
|
||||||
`??vPortYield??INTVEC 126`:
|
`??vPortYield??INTVEC 126`:
|
||||||
DW vPortYield
|
DW vPortYield
|
||||||
|
|
||||||
; set value for the usCriticalNesting
|
; Set value for the usCriticalNesting.
|
||||||
RSEG NEAR_ID:CONST:SORT:NOROOT(1)
|
RSEG NEAR_ID:CONST:SORT:NOROOT(1)
|
||||||
`?<Initializer for usCriticalNesting>`:
|
`?<Initializer for usCriticalNesting>`:
|
||||||
DW 10
|
DW 10
|
||||||
|
|
Loading…
Reference in a new issue