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

📄 qm.c

📁 NecluesRTX RTOS的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*      a single queue.                                                 */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that wait for queue items                      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      QM_Place_On_List                    Place a suspend block on lst*/
/*      QM_Remove_From_List                 Remove suspend block        */
/*      SKP_Suspend_Task                    Suspend the task            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      task_id                             Task identification         */
/*      queue_id                            Queue identification        */
/*      destination_ptr                     Pointer to destination item */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                                                  */
/*                                                                      */
/************************************************************************/
signed int  QM_Wait_To_Retrieve(signed int task_id, signed int queue_id,
             unsigned int *destination_ptr)
{

struct QM_QUEUE_CONTROL_STRUCT  
                  *QCB_ptr;                 /* Pointer to QCB entry     */
struct QM_SUSPENSION_STRUCT  
                   suspend_block;           /* Suspension control block */
signed int         status;                  /* Status of request        */
    

    /* Build a pointer to the queue control block.  */
    QCB_ptr =  &QM_QCB_List[queue_id];

    /* Initialize the status variable as NU_QUEUE_TIMEOUT.  */
    status =  NU_QUEUE_TIMEOUT;

    /* Build suspension structure.  */
    suspend_block.qm_susp_type =    QM_SINGLE;
    suspend_block.qm_task_id =      task_id;
    suspend_block.qm_QCB_ptr =      QCB_ptr;
    suspend_block.qm_return_addr =  &status;
    suspend_block.qm_item_ptr =     destination_ptr;
    suspend_block.qm_next_susp =    NU_NULL;
    suspend_block.qm_prev_susp =    NU_NULL;

    /* Place the suspend block on the queue full suspension for 
       associated queue.  */
    QM_Place_On_List(&(QCB_ptr -> qm_empty_wait_head),
                     &(QCB_ptr -> qm_empty_wait_tail),
                     &suspend_block);

    /* Suspend the task.  */
    SKP_Suspend_Task(task_id, NU_QUEUE_SUSPEND);
    
    /* Check to see if a timeout occurred.  In this case the suspend block
       is still part of the list, remove it!  */
    if (status == NU_QUEUE_TIMEOUT)
    {

        /* Remove the suspend block from the list.  */
        QM_Remove_From_List(&(QCB_ptr -> qm_empty_wait_head),
                            &(QCB_ptr -> qm_empty_wait_tail),
                            &suspend_block);
    }  

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



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "QM_Wait_To_Retrieve_Mult"  */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function suspends the task on the queue empty list for     */
/*      up to MAX_Q_SUSPENSIONS specified queues.                       */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that wait for queue items                      */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      QM_Place_On_List                    Place suspend blocks        */
/*      QM_Remove_From_List                 Remove suspend blocks       */
/*      SKP_Suspend_Task                    Suspend the task            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      task_id                             Task identification         */
/*      queue_id_1                          First queue identification  */
/*      queue_id_2                          Second queue identification */
/*      queue_id_3                          Third queue identification  */
/*      destination_ptr                     Pointer to destination item */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(status)                                                  */
/*                                                                      */
/************************************************************************/
signed int  QM_Wait_To_Retrieve_Mult(signed int task_id,
             signed int queue_id_1, signed int queue_id_2,
             signed int queue_id_3, unsigned int *destination_ptr)
{

struct QM_QUEUE_CONTROL_STRUCT  
                  *QCB_ptr_1,
                  *QCB_ptr_2,
                  *QCB_ptr_3;               /* Pointer to QCB entry     */
struct QM_SUSPENSION_STRUCT  
       suspend_blocks[MAX_Q_SUSPENSIONS];   /* Suspension control blocks*/
unsigned int       i;                       /* Working variable         */
signed int         status;                  /* Status of request        */
    

    /* Build pointers to the various queue control blocks.  */
    if (queue_id_1 != NU_IGNORE_VALUE)
       QCB_ptr_1 =  &QM_QCB_List[queue_id_1];
    else
       QCB_ptr_1 =  NU_NULL;

    if (queue_id_2 != NU_IGNORE_VALUE)
       QCB_ptr_2 =  &QM_QCB_List[queue_id_2];
    else
       QCB_ptr_2 =  NU_NULL;

    if (queue_id_3 != NU_IGNORE_VALUE)
       QCB_ptr_3 =  &QM_QCB_List[queue_id_3];
    else
       QCB_ptr_3 =  NU_NULL;

    /* Initialize the status variable as NU_QUEUE_TIMEOUT.  */
    status =  NU_QUEUE_TIMEOUT;

    /* Initialize the suspension blocks.  */
    suspend_blocks[0].qm_QCB_ptr =      QCB_ptr_1;
    suspend_blocks[1].qm_QCB_ptr =      QCB_ptr_2;
    suspend_blocks[2].qm_QCB_ptr =      QCB_ptr_3;
    suspend_blocks[0].qm_susp_type =    QM_MULTIPLE;
    suspend_blocks[1].qm_susp_type =    QM_MULTIPLE;
    suspend_blocks[2].qm_susp_type =    QM_MULTIPLE;
    
    /* Loop through the suspension blocks.  */
    for (i = 0; i < MAX_Q_SUSPENSIONS; i++)
    {
    
        /* If the queue id is not an ignore value, build the rest of it.  */
        if (suspend_blocks[i].qm_QCB_ptr != NU_NULL)
        {
    
            /* Build suspension structure.  */
            suspend_blocks[i].qm_task_id =      task_id;
            suspend_blocks[i].qm_susp_id =      i;
            suspend_blocks[i].qm_return_addr =  &status;
            suspend_blocks[i].qm_item_ptr =     destination_ptr;
            suspend_blocks[i].qm_next_susp =    NU_NULL;
            suspend_blocks[i].qm_prev_susp =    NU_NULL;

            /* Place the suspend block on the queue full suspension for 
               associated queue.  */
             QM_Place_On_List(
               &(suspend_blocks[i].qm_QCB_ptr -> qm_empty_wait_head),
               &(suspend_blocks[i].qm_QCB_ptr -> qm_empty_wait_tail),
               &suspend_blocks[i]);
        }
    }

    /* Suspend the task.  */
    SKP_Suspend_Task(task_id, NU_QUEUE_SUSPEND);
    
    /* Check to see if a timeout occurred.  In this case the suspend block
       is still part of the list, remove it!  */
    if (status == NU_QUEUE_TIMEOUT)
    {

        /* Walk through each suspension block. */
        for (i = 0; i < MAX_Q_SUSPENSIONS; i++)
        {
        
            /* Determine if this suspension block was used.  */
            if (suspend_blocks[i].qm_QCB_ptr != NU_NULL)
            {
            
                /* Remove the suspend block from the list.  */
                 QM_Remove_From_List(
                    &(suspend_blocks[i].qm_QCB_ptr -> qm_empty_wait_head),
                    &(suspend_blocks[i].qm_QCB_ptr -> qm_empty_wait_tail),
                    &suspend_blocks[i]);
            }
        }
    }  

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



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "QM_Max_Queues"             */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function returns the total number of queues in the system. */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that make queue calls                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      return(QM_Total_Queues)                                        */
/*                                                                      */
/************************************************************************/
signed int  QM_Max_Queues()
{

    /* Return the number of queues to the caller.  */
    return(QM_Total_Queues);
}                                           /* end of  QM_Max_Queues    */



/************************************************************************/
/*                                                                      */
/*  FUNCTION                                "QM_Retrieve_Status"        */
/*                                                                      */
/*                                                                      */
/*  DESCRIPTION                                                         */
/*                                                                      */
/*      This function returns the total number of items in a specified  */
/*      queue as well as the item size of that queue.                   */
/*                                                                      */
/*  AUTHOR                                                              */
/*                                                                      */
/*      William E. Lamie,  Accelerated Technology                       */
/*                                                                      */
/*  CALLED FROM                                                         */
/*                                                                      */
/*      Service routines that make queue calls                          */
/*                                                                      */
/*  ROUTINES CALLED                                                     */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  INPUTS                                                              */
/*                                                                      */
/*      None                                                            */
/*                                                                      */
/*  OUTPUTS                                                             */
/*                                                                      */
/*      item_size                                                       */
/*      return(items_queued)                                            */
/*                                                                      */
/************************************************************************/
signed int  QM_Retrieve_Status(signed int queue_id, signed int *item_size_ptr)
{

struct QM_QUEUE_CONTROL_STRUCT  
                  *QCB_ptr;                 /* Pointer to QCB entry     */

    /* Point to the entry.  */
    QCB_ptr =  &QM_QCB_List[queue_id];

    /* Put the size in the appropriate place.  */
    *item_size_ptr =  QCB_ptr -> qm_item_size;    

    /* Return the number of items queued.  */
    return(QCB_ptr -> qm_queued);
}                                           /* end of QM_Retrieve_Status */

⌨️ 快捷键说明

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