根据消息类型,处理相应的中断回调

#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++){
		
	}	
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值