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

📄 tct.s

📁 Nucleus实时操作系统是Accelerater Technology公司开发的嵌入式RTOS产品,Nucleus的核心是一个实时的多任务内核——Nucleus PLUS
💻 S
📖 第 1 页 / 共 5 页
字号:
        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.  */
;
        ORI.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                                                                */
;/*                                                                       */
;/*      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        07-15-1993      Created initial version 1.0      */
;/*      D. Lamie        07-15-1993      Verified version 1.0             */
;/*                                                                       */
;/*************************************************************************/
        XDEF    _TCT_Control_To_Thread
_TCT_Control_To_Thread:
;VOID  TCT_Control_To_Thread(TC_TCB *thread)
;{
;
;    /* Setup the current thread pointer.  */
;    TCD_Current_Thread =  (VOID *) thread;
;
        MOVEA.L D0,A0                       ; Put thread pointer in A0
        MOVE.L  D0,_TCD_Current_Thread      ; Setup the current thread ptr
;
;    /* Increment the thread scheduled counter.  */
;    thread -> tc_scheduled++;
;
        ADDQ.L  #1,28(A0)                   ; Increment the scheduled count
;
;    /* Check for time slice option.  */
;    if (thread -> tc_cur_time_slice)
;    {
        TST.L   32(A0)                      ; Pickup time slice value
        BEQ.S   _TCT_No_Start_TS            ; If zero, don't start time slice
;
;        /* Start a time slice.  */
;        TMD_Time_Slice =        thread -> tc_cur_time_slice;
;        TMD_Time_Slice_State =  0;
;
        MOVE.L  32(A0),_TMD_Time_Slice      ; Otherwise, start time slice
        CLR.L   _TMD_Time_Slice_State       ;   by setting up the timer 
                                            ;   parameters
;    }
_TCT_No_Start_TS:
;
;    /* Pickup the stack pointer and resume the thread.  */
;    REG_Stack_Ptr =  thread -> tc_stack_pointer;
;
        MOVE.L  44(A0),A7                   ; Switch to thread's stack
;         
;     /* Pop off the saved information associated with the thread. After we
;        determine which type of stack is present.  A 1 on the top of the 
;        stack indicates an interrupt stack, while a 0 on the top of the
;        stack indicates a solicited type of stack.  */
;
        CMPI.W  #0,(A7)+                    ; Determine the type of stack
        BNE     _TCT_Interrupt_Return       ; If not 0, an interrupt stack
                                            ;   is present
        MOVEM.L (A7)+,D2-D7/A2-A6           ; Recover registers preserved 
                                            ;   compiler registers
        MOVE.W  SR,D0                       ; Pickup current SR
        AND.W   #$F8FF,D0                   ; Clear the interrupt lockout
        OR.W    _TCD_Interrupt_Level+2,D0   ; Or-in the interrupt enable level
        MOVE.W  D0,SR                       ; Setup SR with interrupt level
        RTS                                 ; Return to thread
;        
_TCT_Interrupt_Return:
;        
;     /* Remember that the interrupt level that is restored must represent
;        the interrupt level in TCD_Interrupt_Level.  */
        MOVE.W  64(A7),D0                   ; Get saved SR of the thread
        AND.W   #$F8FF,D0                   ; Clear the interrupt level 
        OR.W    _TCD_Interrupt_Level+2,D0   ; Or-in the interrupt enable level
        MOVE.W  D0,64(A7)                   ; Setup the interrupt SR
        MOVEM.L (A7)+,D0-D7/A0-A6           ; Recover all registers
        ADDQ.L  #4,A7                       ; Skip unused space
        RTE                                 ; Return from interrupt
;}
;
;
;
;/*************************************************************************/
;/*                                                                       */
;/* FUNCTION                                                              */
;/*                                                                       */
;/*      TCT_Control_To_System                                            */
;/*                                                                       */
;/* DESCRIPTION                                                           */
;/*                                                                       */
;/*      This function returns control from a thread to the system.  Note */
;/*      that this service is called in a solicited manner, i.e. it is    */
;/*      not called from an interrupt thread.  Registers required by the  */
;/*      compiler to be preserved across function boundaries are saved by */
;/*      this routine.  Note that this is usually a sub-set of the total  */
;/*      number of available registers.                                   */
;/*                                                                       */
;/* AUTHOR                                                                */
;/*                                                                       */
;/*      William E. Lamie, Accelerated Technology, Inc.                   */
;/*                                                                       */
;/* CALLED BY                                                             */
;/*                                                                       */
;/*      Other Components                                                 */
;/*                                                                       */
;/* CALLS                                                                 */
;/*                                                                       */
;/*      TCT_Schedule                        Schedule the next thread     */
;/*                                                                       */
;/* INPUTS                                                                */
;/*                                                                       */
;/*      None                                                             */
;/*                                                                       */
;/* OUTPUTS                                                               */
;/*                                                                       */
;/*      None                                                             */
;/*                                                                       */
;/* HISTORY                                                               */
;/*                                                                       */
;/*         NAME            DATE                    REMARKS               */
;/*                                                                       */
;/*      W. Lamie        07-15-1993      Created initial version 1.0      */
;/*      D. Lamie        07-15-1993      Verified version 1.0             */
;/*      W. Lamie        03-01-1994      Corrected problem in time-slice  */
;/*                                        reset logic, resulting in      */
;/*                                        version 1.1                    */
;/*      D. Lamie        03-01-1994      Verified version 1.1             */
;/*                                                                       */
;/*************************************************************************/
        XDEF    _TCT_Control_To_System
_TCT_Control_To_System:
;VOID  TCT_Control_To_System(void)
;{
;
;    /* Lockout interrupts.  */
;
        ORI.W   #LOCKOUT,SR                 ; Lockout interrupts
;    
;    /* Save a minimal context of the thread.  */
;
        MOVEM.L D2-D7/A2-A6,-(A7)           ; Save D2-D7 and A2-A6
        CLR.W   -(A7)                       ; Solicited type of stack
;
;    /* Setup a pointer to the thread control block.  */
;    REG_Thread_Ptr =  (TC_TCB *) TCD_Current_Thread;
;
        MOVEA.L _TCD_Current_Thread,A0      ; Thread pointer in A0
;
;    /* Clear the current thread control block pointer.  */
;    TCD_Current_Thread =  NU_NULL;
;
        CLR.L   _TCD_Current_Thread         ; Clear the current thread
;    
;    /* Check to see if a time slice is active.  If so, copy the original time
;       slice into the current time slice field of the task's control block. */
;    if (TMD_Time_Slice_State == 0)
;    {
        TST.L   _TMD_Time_Slice_State       ; Is a time slice active?
        BNE.S   _TCT_No_TS_Active_1         ; If non-zero, not active
;
;        /* Insure that the next time the task runs it gets a fresh time 
;           slice.  *

⌨️ 快捷键说明

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