DeterministicESPAsyncWebServer v6.28.0
Zero-allocation, bounded-execution async HTTP server for ESP32
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 (DETWS_ENABLE_RADIO_POWER).
7 *
8 * Applies the WiFi modem-sleep mode (DETWS_RADIO_WIFI_PS) and an optional max-TX
9 * cap (DETWS_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 DETERMINISTICESPASYNCWEBSERVER_RADIO_POWER_H
18#define DETERMINISTICESPASYNCWEBSERVER_RADIO_POWER_H
19
20#include "ServerConfig.h"
21#include <stdint.h>
22
23#if DETWS_ENABLE_RADIO_POWER
24
25/** @brief Modem-sleep modes (match DETWS_RADIO_WIFI_PS). Config/compare values that map to esp_wifi's
26 * wifi_ps_type_t, so integer constants in a namespacing struct (cast-free at ==/switch/the ESP-IDF map). */
27struct DetwsRadioPs
28{
29 static constexpr uint8_t DETWS_PS_NONE = 0; ///< no modem sleep (max performance).
30 static constexpr uint8_t DETWS_PS_MIN_MODEM = 1; ///< wake at every DTIM (balanced).
31 static constexpr uint8_t DETWS_PS_MAX_MODEM = 2; ///< wake at a listen interval (lowest power, higher latency).
32};
33
34/** @brief Name for a modem-sleep mode ("none" / "min_modem" / "max_modem"). */
35const char *detws_radio_ps_name(uint8_t mode);
36
37/** @brief Apply DETWS_RADIO_WIFI_PS (+ TX cap) to the radio. No-op on host. */
38void detws_radio_power_apply(void);
39
40/** @brief Current modem-sleep mode read back from the radio (DETWS_PS_* ; 0 on host). */
41uint8_t detws_radio_ps_get(void);
42
43/**
44 * @brief Hold the radio awake for the duration of a bulk transfer (reference-counted).
45 *
46 * The first hold forces modem sleep off (WIFI_PS_NONE) so a long transfer is not interrupted by DTIM
47 * wakeups; the matching release, once the count returns to zero, restores the configured
48 * DETWS_RADIO_WIFI_PS mode. Balance every @ref detws_radio_busy_hold with exactly one
49 * @ref detws_radio_busy_release. The relay/DNAT listener holds one while any bridge is active; other
50 * bulk paths (large file serves, streaming PUT) can do the same. No-op on host.
51 */
52void detws_radio_busy_hold(void);
53
54/** @brief Release a bulk-transfer hold; restores the configured modem-sleep mode at zero. No-op on host. */
55void detws_radio_busy_release(void);
56
57#endif // DETWS_ENABLE_RADIO_POWER
58#endif // DETERMINISTICESPASYNCWEBSERVER_RADIO_POWER_H
User-facing configuration for DeterministicESPAsyncWebServer.