⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tct.s

📁 mcf5307实验源代码
💻 S
📖 第 1 页 / 共 5 页
字号:
;/* DESCRIPTION                                                           */
;/*                                                                       */
;/*      This function checks the current stack for overflow conditions.  */
;/*      Additionally, this function keeps track of the minimum amount    */
;/*      of stack space for the calling thread and returns the current    */
;/*      available stack space.                                           */
;/*                                                                       */
;/* AUTHOR                                                                */
;/*                                                                       */
;/*      Barry Sellew, Accelerated Technology, Inc.                       */
;/*                                                                       */
;/* CALLED BY                                                             */
;/*                                                                       */
;/*      TCC_Send_Signals                    Send signals to a task       */
;/*                                                                       */
;/* CALLS                                                                 */
;/*                                                                       */
;/*      ERC_System_Error                    System error handler         */
;/*                                                                       */
;/* INPUTS                                                                */
;/*                                                                       */
;/*      None                                                             */
;/*                                                                       */
;/* OUTPUTS                                                               */
;/*                                                                       */
;/*      available bytes in stack                                         */
;/*                                                                       */
;/* HISTORY                                                               */
;/*                                                                       */
;/*         NAME            DATE                    REMARKS               */
;/*                                                                       */
;/*      B. Sellew       02-21-1997      Created and verified version 1.0 */                                               */
;/*                                                                       */
;/*************************************************************************/
        XDEF    _TCT_Check_Stack
_TCT_Check_Stack:
;UNSIGNED  TCT_Check_Stack(void)
;{
;
;TC_TCB         *thread;
;UNSIGNED       remaining;
;
;    /* Pickup the current task/HISR pointer.  */
;    thread =  (TC_TCB *) TCD_Current_Thread;
;
;    /* Determine if there is a current thread.  */
;    if (thread)
;    {
;
        MOVE.L  _TCD_Current_Thread,D0      ; Pickup current thread pointer
        BEQ     _TCT_No_Stack_Check         ; If task or HISR, skip stack check
        MOVEA.L D0,A0                       ; Point at the thread control block
;
;        /* 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))
;
        MOVE.L  A7,D0                       ; Pickup the stack pointer
        CMP.L   36(A0),D0                   ; Compare with end of stack addr
        BCS     _TCT_Stack_Overflow         ; Stack overflow condition
        CMP.L   40(A0),D0                   ; Compare with start of stack addr
        BLS     _TCT_No_Stack_Overflow      ; If within limits, no overflow
;
;            /* Stack overflow condition exits.  */
;            ERC_System_Error(NU_STACK_OVERFLOW);
;
_TCT_Stack_Overflow:
        PEA     3                           ; Put NU_STACK_OVERFLOW on stack
        JSR     _ERC_System_Error           ; Call system error handler
;
_TCT_No_Stack_Overflow:
;
;        /* Calculate the amount of available space on the stack.  */
;        remaining =  (BYTE_PTR) thread -> tc_stack_pointer -
;                          (BYTE_PTR) thread -> tc_stack_start;
;
        SUB.L   36(A0),D0                   ; Calculate the remaining amount of
                                            ;   stack space
;
;        /* Determine if there is enough memory on the stack to save all of the
;           registers.  */
;        if (remaining < 40)
;
        CMPI.L  #40,D0                      ; Compare with a minimal amount of
                                            ;   stack space to save context
        BGT     _TCT_Min_Available          ; If remaining is greater, all is
                                            ;   still okay
;
;            /* Stack overflow condition is about to happen.  */
;            ERC_System_Error(NU_STACK_OVERFLOW);
;
        PEA     3                           ; Put NU_STACK_OVERFLOW on stack
        JSR     _ERC_System_Error           ; Call system error handler
;
_TCT_Min_Available:
;
;        /* Determine if this is a new minimum amount of stack space.  */
;        if (remaining < thread -> tc_stack_minimum)
;
        CMP.L   52(A0),D0                   ; Determine if a new minimum has
                                            ;   been found
        BCC     _TCT_Stack_Check_Finished   ; No, stack checking is finished
;
;            /* Save the new stack minimum.  */
;            thread -> tc_stack_minimum =  remaining;
;
        MOVE.L  D0,52(A0)                   ; Save new minimum
        BRA     _TCT_Stack_Check_Finished   ; Finished
;
;    }
;    else
_TCT_No_Stack_Check:
;
;        /* Set the remaining bytes to 0.  */
;        remaining =  0;
;
        CLR.L   D0                          ; Clear return value
;
_TCT_Stack_Check_Finished:
;
;    /* Return the remaining number of bytes on the stack.  */
;    return(remaining);
;
        RTS                                 ; 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                                                                */
;/*                                                                       */
;/*      Barry Sellew, 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               */
;/*                                                                       */
;/*      B. Sellew       02-21-1997      Created and verified version 1.0 */                                               */
;/*                                                                       */
;/*************************************************************************/
        XDEF    _TCT_Schedule
_TCT_Schedule:
;VOID  TCT_Schedule(void)
;{
;
;    /* Restore interrupts according to the value contained in 
;       TCD_Interrupt_Level.  */
;
        MOVE.W  SR,D0                       ; Pickup current SR
	AND.L	#$0000F8FF,D0               ; Clear the interrupt lockout
	OR.L	_TCD_Interrupt_Level,D0     ; Or-in the interrupt enable level
        MOVE.W  D0,SR                       ; Setup SR with interrupt level
;
;    /* Wait until a thread (task or HISR) is available to execute.  */
;    do
;    {
;
_TCT_Scheduling_Loop:
;
;    } while ((!TCD_Execute_HISR) && (!TCD_Execute_Task));
;
        MOVE.L  _TCD_Execute_HISR,D0        ; Pickup the HISR pointer
        BNE.S   _TCT_Schedule_Thread        ; If not NULL, found an HISR
        MOVE.L  _TCD_Execute_Task,D0        ; Pickup the Task pointer
        BEQ.S   _TCT_Scheduling_Loop        ; Keep checking if task pointer is
                                            ;   also NULL
_TCT_Schedule_Thread:
;
;    /* Yes, either a task or an HISR is ready to execute.  Lockout 
;       interrupts while the thread is transferred to.  */
;
	MOVE.W	#LOCKOUT,SR                 ; 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                                                                */
;/*                                                                       */
;/*      Barry Sellew, Accelerated Technology, Inc.                       */
;/*                                                                       */
;/* CALLED BY                                                             */
;/*                                                                       */
;/*      TCT_Schedule                        Indirectly called            */
;/*      TCT_Protect                         Protection task switch       */
;/*                                                                       */
;/* CALLS                                                                 */
;/*                                                                       */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -