📄 tct.s
字号:
; /* Determine if there is a current thread. */
; if (thread)
; {
;
CMP a1,#0 ; Determine if a thread is active
MOV a4,#0 ; Default remaining value
BEQ TCT_Skip_Stack_Check ; If NU_NULL, skip stack checking
;
; /* Determine if the stack pointers are out of range. */
; if ((thread -> tc_stack_pointer < thread -> tc_stack_start) ||
; (thread -> tc_stack_pointer > thread -> tc_stack_end))
;
LDR a3,[a1,#&24] ; Pickup start of stack area
CMP sp,a3 ; Compare with current stack ptr
BLT TCT_Stack_Range_Error ; If less, stack is out of range
LDR a2,[a1,#&28] ; Pickup end of stack area
CMP sp,a2 ; Compare with current stack ptr
BLE TCT_Stack_Range_Okay ; If less, stack range is okay
;
; /* Stack overflow condition exits. */
; ERC_System_Error(NU_STACK_OVERFLOW);
;
TCT_Stack_Range_Error
;
STR lr,[sp, #4]! ; Store lr on the stack
MOV a1,#3 ; Build NU_STACK_OVERFLOW code
[ THUMB
LDR a4,=ERC_System_Error ; Call system error handler. Note:
BX a4 ; control is not returned!
; ; Examine stack to find return
; ; address of this routine.
|
BL ERC_System_Error ; Call system error handler. Note:
; ; control is not returned!
; ; Examine stack to find return
; ; address of this routine.
]
TCT_Stack_Range_Okay
;
; /* Calculate the amount of available space on the stack. */
; remaining = (BYTE_PTR) thread -> tc_stack_pointer -
; (BYTE_PTR) thread -> tc_stack_start;
;
SUB a4,sp,a3 ; Calculate remaining stack size
;
; /* Determine if there is enough memory on the stack to save all of the
; registers. */
; if (remaining < 80)
;
CMP a4,#80 ; Is there enough room for an
; interrupt frame?
BCS TCT_No_Stack_Error ; If so, no stack overflow yet
;
; /* Stack overflow condition is about to happen. */
; ERC_System_Error(NU_STACK_OVERFLOW);
;
STR lr,[sp, #4]! ; Store lr on the stack
MOV a1,#3 ; Build NU_STACK_OVERFLOW code
[ THUMB
LDR a4,=ERC_System_Error ; Call system error handler. Note:
BX a4 ; control is not returned!
; ; Examine stack to find return
; ; address of this routine.
|
BL ERC_System_Error ; Call system error handler. Note:
; ; control is not returned!
; ; Examine stack to find return
; ; address of this routine.
]
TCT_No_Stack_Error
;
; /* Determine if this is a new minimum amount of stack space. */
; if (remaining < thread -> tc_stack_minimum)
;
LDR a3,[a1,#&34]
CMP a4,a3
STRCC a4,[a1,#&34]
;
; /* Save the new stack minimum. */
; thread -> tc_stack_minimum = remaining;
; }
; else
;
; /* Set the remaining bytes to 0. */
; remaining = 0;
;
; /* Return the remaining number of bytes on the stack. */
; return(remaining);
;
TCT_Skip_Stack_Check
MOV a1,a4 ; Return remaining bytes
[ THUMB
BX lr ; Return to caller
|
MOV pc,lr ; Return to caller
]
;}
;
;
;
;/*************************************************************************/
;/* */
;/* FUNCTION */
;/* */
;/* TCC_Schedule */
;/* */
;/* DESCRIPTION */
;/* */
;/* This function waits for a thread to become ready. Once a thread */
;/* is ready, this function initiates a transfer of control to that */
;/* thread. */
;/* */
;/* AUTHOR */
;/* */
;/* William E. Lamie, Accelerated Technology, Inc. */
;/* */
;/* CALLED BY */
;/* */
;/* INC_Initialize Main initialization routine */
;/* */
;/* CALLS */
;/* */
;/* TCT_Control_To_Thread Transfer control to a thread */
;/* */
;/* INPUTS */
;/* */
;/* TCD_Execute_Task Pointer to task to execute */
;/* */
;/* OUTPUTS */
;/* */
;/* None */
;/* */
;/* HISTORY */
;/* */
;/* NAME DATE REMARKS */
;/* */
;/* W. Lamie 02-15-1994 Created initial version 1.0 */
;/* D. Lamie 02-15-1994 Verified version 1.0 */
;/* */
;/*************************************************************************/
;VOID TCT_Schedule(void)
;{
EXPORT TCT_Schedule
TCT_Schedule
;
; /* Restore interrupts according to the value contained in
; TCD_Interrupt_Level. */
;
LDR a2,[pc, #Int_Level-.-8] ; Build address of interrupt level
MRS a1,CPSR ; Pickup current CPSR
LDR a3,[a2, #0] ; Pickup current interrupt lockout
BIC a1,a1,#LOCK_MSK ; Clear the interrupt lockout bits
ORR a1,a1,a3 ; Build new interrupt lockout CPSR
MSR CPSR_cxsf,a1 ; Setup new CPSR
LDR a3,[pc, #Execute_HISR-.-8] ; Pickup TCD_Execute_HISR address
LDR a4,[pc, #Execute_Task-.-8] ; Pickup TCD_Execute_Task address
;
; /* Wait until a thread (task or HISR) is available to execute. */
; do
; {
TCT_Schedule_Loop
;
; } while ((!TCD_Execute_HISR) && (!TCD_Execute_Task));
;
LDR a1,[a3, #0] ; Pickup highest priority HISR ptr
CMP a1,#0 ; Is there a HISR active?
BNE TCT_Schedule_Thread ; Found an HISR
LDR a1,[a4, #0] ; Pickup highest priority Task ptr
CMP a1,#0 ; Is there a task active?
BEQ TCT_Schedule_Loop ; If not, continue the search
;
; /* Yes, either a task or an HISR is ready to execute. Lockout
; interrupts while the thread is transferred to. */
;
TCT_Schedule_Thread
MRS a2,CPSR ; Pickup CPSR again
ORR a2,a2,#LOCKOUT ; Build interrupt lockout value
MSR CPSR_cxsf,a2 ; Lockout interrupts
;
; /* Transfer control to the thread by falling through to the following
; routine. */
;}
;
;
;
;/*************************************************************************/
;/* */
;/* FUNCTION */
;/* */
;/* TCT_Control_To_Thread */
;/* */
;/* DESCRIPTION */
;/* */
;/* This function transfers control to the specified thread. Each */
;/* time control is transferred to a thread, its scheduled counter */
;/* is incremented. Additionally, time-slicing for task threads is */
;/* enabled in this routine. The TCD_Current_Thread pointer is */
;/* setup by this function. */
;/* */
;/* AUTHOR */
;/* */
;/* William E. Lamie, Accelerated Technology, Inc. */
;/* */
;/* CALLED BY */
;/* */
;/* TCT_Schedule Indirectly called */
;/* TCT_Protect Protection task switch */
;/* */
;/* CALLS */
;/* */
;/* None */
;/* */
;/* INPUTS */
;/* */
;/* thread Thread control block pointer */
;/* */
;/* OUTPUTS */
;/* */
;/* None */
;/* */
;/* HISTORY */
;/* */
;/* NAME DATE REMARKS */
;/* */
;/* W. Lamie 02-15-1994 Created initial version 1.0 */
;/* D. Lamie 02-15-1994 Verified version 1.0 */
;/* */
;/*************************************************************************/
;VOID TCT_Control_To_Thread(TC_TCB *thread)
;{
EXPORT TCT_Control_To_Thread
TCT_Control_To_Thread
;
; /* Setup the current thread pointer. */
; TCD_Current_Thread = (VOID *) thread;
;
LDR a2,[pc,#Current_Thread-.-8]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -