Esempio n. 1
0
void MainTaskCreate(void) {
	OSTaskCreate(main_task, (void *) 0, &main_stack[MAIN_TASK_STACK_SIZE - 1],
			MAIN_TASK_PRIO);
	return;
}
Esempio n. 2
0
void state_test()
{
	OSTaskCreate(state_task, (void *)0, &pTaskStkFirst[task_stk_size-1], task_pio_test_first);
}
Esempio n. 3
0
void TaskStart ( void *data )
{
	PWINDOWS ptr = GetActiveWindow();
	UBYTE  i;
	char   sCmd[MAX_X];
	WORD   key;
	WORD   index, pos = 0x00;

	data = data;                                           /* Prevent compiler warning                 */

	OS_ENTER_CRITICAL();
	PC_VectSet(0x08, OSTickISR);                           /* Install uC/OS-II's clock tick ISR        */
	PC_SetTickRate(OS_TICKS_PER_SEC);                      /* Reprogram tick rate                      */
	OS_EXIT_CRITICAL();

    PC_DispChar(0, 0, ' ', 0x00);               
	PC_DispStr (8, 16, "Determining  CPU's capacity ...", DISP_FGND_WHITE);
	CreateWindow (0, StartY, MAX_X, EndY, DISP_FGND_WHITE, DISP_BGND_BLUE, "[ Prompt Window ]");
	CreateTaskWindows();
	OSStatInit();                                          /* Initialize uC/OS-II's statistics         */

	for (i = 0; i < N_TASKS; i ++)
	{                                                      /* Create N_TASKS identical tasks           */
		TaskData[i] = '0' + i;                             /* Each task will display its own letter    */
		OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);
	}

	DisplayTitle();

	ClearWindow();
	memset(sCmd, 0x00, MAX_X);
	DisplayPrompt();
	for (;;)
	{
		DisplayStatus();                                   // display status of tasks

		if (PC_GetKey(&key) == TRUE)
		{                                                  /* See if key has been pressed              */
			if (key == 0x1B)
			{                                              /* Yes, see if it's the ESCAPE key          */
				PC_DOSReturn();                            /* Return to DOS                            */
			}
			else if (key == 0x08)                           // backspace
			{
				pos --;
				pos = pos <= 0x00 ? 0x00 : pos;
				sCmd[pos] = '\0';
				PC_DispChar(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy, ' ', ptr->color);
				DisplayCursor(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy);
			}
			else if (key == 0x0d || key == 0x0a)                           // enter
			{
				if (pos)
				{
					index = ParseCommand(sCmd);
					HandleCommand(index);
				}
				memset(sCmd, 0x00, MAX_X);
				pos = 0x00;
				ptr->cy ++;
				if (ptr->cy == ptr->ey - 1)
					ClearWindow();
				DisplayPrompt();
			}
			else if ((key >= '0' && key <= '9') ||
				(key >= 'a' && key <= 'z') || (key >= 'A' && key <= 'Z'))
			{
				if (pos < MAX_X)
				{
					sCmd[pos] = (char)key;
					PC_DispChar(ptr->cx + pos + strlen(sCmdPrompt), ptr->cy, key, ptr->color);
	                DisplayCursor (ptr->cx + pos + strlen(sCmdPrompt) + 1, ptr->cy);
				}
				pos ++;
			}

		}
		OSTimeDlyHMSM(0, 0, 0, 200);                         /* Wait 200 ms                          */
	}
}
Esempio n. 4
0
//开始任务函数
void start_task(void *p_arg)
{
    OS_ERR err;
    CPU_SR_ALLOC();
    p_arg = p_arg;

    CPU_Init();
#if OS_CFG_STAT_TASK_EN > 0u
    OSStatTaskCPUUsageInit(&err);  	//统计任务
#endif

#ifdef CPU_CFG_INT_DIS_MEAS_EN		//如果使能了测量中断关闭时间
    CPU_IntDisMeasMaxCurReset();
#endif

#if	OS_CFG_SCHED_ROUND_ROBIN_EN  //当使用时间片轮转的时候
    //使能时间片轮转调度功能,时间片长度为1个系统时钟节拍,既1*5=5ms
    OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
#endif

    OS_CRITICAL_ENTER();	//进入临界区

    OSFlagCreate((OS_FLAG_GRP *)&event_flag,
                 (CPU_CHAR *)"event flag",
                 (OS_FLAGS)0x00,
                 (OS_ERR *)&err
                );
    OSTaskCreate((OS_TCB 	* )&Led0TaskTCB,
                 (CPU_CHAR	* )"led0 task",
                 (OS_TASK_PTR )led0_task,
                 (void		* )0,
                 (OS_PRIO	  )LED0_TASK_PRIO,
                 (CPU_STK   * )&LED0_TASK_STK[0],
                 (CPU_STK_SIZE)LED0_STK_SIZE/10,
                 (CPU_STK_SIZE)LED0_STK_SIZE,
                 (OS_MSG_QTY  )0,
                 (OS_TICK	  )0,
                 (void   	* )0,
                 (OS_OPT      )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
                 (OS_ERR 	* )&err);
    //创建浮点测试任务
    OSTaskCreate((OS_TCB 	* )&FloatTaskTCB,
                 (CPU_CHAR	* )"float test task",
                 (OS_TASK_PTR )float_task,
                 (void		* )0,
                 (OS_PRIO	  )FLOAT_TASK_PRIO,
                 (CPU_STK   * )&FLOAT_TASK_STK[0],
                 (CPU_STK_SIZE)FLOAT_STK_SIZE/10,
                 (CPU_STK_SIZE)FLOAT_STK_SIZE,
                 (OS_MSG_QTY  )5,
                 (OS_TICK	  )0,
                 (void   	* )0,
                 (OS_OPT      )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
                 (OS_ERR 	* )&err);
    //创建协议处理任务
    OSTaskCreate((OS_TCB 	* )&ProtocolTaskTCB,
                 (CPU_CHAR	* )"protocol task",
                 (OS_TASK_PTR )protocol_task,
                 (void		* )0,
                 (OS_PRIO	  )Protocol_TASK_PRIO,
                 (CPU_STK   * )&Protocol_TASK_STK[0],
                 (CPU_STK_SIZE)Protocol_STK_SIZE/10,
                 (CPU_STK_SIZE)Protocol_STK_SIZE,
                 (OS_MSG_QTY  )0,
                 (OS_TICK	  )0,
                 (void   	* )0,
                 (OS_OPT      )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
                 (OS_ERR 	* )&err);
    OS_CRITICAL_EXIT();	//进入临界区


    OSTaskDel(NULL,&err);
}
Esempio n. 5
0
/*!
*
* @brief Alarm Task
*/
void alarm_task(void *arg)
{
    wave_t const *waveform = (wave_t *)NULL;
    uint8_t speaker_task_alive = 0;
    uint8_t create_speaker_task;
    OS_FLAGS flags;
    OS_ERR err;                

    (void)arg;

    speaker_config();

    for (;;)    
    {
        flags = OSFlagPend(&alarm_flags, 0xF, 0,
            OS_OPT_PEND_FLAG_SET_ANY | OS_OPT_PEND_FLAG_CONSUME |
            OS_OPT_PEND_BLOCKING, NULL, &err);
        assert(OS_ERR_NONE == err);

        create_speaker_task = 0;
                
        if ((flags & ALARM_HIGH) && (waveform != &alarm_high))
        {
            kill_speaker_if_alive(&speaker_task_alive);
 
            waveform = &alarm_high;
            create_speaker_task = 1;
        }
        else if ((flags & ALARM_MEDIUM) && (waveform != &alarm_medium))
        {
            kill_speaker_if_alive(&speaker_task_alive);

            waveform = &alarm_medium;
            create_speaker_task = 1;
        }
        else if ((flags & ALARM_LOW) && (waveform != &alarm_low))
        {
            kill_speaker_if_alive(&speaker_task_alive);
            
            waveform = &alarm_low;
            create_speaker_task = 1;
        }
        else if (flags & ALARM_NONE)
        {
            kill_speaker_if_alive(&speaker_task_alive);

            waveform = NULL;
            create_speaker_task = 0;
        }
                
        if (create_speaker_task)
        {
            OSTaskCreate(&speaker_tcb, "Speaker Task", speaker_task,
                (void *)waveform, SPEAKER_PRIO, &speaker_stack[0],
                TASK_STACK_SIZE / 10u, TASK_STACK_SIZE, 0u, 0u, 0, 0, &err);
            assert(OS_ERR_NONE == err);

            speaker_task_alive = 1;
        }
    }
}
Esempio n. 6
0
/*******************************************************************************
* Function Name :void TaskStart(void)
* Description   :任务启动
* Input         :
* Output        :
* Other         :
* Date          :2012.04.18  11:48:23
*******************************************************************************/
static void TaskStart(void)
{
    OS_ERR 		err;
    
    led_init();
    usart1_init(115200);
    SPI_Config() ;
    SysTickInit();
    
    
    OSTaskCreate(   (OS_TCB     *)&task1TCB,
                    (CPU_CHAR   *)"Task1",
                    (OS_TASK_PTR)Task1,
                    (void       *)0,
                    (OS_PRIO    )TASK1_PRIO,
                    (CPU_STK    *)&task1_stk[0],
                    (CPU_STK_SIZE)TASK1_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK1_STK_SIZE,
                    (OS_MSG_QTY )0,
                    (OS_TICK    )0,
                    (void       *)0,
                    (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
                    (OS_ERR     *)&err);
    
    OSTaskCreate(   (OS_TCB     *)&task2TCB,
                    (CPU_CHAR   *)"Task2",
                    (OS_TASK_PTR)Task2,
                    (void       *)0,
                    (OS_PRIO    ) TASK2_PRIO,
                    (CPU_STK    *)&task2_stk[0],
                    (CPU_STK_SIZE)TASK2_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK2_STK_SIZE,
                    (OS_MSG_QTY )0,
                    (OS_TICK    )0,
                    (void       *)0,
                    (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
                    (OS_ERR     *)&err);	
    
    
    OSTaskCreate(   (OS_TCB     *)&task3TCB,
                    (CPU_CHAR   *)"Task3",
                    (OS_TASK_PTR)Task3,
                    (void       *)0,
                    (OS_PRIO    )TASK3_PRIO,
                    (CPU_STK    *)&task3_stk[0],
                    (CPU_STK_SIZE)TASK3_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK3_STK_SIZE,
                    (OS_MSG_QTY )0,
                    (OS_TICK    )0,
                    (void       *)0,
                    (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
                    (OS_ERR     *)&err);
    
    OSTaskCreate(   (OS_TCB     *)&dispTCB,
                    (CPU_CHAR   *)"LCD display",
                    (OS_TASK_PTR)MainTask,
                    (void       *)0,
                    (OS_PRIO    )Disp_PRIO,
                    (CPU_STK    *)&dispStk[0],
                    (CPU_STK_SIZE)TASK4_STK_SIZE / 10,
                    (CPU_STK_SIZE)TASK4_STK_SIZE,
                    (OS_MSG_QTY )0,
                    (OS_TICK    )0,
                    (void       *)0,
                    (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
                    (OS_ERR     *)&err);   
    
    OSTaskCreate(   (OS_TCB     *)&schedTaskEx1TCB,
                    (CPU_CHAR   *)"Sched Task Example1",
                    (OS_TASK_PTR)SchedEx1Task,
                    (void       *)0,
                    (OS_PRIO    )Disp_PRIO,
                    (CPU_STK    *)&dispStk[0],
                    (CPU_STK_SIZE)SCHED_TASK_STK_SIZE / 10,
                    (CPU_STK_SIZE)SCHED_TASK_STK_SIZE,
                    (OS_MSG_QTY )0,
                    (OS_TICK    )0,
                    (void       *)0,
                    (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
                    (OS_ERR     *)&err);  
        
    OSTaskCreate(   (OS_TCB     *)&schedTaskEx2TCB,
                    (CPU_CHAR   *)"Sched Task Example1",
                    (OS_TASK_PTR)SchedEx2Task,
                    (void       *)0,
                    (OS_PRIO    )Disp_PRIO,
                    (CPU_STK    *)&dispStk[0],
                    (CPU_STK_SIZE)SCHED_TASK_STK_SIZE / 10,
                    (CPU_STK_SIZE)SCHED_TASK_STK_SIZE,
                    (OS_MSG_QTY )0,
                    (OS_TICK    )0,
                    (void       *)0,
                    (OS_OPT     )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), 
                    (OS_ERR     *)&err);  


    
    
    OSSemCreate(    (OS_SEM     *)&taskSem, 
                    (CPU_CHAR   *)"taskSem", 
                    (OS_SEM_CTR )0, 
                    (OS_ERR     *)err);
    
    OSTaskDel(      (OS_TCB     *)&taskStartTCB, 
                    (OS_ERR     *)&err);
}
//---------------------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------
void Task_START(void *pdata)
{
    INT8U err;
    OpenTimer0(TIMER_INT_ON & T0_16BIT & T0_SOURCE_INT & T0_PS_1_1);
    
	OpenUSART( USART_TX_INT_OFF &
 				USART_RX_INT_OFF &
 				USART_ASYNCH_MODE &
 				USART_EIGHT_BIT &
 				USART_CONT_RX &
 				//USART_BRGH_LOW,
                USART_BRGH_HIGH,
 			51 );//12 - 9600 LOW
                 //8 - 57.6k HIGH


	OpenADC( ADC_FOSC_32 &
		ADC_RIGHT_JUST &
		ADC_12_TAD,
		ADC_CH0 & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS &
		ADC_INT_OFF, 15 );

    
	TRISA |= 0b01111111;
	TRISD &= 0b01111111;
	TRISE |= 0b00000111;
	ADCON1 &= 0b00000000;
	ADCON1 |= 0b00000000;
	CVRCON &= 0b00111111;
    
    /*
    ANSEL = 0;	//turn off all other analog inputs
	ANSELH = 0;
 	ANSELbits.ANS0 = 1;	// turn on RA0 analog
    ADCON1 = 0;
    ADCON2 = 0b00111000;
    ADCON0 = 0b00000001;
    */


	//STask1  = OSSemCreate(1);
	STaskTxSerial  = OSSemCreate(0);
	STeclado  = OSSemCreate(1);

    dMemory = OSMemCreate((void *)dMemoryData,MEMORY_BLOCK_NUM,MEMORY_SIZE,&err);
    
	QueueADC0 = OSQCreate((void *)QueueADC0Message,QSize);	

	OSTaskCreate(TaskSensores, (void *)0, &TaskSensoresStk[0], 1);
	OSTaskCreate(TaskTxSerial, (void *)0, &TaskTxSerialStk[0], 5);
	OSTaskCreate(TaskTeclado, (void *)0, &TaskTecladoStk[0], 10);

	//i_data = *((int *)pdata);

	// task loop
	for(;;)
	{
		salidaLED_0 = !(salidaLED_0);
		OSTimeDly(50);
		salidaLED_0 = !(salidaLED_0);
		OSTimeDly(50);
	}
}
Esempio n. 8
0
void  OS_IntQTaskInit (OS_ERR  *p_err)
{
    OS_INT_Q      *p_int_q;
    OS_INT_Q      *p_int_q_next;
    OS_OBJ_QTY     i;


    OSIntQOvfCtr = (OS_QTY)0u;                              /* Clear the ISR queue overflow counter                   */

    if (OSCfg_IntQBasePtr == (OS_INT_Q *)0) {
       *p_err = OS_ERR_INT_Q;
        return;
    }

    if (OSCfg_IntQSize < (OS_OBJ_QTY)2u) {
       *p_err = OS_ERR_INT_Q_SIZE;
        return;
    }

    OSIntQTaskTimeMax = (CPU_TS)0;

    p_int_q           = OSCfg_IntQBasePtr;                  /* Initialize the circular ISR queue                      */
    p_int_q_next      = p_int_q;
    p_int_q_next++;
    for (i = 0u; i < OSCfg_IntQSize; i++) {
        p_int_q->Type    =  OS_OBJ_TYPE_NONE;
        p_int_q->ObjPtr  = (void      *)0;
        p_int_q->MsgPtr  = (void      *)0;
        p_int_q->MsgSize = (OS_MSG_SIZE)0u;
        p_int_q->Flags   = (OS_FLAGS   )0u;
        p_int_q->Opt     = (OS_OPT     )0u;
        p_int_q->NextPtr = p_int_q_next;
        p_int_q++;
        p_int_q_next++;
    }
    p_int_q--;
    p_int_q_next        = OSCfg_IntQBasePtr;
    p_int_q->NextPtr    = p_int_q_next;
    OSIntQInPtr         = p_int_q_next;
    OSIntQOutPtr        = p_int_q_next;
    OSIntQNbrEntries    = (OS_OBJ_QTY)0u;
    OSIntQNbrEntriesMax = (OS_OBJ_QTY)0u;

                                                            /* -------------- CREATE THE ISR QUEUE TASK ------------- */
    if (OSCfg_IntQTaskStkBasePtr == (CPU_STK *)0) {
       *p_err = OS_ERR_INT_Q_STK_INVALID;
        return;
    }

    if (OSCfg_IntQTaskStkSize < OSCfg_StkSizeMin) {
       *p_err = OS_ERR_INT_Q_STK_SIZE_INVALID;
        return;
    }

    OSTaskCreate((OS_TCB     *)&OSIntQTaskTCB,
                 (CPU_CHAR   *)((void *)"uC/OS-III ISR Queue Task"),
                 (OS_TASK_PTR )OS_IntQTask,
                 (void       *)0,
                 (OS_PRIO     )0u,                          /* This task is ALWAYS at priority '0' (i.e. highest)     */
                 (CPU_STK    *)OSCfg_IntQTaskStkBasePtr,
                 (CPU_STK_SIZE)OSCfg_IntQTaskStkLimit,
                 (CPU_STK_SIZE)OSCfg_IntQTaskStkSize,
                 (OS_MSG_QTY  )0u,
                 (OS_TICK     )0u,
                 (void       *)0,
                 (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR     *)p_err);
}
Esempio n. 9
0
//开始任务
///////////////////////////////////////////////////////////////////////////////////////////////////////////
void  AppTaskStart (void *p_arg)
{
	OS_ERR  err;
	(void)p_arg;
	//信号量
	OSSemCreate((OS_SEM*		  )&SYNC_SEM,
							(CPU_CHAR*		)"SYNC_SEM",
							(OS_SEM_CTR		)0,
							(OS_ERR*		  )&err
						 );
	//消息队列
	OSQCreate((OS_Q        *)&TIME_DELAY_DATA,
						(CPU_CHAR    *)"delay time",
						(OS_MSG_QTY   )5,
						(OS_ERR      *)&err
						);
	CPU_Init();//初始化cpu,禁用中断,开启时间戳等
	BSP_Tick_Init();//设置滴答定时器
	//OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
//创建任务
    /*------------------------------*/		 
	OSTaskCreate((OS_TCB       *)&AppTaskTASK1TCB,              
                 (CPU_CHAR     *)"task1",
                 (OS_TASK_PTR   )task1, 
                 (void         *)0,
                 (OS_PRIO       )APP_CFG_TASK_TASK1_PRIO,
                 (CPU_STK      *)&AppTaskTASK1Stk[0],
                 (CPU_STK_SIZE  )APP_CFG_TASK_TASK1_STK_SIZE / 10,
                 (CPU_STK_SIZE  )APP_CFG_TASK_TASK1_STK_SIZE,
                 (OS_MSG_QTY    )0,
                 (OS_TICK       )0,
                 (void         *)0,
                 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR       *)&err);
/*------------------------------*/
	OSTaskCreate((OS_TCB       *)&AppTaskTASK2TCB,              
                 (CPU_CHAR     *)"task2",
                 (OS_TASK_PTR   )task2, 
                 (void         *)0,
                 (OS_PRIO       )APP_CFG_TASK_TASK2_PRIO,
                 (CPU_STK      *)&AppTaskTASK2Stk[0],
                 (CPU_STK_SIZE  )APP_CFG_TASK_TASK2_STK_SIZE / 10,
                 (CPU_STK_SIZE  )APP_CFG_TASK_TASK2_STK_SIZE,
                 (OS_MSG_QTY    )0,
                 (OS_TICK       )0,
                 (void         *)0,
                 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR       *)&err);  
/*-------------------------------*/
	OSTaskCreate((OS_TCB       *)&AppTaskTASK3TCB,              
                 (CPU_CHAR     *)"task3",
                 (OS_TASK_PTR   )task3, 
                 (void         *)0,
                 (OS_PRIO       )APP_CFG_TASK_TASK3_PRIO,
                 (CPU_STK      *)&AppTaskTASK3Stk[0],
                 (CPU_STK_SIZE  )APP_CFG_TASK_TASK3_STK_SIZE / 10,
                 (CPU_STK_SIZE  )APP_CFG_TASK_TASK3_STK_SIZE,
                 (OS_MSG_QTY    )0,
                 (OS_TICK       )0,
                 (void         *)0,
                 (OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR       *)&err);
				 
	//创建好其他任务后就删除自己
    OSTaskDel((OS_TCB*)0,&err);
}