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

📄 quc.c

📁 基于OMAP1510的Nucleus移植代码
💻 C
📖 第 1 页 / 共 5 页
字号:
        else

            /* Move the read pointer to where the copy left off.  */
            queue -> qu_read =  source;

        /* Increment the number of available words.  */
        queue -> qu_available =  queue -> qu_available + size;

        /* Decrement the number of messages in the queue.  */
        queue -> qu_messages--;

        /* Return the number of words received.  */
        *actual_size =  size;

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

        /* Determine if any tasks suspended on a full queue can be woken
           up.  */
        if (queue -> qu_suspension_list)
        {

            /* Overhead of each queue message.  */
            if (!queue -> qu_fixed_size)

                i =  1;
            else

                i =  0;

            /* Pickup the suspension list and examine suspension blocks
               to see if the message could now fit in the queue.  */
            suspend_ptr =  queue -> qu_suspension_list;
            preempt =      NU_FALSE;
            while ((suspend_ptr) &&
              ((suspend_ptr -> qu_message_size + i) <= queue -> qu_available))
            {

                /* Place the suspended task's message into the queue.  */

                /* Setup the source and destination pointers.  */
                source =        suspend_ptr -> qu_message_area;
                destination =   queue -> qu_write;
                size =          suspend_ptr -> qu_message_size;

                /* Process according to the type of message supported.  */
                if (queue -> qu_fixed_size)
                {

                    /* Fixed-size messages are supported by this queue.  */

                    /* Loop to copy the message into the queue area.  */
                    i =  (INT) size;
                    do
                    {
                        *(destination++) =  *(source);
                        if ((--i) == 0)
                            break;
                        source++;
                    } while (1);
                }
                else
                {

                    /* Variable-size messages are supported.  Processing must
                       check for queue wrap-around conditions.  */

                    /* Place message size in first location.  */
                    *(destination++) =  size;

                    /* Check for a wrap-around condition on the queue.  */
                    if (destination >= queue -> qu_end)

                        /* Wrap the write pointer back to the top of the queue
                           area.  */
                        destination =  queue -> qu_start;

                    /* Decrement the number of words remaining by 1 for this
                       extra word of overhead.  */
                    queue -> qu_available--;

                    /* Calculate the number of words remaining from the write
                       pointer to the bottom of the queue.  */
                    copy_size =  queue -> qu_end - destination;

                    /* Determine if the message needs to be wrapped around the
                       edge of the queue area.  */
                    if (copy_size >= size)
                    {

                        /* Copy the whole message at once.  */
                        i =  (INT) size;
                        do
                        {
                            *(destination++) =  *(source);
                            if ((--i) == 0)
                                break;
                            source++;
                        } while(1);
                    }
                    else
                    {

                        /* 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 =  queue -> qu_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 >= queue -> qu_end)

                    /* Move the write pointer to the top of the queue area.  */
                    queue -> qu_write =  queue -> qu_start;
                else

                    /* Simply copy the last position of the destination pointer
                       into the write pointer.  */
                    queue -> qu_write =  destination;

                /* Decrement the number of available words.  */
                queue -> qu_available =  queue -> qu_available - size;

                /* Increment the number of messages in the queue.  */
                queue -> qu_messages++;

                /* Decrement the number of tasks waiting counter.  */
                queue -> qu_tasks_waiting--;

                /* Remove the first suspended block from the list.  */
                CSC_Remove_From_List((CS_NODE **)
                    &(queue -> qu_suspension_list),
                                &(suspend_ptr -> qu_suspend_link));

                /* Return a successful status.  */
                suspend_ptr -> qu_return_status =  NU_SUCCESS;

                /* Resume the suspended task.  */
                preempt =  preempt |
                  TCC_Resume_Task((NU_TASK *) suspend_ptr -> qu_suspended_task,
                                                       NU_QUEUE_SUSPEND);

                /* Setup suspend pointer to the head of the list.  */
                suspend_ptr =  queue -> qu_suspension_list;

                /* Overhead of each queue message.  */
                if (!queue -> qu_fixed_size)

                    i =  1;
                else

                    i =  0;
            }

            /* Determine if a preempt condition is present.  */
            if (preempt)

                /* Transfer control to the system if the resumed task function
                   detects a preemption condition.  */
                TCT_Control_To_System();
        }
    }
    else
    {

        /* Queue is empty.  Determine if the task wants to suspend.  */
        if (suspend)
        {

            /* Increment the number of tasks waiting on the queue counter. */
            queue -> qu_tasks_waiting++;

#ifdef INCLUDE_PROVIEW
            _RTProf_DumpQueue(RT_PROF_RECEIVE_FROM_QUEUE,queue,RT_PROF_WAIT);
#endif

            /* Setup the suspend block and suspend the calling task.  */
            suspend_ptr =  &suspend_block;
            suspend_ptr -> qu_queue =                    queue;
            suspend_ptr -> qu_suspend_link.cs_next =     NU_NULL;
            suspend_ptr -> qu_suspend_link.cs_previous = NU_NULL;
            suspend_ptr -> qu_message_area =           (UNSIGNED_PTR) message;
            suspend_ptr -> qu_message_size =             size;
            task =                            (TC_TCB *) TCT_Current_Thread();
            suspend_ptr -> qu_suspended_task =           task;

            /* Determine if priority or FIFO suspension is associated with the
               queue.  */
            if (queue -> qu_fifo_suspend)
            {

                /* FIFO suspension is required.  Link the suspend block into
                   the list of suspended tasks on this queue.  */
                CSC_Place_On_List((CS_NODE **) &(queue -> qu_suspension_list),
                                        &(suspend_ptr -> qu_suspend_link));
            }
            else
            {

                /* Get the priority of the current thread so the suspend block
                   can be placed in the appropriate place.  */
                suspend_ptr -> qu_suspend_link.cs_priority =
                                                    TCC_Task_Priority(task);

                CSC_Priority_Place_On_List((CS_NODE **)
                            &(queue -> qu_suspension_list),
                                            &(suspend_ptr -> qu_suspend_link));
            }

            /* Finally, suspend the calling task. Note that the suspension call
               automatically clears the protection on the queue.  */
            TCC_Suspend_Task((NU_TASK *) task, NU_QUEUE_SUSPEND,
                                        QUC_Cleanup, suspend_ptr, suspend);

            /* Pickup the status of the request.  */
            status =  suspend_ptr -> qu_return_status;
            *actual_size =  suspend_ptr -> qu_actual_size;
        }
        else
        {

            /* Return a status of NU_QUEUE_EMPTY because there are no
               messages in the queue.  */
            status =  NU_QUEUE_EMPTY;

#ifdef INCLUDE_PROVIEW
            _RTProf_DumpQueue(RT_PROF_RECEIVE_FROM_QUEUE,queue,RT_PROF_FAIL);
#endif

        }
    }

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

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

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


/*************************************************************************/
/*                                                                       */
/* FUNCTION                                                              */
/*                                                                       */
/*      QUC_Cleanup                                                      */
/*                                                                       */
/* DESCRIPTION                                                           */
/*                                                                       */
/*      This function is responsible for removing a suspension block     */
/*      from a queue.  It is not called unless a timeout or a task       */
/*      terminate is in progress.  Note that protection is already in    */
/*      effect - the same protection at suspension time.  This routine   */
/*      must be called from Supervisor mode in Supervisor/User mode      */
/*      switching kernels.                                               */
/*                                                                       */
/* CALLED BY                                                             */
/*                                                                       */
/*      TCC_Timeout                         Task timeout                 */
/*      TCC_Terminate                       Task terminate               */
/*                                                                       */
/* CALLS                                                                 */
/*                                                                       */
/*      CSC_Remove_From_List                Remove suspend block from    */

⌨️ 快捷键说明

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