请教下各位老师
AI8051U实验箱第八集视频结构体和指针函数回调问题
1、u8 Tasks_Max = sizeof(Task_Comps)/sizeof(Task_Comps[0]); sizeof(Task_Comps) 是多大值,sizeof(Task_Comps[0]是多大值?
2、指针函数是怎么回调的?
typedef struct
{
u8 Run; //任务状态:Run/Stop
u16 TIMCount; //定时计数器
u16 TRITime; //重载计数器
void (*TaskHook) (void); //任务函数
} TASK_COMPONENTS;
static TASK_COMPONENTS Task_Comps[]=
{
//状态 计数 周期 函数
{0, 300, 300, LED0_Blink}, / task 1 Period: 300ms /
{0, 600, 600, LED1_Blink}, / task 1 Period: 600ms /
{0, 900, 900, LED2_Blink}, / task 1 Period: 600ms /
{0, 10, 10, KEY_Task}, / task 1 Period: 600ms /
};
u8 Tasks_Max = sizeof(Task_Comps)/sizeof(Task_Comps[0]);
void Task_Marks_Handler_Callback(void)
{
u8 i;
for(i=0; i<Tasks_Max; i++)
{
if(Task_Comps[i].TIMCount) / If the time is not 0 /
{
Task_Comps[i].TIMCount--; / Time counter decrement /
if(Task_Comps[i].TIMCount == 0) / If time arrives /
{
/Resume the timer value and try again /
Task_Comps[i].TIMCount = Task_Comps[i].TRITime;
Task_Comps[i].Run = 1; / The task can be run /
}
}
}
}
//========================================================================
// 函数: Task_Pro_Handler_Callback
// 描述: 任务处理回调函数.
// 参数: None.
// 返回: None.
// 版本: V1.0, 2012-10-22
//========================================================================
void Task_Pro_Handler_Callback(void)
{
u8 i;
for(i=0; i<Tasks_Max; i++)
{
if(Task_Comps[i].Run) / If task can be run /
{
Task_Comps[i].Run = 0; / Flag clear 0 /
Task_Comps[i].TaskHook(); / Run task /
}
}
} |