文章作者: 盧宜良
Alerts 有點相似之前介紹的Semaphores,最大的不同是有pending number的功能。可以在在中斷裡面send,並且有記數的作用。
static int my_alert_handler(struct k_alert *alt); K_ALERT_DEFINE(my_alert, my_alert_handler, 10); static int my_alert_handler(struct k_alert *alt) { printk("alert_handler1 [%d]\n", alt->send_count); return 0; } static void tIsr_entry(void *p) { // in isr k_alert_send(&my_alert); k_alert_send(&my_alert); k_alert_send(&my_alert); } void main(void) { //uint32_t uhADCxConvertedValue = 0; //RCC_PeriphCLKInitTypeDef PeriphClkInit; //char buf[64] = {0}; //HAL_Init(); //ADC1_Init(); console_init(); printk("Hello World! %s\n", CONFIG_ARCH); while (1) { printk("main alert_send\n"); k_alert_send(&my_alert); k_alert_send(&my_alert); k_alert_send(&my_alert); k_sleep(2000); printk("irq alert_send\n"); irq_offload(tIsr_entry, NULL); // irq lock -> do tIsr_entry -> irq unlock k_sleep(2000); } }