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

📄 threadx_cpu.c

📁 hreadx实时嵌入式操作系统源代码,ARM移植. threadx是一个很好的多任务实时嵌入式操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    _tx_thread_create                     Create thread service         */
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*                                                                        */ 
/**************************************************************************/ 
void        _tx_thread_stack_build(TX_THREAD *thread_ptr, void (*function_ptr)(void))
{    
    ARM_STACK    *ArmRegister   = 0;
    
    ArmRegister         = (ARM_STACK *)(((int)thread_ptr->tx_stack_end - sizeof(ARM_STACK) - 1) & 0xfffffffc);
    
    ArmRegister->cpsr   = MODE_USR32;
    ArmRegister->lr     = (int)(thread_ptr->tx_thread_entry);    
    ArmRegister->r0     = (unsigned int)thread_ptr->tx_entry_parameter;    
    ArmRegister->r1     = 0;    
    ArmRegister->r2     = 0;    
    ArmRegister->r3     = 0;    
    ArmRegister->r4     = 0;    
    ArmRegister->r5     = 0;    
    ArmRegister->r6     = 0;    
    ArmRegister->r7     = 0;    
    ArmRegister->r8     = 0;    
    ArmRegister->r9     = 0;    
    ArmRegister->r10    = 0;    
    ArmRegister->r11    = 0;    
    ArmRegister->r12    = 0;    
    ArmRegister->pc     = (int)(thread_ptr->tx_thread_entry);    

    thread_ptr->tx_stack_ptr    = (VOID_PTR)ArmRegister;
}
/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    __tx_thread_contex_restore                                          */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*                                                                        */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    When this function has been called, scheduler should be processing  */
/*    here. If no thread was in order, we execute a loop until a thread   */
/*    was actived by interrupt handle. Golbal variable 				      */
/*    _tx_thread_current_ptr was point to the active thread when return.  */
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    __tx_thread_swi_system_return                                       */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*                                                                        */ 
/**************************************************************************/ 
void        __tx_thread_contex_restore(void)
{
    _tx_thread_current_ptr 	= _tx_thread_execute_ptr;                   /*  指向新线程地址              */
    _tx_thread_current_ptr->tx_run_count++;                             /*  调度增加                    */
    _tx_timer_time_slice 	= _tx_thread_current_ptr->tx_time_slice     /*  新的时间片                  */
                            ? _tx_thread_current_ptr->tx_time_slice
                            : _tx_thread_current_ptr->tx_new_time_slice;
}

/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    __tx_thread_contex_save                                             */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*                                                                        */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    Save the time slice                                                 */
/*  																	  */
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    __tx_thread_swi_system_return                                       */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*                                                                        */ 
/**************************************************************************/ 
void        __tx_thread_contex_save(void)
{
    if (_tx_thread_current_ptr != TX_NULL) {
        _tx_thread_current_ptr->tx_time_slice   = _tx_timer_time_slice
                                                ? _tx_timer_time_slice
                                                : _tx_thread_current_ptr->tx_new_time_slice;
    }
}

/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_thread_preempt_check                        68332/Green Hills   */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*    William E. Lamie, Express Logic, Inc.                               */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function checks for a preempt condition that might have taken  */ 
/*    place on top of an optimized assembly language ISR.  If preemption  */ 
/*    should take place, context save/restore processing is called.	      */ 
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    0:    Current thread is active                                      */ 
/*    1:    A new thread is active but contex has saved yet               */
/*    2:    A new thread is active and contex havn't been saved           */
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*   __tx_thread_swi_system_return                                        */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*                                                                        */ 
/**************************************************************************/ 
int        __tx_thread_preempt_check (void)
{
    if (_tx_thread_execute_ptr == _tx_thread_current_ptr) {
        
        return 0;
    } else {
        if (_tx_thread_execute_ptr->tx_stack_ptr > 
            _tx_thread_execute_ptr->tx_stack_end ||
            _tx_thread_execute_ptr->tx_stack_ptr <
            _tx_thread_execute_ptr->tx_stack_start){
            while(1) {
            }
        }

        if (_tx_thread_current_ptr->tx_stack_ptr != 0) {
            return 1;
        } else {
            return 2;
        } 
    }
}
/**************************************************************************/
/*     end of file                                                        */ 
/**************************************************************************/

⌨️ 快捷键说明

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