// CODE_SECTION(OSTaskCreateExt,".UserProgramCode") INT8U OSTaskCreateExt( void ( *task )( void *p_arg ), void *p_arg, OS_STK *ptos, INT8U prio, INT16U id, OS_STK *pbos, INT32U stk_size, void *pext, INT16U opt ) { OS_STK *psp; INT8U err; #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr = 0; #endif #if OS_ARG_CHK_EN > 0 if ( prio > OS_LOWEST_PRIO ) /* Make sure priority is within allowable range */ { return ( OS_ERR_PRIO_INVALID ); } #endif OS_ENTER_CRITICAL(); if ( OSIntNesting > 0 ) /* Make sure we don't create the task from within an ISR */ { OS_EXIT_CRITICAL(); return ( OS_ERR_TASK_CREATE_ISR ); } if ( OSTCBPrioTbl[prio] == ( OS_TCB * )0 ) /* Make sure task doesn't already exist at this priority */ { OSTCBPrioTbl[prio] = OS_TCB_RESERVED;/* Reserve the priority to prevent others from doing ... */ /* ... the same thing until task is created. */ OS_EXIT_CRITICAL(); #if (OS_TASK_STAT_STK_CHK_EN > 0) OS_TaskStkClr( pbos, stk_size, opt ); /* Clear the task stack (if needed) */ #endif psp = OSTaskStkInit( task, p_arg, ptos, opt ); /* Initialize the task's stack */ err = OS_TCBInit( prio, psp, pbos, id, stk_size, pext, opt ); if ( err == OS_ERR_NONE ) { if ( OSRunning == OS_TRUE ) /* Find HPT if multitasking has started */ { OS_Sched(); } } else { OS_ENTER_CRITICAL(); OSTCBPrioTbl[prio] = ( OS_TCB * )0; /* Make this priority avail. to others */ OS_EXIT_CRITICAL(); } return ( err ); } OS_EXIT_CRITICAL(); return ( OS_ERR_PRIO_EXIST ); }
INT8U OSTaskCreateExt (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio, INT16U id, OS_STK *pbos, INT32U stk_size, void *pext, INT16U opt) { #if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */ OS_CPU_SR cpu_sr; #endif OS_STK *psp; INT8U err; #if OS_ARG_CHK_EN > 0 if (prio > OS_LOWEST_PRIO) { /* Make sure priority is within allowable range */ return (OS_PRIO_INVALID); } #endif OS_ENTER_CRITICAL(); if (OSTCBPrioTbl[prio] == (OS_TCB *)0) { /* Make sure task doesn't already exist at this priority */ OSTCBPrioTbl[prio] = (OS_TCB *)1; /* Reserve the priority to prevent others from doing ... */ /* ... the same thing until task is created. */ OS_EXIT_CRITICAL(); OS_TaskStkClr(pbos, stk_size, opt); /* Clear the task stack (if needed) */ psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, opt); /* Initialize the task's stack */ err = OS_TCBInit(prio, psp, pbos, id, stk_size, pext, opt); if (err == OS_NO_ERR) { OS_ENTER_CRITICAL(); OSTaskCtr++; /* Increment the #tasks counter */ OS_EXIT_CRITICAL(); if (OSRunning == TRUE) { /* Find HPT if multitasking has started */ OS_Sched(); } } else { OS_ENTER_CRITICAL(); OSTCBPrioTbl[prio] = (OS_TCB *)0; /* Make this priority avail. to others */ OS_EXIT_CRITICAL(); } return (err); } OS_EXIT_CRITICAL(); return (OS_PRIO_EXIST); }