高级会员
- 积分
- 587
- 金钱
- 587
- 注册时间
- 2015-1-9
- 在线时间
- 80 小时
|
5金钱
[mw_shl_code=c,true]//¿aê¼èÎÎñoˉêy
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); //í3¼ÆèÎÎñ
#endif
#ifdef CPU_CFG_INT_DIS_MEAS_EN //èç1ûê1ÄüáË2aá¿ÖD¶Ï1رÕê±¼ä
CPU_IntDisMeasMaxCurReset();
#endif
#if OS_CFG_SCHED_ROUND_ROBIN_EN //μ±ê1óÃê±¼äƬÂÖ×aμÄê±oò
//ê1Äüê±¼äƬÂÖ×aμ÷¶è1|Äü,ê±¼äƬ3¤¶èÎa5¸öÏμí3ê±Öó½úÅÄ£¬¼è5*1=10ms
OSSchedRoundRobinCfg(DEF_ENABLED,5,&err);
#endif
OS_CRITICAL_ENTER(); //½øèëáù½çÇø
//′′½¨èÎÎñ1
OSTaskCreate( (OS_TCB * )&TASKONETCB,
(CPU_CHAR * )" task one",
(OS_TASK_PTR )taskone,
(void * )0,
(OS_PRIO )TASKONE_PRIO,
(CPU_STK * )&TASKONE_STK[0],
(CPU_STK_SIZE)TASKONE_STK_SIZE/10,
(CPU_STK_SIZE)TASKONE_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )6,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
//′′½¨èÎÎñ2
OSTaskCreate( (OS_TCB * )&TASKTWOTCB,
(CPU_CHAR * )"task two",
(OS_TASK_PTR )tasktwo,
(void * )0,
(OS_PRIO )TASKTWO_PRIO,
(CPU_STK * )&TASKTWO_STK[0],
(CPU_STK_SIZE)TASKTWO_STK_SIZE/10,
(CPU_STK_SIZE)TASKTWO_STK_SIZE,
(OS_MSG_QTY )0,
(OS_TICK )3,
(void * )0,
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
(OS_ERR * )&err);
//OS_TaskSuspend((OS_TCB*)&StartTaskTCB,&err); //1òÆe¿aê¼èÎÎñ
OS_CRITICAL_EXIT(); //3öáù½çÇø
OSTaskDel((OS_TCB*)0,&err);//é¾3yèÎÎñ×Ôéí
}
void taskone(void *p_arg)
{
uint32_t timecounter=0,i;
OS_ERR err;
CPU_SR_ALLOC();
p_arg = p_arg;
GUI_DispStringAt("taskone:",0,50);
while(1)
{
timecounter++;
#ifdef PRINTF_DEBUG
OS_CRITICAL_ENTER(); //½øèëáù½çÇø
printf("taskone time counter: %d\r\n",timecounter);
OS_CRITICAL_EXIT(); //íË3öáù½çÇø
#endif
//OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_HMSM_STRICT,&err); //
}
}
void tasktwo(void *p_arg)
{
uint32_t timecounter=0,i;
OS_ERR err;
CPU_SR_ALLOC();
p_arg = p_arg;
//GUI_DrawCircle(600,250,50);
GUI_DispStringAt("tasktwo:",0,240);
while(1)
{
timecounter++;
#ifdef PRINTF_DEBUG
OS_CRITICAL_ENTER(); //½øèëáù½çÇø
printf("TASKTWO TIME COUNTER: %d\r\n",timecounter);
OS_CRITICAL_EXIT(); //íË3öáù½çÇø
#endif
//OSTimeDlyHMSM(0,0,0,10,OS_OPT_TIME_HMSM_STRICT,&err); //
}
}[/mw_shl_code]
|
最佳答案
查看完整内容[请看2#楼]
这有什么问题,你task里面调用ucos的delay函数就把本身的线程挂起了,剩余的时间片系统当然会运行第二个线程。你要想不这样,换用非ucos的delay方式。
|