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

📄 tx_tsus.c

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

            /* Clear this priority bit in the ready priority bit map.  */
            _tx_thread_priority_map =  _tx_thread_priority_map & ~(thread_ptr -> tx_priority_bit);

            /* Check for a thread preempted that had preemption threshold set.  */
            if (_tx_thread_preempted_map)
            {

                /* Ensure that this thread's priority is clear in the preempt
                   map.  */
                _tx_thread_preempted_map =  _tx_thread_preempted_map & 
                                                ~(thread_ptr -> tx_priority_bit);
            }

            /* Put the priority map in a working copy.  */
            priority_map =  _tx_thread_priority_map;

            /* Find the next highest priority.  */

            /* Check for priorities 0-7.  */
            priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
            if (priority_group)
                _tx_thread_highest_priority =  _tx_thread_lowest_bit[priority_group];		
            else
            {
		
                /* Check for priorities 8-15.  */
                priority_map =    priority_map >> TX_THREAD_GROUP_SIZE;
                priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                if (priority_group)
                       _tx_thread_highest_priority =  
                            TX_THREAD_GROUP_1 + _tx_thread_lowest_bit[priority_group];
                else
                {

                    /* Check for priorities 16-23.  */
                    priority_map =    priority_map >> TX_THREAD_GROUP_SIZE;
                    priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                    if (priority_group)
                           _tx_thread_highest_priority =  
                                TX_THREAD_GROUP_2 + _tx_thread_lowest_bit[priority_group];
                    else
                    {

                        priority_map =    priority_map >> TX_THREAD_GROUP_SIZE;
                        priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                        if (priority_group)
                            _tx_thread_highest_priority =  
                                     TX_THREAD_GROUP_3 + _tx_thread_lowest_bit[priority_group];
                        else
                        {
                        
                            /* Nothing else is ready.  Set highest priority and execute thread
                               accordingly.  */
                            _tx_thread_highest_priority =  TX_MAX_PRIORITIES;
                            _tx_thread_execute_ptr =       TX_NULL;

                            /* Restore interrupts.  */
                            TX_RESTORE

                            /* Return control to the system.  */
                            _tx_thread_system_return();

                            /* Return to caller.  */
                            return;
                        }
                    }
                }	
            }

            /* Determine if this thread is the thread designated to execute.  */
            if (thread_ptr == _tx_thread_execute_ptr)
            {

                /* Pickup the highest priority thread to execute.  */
                _tx_thread_execute_ptr =  _tx_thread_priority_list[_tx_thread_highest_priority];

                /* Determine if a previous thread with preemption threshold was 
                   preempted.  */
                if (_tx_thread_preempted_map)
                {

                    /* 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--;

                    /* Calculate the thread with preemption threshold set that
                       was interrupted by a thread above the preemption level.  */

                    /* Put the preempt map in a working copy.  */
                    priority_map =  _tx_thread_preempted_map;

                    /* Find the highest priority preempted thread.  */

                    /* Check for priorities 0-7.  */
                    priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                    if (priority_group)
                        priority =  _tx_thread_lowest_bit[priority_group];		
                    else
                    {
		
                        /* Check for priorities 8-15.  */
                        priority_map =    priority_map >> TX_THREAD_GROUP_SIZE;
                        priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                        if (priority_group)
                            priority =  
                                TX_THREAD_GROUP_1 + _tx_thread_lowest_bit[priority_group];
                        else
                        {

                            /* Check for priorities 16-23.  */
                            priority_map =    priority_map >> TX_THREAD_GROUP_SIZE;
                            priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                            if (priority_group)
                                priority =  
                                    TX_THREAD_GROUP_2 + _tx_thread_lowest_bit[priority_group];
                            else
                            {

                                priority_map =    priority_map >> TX_THREAD_GROUP_SIZE;
                                priority_group =  (UCHAR) (priority_map & TX_THREAD_PRIORITY_GROUP_MASK);
                                priority =    
                                    TX_THREAD_GROUP_3 + _tx_thread_lowest_bit[priority_group];
                            }
                        }
                    }

                    /* Determine if the next highest priority thread is above the highest
                       priority threshold value.  */
                    if (_tx_thread_highest_priority >= 
                                    (_tx_thread_priority_list[priority] -> tx_preempt_threshold))
                    {

                        /* Thread not allowed to execute until earlier preempted thread 
                           finishes or lowers its preemption threshold.  */
                        _tx_thread_execute_ptr =  _tx_thread_priority_list[priority];

                        /* Clear the corresponding bit in the preempted map, since the
                           preemption has been restored.  */
                        _tx_thread_preempted_map =  
                                _tx_thread_preempted_map & ~(_tx_thread_execute_ptr -> tx_priority_bit);
                    }
                }
            }

            /* Restore interrupts.  */
            TX_RESTORE

            /* Determine if we need to return to the system.  This needs to happen if a self suspension
               takes place or if a higher-priority thread was resumed by an ISR in the part of the
               suspension process that has interrupts enabled.  */
            if ((_tx_thread_current_ptr != _tx_thread_execute_ptr) && (_tx_thread_system_state == 0))
            {

                /* Return control to the system.  */
                _tx_thread_system_return();
            }

            /* Return to caller.  */
            return;
        }
    }
    else
    {

        /* Thread not still suspending...  Restore interrupts.  */
        TX_RESTORE

        /* Check for a preemption condition that might have occurred from an ISR.  */
        if ((_tx_thread_current_ptr != _tx_thread_execute_ptr) && (_tx_thread_system_state == 0))

            /* Return control to the system.  */
            _tx_thread_system_return();
    }
}

⌨️ 快捷键说明

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