Skip to content

Commit e20f7a4

Browse files
committed
Merge remote-tracking branch 'origin' into sandbox
2 parents 69f7e6c + 0387b0a commit e20f7a4

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

src/examples/low_power/low_power.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void setup() {
3232
//
3333
// Here we say that we want to sleep for 30 seconds * 2 = 60 seconds each
3434
// time we invoke sleep
35-
LowPower.begin(SleepMultiplier::THIRTY_SECONDS, 2);
35+
LowPower.begin(SleepMultiplier::THIRTY_SECONDS, 2, SleepMode::REGULAR);
3636
Lte.begin();
3737

3838
while (!Lte.isConnected()) {
@@ -49,7 +49,7 @@ void loop() {
4949

5050
digitalWrite(TIMING_PIN, digitalRead(TIMING_PIN) ? 0 : 1);
5151

52-
SleepStatusCode status_code = LowPower.sleep(SleepMode::REGULAR);
53-
Log.infof("Got out of sleep with status code %d, doing work...\r\n",
54-
status_code);
52+
WakeUpReason wakeup_reason = LowPower.sleep();
53+
Log.infof("Got out of sleep with wake up reason %d, doing work...\r\n",
54+
wakeup_reason);
5555
}

src/low_power.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static volatile bool ring_line_activity = false;
6060
static volatile bool modem_is_in_power_save = false;
6161
static volatile bool pit_triggered = false;
6262

63+
static SleepMode sleep_mode;
6364
static bool retrieved_sleep_time = false;
6465
static uint32_t sleep_time = 0;
6566

@@ -278,7 +279,7 @@ static void disablePIT(void) {
278279
/**
279280
* Modem sleeping and CPU deep sleep.
280281
*/
281-
static SleepStatusCode regularSleep(void) {
282+
static WakeUpReason regularSleep(void) {
282283

283284
const unsigned long start_time_ms = millis();
284285

@@ -288,7 +289,7 @@ static SleepStatusCode regularSleep(void) {
288289
sleep_time = retrieveOperatorSleepTime();
289290

290291
if (sleep_time == 0) {
291-
return SleepStatusCode::INVALID_SLEEP_TIME;
292+
return WakeUpReason::INVALID_SLEEP_TIME;
292293
} else {
293294
retrieved_sleep_time = true;
294295
}
@@ -301,18 +302,18 @@ static SleepStatusCode regularSleep(void) {
301302
// If we surpassed the sleep time during setting the LTE to sleep, we
302303
// don't have any more time to sleep the CPU, so just return.
303304
if (millis() - start_time_ms >= sleep_time * 1000) {
304-
return SleepStatusCode::TIMEOUT;
305+
return WakeUpReason::MODEM_TIMEOUT;
305306
}
306307

307308
enablePIT();
308309

309310
uint32_t remaining_time_seconds =
310311
sleep_time - (uint32_t)(((millis() - start_time_ms) / 1000.0f));
311312

312-
SleepStatusCode status_code = SleepStatusCode::OK;
313+
WakeUpReason wakeup_reason = WakeUpReason::OK;
313314

314315
if (remaining_time_seconds < 0) {
315-
status_code = SleepStatusCode::TIMEOUT;
316+
wakeup_reason = WakeUpReason::MODEM_TIMEOUT;
316317
}
317318

318319
// As the PIT timer has a minimum frequency of 1 Hz, we loop over the
@@ -332,10 +333,10 @@ static SleepStatusCode regularSleep(void) {
332333
if (!modem_is_in_power_save) {
333334

334335
if (remaining_time_seconds < PSM_REMAINING_SLEEP_TIME_THRESHOLD) {
335-
status_code = SleepStatusCode::OK;
336+
wakeup_reason = WakeUpReason::OK;
336337
break;
337338
} else {
338-
status_code = SleepStatusCode::AWOKEN_BY_MODEM_PREMATURELY;
339+
wakeup_reason = WakeUpReason::AWOKEN_BY_MODEM_PREMATURELY;
339340
break;
340341
}
341342
}
@@ -348,13 +349,13 @@ static SleepStatusCode regularSleep(void) {
348349

349350
disablePIT();
350351

351-
return status_code;
352+
return wakeup_reason;
352353
}
353354

354355
/**
355356
* Modem turned off and CPU deep sleep.
356357
*/
357-
static SleepStatusCode deepSleep(void) {
358+
static WakeUpReason deepSleep(void) {
358359

359360
const unsigned long start_time_ms = millis();
360361

@@ -382,11 +383,14 @@ static SleepStatusCode deepSleep(void) {
382383

383384
Lte.begin();
384385

385-
return SleepStatusCode::OK;
386+
return WakeUpReason::OK;
386387
}
387388

388389
bool LowPowerClass::begin(const SleepMultiplier sleep_multiplier,
389-
const uint8_t sleep_value) {
390+
const uint8_t sleep_value,
391+
const SleepMode mode) {
392+
393+
sleep_mode = mode;
390394

391395
// Reset in case there is a reconfiguration after sleep has been called
392396
// previously
@@ -448,13 +452,13 @@ bool LowPowerClass::begin(const SleepMultiplier sleep_multiplier,
448452
return SequansController.retryCommand(command);
449453
}
450454

451-
SleepStatusCode LowPowerClass::sleep(const SleepMode sleep_mode) {
455+
WakeUpReason LowPowerClass::sleep(void) {
452456
switch (sleep_mode) {
453457
case SleepMode::REGULAR:
454458
return regularSleep();
455459
case SleepMode::DEEP:
456460
return deepSleep();
457461
}
458462

459-
return SleepStatusCode::OK;
463+
return WakeUpReason::OK;
460464
}

src/low_power.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ enum class SleepMultiplier {
1818
ONE_MINUTE = 5,
1919
};
2020

21-
enum class SleepStatusCode {
21+
enum class WakeUpReason {
2222
// Invoked if the sleep time retrieved from the operator wasn't valid
2323
INVALID_SLEEP_TIME = 4,
2424

2525
// Invoked if it took so long to put the modem in sleep that it wasn't time
2626
// left for the CPU to sleep. The sleep time should be considered to be
2727
// increased.
28-
TIMEOUT = 3,
28+
MODEM_TIMEOUT = 3,
2929

3030
// The modem went out of sleep before the total time, which may happen if
3131
// e.g. the interval of needing to send MQTT heartbeat is lower than the
@@ -68,10 +68,16 @@ class LowPowerClass {
6868
*
6969
* @param sleep_value Note that max value is 31.
7070
*
71+
* @param sleep_modem:
72+
* - REGULAR: Modem in sleep, CPU in deep sleep
73+
* - DEEP: Modem powered off, CPU in deep sleep. Note that the modem will be
74+
* started again after the sleep in this mode
75+
*
7176
* @return True if configuration was set successfully.
7277
*/
7378
bool begin(const SleepMultiplier sleep_multiplier,
74-
const uint8_t sleep_value);
79+
const uint8_t sleep_value,
80+
const SleepMode = SleepMode::REGULAR);
7581

7682
/**
7783
* @brief Will attempt to put the modem in sleep and then the MCU for the
@@ -80,16 +86,12 @@ class LowPowerClass {
8086
* some time, so the total time both of the units are asleep is highly
8187
* likely to be some seconds shorter than the total sleep time.
8288
*
83-
* @param sleep_modem:
84-
* - REGULAR: Modem in sleep, CPU in deep sleep
85-
* - DEEP: Modem powered off, CPU in deep sleep
86-
*
8789
* @return Status code:
8890
* - INVALID_SLEEP_TIME: if the sleep time configured in begin() wasn't
8991
* valid or something else failed. Consider modifying the sleep time.
9092
*
91-
* - TIMEOUT: Happens when the remining time after putting the modem to
92-
* sleep left there being no time for the CPU to sleep. Not necessarily a
93+
* - MODEM_TIMEOUT: Happens when the remining time after putting the modem
94+
* to sleep left there being no time for the CPU to sleep. Not necessarily a
9395
* problem, but the CPU won't get any sleep time. This can be alleviated by
9496
* increasing the sleep time.
9597
*
@@ -104,7 +106,7 @@ class LowPowerClass {
104106
*
105107
* - OK: Sleep went fine.
106108
*/
107-
SleepStatusCode sleep(const SleepMode sleep_mode);
109+
WakeUpReason sleep(void);
108110
};
109111

110112
extern LowPowerClass LowPower;

0 commit comments

Comments
 (0)