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

📄 tx_qr.c

📁 ThreadX优秀的硬实时操作系统.This Express Start Guide is designed to help you install and use ThreadX for the
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************/ 
/*                                                                        */ 
/*            Copyright (c) 1996-2000 by Express Logic Inc.               */ 
/*                                                                        */ 
/*  This software is copyrighted by and is the sole property of Express   */ 
/*  Logic, Inc.  All rights, title, ownership, or other interests         */ 
/*  in the software remain the property of Express Logic, Inc.  This      */ 
/*  software may only be used in accordance with the corresponding        */ 
/*  license agreement.  Any unauthorized use, duplication, transmission,  */ 
/*  distribution, or disclosure of this software is expressly forbidden.  */ 
/*                                                                        */
/*  This Copyright notice may not be removed or modified without prior    */ 
/*  written consent of Express Logic, Inc.                                */ 
/*                                                                        */ 
/*  Express Logic, Inc. reserves the right to modify this software        */ 
/*  without notice.                                                       */ 
/*                                                                        */ 
/*  Express Logic, Inc.                                                   */
/*  11440 West Bernardo Court               info@expresslogic.com         */
/*  Suite 366                               http://www.expresslogic.com   */
/*  San Diego, CA  92127                                                  */
/*                                                                        */
/**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */ 
/** ThreadX Component                                                     */ 
/**                                                                       */
/**   Queue (QUE)                                                         */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define TX_SOURCE_CODE


/* Include necessary system files.  */

#include    "tx_api.h"
#include    "tx_thr.h"
#include    "tx_tim.h"
#include    "tx_que.h"


/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_queue_receive                                   PORTABLE C      */ 
/*                                                           3.0f         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*    William E. Lamie, Express Logic, Inc.                               */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function receives a message from the specified queue. If there */ 
/*    are no messages in the queue, this function waits according to the  */ 
/*    option specified.                                                   */ 
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    queue_ptr                         Pointer to queue control block    */ 
/*    destination_ptr                   Pointer to message destination    */ 
/*                                        **** MUST BE LARGE ENOUGH TO    */ 
/*                                             HOLD MESSAGE ****          */ 
/*    wait_option                       Suspension option                 */ 
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    status                            Completion status                 */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    _tx_timer_activate                Activate timer routine            */ 
/*    _tx_timer_deactivate              Deactivate timer routine          */ 
/*    _tx_thread_resume                 Resume thread routine             */ 
/*    _tx_thread_suspend                Suspend thread routine            */ 
/*    _tx_thread_system_return          Return to system routine          */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    Application Code                                                    */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*  12-31-1996     William E. Lamie         Initial Version 3.0           */ 
/*  07-04-1997     William E. Lamie         Modified message copy logic   */ 
/*                                            to avoid casting structure  */ 
/*                                            pointers, which causes      */ 
/*                                            compiler warnings in some   */ 
/*                                            development tools,          */ 
/*                                            resulting in version 3.0a.  */ 
/*  11-11-1997     William E. Lamie         Modified comment(s),          */ 
/*                                            resulting in version 3.0b.  */ 
/*  03-01-1998     William E. Lamie         Optimized post RESTORE        */ 
/*                                            processing, resulting in    */ 
/*                                            version 3.0d.               */ 
/*  01-01-1999     William E. Lamie         Modified comment(s),          */ 
/*                                            resulting in version 3.0e.  */ 
/*  11-01-1999     William E. Lamie         Modified comment(s),          */ 
/*                                            added logic to track events,*/ 
/*                                            resulting in version 3.0f.  */ 
/*                                                                        */ 
/**************************************************************************/ 
UINT    _tx_queue_receive(TX_QUEUE *queue_ptr, VOID *destination_ptr, ULONG wait_option)
{

TX_INTERRUPT_SAVE_AREA

REG_1   UINT        status;                 /* Return status           */
REG_2   TX_THREAD   *thread_ptr;            /* Working thread pointer  */
REG_3   ULONG       *source;                /* Source pointer          */
REG_4   ULONG       *destination;           /* Destination pointer     */


    /* Disable interrupts to receive message from queue.  */
    TX_DISABLE

    /* Log this kernel call.  */
    TX_EL_QUEUE_RECEIVE_INSERT

    /* Determine if there is anything in the queue.  */
    if (queue_ptr -> tx_queue_enqueued)
    {

        /* Setup source and destination pointers.  */
        source =  (ULONG *) queue_ptr -> tx_queue_read;
        destination =  (ULONG *) destination_ptr;

        /* Yes, there is something in the queue.  Place the oldest message in the 
           queue into the thread's area.  */
        if (queue_ptr -> tx_queue_message_size == TX_1_ULONG)
        {                
            /* Copy single longword message from the queue.  */
            *destination =  *source;
        }
        else if (queue_ptr -> tx_queue_message_size == TX_2_ULONG)
        {

            /* Copy double longword message from the queue.  */
            *destination++ =  *source++;
            *destination =    *source;
        }
        else if (queue_ptr -> tx_queue_message_size == TX_4_ULONG)
        {

            /* Copy a four longword message from the queue.  */
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination =    *source;
        }
        else if (queue_ptr -> tx_queue_message_size == TX_8_ULONG)
        {

            /* Copy an eight longword message from the queue.  */
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination =    *source;
        }
        else
        {

            /* Copy a sixteen longword message from the queue.  */
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination++ =  *source++;
            *destination =    *source;
        }

        /* Adjust the read pointer.  */
        queue_ptr -> tx_queue_read =  
                    queue_ptr -> tx_queue_read + queue_ptr -> tx_queue_message_size;

        /* Determine if we are at the end.  */
        if (queue_ptr -> tx_queue_read >= queue_ptr -> tx_queue_end)

            /* Yes, wrap around to the beginning.  */
            queue_ptr -> tx_queue_read =  queue_ptr -> tx_queue_start;
        
        /* Successful service.  */
        status =  TX_SUCCESS;

        /* Now determine if there is a thread waiting to place a message in the queue.  */
        if (!queue_ptr -> tx_queue_suspension_list)
        {

            /* No thread waiting on full queue.  */

            /* Increase the amount of available storage.  */
            queue_ptr -> tx_queue_available_storage++;

            /* Decrease the enqueued count.  */
            queue_ptr -> tx_queue_enqueued--;
        }              
        else
        {

            /* Disable preemption.  */
            _tx_thread_preempt_disable++;

            /* Restore interrupts.  */
            TX_RESTORE

            /* Interrupts are enabled briefly here to keep the interrupt
               lockout time deterministic.  */

            /* Disable interrupts again.  */
            TX_DISABLE

            /* Decrement the preemption disable variable.  */
            _tx_thread_preempt_disable--;

⌨️ 快捷键说明

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