📄 tct.s
字号:
; Clear the thread waiting flag.
MOV r3,#0
STR r3,[r0, #TC_THREAD_WAIT] ; Clear the thread waiting flag
; Save the protection pointer in the thread's control block.
STR r0,[r1, #TC_CURRENT_PROTECT]
; Restore interrupts to entry level
LDMIA sp!,{r2}
MSR CPSR_cxsf,r2
TCT_Skip_Protect
; Return to caller
BX lr
;************************************************************************
;*
;* FUNCTION
;*
;* TCT_Unprotect
;*
;* DESCRIPTION
;*
;* This function releases protection of the currently active
;* thread. If the caller is not an active thread, then this
;* request is ignored.
;*
;* CALLED BY
;*
;* Application
;* System Components
;*
;* CALLS
;*
;* None
;*
;* INPUTS
;*
;* None
;*
;* OUTPUTS
;*
;* None
;*
;* REGISTERS MODIFIED
;*
;* r0, r1, r2, r3
;*
;* HISTORY
;*
;* NAME DATE REMARKS
;*
;* Driscoll, D 01/24/2003 Released Version 1.14.1
;************************************************************************
;VOID TCT_Unprotect(void)
EXPORT TCT_Unprotect
TCT_Unprotect
; Determine if the caller is in a task or HISR thread.
LDR r1,TCT_Current_Thread1 ; Pickup current thread ptr address
LDR r1,[r1] ; Pickup current thread pointer
CMP r1,#0 ; Check to see if it is non-NULL
BEQ TCT_Skip_Unprotect ; If NULL, skip unprotection
; Lockout interrupts.
MRS r2,CPSR ; Pickup current CPSR
STMDB sp!,{r2} ; Save CPSR on stack
ORR r2,r2,#LOCKOUT ; Place lockout value in
MSR CPSR_cxsf,r2 ; Lockout interrupts
; Determine if there is a currently active protection.
LDR r0,[r1, #TC_CURRENT_PROTECT] ; Pickup current protect field
CMP r0,#0 ; Is there a protection in force?
BEQ TCT_Not_Protected ; If not, nothing to unprotect
; Check for a higher priority thread waiting for the protection structure.
LDR r2,[r0, #TC_THREAD_WAIT] ; Pickup thread waiting flag
CMP r2,#0 ; Are there any threads waiting?
BEQ TCT_Not_Waiting_Unpr ; If not, just release protection
; Save link register
STMDB sp!,{lr}
; Transfer control to the system. Note that this
; automatically clears the current protection
BL TCT_Control_To_System ; Return control to the system
; Restore link register
LDMIA sp!,{lr}
B TCT_Not_Protected
TCT_Not_Waiting_Unpr
; Clear the protection.
MOV r2,#0 ; Build NU_NULL value
STR r2,[r0, #TC_TCB_PTR] ; Release the protection
STR r2,[r1, #TC_CURRENT_PROTECT] ; Clear protection pointer in the
; control block
TCT_Not_Protected
; Restore interrupts from stack
LDMIA sp!,{r1}
MSR CPSR_cxsf,r1
TCT_Skip_Unprotect
; Return to caller
BX lr
;************************************************************************
;*
;* FUNCTION
;*
;* TCT_Unprotect_Specific
;*
;* DESCRIPTION
;*
;* This function releases a specific protection structure.
;*
;* CALLED BY
;*
;* Application
;* System Components
;*
;* CALLS
;*
;* TCT_Schedule
;*
;* INPUTS
;*
;* r0 - Pointer to protection block
;*
;* OUTPUTS
;*
;* None
;*
;* REGISTERS MODIFIED
;*
;* r1, r2, r3, sp
;*
;* HISTORY
;*
;* NAME DATE REMARKS
;*
;* Driscoll, D 01/24/2003 Released Version 1.14.1
;************************************************************************
;VOID TCT_Unprotect_Specific(TC_PROTECT *protect)
EXPORT TCT_Unprotect_Specific
TCT_Unprotect_Specific
; Determine if the caller is in a task or HISR thread.
LDR r1,TCT_Current_Thread1 ; Pickup current thread ptr address
LDR r3,[r1] ; Pickup current thread pointer
CMP r3,#0 ; Check to see if it is non-NULL
BEQ TCT_Skip_Unprot_Spec ; If NULL, skip unprotect specific
; Lockout interrupts.
MRS r3,CPSR ; Pickup current CPSR
ORR r2,r3,#LOCKOUT ; Place lockout value in
MSR CPSR_cxsf,r2 ; Lockout interrupts
; Clear the protection pointer.
MOV r2,#0 ; Build NU_NULL value
STR r2,[r0, #TC_TCB_PTR] ; Clear protection ownership
; Determine if a thread is waiting.
LDR r2,[r0, #TC_THREAD_WAIT] ; Pickup the waiting field
CMP r2,#0 ; Is there another thread waiting?
BEQ TCT_Not_Waiting_Unspec ; No, restore interrupts and return
; Save a minimal context of the thread on the current stack.
STMDB sp!,{r4-r12,lr}
; Check to see if caller was in THUMB mode
; and update saved CPSR accordingly
TST lr,#1 ; Check bit 0 (set if THUMB mode)
ORRNE r3,r3,#THUMB_BIT ; Set THUMB bit if caller in THUMB mode
; Save CPSR on stack (with caller's lock-out bits / mode set correctly)
STR r3,[sp, #-4]!
; Place the solicited stack type value on the top of the stack
MOV r2,#0 ; Build solicited stack type value
STR r2,[sp, #-4]! ; Place it on the top of the stack
; Setup a pointer to the thread control block and clear the current
; thread control block pointer.
LDR r1,TCT_Current_Thread1 ; Pickup current thread ptr address
LDR r0,[r1] ; Pickup current thread pointer
STR r2,[r1] ; Set current thread pointer to NU_NULL
; Check to see if a time slice is active.
LDR r3,TCT_Slice_State ; Pickup time slice state address
LDR r1,[r3] ; Pickup time slice state flag
CMP r1,#0 ; Compare with active value
BNE TCT_No_Stop_TS_3 ; If non-active, don't disable
; Insure that the next time the task runs it gets a fresh time slice
LDR r1,[r0, #TC_TIME_SLICE] ; Pickup original time slice
STR r1,[r0, #TC_CUR_TIME_SLICE] ; Reset current time slice
; Set the time-slice state to NOT_ACTIVE.
MOV r2,#1 ; Build disable value
STR r2,[r3] ; Disable time slice
TCT_No_Stop_TS_3
; Save off the current stack pointer in the control block.
STR sp,[r0, #TC_STACK_POINTER]
; Switch to the system stack.
LDR r1,TCT_System_Stack ; Pickup address of stack pointer
LDR r2,TCT_System_Limit1 ; Pickup address of stack limit ptr
LDR sp,[r1] ; Switch to system stack
LDR r10,[r2] ; Setup system stack limit
; Finished, return to the scheduling loop
B TCT_Schedule
TCT_Not_Waiting_Unspec
; Restore interrupts to original level
MSR CPSR_cxsf,r3
TCT_Skip_Unprot_Spec
; Return to caller.
BX lr
;************************************************************************
;*
;* FUNCTION
;*
;* TCT_Set_Current_Protect
;*
;* DESCRIPTION
;*
;* This function sets the current protection field of the current
;* thread's control block to the specified protection pointer.
;*
;* CALLED BY
;*
;* TCC_Resume_Task Resume task function
;*
;* CALLS
;*
;* None
;*
;* INPUTS
;*
;* r0 - Pointer to protection block
;*
;* OUTPUTS
;*
;* None
;*
;* REGISTERS MODIFIED
;*
;* r1
;*
;* HISTORY
;*
;* NAME DATE REMARKS
;*
;* Driscoll, D 01/24/2003 Released Version 1.14.1
;************************************************************************
;VOID TCT_Set_Current_Protect(TC_PROTECT *protect)
EXPORT TCT_Set_Current_Protect
TCT_Set_Current_Protect
; Determine if the caller is in a task or HISR thread.
LDR r1,TCT_Current_Thread1 ; Pickup current thread ptr address
LDR r1,[r1] ; Pickup current thread pointer
CMP r1,#0 ; Check to see if a thread is active
; If the caller is in a task or HISR, modify the current protection.
STRNE r0,[r1, #TC_CURRENT_PROTECT]
; Return to caller.
BX lr
;************************************************************************
;*
;* FUNCTION
;*
;* TCT_Protect_Switch
;*
;* DESCRIPTION
;*
;* This function waits until a specific task no longer has any
;* protection associated with it. This is necessary since task's
;* cannot be suspended or terminated unless they have released all
;* of their protection.
;*
;* CALLED BY
;*
;* System Components
;*
;* CALLS
;*
;* None
;*
;* INPUTS
;*
;* r0 - Pointer to protection block
;*
;* OUTPUTS
;*
;* None
;*
;* REGISTERS MODIFIED
;*
;* r0, r1
;*
;* HISTORY
;*
;* NAME DATE REMARKS
;*
;* Driscoll, D 01/24/2003 Released Version 1.14.1
;************************************************************************
;VOID TCT_Protect_Switch(TC_TCB *task)
EXPORT TCT_Protect_Switch
TCT_Protect_Switch
; Lockout interrupts.
MRS r1,CPSR ; Pickup current CPSR
STMDB sp!,{r1} ; Save CPSR on stack
TCT_Swtich_Loop
ORR r1,r1,#LOCKOUT ; Place lockout value in
MSR CPSR_cxsf,r1 ; Lockout interrupts
; Wait until the specified task has no protection associated with it.
LDR r1,[r0, #TC_CURRENT_PROTECT] ; Pickup protection of specified thread
CMP r1,#0 ; Does the specified thread have
; an active protection?
BEQ TCT_Switch_Done ; If not, protect switch is done
; Indicate that a higher priority thread is waiting.
MOV r2,#1 ; Build waiting flag value
STR r2,[r1, #TC_THREAD_WAIT] ; Set waiting flag
; Save r0 and lr on stack
STMDB sp!,{r0,lr}
; Get address of thread holding protection
LDR r0,[r1, #TC_TCB_PTR]
; Schedule the protected thread
BL TCT_Schedule_Protected
; Restore registers
LDMIA sp!,{r0,lr}
; Pickup current CPSR
MRS r1,CPSR
; Keep looping until switch complete (protection free)
B TCT_Swtich_Loop
TCT_Switch_Done
; Restore interrupts.
LDMIA sp!,{r1} ; Get saved CPSR off stack
MSR CPSR_cxsf,r1 ; restore CPSR
; Return to caller
BX lr
;************************************************************************
;*
;* FUNCTION
;*
;*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -