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

📄 os_cpu_a.asm

📁 keil C166下ucos-ii,c164ci的移植程序
💻 ASM
📖 第 1 页 / 共 3 页
字号:
;                                           +0A  USER STACK OFFSET POINTER (R0) of task
;                                           +08  USER STACK PAGE POINTER (DPP1) of task
;                                           +06  PSW flags of task
;                                           +04  OFFSET  of task return address
;                                           +02  SEGMENT of task return address
;             OSTCBHighRdy->OSTCBStkPtr -->   0
;                                           -02  R[1 ..15] General Purpose registers of task
;                                           -20  CP     Context pointer of task
;                                           -22  DPP3   Data page pointer 3 of task
;                                           -24  DPP2   Data page pointer 2 of task
;                                           -26  DPP0   Data page pointer 0 of task
;                                           -28  MDC    Multiply/Divide Control of task
;                                           -2A  MDH    Multiply/Divide High register of task
;                                           -2C  MDL    Multiply/Divide Low register of task
;                                           -2E  Calls to OsIntExit, OSIntCtxSw and locals.   (Low Memory)
;********************************************************************************************************
OSIntCtxSw      PROC    INTERRUPT    UCOS_OSIntCtxSw = 0x51    

                BCLR    IEN                         ; Disable interrupts

                ADD     DPP3:SP,#0Ah                 ; Remove From System Stack the calls to OSIntCtxSw and OsIntExit
                NOP                                                    ; Ignore calls to OSIntExit,OSIntCtxSw and locals.

                POP     R2                          ; Get "current" IP
                POP     R1                          ; Get "current" CSP
                POP     R3                          ; Get "current" PSW


                EXTP    #PAG OSTCBCur,#02h          ; pStack = OSTCBCur->OSTCBStkPtr
                MOV     R8,POF (OSTCBCur)           ; pStack = R9:R8
                MOV     R9,POF (OSTCBCur+2)
                EXTP    R9,#02h
                MOV     R6,[R8+]
                MOV     R7,[R8]

                EXTP    R7,#03h                     ; Save this task's interrupt context in task user stack
                MOV     [R6+#02h],R1                ;     Task CSP
                MOV     [R6+#04h],R2                ;     Task IP
                MOV     [R6+#06h],R3                ;     Task STATUS

                MOV     R4,#TOS                     ; Get the top of the System Stack
                MOV     R5,SP
_OSIntCtxSwSave:
                CMP     R4,R5                       ; Compare if Pointer is equal to Current Stack position on system stack
                JMPA    cc_EQ,_OSIntCtxSwSaveEnd    ; Exit the Loop if they are equal
                SUB     R4,#02H                     ; Decrement pointer of System Stack
                EXTS    #0,#1
                MOV     R3,[R4]                     ; Read data from system stack
                MOV     [-R0],R3                    ; Save System Stack Value to the Task Satck
                JMPA    cc_UC,_OSIntCtxSwSave       ; RE-Loop again
_OSIntCtxSwSaveEnd:
                MOV     R4,DPP1                     ; Get "current" DPP1

                EXTP    R7,#03h
                MOV     [R6+#08H],R4                ;     Task DPP1
                MOV     [R6+#0AH],R0                ;     Task R0
                MOV     [R6+#0CH],R5                ;     Task SP

                CALLS   SEG(OSTaskSwHook),SOF(OSTaskSwHook)  ; Call user defined task switch hook
_ADDR02:
                EXTP    #PAG OSTCBHighRdy,#02h     ; Get the stack pointer of the task to resume
                MOV     R8,POF OSTCBHighRdy        ; OSTCBCur = OSTCBHighRdy
                MOV     R9,POF (OSTCBHighRdy+2)
                EXTP    #PAG OSTCBCur,#02h
                MOV     POF (OSTCBCur),R8
                MOV     POF (OSTCBCur+2),R9

                EXTP    #PAG OSPrioHighRdy,#01h    ;  OSPrioCur = OSPrioHighRdy;
                MOVB    RL1,POF OSPrioHighRdy
                EXTP    #PAG OSPrioCur,#01h
                MOVB    POF OSPrioCur,RL1

                EXTP    R9,#02h                     ; R7:R6 = OSTCBHighRdy->OSTCBStkPtr
                MOV     R6,[R8+]
                MOV     R7,[R8]

                EXTP    R7,#03h
                MOV     R5,[R6+#0Ch]                ;     Get Task SP
                MOV     R0,[R6+#0Ah]                ;     Get Task R0
                MOV     R4,[R6+#08h]                ;     Get Task DPP1

                MOV     DPP1,R4                     ; Write "current task" DPP1

                MOV     SP,R5                       ; Replace the Task System Stack Pointer
                MOV     R4,#TOS                     ; Get the top of the System Stack
_OSIntCtxSwRestore:
                CMP     R4,R5                       ; Compare if Pointer is equal to Satck Pointer (SP)
                JMPA    cc_EQ,_OSIntCtxSwRestoreEnd ; Loop if not equal
                MOV     R3,[R0+]                    ; Read value in the task stack
                EXTS    #0,#1
                MOV     [R5],R3                     ; Replace System Stack Value
                ADD     R5,#02H                     ; Increment pointer of System Stack
                JMPA    cc_UC,_OSIntCtxSwRestore    ; Loop again
_OSIntCtxSwRestoreEnd:

                EXTP    R7,#03h                     ; Load this task's interrupt context on the system stack
                MOV     R3,[R6+#06h]                ;     Get Task PSW
                MOV     R2,[R6+#04h]                ;     Get Task IP
                MOV     R1,[R6+#02h]                ;     Get Task CSP

                PUSH    R3                          ; Replace PSW on System stack
                PUSH    R1                          ; Replace CSP on system Stack
                PUSH    R2                          ; Replace IP on System Stack

                %RestoreContext()                   ; Restore all processor registers from the new task's stack

                BSET    IEN                         ; Enable interrupts

                RETI                                ; Return to new task

OSIntCtxSw      ENDP
;********************************************************************************************************
;                                             HANDLE TICK ISR
;                                          void OSTickISR (void)
;
; Description: 时钟节怕中断服务程序,每10毫秒调用一次
;
; Arguments  : none
;
; Returns    : none
;
; Note(s)    : The following C-like pseudo-code describe the operation being performed in the code below.
;
;              Disable interrupts;
;              Save all registers on the current task's stack;
;              OSIntEnter();
;              OSTimeTick();              Notify uC/OS-II that a tick has occured
;              Clear RTC or Timer Interrupt Response Bit
;              OSIntExit();               Notify uC/OS-II about end of ISR
;              Restore all registers that were save on the current task's stack;
;              Enable interrupts;
;              Return from Interrupt;
;********************************************************************************************************
OSTickISR       PROC    INTERRUPT  UCOS_OSTickISR  = RTC_INT

                BCLR    IEN                         ; Disable interrupts

                %SaveContext()                        ; Save current task's context
                CALLS    SEG (OSIntEnter), SOF(OSIntEnter)
                CALLS    SEG (OSTimeTick), SOF(OSTimeTick)
                CALLS    SEG (RTC_SoftIDW),  SOF(RTC_SoftIDW)
                EXTR     #01H
                BCLR     RTCIR         ; Clear RTC Interrupt Response Bit
                CALLS    SEG (OSIntExit),  SOF(OSIntExit)

                %RestoreContext()                     ; Restore new task's context

                BSET    IEN                         ; Enable interrupts
                RETI                                ; Return to interrupted task

OSTickISR      ENDP
;********************************************************************************************************
;                                        核扫描中断服务程序
;********************************************************************************************************
MessISR         PROC    INTERRUPT  UCOS_MessISR  = MESS_INT
                BCLR    IEN

                %SaveContext()
                CALLS    SEG (OSIntEnter), SOF(OSIntEnter)
                CALLS    SEG (MessDealWith), SOF(MessDealWith)
                CALLS    SEG (OSIntExit),  SOF(OSIntExit)

                %RestoreContext()                     ; Restore new task's context

                BSET    IEN                         ; Enable interrupts
                RETI
MessISR        ENDP
;********************************************************************************************************
;                                        索引脉冲中断服务程序
;********************************************************************************************************
IndexISR         PROC    INTERRUPT  UCOS_IndexISR  = INDEX_INT
                BCLR    IEN

                %SaveContext()
                CALLS    SEG (OSIntEnter), SOF(OSIntEnter)
                CALLS    SEG (Index_IDW), SOF(Index_IDW)
                CALLS    SEG (OSIntExit),  SOF(OSIntExit)

                %RestoreContext()                     ; Restore new task's context

                BSET    IEN                         ; Enable interrupts
                RETI
IndexISR        ENDP
UCOS_C16X       ENDS
                END

⌨️ 快捷键说明

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