Hello , every body: Hope you could give me some suggestion. I use this module to arrange my functions in a period of time, that says, when the times up, the specified routine will execute. I put the structure in the xdata, it seems that no signal was sent in time , but when I use simulator to debug, it actually could run into the corresponding function. Does any one know what's wrong in my program? Thanks a lot! PS. Well , I didn't post the timer routine
#define TASK_CONTROL_BLOCK_ENABLED #define END_LIST (const char *)0 #define TASK_DISABLED -1 #define TASK_ENABLED 0 #define NOT_PRESSED 0 static char idata Tmt_Thermal = 1; //Toggle a port-bit every 2 seconds (this is an example usage) static char idata Tmt_SetSystemVariable=5; static char idata Tmt_DetectFanStatus=10; static char idata Tmt_Hundredth_sec = 0; static char idata Tmt_Tenth_sec = 10; static char idata DetectCommand_timer = 1; #define RESET_DETECT_TIMER DetectCommand_timer = 5 #define RESET_DETECTFANSTATUS Tmt_DetectFanStatus=10 #define RESET_SETSYSTEMVARIABLE Tmt_SetSystemVariable=5 #define RESET_TMT_THERMAL Tmt_Thermal = 1 #define RESET_TMT_TENTH_SEC Tmt_Tenth_sec = 10 typedef xdata struct // Task control Block structure { char *task_flag; void (code * task_action)(void); } TCB _at_ 0x0062 ; static VOID HundredthSecTimer(VOID); static VOID TenthSecTimer(VOID); static BOOL TaskController(TCB *); static xdata const TCB Hundredth_sec[] = { &(Tmt_Hundredth_sec),HundredthSecTimer, &(Tmt_SetSystemVariable), SetSystemThermVariable, //&(Tmt_DetectFanStatus), DetectFanStatus, END_LIST,0 }; static xdata const TCB Tenth_sec[] = { &(Tmt_Tenth_sec), TenthSecTimer, //TODO:: put the EEprom read here END_LIST,0 }; static xdata const TCB Whole_sec[] = { &(Tmt_Thermal),ThermalDetect, END_LIST,0 }; static BOOL TaskController(TCB *tcb_list) { BOOL result=FAIL; while(tcb_list -> task_flag != END_LIST){ // while not at end of TCB list if(*tcb_list -> task_flag == TASK_ENABLED){ // if the timer says the task is ready to execute WATCHDOG_RESET_250ms; tcb_list -> task_action(); // execute the timed task result=SUCCESS; } tcb_list++; // move on to next timed element in the list } return result; //return (tcb_list -> task_flag==END_LIST)?(SUCCESS):(FAIL);//<<<_1011_1::ADD_1>>>// } static VOID HundredthSecTimer(VOID) { TCB *ptr; Tmt_Hundredth_sec = 10; // Reset timer-variable to re-execute this routine in 1/10 second // Decrement all timers in Tenth_sec TCB list every 1/100 second for (ptr = &(Tenth_sec[0]); ptr ->task_flag != END_LIST; ptr ++){ WATCHDOG_RESET_250ms; if (*(ptr -> task_flag) > 0){ *(ptr -> task_flag) -= 1; } } } static VOID TenthSecTimer(VOID) { TCB *ptr; //<<<_1011_1::DEL::put at outside //Tmt_Tenth_sec = 10; // Reset timer-variable to re-execute this routine in 1 second //_1>>> // Decrement all whole_sec timers every 1/10 second for (ptr = &(Whole_sec[0]); ptr ->task_flag != END_LIST; ptr ++){ WATCHDOG_RESET_250ms; if (*(ptr -> task_flag) > 0){ *(ptr -> task_flag) -= 1; } } } void TaskEnable(void) { TCB *ptr; for (ptr = &(Hundredth_sec[0]); ptr ->task_flag != END_LIST; ptr ++) { WATCHDOG_RESET_250ms; if (*(ptr -> task_flag) > 0) { *(ptr -> task_flag) -= 1; } } } VOID TaskControl(VOID) { if(SUCCESS==TaskController(Hundredth_sec)){ (Tmt_SetSystemVariable==0)?RESET_SETSYSTEMVARIABLE:1; (Tmt_DetectFanStatus==0)?RESET_DETECTFANSTATUS:1; RESET_DETECT_TIMER; } if(SUCCESS==TaskController(Tenth_sec)){ (Tmt_Tenth_sec==0)?RESET_TMT_TENTH_SEC:1; } if(SUCCESS==TaskController(Whole_sec)){ RESET_TMT_THERMAL; } } void main(void) { for(;;){ TaskControl(); } }