Line 336... |
Line 336... |
TX0 R1
|
TX0 R1
|
ADC R3
|
ADC R3
|
T0X R3
|
T0X R3
|
.ENDM
|
.ENDM
|
|
|
; SETUP_TASK is a template used to generate code that sets up a single task's
|
; INITIALIZE_TASK_STACK relocates the CPU stack pointer during setup, then
|
; stack and stack pointer for each a task. This macros will temporarily
|
; simulates an RTI by loading an initial flag and return address, then resets
|
; relocate the stack pointer, push the task's initial state to the task's
|
; all registers to 0
|
; stack. Note that it is important to also ensure that the stack has data to
|
.MACRO INITIALIZE_TASK_STACK
|
; not only restore the return address, but also R7:R0, as well as the flag
|
|
; state.
|
|
.MACRO SETUP_TASK
|
|
LDI R0, #\@
|
|
STA R0, TaskMgr.This_Task ; Write This_Task
|
|
|
|
REINIT_TASK_TABLE_PTR ; Use This_Task to initialize R3:R2
|
|
|
|
; Get the task's starting stack address from the table and load
|
; Get the task's starting stack address from the table and load
|
; it into the CPU SP
|
; it into the CPU SP
|
LDO R2, PARAM_STACK_ADDR_HIGH
|
LDO R2, PARAM_STACK_ADDR_HIGH
|
T0X R1
|
T0X R1
|
LDO R2, PARAM_STACK_ADDR_LOW
|
LDO R2, PARAM_STACK_ADDR_LOW
|
Line 381... |
Line 373... |
T0X R3
|
T0X R3
|
T0X R4
|
T0X R4
|
T0X R5
|
T0X R5
|
T0X R6
|
T0X R6
|
T0X R7
|
T0X R7
|
|
|
; Once the task's initial state has been created, "suspend"
|
|
; the task. This will effective initialize its state and
|
|
; SP pointer
|
|
SUSPEND_THIS_TASK
|
|
.ENDM
|
|
|
|
; SUSPEND_THIS_TASK pushes all of the registers to a task's stack, then
|
|
; backups up the stack pointer to the system memory backup location for that
|
|
; task.
|
|
.MACRO SUSPEND_THIS_TASK
|
|
BACKUP_FULL_CONTEXT
|
|
BACKUP_STACK_POINTER
|
|
.ENDM
|
.ENDM
|
|
|
; BACKUP_STACK_POINTER uses the This_Task variable to configure R3:R2 as a
|
; BACKUP_STACK_POINTER uses the This_Task variable to configure R3:R2 as a
|
; pointer into the system memory where stack pointer backups are stored, then
|
; pointer into the system memory where stack pointer backups are stored, then
|
; obtains the current stack address and pushes it to the task's backup
|
; obtains the current stack address and pushes it to the task's backup
|
Line 420... |
Line 399... |
STX R2
|
STX R2
|
TX0 R1
|
TX0 R1
|
STO R2,1
|
STO R2,1
|
.ENDM
|
.ENDM
|
|
|
|
; SUSPEND_THIS_TASK pushes all of the registers to a task's stack, then
|
|
; backups up the stack pointer to the system memory backup location for that
|
|
; task.
|
|
.MACRO SUSPEND_THIS_TASK
|
|
BACKUP_FULL_CONTEXT
|
|
BACKUP_STACK_POINTER
|
|
.ENDM
|
|
|
|
; SETUP_TASK is a template used to generate code that sets up a single task's
|
|
; stack and stack pointer for each a task. This macros will temporarily
|
|
; relocate the stack pointer, push the task's initial state to the task's
|
|
; stack. Note that it is important to also ensure that the stack has data to
|
|
; not only restore the return address, but also R7:R0, as well as the flag
|
|
; state.
|
|
.MACRO SETUP_TASK
|
|
LDI R0, #\@
|
|
STA R0, TaskMgr.This_Task ; Write This_Task
|
|
|
|
REINIT_TASK_TABLE_PTR ; Use This_Task to initialize R3:R2
|
|
INITIALIZE_TASK_STACK ; Setup the new task's stack area
|
|
SUSPEND_THIS_TASK ; Suspend the task to store setup
|
|
.ENDM
|
|
|
; RESTORE_STACK_POINTER uses the This_Task variable to configure R3:R2 as a
|
; RESTORE_STACK_POINTER uses the This_Task variable to configure R3:R2 as a
|
; pointer into the system memory where stack pointer backups are stored. It
|
; pointer into the system memory where stack pointer backups are stored. It
|
; then looks up the task's SP backup variable and pushes it back to the CPU SP
|
; then looks up the task's SP backup variable and pushes it back to the CPU SP
|
.MACRO RESTORE_STACK_POINTER
|
.MACRO RESTORE_STACK_POINTER
|
LDA R0, TaskMgr.This_Task ; Get the task number
|
LDA R0, TaskMgr.This_Task ; Get the task number
|