51/AVR单片机技术驿站!  <在线翻译>     便利工具    特色网址   无弹窗、无插件的绿色站点...  英才招聘   学历查询  喜欢>>收藏我站 

当前位置:首页 > 取经杂谈 > 详细内容
uCOS-II的移植代码 for 8051 !
作者:电子牛  发布时间:2009/10/16  阅读次数:5693  字体大小: 【】 【】【


[dvnews_page=OS_CPU_A.ASM之的内核代码部分1]


;*******************************************************************************
**************************
;                                                                                   START MULTITASKING
;                                                                             void OSStartHighRdy(void) LG_REENTRANT
;出栈后就意味着启动了第一个任务
; The stack frame is assumed to look as follows:
;
;                       出       /\                       出栈:task
底\高                 (高内存)
;                       栈       ||                       出栈:ACC
;                       顺       ||                       出栈:B
;                       序       ||                       出栈:DPH      
       //暂时忽略第二指针
;                         |       ||       |               出栈:DPL
;                         |                 |               出栈:PSW
;                         |______________|               出栈:R7-R4
;                                                       出栈:
os_pdata(R3,R2,R1)用寄存器传递os_pdata
;                       OSTCBHighRdy->OSTCBStkPtr -->       出栈:R0      
       (底内存)
;
; Note : OSStartHighRdy() MUST:
;                     a) Call OSTaskSwHook() then,
;                     b) Set OSRunning to TRUE,
;                     c) Switch to the highest priority task.
;*******************************************************************************
**************************
       ?PR?_?OSStartHighRdy?OS_CPU_A           SEGMENT CODE        
                                               ;第3个问号表示重入函

       RSEG       ?PR?_?OSStartHighRdy?OS_CPU_A       ;函数体段

_?OSStartHighRdy:
       USING       0
       ;OS_ENTER_CRITICAL
       LCALL         _?OSTaskSwHook                       ;调用OSTaskSwHook();
       SETB         OSRunning                       ;OSRunning= TRUE;
       ;切换到最高优先级的任务
       JMP       CtxSw                               ;MOV         ?C_XBP,0

;*******************************************************************************
**************************
;                                                               PERFORM A CONTEXT SWITCH (From task level)
;                                                                                     void OSCtxSw(void)
;
; Note(s): 1) Upon entry,
;                         OSTCBCur         points to the OS_TCB of the task to suspend
;                         OSTCBHighRdy points to the OS_TCB of the task to resume
;
;                   2) The stack frame of the task to suspend looks as follows:
;
;                                 SP -> OFFSET   of task to suspend       (Low memory)
;                                             SEGMENT of task to suspend
;                                             PSW         of task to suspend       (High memory)
;
;                   3) The stack frame of the task to resume looks as follows:
;
;               出       /\       用RET             出栈:task底\高地址         (高内存)
;               栈       ||                       出栈:ACC
;               顺       ||                       出栈:B
;               序       ||                       出栈:DPH      
       //暂时忽略第二指针
;                 |       ||       |               出栈:DPL
;                 |                 |               出栈:PSW
;                 |______________|               出栈:R0
;                                               出栈:os_pdata
(R1,R2,R3)用寄存器传递os_pdata
;               OSTCBHighRdy->OSTCBStkPtr -->       出栈:R4-R7      
       (底内存)
;                                                                                             Flags to load in
PSW                         (High memory)
;任务级切换:
;1:PUSHALL
;2:?C_BXP<=(SP)
;3:OSTCBCur->OSTCBStkPtr<=?C_BXP
;4:     ...
;5:?C_BXP<=OSTCBHighRdy->OSTCBStkPtr
;6:(SP)<=?C_BXP
;7:POPALL
;8:RET
;*******************************************************************************
**************************
       ?PR?_?OSCtxSw?OS_CPU_A                         SEGMENT CODE
       RSEG       ?PR?_?OSCtxSw?OS_CPU_A
_?OSCtxSw:
       USING       0
       ;OS_ENTER_CRITICAL
       ;(1)保存处理器的寄存器
       PUSHALL

       ;(2)拷贝SP(系统)堆栈中的内容到?C_XBP,               SP       满向上
               ;然后清空它(即MOV SP,#?STACK-1)                       ?C_XBP       满向下
       LCALL       _CopySPtoC_XBP                       ;COPY SP 的内容到?
C_XBP

       ;(3)在当前任务的任务控制块中保存当前任务(旧任务)的堆栈指针
               ;OSTCBCur->OSTCBStkPtr=?C_XBP
       MOV         DPH,#HIGH(OSTCBCur)
       MOV         DPL, #LOW(OSTCBCur)

       INC       DPTR                               ;指针是3字节的
把我害死了
       MOVX       A,@DPTR
       MOV       R1,A
       INC       DPTR
       MOVX       A,@DPTR
       MOV       DPH,R1
       MOV       DPL,A
      
       INC       DPTR                               ;指针是3字节的
把我害死了
       MOV       A,?C_XBP
       MOVX       @DPTR,A
       INC       DPTR
       MOV       A,?C_XBP+1
       MOVX       @DPTR,A
       IntCtxSw:
       ;(4)调用OSTaskSwHook();
       ;(5)OSTCBCur       = OSTCBHighRdy;
                     ;(6)OSPrioCur       = OSPrioHighRdy;
               LCALL       _ComCtxSw1

       ;(7)得到将要重新开始运行的任务(新任务)的堆栈指针
       ;?C_XBP       = OSTCBHighRdy->OSTCBStkPtr;(0x0217)
       ;(8)拷贝原任务(新任务)中的?C_XBP到SP(系统)堆栈中       SP       满向上
               ;然后清空它(即?C_XBP中的原堆栈内容)                       ?C_XBP
       满向下
       CtxSw:
               LCALL       _ComCtxSw2
       LCALL       _CopyC_XBPtoSP

                     ;(9)从新任务堆栈中恢复处理器所有寄存器的值
       POPALL
       ;OS_EXIT_CRITICAL
       ;(10)执行返回指令
       SETB         EA                       ;强行开中断!!!!!!
       RET
/*$PAGE*/
;*******************************************************************************
**************************
;                                                               PERFORM A CONTEXT SWITCH (From an ISR)
;                                                                               void OSIntCtxSw(void)
;       ;中断级切换:在OSInExit()中已判断了有高优先级的任务在就绪队列中,所以直接切
换到高优先级任务
;*******************************************************************************
**************************

       ?PR?_?OSIntCtxSw?OS_CPU_A                         SEGMENT CODE
       RSEG       ?PR?_?OSIntCtxSw?OS_CPU_A
_?OSIntCtxSw:
       USING       0
       ;OS_ENTER_CRITICAL
       ACALL       _IntRETI
       JMP       IntCtxSw              
_IntRETI:
       RETI
;*******************************************************************************
**************************
;                                                                                       HANDLE TICK ISR
;*******************************************************************************
**************************
               CSEG       AT         000BH               ;设置T0中断向量
               LJMP       _?OSTickISR

       ?PR?_?OSTickISR?OS_CPU_A                         SEGMENT CODE
       RSEG       ?PR?_?OSTickISR?OS_CPU_A
_?OSTickISR:
       USING       0
       CLR       EA
       ;(1)保存处理器寄存器   先PUSH到SP在COPY到?C_XBP   OSTCBHighRdy
       PUSHALL
       LCALL       _CopySPtoC_XBP&nb
来源:21icbbs
我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

网站导航 管理登陆 ┊ 免责声明 问题反馈  友链说明
本站部分内容来自网络共享资源,如有冒犯您的权利请来信告之删除或纠正!
不得对本站进行复制、盗链或镜像,转载内容须获得同意或授权;欢迎友情链接、站务合作!

    我要报警 Alexa
 mcusy_cn#126.com (请把#改成@) 交流:522422171
本站学习交流群:138..158(高级群1-)、77930286(高级群2)、61804809(群3)
Copyright© MCUSY All Rights Reserved
本站网警备案号: WZ36040002485
  ICP备案证书号:粤ICP备09034963号