Telink TLSR8232 BLE SDK Developer Handbook
AN-19112700-E1
126
Ver.1.0.0
4.5.1 bls_pm_getSystemWakeupTick
The API below is used to obtain suspend wakeup time (system tick value) calculated by
PM module.
u32 bls_pm_getSystemWakeupTick(void);
According to section 4.3.4, this API can be invoked only in the callback function of
“BLT_EV_FLAG_SUSPEND_ENTER” event.
When the
“blt_brx_sleep” function is executed by PM module, the suspend wakeup time
is calculated
according to current Link Layer state and the “SuspendMask” set in APP
layer. APP layer can read this value only via the callback function of
“BLT_EV_FLAG_SUSPEND_ENTER” event. For example, MCU needs to enter suspend
from Conn state, and conn latency is not 0:
u16 latency_use = bls_calculateLatency();
wakeup_tick = T_brx + (late1) * conn_interval;
cpu_sleep_wakeup(0,PM_WAKEUP_TIMER|WakeupSource, wakeup_tick);
APP layer can’t predict in advance the latency_use calculated by “bls_calculateLatency”
and thus does not know the actual wakeup_tick; the wakeup time can be obtained only
by invoking “bls_pm_getSystemWakeupTick” in the callback function of
“BLT_EV_FLAG_SUSPEND_ENTER” event.
Following is a key scan application example to illustrate the usage of
“BLT_EV_FLAG_SUSPEND_ENTER” callback function and
“bls_pm_getSystemWakeupTick”.
bls_app_registerEventCallback(
BLT_EV_FLAG_SUSPEND_ENTER,
&ble_remote_set_sleep_wakeup);
void
ble_remote_set_sleep_wakeup
(
u8
e,
u8
*p,
int
n)
{
if
( bls_ll_getCurrentState() == BLS_LINK_STATE_CONN &&
((
u32
)(bls_pm_getSystemWakeupTick() - clock_time())) >
80 *
CLOCK_SYS_CLOCK_1MS
)
{
//gpio CORE wakeup suspend
bls_pm_setWakeupSource(
PM_WAKEUP_CORE
);
}
}
The callback function is used to avoid key press loss. Generally, a key press lasts for
hundreds of milliseconds~100ms. When “bls_pm_setSuspendMask” configures MCU to
enter suspend from both Advertising state and Conn state
, if “Conn Latency” is not
enabled (0), as long as Adv interval and Conn interval is not especially large (generally
set as a value not exceeding 100ms), suspend time won’t exceed Adv interval and Conn
interval; since it can ensure key scan frequency, key press loss can be avoided. In this
case, GPIO wakeup is not configur
ed, so that key press won’t wakeup MCU.
However, if latency is enabled, (e.g. conn_interval is 10ms, latency is 99), suspend may
last for 1s in Conn state. During this process, there may be key press lost. Check in the