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

📄 threadx_cpu.c

📁 hreadx实时嵌入式操作系统源代码,ARM移植. threadx是一个很好的多任务实时嵌入式操作系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/**************************************************************************/ 
/*                                                                        */ 
/*      only for 32bit mode and dosn't support interrupt nesting          */
/*                                                                        */  
/* File name:               threadX_cpu.c								  */
/* Last modified Date:      2008-03-28									  */
/* Last Version:            0.01										  */
/* Descriptions:            											  */
/* QQ:                      307102293									  */
/* ENAIL:                   wodexinxiang1949@163.com                      */
/*                                                                        */
/**************************************************************************/

/* Include necessary system files.  */
#include "config.h"
#include "tx_api.h"
#include "tx_api.h"
#include "tx_thr.h"
#include "tx_tim.h"
#include "tx_ini.h"
#include "tx_blo.h"
#include "threadX_cpu.h"

/**************************************************************************/
/**************************************************************************/
/**                                                                       */ 
/**     macro Config                                                      */ 
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define __TX_DYNAMIC_MEM_SIZE		    8000
#define __TX_THREAD_TIMER_STKSIZE       512

    /*  dynamic memery declear  */
    static int  _tx_initialize_first_memory[__TX_DYNAMIC_MEM_SIZE];

    /*  stack for timer thread  */
    static int  _tx_timer_stack[__TX_THREAD_TIMER_STKSIZE];

    /*  declear for complier.   none used   */
    char    __ghsbegin_events[100];
    char    __ghsend_events[100];
    
    /*  pointer to system stack */
    extern int *__ptx_sys_statck;

/**************************************************************************/
/**************************************************************************/
/**                                                                       */ 
/**     function for weak complier                                        */ 
/**                                                                       */
/**************************************************************************/
/**************************************************************************/
void        __cpp_exception_init(void **pp){}
void        __cpp_exception_cleanup(void **pp){}

/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_initialize_low_level                                            */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*                                                                        */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function is responsible for any low-level processor            */ 
/*    initialization, including setting up interrupt vectors, saving the  */ 
/*    system stack pointer, finding the first available memory address,   */ 
/*    and setting up parameters for the system's timer thread.            */ 
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    _tx_initialize_kernel_enter           ThreadX entry function        */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*                                                                        */ 
/**************************************************************************/
void        _tx_initialize_low_level(void)
{
    _tx_thread_system_stack_ptr     = (VOID_PTR)__ptx_sys_statck;
    _tx_timer_stack_start           = &_tx_timer_stack[0];
    _tx_timer_stack_size            = sizeof(_tx_timer_stack);
    _tx_timer_priority              = 0;
    _tx_initialize_unused_memory    = (VOID_PTR) &_tx_initialize_first_memory[0];    
    __tx_initialize_low_level();
}

/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_timer_interrupt                                                 */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*                                                                        */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function processes the hardware timer interrupt.  This         */ 
/*    processing includes incrementing the system clock and checking for  */ 
/*    time slice and/or timer expiration.  If either is found, the        */ 
/*    interrupt context save/restore functions are called along with the  */ 
/*    expiration functions.                                               */ 
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  OUTPUT                                                                */ 
/*                                                                        */ 
/*    None                                                                */ 
/*                                                                        */ 
/*  CALLS                                                                 */ 
/*                                                                        */ 
/*    _tx_thread_context_save               Save interrupted context      */ 
/*    _tx_thread_resume                     Resume timer processing thread*/ 
/*    _tx_thread_time_slice                 Time slice interrupted thread */ 
/*    _tx_thread_context_restore            Restore interrupted context   */ 
/*                                                                        */ 
/*  CALLED BY                                                             */ 
/*                                                                        */ 
/*    interrupt vector                                                    */ 
/*                                                                        */ 
/*  RELEASE HISTORY                                                       */ 
/*                                                                        */ 
/*    DATE              NAME                      DESCRIPTION             */ 
/*                                                                        */ 
/*                                                                        */ 
/**************************************************************************/ 
VOID   _tx_timer_interrupt(VOID)
{
    _tx_timer_system_clock++;                                           /*  系统滴答时间加              */
    if (_tx_timer_time_slice) {                                         /*  如果有剩余的时间片          */
		_tx_timer_time_slice--;                                         /*  时间片调整、减一            */
		if (_tx_timer_time_slice == 0) {                                /*  如果当前时间片耗尽          */
			_tx_timer_expired_time_slice =  TX_TRUE;                    /*  设置标识                    */
		}
    }

    if (*_tx_timer_current_ptr) {                                       /*  是否有定时器需要处理        */
        _tx_timer_expired =  TX_TRUE;
    } else {
        _tx_timer_current_ptr++;                                        /*  指向下一时刻定时器就绪链表头*/
        if (_tx_timer_current_ptr == _tx_timer_list_end){
            _tx_timer_current_ptr =  _tx_timer_list_start;
		}
    }

    if ((_tx_timer_expired_time_slice) || (_tx_timer_expired)) {        /*  有事情要做                  */
		if (_tx_timer_expired) {
		    _tx_timer_expired   = TX_FALSE;
			_tx_thread_preempt_disable++;
	
			_tx_thread_resume(&_tx_timer_thread);                       /*  回复定时器线程              */
		}
		if (_tx_timer_expired_time_slice) {
    		_tx_timer_expired_time_slice    = TX_FALSE;
			if (_tx_thread_time_slice() == TX_FALSE) {                  /*  不需要切换,载入分配的时间片*/
				_tx_timer_time_slice =  _tx_thread_current_ptr -> tx_time_slice;
			}
		 } 
    }
}

/**************************************************************************/ 
/*                                                                        */ 
/*  FUNCTION                                               RELEASE        */ 
/*                                                                        */ 
/*    _tx_thread_stack_build                                              */ 
/*                                                           3.0a         */ 
/*  AUTHOR                                                                */ 
/*                                                                        */ 
/*                                                                        */ 
/*                                                                        */ 
/*  DESCRIPTION                                                           */ 
/*                                                                        */ 
/*    This function builds a stack frame on the supplied thread's stack.  */
/*    The stack frame results in a fake interrupt return to the supplied  */
/*    function pointer.                                                   */ 
/*                                                                        */ 
/*  INPUT                                                                 */ 
/*                                                                        */ 
/*    thread_ptr                            Pointer to thread control blk */
/*    function_ptr                          Pointer to return function    */

⌨️ 快捷键说明

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