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

📄 os_cpu_c.c

📁 uCOS-II的移植代码 for 8051 [绝对原著]
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
********************************************************************************
*************************
*                                        INITIALIZE A TASK'S STACK
*
* Description: This function is called by either OSTaskCreate() or 
OSTaskCreateExt() to initialize the
*              stack frame of the task being created.  This function is highly 
processor specific.
*
* Arguments  : task          is a pointer to the task code
*
*              os_pdata         is a pointer to a user supplied data area that 
will be passed to the task
*                            when the task first executes.
*
*              ptos          is a pointer to the top of stack.  It is assumed 
that 'ptos' points to
*                            a 'free' entry on the task stack.  If 
OS_STK_GROWTH is set to 1 then 
*                            'ptos' will contain the HIGHEST valid address of 
the stack.  Similarly, if
*                            OS_STK_GROWTH is set to 0, the 'ptos' will 
contains the LOWEST valid address
*                            of the stack.
*
*              opt           specifies options that can be used to alter the 
behavior of OSTaskStkInit().
*                            (see uCOS_II.H for OS_TASK_OPT_???).
*
* Returns    : Always returns the location of the new top-of-stack' once the 
processor registers have
*              been placed on the stack in the proper order.
*
* Note(s)    : Interrupts are enabled when your task starts executing. You can 
change this by setting the
*              PSW to 0x0002 instead.  In this case, interrupts would be 
disabled upon task startup.  The
*              application code would be responsible for enabling interrupts at 
the beginning of the task
*              code.  You will need to modify OSTaskIdle() and OSTaskStat() so 
that they enable 
*              interrupts.  Failure to do this will make your system crash!
********************************************************************************
*************************
*/
/*
at89c55wd PDL(sp form LOW to HIGH):        (堆栈指针所指的栈顶数据为有效数
据)
                            装入堆栈指
针ptos到stk
                    
                stk-->        入栈:task底\高    
                    (高内存)
                入    ||        入栈:ACC
                栈    ||        入栈:B
                顺    ||        入栈:DPH    
    //暂时忽略第二指针
                序    ||         入栈:DPL
                 |  \/    |     入栈:PSW
                 |        |     入栈:R7-
R4
                 |______|    入栈:os_pdata(R3,R2,R1)用寄存
器传递os_pdata
                            入栈:R0    
                        (底内存)

            //                入栈:
DPS??        //双数据指针选择寄存器??
            //                入栈:PC
自己应该参照编译器定义入栈/出栈顺序,写出来备以后查阅
*/
OS_STK  *OSTaskStkInit (void (*task)(void *pd)LG_REENTRANT, void *os_pdata, 
OS_STK *ptos, INT16U opt) LG_REENTRANT
{
    //INT16U *stk;
    OS_STK    *stk;

    opt    = opt;                           /* 'opt' is not used, prevent 
warning                      */
    stk    = (OS_STK *)ptos;                /* Load stack 
pointer                                      */
                                
            //装入堆栈指针ptos到stk

    *stk = 0;                            
    //入栈:R0
    stk               -= sizeof(void *);
    *(void **)stk   = (void *)os_pdata;        //用寄存器传递
os_pdata
    *--stk = 4;                        
        //入栈:R4-R7
    *--stk = 5;
    *--stk = 6;
    *--stk = 7;                        
        

    *--stk = PSW;                        
    //入栈:PSW
    *--stk = 'L';                        
    //入栈:DPL
    *--stk = 'H';                        
    //入栈:DPH        //暂时忽略第二指针
    *--stk = 'B';                        
    //入栈:B
    *--stk = 'A';                        
    //入栈:ACC

    *--stk    = ((INT16U)task & 0xff00) >> 8;    //保存任务地址
    *--stk    = (INT16U)task & 0x00ff;

    *--stk = 15;                        
    //入栈个数
                                
            //END
    return ((OS_STK *)stk);
}

/*$PAGE*/
/*
********************************************************************************
*************************
*                        INITIALIZE A TASK'S STACK FOR FLOATING POINT EMULATION
*
********************************************************************************
*************************
*/

/*$PAGE*/
//void  OSTaskStkInit_FPE_x86 (OS_STK **pptos, OS_STK **ppbos, INT32U *psize)
//{
//}

/*$PAGE*/
/*
********************************************************************************
*************************
*                                           TASK SWITCH HOOK
*
* Description: This function is called when a task switch is performed.  This 
allows you to perform other
*              operations during a context switch.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts are disabled during this call.
*              2) It is assumed that the global pointer 'OSTCBHighRdy' points 
to the TCB of the task that
*                 will be 'switched in' (i.e. the highest priority task) 
and, 'OSTCBCur' points to the 
*                 task being switched out (i.e. the preempted task).
********************************************************************************
*************************
*/
#if OS_CPU_HOOKS_EN > 0 
void  OSTaskSwHook (void) LG_REENTRANT
{
}
#endif

/*
********************************************************************************
*************************
*                                           OSTCBInit() HOOK
*
* Description: This function is called by OS_TCBInit() after setting up most of 
the TCB.
*
* Arguments  : ptcb    is a pointer to the TCB of the task being created.
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
********************************************************************************
*************************
*/
#if OS_CPU_HOOKS_EN > 0 && OS_VERSION > 203
void  OSTCBInitHook (OS_TCB *ptcb) LG_REENTRANT
{
    ptcb = ptcb;                                           /* Prevent Compiler 
warning                 */
}
#endif


/*
********************************************************************************
*************************
*                                               TICK HOOK
*
* Description: This function is called every tick.
*
* Arguments  : none
*
* Note(s)    : 1) Interrupts may or may not be ENABLED during this call.
********************************************************************************
*************************
*/
#if OS_CPU_HOOKS_EN > 0 
void  OSTimeTickHook (void) LG_REENTRANT
{
}
#endif


/*
********************************************************************************
*************************
*                                
                中断服务程序外挂
*        NOTE  :  注意:所有中断外挂都在临界区之外,用户可以自行控制进/退
临界区
********************************************************************************
*************************
*/
#if OS_ISR_T1_EN > 0
void    OSISR_T1HOOK (void) LG_REENTRANT
{

        /* 请在这里输入中断服务程序            
    */

}
#endif

#if OS_ISR_INT0_EN > 0
void    OSISR_INT0HOOK (void) LG_REENTRANT
{

        /* 请在这里输入中断服务程序            
    */

}
#endif

#if OS_ISR_INT1_EN > 0
void    OSISR_INT1HOOK (void) LG_REENTRANT
{

        /* 请在这里输入中断服务程序            
    */

}
#endif

#if OS_ISR_S0_EN > 0
void    OSISR_S0HOOK (void) LG_REENTRANT
{

        /* 请在这里输入中断服务程序            
    */

        

}
#endif

----------------

;*******************************************************************************
*************************
;                                               uC/OS-II
;                                         The Real-Time Kernel
;
;                          (c) Copyright 1992-2002, Jean J. Labrosse, Weston, FL
;                                          All Rights Reserved
;
;
;                                       at89c55wd Specific code
;                                          LARGE MEMORY MODEL
;
;                                           keil C/C++ V7.2
;                                       (at89c55wd Compatible Target)
;
; File         : OS_CPU_A.ASM
; By           : Jean J. Labrosse
; Port by      : 牛毅    2005-04-25->2005-04-28    
    QQ:75011221    niuyimail@126.com
;        修补 :  2005-05-02-01:30  (增加了中断管理和临界区宏)
;        修补 :  2005-05-16-13:00  (修补_CopySPtoC_XBP的漏洞, 有标记
处%%%%????%%%%%%)
;*******************************************************************************
*************************
#include    "OS_CFG.H"

            NAME    OS_CPU_A

;*******************************************************************************
*************************
;                                      要使用的外部函数和公共数据
;*******************************************************************************
*************************
            EXTRN CODE  (_?OSIntExit)
            EXTRN CODE  (_?OSTimeTick)
            EXTRN CODE  (_?OSTaskSwHook)

IF    OS_ISR_T1_EN <> 0
        EXTRN CODE    (_?OSISR_T1HOOK)
ENDIF
IF    OS_ISR_INT0_EN <> 0
        EXTRN CODE    (_?OSISR_INT0HOOK)
ENDIF
IF    OS_ISR_INT1_EN <> 0
        EXTRN CODE    (_?OSISR_INT1HOOK)
ENDIF
IF    OS_ISR_S0_EN <> 0
        EXTRN CODE    (_?OSISR_S0HOOK)
ENDIF

        EXTRN DATA    (?C_XBP)
;DT?C_XBP    SEGMENT    DATA
;        RSEG    DT?C_XBP
;?C_XBP:
;C_XBP:
;    DS    1
        ?STACK    SEGMENT IDATA
        RSEG    ?STACK
        ;?STACK:
        Stack:
        DS    40    

            EXTRN BIT     (OSRunning)
            EXTRN XDATA (OSIntNesting)
;            EXTRN XDATA (OSTickDOSCtr)
            EXTRN XDATA (OSPrioHighRdy)
            EXTRN XDATA (OSPrioCur)
        EXTRN XDATA (OSTCBCur)        
            EXTRN XDATA (OSTCBHighRdy)

;*******************************************************************************
*************************
;                                               MACRO DEFINE
;*******************************************************************************
*************************
PUSHALL    MACRO
    ;PUSH    PC    
    PUSH    ACC
    PUSH    B
    PUSH    DPH
    PUSH    DPL

⌨️ 快捷键说明

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