Beispiel #1
0
/*
*********************************************************************************************************
*                                    KILL A TASK ITSELF WHEN IT'S COMPLETE
*
* Note(s)    : 1) Used in OSTaskStkInit.
*********************************************************************************************************
*/
void OSTaskEndSelf(void) {
	INT8U err;
	INT8U tsk_name[0x24];

	OSTaskNameGet(OSPrioCur, tsk_name, &err);
	if (OS_ERR_NONE == err) {
		printf("\r\ntask %s (pid %d) over!", tsk_name, OSPrioCur);	
	}
	while (1) {
		if (OS_ERR_NONE != OSTaskDel(OSPrioCur)) {
			printf("\r\nOSTaskDel(%d) error!", OSPrioCur);
		}
		OSTimeDlyHMSM(0, 0, 0, 500);
	}
	// return;
}
Beispiel #2
0
void start_task(void *pdata)
{	
	INT8U err;//错误码
	INT8U *pname;
	INT8U len;//名字的长度
	char buffer[16];

	OS_CPU_SR cpu_sr = 0;
	pdata = pdata;

	delay_init(168);

	OS_ENTER_CRITICLE();	//进入临界区 无法被中断打断
	OSTaskCreate(	led0Task, 
			(void *)0, 
			(OS_STK *)LED0_TASK_STK[LED0_STK_SIZE-1],
			LED0_TASK_PRIO);//创建LED任务
	// OSTaskCreate(	beepTask, (void *)0, 
	// 		(OS_STK *)BEEP_TASK_STK[BEEP_STK_SIZE-1],
	// 		BEEP_TASK_PRIO);//创建BEEP任务
	//用OSTaskCreateExt改写
	OSTaskCreateExt(	beepTask, (void *)0,
				(OS_STK *)BEEP_TASK_STK[BEEP_STK_SIZE-1],
				BEEP_TASK_PRIO,
				BEEP_TASK_PRIO,//ID设置为跟优先级一样
				(OS_STK *)BEEP_TASK_STK[0],//栈底指针
				BEEP_STK_SIZE,//堆栈大小
				(void *) 0,//额外参数为空
				OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR//使用任务堆栈检查和清零功能

		)
	OSTaskNameSet(BEEP_TASK_PRIO,(INT8U *)BEEP_NAME,&err);//BEEP_NAME必须为全局变量
	len = OSTaskNameGet(BEEP_TASK_PRIO,&pname,&err)//pname本身为一个指针变量,
	//对pname取地址变成二维指针 
	memcopy(buffer,pname,len);//把pname的内容拷贝到buffer中


	OSTaskSuspend(START_TASK_PRIO);//挂起起始任务
	OS_EXIT_CRITICLE();		//退出临界区 可以被中断打断

	

}
ADI_OSAL_STATUS adi_osal_ThreadGetName(ADI_OSAL_THREAD_HANDLE const hThread,
                                       char_t *pTaskName,
                                       uint32_t nNumBytesToCopy)
{
    char_t *sThreadName = NULL;
    INT8U nErr;
    INT8U nUcosNameSize;
    ADI_OSAL_STATUS eRetStatus;
#pragma diag(push)
#pragma diag(suppress:misra_rule_11_4 : "typecasting is necessary to convert the handle type into a useful type")
        ADI_OSAL_THREAD_INFO_PTR hThreadNode = (ADI_OSAL_THREAD_INFO_PTR) hThread;
#pragma diag(pop)
    INT16U nUcosVersion = OSVersion();

#ifdef OSAL_DEBUG
    /* check validity of the handle */
    if ((hThreadNode==NULL) || (hThread==ADI_OSAL_INVALID_THREAD))
    {
        return (ADI_OSAL_BAD_HANDLE);
    }
    if (hThreadNode->pThreadLocalStorageBuffer==NULL)
    {
        return (ADI_OSAL_BAD_HANDLE);
    }
#endif

   /* In version 2.92 or later the task stores a pointer and GetName returns it
    * so we don't  need to allocate memory for this variable because the uCOS
    * code does not copy the string to it, it simply sets the pointer 
    *
    * In older versions the maximum Task name size (OSTaskNameSize) is only set
    * in uCOS in debug mode so we cannot use it. We use UCHAR_MAX as the max
    * length because the return value is an INT8U.  
    *
    * Note that the prototype of OSTaskNameGet has changed and the pointer is
    * different.
    */

    #pragma diag(push)
    #pragma diag(suppress:misra_rule_11_4 : "typecasting is necessary to convert the char_t type into INT8U type")
    if (nUcosVersion < 292u) 
    {

    /* allocate memory to get the task name based on the maximum task name size
     */

        if (ADI_OSAL_SUCCESS != _adi_osal_MemAlloc((void*) &sThreadName, UCHAR_MAX))
        {
            return (ADI_OSAL_MEM_ALLOC_FAILED);
        }
        PAUSE_PROFILING();
        nUcosNameSize = OSTaskNameGet(hThreadNode->nThreadPrio, 
                                      (void*) sThreadName, &nErr);
        RESUME_PROFILING();

     }
     else
     {
        PAUSE_PROFILING();
        nUcosNameSize = OSTaskNameGet(hThreadNode->nThreadPrio, 
                                      (void*) &sThreadName, &nErr);
        RESUME_PROFILING();
     }

#pragma diag(pop)

    switch(nErr)
    {
        case OS_ERR_NONE:
            strncpy(pTaskName, sThreadName, nNumBytesToCopy - 1u);
            /* We zero-terminate the string in either the last element or 
               where the uCOS name finished
             */
            if (nUcosNameSize < (nNumBytesToCopy) )
            {
                pTaskName[nUcosNameSize + 1u] ='\0';

            }
            else
            {
                pTaskName[nNumBytesToCopy] ='\0';
            }

            eRetStatus = ADI_OSAL_SUCCESS;
            break;
        case OS_ERR_TASK_NOT_EXIST:
        case OS_ERR_PRIO_INVALID:
            eRetStatus = ADI_OSAL_BAD_HANDLE;
            break;
        case OS_ERR_NAME_GET_ISR:
            eRetStatus = ADI_OSAL_CALLER_ERROR;
            break;
        case OS_ERR_PNAME_NULL:
        default:
            eRetStatus = ADI_OSAL_FAILED;
            break;
    }

    if (nUcosVersion < 292u) 
    {
        _adi_osal_MemFree(sThreadName);
    }

    return (eRetStatus);
}
Beispiel #4
0
int
TK_NEWTASK(struct inet_taskinfo * nettask)
{
   INT8U    error;
   OS_STK * stack;

   stack = (OS_STK*)npalloc(nettask->stacksize);
   if(!stack)
      panic("stack alloc");

#if OS_TASK_CREATE_EXT_EN > 0
   error = OSTaskCreateExt(
      nettask->entry,
      NULL,
      stack + (nettask->stacksize/sizeof(OS_STK)) - 1,
      nettask->priority,
      nettask->priority,
      stack, 
      (INT32U)nettask->stacksize / sizeof(OS_STK),
      NULL,
      OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR);
#else
#ifndef TCPWAKE_RTOS
#error  !TCPWAKE_RTOS requires OS_TASK_CREATE_EXT_EN
#endif
   error = OSTaskCreate(
      (void (*)(void *)) nettask->entry,
      NULL,
      stack + (nettask->stacksize/sizeof(OS_STK)) - 1,
      nettask->priority);
#endif
   /* If we go here, then there's another task using our priority */
   /* Tell the user and exit with an error */
   if (error == OS_PRIO_EXIST)
   { 
     char curr_task[OS_TASK_NAME_SIZE];
     INT8U err;
     OSTaskNameGet(nettask->priority, curr_task, &err);
     curr_task[OS_TASK_NAME_SIZE-1]=0;
    
     printf("Priority requested for task \"%s\" (Prio:%d) conflicts with "\
            "already running task \"%s\" (Prio: %d)\n",
             nettask->name, nettask->priority, curr_task, nettask->priority);
             
     printf("You may wish to check your task priority settings in "\
            "\"<bsp path>\\iniche\\src\\h\\nios2\\ipport.h\" against "\
            "the priority settings in your application and recompile.\n\n");
   }
   else if (error == OS_PRIO_INVALID)
   {
     printf("Priority requested for task \"%s\" (Prio:%d) exceeds "\
            "available priority levels in the system (OS_LOWEST_PRIO = %d)\n\n",
             nettask->name, nettask->priority, OS_LOWEST_PRIO);
             
     printf("Please modify the tasks priority level, or modify the "\
            "\"Lowest assignable priority\" setting in the MicroC/OS-II "\
            "component\n");
   }
   else if (error != OS_NO_ERR)
   {                          /* All other errors are fatal */
      printf("Task create error /(MicroC/OS-II error code:%d/) on %s\n",
             error, nettask->name);
      return (-1);
   }

   /* Include the task name, so that uc/osII (os aware) debuggers can
    * display it.
    */
   OSTaskNameSet(nettask->priority, &nettask->name[0], &error);

   nettask->stackbase = (char*)stack;
   *nettask->tk_ptr = (INT8U)nettask->priority;  

   printf("Created \"%s\" task (Prio: %d)\n",
         (char *)nettask->name, nettask->priority);

   return (0);
}