ProtoCore v0.0.2
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
radio_power.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file radio_power.h
6 * @brief WiFi radio power controls (PC_ENABLE_RADIO_POWER).
7 *
8 * Applies the WiFi modem-sleep mode (PC_RADIO_WIFI_PS) and an optional max-TX
9 * cap (PC_RADIO_MAX_TX_DBM) in one call - trade throughput/latency for lower
10 * average power on a battery device. The mode names are pure/host-tested; the
11 * apply + readback use esp_wifi on ESP32 (no-ops on host).
12 *
13 * @author Douglas Quigg (dstroy0)
14 * @date 2026
15 */
16
17#ifndef PROTOCORE_RADIO_POWER_H
18#define PROTOCORE_RADIO_POWER_H
19
20#include "protocore_config.h"
21#include <stdint.h>
22
23#if PC_ENABLE_RADIO_POWER
24
25/** @brief Modem-sleep modes (match PC_RADIO_WIFI_PS). Config/compare values, so integer constants in
26 * a namespacing struct (cast-free at ==/switch). The service maps these onto the L1 `pc_phy_ps`
27 * contract; what the radio backend calls them is its own business. */
28struct pc_radio_ps
29{
30 static constexpr uint8_t PC_PS_NONE = 0; ///< no modem sleep (max performance).
31 static constexpr uint8_t PC_PS_MIN_MODEM = 1; ///< wake at every DTIM (balanced).
32 static constexpr uint8_t PC_PS_MAX_MODEM = 2; ///< wake at a listen interval (lowest power, higher latency).
33};
34
35/** @brief Name for a modem-sleep mode ("none" / "min_modem" / "max_modem"). */
36const char *pc_radio_ps_name(uint8_t mode);
37
38/** @brief Apply PC_RADIO_WIFI_PS (+ TX cap) to the radio. No-op on host. */
39void pc_radio_power_apply(void);
40
41/** @brief Current modem-sleep mode read back from the radio (PC_PS_* ; 0 on host). */
42uint8_t pc_radio_ps_get(void);
43
44/**
45 * @brief Hold the radio awake for the duration of a bulk transfer (reference-counted).
46 *
47 * The first hold forces modem sleep off so a long transfer is not interrupted by DTIM
48 * wakeups; the matching release, once the count returns to zero, restores the configured
49 * PC_RADIO_WIFI_PS mode. Balance every @ref pc_radio_busy_hold with exactly one
50 * @ref pc_radio_busy_release. The relay/DNAT listener holds one while any bridge is active; other
51 * bulk paths (large file serves, streaming PUT) can do the same. No-op on host.
52 */
53void pc_radio_busy_hold(void);
54
55/** @brief Release a bulk-transfer hold; restores the configured modem-sleep mode at zero. No-op on host. */
56void pc_radio_busy_release(void);
57
58#endif // PC_ENABLE_RADIO_POWER
59#endif // PROTOCORE_RADIO_POWER_H
User-facing configuration for ProtoCore.