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

📄 pic.c

📁 nuclues 内核源代码已经在arm7-9 上作了移植
💻 C
📖 第 1 页 / 共 5 页
字号:
                
                    /* Copy the first half of the message.  */
                    i =  (INT) copy_size;
                    do
                    {
                        *(destination) =  *(source++);
                        if ((--i) == 0)
                            break;
                        destination++;
                    } while (1);

                    /* Copy the second half of the message.  */
                    destination =  pipe -> pi_start;
                    i =  (INT) (size - copy_size);
                    do
                    {
                        *(destination++) =  *(source);
                        if ((--i) ==  0)
                            break;
                        source++;
                    } while (1);
                }
            }
            
            /* Check again for wrap-around condition on the write pointer. */
            if (destination >= pipe -> pi_end)
            
                /* Move the write pointer to the top of the pipe area.  */
                destination =  pipe -> pi_start;
                
            /* Determine if the pipe supports variable-length messages.  If
               so, pad bytes are needed to keep UNSIGNED alignment.  */
            if (pad)
            {
            
                /* Variable-size message.  Add pad bytes to the write 
                   pointer.  */

                /* Calculate the number of bytes remaining from the write 
                   pointer to the bottom of the pipe.  */
                copy_size =  pipe -> pi_end - destination;

                /* If there is not enough room at the bottom of the pipe, the
                   pad bytes must be wrapped around to the top.  */
                if (copy_size <= pad)
                        
                    /* Move write pointer to the top of the pipe and make the
                       necessary adjustment.  */
                    destination =  pipe -> pi_start + (pad - copy_size);
                else
                
                    /* There is enough room in the pipe to simply add the 
                       the pad bytes to the write pointer.  */
                    destination =  destination + pad;

                /* Decrement the number of available bytes.  */
                pipe -> pi_available =  pipe -> pi_available - pad;
            }

            /* Update the actual write pointer.  */
            pipe -> pi_write =  destination;

            /* Decrement the number of available bytes.  */
            pipe -> pi_available =  pipe -> pi_available - size;
            
            /* Increment the number of messages in the pipe.  */
            pipe -> pi_messages++;

#ifdef INCLUDE_PROVIEW
		_RTProf_DumpPipe(RT_PROF_SEND_TO_PIPE,pipe,RT_PROF_OK);
#endif
        }
    }

    /* Release protection against access to the pipe.  */
    TCT_Unprotect();

    /* Return the completion status.  */
    return(status);
}


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      PIC_Receive_From_Pipe                                            */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function receives a message from the specified pipe.  The   */
/*      size of the message is specified by the caller.  If there is a   */
/*      message currently in the pipe, the message is removed from the   */
/*      pipe and placed in the caller's area.  Suspension is possible    */
/*      if the request cannot be satisfied.                              */
/*                                                                       */
/* AUTHOR                                                                */
/*                                                                       */
/*      Accelerated Technology, Inc.                                     */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      Application                                                      */
/*      PICE_Receive_From_Pipe              Error checking shell         */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      CSC_Place_On_List                   Place on suspend list        */
/*      CSC_Remove_From_List                Remove from suspend list     */
/*      [HIC_Make_History_Entry]            Make entry in history log    */
/*      TCC_Resume_Task                     Resume a suspended task      */
/*      TCC_Suspend_Task                    Suspend calling task         */
/*      TCC_Task_Priority                   Pickup task's priority       */
/*      [TCT_Check_Stack]                   Stack checking function      */
/*      TCT_Control_To_System               Transfer control to system   */
/*      TCT_Current_Thread                  Pickup current thread pointer*/
/*      TCT_System_Protect                  Protect pipe                 */
/*      TCT_Unprotect                       Release protection           */
/*                                                                       */
/* INPUTS                                                                */
/*                                                                       */
/*      pipe_ptr                            Pipe control block pointer   */
/*      message                             Pointer to message to send   */
/*      size                                Size of the message          */
/*      actual_size                         Size of message received     */
/*      suspend                             Suspension option if empty   */
/*                                                                       */
/* OUTPUTS                                                               */
/*                                                                       */
/*      NU_SUCCESS                          If service is successful     */
/*      NU_PIPE_EMPTY                       If pipe is currently empty   */
/*      NU_TIMEOUT                          If timeout on service expires*/
/*      NU_PIPE_DELETED                     If pipe was deleted during   */
/*                                            suspension                 */
/*      NU_PIPE_RESET                       If pipe was reset during     */
/*                                            suspension                 */
/*                                                                       */
/* 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, changed                  */
/*                      protection logic to reduce                       */
/*                      overhead, optimized copy loop,                   */
/*                      resulting in version 1.1                         */
/*                                                                       */
/*      03-18-1994      Verified version 1.1                             */
/*                                                                       */
/*************************************************************************/
STATUS  PIC_Receive_From_Pipe(NU_PIPE *pipe_ptr, VOID *message,
                UNSIGNED size, UNSIGNED *actual_size, UNSIGNED suspend)
{

R1 PI_PCB      *pipe;                       /* Pipe control block ptr    */
PI_SUSPEND      suspend_block;              /* Allocate suspension block */
PI_SUSPEND     *suspend_ptr;                /* Pointer to suspend block  */
R2 BYTE_PTR     source;                     /* Pointer to source         */
R3 BYTE_PTR     destination;                /* Pointer to destination    */
TC_TCB         *task;                       /* Task pointer              */
UNSIGNED        copy_size;                  /* Number of bytes to copy   */
UNSIGNED        pad =  0;                   /* Number of pad bytes       */
R4 INT          i;                          /* Working counter           */
STATUS          preempt;                    /* Preemption flag           */
STATUS          status;                     /* Completion status         */



    /* 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_RECEIVE_FROM_PIPE_ID, (UNSIGNED) pipe, 
                                        (UNSIGNED) message, (UNSIGNED) size);

#endif

    /* Initialize the status as successful.  */
    status =  NU_SUCCESS;

    /* Protect against simultaneous access to the pipe.  */
    TCT_System_Protect();
    
    /* Determine if an urgent message request is currently suspended.  */
    if (pipe -> pi_urgent_list)
    {
    
        /* If so, copy the message from the suspended request block and 
           resume the associated task.  */
           
        /* Decrement the number of tasks waiting on pipe.  */
        pipe -> pi_tasks_waiting--;

        /* Remove the first suspended block from the list.  */
        suspend_ptr =  pipe -> pi_urgent_list;
        CSC_Remove_From_List((CS_NODE **) &(pipe -> pi_urgent_list),
                                          &(suspend_ptr -> pi_suspend_link));

        /* Setup the source and destination pointers.  */
        destination =   (BYTE_PTR) message;
        source =        suspend_ptr -> pi_message_area;

        /* Initialize the return status.  */
        suspend_ptr -> pi_return_status =  NU_SUCCESS;

        /* Loop to actually copy the message.  */
        i =  (INT) size;
        do
        {
            *(destination++) =  *(source);
            if ((--i) == 0)
                break;
            source++;
        } while (1);
            
        /* Return the size of the message copied.  */
        *actual_size =  suspend_ptr -> pi_message_size;

        /* Wakeup the waiting task and check for preemption.  */
        preempt =  
            TCC_Resume_Task((NU_TASK *) suspend_ptr -> pi_suspended_task, 
                                                     NU_PIPE_SUSPEND);

        /* Determine if preemption needs to take place. */
        if (preempt)
            
             /* Transfer control to the system if the resumed task function
                detects a preemption condition.  */
             TCT_Control_To_System();
    }
    
    /* Determine if there are messages in the pipe.  */
    else if (pipe -> pi_messages)
    {

        /* Copy message from pipe into the caller's area.  */

        /* Setup the source and destination pointers.  */
        destination =  (BYTE_PTR) message;
        source =       pipe -> pi_read;
            
        /* Process according to the type of message supported by the pipe.  */
        if (pipe -> pi_fixed_size)
        {
        
            /* Pipe supports fixed-size messages.  */
            
            /* Copy the message from the pipe area into the destination.  */
            i =  (INT) size;
            do
            {
                *(destination) =  *(source++);
                if ((--i) == 0)
                    break;
                destination++;
            } while (1);
        }
        else
        {

            /* Pipe supports variable-size messages.  */
            
            /* Variable length message size is actually in the pipe area. */
            size =  *((UNSIGNED *) source);
            source =  source + sizeof(UNSIGNED);
            

⌨️ 快捷键说明

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