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

📄 emos_core.c

📁 emos是一个新的类似于ucos的内核
💻 C
📖 第 1 页 / 共 4 页
字号:
                   {    
                   	/* Is task suspended? */
                       gEmosRdyGrp               |= ptcb->osTCBBitY; /* No suspended,  Make task Rdy to Run (timed out)*/
                       gEmosRdyTbl[ptcb->osTCBY] |= ptcb->osTCBBitX;
                   } 
                   else 
                   {   
                   	/* Yes, Leave 1 tick to prevent , for suspend   */
                       ptcb->osTCBDly = 1;   /* loosing the task when the, */
                   } 
               }
        	}

        	/*check wait forever ending and display the debug message of WIAT FOREVER Delay*/
            #ifdef EMOS_DEBUG_EN_        	
        	else
        	{
              EMOS_Print("EMOS Wait ForEver Happening TCB=%p pri=%d\r\n",ptcb,(int)ptcb->osTCBPrio); 
        	}
        	#endif
        	
        }
        
        ptcb = ptcb->osTCBNext;  /* Point at next TCB in TCB list */
        EMOS_EXIT_CRITICAL();
    }
    
    EMOS_ENTER_CRITICAL(); /* Update the 32-bit tick counter */
    gEmosTime++;
    EMOS_EXIT_CRITICAL();

}

void emosTimeDly (uint16 ticks)
{
    if (ticks > 0) 
    {  
    	/* 0 means no delay! */
        EMOS_ENTER_CRITICAL();
        if ((gEmosRdyTbl[gEmosTCBCur->osTCBY] &= ~gEmosTCBCur->osTCBBitX) == 0) 
        {  
        	/* Delay current task */
            gEmosRdyGrp &= ~gEmosTCBCur->osTCBBitY;
        }
        
        gEmosTCBCur->osTCBDly = ticks;  /* Load ticks in TCB*/
        EMOS_EXIT_CRITICAL();
        emosSched();                    /* Find next task to run!*/
    }
}

/*********************************************************************************************************
* DELAY TASK FOR SPECIFIED TIME
* Description: This function is called to delay execution of the currently running task until some time
*              expires.  This call allows you to specify the delay time in HOURS, MINUTES, SECONDS and
*              MILLISECONDS instead of ticks.
* Arguments  : hours     specifies the number of hours that the task will be delayed (max. is 255)
*              minutes   specifies the number of minutes (max. 59)    
*              seconds   specifies the number of seconds (max. 59)
*              milli     specifies the number of milliseconds (max. 999)
* Returns    : EMOS_NO_ERR
*              EMOS_TIME_INVALID_MINUTES
*              EMOS_TIME_INVALID_SECONDS
*              EMOS_TIME_INVALID_MS
*              EMOS_TIME_ZERO_DLY
* Note(s)    : The resolution on the milliseconds depends on the tick rate.  For example, you can't do
*              a 10 mS delay if the ticker interrupts every 100 mS.  In this case, the delay would be
*              set to 0.  The actual delay is rounded to the nearest tick.
**********************************************************************************************************/
uint8 emosTimeDlyHMSM (uint8 hours, uint8 minutes, uint8 seconds, uint16 milli)
{
    uint32 ticks;
    uint16 loops;

    if (hours > 0 || minutes > 0 || seconds > 0 || milli > 0) 
    {
        if (minutes > 59) 
        {
            return (EMOS_TIME_INVALID_MINUTES);    /* Validate arguments to be within range*/
        }
        
        if (seconds > 59) 
        {
            return (EMOS_TIME_INVALID_SECONDS);
        }
        
        if (milli > 999) 
        {
            return (EMOS_TIME_INVALID_MILLI);
        }

        /* Compute the total number of clock ticks required.. */
        /* .. (rounded to the nearest tick)*/
        ticks = ((uint32)hours * 3600L + (uint32)minutes * 60L + (uint32)seconds) * EMOS_TICKS_PER_SEC
              + EMOS_TICKS_PER_SEC * ((uint32)milli + 500L / EMOS_TICKS_PER_SEC) / 1000L;
        loops = ticks / 65536L; /* Compute the integral number of 65536 tick delays   */
        ticks = ticks % 65536L;/* Obtain  the fractional number of ticks             */
        emosTimeDly(ticks);
        while (loops > 0) 
        {
            emosTimeDly(32768);
            emosTimeDly(32768);
            loops--;
        }
        return (EMOS_NO_ERR);
        
    }

    else 
    {
        return (EMOS_TIME_ZERO_DLY);
    }
}

/*********************************************************************************************************
* RESUME A DELAYED TASK
* Description: This function is used resume a task that has been delayed through a call to either
*              OSTimeDly() or OSTimeDlyHMSM().  Note that you MUST NOT call this function to resume a 
*              task that is waiting for an event with timeout.  This situation would make the task look 
*              like a timeout occurred (unless you desire this effect).  Also, you cannot resume a task 
*              that has called OSTimeDlyHMSM() with a combined time that exceeds 65535 clock ticks.  In 
*              other words, if the clock tick runs at 100 Hz then, you will not be able to resume a 
*              delayed task that called OSTimeDlyHMSM(0, 10, 55, 350) or higher.  
*                  (10 Minutes * 60 + 55 Seconds + 0.35) * 100 ticks/second.
* Arguments  : prio      specifies the priority of the task to resume
* Returns    : EMOS_NO_ERR                 Task has been resumed
*              EMOS_PRIO_INVALID           if the priority you specify is higher that the maximum allowed 
*                                        (i.e. >= EMOS_LOWEST_PRIO)
*              EMOS_TIME_NOT_DLY           Task is not waiting for time to expire
*              EMOS_TASK_NOT_EXIST         The desired task has not been created
**********************************************************************************************************/
uint8 emosTimeDlyResume (uint8 prio)
{
    EMOS_TCB_T* ptcb = NULL;

    if (prio >= EMOS_LOWEST_PRIO) 
    {
        return (EMOS_PRIO_INVALID);
    }
    
    EMOS_ENTER_CRITICAL();
    ptcb = (EMOS_TCB_T *)gEmosTCBPrioTbl[prio];/* Make sure that task exist*/
    if (ptcb != (EMOS_TCB_T *)0) 
    {
        if (ptcb->osTCBDly != 0) 
        {  
        	/* See if task is delayed*/
            ptcb->osTCBDly  = 0;  /* Clear the time delay */
            if (!(ptcb->osTCBStat & EMOS_STAT_SUSPEND)) 
            {    /* See if task is ready to run */
                gEmosRdyGrp               |= ptcb->osTCBBitY; /* Make task ready to run */
                gEmosRdyTbl[ptcb->osTCBY] |= ptcb->osTCBBitX;
                EMOS_EXIT_CRITICAL();
                emosSched();  /* See if this is new highest priority */
            } 
            else
            {
                EMOS_EXIT_CRITICAL();  /* Task may be suspended */
            }
            
            return (EMOS_NO_ERR);   
        } 
        else 
        {
            EMOS_EXIT_CRITICAL();
            return (EMOS_TIME_NOT_DLY); /* Indicate that task was not delayed*/
        }
    } 
    else 
    {
        EMOS_EXIT_CRITICAL();
        return (EMOS_TASK_NOT_EXIST);                        /* The task does not exist                  */
    }
}

/*GET CURRENT SYSTEM TIME*/
uint32 emosTimeGet (void)
{
    uint32 ticks;

    EMOS_ENTER_CRITICAL();
    ticks = gEmosTime;
    EMOS_EXIT_CRITICAL();
    return (ticks);
}

/*SET SYSTEM CLOCK*/
void emosTimeSet (uint32 ticks)
{
    EMOS_ENTER_CRITICAL();
    gEmosTime = ticks;
    EMOS_EXIT_CRITICAL();
}

uint16 emosVersion()
{
    return (EMOS_VERSION);
}

char* emosVersionString()
{
    return (EMOS_VER_STRING);
}

void emosDbgShow()
{
  int i = 0;
  EMOS_TCB_T* p = NULL;
  
  printf("\r\n--------------- EMOS Debug Information by zenf_zhao Jan2008--------------\r\n");
  printf("TCBCur  TCBHRdy  PriCur PriHRdy  gTCBList RdyGrp taskIdle taskStat timeTick\r\n");
  printf("%08x ",(int)gEmosPrioCur);
  printf("%08x ",(int)gEmosTCBHighRdy);
  printf("%06d ",gEmosPrioCur);
  printf("%07d ",gEmosPrioHighRdy);
  printf("%08x ",(int)gEmosTCBList );
  printf("%06x ",gEmosRdyGrp);
  printf("%08x ",(int)emosTaskIdle);
  #if EMOS_TASK_STAT_EN
  printf("%08x ",(int)emosTaskStat);
  #else
  printf("%08x ",(int)0);
  #endif
  printf("%08d ",(int)gEmosTime);
  printf("\r\n");
  	
  printf("RDY TBL All:\r\n");
  for(i=0; i< EMOS_RDY_TBL_SIZE; i++)
  {
    printf("Rdy[%d]=%02x ",i, gEmosRdyTbl[i]);
  }
  printf("\r\n");

  printf("TcbPrioTbl TBL All:\r\n");
  for(i=0; i<= EMOS_LOWEST_PRIO; i++)
  {
    printf("%08x ",(int)gEmosTCBPrioTbl[i]);
    if(i%8==7) printf("\r\n");
  }
  printf("\r\n");
  
  printf("Tcb_Addr Tcb_next Tcb_prev stk_Ptr  Sta Dly Pri tX tY bX bY\r\n");
  for(i=0; i<= EMOS_LOWEST_PRIO; i++)
  { 
  	p = gEmosTCBPrioTbl[i];
  	if(NULL != p)
    {
    	printf("%08x ",(int)p);
        printf("%08x ",(int)p->osTCBNext);
    	printf("%08x ",(int)p->osTCBPrev);
        printf("%08x ",(int)p->osTCBStkPtr);
    	printf("%03x ",(int)p->osTCBStat);
    	printf("%03d ",(int)p->osTCBDly);
    	printf("%03d ",(int)p->osTCBPrio);
    	printf("%02d ",(int)p->osTCBX);
    	printf("%02d ",(int)p->osTCBY);
    	printf("%02x ",(int)p->osTCBBitX);
    	printf("%02x ",(int)p->osTCBBitY);
    	printf("\r\n");
    }
  }
  /*printf("\r\n");*/ 

  //printf("\r\n");
  printf("--------------- Debug Information end --------------\r\n");
  printf("\r\n");
  //getch();
  return ;
}

/**************************end of emos core function******************************************/


/*
void        emosCtxSw(void) {;}
void        emosIntCtxSw(void){;}
void        emosStartHighRdy(void){;}
void        emosTickISR(void){;}
void         emosTimeDly(uint16 ticks){;}
void         emosTimeSet(uint32 ticks){;}
uint8        emosTimeDlyHMSM(uint8 hours, uint8 minutes, uint8 seconds, uint16 milli) ;

uint8        emosTimeDlyResume(uint8 prio){return 0;}
uint32       emosTimeGet(void){return 0;}
*/

/*implement in the user files/core.c*/
/*
void        emosTaskCreateHook(EMOS_TCB_T *ptcb){;}
void        emosTaskDelHook(EMOS_TCB_T *ptcb){;}
void        emosTaskStatHook(void){;}
void        emosTaskSwHook(void){;}
void        emosTimeTickHook(void){;}
void*       emosTaskStkInit(void (*task)(void *pd), void *pdata, void *ptos, uint16 opt)  { return NULL;}
*/

/*
EMOS is a real-time embedded operating system core;

It bases on the ucOS/II concept and based on the ucOS/II 2.5 source code attached on the ucOS/II book floppy disk; EMOS will modified 50% of ucOS/II code and add some new functionalities like the VxWorks like MSGQ operation; EMOS present version will runing on the MinGW for simulation; EMOS provides the debug testcase of the core besides providing some examples;

The real-time kernel can be ported to any other CPU as ucOS/II;
also use the UltraEdit or SourceInsight with courier type character to read the code.
*/

 /*
 * Please add "$" around "Id" and "Log".
 * $Id$
 * $Log$
 */

 

⌨️ 快捷键说明

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