OS_Thread_t motor_angel_thread;
OS_Queue_t motor_queue;
void motor_angel_pth(void *param)
{
event_obj_t msg;
int ret;
while(1)
{
memset(&msg, 0x0, sizeof(msg));
ret = OS_QueueReceive(&q_motor_pir_t.motor_queue, &msg, 200);
if ((ret == 0) && (msg.event_cb)) {
ret = msg.event_cb(msg.args, msg.msg_type);
}
}
}
int motor_angel(void)
{
printf("motor_angel\r\n");
int ret;
ret = OS_QueueCreate(&q_motor_pir_t.motor_queue, 30, sizeof(event_obj_t));
if (ret != 0) {
printf("Create queue err:%d\n", ret);
return -1;
}
if((ret = OS_ThreadCreate(&q_motor_pir_t.motor_angel_thread, "motor_angel_pth",
motor_angel_pth, NULL, 1, 2048)) < 0) {
printf("Create motor_angel_pth err:%d\n", ret);
return -1;
}
return 0;
}
int event_push_event_to_queue(int type, pfunc_event_cb_ex cb, void *arg)
{
int ret = 0;
event_obj_t msg;
msg.args = arg;
msg.event_cb = cb;
msg.msg_type = type;
ret = OS_QueueSend(&q_motor_pir_t.motor_queue, &msg, 0);
return ret;
}
typedef int (*pfunc_event_cb_ex)(void *args, int type);
typedef struct __event_obj{
int msg_type;
pfunc_event_cb_ex event_cb;
void *args;
} event_obj_t;
触发回调函数后 使用event_push_event_to_queue 向消息队列发送 收到后进行相应处理