μC/OSのOSTaskCreate()


    OSTaskCreate()
1.OSTaskCreate()     
    INT8U OSTaskCreate(void(*task)(void*pd),void*pdata,OS_STK *ptos,INT8U prio)
     1.1     INT8U
     1.2  :4   ,               task,         pdata,               ptos,        prio
2.OSTaskCreate()     
     INT8U OSTaskCreate(void(*task)(void*pd),void*pdata,OS_STK *ptos,INT8U prio)
     {
         void *psp;                             /*                 */
         INT8U err;                             /*      TCB        */
 
         if(prio>OS_LOWEST_PRIO)                /*                 ,                   */
         {                                       /*    ,      */
             return (OS_PRIO_INVALID)            /*        */
         }
         OS_ENTER_CRITICAL();
         if (OSTCBPrioTbl[prio]==(OS_TCB *)0)   /*                    ,(OS_TCB)*0       */
         {
             OSTCBPrioTbl[prio]=(OS_TCB *)1;    /*         OSTCBPrioTbl[]          (OS_TCB)*1,  :
             OS_EXIT_CRITICAL();                /* (OS_TCB)*1          ,               */
             psp=(void *)OSTaskStkInit(task,pdata,ptos,0);/*          ,             psp*/  
                                                          /*               :①     ②     ③     */
             err=OSTCBInit(prio,psp,(void *)0,0,0,(void*0),0);/*TCB    ,       :①             ②           */
             if(err==OS_NO_ERR)                              /*  TCB     */
             {
                OS_ENTER_CRITICAL();
                OSTaskCtr++;                                 /*          1*/
                OSTaskCreateHook(OSTCBPrioTbl[prio]);        /*         ,         ,        ,        */
                OS_EXIT_CRITICAL();
                if(OSRunning)                               /*       ,             ,       OSStart() */
                   {
                      OSSched();                           /*              ,        OSSched()      */
                   }
              }
              else
              {
                 OS_ENTER_CRITICAL();
                 OSTCBPrioTble[prio]=(OS_TCB *)0;          /*  TCB     ,       OSTCBPrioTble[]                */
                 OS_EXIT_CRITICAL();
              }
              return (err);                                /*                 ,  TCB          ,    TCB     */
           }
           else
           {
               OS_EXIT_CRITICAL();
               return (OS_PRIO_EXIST);                    /*           ,   OS_PRIO_EXIST,               */
            }
      }
    
    
3.  
       OSTaskCreate()         ?    
①        ;
②   OSTCBPrioTbl[];
③        ;
④  TCB    。    

    :   ,            ,         ,          ;
             ,               ,          ,            ;
             , OSTCBPrioTbl[]    1,          ;
             ,        ;
             ,  TCB    ,           ,  TCB          OSTaskCreate();
             ,  TCB      ,  OSTCBPrioTbl[]       0,           ;  TCB      
                            1,      ;
             ,              ,               。

  :1.OSTaskCreate()           :
      ①task,pdata ptos           ,          ,    ,             
      ②prio   PCB    。
      2.  OSTCBPrioTbl[]   ,         TCB   ,     (OS_TCB *)0                ,
          (OS_TCB *)0 ,             ,             :
      ①(OS_TCB *)1 ,                       TCB;
      ②                TCB,    TCB        。