STAR
Cal STAR — firmware, DAQ server, and engine design
Loading...
Searching...
No Matches
idle_port.h
Go to the documentation of this file.
1#ifndef STAR_IDLE_PORT_H
2#define STAR_IDLE_PORT_H
3
4/*
5 * Idle seam: the only hardware operations Idle logic may use.
6 *
7 * Idle never calls STM32 HAL. The board provides these callbacks through
8 * adapters that own the HAL handles; host tests provide fakes. Sleep entry,
9 * RTC wakeup scheduling and clock restoration belong to the state machine,
10 * not to this seam (see src/app/IDLE.md).
11 *
12 * Battery samples and replies reuse the self-test types so both modules
13 * share one battery adapter and one result vocabulary.
14 */
15
16#include <stdbool.h>
17#include <stdint.h>
18
19#include "self_test_port.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25typedef enum {
26 IDLE_CMD_NONE = 0, /* nothing waiting (not a failure) */
30
31typedef enum {
32 IDLE_BATT_UNKNOWN = 0, /* no reading yet */
36 IDLE_BATT_USB, /* board is on USB power; reading is not battery health */
37 IDLE_BATT_INVALID /* read failed, pending, unsupported or out of range */
39
40/* Heartbeat contents. Byte layout and checksum belong to the radio adapter. */
41typedef struct {
42 uint32_t sequence; /* increments every heartbeat, wraps modulo 2^32 */
43 uint32_t uptime_ms; /* monotonic clock, wraps modulo 2^32 */
44 uint16_t supply_mv; /* converted PA0 reading; 0 when INVALID */
46 /* Result of the previous heartbeat send (PENDING before the first). */
48 uint8_t consecutive_send_failures; /* saturates at 255 */
50
51/*
52 * All callbacks must return within budget_ms where given, must not block on
53 * the radio or a bus, and must not retain the pointers they are passed.
54 */
55typedef struct {
56 /* Raw ADC counts from PA0 (16-bit). Same contract as self-test's
57 * read_battery: valid must be set on success. */
58 self_test_battery_t (*read_battery)(void* context, uint32_t now_ms,
59 uint32_t budget_ms);
60 /* Reads SW_ST (PE10). True when the board runs on USB, in which case the
61 * PA0 reading is USB voltage and must not be reported as battery health.
62 */
63 bool (*on_usb_power)(void* context);
64 /* Send one heartbeat over LoRa. PASS only after SX1262 TxDone within
65 * budget_ms; enqueueing bytes is not success. */
67 const idle_heartbeat_t* heartbeat,
68 uint32_t budget_ms);
69 /* Return the next received ground command without waiting. */
70 idle_command_t (*poll_command)(void* context);
72
73#ifdef __cplusplus
74}
75#endif
76#endif
idle_command_t
Definition idle_port.h:25
@ IDLE_CMD_NONE
Definition idle_port.h:26
@ IDLE_CMD_ARM
Definition idle_port.h:27
@ IDLE_CMD_DISARM
Definition idle_port.h:28
idle_battery_state_t
Definition idle_port.h:31
@ IDLE_BATT_FAIL
Definition idle_port.h:35
@ IDLE_BATT_INVALID
Definition idle_port.h:37
@ IDLE_BATT_USB
Definition idle_port.h:36
@ IDLE_BATT_OK
Definition idle_port.h:33
@ IDLE_BATT_WARN
Definition idle_port.h:34
@ IDLE_BATT_UNKNOWN
Definition idle_port.h:32
self_test_result_t
uint32_t sequence
Definition idle_port.h:42
self_test_result_t previous_send
Definition idle_port.h:47
idle_battery_state_t battery
Definition idle_port.h:45
uint32_t uptime_ms
Definition idle_port.h:43
uint16_t supply_mv
Definition idle_port.h:44
uint8_t consecutive_send_failures
Definition idle_port.h:48
idle_command_t(* poll_command)(void *context)
Definition idle_port.h:70
self_test_battery_t(* read_battery)(void *context, uint32_t now_ms, uint32_t budget_ms)
Definition idle_port.h:58
self_test_reply_t(* send_heartbeat)(void *context, const idle_heartbeat_t *heartbeat, uint32_t budget_ms)
Definition idle_port.h:66
bool(* on_usb_power)(void *context)
Definition idle_port.h:63