Zephyr API Documentation  3.6.0
A Scalable Open Source RTOS
3.6.0
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
gnss.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Trackunit Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
12#ifndef ZEPHYR_INCLUDE_DRIVERS_GNSS_H_
13#define ZEPHYR_INCLUDE_DRIVERS_GNSS_H_
14
22#include <zephyr/types.h>
23#include <zephyr/device.h>
25#include <errno.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
41};
42
44typedef int (*gnss_set_fix_rate_t)(const struct device *dev, uint32_t fix_interval_ms);
45
47typedef int (*gnss_get_fix_rate_t)(const struct device *dev, uint32_t *fix_interval_ms);
48
60};
61
63typedef int (*gnss_set_periodic_config_t)(const struct device *dev,
64 const struct gnss_periodic_config *periodic_config);
65
67typedef int (*gnss_get_periodic_config_t)(const struct device *dev,
68 struct gnss_periodic_config *periodic_config);
69
80};
81
83typedef int (*gnss_set_navigation_mode_t)(const struct device *dev,
84 enum gnss_navigation_mode mode);
85
87typedef int (*gnss_get_navigation_mode_t)(const struct device *dev,
88 enum gnss_navigation_mode *mode);
89
108};
109
112
114typedef int (*gnss_set_enabled_systems_t)(const struct device *dev, gnss_systems_t systems);
115
117typedef int (*gnss_get_enabled_systems_t)(const struct device *dev, gnss_systems_t *systems);
118
120typedef int (*gnss_get_supported_systems_t)(const struct device *dev, gnss_systems_t *systems);
121
132};
133
150};
151
153struct gnss_info {
162};
163
165struct gnss_time {
178};
179
181__subsystem struct gnss_driver_api {
191};
192
194struct gnss_data {
201};
202
204typedef void (*gnss_data_callback_t)(const struct device *dev, const struct gnss_data *data);
205
209 const struct device *dev;
212};
213
228};
229
231typedef void (*gnss_satellites_callback_t)(const struct device *dev,
232 const struct gnss_satellite *satellites,
233 uint16_t size);
234
238 const struct device *dev;
241};
242
252__syscall int gnss_set_fix_rate(const struct device *dev, uint32_t fix_interval_ms);
253
254static inline int z_impl_gnss_set_fix_rate(const struct device *dev, uint32_t fix_interval_ms)
255{
256 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
257
258 if (api->set_fix_rate == NULL) {
259 return -ENOSYS;
260 }
261
262 return api->set_fix_rate(dev, fix_interval_ms);
263}
264
274__syscall int gnss_get_fix_rate(const struct device *dev, uint32_t *fix_interval_ms);
275
276static inline int z_impl_gnss_get_fix_rate(const struct device *dev, uint32_t *fix_interval_ms)
277{
278 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
279
280 if (api->get_fix_rate == NULL) {
281 return -ENOSYS;
282 }
283
284 return api->get_fix_rate(dev, fix_interval_ms);
285}
286
296__syscall int gnss_set_periodic_config(const struct device *dev,
297 const struct gnss_periodic_config *config);
298
299static inline int z_impl_gnss_set_periodic_config(const struct device *dev,
300 const struct gnss_periodic_config *config)
301{
302 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
303
304 if (api->set_periodic_config == NULL) {
305 return -ENOSYS;
306 }
307
308 return api->set_periodic_config(dev, config);
309}
310
320__syscall int gnss_get_periodic_config(const struct device *dev,
321 struct gnss_periodic_config *config);
322
323static inline int z_impl_gnss_get_periodic_config(const struct device *dev,
324 struct gnss_periodic_config *config)
325{
326 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
327
328 if (api->get_periodic_config == NULL) {
329 return -ENOSYS;
330 }
331
332 return api->get_periodic_config(dev, config);
333}
334
344__syscall int gnss_set_navigation_mode(const struct device *dev,
345 enum gnss_navigation_mode mode);
346
347static inline int z_impl_gnss_set_navigation_mode(const struct device *dev,
348 enum gnss_navigation_mode mode)
349{
350 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
351
352 if (api->set_navigation_mode == NULL) {
353 return -ENOSYS;
354 }
355
356 return api->set_navigation_mode(dev, mode);
357}
358
368__syscall int gnss_get_navigation_mode(const struct device *dev,
369 enum gnss_navigation_mode *mode);
370
371static inline int z_impl_gnss_get_navigation_mode(const struct device *dev,
372 enum gnss_navigation_mode *mode)
373{
374 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
375
376 if (api->get_navigation_mode == NULL) {
377 return -ENOSYS;
378 }
379
380 return api->get_navigation_mode(dev, mode);
381}
382
392__syscall int gnss_set_enabled_systems(const struct device *dev, gnss_systems_t systems);
393
394static inline int z_impl_gnss_set_enabled_systems(const struct device *dev,
395 gnss_systems_t systems)
396{
397 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
398
399 if (api->set_enabled_systems == NULL) {
400 return -ENOSYS;
401 }
402
403 return api->set_enabled_systems(dev, systems);
404}
405
415__syscall int gnss_get_enabled_systems(const struct device *dev, gnss_systems_t *systems);
416
417static inline int z_impl_gnss_get_enabled_systems(const struct device *dev,
418 gnss_systems_t *systems)
419{
420 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
421
422 if (api->get_enabled_systems == NULL) {
423 return -ENOSYS;
424 }
425
426 return api->get_enabled_systems(dev, systems);
427}
428
438__syscall int gnss_get_supported_systems(const struct device *dev, gnss_systems_t *systems);
439
440static inline int z_impl_gnss_get_supported_systems(const struct device *dev,
441 gnss_systems_t *systems)
442{
443 const struct gnss_driver_api *api = (const struct gnss_driver_api *)dev->api;
444
445 if (api->get_supported_systems == NULL) {
446 return -ENOSYS;
447 }
448
449 return api->get_supported_systems(dev, systems);
450}
451
458#if CONFIG_GNSS
459#define GNSS_DATA_CALLBACK_DEFINE(_dev, _callback) \
460 static const STRUCT_SECTION_ITERABLE(gnss_data_callback, \
461 _gnss_data_callback__##_callback) = { \
462 .dev = _dev, \
463 .callback = _callback, \
464 }
465#else
466#define GNSS_DATA_CALLBACK_DEFINE(_dev, _callback)
467#endif
468
475#if CONFIG_GNSS_SATELLITES
476#define GNSS_SATELLITES_CALLBACK_DEFINE(_dev, _callback) \
477 static const STRUCT_SECTION_ITERABLE(gnss_satellites_callback, \
478 _gnss_satellites_callback__##_callback) = { \
479 .dev = _dev, \
480 .callback = _callback, \
481 }
482#else
483#define GNSS_SATELLITES_CALLBACK_DEFINE(_dev, _callback)
484#endif
485
490#ifdef __cplusplus
491}
492#endif
493
494#include <syscalls/gnss.h>
495
496#endif /* ZEPHYR_INCLUDE_DRIVERS_GNSS_H_ */
System error numbers.
void(* gnss_data_callback_t)(const struct device *dev, const struct gnss_data *data)
Template for GNSS data callback.
Definition: gnss.h:204
int gnss_get_enabled_systems(const struct device *dev, gnss_systems_t *systems)
Get enabled GNSS systems.
gnss_fix_status
GNSS fix status.
Definition: gnss.h:123
int gnss_set_fix_rate(const struct device *dev, uint32_t fix_interval_ms)
Set the GNSS fix rate.
int(* gnss_set_periodic_config_t)(const struct device *dev, const struct gnss_periodic_config *periodic_config)
API for setting periodic tracking configuration.
Definition: gnss.h:63
gnss_pps_mode
GNSS PPS modes.
Definition: gnss.h:32
int gnss_get_periodic_config(const struct device *dev, struct gnss_periodic_config *config)
Get the GNSS periodic tracking configuration.
int gnss_get_supported_systems(const struct device *dev, gnss_systems_t *systems)
Get supported GNSS systems.
int(* gnss_get_fix_rate_t)(const struct device *dev, uint32_t *fix_interval_ms)
API for getting fix rate.
Definition: gnss.h:47
uint32_t gnss_systems_t
Type storing bitmask of GNSS systems.
Definition: gnss.h:111
int(* gnss_set_fix_rate_t)(const struct device *dev, uint32_t fix_interval_ms)
API for setting fix rate.
Definition: gnss.h:44
int(* gnss_get_periodic_config_t)(const struct device *dev, struct gnss_periodic_config *periodic_config)
API for setting periodic tracking configuration.
Definition: gnss.h:67
int gnss_set_periodic_config(const struct device *dev, const struct gnss_periodic_config *config)
Set the GNSS periodic tracking configuration.
void(* gnss_satellites_callback_t)(const struct device *dev, const struct gnss_satellite *satellites, uint16_t size)
Template for GNSS satellites callback.
Definition: gnss.h:231
int gnss_set_enabled_systems(const struct device *dev, gnss_systems_t systems)
Set enabled GNSS systems.
int gnss_get_fix_rate(const struct device *dev, uint32_t *fix_interval_ms)
Get the GNSS fix rate.
int(* gnss_set_enabled_systems_t)(const struct device *dev, gnss_systems_t systems)
API for enabling systems.
Definition: gnss.h:114
gnss_system
Systems contained in gnss_systems_t.
Definition: gnss.h:91
int(* gnss_get_navigation_mode_t)(const struct device *dev, enum gnss_navigation_mode *mode)
API for getting navigation mode.
Definition: gnss.h:87
int gnss_set_navigation_mode(const struct device *dev, enum gnss_navigation_mode mode)
Set the GNSS navigation mode.
gnss_fix_quality
GNSS fix quality.
Definition: gnss.h:135
int(* gnss_get_enabled_systems_t)(const struct device *dev, gnss_systems_t *systems)
API for getting enabled systems.
Definition: gnss.h:117
gnss_navigation_mode
GNSS navigation modes.
Definition: gnss.h:71
int gnss_get_navigation_mode(const struct device *dev, enum gnss_navigation_mode *mode)
Get the GNSS navigation mode.
int(* gnss_set_navigation_mode_t)(const struct device *dev, enum gnss_navigation_mode mode)
API for setting navigation mode.
Definition: gnss.h:83
int(* gnss_get_supported_systems_t)(const struct device *dev, gnss_systems_t *systems)
API for getting enabled systems.
Definition: gnss.h:120
@ GNSS_FIX_STATUS_ESTIMATED_FIX
Estimated fix acquired.
Definition: gnss.h:131
@ GNSS_FIX_STATUS_DGNSS_FIX
Differential GNSS fix acquired.
Definition: gnss.h:129
@ GNSS_FIX_STATUS_NO_FIX
No GNSS fix aqcuired.
Definition: gnss.h:125
@ GNSS_FIX_STATUS_GNSS_FIX
GNSS fix aqcuired.
Definition: gnss.h:127
@ GNSS_PPS_MODE_ENABLED_AFTER_LOCK
PPS output enabled from first lock.
Definition: gnss.h:38
@ GNSS_PPS_MODE_DISABLED
PPS output disabled.
Definition: gnss.h:34
@ GNSS_PPS_MODE_ENABLED
PPS output always enabled.
Definition: gnss.h:36
@ GNSS_PPS_MODE_ENABLED_WHILE_LOCKED
PPS output enabled while locked.
Definition: gnss.h:40
@ GNSS_SYSTEM_GALILEO
Galileo.
Definition: gnss.h:97
@ GNSS_SYSTEM_BEIDOU
BeiDou Navigation Satellite System.
Definition: gnss.h:99
@ GNSS_SYSTEM_SBAS
Satellite-Based Augmentation System (SBAS)
Definition: gnss.h:105
@ GNSS_SYSTEM_IMES
Indoor Messaging System (IMES)
Definition: gnss.h:107
@ GNSS_SYSTEM_GLONASS
GLObal NAvigation Satellite System (GLONASS)
Definition: gnss.h:95
@ GNSS_SYSTEM_IRNSS
Indian Regional Navigation Satellite System (IRNSS)
Definition: gnss.h:103
@ GNSS_SYSTEM_GPS
Global Positioning System (GPS)
Definition: gnss.h:93
@ GNSS_SYSTEM_QZSS
Quasi-Zenith Satellite System (QZSS)
Definition: gnss.h:101
@ GNSS_FIX_QUALITY_GNSS_SPS
Standard positioning service.
Definition: gnss.h:139
@ GNSS_FIX_QUALITY_RTK
Real-time kinematic.
Definition: gnss.h:145
@ GNSS_FIX_QUALITY_DGNSS
Differential GNSS.
Definition: gnss.h:141
@ GNSS_FIX_QUALITY_INVALID
Invalid fix.
Definition: gnss.h:137
@ GNSS_FIX_QUALITY_ESTIMATED
Estimated fix.
Definition: gnss.h:149
@ GNSS_FIX_QUALITY_GNSS_PPS
Precise positioning service.
Definition: gnss.h:143
@ GNSS_FIX_QUALITY_FLOAT_RTK
Floating real-time kinematic.
Definition: gnss.h:147
@ GNSS_NAVIGATION_MODE_HIGH_DYNAMICS
High dynamics have higher impact on tracking.
Definition: gnss.h:79
@ GNSS_NAVIGATION_MODE_ZERO_DYNAMICS
Dynamics have no impact on tracking.
Definition: gnss.h:73
@ GNSS_NAVIGATION_MODE_BALANCED_DYNAMICS
Low and high dynamics have equal impact on tracking.
Definition: gnss.h:77
@ GNSS_NAVIGATION_MODE_LOW_DYNAMICS
Low dynamics have higher impact on tracking.
Definition: gnss.h:75
#define BIT(n)
Unsigned integer with bit position n set (signed in assembly language).
Definition: util_macro.h:44
#define ENOSYS
Function not implemented.
Definition: errno.h:83
__UINT32_TYPE__ uint32_t
Definition: stdint.h:90
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:387
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:393
GNSS callback structure.
Definition: gnss.h:207
gnss_data_callback_t callback
Callback called when GNSS data is published.
Definition: gnss.h:211
const struct device * dev
Filter callback to GNSS data from this device if not NULL.
Definition: gnss.h:209
GNSS data structure.
Definition: gnss.h:194
struct navigation_data nav_data
Navigation data acquired.
Definition: gnss.h:196
struct gnss_info info
GNSS info when navigation data was acquired.
Definition: gnss.h:198
struct gnss_time utc
UTC time when data was acquired.
Definition: gnss.h:200
GNSS API structure.
Definition: gnss.h:181
gnss_set_fix_rate_t set_fix_rate
Definition: gnss.h:182
gnss_set_enabled_systems_t set_enabled_systems
Definition: gnss.h:188
gnss_set_periodic_config_t set_periodic_config
Definition: gnss.h:184
gnss_get_navigation_mode_t get_navigation_mode
Definition: gnss.h:187
gnss_set_navigation_mode_t set_navigation_mode
Definition: gnss.h:186
gnss_get_periodic_config_t get_periodic_config
Definition: gnss.h:185
gnss_get_enabled_systems_t get_enabled_systems
Definition: gnss.h:189
gnss_get_fix_rate_t get_fix_rate
Definition: gnss.h:183
gnss_get_supported_systems_t get_supported_systems
Definition: gnss.h:190
GNSS info data structure.
Definition: gnss.h:153
enum gnss_fix_quality fix_quality
The fix quality.
Definition: gnss.h:161
enum gnss_fix_status fix_status
The fix status.
Definition: gnss.h:159
uint16_t hdop
Horizontal dilution of precision in 1/1000.
Definition: gnss.h:157
uint16_t satellites_cnt
Number of satellites being tracked.
Definition: gnss.h:155
GNSS periodic tracking configuration.
Definition: gnss.h:55
uint32_t active_time_ms
The time the GNSS will spend in the active state in ms.
Definition: gnss.h:57
uint32_t inactive_time_ms
The time the GNSS will spend in the inactive state in ms.
Definition: gnss.h:59
GNSS satellite structure.
Definition: gnss.h:215
uint8_t prn
Pseudo-random noise sequence.
Definition: gnss.h:217
uint16_t azimuth
Azimuth relative to True North in degrees [0, 359].
Definition: gnss.h:223
uint8_t elevation
Elevation in degrees [0, 90].
Definition: gnss.h:221
uint8_t snr
Signal-to-noise ratio in dB.
Definition: gnss.h:219
enum gnss_system system
System of satellite.
Definition: gnss.h:225
uint8_t is_tracked
True if satellite is being tracked.
Definition: gnss.h:227
GNSS callback structure.
Definition: gnss.h:236
const struct device * dev
Filter callback to GNSS data from this device if not NULL.
Definition: gnss.h:238
gnss_satellites_callback_t callback
Callback called when GNSS satellites is published.
Definition: gnss.h:240
GNSS time data structure.
Definition: gnss.h:165
uint8_t month
Month [1, 12].
Definition: gnss.h:175
uint16_t millisecond
Millisecond [0, 59999].
Definition: gnss.h:171
uint8_t minute
Minute [0, 59].
Definition: gnss.h:169
uint8_t century_year
Year [0, 99].
Definition: gnss.h:177
uint8_t hour
Hour [0, 23].
Definition: gnss.h:167
uint8_t month_day
Day of month [1, 31].
Definition: gnss.h:173
Navigation data structure.
Definition: navigation.h:25