那个读懂的,请给加个中文注释。
H文件
typedef struct {
u16 id; // Application ID
void (*ini_func)(void*); // Function - Initialization
void (*end_func)(void*); // Function - Finalization
void (*run_func)(void*); // Function - Proccess
} AP_TBL_ST;
typedef struct {
u16 id;
AP_TBL_ST* pCurAP;
u8 gr_timer_handle;
u16 reserve_id;
} CONTEXT_ST;
/* Private define ------------------------------------------------------------*/
#define AP_INIT (0x8000)
#define AP_SET(id) (AP_INIT|(id))
#define AP_END (0xFFFF)
/* Input Context ID */
#define AP_INPUT_UACTL (0)
/* State Context ID */
#define AP_STATE_DETECT (0)
#define AP_STATE_UACTL (1)
#define AP_STATE_SYSERR (2)
/* Display Context ID */
#define AP_DISPLAY_DETECT (0)
#define AP_DISPLAY_UACTL (1)
#define AP_DISPLAY_MONITOR (2)
c 代码
// Input Table
static AP_TBL_ST gstInputTbl[] = {
{ AP_INPUT_UACTL, AP_Input_Ini_UACTL, AP_Input_End_UACTL, AP_Input_Run_UACTL },
{ AP_END, 0, 0, 0 }
};
// State Table
static AP_TBL_ST gstStateTbl[] = {
{ AP_STATE_DETECT, AP_State_Ini_Detect, AP_State_End_Detect, AP_State_Run_Detect },
{ AP_STATE_UACTL, AP_State_Ini_UACTL, AP_State_End_UACTL, AP_State_Run_UACTL },
{ AP_STATE_SYSERR, AP_State_Ini_sys_error, 0, 0 },
{ AP_END, 0, 0, 0 }
};
// Display Table
static AP_TBL_ST gstDisplayTbl[] = {
{ AP_DISPLAY_DETECT, AP_Display_Ini_Detect, AP_Display_End_Detect, AP_Display_Run_Detect },
{ AP_DISPLAY_UACTL, AP_Display_Ini_UACTL, AP_Display_End_UACTL, AP_Display_Run_UACTL },
{ AP_DISPLAY_MONITOR, AP_Display_Ini_Monitor, AP_Display_End_Monitor, AP_Display_Run_Monitor },
{ AP_END, 0, 0, 0 }
};
static MAIN_OBJ_ST gu_obMain;
int main(void)
{
INPUT_OBJ_ST* pInput;
STATE_OBJ_ST* pState;
DISPLAY_OBJ_ST* pDisplay;
省略初始化部分
appInitialize( &gu_obMain );
pInput = &gu_obMain.obInput;
pState = &gu_obMain.obState;
pDisplay = &gu_obMain.obDisplay;
while (1)
{
processContext( &pInput->ctx, gstInputTbl, (void*)&gu_obMain );
// State Control process
processContext( &pState->ctx, gstStateTbl, (void*)&gu_obMain );
// Display Control process
processContext( &pDisplay->ctx, gstDisplayTbl, (void*)&gu_obMain );
}
}
|