亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? os-task-switch.c

?? ucos-ii-at90S-icc-avr
?? C
字號:
//os主要代碼
#define  OS_GLOBALS                           /* Declare GLOBAL variables                              */
#include "includes.h"

#define  OS_MASTER_FILE                       /* Prevent the following files from including includes.h */

void        OSInit(void)
{
  INT8U i;

  OSIntNesting=0;             /* Interrupt nesting level                              */
  OSLockNesting=0;            /* Multitasking lock nesting level                      */
  OSPrioCur=0xff;                /* Priority of current task                             */
  OSPrioHighRdy=0xff;            /* Priority of highest priority task                    */
  OSRunning = FALSE;

  OSTCBCur=0;                        /* Pointer to currently running TCB              */
  OSTCBHighRdy=0;                    /* Pointer to highest priority TCB ready to run  */
/*init task tcb pointers list*/
  for(i=0;i<OS_TASK_COUNT;i++)
    OSpTCBList[i]=(OS_TCB*)0;
}
/*
OS_STK *	OSTaskStkInit (void (*task)(void *pd),void *pdata, OS_STK *ptos);
INT8U       OSTCBInit(OS_TCB *ptcb,INT8U prio, OS_STK *ptos,INT16U stk_size);
*/

INT8U       OSTaskCreate(OS_TCB *ptcb,void (*task)(void *pd), void *pdata, OS_STK *ptos,INT16U stk_size, INT8U prio)
{
    void   *psp;
    INT8U   err;

    if (prio > OS_LOWEST_PRIO) {             /* Make sure priority is within allowable range           */
        return (OSERR_PRIO_INVALID);
    }
    OS_ENTER_CRITICAL();
    if (OSpTCBList[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority  */
        OSpTCBList[prio] = ptcb;    /* Reserve the priority to prevent others from doing ...  */
        OS_EXIT_CRITICAL();
        psp = (void *)OSTaskStkInit(task, pdata, ptos, stk_size); /* Initialize the task's stack              */
        err = OSTCBInit(ptcb,prio, psp,stk_size);         
        if (err == OS_NO_ERR) {
            if (OSRunning) {                 /* Find highest priority task if multitasking has started */
                OSSched();
            }
        } else {
        }
        return (err);
    } else {
        OS_EXIT_CRITICAL();
        return (OSERR_PRIO_EXIST);
    }
}

/*
*********************************************************************************************************
*                                            INITIALIZE TCB
*
* Description: This function is internal to uC/OS-II and is used to initialize a Task Control Block when
*              a task is created (see OSTaskCreate() and OSTaskCreateExt()).
*
* Arguments  : prio          is the priority of the task being created
*
*              ptos          is a pointer to the task's top-of-stack assuming that the CPU registers
*                            have been placed on the stack.  Note that the top-of-stack corresponds to a 
*                            'high' memory location is OS_STK_GROWTH is set to 1 and a 'low' memory
*                            location if OS_STK_GROWTH is set to 0.  Note that stack growth is CPU
*                            specific.
*
*              pbos          is a pointer to the bottom of stack.  A NULL pointer is passed if called by
*                            'OSTaskCreate()'.
*
*              id            is the task's ID (0..65535)
*
*              stk_size      is the size of the stack (in 'stack units').  If the stack units are INT8Us
*                            then, 'stk_size' contains the number of bytes for the stack.  If the stack
*                            units are INT32Us then, the stack contains '4 * stk_size' bytes.  The stack
*                            units are established by the #define constant OS_STK which is CPU
*                            specific.  'stk_size' is 0 if called by 'OSTaskCreate()'.
*
*              pext          is a pointer to a user supplied memory area that is used to extend the task
*                            control block.  This allows you to store the contents of floating-point
*                            registers, MMU registers or anything else you could find useful during a 
*                            context switch.  You can even assign a name to each task and store this name
*                            in this TCB extension.  A NULL pointer is passed if called by OSTaskCreate().
*
*              opt           options as passed to 'OSTaskCreateExt()' or, 
*                            0 if called from 'OSTaskCreate()'.
*
* Returns    : OS_NO_ERR         if the call was successful
*              OS_NO_MORE_TCB    if there are no more free TCBs to be allocated and thus, the task cannot
*                                be created.
*
* Note       : This function is INTERNAL to uC/OS-II and your application should not call it.
*********************************************************************************************************
*/

INT8U OSTCBInit (OS_TCB *ptcb,INT8U prio, OS_STK *ptos, INT16U stk_size)
{
#if OS_STRICT
  if((0==ptcb)||(prio>OS_LOWEST_PRIO)||((INT16U)ptos<OS_HARDWARE_STACK_SIZE+40)||(stk_size<OS_HARDWARE_STACK_SIZE+40))
    OSError(0);
#endif
    OS_ENTER_CRITICAL();
    if ((OS_TCB *)0!=ptcb) {
        OS_EXIT_CRITICAL();
        ptcb->OSTCBStkPtr    = ptos;                       /* Load Stack pointer in TCB                */
        ptcb->OSTCBPrio      = (INT8U)prio;                /* Load task priority into TCB              */
        ptcb->OSTCBStat      = OS_STAT_RDY;                /* Task is ready to run                     */
        ptcb->OSTCBDly       = 0;                          /* Task is not delayed                      */

        return (OS_NO_ERR);
    } else {
        OS_EXIT_CRITICAL();
        return (OSERR_TCB_INVALID);
    }
}

/*
*********************************************************************************************************
*                                              SCHEDULER
*
* Description: This function is called by other uC/OS-II services to determine whether a new, high
*              priority task has been made ready to run.  This function is invoked by TASK level code
*              and is not used to reschedule tasks from ISRs (see OSIntExit() for ISR rescheduling).
*
* Arguments  : none
*
* Returns    : none
*
* Notes      : 1) This function is INTERNAL to uC/OS-II and your application should not call it.
*              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
*********************************************************************************************************
*/

void OSSched (void)
{
    OS_ENTER_CRITICAL();
    if ((OSLockNesting | OSIntNesting) == 0) {   /* Task scheduling must be enabled and not ISR level  */
        OSPrioHighRdy=OSGetPrioRdy();
		if(OSPrioHighRdy>OS_LOWEST_PRIO)
		{
#if OS_STRICT
		  OSError(0);
#endif
		}else if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
            OSTCBHighRdy = OSpTCBList[OSPrioHighRdy];
#if OS_STRICT
		  	if(0==OSTCBHighRdy)
			  OSError(0);
#endif			
			OS_TASK_SW();                        /* Perform a context switch                           */
        }//end OSPrioHighRdy != OSPrioCur
    }//end nesting==0
    OS_EXIT_CRITICAL();
}

/*
*********************************************************************************************************
*                                          START MULTITASKING
*
* Description: This function is used to start the multitasking process which lets uC/OS-II manages the
*              task that you have created.  Before you can call OSStart(), you MUST have called OSInit()
*              and you MUST have created at least one task.
*
* Arguments  : none
*
* Returns    : none
*
* Note       : OSStartHighRdy() MUST:
*                 a) Call OSTaskSwHook() then,
*                 b) Set OSRunning to TRUE.
*********************************************************************************************************
*/

void OSStart (void)
{
    if (OSRunning == FALSE) {
        OSPrioHighRdy = 0;
        OSPrioCur     = 0;
        OSTCBHighRdy  = OSpTCBList[OSPrioHighRdy]; /* Point to highest priority task ready to run    */
        OSTCBCur      = OSTCBHighRdy;
#if OS_STRICT
		if(0==OSTCBCur) 
		  OSError(0);
#endif		
        OSStartHighRdy();                            /* Execute target specific code to start task     */
    }
#if OS_STRICT
	else OSError(0);
#endif
}

/*
*********************************************************************************************************
*                                DELAY TASK 'n' TICKS   (n from 0 to 65535)
*
* Description: This function is called to delay execution of the currently running task until the 
*              specified number of system ticks expires.  This, of course, directly equates to delaying
*              the current task for some time to expire.  No delay will result If the specified delay is 
*              0.  If the specified delay is greater than 0 then, a context switch will result.
*
* Arguments  : ticks     is the time delay that the task will be suspended in number of clock 'ticks'.  
*                        Note that by specifying 0, the task will not be delayed.
*
* Returns    : none
*********************************************************************************************************
*/

void OSTimeDly (INT16U ticks)
{
    if (ticks > 0) {                                                      /* 0 means no delay!         */
        OS_ENTER_CRITICAL();
        OSTCBCur->OSTCBDly = ticks;                                       /* Load ticks in TCB         */
        OS_EXIT_CRITICAL();
        OSSched();                                                        /* Find next task to run!    */
    }
}

INT8U OSGetPrioRdy(void)
{
  INT8U i,ret=0xff;
  OS_TCB *ptcb;
  for(i=0;i<OS_TASK_COUNT;i++)
  {
    ptcb=OSpTCBList[i];
    //OS_ENTER_CRITICAL();
    if(ptcb)
	  if((0==ptcb->OSTCBDly)&&
	     (OS_STAT_RDY==ptcb->OSTCBStat))
	  {
#if OS_STRICT
	    if(i!=ptcb->OSTCBPrio)
		  OSError(0);
#endif  
        ret=ptcb->OSTCBPrio;     
#if OS_STRICT
		if(ret>OS_LOWEST_PRIO)
		  OSError(0);
#endif  		
	    break;//for
	  }
    //OS_EXIT_CRITICAL();
  }
  return ret;
}

/*
*********************************************************************************************************
*                                         PROCESS SYSTEM TICK
*
* Description: This function is used to signal to uC/OS-II the occurrence of a 'system tick' (also known
*              as a 'clock tick').  This function should be called by the ticker ISR but, can also be
*              called by a high priority task.
*
* Arguments  : none
*
* Returns    : none
*********************************************************************************************************
*/

void OSTimeTick (void)
{
    INT8U i,ret;
    OS_TCB *ptcb;
	//skip last task,last task must be idle task
	for(i=0;i<OS_TASK_COUNT-1;i++)
	{
	ptcb=OSpTCBList[i];
//    OS_ENTER_CRITICAL();
    //check ptcb != 0
	if(ptcb){              /* Go through all TCBs in TCB list          */
        if (ptcb->OSTCBDly != 0) {                         /* Delayed or waiting for event with TO     */
            if (--ptcb->OSTCBDly == 0) {                   /* Decrement nbr of ticks to end of delay   */
//                if (!(ptcb->OSTCBStat & OS_STAT_SUSPEND)) {    /* Is task suspended?                   */
//                    OSRdyGrp               |= ptcb->OSTCBBitY; /* No,  Make task Rdy to Run (timed out)*/
//                    OSRdyTbl[ptcb->OSTCBY] |= ptcb->OSTCBBitX;
                } else {                                       /* Yes, Leave 1 tick to prevent ...     */
                    ptcb->OSTCBDly = 1;                        /* ... loosing the task when the ...    */
                }                                              /* ... suspension is removed.           */
            }//end OSTCBDly!=0
        }//end if(ptcb)
  //  OS_EXIT_CRITICAL();
    }//end for
}

/*
*********************************************************************************************************
*                                               EXIT ISR
*
* Description: This function is used to notify uC/OS-II that you have completed serviving an ISR.  When 
*              the last nested ISR has completed, uC/OS-II will call the scheduler to determine whether
*              a new, high-priority task, is ready to run.
*
* Arguments  : none
*
* Returns    : none
*
* Notes      : 1) You MUST invoke OSIntEnter() and OSIntExit() in pair.  In other words, for every call
*                 to OSIntEnter() at the beginning of the ISR you MUST have a call to OSIntExit() at the
*                 end of the ISR.
*              2) Rescheduling is prevented when the scheduler is locked (see OSSchedLock())
*********************************************************************************************************
*/

void OSIntExit(void)
{
    OS_ENTER_CRITICAL();
    if ((--OSIntNesting | OSLockNesting) == 0) { /* Reschedule only if all ISRs completed & not locked */
        OSPrioHighRdy=OSGetPrioRdy();
		if(OSPrioHighRdy>OS_LOWEST_PRIO)
		{
#if OS_STRICT
		  OSError(0);
#endif
		}else if (OSPrioHighRdy != OSPrioCur) {         /* No context switch if current task is highest ready */
            OSTCBHighRdy = OSpTCBList[OSPrioHighRdy];
#if OS_STRICT
		  	if((0==OSTCBHighRdy)||(0==OSTCBCur)||
			   (OSPrioCur>OS_LOWEST_PRIO)||(OSPrioHighRdy>OS_LOWEST_PRIO))
			  OSError(0);
#endif			
            OSDebug();
            OSIntCtxSw();                        /* Perform interrupt level context switch             */
        }//end OSPrioHighRdy != OSPrioCur
    }//end nesting==0
    OS_EXIT_CRITICAL();
}

void OSDebug(void)
{
INT8U port_a;
            //debug
			DDRA=0;port_a=PORTA;
			DDRA=0xff;PORTA=~port_a;
			//end debug
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩一级欧美一级| 97成人超碰视| 精品国产乱码久久久久久牛牛 | 亚洲综合免费观看高清在线观看 | zzijzzij亚洲日本少妇熟睡| 国产午夜精品理论片a级大结局| 国产成人精品免费视频网站| 国产精品无码永久免费888| 成人激情小说网站| 一区二区三区在线免费视频| 欧美日韩mp4| 国产自产高清不卡| 一区免费观看视频| 欧美精品一卡二卡| 国产专区欧美精品| 亚洲欧美另类图片小说| 911精品国产一区二区在线| 久国产精品韩国三级视频| 国产免费久久精品| 91激情在线视频| 久久国产精品99久久久久久老狼| 久久久久国产精品麻豆ai换脸| 99精品国产热久久91蜜凸| 日本三级韩国三级欧美三级| 久久久久国产精品麻豆ai换脸| 色香色香欲天天天影视综合网| 人人爽香蕉精品| 国产午夜亚洲精品理论片色戒| 色999日韩国产欧美一区二区| 另类小说色综合网站| 中文字幕一区二区三区四区| 制服视频三区第一页精品| 国产美女视频一区| 婷婷综合另类小说色区| 中文字幕乱码亚洲精品一区| 欧美日韩在线播放| 不卡一区在线观看| 久国产精品韩国三级视频| 亚洲一区二区美女| 欧美韩国日本不卡| 欧美一级生活片| 在线亚洲欧美专区二区| 国产91综合网| 免费观看一级特黄欧美大片| 亚洲狠狠丁香婷婷综合久久久| 国产亚洲人成网站| 日韩欧美精品在线| 欧美日韩激情一区二区三区| 成人激情文学综合网| 国产自产2019最新不卡| 水蜜桃久久夜色精品一区的特点| 国产精品成人在线观看| 欧美精品一区二区三区很污很色的 | 久久精工是国产品牌吗| 亚洲午夜激情网页| 中文字幕中文乱码欧美一区二区| 久久久噜噜噜久久人人看| 在线成人小视频| 色婷婷精品久久二区二区蜜臀av| 懂色av中文字幕一区二区三区| 六月丁香婷婷色狠狠久久| 水野朝阳av一区二区三区| 亚洲一卡二卡三卡四卡| 亚洲精品视频一区二区| 中文字幕日韩精品一区 | 亚洲免费资源在线播放| 欧美国产日韩亚洲一区| 久久久亚洲综合| 亚洲精品一区二区三区99| 欧美变态tickle挠乳网站| 337p亚洲精品色噜噜| 欧美人与z0zoxxxx视频| 在线观看国产一区二区| 色狠狠一区二区三区香蕉| 99精品偷自拍| 色综合视频一区二区三区高清| 99久久精品一区| 91年精品国产| 欧美午夜影院一区| 欧美在线高清视频| 69久久99精品久久久久婷婷| 666欧美在线视频| 日韩一级免费观看| 精品国产91亚洲一区二区三区婷婷 | av中文字幕在线不卡| www.av精品| 91极品视觉盛宴| 91精品国产综合久久精品app| 538prom精品视频线放| 日韩丝袜美女视频| 久久夜色精品一区| 国产精品水嫩水嫩| 亚洲美腿欧美偷拍| 污片在线观看一区二区| 精品一区二区三区视频| 不卡大黄网站免费看| 色哟哟一区二区| 在线不卡中文字幕播放| 欧美va在线播放| 中文字幕精品在线不卡| 亚洲激情网站免费观看| 日韩精品电影一区亚洲| 国模少妇一区二区三区| 91蜜桃在线免费视频| 欧美裸体bbwbbwbbw| 久久综合久久综合亚洲| 国产精品大尺度| 午夜精品久久久久久久蜜桃app| 久久精品久久综合| av中文字幕亚洲| 制服.丝袜.亚洲.另类.中文| 国产欧美日本一区视频| 亚洲国产精品一区二区久久 | 亚洲成人av电影| 国产一区久久久| 色综合色狠狠天天综合色| 欧美欧美午夜aⅴ在线观看| 国产欧美视频一区二区| 亚洲午夜精品一区二区三区他趣| 国产乱码精品一区二区三区忘忧草| 波多野结衣91| 日韩欧美国产一区二区三区| 国产精品久久久久久久久快鸭 | 亚洲精品高清在线| 韩国av一区二区三区四区| 91啪九色porn原创视频在线观看| 欧美成人精品高清在线播放| 18成人在线观看| 六月婷婷色综合| 欧美四级电影在线观看| 欧美激情资源网| 秋霞影院一区二区| 色综合久久88色综合天天6| 久久蜜桃一区二区| 日韩精品欧美成人高清一区二区| av资源站一区| 国产欧美日韩视频一区二区| 秋霞午夜av一区二区三区| 欧美性三三影院| 中文字幕一区二区不卡| 韩国在线一区二区| 欧美精品久久久久久久多人混战| 中文字幕中文字幕一区| 国产乱妇无码大片在线观看| 日韩免费福利电影在线观看| 午夜精品久久久久久久久久久 | 欧美日韩免费一区二区三区 | 国产精品久久久久7777按摩| 免费在线观看一区二区三区| 欧美日韩亚洲综合| 一二三区精品福利视频| 99久久精品久久久久久清纯| 欧美国产日韩亚洲一区| 国产成人精品一区二区三区网站观看| 日韩一级精品视频在线观看| 五月婷婷激情综合网| 欧美丝袜丝交足nylons图片| 亚洲三级久久久| 99精品视频在线免费观看| 欧美国产成人在线| 国产成人在线视频网站| 欧美videos中文字幕| 激情国产一区二区| 欧美成人r级一区二区三区| 六月丁香婷婷色狠狠久久| 日韩一级大片在线观看| 久久成人麻豆午夜电影| 精品区一区二区| 国产一区欧美二区| 久久精品免费在线观看| 国产成人一区在线| 国产精品乱码一区二三区小蝌蚪| 国产91富婆露脸刺激对白| 中文字幕的久久| 91香蕉视频在线| 亚洲国产视频a| 欧美一区在线视频| 九一九一国产精品| 久久久久久电影| 99久久99久久免费精品蜜臀| 亚洲精品高清视频在线观看| 精品视频色一区| 久久精品国产99| 中文一区一区三区高中清不卡| 99久久伊人久久99| 亚洲电影第三页| 欧美电影免费观看完整版| 国产精品1区2区| 中文字幕一区日韩精品欧美| 欧美在线免费播放| 久久er精品视频| 中文字幕一区二区三区蜜月 | 国产欧美日本一区视频| 91在线一区二区| 日韩精品电影在线观看| 久久综合九色综合97_久久久| www.在线成人| 日韩黄色免费电影| 中文字幕免费不卡在线| 欧美三级电影在线看|