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

📄 pic.c

📁 nucleus 2006 source code
💻 C
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************/
/*                                                                       */
/*               Copyright Mentor Graphics Corporation 2004              */
/*                         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       */
/*                                                                       */
/*      pic.c                                          Nucleus PLUS 1.15 */
/*                                                                       */
/* COMPONENT                                                             */
/*                                                                       */
/*      PI - Pipe Management                                             */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This file contains the core routines for the pipe management     */
/*      component.                                                       */
/*                                                                       */
/* DATA STRUCTURES                                                       */
/*                                                                       */
/*      None                                                             */
/*                                                                       */
/* FUNCTIONS                                                             */
/*                                                                       */
/*      PIC_Create_Pipe                     Create a message pipe        */
/*      PIC_Delete_Pipe                     Delete a message pipe        */
/*      PIC_Send_To_Pipe                    Send message to a pipe       */
/*      PIC_Receive_From_Pipe               Receive a message from pipe  */
/*      PIC_Cleanup                         Cleanup on timeout or a      */
/*                                            terminate condition        */
/*                                                                       */
/* DEPENDENCIES                                                          */
/*                                                                       */
/*      cs_extr.h                           Common Service functions     */
/*      tc_extr.h                           Thread Control functions     */
/*      pi_extr.h                           Pipe functions               */
/*      hi_extr.h                           History functions            */
/*                                                                       */
/*************************************************************************/
#define         NU_SOURCE_FILE


#include        "plus/inc/cs_extr.h"        /* Common service functions  */
#include        "plus/inc/tc_extr.h"        /* Thread control functions  */
#include        "plus/inc/pi_extr.h"        /* Pipe functions            */
#include        "plus/inc/hi_extr.h"        /* History functions         */


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

extern CS_NODE         *PID_Created_Pipes_List;
extern UNSIGNED         PID_Total_Pipes;
extern TC_PROTECT       PID_List_Protect;


/* Define internal component function prototypes.  */

VOID    PIC_Cleanup(VOID *information);


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      PIC_Create_Pipe                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function creates a pipe and then places it on the list      */
/*      of created pipes.                                                */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      PICE_Create_Pipe                    Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      CSC_Place_On_List                   Add to node to linked-list   */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Protect                         Data structure protect       */
/*      TCT_Unprotect                       Un-protect data structure    */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      pipe_ptr                            Pipe control block pointer   */
/*      name                                Pipe name                    */
/*      start_address                       Starting address of actual   */
/*                                            pipe area                  */
/*      pipe_size                           Total size of pipe in bytes  */
/*      message_type                        Type of message supported by */
/*                                            the pipe (fixed/variable)  */
/*      message_size                        Size of message.  Variable   */
/*                                            message-length pipes, this */
/*                                            represents the maximum size*/
/*      suspend_type                        Suspension type              */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                                                       */
/*                                                                       */
/*************************************************************************/
STATUS  PIC_Create_Pipe(NU_PIPE *pipe_ptr, CHAR *name,
                      VOID *start_address, UNSIGNED pipe_size,
                      OPTION message_type, UNSIGNED message_size,
                      OPTION suspend_type)
{

R1 PI_PCB      *pipe;                       /* Pipe control block ptr    */
INT             i;                          /* Working index variable    */
NU_SUPERV_USER_VARIABLES

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

    /* Move input pipe pointer into internal pointer.  */
    pipe =  (PI_PCB *) pipe_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_PIPE_ID, (UNSIGNED) pipe,
                                (UNSIGNED) name, (UNSIGNED) start_address);

#endif

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

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

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

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

    else

        /* Priority suspension is selected.  */
        pipe -> pi_fifo_suspend =  NU_FALSE;

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

        /* Fixed-size messages are required.  */
        pipe -> pi_fixed_size =  NU_TRUE;
    else

        /* Variable-size messages are required.  */
        pipe -> pi_fixed_size =  NU_FALSE;

    /* Setup the message size.  */
    pipe -> pi_message_size =  message_size;

    /* Clear the messages counter.   */
    pipe -> pi_messages =  0;

    /* Setup the actual pipe pointers.  */
    pipe -> pi_pipe_size =     pipe_size;

    /* Determine if the pipe's size needs to be adjusted.  */
    if (pipe -> pi_fixed_size)

        /* The size of a fixed-size message pipe must be an even multiple of
           the actual message size.  */
        pipe_size =  (pipe_size/message_size) * message_size;

    else

        /* Insure that the size is in terms of UNSIGNED data elements.  This
           insures that the UNSIGNED word is never written past the end of
           the pipe.  */
        pipe_size =  (pipe_size/sizeof(UNSIGNED)) * sizeof(UNSIGNED);

    pipe -> pi_available =     pipe_size;
    pipe -> pi_start =         (BYTE_PTR) start_address;
    pipe -> pi_end =           pipe -> pi_start + pipe_size;
    pipe -> pi_read =          (BYTE_PTR) start_address;
    pipe -> pi_write =         (BYTE_PTR) start_address;

    /* Clear the suspension list pointer.  */
    pipe -> pi_suspension_list =  NU_NULL;

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

    /* Clear the urgent message list pointer.  */
    pipe -> pi_urgent_list =  NU_NULL;

    /* Initialize link pointers.  */
    pipe -> pi_created.cs_previous =    NU_NULL;
    pipe -> pi_created.cs_next =        NU_NULL;

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

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

    /* Link the pipe into the list of created pipes and increment the
       total number of pipes in the system.  */
    CSC_Place_On_List(&PID_Created_Pipes_List, &(pipe -> pi_created));
    PID_Total_Pipes++;

#ifdef NU_PROFILE_PLUS

    PRF_PLUS_PIC_CREATE_PIPE_0

#endif /* NU_PROFILE_PLUS */

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

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

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


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      PIC_Delete_Pipe                                                  */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function deletes a pipe and removes it from the list of     */
/*      created pipes.  All tasks suspended on the pipe are              */
/*      resumed.  Note that this function does not free the memory       */
/*      associated with the pipe.                                        */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      PICE_Delete_Pipe                    Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      CSC_Remove_From_List                Remove node from list        */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      TCC_Resume_Task                     Resume a suspended task      */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Control_To_System               Transfer control to system   */
/*      TCT_Protect                         Protect created list         */
/*      TCT_Set_Current_Protect             Modify current protection    */
/*      TCT_System_Protect                  Protect against system access*/
/*      TCT_System_Unprotect                Release system protection    */
/*      TCT_Unprotect                       Release protection           */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      pipe_ptr                            Pipe control block pointer   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                                                       */
/*                                                                       */
/*************************************************************************/
STATUS  PIC_Delete_Pipe(NU_PIPE *pipe_ptr)
{

R1 PI_PCB      *pipe;                       /* Pipe control block ptr    */
PI_SUSPEND     *suspend_ptr;                /* Suspend block pointer     */
PI_SUSPEND     *next_ptr;                   /* Next suspension block ptr */
STATUS          preempt;                    /* Status for resume call    */
NU_SUPERV_USER_VARIABLES

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

    /* Move input pipe pointer into internal pointer.  */
    pipe =  (PI_PCB *) pipe_ptr;


#ifdef  NU_ENABLE_STACK_CHECK

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

⌨️ 快捷键说明

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