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

📄 os_cpu_a.s

📁 m683xx系列单片机(8位)
💻 S
📖 第 1 页 / 共 2 页
字号:
;                                            + 48         A4    (H)
;                                            + 50         A4    (L)
;                                            + 52         A5    (H)
;                                            + 54         A5    (L)
;                                            + 56         A6    (H)
;                                            + 58         A6    (L)
;                                            + 60         OS_INITIAL_SR
;                                            + 62         PC of task  (H)
;                                            + 64         PC of task  (L)
;                                            + 66         0x80 + 4 * TRAP#    High Memory
;********************************************************************************************************

_OSCtxSw:
    MOVEM.L   A0-A6/D0-D7,-(A7)              ; 72~ Save the registers of the current task
    
    MOVE.L    (_OSTCBCur),A1                 ;  4~ Save the stack pointer in the suspended task TCB
    MOVE.L    A7,(A1)                        ;  4~
    
    JSR       _OSTaskSwHook                  ; 13~ Invoke user defined context switch hook            

    MOVE.L    (_OSTCBHighRdy),A1             ;  4~ OSTCBCur  = OSTCBHighRdy
    MOVE.L    A1,(_OSTCBCur)                 ;  4~
    MOVE.L    (A1),A7                        ;  4~ Get the stack pointer of the task to resume
    
    MOVE.B    _OSPrioHighRdy,_OSPrioCur      ;  6~ OSPrioCur = OSPrioHighRdy
    
    MOVEM.L   (A7)+,A0-A6/D0-D7              ; 70~ Restore the CPU registers

    RTE                                      ; 24~ Run task                                           

;********************************************************************************************************
;                                      INTERRUPT LEVEL CONTEXT SWITCH
;
; Description : This function is provided for backward compatibility and your ISR MUST NOT call 
;               OSIntExit().  Instead, your ISR MUST JUMP to OSIntExit68K().
;
; Arguments   : none
;
; Note(s)     : 1) The stack frame upon entry:
;
;********************************************************************************************************

_OSIntCtxSw:
    ADDA.L    #18,A7                         ; Adjust the stack
    
    MOVE.L    (_OSTCBCur),A1                 ; Save the stack pointer in the suspended task TCB
    MOVE.L    A7,(A1)
    
    JSR       _OSTaskSwHook                  ; Invoke user defined context switch hook            

    MOVE.L    (_OSTCBHighRdy),A1             ; OSTCBCur  = OSTCBHighRdy
    MOVE.L    A1,(_OSTCBCur)                 

    MOVE.B    _OSPrioHighRdy,_OSPrioCur      ; OSPrioCur = OSPrioHighRdy
    
    MOVE.L    (A1),A7                        ; Get the stack pointer of the task to resume
    
    MOVEM.L   (A7)+,A0-A6/D0-D7              ; Restore the CPU registers

    RTE                                      ; Run task                                           

;********************************************************************************************************
;                                      INTERRUPT EXIT FUNCTION
;
; Description : Your ISR MUST JUMP to this function when it is done.
;
; Arguments   : none
;
; Note(s)     : 1) Stack frame upon entry:
;
;                  SP +  0  ---->  D0    (H)                         Low Memory
;                     +  2         D0    (L)
;                     +  4         D1    (H)
;                     +  6         D1    (L)
;                     +  8         D2    (H)
;                     + 10         D2    (L)
;                     + 12         D3    (H)
;                     + 14         D3    (L)
;                     + 16         D4    (H)
;                     + 18         D4    (L)
;                     + 20         D5    (H)
;                     + 22         D5    (L)
;                     + 24         D6    (H)
;                     + 26         D6    (L)
;                     + 28         D7    (H)
;                     + 30         D7    (L)
;                     + 32         A0    (H)
;                     + 34         A0    (L)
;                     + 36         A1    (H)
;                     + 38         A1    (L)
;                     + 40         A2    (H)
;                     + 42         A2    (L)
;                     + 44         A3    (H)
;                     + 46         A3    (L)
;                     + 48         A4    (H)
;                     + 50         A4    (L)
;                     + 52         A5    (H)
;                     + 54         A5    (L)
;                     + 56         A6    (H)
;                     + 58         A6    (L)
;                     + 60         Task or ISR's SR
;                     + 62         PC of task  (H)
;                     + 64         PC of task  (L)
;                     + 66         0x80 + 4 * TRAP#                  High Memory
;********************************************************************************************************

_OSIntExit68K:
    ORI       #$0700,SR                     ; Disable interrupts

    SUBQ.B    #1,_OSIntNesting              ; OSIntNesting--;
    BNE       OSIntExit68K_Exit

    MOVE.B    _OSLockNesting,D0			    ; if (OSLockNesting == 0) {
    BNE       OSIntExit68K_Exit

    MOVE.W    (60,A7),D0                    ;     if (LAST nested ISR) {
    ANDI.W    #$0700,D0
    BNE       OSIntExit68K_Exit
                                            
    MOVEQ.L   #0,D0                         ;         y = OSUnMapTbl[OSRdyGrp];
    MOVE.B    _OSRdyGrp,D0
    MOVE.L    D0,A0
    MOVE.B    (_OSUnMapTbl,A0),D2
                                            
    MOVE.B    D2,D0                         ;         OSPrioHighRdy = (INT8U)((y << 3) + OSUnMapTbl[OSRdyTbl[y]]);
    LSL.B     #3,D0
    MOVEQ.L   #0,D1
    MOVE.B    D2,D1
    MOVE.L    D1,A0
    MOVEQ.L   #0,D1
    MOVE.B    (_OSRdyTbl,A0),D1
    MOVE.L    D1,A0
    ADD.B     (_OSUnMapTbl,A0),D0

    MOVE.B    D0,_OSPrioHighRdy             ;          if (OSPrioHighRdy != OSPrioCur) {
    CMP.B     _OSPrioCur,D0                 
    BEQ       OSIntExit68K_Exit
                                            
    MOVEQ.L   #0,D1                         ;              OSTCBHighRdy  = OSTCBPrioTbl[OSPrioHighRdy];
    MOVE.B    D0,D1
    LSL.L     #2,D1
    MOVE.L    D1,A0
    MOVE.L    (_OSTCBPrioTbl,A0),_OSTCBHighRdy

                                             
    ADDQ.L    #1,_OSCtxSwCtr                ;              OSCtxSwCtr++;
                                            ;              PERFORM INTERRUPT LEVEL CONTEXT SWITCH:            
    MOVE.L    (_OSTCBCur),A1                ;                  Save the stack pointer in the suspended task TCB
    MOVE.L    A7,(A1)
    
    JSR       _OSTaskSwHook                 ;                  Invoke user defined context switch hook            

    MOVE.L    (_OSTCBHighRdy),A1            ;                  OSTCBCur  = OSTCBHighRdy
    MOVE.L    A1,(_OSTCBCur)                

    MOVE.B    _OSPrioHighRdy,_OSPrioCur     ;                  OSPrioCur = OSPrioHighRdy
    
    MOVE.L    (A1),A7                       ;                  Get the stack pointer of the task to resume
    
OSIntExit68K_Exit:
    MOVEM.L   (A7)+,A0-A6/D0-D7             ; Restore the CPU registers

    RTE                                     ; Return to task or nested ISR

;********************************************************************************************************
;                                           SYSTEM TICK ISR
;
; Description : This function is the ISR used to notify uC/OS-II that a system tick has occurred.  
;
; Arguments   : none
;
; Note(s)    : The following C-like pseudo-code describe the operation being performed in the code below.
;
;              OSIntNesting++;
;              Save all registers on the current task's stack;
;              if (OSIntNesting == 1) {
;                 OSTCBCur->OSTCBStkPtr = SP
;              }
;              Clear the interrupt source;
;              OSTimeTick();              Notify uC/OS-II that a tick has occured
;              JUMP to OSIntExit68K;      Notify uC/OS-II about end of ISR
;********************************************************************************************************

_OSTickISR:
    ADDQ.B    #1,_OSIntNesting               ; OSIntNesting++;

    MOVEM.L   A0-A6/D0-D7,-(A7)              ; Save the registers of the current task

    CMPI      #1,_OSIntNesting               ; if (OSIntNesting == 1) {
    BNE       _OSTickISR1
;
    MOVE.L    (_OSTCBCur),A1                 ;     OSTCBCur->OSTCBStkPtr = SP;
    MOVE.L    A7,(A1)                        ; }

_OSTickISR1:
;   CLEAR the INTERRUPT source!
    
    JSR       _OSTimeTick                    ; Call uC/OS-II's tick updating function                 
    
    JMP       _OSIntExit68K                  ; Exit ISR through uC/OS-II
    
    END
    

⌨️ 快捷键说明

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