Skip to content

Commit 60d10b4

Browse files
committed
Improve cyw43.set_power_management documentation
.. and provide 4 preset values
1 parent fcf7cfe commit 60d10b4

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
//|
@@ -48,14 +47,42 @@ const mp_obj_type_t cyw43_pin_type = {
4847
)
4948
};
5049

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

86117
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)