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

📄 clp.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
        }
    }
    else
    {

        /* Store off the time in the remaining field.  */
        timer_ptr -> cl_remaining =  time;
        timer_ptr -> cl_ignore =     0;
    
        /* This is the only timer, update accordingly.  */
        CLP_Timer_Request =  time;

        /* Load the new timer value.  */
        CLD_Load_Timer(time);
    }
}                                           /* end of CLP_Start_Timer   */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "CLP_Stop_Timer"            */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function removes a timer from the ready list if it is      */
/*      active.  It is assumed that interrupts are disabled prior to    */
/*      this routine.                                                   */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Task timeout suspension routines                                */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      timer_id                            Timer identification        */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Active timer list                                               */
/*      CLP_Timer_Request                   Copy of CLP_Timer           */
/*                                                                      */
/************************************************************************/
void  CLP_Stop_Timer(unsigned int timer_id)
{

struct CL_TIMER_REQUEST_STRUCT *timer_ptr;  /* Timer pointer            */


    /* Point to the timer id request structure.  */
    timer_ptr =  &CLP_TR_List[timer_id];

    /* Remove the timer from the list.  */
    if (timer_ptr -> cl_next != NU_NULL)
       (timer_ptr -> cl_next) -> cl_previous =  timer_ptr -> cl_previous;
    if (timer_ptr -> cl_previous != NU_NULL)
       (timer_ptr -> cl_previous) -> cl_next =  timer_ptr -> cl_next;
           
    /* Adjust the head of the list if necessary.  */
    if (CLP_Active_List_Ptr ==  timer_ptr)
    {
    
        /* Adjust the timer linked-list head.  */
        CLP_Active_List_Ptr =  timer_ptr -> cl_next;
        
        /* Check for nothing left in the list.  */
        if (CLP_Active_List_Ptr == NU_NULL)
        
            /* Clear the timer request variable.  */
            CLP_Timer_Request =  0;
    }
            
    /* Clear the pointers.  */
    timer_ptr -> cl_next =      NU_NULL;
    timer_ptr -> cl_previous =  NU_NULL;
}                                           /* end of CLP_Stop_Timer    */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "CLP_Timer_Expiration"      */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function examines the active timer list for timer(s) that  */
/*      have expired and calls the appropriate routine to handle the    */
/*      timer expiration.  After expired timers have been processed,    */
/*      the next lowest timer is initiated.                             */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      CLD_Timer_Interrupt                 Target dependent clock      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      CLD_Load_Timer                      Load the timer              */
/*      SKP_Ready_Task                      Place task on ready list    */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      CLP_Timer_Request                   Last timer load value       */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Active timer list                                               */
/*      CLP_Timer_Request                   Copy of CLP_Timer           */
/*                                                                      */
/************************************************************************/
void  CLP_Timer_Expiration()

{

struct CL_TIMER_REQUEST_STRUCT *timer_ptr;  /* Timer pointer            */
struct CL_TIMER_REQUEST_STRUCT *temp_ptr;   /* Temporary timer pointer  */
unsigned int                    timer_req;  /* Last timer request value */

    /* Set up the new time pointer.  */
    timer_ptr =  CLP_Active_List_Ptr;

    /* Save the last timer request for use in the update of the list.  */
    timer_req =  CLP_Timer_Request;

    /* Clear the timer request.  This will be reset when another 
        active timer is left on the list.  */
    CLP_Timer_Request =  0;
            
    /* Walk through the list to process the expired timer(s).  */
    while(timer_ptr != NU_NULL)
    {
   
        /* Quickly check for any ignore time for a just-started timer.  */
        if (timer_ptr -> cl_ignore)
        {
        
            /* See if the ignore time is less than the elapsed time.  */
            if (timer_ptr -> cl_ignore < timer_req)
            {
            
                /* See if this timer request has been satisfied.  */
                if (timer_ptr -> cl_remaining <= 
                                (timer_req - (timer_ptr -> cl_ignore)))
                
                    /* Yes, the timer has been satisfied, clear the 
                       time remaining field.  */
                    timer_ptr -> cl_remaining =  0;
                else
                {
                
                    /* Adjust the remaining time and clear the ignore.  */
                    timer_ptr -> cl_remaining = 
                            timer_ptr -> cl_remaining -
                                       (timer_req - timer_ptr -> cl_ignore);
                    timer_ptr -> cl_ignore =  0;
                }
            }
            else
            
                /* Just decrement the ignore time, since the current timer
                   expiration is less.  */
                timer_ptr -> cl_ignore =  timer_ptr -> cl_ignore - timer_req;
        }
        else if (timer_ptr -> cl_remaining <= timer_req)
        
            /* Clear the remaining field since the timer has expired.  */
            timer_ptr -> cl_remaining =  0;
        else
        
            /* Decrement the remaining field by the elapsed time.  */
            timer_ptr -> cl_remaining =  timer_ptr -> cl_remaining - timer_req;
            
        /* Check for timer expiration.  */
        if (timer_ptr -> cl_remaining == 0)
        {
        
            /* A task timer has expired.  That means that the task needs
               to be resumed.  */
            SKP_Ready_Task(timer_ptr -> cl_timer_id);
            
            /* Unlink this timer request from the list.  */
            if (timer_ptr -> cl_next != NU_NULL)
               (timer_ptr -> cl_next) -> cl_previous =  
                                               timer_ptr -> cl_previous;
            if (timer_ptr -> cl_previous != NU_NULL)
                (timer_ptr -> cl_previous) -> cl_next =  timer_ptr -> cl_next;
           
            /* Adjust the head of the list if necessary.  */
            if (CLP_Active_List_Ptr ==  timer_ptr)
            {

                /* Update the head of the list.  */
                CLP_Active_List_Ptr =  timer_ptr -> cl_next;
            }

            /* Save the next pointer.  */
            temp_ptr =  timer_ptr -> cl_next;

            /* Clear the pointers.  */
            timer_ptr -> cl_next =      NU_NULL;
            timer_ptr -> cl_previous =  NU_NULL;

            /* Look at the next timer.  */
            timer_ptr =  temp_ptr;
        }
        else
        {

            /* Check for the lowest timer value?  */
            if ((timer_ptr -> cl_remaining < CLP_Timer_Request) ||
                (CLP_Timer_Request == 0))
            {

                /* New low value found.  */
                CLP_Timer_Request =  timer_ptr -> cl_remaining;
            }

            /* Point to the next entry.  */
            timer_ptr =  timer_ptr -> cl_next;
        }
    }

    /* If the CLP_Timer_Request has a value load it.  */
    if (CLP_Timer_Request)
    {
        /* Load the timer request value into the timer.  */
        CLD_Load_Timer(CLP_Timer_Request);
    }
}                                           /* end of CLP_Timer_Expiration */

⌨️ 快捷键说明

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