本文主要是介绍rtos:zephyr同步alerts(通知),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
alert可以同linux平台下的signal。
alert的初始化:
方法1:
extern int my_alert_handler(struct k_alert *alert);struct k_alert my_alert;k_alert_init(&my_alert, my_alert_handler, 10);
方法2:
extern int my_alert_handler(struct k_alert *alert);K_ALERT_DEFINE(my_alert, my_alert_handler, 10);
发出一个alert:
extern int my_alert_handler(struct k_alert *alert);K_ALERT_DEFINE(my_alert, my_alert_handler, 10);void keypress_interrupt_handler(void *arg)
{...k_alert_send(&my_alert);...
}
处理一个alert:
int <function_name>(struct k_alert *alert)
{/* catch the alert signal; return zero if the signal is consumed, *//* or non-zero to let the alert pend */...
}
int my_alert_handler(struct k_alert *alert_id_is_unused)
{/* determine what key was pressed */char c = get_keypress();/* do complex processing of the keystroke */.../* signaled alert has been consumed */return 0;
}
接收一个alert:
int my_alert_handler(struct k_alert *alert_id_is_unused)
{/* determine what key was pressed */char c = get_keypress();/* signal thread only if key pressed was a digit */if ((c >= '0') && (c <= '9')) {/* save key press information */.../* signaled alert should be pended */return 1;} else {/* signaled alert has been consumed */return 0;}
}void keypress_thread(void *unused1, void *unused2, void *unused3)
{/* consume numeric key presses */while (1) {/* wait for a key press alert to pend */k_alert_recv(&my_alert, K_FOREVER);/* process saved key press, which must be a digit */...}
}
一个挂起的的alter可以通过另一个线程调用k_alert_recv()接口接收这个alter。
这篇关于rtos:zephyr同步alerts(通知)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!