Skip to content

Commit 943b992

Browse files
committed
Improve cyw43.set_power_management documentation
.. and provide 4 preset values
1 parent f9e655d commit 943b992

File tree

2 files changed

+52
-5
lines changed

2 files changed

+52
-5
lines changed

ports/raspberrypi/bindings/cyw43/__init__.c

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "shared-bindings/microcontroller/__init__.h"
3232
#include "shared-bindings/microcontroller/Pin.h"
3333
#include "bindings/cyw43/__init__.h"
34-
3534
//| class CywPin:
3635
//| """A class that represents a GPIO pin attached to the wifi chip.
3736
//|
@@ -49,14 +48,42 @@ const mp_obj_type_t cyw43_pin_type = {
4948
)
5049
};
5150

51+
//| PM_STANDARD: int
52+
//| """The standard power management mode"""
53+
//| PM_AGGRESSIVE: int
54+
//| """Aggressive power management mode for optimial power usage at the cost of performance"""
55+
//| PM_PERFORMANCE: int
56+
//| """Performance power management mode where more power is used to increase performance"""
57+
//| PM_DISABLED: int
58+
//| """Disable power management and always use highest power mode"""
59+
//|
5260
//| def set_power_management(value: int) -> None:
5361
//| """Set the power management register
5462
//|
55-
//| According to Raspberry Pi documentation, the value 0xa11140
56-
//| increases responsiveness at the cost of higher power usage.
63+
//| For transmitter power, see ``wifi.Radio.txpower``.
64+
//| This controls software power saving features inside the cyw43 chip.
65+
//| it does not control transmitter power.
66+
//|
67+
//| The value is interpreted as a 24-bit hexadecimal number of the form
68+
//| ``0x00adbrrm``.
69+
//|
70+
//| The low 4 bits, ``m``, are the power management mode:
71+
//| * 0: disabled
72+
//| * 1: aggressive power saving which reduces wifi throughput
73+
//| * 2: Power saving with High througput
74+
//|
75+
//| The next 8 bits, ``r``, specify "the maximum time to wait before going back to sleep" for power management mode 2. The units of ``r`` are 10ms.
76+
//|
77+
//| The next 4 bits, ``b``, are the "wake period is measured in beacon periods".
78+
//|
79+
//| The next 4 bits, ``d``, specify the "wake interval measured in DTIMs. If this is set to 0, the wake interval is measured in beacon periods".
80+
//|
81+
//| The top 4 bits, ``a``, specifies the "wake interval sent to the access point"
5782
//|
58-
//| Besides this value, there appears to be no other public documentation
59-
//| of the values that can be used.
83+
//| Several ``PM_`` constants gathered from various sources are included
84+
//| in this module. According to Raspberry Pi documentation, the value 0xa11140
85+
//| (called `cyw43.PM_DISABLED` here) increases responsiveness at the cost of higher power
86+
//| usage.
6087
//| """
6188
//|
6289
STATIC mp_obj_t cyw43_set_power_management(const mp_obj_t value_in) {
@@ -83,6 +110,10 @@ STATIC const mp_rom_map_elem_t cyw43_module_globals_table[] = {
83110
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cyw43) },
84111
{ MP_ROM_QSTR(MP_QSTR_CywPin), MP_ROM_QSTR(MP_QSTR_CywPin) },
85112
{ MP_ROM_QSTR(MP_QSTR_set_power_management), &cyw43_set_power_management_obj },
113+
{ MP_ROM_QSTR(MP_QSTR_PM_STANDARD), MP_ROM_INT(PM_STANDARD) },
114+
{ MP_ROM_QSTR(MP_QSTR_PM_AGGRESSIVE), MP_ROM_INT(PM_AGGRESSIVE) },
115+
{ MP_ROM_QSTR(MP_QSTR_PM_PERFORMANCE), MP_ROM_INT(PM_PERFORMANCE) },
116+
{ MP_ROM_QSTR(MP_QSTR_PM_DISABLED), MP_ROM_INT(PM_DISABLED) },
86117
};
87118

88119
STATIC MP_DEFINE_CONST_DICT(cyw43_module_globals, cyw43_module_globals_table);

ports/raspberrypi/bindings/cyw43/__init__.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,19 @@
3232
extern const mp_obj_type_t cyw43_pin_type;
3333
const mcu_pin_obj_t *validate_obj_is_free_pin_including_cyw43(mp_obj_t obj);
3434
const mcu_pin_obj_t *validate_obj_is_pin_including_cyw43(mp_obj_t obj);
35+
36+
#define CONSTANT_CYW43_PM_VALUE(pm_mode, pm2_sleep_ret_ms, li_beacon_period, li_dtim_period, li_assoc) \
37+
(li_assoc << 20 | /* listen interval sent to ap */ \
38+
li_dtim_period << 16 | \
39+
li_beacon_period << 12 | \
40+
(pm2_sleep_ret_ms / 10) << 4 | /* cyw43_ll_wifi_pm multiplies this by 10 */ \
41+
pm_mode /* CYW43_PM2_POWERSAVE_MODE etc */)
42+
43+
// CYW43_DEFAULT_PM (except a compile-time constant)
44+
#define PM_STANDARD CONSTANT_CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 200, 1, 1, 10)
45+
// CYW43_AGGRESSIVE_PM (except a compile-time constant)
46+
#define PM_AGGRESSIVE CONSTANT_CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 2000, 1, 1, 10)
47+
// CYW43_PERFORMANCE_PM (except a compile-time constant)
48+
#define PM_PERFORMANCE CONSTANT_CYW43_PM_VALUE(CYW43_PM2_POWERSAVE_MODE, 20, 1, 1, 1)
49+
// The 0xa11140 magic value
50+
#define PM_DISABLED CONSTANT_CYW43_PM_VALUE(CYW43_NO_POWERSAVE_MODE, 200, 1, 1, 10)

0 commit comments

Comments
 (0)