STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
gnss_core.h
Go to the documentation of this file.
1#ifndef STAR_GNSS_CORE_H
2#define STAR_GNSS_CORE_H
3
4/*
5 * MAX-M10S on UART9 as one state machine. Portable: bytes, baud changes and
6 * time are passed in / out, so gnss_task and the host tests run the same code.
7 *
8 * DETECT listen GNSS_LISTEN_US at each of 9600 (the module's default,
9 * data sheet p.13), 38400, 115200 for one valid NMEA/UBX frame
10 * CONFIG at 115200 (sent VALSET baud first if found lower): VALSET
11 * NMEA off, NAV-PVT on, 10 Hz, dynamic model AIR4; wait for
12 * UBX-ACK-ACK (GNSS_ACK_US, GNSS_CONFIG_TRIES tries)
13 * RUN every NAV-PVT -> REC_GNSS; none for GNSS_SILENCE_US -> DETECT
14 * on request (gnss_core_request_status): poll MON-RF (antenna)
15 * and NAV-SAT (satellites); the answers land in rf / sats
16 * Nothing is written to the module's flash: the RAM-layer config is re-sent
17 * after every power-up or silence.
18 */
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <stdint.h>
23
24#include "gnss_frame.h"
25#include "records.h"
26#include "ubx.h"
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32#define GNSS_RUN_BAUD 115200U
33#define GNSS_LISTEN_US 1500000U /* > one 1 Hz NMEA period */
34#define GNSS_ACK_US 500000U
35#define GNSS_CONFIG_TRIES 3U
36#define GNSS_SILENCE_US 2000000U
37#define GNSS_RATE_MS 100U /* 10 Hz NAV-PVT (data sheet p.4: up to 10 Hz) */
38
39typedef struct {
40 /* Blocking write of bytes to the module (returns when sent). */
41 void (*send)(void* ctx, const uint8_t* bytes, uint16_t len);
42 /* Re-open UART9 at this baud; received bytes after it are at the new
43 * rate. */
44 void (*set_baud)(void* ctx, uint32_t baud);
45 void* ctx;
46} gnss_io_t;
47
49
50typedef struct {
55 uint32_t baud;
56 uint8_t candidate; /* index into the DETECT baud list */
57 uint8_t tries;
58 uint32_t deadline_us;
59 uint32_t pps_us;
60 /* Counters */
61 uint32_t detected_baud; /* last baud a frame was heard at */
62 uint32_t fixes; /* NAV-PVT records produced */
63 uint32_t configs; /* configurations acknowledged */
64 uint32_t naks, resets; /* NAKs; returns to DETECT */
66 /* Receiver status, only filled when asked for (bench, bring-up) */
67 uint32_t rf_reports, sat_reports; /* answers decoded */
71
72/* io and sink set first. Opens UART9 at the first candidate baud. */
73void gnss_core_init(gnss_core_t* core, uint32_t now_us);
74
75/* Bytes received on UART9 (any amount, in order). */
76void gnss_core_feed(gnss_core_t* core, const uint8_t* bytes, size_t n,
77 uint32_t now_us);
78
79/* Deadlines: listen window, ACK timeout, silence. Call when woken. */
80void gnss_core_poll(gnss_core_t* core, uint32_t now_us);
81
82/* Latest GPS TIMEPULSE edge (board_time_last_pps), stamped into records. */
83void gnss_core_set_pps(gnss_core_t* core, uint32_t edge_us);
84
85/* Ask the module for MON-RF and NAV-SAT once. Only in RUN (the module is
86 * configured and at GNSS_RUN_BAUD); returns false otherwise. */
88
89/* Microseconds until the next deadline. */
90uint32_t gnss_core_wait_us(const gnss_core_t* core, uint32_t now_us);
91
92#ifdef __cplusplus
93}
94#endif
95#endif
void gnss_core_feed(gnss_core_t *core, const uint8_t *bytes, size_t n, uint32_t now_us)
Definition gnss_core.c:139
void gnss_core_poll(gnss_core_t *core, uint32_t now_us)
Definition gnss_core.c:149
gnss_state_t
Definition gnss_core.h:48
@ GNSS_CONFIG
Definition gnss_core.h:48
@ GNSS_DETECT
Definition gnss_core.h:48
@ GNSS_RUN
Definition gnss_core.h:48
void gnss_core_set_pps(gnss_core_t *core, uint32_t edge_us)
Definition gnss_core.c:60
uint32_t gnss_core_wait_us(const gnss_core_t *core, uint32_t now_us)
Definition gnss_core.c:183
void gnss_core_init(gnss_core_t *core, uint32_t now_us)
Definition gnss_core.c:53
bool gnss_core_request_status(gnss_core_t *core)
Definition gnss_core.c:171
static gnss_core_t core
Definition gnss_task.c:12
*brief user defined string literal for JSON values *sa std::size_t n
Definition json.hpp:24474
rec_gnss_t
Definition records.h:63
uint32_t sat_reports
Definition gnss_core.h:67
gnss_frame_parser_t parser
Definition gnss_core.h:53
ubx_rf_t rf
Definition gnss_core.h:68
uint32_t naks
Definition gnss_core.h:64
gnss_io_t io
Definition gnss_core.h:51
uint32_t fixes
Definition gnss_core.h:62
rec_gnss_t latest
Definition gnss_core.h:65
uint32_t detected_baud
Definition gnss_core.h:61
uint32_t configs
Definition gnss_core.h:63
uint8_t candidate
Definition gnss_core.h:56
gnss_state_t state
Definition gnss_core.h:54
uint32_t deadline_us
Definition gnss_core.h:58
uint32_t pps_us
Definition gnss_core.h:59
record_sink_t sink
Definition gnss_core.h:52
uint8_t tries
Definition gnss_core.h:57
uint32_t resets
Definition gnss_core.h:64
uint32_t rf_reports
Definition gnss_core.h:67
ubx_sats_t sats
Definition gnss_core.h:69
uint32_t baud
Definition gnss_core.h:55
void(* set_baud)(void *ctx, uint32_t baud)
Definition gnss_core.h:44
void * ctx
Definition gnss_core.h:45
void(* send)(void *ctx, const uint8_t *bytes, uint16_t len)
Definition gnss_core.h:41
Definition ubx.h:96