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

📄 os_cpu_a.s

📁 uCOSII在motorala单片机上的移植
💻 S
📖 第 1 页 / 共 2 页
字号:
;********************************************************************************************************
;                                               uC/OS-II
;                                         The Real-Time Kernel
;
;                            (c) Copyright 1999, Jean J. Labrosse, Weston, FL
;                                          All Rights Reserved
;
;
;                                           683xx Specific code
;                                               SDS C V7.4
;
; File         : OS_CPU_A.S
; By           : Jean J. Labrosse
;********************************************************************************************************

    .OPTION  target=CPU32,flags=gG

;********************************************************************************************************
;                                            REVISION HISTORY
;
; $Log:   J:/software/ucos-ii/m683xx/sds/source/vc/os_cpu_a.s_v  $
;    
;      Rev 1.3   01 May 1999 11:51:40   JJL
;      ***************************** M683xx REL V1.05 ******************************
;      - Added check of OSIntNesting in OSIntExit68K() (see OS_CPU_A.S).
;    
;      Rev 1.2   29 Jun 1999 22:04:02   JJL
;      ***************************** M683xx REL V1.04 ******************************
;      - Added function OSIntExit68K() (see OS_CPU_A.S) which must now be JUMPed to
;        at the end of ALL ISRs.  Your ISR code MUST now look as follows:
;        
;        _YourISR:
;            ADDQ.B    #1,_OSIntNesting       ; OSIntNesting++
;            MOVEM.L   A0-A6/D0-D7,-(A7)      ; Save ALL registers 
;            ;   CLEAR the INTERRUPT source!
;            JSR       _YourISRHandler
;            JMP       _OSIntExit68K          ; Exit through uC/OS-II at end of ISR
;    
;        As you can see, you MUST increment OSIntNesting at the beginning of the ISR
;        and NOT call OSIntExit().  OSIntExit68K() knows to return to task level code 
;        because it examines the stack frame for the contents of the Status register 
;        (SR) that is pushed onto the stack when the CPU recognizes an interrupt.
;********************************************************************************************************


;********************************************************************************************************
;                                          PUBLIC DECLARATIONS
;********************************************************************************************************
   
    xdef   _OSCtxSw
    xdef   _OSIntCtxSw                     ; Satisfy OSIntExit() in OS_CORE.C
    xdef   _OSIntExit68K
    xdef   _OSStartHighRdy
    xdef   _OSTickISR
    
;********************************************************************************************************
;                                         EXTERNAL DECLARATIONS
;********************************************************************************************************
   
    xref   _OSCtxSwCtr
    xref   _OSIntExit
    xref   _OSIntNesting  
    xref   _OSLockNesting  
    xref   _OSPrioCur    
    xref   _OSPrioHighRdy
    xref   _OSRdyGrp
    xref   _OSRdyTbl
    xref   _OSRunning   
    xref   _OSTaskSwHook 
    xref   _OSTCBCur     
    xref   _OSTCBHighRdy 
    xref   _OSTCBPrioTbl
    xref   _OSTimeTick
    xref   _OSUnMapTbl

;********************************************************************************************************
;                               START HIGHEST PRIORITY TASK READY-TO-RUN
;
; Description : This function is called by OSStart() to start the highest priority task that was created
;               by your application before calling OSStart().
;
; Arguments   : none
;
; Note(s)     : 1) The stack frame is assumed to look as follows:
;   
;                  OSTCBHighRdy->OSTCBStkPtr +  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         OS_INITIAL_SR
;                                            + 62         task  (H)
;                                            + 64         task  (L)
;                                            + 66         0x80 + 4 * TRAP#
;                                            + 68         task  (H)
;                                            + 70         task  (L)
;                                            + 72         pdata (H)
;                                            + 74         pdata (L)        High Memory
;
;               2) OSStartHighRdy() MUST:
;                      a) Call OSTaskSwHook() then,
;                      b) Set OSRunning to TRUE,
;                      c) Switch to the highest priority task.
;********************************************************************************************************

    SECTION   code
    
_OSStartHighRdy:
    JSR       _OSTaskSwHook            ; Invoke user defined context switch hook            
    ADDQ.B    #1,_OSRunning            ; Indicate that we are multitasking                  

    MOVE.L    (_OSTCBHighRdy),A1       ; Point to TCB of highest priority task ready to run 
    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                                           

;********************************************************************************************************
;                                       TASK LEVEL CONTEXT SWITCH
;
; Description : This function is called when a task makes a higher priority task ready-to-run.
;
; Arguments   : none
;
; 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 (the registers for
;                  task to suspend need to be saved):
;
;                                         SP +  0  ---->  SR                   Low Memory
;                                            +  2         PC of task  (H)
;                                            +  4         PC of task  (L)      
;                                            +  6         0x80 + 4 * TRAP#     High Memory
;
;               3) The stack frame of the task to resume looks as follows:
; 
;                  OSTCBHighRdy->OSTCBStkPtr +  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         OS_INITIAL_SR       (See OS_CPU.H)
;                                            + 62         PC of task  (H)
;                                            + 64         PC of task  (L)
;                                            + 66         0x80 + 4 * TRAP#    High Memory
;********************************************************************************************************

_OSCtxSw:
    MOVEM.L   A0-A6/D0-D7,-(A7)              ; Save the registers of the current task
    
    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

⌨️ 快捷键说明

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