#include <stdio.h>
#include <stdlib.h>
/*******macro definition*********/
#define MSG_TYPE1 0x1
#define MSG_TYPE2 0x2
/*******type definition*********/
typedef void * VOID_PTR;
typedef void (*demo_pro_callBack_f)(void);
typedef struct message_tag{
int message_type;
int message_body;
}message_t;
/*******func definition*********/
demo_pro_callBack_f demo_pro_callBack;
void demo_process_func1(void){
printf("demo_process_func1\n");
}
void demo_process_func2(void){
printf("demo_process_func2\n");
}
/*******Function declaration*********/
void demo_message_prase_func(VOID_PTR vp_msg_body);
void demo_pro_isr(void);
void demo_sleep(int sleep_time);
int main(int argc, char *argv[]) {
message_t *demo_msg;
demo_msg = (message_t *)malloc(sizeof(message_t));
demo_msg->message_type = 0x2;
demo_msg->message_body = 100;
demo_message_prase_func((VOID_PTR)demo_msg);
demo_sleep(500000);
demo_pro_isr();
free(demo_msg);
demo_msg = NULL;
return 0;
}
void demo_pro_isr(){
(*demo_pro_callBack)();
demo_pro_callBack = NULL;
}
void demo_message_prase_func(VOID_PTR vp_msg_body){
message_t *msg_tmp;
int msg_type = -1;
msg_tmp =(message_t *)vp_msg_body;
msg_type = msg_tmp->message_type;
switch(msg_type){
case MSG_TYPE1:
demo_pro_callBack = demo_process_func1;
break;
case MSG_TYPE2:
demo_pro_callBack = demo_process_func2;
break;
default:
printf("error message type,line = %d\n",__LINE__);
break;
}
}
void demo_sleep(int sleep_time){
int i = 0;
for(i = 0;i < sleep_time;i++){
}
}