1 /*
2  * Copyright (c) 2023 Trackunit Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/drivers/gnss/gnss_publish.h>
8 #include <zephyr/kernel.h>
9 #include <zephyr/sys/iterable_sections.h>
10 
11 static K_SEM_DEFINE(semlock, 1, 1);
12 
gnss_publish_data(const struct device * dev,const struct gnss_data * data)13 void gnss_publish_data(const struct device *dev, const struct gnss_data *data)
14 {
15 	(void)k_sem_take(&semlock, K_FOREVER);
16 
17 	STRUCT_SECTION_FOREACH(gnss_data_callback, callback) {
18 		if (callback->dev == NULL || callback->dev == dev) {
19 			callback->callback(dev, data);
20 		}
21 	}
22 
23 	k_sem_give(&semlock);
24 }
25 
26 #if CONFIG_GNSS_SATELLITES
gnss_publish_satellites(const struct device * dev,const struct gnss_satellite * satellites,uint16_t size)27 void gnss_publish_satellites(const struct device *dev, const struct gnss_satellite *satellites,
28 			     uint16_t size)
29 {
30 	(void)k_sem_take(&semlock, K_FOREVER);
31 
32 	STRUCT_SECTION_FOREACH(gnss_satellites_callback, callback) {
33 		if (callback->dev == NULL || callback->dev == dev) {
34 			callback->callback(dev, satellites, size);
35 		}
36 	}
37 
38 	k_sem_give(&semlock);
39 }
40 #endif
41