Beispiel #1
0
INT8U  OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
{
#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
    psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0);    /* Initialize the task's stack         */
    err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
    if (err == OS_NO_ERR) {
        OS_ENTER_CRITICAL();
        OSTaskCtr++;                                        /* Increment the #tasks counter        */
        OS_EXIT_CRITICAL();
        if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
            OS_Sched();
        }
    }
    return (err);
}
Beispiel #2
0
// 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 );
}
Beispiel #3
0
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();

        if (((opt & OS_TASK_OPT_STK_CHK) != 0x0000) ||   /* See if stack checking has been enabled     */
            ((opt & OS_TASK_OPT_STK_CLR) != 0x0000)) {   /* See if stack needs to be cleared           */
            #if OS_STK_GROWTH == 1
            (void)memset(pbos, 0, stk_size * sizeof(OS_STK));
            #else
            (void)memset(ptos, 0, stk_size * sizeof(OS_STK));
            #endif
        }

        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);
}
Beispiel #4
0
void OSInitTaskIdle(void)
{
	OS_ENTER_CRITICAL();
	OSTCBTbl[0].OSTCBStkPtr = OSTaskStkInit(OS_TaskIdle, (void *)0, (OS_STK*)&TASK_IDLE_STK[TASK_STACK_SIZE - 1]);
	//OSTCBTbl[0].OSTCBStat = TASK_STATE_RUNNING;
	OSTCBTbl[0].IsDaemon = ~TASK_DAEMON;
	OSTCBTbl[0].Priority = LOWEST_PRIORITY; 
	OSTCBTbl[0].TaskState = TASK_STATE_IDLE;
	OS_EXIT_CRITICAL();
}
Beispiel #5
0
void OSTaskCreate(void (*task)(void *p_arg), 
		  void *p_arg, 
		  OS_STK *p_tos)
{
	OS_STK * tmp;
	INT8U i = 1;
	OS_ENTER_CRITICAL();
	while(OSTCBTbl[i].OSTCBStkPtr != (OS_STK*)0) {
		i++;
	}
	tmp = OSTaskStkInit(task, p_arg, p_tos);
	OSTCBSet(&OSTCBTbl[i], tmp, ~TASK_DAEMON, LOWEST_PRIORITY, TASK_STATE_PAUSING);
		// OSTCBSet(&OSTCBTbl[i], tmp, ~TASK_DAEMON, 1, TASK_STATE_PAUSING);
	OS_EXIT_CRITICAL();
}
Beispiel #6
0
INT8U  OSTaskCreate (void (*task)(void *p_arg), void *p_arg, OS_STK *ptos, INT8U prio)
{
    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();
        psp = OSTaskStkInit(task, p_arg, ptos, 0);              /* Initialize the task's stack         */
        err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
        if (err == OS_ERR_NONE) {
            if (OSRunning == OS_TRUE) {      /* Find highest priority task if multitasking has started */
                OS_Sched();
            }
        } else {
            OS_ENTER_CRITICAL();
            OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
            OS_EXIT_CRITICAL();
        }
        return (err);
    }
    OS_EXIT_CRITICAL();
    return (OS_ERR_PRIO_EXIST);
}
Beispiel #7
0
INT8U  OSTaskCreate (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT8U prio)
{
#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();
        psp = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0);    /* Initialize the task's stack         */
        err = OS_TCBInit(prio, psp, (OS_STK *)0, 0, 0, (void *)0, 0);
        if (err == OS_NO_ERR) {
            OS_ENTER_CRITICAL();
            OSTaskCtr++;                                        /* Increment the #tasks counter        */
            OS_EXIT_CRITICAL();
            if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
                OS_Sched();
            }
        } else {
            OS_ENTER_CRITICAL();
            OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
            OS_EXIT_CRITICAL();
        }
        return (err);
    }
    OS_EXIT_CRITICAL();
    return (OS_PRIO_EXIST);
}
Beispiel #8
0
SMPOSHANDLE SmpOS_ThreadCreate(THREADPROC ThreadProc, VOID* pdata, SMPOS_STK* pStack, UINT8 prio)
{
	SMPOSHANDLE handle = NULL;
	SMPOSERR reterr = SMPOS_UNKNOWN;
	PSMPOS_THREAD pThread = NULL;
	pThread = SmpOS_CoreObtainThreadList();
	if(pThread)
	{
		SmpOS_ARMContextInit(ThreadProc, pdata, pStack, &pThread->SmpOStcb.ARMcontext);
		reterr = SmpOS_CoreAddToReadyList(pThread);
		SmpOS_SetLastError(reterr);
		if(SMPOS_SUCCESS == reterr)
		{
			handle = (SMPOSHANDLE)pThread;
		}
		else
		{
			handle = NULL;
		}
	}
	else
	{
		handle = NULL;
		SmpOS_SetLastError(SMPOS_CORE_NOOSTCBLIST);
	}
	
    return handle;
#if 0
    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();
        pSP = (OS_STK *)OSTaskStkInit(task, pdata, ptos, 0);    /* Initialize the task's stack         */
        err = OS_TCBInit(prio, pSP, (OS_STK *)0, 0, 0, (void *)0, 0);
        if (err == OS_NO_ERR) {
            OS_ENTER_CRITICAL();
            OSTaskCtr++;                                        /* Increment the #tasks counter        */
            OS_EXIT_CRITICAL();
            if (OSRunning == TRUE) {         /* Find highest priority task if multitasking has started */
                OS_Sched();
            }
        } else {
            OS_ENTER_CRITICAL();
            OSTCBPrioTbl[prio] = (OS_TCB *)0;/* Make this priority available to others                 */
            OS_EXIT_CRITICAL();
        }
        return (err);
    }
    OS_EXIT_CRITICAL();
#endif
}