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

📄 os_cpu_a.asm

📁 TI公司的dsp55xx的ports应用。是官方的
💻 ASM
📖 第 1 页 / 共 2 页
字号:
        mov     XAR0, dbl(*(#_pargsav))  ;* AR0  _p_arg
        ;
        ; This function does not return the correct value of the new TOS because
        ; it is no known here.  It will be fixed in OSTaskCreateHook()
        ;
        ret

;       This is the actual Task Stack Init function.
;

_IntStack:                              ; trap 5 lands here
;
;       Save the Interrupt context
;
        nop
        nop
        nop
        mov     xsp, dbl(*(#_XSPsav))   ; XSP
        mov     xssp, dbl(*(#_XSSPsav)) ; XSSP

        CONTEXT_SAVE
        nop
        nop
        nop
        mov     xsp, dbl(*(#_XSPsav1))  ; XSP
        mov     xssp, dbl(*(#_XSSPsav1)); XSSP
        nop
        nop
        nop
        nop
        nop
        nop
        mov     dbl(*(#_XSPsav)), xsp   ; XSP
        mov     dbl(*(#_XSSPsav)), xssp ; XSSP
        nop
        nop
        nop
        nop
        nop
        nop
        mov     ssp, AR3
        nop
        nop
        nop
        mov     *AR3+, AR1
        mov     *AR3+, AR1
        mov     AR1, *(#_SSP2)          ; DBSTAT
        mov     *AR3, AR1
        mov     AR1, *(#_SSP3)           ;  ST0_55
;
        mov     *SP(#0), AR1
        mov     *SP(#1), AR1
        bclr    #11, AR1       ; Enable interrupts
        mov     AR1, *(#_SP2)            ; ST1_55
        mov     *SP(#2), AR1
        mov     AR1, *(#_SP3)            ; ST2_55
;
;
;  Restore the stack to where it was just before the trap
;  and get the function parameters that were passed to OSTaskStkInit(...)
;

        mov     dbl(*(#_ptoSSsav)), XAR1        ; Build a reti SSP stack (using SP)
        mov     XAR1, XSSP                      ; SSP = ptoSS
        mov     dbl(*(#_ptossav)), XAR1         ; Build a reti SP stack
        mov     XAR1, XSP                       ; SP = ptos
                nop                             ; a little time to let the SP settle
        nop
        nop
        mov     dbl(*(#_SSP3)), AC0             ; ST0_55  ST2_55
        pshboth AC0
        mov     dbl(*(#_SSP2)), AC0             ; DBSTAT  ST1_55
        pshboth AC0
        mov     dbl(*(#_tasksav)), AC0          ; (Loop bits): PC(23-16) and PC(15-0)
        pshboth AC0

        mov     #0x0000, AC0
        mov     #0x0101, AC1
        mov     #0x0202, AC2
        mov     #0x0303, AC3
        mov     #0x0404, T0
        mov     #0x0505, T1
;;        amov    #0x0606, XAR0
        mov    dbl(*(#_pargsav)), XAR0
        amov    #0x0707, XAR1
        amov    #0x0808, XAR2
        amov    #0x0909, XAR3
        amov    #0x1010, XAR4
        amov    #0x1111, XAR5
        amov    #0x1212, XAR6
        amov    #0x1313, XAR7

        CONTEXT_SAVE;
        mov     xsp, dbl(*(_pbossav))           ; save the current stack pointer for OSTaskCreateHook()
        mov     dbl(*(#_XSPsav1)), xsp          ; XSP
        mov     dbl(*(#_XSSPsav1)), xssp        ; XSSP
        nop
        nop
        nop
        nop
        nop
        nop
        CONTEXT_RESTORE
        nop
        nop
        nop
        nop
        nop
        nop
        reti


;*********************************************************************************************************
;                                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 -> PC of task to suspend
;
;          3) The stack frame of the task to resume looks as follows:
;
;                 PC of task to resume
;*********************************************************************************************************

_OSCtxSw:
        CONTEXT_SAVE                    ; save all registers on the current stack
        nop                             ;
        nop                             ;
        nop                             ;
;
;       OSTCBCur->OSTCBStkPtr = SP
;
        mov     dbl(*(#_OSTCBCur)), XAR3
        mov     XSP, dbl(*AR3)                  ;OSTCBCur->OSTCBStkPtr = SP
;
;       Call OSTaskSwHook();
;
        call    #_OSTaskSwHook
;
;       Make high ready task the current task
;
        mov     dbl(*abs16(#_OSTCBHighRdy)), XAR0
        nop                                     ;
        mov     XAR0, dbl(*(#_OSTCBCur))        ; OSTCBCur = OSTCBHighRdy
;
        mov     *abs16(#_OSPrioHighRdy), AR3
        nop                                     ;
        mov     AR3, *(#_OSPrioCur)             ; OSPrioCur = OSPrioHighRdy
;
; restore new task  ( SP = OSTCBHighRdy->OSTCBStkPtr )
;
        mov     dbl(*AR0+), XAR3
        nop
        mov     XAR3, XSP               ; load the sp for new task
        nop                             ;
        nop                             ;
        nop                             ;

        CONTEXT_RESTORE                 ; new task context is restored here, no A has *pdata, sp point to *task

        nop
        nop
        nop
        nop
        nop
        nop
        reti                            ;      run task

;*********************************************************************************************************
;                                PERFORM A CONTEXT SWITCH (From an ISR)
;                                        void OSIntCtxSw(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 --> 	FRAME -1 from OSIntExit
;                                	        return address to OSIntExit()
;                                    	    return address to ISR
;                                         	dummy to make even SP after push old SP
;                                           old SP, -- SP before old even adjustment
;                                           if old SP is odd, this is a dummy, otherwise non-exist
;                                           MMRs - but no IMR
;                                           ..
;											..
;											..
;                                           return address of the task code

;          3) The stack frame of the task to resume looks as follows:
;
;             OSTCBHighRdy->OSTCBStkPtr --> MMRs
;                                           address of the task to resume
;*********************************************************************************************************

_OSIntCtxSw:
        aadd    #-1, SP
;
;       Call OSTaskSwHook();
;
        call    #_OSTaskSwHook
;
;       Make high ready task the current task
;
        mov     dbl(*abs16(#_OSTCBHighRdy)), XAR0
        nop                                     ;
        mov     XAR0, dbl(*(#_OSTCBCur))        ; OSTCBCur = OSTCBHighRdy
;
        mov     *abs16(#_OSPrioHighRdy), AR3
        nop                                     ;
        mov     AR3, *(#_OSPrioCur)             ; OSPrioCur = OSPrioHighRdy
;
; restore new task  ( SP = OSTCBHighRdy->OSTCBStkPtr )
;
        mov     dbl(*AR0+), XAR3
        nop
        mov     XAR3, XSP               ; load the sp for new task

        nop                             ;
        nop                             ;
        nop                             ;

        CONTEXT_RESTORE                 ; new task context is restored here
        nop
        nop
        nop
        nop
        nop
        nop
	reti;

;*********************************************************************************************************
;                                            HANDLE TICK ISR
;
; Description: This function is .
;
; Arguments  : none
;
; Returns    : none
;
; Note(s)    : The following C-like pseudo-code describe the operation being performed in the code below.
;
;              Save all registers on the current task's stack;
;              OSIntNesting++;
;              OSTimeTick();              Notify uC/OS-II that a tick has occured
;              OSIntExit();               Notify uC/OS-II about end of ISR
;              Restore all registers that were save on the current task's stack;
;              Return from Interrupt;
;*********************************************************************************************************

_OSTickISR:
;
;              Save all registers on the current task's stack
;
        CONTEXT_SAVE
        nop
        nop
        nop
;
;              OSIntNesting++;
;
        and     #0FBFFh, mmap(ST1_55)   ; clear M40
        add     1, *(#_OSIntNesting)
;
;       if OSIntNesting == 1 then save the SP of the current task into OSTCBCur->OSTCBStkPtr
;
        mov     *(#_OSIntNesting), AR1
        cmp     mmap(AR1) == 1, TC1
        bcc     L3,!TC1                 ; branch if not
        mov     dbl(*(#_OSTCBCur)), XAR3
        mov     XSP, dbl(*AR3)          ;OSTCBCur->OSTCBStkPtr = SP
;
;              OSTimeTick();            Notify uC/OS-II that a tick has occured
;
L3:     call    _OSTimeTick
;
;              OSIntExit();             Notify uC/OS-II about end of ISR
;
        call    _OSIntExit
;
;              Restore all registers that were save on the current task's stack;
;              Return from Interrupt
;
        CONTEXT_RESTORE
        nop
        nop
        nop
        nop
        nop
        nop
        reti

;*********************************************************************************************************
;                               Save / Restore status routines
;
;       Support for OS_ENTER_CRITICAL and OS_ENTER_CRITICAL
;
;       OS_CPU_SaveSR saves the current interrupt enable status, disables interrupts and returns the
;       previous setting to the caller.
;
;       OS_CPU_RestoreSR sets the interrupt enable to the passed value.
;
;*********************************************************************************************************
;
; OS_CPU_SR OS_CPU_SaveSR(void)
;
_OS_CPU_SaveSR:
        mov     mmap(ST1_55),  T0       ; get the interrupt enable bit
        and     #0800h,  T0, T0
        bclr    #st1_intm, st1_55       ; Disable interrupts
        ret

;
; OS_CPU_RestoreSR(OS_CPU_SR foo)
;
_OS_CPU_RestoreSR:
        aadd    #-1, SP
        mov     T0, *SP(#0)
        cmp     *SP(#0) == #0800h, TC1  ; Were interrupts enabled when OSEnterCritical called?
        bcc     L1,!TC1
        bset    #st1_intm, st1_55       ; yes, enable them again
        b L2
L1:
        bclr    #st1_intm, st1_55       ; no, leave them disabled
L2:
        aadd    #1, SP
        ret

;*********************************************************************************************************
;                               VectorInit
;
;       For debugging only.  Changes the interrupt vector table location for testing w/o burning flash
;
;*********************************************************************************************************
_VectorInit:
        mov     T0, mmap(IVPD)
        mov     T0, mmap(IVPH)
        ret

;*********************************************************************************************************
;                               Error Interrupt Catch-all
;
;       These error traps need to be expanded to provide safe shutdown or controlled restart!
;
;*********************************************************************************************************
_BerrISR:
        b _BerrISR
        nop
        nop
        nop

_InvalidISR:
        b _InvalidISR
        nop
        nop
        nop

.end




⌨️ 快捷键说明

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