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

📄 tx_el.c

📁 threadx嵌入式实时操作系统源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    _tx_thread_create                 ThreadX thread create function    */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*  12-02-1999     William E. Lamie         Initial Version 3.0a          */ 
/*                                                                        */ 
/**************************************************************************/ 
UINT  _tx_el_thread_register(TX_THREAD *thread_ptr)
{

UCHAR   *entry_ptr;
UCHAR   *work_ptr;
UCHAR   *read_ptr;
UINT    i;


    /* First of all, search for a free slot in the TNI area.  */
    entry_ptr =  _tx_el_tni_start;
    i =         0;
    while (i < TX_EL_TNIS)
    {

        /* Determine if this entry is available.  */
        if (*(entry_ptr + TX_EL_TNI_VALID_OFFSET) == TX_EL_INVALID_ENTRY)
            break;

        /* Otherwise, increment the associated pointers and indicies.  */
        i++;
        entry_ptr =  entry_ptr + TX_EL_TNI_ENTRY_SIZE;
    }
    
    /* Check to see if there were no more valid entries.  */
    if (i >= TX_EL_TNIS)
        return(TX_EL_NO_MORE_TNI_ROOM);

    /* Otherwise, we have room in the TNI and a valid record.  */

    /* Setup the thread's name.  */
    work_ptr =  entry_ptr;
    read_ptr =  (UCHAR *) thread_ptr -> tx_thread_name;
    i =         0;
    while ((i < TX_EL_TNI_NAME_SIZE) && (*read_ptr))
    {

        /* Copy a character of thread's name into TNI area of log.  */
        *work_ptr++ =  *read_ptr++;

        /* Increment the character count.  */
        i++;
    }

    /* Determine if a NULL needs to be inserted.  */
    if (i < TX_EL_TNI_NAME_SIZE)
    {

        /* Yes, insert a NULL into the event log string.  */
        *work_ptr =  (unsigned char) 0;        
    }

    /* Setup the thread ID.  */
    *((ULONG *) (entry_ptr + TX_EL_TNI_THREAD_ID_OFFSET)) =  (ULONG) thread_ptr;

    /* Setup the thread priority.  */
    *((ULONG *) (entry_ptr + TX_EL_TNI_THREAD_PRIORITY_OFF)) =  (ULONG) thread_ptr -> tx_priority;

    /* Set the valid field to indicate the entry is complete.  */
    *((UCHAR *) (entry_ptr + TX_EL_TNI_VALID_OFFSET)) =  (ULONG) TX_EL_VALID_ENTRY;
}


/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_el_user_event_insert                         68332/Green Hills  */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*    William E. Lamie, Express Logic, Inc.                               */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function inserts a user event into the event log.              */
/*    If the event log is full, the oldest event is overwritten.          */ 
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    sub_type                              Event sub-type for kernel call*/
/*    info_1                                First information field       */
/*    info_2                                Second information field      */
/*    info_3                                Third information field       */
/*    info_4                                Fourth information field      */
/*                                                                        */
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    ThreadX services                                                    */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*  12-02-1999     William E. Lamie         Initial Version 3.0a          */ 
/*                                                                        */ 
/**************************************************************************/ 
VOID  _tx_el_user_event_insert(UINT sub_type, ULONG info_1, ULONG info_2, 
                                                    ULONG info_3, ULONG info_4)
{

TX_INTERRUPT_SAVE_AREA

UINT    upper_tb;
UCHAR   *entry_ptr;

    /* Disable interrupts.  */
    TX_DISABLE

    /* Increment total event counter.  */
    _tx_el_total_events++;

    /* Setup working entry pointer first.  */
    entry_ptr =  *_tx_el_current_event;

    /* Store the event type and sub-type.  */
    *((unsigned short *) entry_ptr) =  TX_EL_USER_EVENT;
    *((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) = (unsigned short) sub_type;

    /* Store the upper time stamp.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
                                (ULONG) 0;

    /* Store the lower time stamp.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_LOWER_OFFSET)) =
                                (ULONG) _tx_el_fake_time_stamp++;

    /* Store the current thread.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_THREAD_OFFSET)) =
                                (ULONG) _tx_thread_current_ptr;

    /* Store the first info field.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_1_OFFSET)) =
                                (ULONG) info_1;

    /* Store the second info field.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_2_OFFSET)) =
                                (ULONG) info_2;

    /* Store the third info field.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_3_OFFSET)) =
                                (ULONG) info_3;

    /* Store the fourth info field.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_INFO_4_OFFSET)) =
                                (ULONG) info_4;

    /* Now move the current event log pointer.  */
    entry_ptr =  entry_ptr + TX_EL_EVENT_SIZE;

    /* Check for a wrap-around condition.  */
    if (entry_ptr >= _tx_el_event_area_end)
    {

        /* Yes, we have wrapped around to the end of the event area.  
           Start back at the top!  */
        entry_ptr =  _tx_el_event_area_start;
    }

    /* Write the entry pointer back into the header.  */
    *_tx_el_current_event =  entry_ptr;

    /* Restore interrupts.  */
    TX_RESTORE
}


/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_el_thread_running                            68332/Green Hills  */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*    William E. Lamie, Express Logic, Inc.                               */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function inserts a thread change event into the event          */
/*    log, which indicates that a context switch is taking place.         */
/*    If the event log is full, the oldest event is overwritten.          */
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    thread_ptr                            Pointer to thread being       */
/*                                            scheduled                   */
/*                                                                        */
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    _tx_thread_schedule                   ThreadX scheduler             */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*  12-02-1999     William E. Lamie         Initial Version 3.0a          */ 
/*                                                                        */ 
/**************************************************************************/ 
VOID  _tx_el_thread_running(TX_THREAD *thread_ptr)
{

UINT    upper_tb;
UCHAR   *entry_ptr;

    TX_EL_NO_STATUS_EVENTS 

    /* Increment total event counter.  */
    _tx_el_total_events++;

    /* Setup working entry pointer first.  */
    entry_ptr =  *_tx_el_current_event;

    /* Store the event type and sub-type.  */
    *((unsigned short *) entry_ptr) =  TX_EL_THREAD_CHANGE; 
    *((unsigned short *) (entry_ptr + TX_EL_EVENT_SUBTYPE_OFFSET)) = (unsigned short) 0; \

    /* Store the upper time stamp.  */
    *((ULONG *) (entry_ptr + TX_EL_EVENT_TIME_UPPER_OFFSET)) =
                                (ULONG) 0;

⌨️ 快捷键说明

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