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

📄 196.c

📁 ucos 在 Intel 196 单片机上的移植
💻 C
字号:
/*===========================================================================*/
/*                1 9 6 . C                                                  */
/*===========================================================================*/
/* Changed < 196.c >  5-19-1994   9:44 AM   T/R Systems Confidential         */
/*===========================================================================*/
/*                                uCOS                                       */
/*          Microcomputer Real-Time Multitasking Operating System            */
/*                                                                           */
/*                         80196 Specific code                               */
/*===========================================================================*/
/*---------------------------------------------------------------------------*/
/*--------------> I N C L U D E S <------------------------------------------*/
/*---------------------------------------------------------------------------*/
#include    "common.H"
#include    "196.H"
#include    "UCOS.H"
#include    "iomap.h" 
#include    "fp.h" /* temp */

/*---------------------------------------------------------------------------*/
/*--------------> F U N C T I O N S <----------------------------------------*/
/*---------------------------------------------------------------------------*/
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*                             --------------                                */
/*                            | OSTaskCreate |                               */
/*                             --------------                                */
/* This function creates and initializes new tasks.                          */
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
BYTE OSTaskCreate(void ( *task)(void *pd), void *pdata,void *pstk,BYTE p)
{
WORD *stk;
BYTE  err;

    OS_ENTER_CRITICAL();
    if (OSTCBPrioTbl[p] == (OS_TCB *)0)
    {               /* Make sure task doesn't already exist at this priority */
        OS_EXIT_CRITICAL();
        stk = (WORD *)pstk;                            /* Load stack pointer */
/*        *--stk = (WORD)pdata;*/     /* Simulate call to function with argument */
        *--stk = (WORD)task;          /* Put pointer to task on top of stack */
        *--stk = (WORD)0x0000;                      /* PSW/IMASK = 0 (PUSHA) */
        *--stk = (WORD)0x0000;                     /* IMASK1/WSR = 0 (PUSHA) */
        *--stk = (WORD)0x0000;                               /* PLMREG+0 = 0 */
        *--stk = (WORD)0x0000;                               /* PLMREG+2 = 0 */
        *--stk = (WORD)0x0000;                               /* PLMREG+4 = 0 */
        *--stk = (WORD)0x0000;                               /* PLMREG+6 = 0 */
        *--stk = (WORD)0x0000;                               /* ?FRAME01 = 0 */
        err = OSTCBInit(p, (void  *)stk);        /* Get and initialize a TCB */
        if (err == OS_NO_ERR)
        {
            if (OSRunning)
            {      /* Find highest priority task if multitasking has started */
                OSSched();
            }
        }
        return (err);
    } else
    {
        OS_EXIT_CRITICAL();
        return (OS_PRIO_EXIST);
    }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*                             ----------------                              */
/*                            | OSStartHighRdy |                             */
/*                             ----------------                              */
/* This function starts the highest priority task for the uCos system.       */
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
void OSStartHighRdy(void)
{
static void register *temp_SP;

   OSTCBCur = OSTCBHighRdy;

/*   SP = OSTCBHighRdy->OSTCBStkPtr;*/
   temp_SP = OSTCBHighRdy->OSTCBStkPtr;
   asm ld 0x18,temp_SP;

   asm                                                  /* restore registers */
   {  
      pop 0x1A;                                                  /* ?FRAME01 */
      pop 0x22;                                                      /* TMP6 */
      pop 0x20;                                                      /* TMP4 */
      pop 0x1E;                                                      /* TMP2 */
      pop 0x1C;                                             /* PLMREG - TMP0 */
      stb gimask1,1[0x18];   /* Restore int mask to global mask before popa. */
      stb gint_mask,2[0x18];
      popa;
   }
}
   
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*                             ---------                                     */
/*                            | OSCtxSw |                                    */
/*                             ---------                                     */
/* This function performs a context switch from the task level for the uCos  */
/* system.                                                                   */
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
void OSCtxSw(void)
{
static void register *temp_SP;

   asm                                                     /* save registers */
   {
      pusha; 
      push 0x1C;                                                     /* TMP0 */
      push 0x1E;                                                     /* TMP2 */
      push 0x20;                                                     /* TMP4 */
      push 0x22;                                                     /* TMP6 */
      push 0x1A;                                                 /* ?FRAME01 */
   }

/*   OSTCBCur->OSTCBStkPtr = SP;*/
   asm ld temp_SP,0x18;
   OSTCBCur->OSTCBStkPtr = temp_SP;

   OSTCBCur = OSTCBHighRdy;

/*   SP = OSTCBHighRdy->OSTCBStkPtr;*/
   temp_SP = OSTCBHighRdy->OSTCBStkPtr;
   asm ld 0x18,temp_SP;

   asm                                                  /* restore registers */
   {  
      pop 0x1A;                                                  /* ?FRAME01 */
      pop 0x22;                                                      /* TMP6 */
      pop 0x20;                                                      /* TMP4 */
      pop 0x1E;                                                      /* TMP2 */
      pop 0x1C;                                             /* PLMREG - TMP0 */
      stb gimask1,1[0x18];   /* Restore int mask to global mask before popa. */
      stb gint_mask,2[0x18];
      popa;
   }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*                             ------------                                  */
/*                            | OSIntCtxSw |                                 */
/*                             ------------                                  */
/* This function performs a context switch from the Interrupt level for the  */
/* uCos system.                                                              */
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
void OSIntCtxSw(void)
{
static void register *temp_SP;

   asm add 0x18,#4;              /* Ignore calls to OSIntExit and OSIntCtxSw */
   asm push 0x1A;                                                 /* ?FRAME01 */

/*   OSTCBCur->OSTCBStkPtr = SP;*/
   asm ld temp_SP,0x18;
   OSTCBCur->OSTCBStkPtr = temp_SP;

   OSTCBCur = OSTCBHighRdy;

/*   SP = OSTCBHighRdy->OSTCBStkPtr;*/
   temp_SP = OSTCBHighRdy->OSTCBStkPtr;
   asm ld 0x18,temp_SP;

   asm                                                  /* restore registers */
   {  
      pop 0x1A;                                                  /* ?FRAME01 */
      pop 0x22;                                                      /* TMP6 */
      pop 0x20;                                                      /* TMP4 */
      pop 0x1E;                                                      /* TMP2 */
      pop 0x1C;                                             /* PLMREG - TMP0 */
      stb gimask1,1[0x18];   /* Restore int mask to global mask before popa. */
      stb gint_mask,2[0x18];
      popa;
   }
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
/*                             -----------                                   */
/*                            | OSReplace |                                  */
/*                             -----------                                   */
/* This function replaces the current task with the task passed. This is     */
/* used for state machines to reduce the RAM requirements for the stack and  */
/* it is also eliminates the following problem : task X and Y are 2 states   */
/* of a state machine, task X starts task Y and task Y starts task X,        */
/* task Y's priority is higher than X's, when task X starts Y, task Y gets   */
/* control and trys to restart X before X has deleted its self.              */
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
void OSReplace(void ( *task)(void *pd), void *pstk )
{
static void register *temp_SP;

   OS_ENTER_CRITICAL();

   OSTCBCur->OSTCBStkPtr = --(WORD *)pstk;         /* Load Stack pointer for
                                                          return addr in TCB */
   temp_SP = OSTCBCur->OSTCBStkPtr;
   asm ld 0x18,temp_SP;                             /* adjust stack location */

   temp_SP = task;             /* store return address in temp stack pointer */
   asm
   {
      st temp_SP,[0x18];      /* store starting address of new task on stack */
      ei;                                             /* OS_EXIT_CRITICAL(); */
      ret;                                    /* routine returns to new task */
   }
}

⌨️ 快捷键说明

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