简单的多任务操作系统
char i;
#define txk_num 3
#define stk_deep 12
unsigned char txk_id;
unsigned int txk_sp[txk_num];
unsigned char txk_stack[txk_num][stk_deep];
void txk_switch()
{
txk_sp[txk_id]=SP; 保存了运行状态
if(txk_id==(txk_num-1))txk_id=0;
else txk_id++;
SP=txk_sp[txk_id];
}
void txk_load(unsigned int txk_name,unsigned char txk_channel)
{
txk_stack[txk_channel][0]=(unsigned int)txk_name&0x00ff;
txk_stack[txk_channel][1]=(unsigned int)txk_name>>8;
txk_sp[txk_channel]=txk_stack[txk_channel]+1;
}
void os_go(unsigned char first_txk_id)
{
txk_id=first_txk_id;SP=txk_stack[first_txk_id]+1;
}
void task1()
{
while(1)
{
i++;
txk_switch();
i++;
i++;
i++;}
}
void task2()
{
while(1)
{
i++;
txk_switch();
i++;
i++;
i++;}
}
void task3()
{
while(1)
{
i++;
txk_switch();
i++;
i++;
i++;}
}
void main()
{
txk_load(task1,0);
txk_load(task2,1);
txk_load(task3,2);
os_go(0);
}
4796

被折叠的 条评论
为什么被折叠?



