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

📄 tx_tte.c

📁 ThreadX优秀的硬实时操作系统.This Express Start Guide is designed to help you install and use ThreadX for the
💻 C
📖 第 1 页 / 共 2 页
字号:
                                                    current_timer -> tx_active_previous;
                (current_timer -> tx_active_previous) -> tx_active_next =
                                                    current_timer -> tx_active_next;

                /* Modify the next timer's list head to point at the current list head.  */
                (current_timer -> tx_active_next) -> tx_list_head =  &expired_timers;

                /* Set the list head pointer.  */
                expired_timers =  current_timer -> tx_active_next;
            }

            /* In any case, the timer is now off of the expired list.  */

            /* Determine if the timer has expired or if it is just a really 
               big timer that needs to be placed in the list again.  */
            if (current_timer -> tx_remaining_ticks > TX_TIMER_ENTRIES)
            {

                /* Timer is bigger than the timer entries and must be
                   re-scheduled.  */

                /* Decrement the remaining ticks of the timer.  */
                current_timer -> tx_remaining_ticks =  
                        current_timer -> tx_remaining_ticks - TX_TIMER_ENTRIES;
                
                /* Set the timeout function to NULL in order to bypass the
                   expiration.  */
                timeout_function =  TX_NULL;

                /* Make the timer appear that it is still active while interrupts
                   are enabled.  This will permit proper processing of a timer
                   deactivate from an ISR.  */
                current_timer -> tx_list_head =    &reactivate_timer;
                current_timer -> tx_active_next =  current_timer;
            }
            else
            {

                /* Timer did expire.  Copy the calling function and ID 
                   into local variables before interrupts are re-enabled.  */
                timeout_function =  current_timer -> tx_timeout_function;
                timeout_param =     current_timer -> tx_timeout_param;

                /* Copy the re-initialize ticks into the remaining ticks.  */
                current_timer -> tx_remaining_ticks =  current_timer -> tx_re_initialize_ticks;

                /* Determine if the timer should be re-activated.  */
                if (current_timer -> tx_remaining_ticks)
                {

                    /* Make the timer appear that it is still active while processing
                       the expiration routine and with interrupts enabled.  This will 
                       permit proper processing of a timer deactivate from both the
                       expiration routine and an ISR.  */
                    current_timer -> tx_list_head =    &reactivate_timer;
                    current_timer -> tx_active_next =  current_timer;
                }
                else
                {

                    /* Set the list pointer of this timer to NULL.  This is used to indicate
                       the timer is no longer active.  */
                    current_timer -> tx_list_head =  TX_NULL;
                }
            }

            /* Restore interrupts for timer expiration call.  */
            TX_RESTORE

            /* Call the timer-expiration function, if non-NULL.  */
            if (timeout_function)
                (timeout_function) (timeout_param);

            /* Lockout interrupts again.  */
            TX_DISABLE

            /* Determine if the timer needs to be re-activated.  */
            if (current_timer -> tx_list_head == &reactivate_timer)
            {

                /* Re-activate the timer.  */

                /* Calculate the amount of time remaining for the timer.  */
                if (current_timer -> tx_remaining_ticks > TX_TIMER_ENTRIES)
                {

                    /* Set expiration time to the maximum number of entries.  */
                    expiration_time =  TX_TIMER_ENTRIES - 1;
                }
                else
                {

                    /* Timer value fits in the timer entries.  */

                    /* Set the expiration time.  */
                    expiration_time =  (UINT) current_timer -> tx_remaining_ticks - 1;
                }

                /* At this point, we are ready to put the timer back on one of
                   the timer lists.  */
    
                /* Calculate the proper place for the timer.  */
                timer_list =  _tx_timer_current_ptr + expiration_time;
                if (timer_list >= _tx_timer_list_end)
                {

                    /* Wrap from the beginning of the list.  */
                    timer_list =  _tx_timer_list_start +
                                        (timer_list - _tx_timer_list_end);
                }

                /* Now put the timer on this list.  */
                if (*timer_list)
                {

                    /* This list is not NULL, add current timer to the end. */
                    current_timer -> tx_active_next =                          *timer_list;
                    current_timer -> tx_active_previous =                      (*timer_list) -> tx_active_previous;
                    (current_timer -> tx_active_previous) -> tx_active_next =  current_timer;
                    (*timer_list) -> tx_active_previous =                      current_timer;
                    current_timer -> tx_list_head =                            timer_list;
                }
                else
                {
                
                    /* This list is NULL, just put the new timer on it.  */

                    /* Setup the links in this timer.  */
                    current_timer -> tx_active_next =      current_timer;
                    current_timer -> tx_active_previous =  current_timer;
                    current_timer -> tx_list_head =        timer_list;

                    /* Setup the list head pointer.  */
                    *timer_list =  current_timer;
                }
            }

            /* Restore interrupts.  */
            TX_RESTORE

            /* Lockout interrupts again.  */
            TX_DISABLE
        }

        /* Finally, suspend this thread and wait for the next expiration.  */

        /* Determine if another expiration took place while we were in this
           thread.  If so, process another expiration.  */
        if (!_tx_timer_expired)
        {

            /* Otherwise, no timer expiration, so suspend the thread.  */

            /* Set the status to suspending, in order to indicate the 
               suspension is in progress.  */
            _tx_thread_current_ptr -> tx_state =  TX_SUSPENDED;

            /* Set the suspending flag. */
            _tx_thread_current_ptr -> tx_suspending =  TX_TRUE;

            /* Increment the preempt disable count prior to suspending.  */
            _tx_thread_preempt_disable++;

            /* Restore interrupts.  */
            TX_RESTORE

            /* Call actual thread suspension routine.  */
            _tx_thread_suspend(_tx_thread_current_ptr);
        }
        else
        {

            /* Restore interrupts.  */
            TX_RESTORE
        }

    } while (TX_FOREVER);
}

⌨️ 快捷键说明

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