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

📄 os_xa-cl.c

📁 uCOS的源码例子
💻 C
字号:
/*
*********************************************************************************************************
*                                                 uC/OS
*                                          The Real-Time Kernel
*
*                                              CREATE TASK
*
*                                       Philips Semiconductors, Inc.
*                                             XA (Large Model)
*
* File : OS_XA-CL.C
*********************************************************************************************************
*/

#include "INCLUDES.H"

/*$PAGE*/
/*
*********************************************************************************************************
*                                           CREATE A TASK
*
* Notes : 1) Two bytes are pushed on the stack for the ES   register because the POPU.B ES   instruction
*            (see OS_XA-AL.AS) actually pops 2 bytes off the stack.  The upper byte of the poped value is
*            discarded by the XA.
*         2) Two bytes are pushed on the stack for the SSEL register because the POPU.B SSEL instruction
*            (see OS_XA-AL.AS) actually pops 2 bytes off the stack.  The upper byte of the poped value is
*            discarded by the XA.
*********************************************************************************************************
*/

UBYTE OSTaskCreate(void (*task)(far void *pd), far void *pdata, far void *pstk, UBYTE p)
{
    far UWORD *stk;
        UBYTE  err;
        ULONG  temp;


    OS_ENTER_CRITICAL();
    if (OSTCBPrioTbl[p] == (far OS_TCB *)0) {         /* Task must not already exist at this priority  */
        OS_EXIT_CRITICAL();
        stk      = (far UWORD *)pstk;                 /* Load stack pointer                            */
        temp     = (ULONG)pdata;                      /* Simulate call to function with an argument    */
        *--stk   = (UWORD)(temp >> 16);               /* Push HIGH word first                          */
        *--stk   = (UWORD)(temp & 0xFFFFL);
        temp     = (ULONG)task;
        *--stk   = (UWORD)( temp & 0xFFFFL);          /* Simulate FCALL (Push LOW word first)          */
        *--stk   = (UWORD)((temp & 0x00FFL) >> 16);
        *--stk   = (UWORD)0x6666;                     /* R6   = 0x6666 ;Identify register for debug... */
        *--stk   = (UWORD)0x5555;                     /* R5   = 0x5555 ;... purposes.                  */
        *--stk   = (UWORD)0x4444;                     /* R4   = 0x4444                                 */
        *--stk   = (UWORD)0x3333;                     /* R3   = 0x3333                                 */
        *--stk   = (UWORD)0x2222;                     /* R2   = 0x2222                                 */
        *--stk   = (UWORD)0x1111;                     /* R1   = 0x1111                                 */
        *--stk   = (UWORD)0x0000;                     /* R0   = 0x0000                                 */
        *--stk   = (UWORD)0xEEEE;                     /* ES   = 0xEE   ;Identify ES register           */
        *--stk   = (UWORD)0x8080;                     /* SSEL = 0x80   ;Allow writes to ES register    */
        *--stk   = (UWORD)0x0000;                     /* PSW  = User Mode, Register bank #0, Ints. En. */
        *--stk   = (UWORD)((temp & 0x00FFL) >> 16);   /* Pointer to task in reverse order ...          */
        *--stk   = (UWORD)( temp & 0xFFFFL);          /* ... Push HIGH word first                      */
        err      = OSTCBInit(p, (far void *)stk);     /* Get and initialize a TCB                      */
        if (err == OS_NO_ERR) {
            if (OSRunning) {                          /* Find highest priority task if tasking         */
                OSSched();
            }
        }
        return (err);
    } else {
        OS_EXIT_CRITICAL();
        return (OS_PRIO_EXIST);
    }
}

⌨️ 快捷键说明

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