Skip to content

Commit 4fa99de

Browse files
committed
Increase the T3324 timer length as it caused incorrect timing for the rest of the sleep phase
1 parent ba56977 commit 4fa99de

File tree

3 files changed

+59
-28
lines changed

3 files changed

+59
-28
lines changed

src/examples/low_power/low_power.ino

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ void setup() {
4242
// Configure the power save configuration, start the LTE modem and wait
4343
// until we are connected to the operator
4444
//
45-
// Here we say that we want to sleep for 30 seconds * 3 = 90 seconds each
45+
// Here we say that we want to sleep for 30 seconds * 2 = 60 seconds each
4646
// time we invoke sleep
47-
LowPower.begin(SleepMultiplier::ONE_MINUTE, 3, SleepMode::REGULAR);
47+
LowPower.begin(SleepMultiplier::THIRTY_SECONDS, 2, SleepMode::REGULAR);
4848
Lte.begin();
4949
Log.infof("Connecting to operator");
5050
while (!Lte.isConnected()) {
@@ -73,8 +73,8 @@ void loop() {
7373
Log.info("Got woken up by modem prematurely");
7474
break;
7575
case WakeUpReason::MODEM_TIMEOUT:
76-
Log.info(
77-
"Took too long to put modem in sleep, not time left for sleeping");
76+
Log.info("Took too long to put modem in sleep, no time left for "
77+
"sleeping. You might have to increase the sleep time.");
7878
break;
7979
case WakeUpReason::INVALID_SLEEP_TIME:
8080
Log.info("Got invalid sleep time from operator");
@@ -83,5 +83,5 @@ void loop() {
8383

8484
// Do work ...
8585
Log.info("Doing work...");
86-
delay(5000);
86+
delay(10000);
8787
}

src/low_power.cpp

Lines changed: 53 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
//
4444
// This parameter thus only specifies how quickly the modem can go to sleep,
4545
// which we want to be as low as possible.
46-
#define PSM_DEFAULT_AWAKE_PARAMETER "00000001"
47-
#define PSM_DEFAULT_AWAKE_TIME 2
46+
//
47+
// This is 10 seconds
48+
#define PSM_DEFAULT_AWAKE_PARAMETER "00000101"
4849

4950
#define PSM_REMAINING_SLEEP_TIME_THRESHOLD 5
5051

@@ -79,6 +80,7 @@ static volatile bool pit_triggered = false;
7980
static SleepMode sleep_mode;
8081
static bool retrieved_sleep_time = false;
8182
static uint32_t sleep_time = 0;
83+
static uint32_t sleep_time_requested = 0;
8284

8385
static uint8_t cell_led_state = 0;
8486
static uint8_t con_led_state = 0;
@@ -333,12 +335,24 @@ static WakeUpReason regularSleep(void) {
333335
sleep_time = retrieveOperatorSleepTime();
334336

335337
if (sleep_time == 0) {
336-
Log.debugf("Got invalid sleep time: %d\r\n", sleep_time);
338+
Log.debugf("Got invalid sleep time from operator: %d\r\n",
339+
sleep_time);
337340
return WakeUpReason::INVALID_SLEEP_TIME;
338341
} else {
339-
Log.debugf("Sleep time set to: %d seconds\r\n", sleep_time);
342+
if (sleep_time_requested != sleep_time) {
343+
Log.warnf("Operator was not able to match the requested sleep "
344+
"time of %d seconds. ",
345+
sleep_time_requested);
346+
Log.rawf("Operator sat the sleep time to %d seconds.\r\n",
347+
sleep_time);
348+
}
349+
340350
retrieved_sleep_time = true;
341351
}
352+
353+
// Retrieving the operator sleep time will call CEREG, which will
354+
// trigger led ctrl, so we just disable it again.
355+
LedCtrl.off(Led::CELL, true);
342356
}
343357

344358
// The timeout here is arbitrary as we attempt to put the modem in sleep in
@@ -370,28 +384,38 @@ static WakeUpReason regularSleep(void) {
370384

371385
sleep_cpu();
372386

373-
// Woken up by some external interrupt
374-
if (!pit_triggered && modem_is_in_power_save) {
375-
wakeup_reason = WakeUpReason::EXTERNAL_INTERRUPT;
376-
break;
377-
}
378-
379387
// Got woken up by the PIT interrupt
380388
if (pit_triggered) {
381389
remaining_time_seconds -= 1;
382-
pit_triggered = false;
383390
}
384391

385-
// Modem caused the CPU to be awoken
386-
if (!modem_is_in_power_save) {
392+
// If we are within the threshold, we assume that the awake was from the
393+
// modem
394+
if (remaining_time_seconds < PSM_REMAINING_SLEEP_TIME_THRESHOLD) {
395+
wakeup_reason = WakeUpReason::OK;
396+
break;
387397

388-
if (remaining_time_seconds < PSM_REMAINING_SLEEP_TIME_THRESHOLD) {
389-
wakeup_reason = WakeUpReason::OK;
390-
break;
391-
} else {
392-
wakeup_reason = WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY;
393-
break;
394-
}
398+
}
399+
// If modem is already awake and the remaining time was not within
400+
// the threshold, the modem has woken the CPU up prematurely to do
401+
// some work
402+
else if (!pit_triggered && !modem_is_in_power_save) {
403+
wakeup_reason = WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY;
404+
break;
405+
}
406+
// If we are not within the remaining sleep time threshold, the modem
407+
// did not wake the CPU up, neither the PIT, the reason for wake up is
408+
// bound to be by some external interrupt.
409+
else if (!pit_triggered) {
410+
wakeup_reason = WakeUpReason::EXTERNAL_INTERRUPT;
411+
break;
412+
}
413+
414+
// We clear the flag here as we want the information whether the PIT was
415+
// triggered or not as well as the remaining time for the other cases
416+
// above
417+
if (pit_triggered) {
418+
pit_triggered = false;
395419
}
396420
}
397421

@@ -499,8 +523,15 @@ bool LowPowerClass::begin(const SleepMultiplier sleep_multiplier,
499523
sleep_parameter_str,
500524
PSM_DEFAULT_AWAKE_PARAMETER);
501525

502-
sleep_time = decodeSleepMultiplier(sleep_multiplier) *
503-
min(sleep_value, PSM_VALUE_MAX);
526+
sleep_time_requested = decodeSleepMultiplier(sleep_multiplier) *
527+
min(sleep_value, PSM_VALUE_MAX);
528+
529+
// If we choose deep sleep, the modem will be completely off and we don't
530+
// have to negotiate the sleep time with the operator, thus the requested
531+
// sleep time and the actual sleep time will be equal
532+
if (mode == SleepMode::DEEP) {
533+
sleep_time = sleep_time_requested;
534+
}
504535

505536
return SequansController.retryCommand(command);
506537
}

src/low_power.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class LowPowerClass {
102102
* can be put to sleep after the matter causing the wake up has been taken
103103
* care of.
104104
*
105-
* - AWOKEN_BY_EXTERNAL_EVENT: Awoken by some external unknown interrupt.
105+
* - EXTERNAL_INTERRUPT: Awoken by some external unknown interrupt.
106106
*
107107
* - OK: Sleep went fine.
108108
*/

0 commit comments

Comments
 (0)