ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
radio_power.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - 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 Layer 1 (Physical) - 802.11 power management and transmit power control
7 * (PROTOCORE_ENABLE_RADIO_POWER).
8 *
9 * IEEE Std 802.11-2020 is the normative source for every call here; no IETF RFC governs radio
10 * power management. 11.2.3.2 (Non-AP STA power management modes) names the two modes a non-AP
11 * STA runs in, active mode and PS mode, and 6.3.2.2 (MLME-POWERMGT.request) is the primitive
12 * that selects one. A STA in PS mode dozes and wakes for the DTIM of 11.2.3.4 (TIM types),
13 * across at most the beacon count of 9.4.1.6 (Listen Interval field). 11.7 (TPC procedures)
14 * governs transmit power in dBm, bounded by 11.7.5 (Specification of regulatory and local
15 * maximum transmit power levels).
16 *
17 * PROTOCORE_RADIO_WIFI_PS picks the mode and PROTOCORE_RADIO_MAX_TX_DBM the cap; @ref RadioNs::power
18 * applies both in one call, trading throughput and latency for lower average draw. The mode
19 * names are pure and host-tested; the apply and the readback go through the L1 phy contract,
20 * which reports failure when the part carries no radio backend.
21 *
22 * The module exports one symbol, @ref Radio. Everything in radio_power.c has internal linkage, so no
23 * name from this module reaches the library-wide symbol space and none of them can collide.
24 *
25 * @author Douglas Quigg (dstroy0)
26 * @date 2026
27 */
28
29#ifndef PROTOCORE_RADIO_POWER_H
30#define PROTOCORE_RADIO_POWER_H
31
32#include "protocore_config.h" // the entry point: the enable gate below, and the widths
33
34#if PROTOCORE_ENABLE_RADIO_POWER
35
36#include "network_drivers/physical/physical/physical.h" // protocore_phy_ps: the L1 contract
37
39
40/** @brief The power management mode a call applies or renders (802.11-2020 11.2.3.2). */
41typedef struct
42{
43 protocore_phy_ps mode; ///< active mode or PS mode, in L1's own protocore_phy_ps terms
44} RadioPsArgs;
45
46/** @brief The transmit power a cap applies (802.11-2020 11.7.6). */
47typedef struct
48{
49 int8_t dbm; ///< maximum transmit power in whole dBm; 802.11-2020 11.7.5 bounds it
50} RadioTxArgs;
51
52/** @brief The radio's own state and the calls that reach it, described only in radio_power.c. */
53
54/**
55 * @brief The radio: its power management mode and its transmit power cap.
56 *
57 * A caller sets the members a call takes, invokes it through ::Radio, and reads the outcome off the
58 * same handle. The keep-awake count is behind @ref internal.
59 *
60 * @var RadioNs::ps the power management mode a call applies or renders (802.11-2020 11.2.3.2)
61 * @var RadioNs::tx the transmit power a cap applies (802.11-2020 11.7)
62 * @var RadioNs::ok a call's true/false outcome
63 * @var RadioNs::mode the mode the radio reports, in L1's own protocore_phy_ps terms
64 * @var RadioNs::text the name a render reports ("none" / "min_modem" / "max_modem")
65 * @var RadioNs::power apply PROTOCORE_RADIO_WIFI_PS, and PROTOCORE_RADIO_MAX_TX_DBM when nonzero
66 * @var RadioNs::ps_name render a power management mode as text
67 * @var RadioNs::busy_hold hold the radio in active mode for a bulk transfer (reference-counted)
68 * @var RadioNs::busy_release release one bulk-transfer hold
69 * @var RadioNs::ps_set select active mode or PS mode (802.11-2020 6.3.2.2)
70 * @var RadioNs::ps_mode read the mode back into @ref RadioNs::mode
71 * @var RadioNs::tx_power_set cap transmit power at @ref RadioTxArgs::dbm (802.11-2020 11.7.6)
72 *
73 * The first @ref RadioNs::busy_hold puts the radio in active mode so a long transfer crosses no
74 * doze interval; the matching release, once the count returns to zero, applies the configured
75 * PROTOCORE_RADIO_WIFI_PS mode again. Balance every hold with exactly one release. The relay/DNAT
76 * listener holds one while any bridge is active; other bulk paths (large file serves, streaming
77 * PUT) can do the same.
78 */
79typedef struct RadioNs
80{
81 RadioPsArgs ps; ///< the power management mode a call applies or renders (802.11-2020 11.2.3.2)
82 RadioTxArgs tx; ///< the transmit power a cap applies (802.11-2020 11.7)
83
84 proto_bool ok;
86 const char *text;
87
88 void (*const power)(uint8_t *work);
89 void (*const ps_name)(uint8_t *work);
90 void (*const busy_hold)(uint8_t *work);
91 void (*const busy_release)(uint8_t *work);
92 void (*const ps_set)(uint8_t *work);
93 void (*const ps_mode)(uint8_t *work);
94 void (*const tx_power_set)(uint8_t *work);
95
96} RadioNs;
97
98/** @brief The one symbol this module exports. */
99extern RadioNs Radio;
100
101/**
102 * @brief The PROTOCORE_RADIO_POWER_BORROW bytes this module's state lives in.
103 *
104 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where that
105 * borrow comes from. Taken once from the end of the pool, so it lasts the life of the program.
106 *
107 * @return the span.
108 */
109uint8_t *protocore_radio_power_span(void);
110
112
113#endif // PROTOCORE_ENABLE_RADIO_POWER
114
115#endif // PROTOCORE_RADIO_POWER_H
Layer 1 (Physical) - link bring-up, the interface registry, and live egress reporting.
enum PROTO_ENUM_PACKED protocore_phy_ps
Radio power-save mode, in the library's own vocabulary (IEEE 802.11 power management).
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97