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

📄 quc.c

📁 NucleusPLUS嵌入式操作系统是目前最受欢迎的操作系统NucleusPLUS是为实时嵌入式应用而设计的一个抢先式多任务操作系统内核
💻 C
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************/
/*                                                                       */
/*               Copyright Mentor Graphics Corporation 2002              */
/*                         All Rights Reserved.                          */
/*                                                                       */
/* THIS WORK CONTAINS TRADE SECRET AND PROPRIETARY INFORMATION WHICH IS  */
/* THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS   */
/* SUBJECT TO LICENSE TERMS.                                             */
/*                                                                       */
/*************************************************************************/

/*************************************************************************/
/*                                                                       */
/* FILE NAME                                               VERSION       */
/*                                                                       */
/*      quc.c                                          Nucleus PLUS 1.14 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      QU - Queue Management                                            */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the core routines for the Queue management    */
/*      component.                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      QUC_Create_Queue                    Create a message queue       */
/*      QUC_Delete_Queue                    Delete a message queue       */
/*      QUC_Send_To_Queue                   Send message to a queue      */
/*      QUC_Receive_From_Queue              Receive a message from queue */
/*      QUC_Cleanup                         Cleanup on timeout or a      */
/*                                            terminate condition        */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      cs_extr.h                           Common Service functions     */
/*      tc_extr.h                           Thread Control functions     */
/*      qu_extr.h                           Queue functions              */
/*      hi_extr.h                           History functions            */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      08-09-1993      Corrected pointer retrieval                      */
/*                      loop, resulting in version 1.0a                  */
/*      08-09-1993      Verified version 1.0a                            */
/*      11-01-1993      Corrected a problem with fixed-                  */
/*                      size queues of a size equal to                   */
/*                      one message, resulting in                        */
/*                      version 1.0b                                     */
/*      11-01-1993      Verified version 1.0b                            */
/*      03-01-1994      Moved non-core functions into                    */
/*                      supplemental files, changed                      */
/*                      function interfaces to match                     */
/*                      those in prototype, added                        */
/*                      register options, changed                        */
/*                      protection logic to reduce                       */
/*                      overhead, corrected bug in                       */
/*                      queue reset, optimized item                      */
/*                      copy loops, resulting in                         */
/*                      version 1.1                                      */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*      04-17-1996      updated to version 1.2                           */
/*      01-28-1998      Corrected SPR412 resulting in                    */
/*                      version 1.2a.                                    */
/*      03-24-1998      Released version 1.3                             */
/*      03-26-1999      Released 1.11m (new release                      */
/*                        numbering scheme)                              */
/*      04-17-2002      Released version 1.13m                           */
/*      11-07-2002      Released version 1.14                            */
/*************************************************************************/
#define         NU_SOURCE_FILE


#include        "cs_extr.h"                 /* Common service functions  */
#include        "tc_extr.h"                 /* Thread control functions  */
#include        "qu_extr.h"                 /* Queue functions           */
#include        "hi_extr.h"                 /* History functions         */


/* Define external inner-component global data references.  */

extern CS_NODE         *QUD_Created_Queues_List;
extern UNSIGNED         QUD_Total_Queues;
extern TC_PROTECT       QUD_List_Protect;


/* Define internal component function prototypes.  */

VOID    QUC_Cleanup(VOID *information);


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      QUC_Create_Queue                                                 */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function creates a queue and then places it on the list     */
/*      of created queues.                                               */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      QUCE_Create_Queue                   Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      CSC_Place_On_List                   Add node to linked-list      */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Protect                         Protect created list         */
/*      TCT_Unprotect                       Un-protect data structure    */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      queue_ptr                           Queue control block pointer  */
/*      name                                Queue name                   */
/*      start_address                       Starting address of actual   */
/*                                            queue area                 */
/*      queue_size                          Total size of queue          */
/*      message_type                        Type of message supported by */
/*                                            the queue (fixed/variable) */
/*      message_size                        Size of message.  Variable   */
/*                                            message-length queues, this*/
/*                                            represents the maximum size*/
/*      suspend_type                        Suspension type              */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                                                       */
/*                                                                       */
/* HISTORY                                                               */
/*                                                                       */
/*         DATE                    REMARKS                               */
/*                                                                       */
/*      03-01-1993      Created initial version 1.0                      */
/*      04-19-1993      Verified version 1.0                             */
/*      03-01-1994      Changed function interfaces to                   */
/*                      match those in prototype,                        */
/*                      added register options,                          */
/*                      resulting in version 1.1                         */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*                                                                       */
/*************************************************************************/
STATUS  QUC_Create_Queue(NU_QUEUE *queue_ptr, CHAR *name,
                      VOID *start_address, UNSIGNED queue_size,
                      OPTION message_type, UNSIGNED message_size,
                      OPTION suspend_type)
{

R1 QU_QCB      *queue;                      /* Queue control block ptr   */
INT             i;                          /* Working index variable    */
NU_SUPERV_USER_VARIABLES

    /* Switch to supervisor mode */
    NU_SUPERVISOR_MODE();

    /* Move input queue pointer into internal pointer.  */
    queue =  (QU_QCB *) queue_ptr;


#ifdef  NU_ENABLE_STACK_CHECK

    /* Call stack checking function to check for an overflow condition.  */
    TCT_Check_Stack();

#endif

#ifdef  NU_ENABLE_HISTORY

    /* Make an entry that corresponds to this function in the system history
       log.  */
    HIC_Make_History_Entry(NU_CREATE_QUEUE_ID, (UNSIGNED) queue,
                                (UNSIGNED) name, (UNSIGNED) start_address);

#endif

    /* First, clear the queue ID just in case it is an old Queue
       Control Block.  */
    queue -> qu_id =             0;

    /* Fill in the queue name.  */
    for (i = 0; i < NU_MAX_NAME; i++)
        queue -> qu_name[i] =  name[i];

    /* Setup the queue suspension type.  */
    if (suspend_type == NU_FIFO)

        /* FIFO suspension is selected, setup the flag accordingly.  */
        queue -> qu_fifo_suspend =  NU_TRUE;

    else

        /* Priority suspension is selected.  */
        queue -> qu_fifo_suspend =  NU_FALSE;

    /* Setup the queue message type.  */
    if (message_type == NU_FIXED_SIZE)

        /* Fixed-size messages are required.  */
        queue -> qu_fixed_size =  NU_TRUE;
    else

        /* Variable-size messages are required.  */
        queue -> qu_fixed_size =  NU_FALSE;

    /* Setup the message size.  */
    queue -> qu_message_size =  message_size;

    /* Clear the messages counter.   */
    queue -> qu_messages =  0;

    /* Setup the actual queue parameters.  */
    queue -> qu_queue_size =    queue_size;

    /* If the queue supports fixed-size messages, make sure that the queue
       size is an even multiple of the message size.  */
    if (queue -> qu_fixed_size)

        /* Adjust the area of the queue being used.  */
        queue_size =  (queue_size / message_size) * message_size;

    queue -> qu_available =     queue_size;
    queue -> qu_start =         (UNSIGNED *) start_address;
    queue -> qu_end =           queue -> qu_start + queue_size;
    queue -> qu_read =          (UNSIGNED *) start_address;
    queue -> qu_write =         (UNSIGNED *) start_address;

    /* Clear the suspension list pointer.  */
    queue -> qu_suspension_list =  NU_NULL;

    /* Clear the number of tasks waiting on the queue counter.  */
    queue -> qu_tasks_waiting =  0;

    /* Clear the urgent message list pointer.  */
    queue -> qu_urgent_list =  NU_NULL;

    /* Initialize link pointers.  */
    queue -> qu_created.cs_previous =    NU_NULL;
    queue -> qu_created.cs_next =        NU_NULL;

    /* Protect against access to the list of created queues.  */
    TCT_Protect(&QUD_List_Protect);

    /* At this point the queue is completely built.  The ID can now be
       set and it can be linked into the created queue list.  */
    queue -> qu_id =                     QU_QUEUE_ID;

    /* Link the queue into the list of created queues and increment the
       total number of queues in the system.  */
    CSC_Place_On_List(&QUD_Created_Queues_List, &(queue -> qu_created));
    QUD_Total_Queues++;

#ifdef INCLUDE_PROVIEW
    _RTProf_DumpQueue(RT_PROF_CREATE_QUEUE,queue,RT_PROF_OK);
#endif

    /* Release protection against access to the list of created queues.  */
    TCT_Unprotect();

    /* Return to user mode */
    NU_USER_MODE();

    /* Return successful completion.  */
    return(NU_SUCCESS);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      QUC_Delete_Queue                                                 */

⌨️ 快捷键说明

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