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

📄 kernel.lib

📁 一个C style Assembler的source code
💻 LIB
字号:
;;; An interrupt-driven multi-processing library for the Intel 8052.;;; This package requires an 80C52-compatible microprocessor with at least;;; 256k of indirectly addressible RAM.  All interrupts are reserved for;;; process-handling, in this library.  But you still have to write the;;; software that enables/disables them.  Timer 2's interrupt-handlers are set;;; up to handle capture mode.  Different handlers should be written in place;;; of this for the different timer 2 modes.;;; Initially, the only process run is main().  It or any other process can;;; Spawn() other processes and main() can even go idle with the other;;; processes running in the background.  A background process is tied to an;;; interrupt or to another (accessible) background process through Resume().;;;  When Resume() is called, the process continues where it left off at the;;; last call of Pause() and continues until either it returns or calls Pause();;; again.;;; /* Task control block */;;; typedef struct {;;;    char *SP; /* The process's stack pointer */;;; } Task;;;; /* Process stack. */PSP    equ 105  ;;; Task *PSP;PStack equ 106  ;;; Task PStack[8];;;; /* Interrupt descriptor table. */SP_IE0  equ  114SP_TF0  equ  115SP_IE1  equ  116SP_TF1  equ  117SP_RI   equ  118SP_TI   equ  119SP_TF2  equ  120SP_EXF2 equ  121SP_SW0  equ  122SP_SW1  equ  123SP_SW2  equ  124SP_SW3  equ  125SP_BASE equ  126;;; Special function registers for the 8052T2CON  equ 0xc8RCAP2L equ 0xcaRCAP2H equ 0xcbTL2    equ 0xccTH2    equ 0xcd;;; SFR bits for the 80c52.;;; P1T2Ex bit P1.1T2   bit P1.0;;; T2CONTF2    bit T2CON.7EXF2   bit T2CON.6RCLK   bit T2CON.5TCLK   bit T2CON.4EXEN2  bit T2CON.3TR2    bit T2CON.2C_T2   bit T2CON.1CP_RL2 bit T2CON.0;;; IE and IPET2 bit IE.5PT2 bit IP.5org 00hsjmp Startorg 03h   mov R0, #SP_IE0   acall Resumeretiorg 0bh   mov R0, #SP_TF0   acall Resumeretiorg 13h   mov R0, #SP_IE1   acall Resumeretiorg 1bh   mov R0, #SP_TF1   acall Resumeretiorg 23h   jbc TI, DidTx   jbc RI, DidRxretiorg 2bh   jnb EXEN2, DidTF2   jnb EXF2, DidTF2   jnb TF2, DidEXF2   mov A, RCAP2H   jnb Acc.7, DidTF2 ;;; This determines if TF2 or EXF2 was first.DidEXF2:   clr EXF2   mov R0, #SP_EXF2   acall ResumeretiDidTF2:   clr TF2   mov R0, #SP_TF2   acall ResumeretiDidTx:   mov R0, #SP_TI   acall ResumeretiDidRx:   mov R0, #SP_RI   acall ResumeretiStart: ;;; Install main(), set its return address to Die().   mov PSP, #PStack        ;;; PSP = &PStack[0];   mov SP, #(SP_BASE - 1)  ;;; SP = SP_BASE - 1;   mov DPTR, #Exit   push DPL   push DPH                ;;; *SP++ = Exit();   acall mainDie:   orl PCON, #1sjmp DiePause:                     ;;; void Pause(Task *R0) {   mov @R0, SP             ;;;    R0->SP = SP;   dec PSP   mov R0, PSP   mov SP, @R0             ;;;    SP = (--PSP)->SP;ret                        ;;;    "wait for Resume";Resume:   mov R1, PSP   mov @R1, SP   inc PSP                 ;;;    (PSP++)->SP = SP;   mov SP, @R0             ;;;    SP = R0->SP;   mov @R0, #(SP_BASE + 1) ;;;    R0->SP = SP_BASE + 1;ret                        ;;; }Spawn:                   ;;; int Spawn(char *R0, void (*DPTR)()) {   mov R1, PSP   mov @R1, SP   inc PSP               ;;;    (PSP++)->SP = SP;   dec R0   mov SP, R0            ;;;    SP = --R0;   acall Enter           ;;;    (*DPTR)();Exit:   dec PSP   mov R0, PSP   mov SP, @R0           ;;;    SP = (--PSP)->SP;ret                      ;;; }Enter:   push DPL   push DPHret

⌨️ 快捷键说明

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