在STM8写了一个任务调度器,总是运行一会就卡死。
typedef struct {
void(*funname)();
unsigned int delaytime[2];
unsigned char flag;
}TASK_DEF;
extern TASK_DEF Task[];extern void (*function)(void);
调度器:
void exchang_fun(void)
{ unsigned char i;
while(1)
{ for(i = 0;i < maxtask;i++)
{
if((Task.flag==1)&&(Task.delaytime[0]==0))
{
Task.delaytime[0] = Task.delaytime[1];
Task.flag = 0;
function=Task.funname;
(*function)();
}
}
}
}
中断函数:
@far @interrupt void TIM4_IRQ(void)
{
unsigned char id;
TIM4_SR = 0x00;
for(id=0;id<maxtask;id++)
{
if(Task[id].delaytime[0]>0)
{
Task[id].delaytime[0]--;
}
if(Task[id].delaytime[0]==0)
{
Task[id].flag = 1;
}
}
}
为什么总是卡死?
|