|
10 | 10 | #include <avr/sleep.h> |
11 | 11 |
|
12 | 12 | #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" |
14 | 15 | #define AT_COMMAND_SET_RING_BEHAVIOUR "AT+SQNRICFG=1,2,1000" |
15 | 16 | #define AT_COMMAND_CONNECTION_STATUS "AT+CEREG?" |
16 | 17 |
|
|
20 | 21 | // Command without arguments: 18 bytes |
21 | 22 | // Both arguments within the quotes are strings of 8 numbers: 8 * 2 = 16 bytes |
22 | 23 | // Total: 18 + 16 = 34 bytes |
23 | | -#define AT_COMMAND_SET_PSM_LENGTH 34 |
| 24 | +#define AT_COMMAND_ENABLE_PSM_LENGTH 34 |
24 | 25 |
|
25 | 26 | // Max is 0b11111 = 31 for the value of the timers for power saving mode (not |
26 | 27 | // the multipliers). |
@@ -321,6 +322,33 @@ static void powerUpPeripherals(void) { |
321 | 322 | } |
322 | 323 | } |
323 | 324 |
|
| 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 | + |
324 | 352 | bool LowPowerClass::configurePeriodicPowerSave( |
325 | 353 | const PowerSaveModePeriodMultiplier power_save_mode_period_multiplier, |
326 | 354 | const uint8_t power_save_mode_period_value) { |
@@ -372,9 +400,9 @@ bool LowPowerClass::configurePeriodicPowerSave( |
372 | 400 |
|
373 | 401 | // Now we can embed the values for the awake and sleep periode in the |
374 | 402 | // 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 |
376 | 404 | sprintf(command, |
377 | | - AT_COMMAND_SET_PSM, |
| 405 | + AT_COMMAND_ENABLE_PSM, |
378 | 406 | period_parameter_str, |
379 | 407 | PSM_DEFAULT_PAGING_PARAMETER); |
380 | 408 |
|
@@ -446,7 +474,6 @@ void LowPowerClass::powerDown(const uint32_t power_down_time_seconds) { |
446 | 474 | power_down_time_seconds - |
447 | 475 | (uint32_t)(((millis() - start_time_ms) / 1000.0f)); |
448 | 476 |
|
449 | | - // TODO: There is some external interrupt causing the avr to wake |
450 | 477 | while (remaining_time_seconds > 0) { |
451 | 478 |
|
452 | 479 | sleep_cpu(); |
|
0 commit comments