Line 222... |
Line 222... |
.STRUCT str_isr_flag
|
.STRUCT str_isr_flag
|
Flag DB ; Single-byte flag variable for returning semaphores
|
Flag DB ; Single-byte flag variable for returning semaphores
|
.ENDST
|
.ENDST
|
|
|
.DEFINE TSB_SIZE 2 * TASK_COUNT
|
.DEFINE TSB_SIZE 2 * TASK_COUNT
|
.DEFINE FREE_SYS 124 - TSB_SIZE
|
.DEFINE FREE_SYS WP_Rgn_Size - 8 - TSB_SIZE
|
|
|
.STRUCT str_taskman
|
.STRUCT str_taskman
|
This_Task DB ; Holds the task number of the current task
|
This_Task DB ; Holds the task number of the current task
|
Next_Task DB ; Specifieds which task to be executed next
|
Next_Task DB ; Specifieds which task to be executed next
|
Fault_Flag DB ; Memory write fault flag
|
Fault_Flag DB ; Memory write fault flag
|
Fault_Task DB ; Task active/responsible for write fault
|
Fault_Task DB ; Task active/responsible for write fault
|
|
Temp_R0 DB ; Temp storage for R0
|
|
Temp_R1 DB ; Temp storage for R1
|
|
Temp_R2 DB ; Temp storage for R2
|
|
Temp_R3 DB ; Temp storage for R3
|
Task_Stacks DSB TSB_SIZE ; First location for stack data*
|
Task_Stacks DSB TSB_SIZE ; First location for stack data*
|
Free_Mem DSB FREE_SYS ; Unused memory in system region
|
Free_Mem DSB FREE_SYS ; Unused memory in system region
|
.ENDST
|
.ENDST
|
|
|
; * Note that this location is used to setup a pointer, which the task manager
|
; * Note that this location is used to setup a pointer, which the task manager
|
Line 931... |
Line 935... |
|
|
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
; ISR/Supervisory Mode Functions - Allows tasks to define up to 5 functions
|
; ISR/Supervisory Mode Functions - Allows tasks to define up to 5 functions
|
; that will operate in supervisor mode by calling a soft-int.
|
; that will operate in supervisor mode by calling a soft-int.
|
;
|
;
|
; Note 1: Due to assembler limitations, it is actually necessary for each task
|
; Note 1: that using these functions requires at least 5 free bytes of stack
|
|
;
|
|
; Note 2: Due to assembler limitations, it is actually necessary for each task
|
; to define all 5 sets of these macros, even if not used. These are defined
|
; to define all 5 sets of these macros, even if not used. These are defined
|
; in the pattern of TASKx_SPV_FUNCy, where x is the task number and
|
; in the pattern of TASKx_SPV_FUNCy, where x is the task number and
|
; y is the function 0-4.
|
; y is the function 0-4.
|
;
|
;
|
; Note 2: Task code for these functions should NOT use RTS or RTI, as this WILL
|
; Note 3: Task code for these functions should NOT use RTS or RTI, as this WILL
|
; corrupt their stacks and likely crash the whole system. These are intended
|
; corrupt their stacks and likely crash the whole system. These are intended
|
; for operations that are atomic in nature, or that require supervisor perms
|
; for operations that are atomic in nature, or that require supervisor perms
|
; due to write access (writing flags/messages to other tasks)
|
; due to write access (writing flags/messages to other tasks) Registers will
|
|
; be preserved in local system memory and restored prior to entering the stub
|
|
; effectively meaning that registers will retain their state through the
|
|
; function call. The state of system flags will NOT be retained, however.
|
;
|
;
|
; Note 3: These functions will run to completion (or hang) regardless of the
|
; Note 4: These functions will run to completion (or hang) regardless of the
|
; task timer, as interrupts can't pre-empt each other, so caution should be
|
; task timer, as interrupts can't pre-empt each other, so caution should be
|
; used with them. However, both the internal and external interrupt managers
|
; used with them. However, both the internal and external interrupt managers
|
; will latch incoming interrupts while these are running.
|
; will latch incoming interrupts while these are running.
|
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
|
|
; CREATE_SUPV_FUNC creates an individual supervisory task function, which is
|
; CREATE_SUPV_FUNC creates an individual supervisory task function, which is
|
; referenced in the ISR table. (EXEC_SUPVn is used in the interrupt table)
|
; referenced in the ISR table. (EXEC_SUPVn is used in the interrupt table)
|
|
|
.MACRO CREATE_SUPV_FUNC
|
.MACRO CREATE_SUPV_FUNC
|
EXEC_SUPV\@: BACKUP_FULL_CONTEXT
|
EXEC_SUPV\@: STA R0, TaskMgr.Temp_R0 ; Copy R0-R3 to local RAM, not stack
|
|
STA R1, TaskMgr.Temp_R1
|
|
STA R2, TaskMgr.Temp_R2
|
|
STA R3, TaskMgr.Temp_R3
|
|
|
REINIT_TASK_TABLE_PTR ; Setup R3:R2 to point to the task table
|
REINIT_TASK_TABLE_PTR ; Setup R3:R2 to point to the task table
|
|
|
LDO R2, SUPV_FN\@_ENTRY_HIGH
|
LDO R2, SUPV_FN\@_ENTRY_HIGH
|
PSH R0
|
PSH R0
|
|
|
LDO R2, SUPV_FN\@_ENTRY_LOW
|
LDO R2, SUPV_FN\@_ENTRY_LOW
|
PSH R0
|
PSH R0
|
|
|
|
LDA R3, TaskMgr.Temp_R3 ; Replace R0-R3 from local RAM so that
|
|
LDA R2, TaskMgr.Temp_R2 ; the stub has the same register space
|
|
LDA R1, TaskMgr.Temp_R1 ; as a function call - less the flag
|
|
LDA R0, TaskMgr.Temp_R0 ; state, which isn't preserved
|
|
|
RTS ; Use RTS to "return" to our jump addr
|
RTS ; Use RTS to "return" to our jump addr
|
|
|
_F\@_EXIT: RESTORE_FULL_CONTEXT
|
.REPEAT TASK_COUNT ; Create a stub for each task. The final
|
RTI
|
CREATE_F\@_FUNCTION_STUB ; RTI will be handled in the stubs
|
|
.ENDR
|
.ENDM
|
.ENDM
|
|
|
; CREATE_Fn_FUNCTION_STUB creates an entry point that is referenced in the
|
; CREATE_Fn_FUNCTION_STUB creates an entry point that is referenced in the
|
; TASK_PARAM_TABLE, and is "RTS JMP'ed" to by the code from CREATE_SUPV_FUNC.
|
; TASK_PARAM_TABLE, and is "RTS JMP'ed" to by the code from CREATE_SUPV_FUNC.
|
; Because RTS was used to reach the code generated in these blocks, a final
|
; Because RTS was used to reach the code generated in these blocks, a final
|
; JMP instruction will return to the calling supervisory function without
|
; JMP instruction will return to the calling supervisory function without
|
; disrupting the stack. (These aren't technically subroutines)
|
; disrupting the stack. (These aren't technically subroutines)
|
|
|
.MACRO CREATE_F0_FUNCTION_STUB
|
.MACRO CREATE_F0_FUNCTION_STUB
|
_F0_EXE_S\@: TASK\@_SUPV_FN0
|
_F0_EXE_S\@: TASK\@_SUPV_FN0 ; Run the stub code from the task
|
JMP _F0_EXIT
|
RTI ; Return from the interrupt
|
.ENDM
|
.ENDM
|
|
|
.MACRO CREATE_F1_FUNCTION_STUB
|
.MACRO CREATE_F1_FUNCTION_STUB
|
_F1_EXE_S\@: TASK\@_SUPV_FN1
|
_F1_EXE_S\@: TASK\@_SUPV_FN1 ; Run the stub code from the task
|
JMP _F1_EXIT
|
RTI ; Return from the interrupt
|
.ENDM
|
.ENDM
|
|
|
.MACRO CREATE_F2_FUNCTION_STUB
|
.MACRO CREATE_F2_FUNCTION_STUB
|
_F2_EXE_S\@: TASK\@_SUPV_FN2
|
_F2_EXE_S\@: TASK\@_SUPV_FN2 ; Run the stub code from the task
|
JMP _F2_EXIT
|
RTI ; Return from the interrupt
|
.ENDM
|
.ENDM
|
|
|
.MACRO CREATE_F3_FUNCTION_STUB
|
.MACRO CREATE_F3_FUNCTION_STUB
|
_F3_EXE_S\@: TASK\@_SUPV_FN3
|
_F3_EXE_S\@: TASK\@_SUPV_FN3 ; Run the stub code from the task
|
JMP _F3_EXIT
|
RTI ; Return from the interrupt
|
.ENDM
|
.ENDM
|
|
|
.MACRO CREATE_F4_FUNCTION_STUB
|
.MACRO CREATE_F4_FUNCTION_STUB
|
_F4_EXE_S\@: TASK\@_SUPV_FN4
|
_F4_EXE_S\@: TASK\@_SUPV_FN4 ; Run the stub code from the task
|
JMP _F4_EXIT
|
RTI ; Return from the interrupt
|
.ENDM
|
.ENDM
|
|
|
; INSTANCE_SUPV_FUNCS creates all 5 supervisory function entry points and a set
|
; INSTANCE_SUPV_FUNCS creates all 5 supervisory function entry points and a set
|
; of stub functions for each task and is used to place everything in ROM
|
; of stub functions for each task and is used to place everything in ROM
|
.MACRO INSTANCE_SUPV_FUNCS
|
.MACRO INSTANCE_SUPV_FUNCS
|
.REPEAT 5
|
.REPEAT 5
|
CREATE_SUPV_FUNC
|
CREATE_SUPV_FUNC
|
.ENDR
|
.ENDR
|
|
|
.REPEAT TASK_COUNT
|
|
CREATE_F0_FUNCTION_STUB
|
|
CREATE_F1_FUNCTION_STUB
|
|
CREATE_F2_FUNCTION_STUB
|
|
CREATE_F3_FUNCTION_STUB
|
|
CREATE_F4_FUNCTION_STUB
|
|
.ENDR
|
|
.ENDM
|
.ENDM
|
|
|
;------------------------------------------------------------------------------
|
;------------------------------------------------------------------------------
|
No newline at end of file
|
No newline at end of file
|