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

📄 os_cpu_a.asm

📁 uCosII+543+lcd 128*64 汉字显示
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;********************************************************************************************************
;                                               uC/OS-II
;                                         The Real-Time Kernel
;
;                         (c) Copyright 1992-1999, Jean J. Labrosse, Weston, FL
;                                          All Rights Reserved
;
;
;                                       Fujitsu F2MC-16LX Specific code
;                                             ALL MEMORY MODELS
;
;                                   FFMC-16 Family Softune Assembler V30L05
;
; File         : OS_CPU_A.ASM
; By           : Andrey Mozzhevilov. Yekaterinburg. Russia. andy@svrw.ru, andy_moz@mail.ru
;                                                           www.geocities.com/andy_moz
; Port Version : 1.00
; Date         : 07-December-2001
;
; Notes        :
;
;********************************************************************************************************

;********************************************************************************************************
;                                    GLOBAL REFERENCES
;********************************************************************************************************

        .PROGRAM  OS_CPU_A
        .LIBRARY  "lib905s.lib"

        .GLOBAL _OSTickISR

	.GLOBAL	_iDIRR_ISR
	.GLOBAL	__dirr

        .GLOBAL _OSStartHighRdy
        .GLOBAL _OSCtxSw
        .GLOBAL _OSIntCtxSw

        .GLOBAL _OSIntExit
        .GLOBAL _OSTimeTick
        .GLOBAL _OSTaskSwHook

        .GLOBAL _OSIntNesting
        .GLOBAL _OSTickDOSCtr
        .GLOBAL _OSPrioHighRdy
        .GLOBAL _OSPrioCur
        .GLOBAL _OSRunning
        .GLOBAL _OSTCBCur
        .GLOBAL _OSTCBHighRdy

	.SECTION CTXSWVECT, CONST, LOCATE=H'FFFFFC
	.DATA.L	_OSCtxSw

;********************************************************************************************************
;         Include OS config
;********************************************************************************************************
#include "os_cpu.h"
#include "os_cfg.h"

; ------- Memory models ---------      default address size
                                   ;      data      code
#set      SMALL     0              ;     16 Bit    16 Bit
#set      MEDIUM    1              ;     16 Bit    24 Bit
#set      COMPACT   2              ;     24 Bit    16 Bit
#set      LARGE     3              ;     24 Bit    24 Bit

; You should use one of the these lines or define MEMMODEL_xxx by option "-D" assembler */
;#define MEMMODEL_SMALL
;#define MEMMODEL_COMPACT
;#define MEMMODEL_MEDIUM    
#define MEMMODEL_LARGE  /*wyj 05.11.14*/

#ifndef MEMMODEL_SMALL
  #ifndef MEMMODEL_COMPACT
    #ifndef MEMMODEL_MEDIUM
      #ifndef MEMMODEL_LARGE
        #error MEMMODEL_...... must be specify
      #endif
    #endif
  #endif
#endif

#ifdef MEMMODEL_SMALL
  #set MEMMODEL SMALL
#endif

#ifdef MEMMODEL_COMPACT
  #set MEMMODEL COMPACT
#endif

#ifdef MEMMODEL_MEDIUM
  #set MEMMODEL MEDIUM
#endif

#ifdef MEMMODEL_LARGE
  #set MEMMODEL LARGE
#endif

#if (OS_CRITICAL_METHOD != 1) && (OS_CRITICAL_METHOD != 2) && (OS_CRITICAL_METHOD != 12)
#error OS CRITICAL METHOD must be set as 1, 2 or 12, see os_cpu.h
#endif

#ifndef TASKS_CAN_USE_BANK0
#error TASKS CAN USE BANK0 must be set as 1 or 0, see os_cfg.h
#endif

;********************************************************************************************************
;         Include interrupt enter macro
;********************************************************************************************************
#include "isr_mac.inc"


        .SECTION CODE, CODE, ALIGN=1

;*********************************************************************************************************
;                                Macro  SAVE_REGISTERS_CONTEXT
;  It Is Used in _OSCtxSw and _iDIR_ISR for save bank of registers in the task stack.
;
;  Loads the word with tops of stack and defines, what bank of registers uses task to suspend.
;  If this bank of registers #0, that is in addition produced the save in stack of task to suspend
;  bank of registers #0. And place PS on top of stack again.
;
;*********************************************************************************************************

#macro SAVE_REGISTERS_CONTEXT
#local skip
#if TASKS_CAN_USE_BANK0 == 1
     POPW   A                                      ; Get PS at top of stack
     PUSHW  A                                      ;
     ANDW   A,#1F00H                               ;
     BNZ    skip                                   ;

     MOVW   A,SP                                   ;
     MOVW   A,@A                                   ;
     MOV    RP,#00H                                ;
     PUSHW  (RW0,RW1,RW2,RW3,RW4,RW5,RW6,RW7)      ; Save interrupted task's context
     PUSHW  A                                      ; Save PS at top of stack
#endif
skip:
#endm


;*********************************************************************************************************
;                                Macro  RESTORE_REGISTERS_CONTEXT
;                 It Is Used in _OSStartHighRdy, _OSCtxSw   _iDIRR_ISR
;
;  Loads the word with tops of stack and defines, what bank of registers uses task to resume.
;  If this bank of registers #0, that is in addition produced the restore bank of registers #0.
;*********************************************************************************************************

#macro RESTORE_REGISTERS_CONTEXT
#local skip
#if TASKS_CAN_USE_BANK0 == 1
     POPW   A                                      ; Get PS at top of stack
     PUSHW  A                                      ;
     ANDW   A,#1F00H                               ;
     BNZ    skip                                   ;

     POPW   A                                      ;
     MOV    RP,#00H                                ;
     POPW   (RW0,RW1,RW2,RW3,RW4,RW5,RW6,RW7)      ; Load new task's context
#endif
skip:
#endm


;*********************************************************************************************************
;                                          START MULTITASKING
;                                       void OSStartHighRdy(void)
; Note(s):
;
;  The stack frame is assumed to look as follows:
;
; 1) If task uses bank of registers other that #0, then the
;    stack frame of the task looks as follows:
;
;            (High memory)
;          |       |       |
;          |       |       | <- a value of SSP must be here after reti instruction
;          |       AH      |
;          |       AL      |
;          |  DPR  |  ADB  |
;          |  DTB  |  PCB  |
;          |       PC      |
;          |       PS      | <- OSTCBHighRdy->OSTCBStkPtr
;          |       |       |
;            (Low memory)
;
; 2) If task uses bank of registers #0, then the
;    stack frame of the task looks as follows:
;
;            (High memory)
;          |       |       |
;          |       |       | <- a value of SSP must be here after reti instruction
;          |       AH      |
;          |       AL      |
;          |  DPR  |  ADB  |
;          |  DTB  |  PCB  |
;          |       PC      |
;          |       PS      |
;          |  RW7-bank(0)  |
;          |  RW6-bank(0)  |
;          |  RW5-bank(0)  |
;          |  RW4-bank(0)  |
;          |  RW3-bank(0)  |
;          |  RW2-bank(0)  |
;          |  RW1-bank(0)  |
;          |  RW0-bank(0)  |
;          |       PS      | <- OSTCBHighRdy->OSTCBStkPtr
;          |       |       |
;            (Low memory)
;
; Note : OSStartHighRdy() MUST:
;           a) Call OSTaskSwHook() then,
;           b) Set OSRunning to TRUE,
;           c) Switch to the highest priority task.
;*********************************************************************************************************


_OSStartHighRdy:

#if MEMMODEL == SMALL || MEMMODEL == COMPACT
     CALL   _OSTaskSwHook                          ; Call user defined task switch hook
#elif MEMMODEL == MEDIUM || MEMMODEL == LARGE
     CALLP  _OSTaskSwHook                          ; Call user defined task switch hook
#endif
;

#if MEMMODEL == SMALL || MEMMODEL == MEDIUM
     MOVW   A,_OSTCBHighRdy                        ;
;
     MOVW   A,@A                                   ;
     MOVW   SP,A                                   ; SP = *OSTCBHighRdy->OSTCBStkPtr
#endif

#if MEMMODEL == COMPACT || MEMMODEL == LARGE

     MOV    A, #bnksym _OSTCBHighRdy               ;
     MOV    ADB, A                                 ; Set bank of _OSTCBHighRdy

     MOVL   A,ADB:_OSTCBHighRdy                    ; Get OSTCBStkPtr
;
     PUSHW  A                                      ;

     SWAPW                                         ; Set bank for access to
     MOV    ADB, A                                 ; *OSTCBHighRdy->OSTCBStkPtr
     SWAPW                                         ;
;
     MOVW   A,ADB:@A                               ;
     POPW   A                                      ;
     SWAPW                                         ;
     MOVW   SP,A                                   ; SP = *OSTCBHighRdy->OSTCBStkPtr

     SWAPW                                         ;
     ADDW   A,#2                                   ;
     MOVW   A,ADB:@A                               ;
     MOV    SSB,A
#endif
;
     RESTORE_REGISTERS_CONTEXT                     ; Restore context of resisters
;
     MOVN   A,#1                                   ;
     MOV    _OSRunning,A                           ; OSRunning = TRUE;
;
     RETI                                          ; Run task


;*********************************************************************************************************
;                                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) If task to suspend uses bank of registers other that #0, then the
;             stack frame of the task looks as follows:
;
;            (High memory)
;          |       |       |
;          |       |       | <- a value of SSP before the CtxSw sowtware interrupt occurrence
;          |       AH      |
;          |       AL      |
;          |  DPR  |  ADB  |
;          |  DTB  |  PCB  |
;          |       PC      |
;          |       PS      | <- a value of SSP after the CtxSw interrupt occurrence
;          |       |       |
;            (Low memory)
;
;          3) If task to suspend uses bank of registers #0, then the
;             stack frame of the task looks as follows:
;
;            (High memory)
;          |       |       |
;          |       |       | <- a value of SSP before the CtxSw sowtware interrupt occurrence
;          |       AH      |
;          |       AL      |
;          |  DPR  |  ADB  |
;          |  DTB  |  PCB  |
;          |       PC      |
;          |       PS      | <- a value of SSP after the CtxSw interrupt occurrence
;          |  RW7-bank(0)  |
;          |  RW6-bank(0)  |
;          |  RW5-bank(0)  |
;          |  RW4-bank(0)  |
;          |  RW3-bank(0)  |
;          |  RW2-bank(0)  |
;          |  RW1-bank(0)  |
;          |  RW0-bank(0)  |
;          |       PS      | <- a value of SSP must be here after registers context saved
;          |       |       |
;            (Low memory)
;
;          4) If task to resume uses bank of registers other that #0, then the
;             stack frame of the task looks as follows:
;
;            (High memory)
;          |       |       |
;          |       |       | <- a value of SSP must be here after reti instruction
;          |       AH      |
;          |       AL      |
;          |  DPR  |  ADB  |
;          |  DTB  |  PCB  |
;          |       PC      |
;          |       PS      | <- OSTCBHighRdy->OSTCBStkPtr
;          |       |       |
;            (Low memory)
;
;          5) If task to resume uses bank of registers #0, then the stack frame
;             of the task looks as follows:
;            (High memory)
;          |       |       |
;          |       |       | <- a value of SSP must be here after reti instruction
;          |       AH      |
;          |       AL      |
;          |  DPR  |  ADB  |
;          |  DTB  |  PCB  |
;          |       PC      |
;          |       PS      | <- a value of SSP must be here after registers context restored
;          |  RW7-bank(0)  |
;          |  RW6-bank(0)  |
;          |  RW5-bank(0)  |
;          |  RW4-bank(0)  |
;          |  RW3-bank(0)  |
;          |  RW2-bank(0)  |
;          |  RW1-bank(0)  |
;          |  RW0-bank(0)  |
;          |       PS      | <- OSTCBHighRdy->OSTCBStkPtr
;          |       |       |
;            (Low memory)
;*********************************************************************************************************

_OSCtxSw:
;
#if OS_CRITICAL_METHOD == 12

⌨️ 快捷键说明

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