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

📄 nu.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 5 页
字号:

        /* Check to see if we have anything.  */
        if ((status == NU_QUEUE_EMPTY) && (wait_timeout != NU_NO_TIMEOUT))
        {
        
            /* Get the task_id.  */
            task_id =  SKP_Get_Task_ID();
        
            /* Check for a valid task ID.  */
            if (task_id != NU_SYSTEM)
            {
            
                /* Check for a timeout request.  */
                if (wait_timeout != NU_WAIT_FOREVER)
                {
                
                    /* A timeout is requested, call "CLP_Start_Timer" to 
                       start the timer for this operation.  */
                    CLP_Start_Timer(task_id, wait_timeout);
                }

                /* Wait for something to appear in the queue.  */
                status =  QM_Wait_To_Retrieve_Mult(task_id, 
                                              queue_id_1, 
                                              queue_id_2,
                                              queue_id_3,
                                              destination_ptr);

                /* Check to see if we need to delete a previously scheduled
                   timer.  */
                if ((wait_timeout != NU_WAIT_FOREVER) && 
                    (status != NU_QUEUE_TIMEOUT))
                {

                    /* Delete the previously scheduled timeout.  */
                    CLP_Stop_Timer(task_id);
                }
            }
        }        
    }

    /* Restore previous interrupt level.  */
    IND_Set_Interrupt_Level(interrupt_level);

    /* Return the status to caller.  */
    return(status);
}                                           /* end of NU_Retrieve_Item  */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                             "NU_Force_Item_In_Front"       */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to place an item in the front of a queue. */
/*      If the queue is full, the last item put in the queue is         */
/*      overwritten.                                                    */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Application Routines                                            */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      DS_Make_History_Entry               Make an history entry       */
/*      QM_Force_Item_In_Front              Place an item in front of Q */
/*      IND_Set_Interrupt_Level             Disable/Enable interrupts   */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      queue_id                            Queue to send to            */
/*      source_ptr                          Pointer to source area      */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      Queue                                                           */
/*      return(status)                      Status of request           */
/*                                                                      */
/************************************************************************/
signed int  NU_Force_Item_In_Front(signed int queue_id,
             unsigned int *source_ptr)
{

int                interrupt_level;         /* Saved interrupt level    */
signed int         status;                  /* Return status            */

    /* Make an entry in the history table, if the conditional compilation
       flag is set.  */
    #ifdef  NU_ENABLE_HISTORY
    DS_Make_History_Entry(NU_HIST_NU_FORCE_ITEM_IN_FRONT,
                                           (unsigned int) queue_id,
                                           (unsigned int) source_ptr);
    #endif

    /* Lock out interrupts while checking.  */
    interrupt_level =  IND_Set_Interrupt_Level(NU_DISABLE_INTERRUPTS);
    
    /* Check for a valid queue entry.  */
    if ((queue_id >= 0) && (queue_id < NU_Total_Queues))
    {
    
        /* Call "QM_Force_Item_In_Front" to place an item in the front
           of the queue.  */
        status =  QM_Force_Item_In_Front(queue_id, source_ptr);
    }
    else
     
        /* Invalid queue id, status as such.  */
        status =  NU_INVALID_QUEUE;

    /* Restore previous interrupt level.  */
    IND_Set_Interrupt_Level(interrupt_level);

    /* Return the status to caller.  */
    return(status);
}                                           /* end of NU_Force_Item_In_Front */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                             "NU_Sleep"                     */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to suspend a process for a specific       */
/*      number of clock ticks.  Clock ticks are defined by how the      */
/*      clock dependent code is implemented.                            */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  DATE CREATED                                                        */
/*                                                                      */
/*      April 16, 1990                                                  */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      DS_Make_History_Entry               Make an history entry       */
/*      SKP_Get_Task_ID                     Get the current task ID     */
/*      CLP_Start_Timer                     Start a system timer        */
/*      SKP_Suspend_Task                    Suspend the task            */
/*      IND_Set_Interrupt_Level             Disable/Enable interrupts   */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      time_ticks                          Time (in clicks) to wait    */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                      Status of request           */
/*                                                                      */
/************************************************************************/
signed int  NU_Sleep(unsigned int time_ticks)
{

signed int         task_id;                 /* Current task's ID        */
int                interrupt_level;         /* Saved interrupt level    */
signed int         status;                  /* Return status            */

    /* Make an entry in the history table, if the conditional compilation
       flag is set.  */
    #ifdef  NU_ENABLE_HISTORY
    DS_Make_History_Entry(NU_HIST_NU_SLEEP, 
                                           (unsigned int) time_ticks, 
                                           (unsigned int) 0);
    #endif

    /* Initialize the return value.  */
    status =  NU_SUCCESS;

    /* Lock out interrupts while checking.  */
    interrupt_level =  IND_Set_Interrupt_Level(NU_DISABLE_INTERRUPTS);
    
    /* Get the current task's task ID.  */
    task_id =  SKP_Get_Task_ID();
    
    /* Schedule a timer for the sleep request amount.  */
    CLP_Start_Timer(task_id, time_ticks);
    
    /* Suspend this task for time.  */
    status =  SKP_Suspend_Task(task_id, NU_TIME_SUSPEND);

    /* Restore interrupt level prior to the call.  */
    IND_Set_Interrupt_Level(interrupt_level);

    /* Return the status to caller.  */
    return(status);
}                                           /* end of NU_Sleep          */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                             "NU_Relinquish"                */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function is used to place this task at the end of the      */
/*      list of ready tasks.                                            */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Application Routines                                            */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      DS_Make_History_Entry               Make an history entry       */
/*      SKP_Move_To_End                     Move task to end of chain   */
/*      SKD_Leave_Task                      Leave the task              */
/*      IND_Set_Interrupt_Level             Disable/Enable interrupts   */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                      Status of request           */
/*                                                                      */
/************************************************************************/
signed int  NU_Relinquish()

{

int                interrupt_level;         /* Saved interrupt level    */

    /* Make an entry in the history table, if the conditional compilation
       flag is set.  */
    #ifdef  NU_ENABLE_HISTORY
    DS_Make_History_Entry(NU_HIST_NU_RELINQUISH, 0, 0);
    #endif

    /* Lock out interrupts while checking.  */
    interrupt_level =  IND_Set_Interrupt_Level(NU_DISABLE_INTERRUPTS);

⌨️ 快捷键说明

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