![]() |
no-OS
|
Implementation of GNSS Driver. More...
#include "nmea_ubx.h"#include <stdbool.h>#include <stdint.h>#include <string.h>#include <stdio.h>#include "no_os_util.h"#include "no_os_uart.h"#include "no_os_gpio.h"#include "no_os_irq.h"#include "no_os_delay.h"#include "no_os_alloc.h"#include "no_os_print_log.h"#include <stdlib.h>#include <errno.h>Functions | |
| void | gnss_calculate_checksum (uint8_t *data, uint16_t length, uint8_t *checksumA, uint8_t *checksumB) |
| Calculate UBX checksum. | |
| int | gnss_verify_checksum (uint8_t *data, uint16_t length, uint8_t checksumA, uint8_t checksumB) |
| Verify UBX checksum. | |
| int | gnss_init (struct gnss_dev **device, struct gnss_init_param init_param) |
| Initialize the GNSS device and configure communication. | |
| int | gnss_remove (struct gnss_dev *dev) |
| Remove the GNSS device and release allocated resources. | |
| int | gnss_hw_reset (struct gnss_dev *dev) |
| Reset the GNSS device using hardware reset pin. | |
| int | gnss_ubx_sw_reset (struct gnss_dev *dev) |
| Reset the device using SW reset. | |
| int | gnss_write (struct gnss_dev *dev, uint8_t *data, uint16_t size) |
| Write data to the device. | |
| int | gnss_read (struct gnss_dev *dev, uint8_t *data, uint16_t size) |
| Read data from the device. | |
| int | gnss_ubx_send_packet (struct gnss_dev *dev, uint8_t cls, uint8_t id, uint8_t *payload, uint16_t length) |
| Send UBX binary protocol packet to the GNSS device. | |
| int | gnss_ubx_receive_packet (struct gnss_dev *dev, struct gnss_ubx_packet *packet) |
| UBX packet receive. | |
| int | gnss_ubx_wait_for_ack (struct gnss_dev *dev, uint8_t cls, uint8_t id) |
| Wait for ACK/NAK. | |
| int | gnss_ubx_set_val_no_ack (struct gnss_dev *dev, uint32_t key_id, uint64_t value, uint8_t value_size, uint8_t layer) |
| Set configuration value by key (no ACK version) | |
| int | gnss_ubx_set_val (struct gnss_dev *dev, uint32_t key_id, uint64_t value, uint8_t value_size, uint8_t layer) |
| Set configuration value by key. | |
| int | gnss_ubx_get_val (struct gnss_dev *dev, uint32_t key_id, uint64_t *value, uint8_t value_size, uint8_t layer) |
| Get configuration value by key. | |
| int | gnss_ubx_clr_save_load_config (struct gnss_dev *dev, uint8_t mask) |
| Clear save load configuration from flash/BBR. | |
| int | gnss_ubx_set_input_protocol_uart1 (struct gnss_dev *dev, enum gnss_protocol protocol, uint8_t enable, uint8_t layer) |
| Configure input protocol on UART1. | |
| int | gnss_ubx_set_output_protocol_uart1 (struct gnss_dev *dev, enum gnss_protocol protocol, uint8_t enable, uint8_t layer) |
| Configure output protocol on UART1. | |
| int | gnss_ubx_set_output_protocol_usb (struct gnss_dev *dev, enum gnss_protocol protocol, uint8_t enable, uint8_t layer) |
| Configure output protocol USB. | |
| int | gnss_ubx_set_input_protocol_uart2 (struct gnss_dev *dev, enum gnss_protocol protocol, uint8_t enable, uint8_t layer) |
| Configure input protocol on UART2. | |
| int | gnss_ubx_set_output_protocol_uart2 (struct gnss_dev *dev, enum gnss_protocol protocol, uint8_t enable, uint8_t layer) |
| Configure output protocol on UART2. | |
| int | gnss_ubx_configure_baudrate (struct gnss_dev *dev, uint32_t baudrate) |
| Configure UBX device baudrate via UBX commands. | |
| int | gnss_ubx_poll_nav_pvt (struct gnss_dev *dev, struct gnss_ubx_nav_pvt *nav_data) |
| Poll navigation data (NAV-PVT) | |
| int | gnss_ubx_poll_nav_timeutc (struct gnss_dev *dev, struct gnss_ubx_nav_timeutc *time_data) |
| Poll time data (NAV-TIMEUTC) | |
| int | gnss_get_nav_data (struct gnss_dev *dev, struct gnss_ubx_nav_pvt *nav_data) |
| Get latest navigation data. | |
| int | gnss_get_time_data (struct gnss_dev *dev, struct gnss_ubx_nav_timeutc *time_data) |
| Get latest time data. | |
| float | gnss_coord_to_degrees (int32_t coord) |
| Convert coordinates from 1e-7 degrees to float degrees. | |
| float | gnss_velocity_to_ms (int32_t vel) |
| Convert velocity from cm/s to m/s. | |
| float | gnss_time_acc_to_ms (uint32_t acc) |
| Convert time accuracy from ns to ms. | |
| float | gnss_pos_acc_to_m (uint32_t acc) |
| Convert position accuracy from mm to m. | |
| int32_t | gnss_ubx_get_nanoseconds (struct gnss_dev *dev) |
| Get nanosecond fraction of current time from NAV-PVT data. | |
| int | gnss_ubx_get_time_valid (struct gnss_dev *dev, bool *valid) |
| Check if the current time is valid. | |
| int | gnss_ubx_get_time_fully_resolved (struct gnss_dev *dev, bool *resolved) |
| Check if the current time is fully resolved. | |
| uint32_t | gnss_calculate_unix_epoch (uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second) |
| Calculate Unix epoch from date/time components. | |
| int | gnss_ubx_get_unix_epoch_with_micros (struct gnss_dev *dev, uint32_t *epoch, uint32_t *microseconds) |
| Get Unix epoch time with microsecond precision. | |
| int | gnss_ubx_get_precise_time (struct gnss_dev *dev, struct gnss_precise_time *precise_time) |
| Get comprehensive precise time information. | |
| int | gnss_ubx_configure_time_pulse (struct gnss_dev *dev, bool enable) |
| Configure time pulse output for PPS (Pulse Per Second) | |
| int | gnss_init_pps (struct gnss_dev *dev, bool enable) |
| Configure PPS output with optimal settings for timing sync. | |
| int | gnss_ubx_is_time_pulse_enabled (struct gnss_dev *dev, bool *enabled) |
| Check if time pulse is currently enabled. | |
| int | gnss_configure_baudrate_via_nmea (struct gnss_dev *dev, uint32_t baudrate) |
| Configure baudrate via standard NMEA command for NMEA-only devices. | |
| int | gnss_configure_messages_via_nmea (struct gnss_dev *dev, uint8_t rate_hz) |
| Enable GPRMC/GNRMC message and disable others for clean timing via NMEA commands. | |
| int | gnss_configure_nmea_device (struct gnss_dev *dev, uint32_t baudrate, uint8_t message_rate_hz) |
| Configure NMEA-only device for timing operation. | |
| int | gnss_parse_gprmc_sentence (const char *sentence, struct gnss_nmea_time *rmc_time) |
| Parse GPRMC sentence for time and date information. | |
| int | gnss_get_nmea_timing_data (struct gnss_dev *dev, struct gnss_nmea_time *rmc_time) |
| Get timing data from NMEA-only device via GPRMC parsing. | |
| int | gnss_refresh_timing_data (struct gnss_dev *dev) |
| Refresh timing data from device (unified API for both UBX and NMEA devices) | |
| int | gnss_get_unified_timing (struct gnss_dev *dev, struct gnss_precise_time *precise_time) |
| Get comprehensive timing information (unified API for both device types) | |
| int | gnss_is_timing_valid (struct gnss_dev *dev, bool *valid) |
| Check if timing data is valid (unified API for both device types) | |
| int | gnss_get_unix_epoch_unified (struct gnss_dev *dev, uint32_t *epoch, uint32_t *fractional_seconds) |
| Get Unix epoch time with best available precision (unified API) | |
| int | gnss_parse_gpgga_sentence (const char *sentence, struct gnss_nmea_position *position_data) |
| Parse GPGGA sentence for position and fix information. | |
| int | gnss_get_nmea_position_data (struct gnss_dev *dev, struct gnss_nmea_position *position_data) |
| Get GPS fix quality and position data (NMEA-only devices) | |
Implementation of GNSS Driver.
Copyright 2025(c) Analog Devices, Inc.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES, INC. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANALOG DEVICES, INC. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
| void gnss_calculate_checksum | ( | uint8_t * | data, |
| uint16_t | length, | ||
| uint8_t * | checksumA, | ||
| uint8_t * | checksumB ) |
Calculate UBX checksum.
| data | - Data buffer |
| length | - Data length |
| checksumA | - Checksum A output |
| checksumB | - Checksum B output |
| uint32_t gnss_calculate_unix_epoch | ( | uint16_t | year, |
| uint8_t | month, | ||
| uint8_t | day, | ||
| uint8_t | hour, | ||
| uint8_t | minute, | ||
| uint8_t | second ) |
Calculate Unix epoch from date/time components.
| year | - Year (must be >= 1970) |
| month | - Month (1-12) |
| day | - Day of month |
| hour | - Hour (0-23) |
| minute | - Minute (0-59) |
| second | - Second (0-59) |
| int gnss_configure_baudrate_via_nmea | ( | struct gnss_dev * | dev, |
| uint32_t | baudrate ) |
Configure baudrate via standard NMEA command for NMEA-only devices.
| dev | - The device structure |
| baudrate | - Desired baudrate |
| int gnss_configure_messages_via_nmea | ( | struct gnss_dev * | dev, |
| uint8_t | rate_hz ) |
Enable GPRMC/GNRMC message and disable others for clean timing via NMEA commands.
| dev | - The device structure |
| rate_hz | - GPRMC/GNRMC message rate in Hz (typically 1) |
| int gnss_configure_nmea_device | ( | struct gnss_dev * | dev, |
| uint32_t | baudrate, | ||
| uint8_t | message_rate_hz ) |
Configure NMEA-only device for timing operation.
| dev | - The device structure |
| baudrate | - Desired baudrate |
| message_rate_hz | - GPRMC message rate |
| float gnss_coord_to_degrees | ( | int32_t | coord | ) |
Convert coordinates from 1e-7 degrees to float degrees.
| coord | - Coordinate in 1e-7 degrees |
| int gnss_get_nav_data | ( | struct gnss_dev * | dev, |
| struct gnss_ubx_nav_pvt * | nav_data ) |
Get latest navigation data.
| dev | - The device structure |
| nav_data | - Navigation data structure to fill |
| int gnss_get_nmea_position_data | ( | struct gnss_dev * | dev, |
| struct gnss_nmea_position * | position_data ) |
Get GPS fix quality and position data (NMEA-only devices)
| dev | - The device structure |
| position_data | - Output structure for position data |
| int gnss_get_nmea_timing_data | ( | struct gnss_dev * | dev, |
| struct gnss_nmea_time * | rmc_time ) |
Get timing data from NMEA-only device via GPRMC parsing.
| dev | - The device structure |
| rmc_time | - Output structure for time data |
| int gnss_get_time_data | ( | struct gnss_dev * | dev, |
| struct gnss_ubx_nav_timeutc * | time_data ) |
Get latest time data.
| dev | - The device structure |
| time_data | - Time data structure to fill |
| int gnss_get_unified_timing | ( | struct gnss_dev * | dev, |
| struct gnss_precise_time * | precise_time ) |
Get comprehensive timing information (unified API for both device types)
| dev | - The device structure |
| precise_time | - Structure to store precise time data |
| int gnss_get_unix_epoch_unified | ( | struct gnss_dev * | dev, |
| uint32_t * | epoch, | ||
| uint32_t * | fractional_seconds ) |
Get Unix epoch time with best available precision (unified API)
| dev | - The device structure |
| epoch | - Pointer to store Unix epoch time in seconds |
| fractional_seconds | - Pointer to store fractional seconds (microseconds) |
| int gnss_hw_reset | ( | struct gnss_dev * | dev | ) |
Reset the GNSS device using hardware reset pin.
| dev | - The device structure. |
| int gnss_init | ( | struct gnss_dev ** | device, |
| struct gnss_init_param | init_param ) |
Initialize the GNSS device and configure communication.
| device | - The device structure. |
| init_param | - The structure that contains the device initial parameters. |
Configure PPS output with optimal settings for timing sync.
| dev | - The device structure |
| enable | - Enable/disable PPS output |
Check if timing data is valid (unified API for both device types)
| dev | - The device structure |
| valid | - Pointer to store validity status |
| int gnss_parse_gpgga_sentence | ( | const char * | sentence, |
| struct gnss_nmea_position * | position_data ) |
Parse GPGGA sentence for position and fix information.
| sentence | - Complete GPGGA sentence string |
| position_data | - Output structure for parsed position data |
| int gnss_parse_gprmc_sentence | ( | const char * | sentence, |
| struct gnss_nmea_time * | rmc_time ) |
Parse GPRMC sentence for time and date information.
| sentence | - Complete GPRMC sentence string |
| rmc_time | - Output structure for parsed time data |
| float gnss_pos_acc_to_m | ( | uint32_t | acc | ) |
Convert position accuracy from mm to m.
| acc | - Position accuracy in mm |
| int gnss_read | ( | struct gnss_dev * | dev, |
| uint8_t * | data, | ||
| uint16_t | size ) |
Read data from the device.
| dev | - The device structure |
| data | - Data buffer to read into |
| size | - Number of bytes to read |
| int gnss_refresh_timing_data | ( | struct gnss_dev * | dev | ) |
Refresh timing data from device (unified API for both UBX and NMEA devices)
| dev | - The device structure |
| int gnss_remove | ( | struct gnss_dev * | dev | ) |
Remove the GNSS device and release allocated resources.
| dev | - The device structure. |
| float gnss_time_acc_to_ms | ( | uint32_t | acc | ) |
Convert time accuracy from ns to ms.
| acc | - Time accuracy in ns |
| int gnss_ubx_clr_save_load_config | ( | struct gnss_dev * | dev, |
| uint8_t | mask ) |
Clear save load configuration from flash/BBR.
| dev | - The device structure |
| mask | - Load mask (which layers to load) |
| int gnss_ubx_configure_baudrate | ( | struct gnss_dev * | dev, |
| uint32_t | baudrate ) |
Configure UBX device baudrate via UBX commands.
| dev | - The device structure |
| baudrate | - Desired baudrate |
Configure time pulse output for PPS (Pulse Per Second)
| dev | - The device structure |
| enable | - Enable/disable time pulse |
| int32_t gnss_ubx_get_nanoseconds | ( | struct gnss_dev * | dev | ) |
Get nanosecond fraction of current time from NAV-PVT data.
| dev | - The device structure |
| int gnss_ubx_get_precise_time | ( | struct gnss_dev * | dev, |
| struct gnss_precise_time * | precise_time ) |
Get comprehensive precise time information.
| dev | - The device structure |
| precise_time | - Structure to store precise time data |
Check if the current time is fully resolved.
| dev | - The device structure |
| resolved | - Pointer to store resolved status |
Check if the current time is valid.
| dev | - The device structure |
| valid | - Pointer to store validity status |
| int gnss_ubx_get_unix_epoch_with_micros | ( | struct gnss_dev * | dev, |
| uint32_t * | epoch, | ||
| uint32_t * | microseconds ) |
Get Unix epoch time with microsecond precision.
| dev | - The device structure |
| epoch | - Pointer to store Unix epoch time in seconds |
| microseconds | - Pointer to store microsecond fraction |
| int gnss_ubx_get_val | ( | struct gnss_dev * | dev, |
| uint32_t | key_id, | ||
| uint64_t * | value, | ||
| uint8_t | value_size, | ||
| uint8_t | layer ) |
Get configuration value by key.
| dev | - The device structure |
| key_id | - Configuration key ID |
| value | - Pointer to store the value |
| value_size | - Size of value (1, 2, 4, or 8 bytes) |
| layer | - Configuration layer (RAM, BBR, Flash) |
Check if time pulse is currently enabled.
| dev | - The device structure |
| enabled | - Pointer to store enabled status |
| int gnss_ubx_poll_nav_pvt | ( | struct gnss_dev * | dev, |
| struct gnss_ubx_nav_pvt * | nav_data ) |
Poll navigation data (NAV-PVT)
| dev | - The device structure |
| nav_data | - Navigation data structure to fill |
| int gnss_ubx_poll_nav_timeutc | ( | struct gnss_dev * | dev, |
| struct gnss_ubx_nav_timeutc * | time_data ) |
Poll time data (NAV-TIMEUTC)
| dev | - The device structure |
| time_data | - Time data structure to fill |
| int gnss_ubx_receive_packet | ( | struct gnss_dev * | dev, |
| struct gnss_ubx_packet * | packet ) |
UBX packet receive.
| dev | - The device structure |
| packet | - Packet structure to fill |
| int gnss_ubx_send_packet | ( | struct gnss_dev * | dev, |
| uint8_t | cls, | ||
| uint8_t | id, | ||
| uint8_t * | payload, | ||
| uint16_t | length ) |
Send UBX binary protocol packet to the GNSS device.
| dev | - The device structure. |
| cls | - UBX message class. |
| id | - UBX message ID. |
| payload | - Pointer to payload data buffer. |
| length | - Payload length in bytes. |
| int gnss_ubx_set_input_protocol_uart1 | ( | struct gnss_dev * | dev, |
| enum gnss_protocol | protocol, | ||
| uint8_t | enable, | ||
| uint8_t | layer ) |
Configure input protocol on UART1.
| dev | - The device structure |
| protocol | - Protocol type |
| enable | - Enable/disable |
| layer | - Configuration layer |
| int gnss_ubx_set_input_protocol_uart2 | ( | struct gnss_dev * | dev, |
| enum gnss_protocol | protocol, | ||
| uint8_t | enable, | ||
| uint8_t | layer ) |
Configure input protocol on UART2.
| dev | - The device structure |
| protocol | - Protocol type |
| enable | - Enable/disable |
| layer | - Configuration layer |
| int gnss_ubx_set_output_protocol_uart1 | ( | struct gnss_dev * | dev, |
| enum gnss_protocol | protocol, | ||
| uint8_t | enable, | ||
| uint8_t | layer ) |
Configure output protocol on UART1.
| dev | - The device structure |
| protocol | - Protocol type |
| enable | - Enable/disable |
| layer | - Configuration layer |
| int gnss_ubx_set_output_protocol_uart2 | ( | struct gnss_dev * | dev, |
| enum gnss_protocol | protocol, | ||
| uint8_t | enable, | ||
| uint8_t | layer ) |
Configure output protocol on UART2.
| dev | - The device structure |
| protocol | - Protocol type |
| enable | - Enable/disable |
| layer | - Configuration layer |
| int gnss_ubx_set_output_protocol_usb | ( | struct gnss_dev * | dev, |
| enum gnss_protocol | protocol, | ||
| uint8_t | enable, | ||
| uint8_t | layer ) |
Configure output protocol USB.
| dev | - The device structure |
| protocol | - Protocol type |
| enable | - Enable/disable |
| layer | - Configuration layer |
| int gnss_ubx_set_val | ( | struct gnss_dev * | dev, |
| uint32_t | key_id, | ||
| uint64_t | value, | ||
| uint8_t | value_size, | ||
| uint8_t | layer ) |
Set configuration value by key.
| dev | - The device structure |
| key_id | - Configuration key ID |
| value | - Value to set |
| value_size | - Size of value (1, 2, 4, or 8 bytes) |
| layer | - Configuration layer (RAM, BBR, Flash) |
| int gnss_ubx_set_val_no_ack | ( | struct gnss_dev * | dev, |
| uint32_t | key_id, | ||
| uint64_t | value, | ||
| uint8_t | value_size, | ||
| uint8_t | layer ) |
Set configuration value by key (no ACK version)
| dev | - The device structure |
| key_id | - Configuration key ID |
| value | - Value to set |
| value_size | - Size of value (1, 2, 4, or 8 bytes) |
| layer | - Configuration layer (RAM, BBR, Flash) |
| int gnss_ubx_sw_reset | ( | struct gnss_dev * | dev | ) |
Reset the device using SW reset.
| dev | - The device structure |
| int gnss_ubx_wait_for_ack | ( | struct gnss_dev * | dev, |
| uint8_t | cls, | ||
| uint8_t | id ) |
Wait for ACK/NAK.
| dev | - The device structure |
| cls | - Expected class |
| id | - Expected message ID |
| float gnss_velocity_to_ms | ( | int32_t | vel | ) |
Convert velocity from cm/s to m/s.
| vel | - Velocity in cm/s |
| int gnss_verify_checksum | ( | uint8_t * | data, |
| uint16_t | length, | ||
| uint8_t | checksumA, | ||
| uint8_t | checksumB ) |
Verify UBX checksum.
| data | - Data buffer |
| length | - Data length |
| checksumA | - Expected checksum A |
| checksumB | - Expected checksum B |
| int gnss_write | ( | struct gnss_dev * | dev, |
| uint8_t * | data, | ||
| uint16_t | size ) |
Write data to the device.
| dev | - The device structure |
| data | - Data buffer to write |
| size | - Number of bytes to write |