2023-08-02 19:54:19 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2023 Trackunit Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2023-11-26 23:35:04 +08:00
|
|
|
#include <zephyr/drivers/gnss/gnss_publish.h>
|
2023-08-02 19:54:19 +08:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/sys/iterable_sections.h>
|
|
|
|
|
2024-05-03 00:19:27 +08:00
|
|
|
static K_SEM_DEFINE(semlock, 1, 1);
|
2023-08-02 19:54:19 +08:00
|
|
|
|
|
|
|
void gnss_publish_data(const struct device *dev, const struct gnss_data *data)
|
|
|
|
{
|
2024-05-03 00:19:27 +08:00
|
|
|
(void)k_sem_take(&semlock, K_FOREVER);
|
|
|
|
|
|
|
|
STRUCT_SECTION_FOREACH(gnss_data_callback, callback) {
|
|
|
|
if (callback->dev == NULL || callback->dev == dev) {
|
|
|
|
callback->callback(dev, data);
|
2023-08-02 19:54:19 +08:00
|
|
|
}
|
|
|
|
}
|
2024-05-03 00:19:27 +08:00
|
|
|
|
|
|
|
k_sem_give(&semlock);
|
2023-08-02 19:54:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if CONFIG_GNSS_SATELLITES
|
|
|
|
void gnss_publish_satellites(const struct device *dev, const struct gnss_satellite *satellites,
|
|
|
|
uint16_t size)
|
|
|
|
{
|
2024-05-03 00:19:27 +08:00
|
|
|
(void)k_sem_take(&semlock, K_FOREVER);
|
|
|
|
|
|
|
|
STRUCT_SECTION_FOREACH(gnss_satellites_callback, callback) {
|
|
|
|
if (callback->dev == NULL || callback->dev == dev) {
|
|
|
|
callback->callback(dev, satellites, size);
|
2023-08-02 19:54:19 +08:00
|
|
|
}
|
|
|
|
}
|
2024-05-03 00:19:27 +08:00
|
|
|
|
|
|
|
k_sem_give(&semlock);
|
2023-08-02 19:54:19 +08:00
|
|
|
}
|
|
|
|
#endif
|