📄 task.lst
字号:
if (_tasks[prio].state & STATE_READY) {
_tasks[prio].state |= STATE_SUSPEND;
__ready_que_susremove(prio, _tasks[prio].state);
CRITICAL_EXIT;
__schedule();
return EOK;
} else {
CRITICAL_EXIT;
return ENOTEXIST;
}
}
err_t task_resume(u8 prio)
{
C51 COMPILER V6.12 TASK 12/07/2004 17:58:47 PAGE 10
#if CFG_ARG_CHK > 1
if (prio >= TASK_IDLE_PRIO) {
return EOUTRANGE;
}
#else
__ASSERT(prio < TASK_IDLE_PRIO);
#endif
CRITICAL_ENTER;
if (!(_tasks[prio].state & STATE_READY)) {
CRITICAL_EXIT;
return ENOTEXIST;
}
_tasks[prio].state &= ~STATE_SUSPEND;
if ((_tasks[prio].state & STATE_PREREADY) ||
(!(_tasks[prio].state & STATE_BLOCKED) &&
_tasks[prio].delay == 0)) {
_tasks[prio].state &= ~STATE_PREREADY;
__ready_que_add(prio);
}
CRITICAL_EXIT;
__schedule();
return EOK;
}
#elif CFG_TASK_SUS_EN > 0
err_t task_suspend(u8 prio)
{
register u8 cprio;
#if CFG_ARG_CHK > 1
if (prio >= TASK_IDLE_PRIO && prio != SELF_PRIO) {
return EOUTRANGE;
}
#else
__ASSERT(prio < TASK_IDLE_PRIO || prio == SELF_PRIO);
#endif
CRITICAL_ENTER;
if (prio == SELF_PRIO) {
cprio = _current_prio;
prio = _tasks[cprio].prio.normal;
} else if (!__prio_if_normal(prio)) {
CRITICAL_EXIT;
return ENOTEXIST;
} else {
cprio = _tasks[prio].prio.current;
}
_tasks[cprio].state |= STATE_SUSPEND;
__ready_que_susremove(cprio, _tasks[cprio].state);
CRITICAL_EXIT;
__schedule();
return EOK;
}
err_t task_resume(u8 prio)
{
C51 COMPILER V6.12 TASK 12/07/2004 17:58:47 PAGE 11
register u8 cprio;
#if CFG_ARG_CHK > 1
if (prio >= TASK_IDLE_PRIO) {
return EOUTRANGE;
}
#else
__ASSERT(prio < TASK_IDLE_PRIO);
#endif
CRITICAL_ENTER;
if (!__prio_if_normal(prio)) {
CRITICAL_EXIT;
return ENOTEXIST;
}
cprio = _tasks[prio].prio.current;
_tasks[cprio].state &= ~STATE_SUSPEND;
if ((_tasks[cprio].state & STATE_PREREADY) ||
(!(_tasks[cprio].state & STATE_BLOCKED) &&
_tasks[cprio].delay == 0)) {
_tasks[cprio].state &= ~STATE_PREREADY;
__ready_que_add(cprio);
}
CRITICAL_EXIT;
__schedule();
return EOK;
}
#endif
643
644 void __idle_task(arg_t arg)
645 {
646 1 arg = arg;
647 1
648 1 while (true) {
649 2 hook_idle_task();
650 2
651 2 #if CFG_TASK_INFO_EN>0
CRITICAL_ENTER;
_idle_counter++;
CRITICAL_EXIT;
#endif
656 2 }
657 1 }
658
659 #if CFG_TASK_INFO_EN > 0
u32 __get_max_idlecnt(void)
{
u32 idle_cnt_max;
task_sleep(2);
CRITICAL_ENTER;
_idle_counter = 0L;
CRITICAL_EXIT;
task_sleep(TICKS_PER_SECOND);
CRITICAL_ENTER;
idle_cnt_max = _idle_counter;
CRITICAL_EXIT;
C51 COMPILER V6.12 TASK 12/07/2004 17:58:47 PAGE 12
return idle_cnt_max;
}
void __usrtask_suspend(void)
{
u8 prio;
for (prio = 0; prio != TASK_INFO_PRIO; prio++) {
task_suspend(prio);
}
}
void __usrtask_resume(void)
{
u8 prio;
for (prio = 0; prio != TASK_INFO_PRIO; prio++) {
task_resume(prio);
}
}
void __info_task(arg_t arg)
{
u32 idle_cnt;
u32 idle_cnt_max;
s8 usage;
arg = arg;
idle_cnt_max = __get_max_idlecnt();
__usrtask_resume();
__ASSERT(idle_cnt_max != 0);
for (;;) {
hook_info_task();
task_lock();
idle_cnt = _idle_counter;
_idle_counter = 0L;
usage = (s8)(100L - 100L * idle_cnt / idle_cnt_max);
if (usage >= 0) {
_task_info.cpu_usage = usage;
} else {
_task_info.cpu_usage = 0;
}
task_unlock();
task_sleep(TICKS_PER_SECOND);
}
}
err_t task_getinfo(info_t __p_* info)
{
register u8 prio;
__ASSERT(info != NULL);
prio = info->prio;
C51 COMPILER V6.12 TASK 12/07/2004 17:58:47 PAGE 13
#if TASK_IDLE_PRIO < 0xff && CFG_ARG_CHK > 1
if (prio > TASK_IDLE_PRIO) {
return EOUTRANGE;
}
#elif TASK_IDLE_PRIO < 0xff
__ASSERT(prio <= TASK_IDLE_PRIO);
#endif
task_lock();
info->cpu_usage = _task_info.cpu_usage;
info->state = _tasks[prio].state;
info->delay = _tasks[prio].delay;
info->stack = _tasks[prio].stack;
task_unlock();
return EOK;
}
#endif
755
756 void __task_init(void)
757 {
758 1 u8 prio;
759 1
760 1 prio = TASK_IDLE_PRIO + 1;
761 1 do {
762 2 __memclr(&_tasks[--prio], sizeof(task_t));
763 2 } while (prio != 0);
764 1
765 1 task_create(TASK_IDLE_PRIO,
771 1 __idle_task,
771 1 (arg_t)0,
771 1 "__idle",
771 1 (sp_t)IDLE_STK_TOP,
771 1 CFG_IDLE_STACKSZ,
771 1 0);
772 1
773 1 #if CFG_TASK_INFO_EN>0
task_create(TASK_INFO_PRIO,
__info_task,
(arg_t)0,
"__info",
(sp_t)STATUS_STK_TOP,
CFG_INFO_STACKSZ,
0);
#endif
782 1
783 1 }
784
785
786 /*===========================================================================*/
787
788
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 303 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 16 7
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
C51 COMPILER V6.12 TASK 12/07/2004 17:58:47 PAGE 14
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -