Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
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
13#ifndef ZEPHYR_INCLUDE_DRIVERS_GNSS_H_
14#define ZEPHYR_INCLUDE_DRIVERS_GNSS_H_
15
24
25#include <zephyr/kernel.h>
26#include <zephyr/types.h>
27#include <zephyr/device.h>
29#include <errno.h>
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
44
56
57
58
70
71
72
92
95
96
97
109
127
141
157
162
164typedef int (*gnss_start_t)(const struct device *dev, enum gnss_start_mode mode);
165
167typedef int (*gnss_stop_t)(const struct device *dev);
168
170typedef int (*gnss_set_fix_rate_t)(const struct device *dev, uint32_t fix_interval_ms);
171
173typedef int (*gnss_get_fix_rate_t)(const struct device *dev, uint32_t *fix_interval_ms);
174
176typedef int (*gnss_set_navigation_mode_t)(const struct device *dev,
177 enum gnss_navigation_mode mode);
178
180typedef int (*gnss_get_navigation_mode_t)(const struct device *dev,
181 enum gnss_navigation_mode *mode);
182
184typedef int (*gnss_set_enabled_systems_t)(const struct device *dev, gnss_systems_t systems);
185
187typedef int (*gnss_get_enabled_systems_t)(const struct device *dev, gnss_systems_t *systems);
188
190typedef int (*gnss_get_supported_systems_t)(const struct device *dev, gnss_systems_t *systems);
191
193typedef int (*gnss_get_latest_timepulse_t)(const struct device *dev, k_ticks_t *timestamp);
194
240
243
253
255typedef void (*gnss_data_callback_t)(const struct device *dev, const struct gnss_data *data);
256
264
282
284typedef void (*gnss_satellites_callback_t)(const struct device *dev,
285 const struct gnss_satellite *satellites,
286 uint16_t size);
287
295
312__syscall int gnss_start(const struct device *dev, enum gnss_start_mode mode);
313
314static inline int z_impl_gnss_start(const struct device *dev, enum gnss_start_mode mode)
315{
316 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
317
318 if (api->start == NULL) {
319 return -ENOSYS;
320 }
321
322 return api->start(dev, mode);
323}
324
338__syscall int gnss_stop(const struct device *dev);
339
340static inline int z_impl_gnss_stop(const struct device *dev)
341{
342 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
343
344 if (api->stop == NULL) {
345 return -ENOSYS;
346 }
347
348 return api->stop(dev);
349}
350
360__syscall int gnss_set_fix_rate(const struct device *dev, uint32_t fix_interval_ms);
361
362static inline int z_impl_gnss_set_fix_rate(const struct device *dev, uint32_t fix_interval_ms)
363{
364 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
365
366 if (api->set_fix_rate == NULL) {
367 return -ENOSYS;
368 }
369
370 return api->set_fix_rate(dev, fix_interval_ms);
371}
372
382__syscall int gnss_get_fix_rate(const struct device *dev, uint32_t *fix_interval_ms);
383
384static inline int z_impl_gnss_get_fix_rate(const struct device *dev, uint32_t *fix_interval_ms)
385{
386 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
387
388 if (api->get_fix_rate == NULL) {
389 return -ENOSYS;
390 }
391
392 return api->get_fix_rate(dev, fix_interval_ms);
393}
394
404__syscall int gnss_set_navigation_mode(const struct device *dev,
405 enum gnss_navigation_mode mode);
406
407static inline int z_impl_gnss_set_navigation_mode(const struct device *dev,
408 enum gnss_navigation_mode mode)
409{
410 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
411
412 if (api->set_navigation_mode == NULL) {
413 return -ENOSYS;
414 }
415
416 return api->set_navigation_mode(dev, mode);
417}
418
428__syscall int gnss_get_navigation_mode(const struct device *dev,
429 enum gnss_navigation_mode *mode);
430
431static inline int z_impl_gnss_get_navigation_mode(const struct device *dev,
432 enum gnss_navigation_mode *mode)
433{
434 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
435
436 if (api->get_navigation_mode == NULL) {
437 return -ENOSYS;
438 }
439
440 return api->get_navigation_mode(dev, mode);
441}
442
452__syscall int gnss_set_enabled_systems(const struct device *dev, gnss_systems_t systems);
453
454static inline int z_impl_gnss_set_enabled_systems(const struct device *dev,
455 gnss_systems_t systems)
456{
457 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
458
459 if (api->set_enabled_systems == NULL) {
460 return -ENOSYS;
461 }
462
463 return api->set_enabled_systems(dev, systems);
464}
465
475__syscall int gnss_get_enabled_systems(const struct device *dev, gnss_systems_t *systems);
476
477static inline int z_impl_gnss_get_enabled_systems(const struct device *dev,
478 gnss_systems_t *systems)
479{
480 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
481
482 if (api->get_enabled_systems == NULL) {
483 return -ENOSYS;
484 }
485
486 return api->get_enabled_systems(dev, systems);
487}
488
498__syscall int gnss_get_supported_systems(const struct device *dev, gnss_systems_t *systems);
499
500static inline int z_impl_gnss_get_supported_systems(const struct device *dev,
501 gnss_systems_t *systems)
502{
503 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
504
505 if (api->get_supported_systems == NULL) {
506 return -ENOSYS;
507 }
508
509 return api->get_supported_systems(dev, systems);
510}
511
525__syscall int gnss_get_latest_timepulse(const struct device *dev, k_ticks_t *timestamp);
526
527static inline int z_impl_gnss_get_latest_timepulse(const struct device *dev,
528 k_ticks_t *timestamp)
529{
530 const struct gnss_driver_api *api = DEVICE_API_GET(gnss, dev);
531
532 if (api->get_latest_timepulse == NULL) {
533 return -ENOSYS;
534 }
535
536 return api->get_latest_timepulse(dev, timestamp);
537}
538
545#if CONFIG_GNSS
546#define GNSS_DATA_CALLBACK_DEFINE(_dev, _callback) \
547 static const STRUCT_SECTION_ITERABLE(gnss_data_callback, \
548 _gnss_data_callback__##_callback) = { \
549 .dev = _dev, \
550 .callback = _callback, \
551 }
552
559#define GNSS_DT_DATA_CALLBACK_DEFINE(_node_id, _callback) \
560 static const STRUCT_SECTION_ITERABLE( \
561 gnss_data_callback, \
562 CONCAT(_gnss_data_callback_, DT_DEP_ORD(_node_id), _, _callback)) = { \
563 .dev = DEVICE_DT_GET(_node_id), \
564 .callback = _callback, \
565 }
566#else
567#define GNSS_DATA_CALLBACK_DEFINE(_dev, _callback)
568#define GNSS_DT_DATA_CALLBACK_DEFINE(_node_id, _callback)
569#endif
570
577#if CONFIG_GNSS_SATELLITES
578#define GNSS_SATELLITES_CALLBACK_DEFINE(_dev, _callback) \
579 static const STRUCT_SECTION_ITERABLE(gnss_satellites_callback, \
580 _gnss_satellites_callback__##_callback) = { \
581 .dev = _dev, \
582 .callback = _callback, \
583 }
584
591#define GNSS_DT_SATELLITES_CALLBACK_DEFINE(_node_id, _callback) \
592 static const STRUCT_SECTION_ITERABLE( \
593 gnss_satellites_callback, \
594 CONCAT(_gnss_satellites_callback_, DT_DEP_ORD(_node_id), _, _callback)) = { \
595 .dev = DEVICE_DT_GET(_node_id), \
596 .callback = _callback, \
597 }
598#else
599#define GNSS_SATELLITES_CALLBACK_DEFINE(_dev, _callback)
600#define GNSS_DT_SATELLITES_CALLBACK_DEFINE(_node_id, _callback)
601#endif
602
606
607#ifdef __cplusplus
608}
609#endif
610
611#include <zephyr/syscalls/gnss.h>
612
613#endif /* ZEPHYR_INCLUDE_DRIVERS_GNSS_H_ */
APIs and macros for the Zephyr device model.
#define DEVICE_API_GET(_class, _dev)
Expands to the pointer of a device's API for a given class.
Definition device.h:1486
System error numbers.
uint32_t k_ticks_t
Tick precision used in timeout APIs.
Definition clock.h:48
void(* gnss_data_callback_t)(const struct device *dev, const struct gnss_data *data)
Template for GNSS data callback.
Definition gnss.h:255
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:99
int gnss_set_fix_rate(const struct device *dev, uint32_t fix_interval_ms)
Set the GNSS fix rate.
gnss_pps_mode
GNSS PPS modes.
Definition gnss.h:46
int gnss_stop(const struct device *dev)
Stop the GNSS receiver engine.
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:173
int gnss_start(const struct device *dev, enum gnss_start_mode mode)
Start the GNSS receiver engine.
gnss_start_mode
GNSS receiver start modes.
Definition gnss.h:36
uint32_t gnss_systems_t
Type storing bitmask of GNSS systems.
Definition gnss.h:94
int(* gnss_set_fix_rate_t)(const struct device *dev, uint32_t fix_interval_ms)
API for setting fix rate.
Definition gnss.h:170
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:284
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_get_latest_timepulse(const struct device *dev, k_ticks_t *timestamp)
Get the timestamp of the latest PPS timepulse.
int(* gnss_start_t)(const struct device *dev, enum gnss_start_mode mode)
@def_driverbackendgroup{GNSS,gnss_interface}
Definition gnss.h:164
int(* gnss_stop_t)(const struct device *dev)
API for stopping the GNSS receiver engine.
Definition gnss.h:167
int(* gnss_set_enabled_systems_t)(const struct device *dev, gnss_systems_t systems)
API for enabling systems.
Definition gnss.h:184
gnss_system
Systems contained in gnss_systems_t.
Definition gnss.h:74
int(* gnss_get_navigation_mode_t)(const struct device *dev, enum gnss_navigation_mode *mode)
API for getting navigation mode.
Definition gnss.h:180
int gnss_set_navigation_mode(const struct device *dev, enum gnss_navigation_mode mode)
Set the GNSS navigation mode.
int(* gnss_get_latest_timepulse_t)(const struct device *dev, k_ticks_t *timestamp)
API for getting timestamp of last PPS pulse.
Definition gnss.h:193
gnss_fix_quality
GNSS fix quality.
Definition gnss.h:111
int(* gnss_get_enabled_systems_t)(const struct device *dev, gnss_systems_t *systems)
API for getting enabled systems.
Definition gnss.h:187
gnss_navigation_mode
GNSS navigation modes.
Definition gnss.h:60
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:176
int(* gnss_get_supported_systems_t)(const struct device *dev, gnss_systems_t *systems)
API for getting enabled systems.
Definition gnss.h:190
@ GNSS_FIX_STATUS_ESTIMATED_FIX
Estimated fix acquired.
Definition gnss.h:107
@ GNSS_FIX_STATUS_DGNSS_FIX
Differential GNSS fix acquired.
Definition gnss.h:105
@ GNSS_FIX_STATUS_NO_FIX
No GNSS fix acquired.
Definition gnss.h:101
@ GNSS_FIX_STATUS_GNSS_FIX
GNSS fix acquired.
Definition gnss.h:103
@ GNSS_PPS_MODE_ENABLED_AFTER_LOCK
PPS output enabled from first lock.
Definition gnss.h:52
@ GNSS_PPS_MODE_DISABLED
PPS output disabled.
Definition gnss.h:48
@ GNSS_PPS_MODE_ENABLED
PPS output always enabled.
Definition gnss.h:50
@ GNSS_PPS_MODE_ENABLED_WHILE_LOCKED
PPS output enabled while locked.
Definition gnss.h:54
@ GNSS_HOT_START
Restart with all navigation data preserved (fastest TTFF).
Definition gnss.h:38
@ GNSS_WARM_START
Restart clearing ephemeris; almanac and position are retained.
Definition gnss.h:40
@ GNSS_COLD_START
Restart clearing all navigation data (longest TTFF).
Definition gnss.h:42
@ GNSS_SYSTEM_GALILEO
Galileo.
Definition gnss.h:80
@ GNSS_SYSTEM_BEIDOU
BeiDou Navigation Satellite System.
Definition gnss.h:82
@ GNSS_SYSTEM_SBAS
Satellite-Based Augmentation System (SBAS).
Definition gnss.h:88
@ GNSS_SYSTEM_IMES
Indoor Messaging System (IMES).
Definition gnss.h:90
@ GNSS_SYSTEM_GLONASS
GLObal NAvigation Satellite System (GLONASS).
Definition gnss.h:78
@ GNSS_SYSTEM_IRNSS
Indian Regional Navigation Satellite System (IRNSS).
Definition gnss.h:86
@ GNSS_SYSTEM_GPS
Global Positioning System (GPS).
Definition gnss.h:76
@ GNSS_SYSTEM_QZSS
Quasi-Zenith Satellite System (QZSS).
Definition gnss.h:84
@ GNSS_FIX_QUALITY_GNSS_SPS
Standard positioning service.
Definition gnss.h:115
@ GNSS_FIX_QUALITY_RTK
Real-time kinematic.
Definition gnss.h:121
@ GNSS_FIX_QUALITY_DGNSS
Differential GNSS.
Definition gnss.h:117
@ GNSS_FIX_QUALITY_INVALID
Invalid fix.
Definition gnss.h:113
@ GNSS_FIX_QUALITY_ESTIMATED
Estimated fix.
Definition gnss.h:125
@ GNSS_FIX_QUALITY_GNSS_PPS
Precise positioning service.
Definition gnss.h:119
@ GNSS_FIX_QUALITY_FLOAT_RTK
Floating real-time kinematic.
Definition gnss.h:123
@ GNSS_NAVIGATION_MODE_HIGH_DYNAMICS
High dynamics have higher impact on tracking.
Definition gnss.h:68
@ GNSS_NAVIGATION_MODE_ZERO_DYNAMICS
Dynamics have no impact on tracking.
Definition gnss.h:62
@ GNSS_NAVIGATION_MODE_BALANCED_DYNAMICS
Low and high dynamics have equal impact on tracking.
Definition gnss.h:66
@ GNSS_NAVIGATION_MODE_LOW_DYNAMICS
Low dynamics have higher impact on tracking.
Definition gnss.h:64
#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
#define NULL
Definition iar_missing_defs.h:20
Public kernel APIs.
Header file for navigation data structures.
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__INT32_TYPE__ int32_t
Definition stdint.h:74
__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:543
GNSS callback structure.
Definition gnss.h:258
gnss_data_callback_t callback
Callback called when GNSS data is published.
Definition gnss.h:262
const struct device * dev
Filter callback to GNSS data from this device if not NULL.
Definition gnss.h:260
GNSS data structure.
Definition gnss.h:245
struct navigation_data nav_data
Navigation data acquired.
Definition gnss.h:247
struct gnss_info info
GNSS info when navigation data was acquired.
Definition gnss.h:249
struct gnss_time utc
UTC time when data was acquired.
Definition gnss.h:251
@driver_ops{GNSS}
Definition gnss.h:198
gnss_set_fix_rate_t set_fix_rate
@driver_ops_optional Set the GNSS fix rate.
Definition gnss.h:210
gnss_set_enabled_systems_t set_enabled_systems
@driver_ops_optional Set enabled GNSS systems.
Definition gnss.h:226
gnss_get_latest_timepulse_t get_latest_timepulse
@driver_ops_optional Get the timestamp of the latest PPS timepulse.
Definition gnss.h:238
gnss_start_t start
@driver_ops_optional Start the GNSS receiver engine.
Definition gnss.h:202
gnss_get_navigation_mode_t get_navigation_mode
@driver_ops_optional Get the GNSS navigation mode.
Definition gnss.h:222
gnss_set_navigation_mode_t set_navigation_mode
@driver_ops_optional Set the GNSS navigation mode.
Definition gnss.h:218
gnss_get_enabled_systems_t get_enabled_systems
@driver_ops_optional Get enabled GNSS systems.
Definition gnss.h:230
gnss_get_fix_rate_t get_fix_rate
@driver_ops_optional Get the GNSS fix rate.
Definition gnss.h:214
gnss_stop_t stop
@driver_ops_optional Stop the GNSS receiver engine.
Definition gnss.h:206
gnss_get_supported_systems_t get_supported_systems
@driver_ops_optional Get supported GNSS systems.
Definition gnss.h:234
GNSS info data structure.
Definition gnss.h:129
enum gnss_fix_quality fix_quality
The fix quality.
Definition gnss.h:139
uint32_t hdop
Horizontal dilution of precision in 1/1000.
Definition gnss.h:133
int32_t geoid_separation
Geoid separation in millimeters.
Definition gnss.h:135
enum gnss_fix_status fix_status
The fix status.
Definition gnss.h:137
uint16_t satellites_cnt
Number of satellites being tracked.
Definition gnss.h:131
GNSS satellite structure.
Definition gnss.h:266
uint8_t prn
Pseudo-random noise sequence.
Definition gnss.h:268
uint16_t azimuth
Azimuth relative to True North in degrees [0, 359].
Definition gnss.h:274
uint8_t elevation
Elevation in degrees [0, 90].
Definition gnss.h:272
uint8_t is_corrected
True if satellite tracking has RTK corrections.
Definition gnss.h:280
uint8_t snr
Signal-to-noise ratio in dB.
Definition gnss.h:270
enum gnss_system system
System of satellite.
Definition gnss.h:276
uint8_t is_tracked
True if satellite is being tracked.
Definition gnss.h:278
GNSS callback structure.
Definition gnss.h:289
const struct device * dev
Filter callback to GNSS data from this device if not NULL.
Definition gnss.h:291
gnss_satellites_callback_t callback
Callback called when GNSS satellites is published.
Definition gnss.h:293
GNSS time data structure.
Definition gnss.h:143
uint8_t month
Month [1, 12].
Definition gnss.h:153
uint16_t millisecond
Millisecond [0, 60999].
Definition gnss.h:149
uint8_t minute
Minute [0, 59].
Definition gnss.h:147
uint8_t century_year
Year [0, 99].
Definition gnss.h:155
uint8_t hour
Hour [0, 23].
Definition gnss.h:145
uint8_t month_day
Day of month [1, 31].
Definition gnss.h:151
Navigation data structure.
Definition navigation.h:31