Skip to content

Commit bd98aea

Browse files
committed
Fix bug where power down was interrupted
1 parent 66210c0 commit bd98aea

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

src/low_power.cpp

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#include <avr/sleep.h>
1111

1212
#define AT_COMMAND_DISABLE_EDRX "AT+SQNEDRX=0"
13-
#define AT_COMMAND_SET_PSM "AT+CPSMS=1,,,\"%s\",\"%s\""
13+
#define AT_COMMAND_ENABLE_PSM "AT+CPSMS=1,,,\"%s\",\"%s\""
14+
#define AT_COMMAND_DISABLE_PSM "AT+CPSMS=0"
1415
#define AT_COMMAND_SET_RING_BEHAVIOUR "AT+SQNRICFG=1,2,1000"
1516
#define AT_COMMAND_CONNECTION_STATUS "AT+CEREG?"
1617

@@ -20,7 +21,7 @@
2021
// Command without arguments: 18 bytes
2122
// Both arguments within the quotes are strings of 8 numbers: 8 * 2 = 16 bytes
2223
// Total: 18 + 16 = 34 bytes
23-
#define AT_COMMAND_SET_PSM_LENGTH 34
24+
#define AT_COMMAND_ENABLE_PSM_LENGTH 34
2425

2526
// Max is 0b11111 = 31 for the value of the timers for power saving mode (not
2627
// the multipliers).
@@ -321,6 +322,33 @@ static void powerUpPeripherals(void) {
321322
}
322323
}
323324

325+
bool LowPowerClass::configurePowerDown(void) {
326+
327+
// We need sequans controller to be initialized first before configuration.
328+
// This is because we need to disable the PSM mode so that the modem don't
329+
// do periodic power save, but we can shut it down completely.
330+
if (!SequansController.isInitialized()) {
331+
SequansController.begin();
332+
333+
// Allow 500ms for boot
334+
delay(500);
335+
}
336+
337+
SequansController.clearReceiveBuffer();
338+
339+
// First we disable EDRX
340+
if (!SequansController.retryCommand(AT_COMMAND_DISABLE_EDRX)) {
341+
return false;
342+
}
343+
344+
// Disable PSM
345+
if (!SequansController.retryCommand(AT_COMMAND_DISABLE_PSM)) {
346+
return false;
347+
}
348+
349+
return true;
350+
}
351+
324352
bool LowPowerClass::configurePeriodicPowerSave(
325353
const PowerSaveModePeriodMultiplier power_save_mode_period_multiplier,
326354
const uint8_t power_save_mode_period_value) {
@@ -372,9 +400,9 @@ bool LowPowerClass::configurePeriodicPowerSave(
372400

373401
// Now we can embed the values for the awake and sleep periode in the
374402
// power saving mode configuration command
375-
char command[AT_COMMAND_SET_PSM_LENGTH + 1]; // + 1 for null termination
403+
char command[AT_COMMAND_ENABLE_PSM_LENGTH + 1]; // + 1 for null termination
376404
sprintf(command,
377-
AT_COMMAND_SET_PSM,
405+
AT_COMMAND_ENABLE_PSM,
378406
period_parameter_str,
379407
PSM_DEFAULT_PAGING_PARAMETER);
380408

@@ -446,7 +474,6 @@ void LowPowerClass::powerDown(const uint32_t power_down_time_seconds) {
446474
power_down_time_seconds -
447475
(uint32_t)(((millis() - start_time_ms) / 1000.0f));
448476

449-
// TODO: There is some external interrupt causing the avr to wake
450477
while (remaining_time_seconds > 0) {
451478

452479
sleep_cpu();

src/low_power.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ class LowPowerClass {
3737
return instance;
3838
}
3939

40+
/**
41+
* @brief Configures the low power module for power down configuration.
42+
*
43+
* @return true if the configuration was successful.
44+
*/
45+
bool configurePowerDown(void);
46+
4047
/**
4148
* @brief Used to configure power save mode for the LTE modem. The total
4249
* power save time period for the LTE modem will be

src/sequans_controller.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ void SequansControllerClass::end(void) {
352352
USART1.CTRLB = 0;
353353
USART1.CTRLC = 0;
354354

355-
pinConfigure(CTS_PIN, 0);
355+
pinConfigure(CTS_PIN, PIN_ISC_DISABLE);
356356

357357
// Set RTS high to halt the modem
358358
pinConfigure(RTS_PIN, PIN_DIR_OUTPUT);

0 commit comments

Comments
 (0)