|
10 | 10 | #include <avr/io.h> |
11 | 11 | #include <avr/sleep.h> |
12 | 12 |
|
13 | | -#define AT_COMMAND_DISABLE_EDRX "AT+SQNEDRX=0" |
14 | | -#define AT_COMMAND_ENABLE_PSM "AT+CPSMS=1,,,\"%s\",\"%s\"" |
15 | | -#define AT_COMMAND_DISABLE_PSM "AT+CPSMS=0" |
16 | | -#define AT_COMMAND_SET_RING_BEHAVIOUR "AT+SQNRICFG=1,2,1000" |
17 | | -#define AT_COMMAND_CONNECTION_STATUS "AT+CEREG?" |
18 | | - |
19 | | -// For use of the rest of library, for example low power |
20 | | -#define RESPONSE_CONNECTION_STATUS_SIZE 70 |
| 13 | +#define AT_COMMAND_DISABLE_EDRX "AT+SQNEDRX=0" |
| 14 | +#define AT_COMMAND_ENABLE_PSM "AT+CPSMS=1,,,\"%s\",\"%s\"" |
| 15 | +#define AT_COMMAND_DISABLE_PSM "AT+CPSMS=0" |
| 16 | +#define AT_COMMAND_SET_RING_BEHAVIOUR "AT+SQNRICFG=1,2,1000" |
| 17 | +#define AT_COMMAND_CONNECTION_STATUS "AT+CEREG?" |
| 18 | +#define AT_COMMAND_SET_RTS0_HIGH_TRIGGERS_SLEEP "AT+SQNIPSCFG=1,1000" |
| 19 | + |
| 20 | +#define AT_COMMAND_ENTER_MANUFACTURING_MODE "AT+CFUN=5" |
| 21 | +#define AT_COMMAND_DISABLE_WAKE_ON_RTS1 "AT+SQNHWCFG=\"wakeRTS1\",\"disable\"" |
| 22 | +#define AT_COMMAND_DISABLE_WAKE_ON_SIM0 "AT+SQNHWCFG=\"wakeSim0\",\"disable\"" |
| 23 | +#define AT_COMMAND_DISABLE_WAKE_ON_WAKE0 "AT+SQNHWCFG=\"wake0\",\"disable\"" |
| 24 | +#define AT_COMMAND_DISABLE_WAKE_ON_WAKE1 "AT+SQNHWCFG=\"wake1\",\"disable\"" |
| 25 | +#define AT_COMMAND_DISABLE_WAKE_ON_WAKE2 "AT+SQNHWCFG=\"wake2\",\"disable\"" |
| 26 | +#define AT_COMMAND_DISABLE_WAKE_ON_WAKE3 "AT+SQNHWCFG=\"wake3\",\"disable\"" |
| 27 | +#define AT_COMMAND_DISABLE_WAKE_ON_WAKE4 "AT+SQNHWCFG=\"wake4\",\"disable\"" |
| 28 | +#define AT_COMMAND_DISABLE_UART1 "AT+SQNHWCFG=\"uart1\",\"disable\"" |
| 29 | +#define AT_COMMAND_DISABLE_UART2 "AT+SQNHWCFG=\"uart2\",\"disable\"" |
| 30 | + |
| 31 | +#define AT_RESET "AT^RESET" |
| 32 | + |
| 33 | +#define RESPONSE_CONNECTION_STATUS_SIZE 96 |
21 | 34 |
|
22 | 35 | // Command without arguments: 18 bytes |
23 | 36 | // Both arguments within the quotes are strings of 8 numbers: 8 * 2 = 16 bytes |
|
55 | 68 |
|
56 | 69 | #ifdef __AVR_AVR128DB48__ // MINI |
57 | 70 |
|
58 | | -#define RING_PORT VPORTC |
| 71 | +#define RING_PORT PORTC |
59 | 72 | #define RING_PIN_bm PIN6_bm |
60 | 73 |
|
61 | 74 | #define LOWQ_PIN PIN_PB4 |
|
66 | 79 |
|
67 | 80 | #ifdef __AVR_AVR128DB64__ // Non-Mini |
68 | 81 |
|
69 | | -#define RING_PORT VPORTC |
| 82 | +#define RING_PORT PORTC |
70 | 83 | #define RING_PIN_bm PIN4_bm |
71 | 84 |
|
72 | 85 | #define LOWQ_PIN PIN_PB4 |
@@ -242,11 +255,10 @@ static uint32_t retrieveOperatorSleepTime(void) { |
242 | 255 |
|
243 | 256 | // First we call CEREG in order to get the byte where the sleep time is |
244 | 257 | // encoded |
245 | | - SequansController.clearReceiveBuffer(); |
246 | | - SequansController.writeCommand(AT_COMMAND_CONNECTION_STATUS); |
247 | | - |
248 | 258 | char response[RESPONSE_CONNECTION_STATUS_SIZE] = ""; |
249 | | - const ResponseResult response_result = SequansController.readResponse( |
| 259 | + SequansController.clearReceiveBuffer(); |
| 260 | + const ResponseResult response_result = SequansController.writeCommand( |
| 261 | + AT_COMMAND_CONNECTION_STATUS, |
250 | 262 | response, |
251 | 263 | RESPONSE_CONNECTION_STATUS_SIZE); |
252 | 264 |
|
@@ -658,6 +670,33 @@ void LowPowerClass::configurePeriodicPowerSave( |
658 | 670 | SequansController.begin(); |
659 | 671 | } |
660 | 672 |
|
| 673 | + // First we need to enter manufactoring mode to disable wake up sources |
| 674 | + SequansController.writeCommand(AT_COMMAND_ENTER_MANUFACTURING_MODE); |
| 675 | + |
| 676 | + // Disable all the wake sources except RTS0 (which is on by default) |
| 677 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_RTS1); |
| 678 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_SIM0); |
| 679 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE0); |
| 680 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE1); |
| 681 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE2); |
| 682 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE3); |
| 683 | + SequansController.writeCommand(AT_COMMAND_DISABLE_WAKE_ON_WAKE4); |
| 684 | + |
| 685 | + // Disable the other UARTs on the modem in case the message buffers |
| 686 | + // within these UARTs prevent the modem to sleep |
| 687 | + SequansController.writeCommand(AT_COMMAND_DISABLE_UART1); |
| 688 | + SequansController.writeCommand(AT_COMMAND_DISABLE_UART2); |
| 689 | + |
| 690 | + // Now we need to issue a reset to get back into regular mode |
| 691 | + SequansController.writeCommand(AT_RESET); |
| 692 | + |
| 693 | + // Wait for the modem to boot again |
| 694 | + SequansController.waitForURC("SYSSTART"); |
| 695 | + |
| 696 | + // Set device to sleep when RTS0 is pulled high. By default the modem will |
| 697 | + // sleep if RTS0, RTS1 and RTS2 are pulled high, so we want to change that |
| 698 | + SequansController.writeCommand(AT_COMMAND_SET_RTS0_HIGH_TRIGGERS_SLEEP); |
| 699 | + |
661 | 700 | // Disable EDRX as we use PSM |
662 | 701 | SequansController.writeCommand(AT_COMMAND_DISABLE_EDRX); |
663 | 702 |
|
@@ -722,7 +761,7 @@ void LowPowerClass::powerSave(void) { |
722 | 761 | } |
723 | 762 | } |
724 | 763 |
|
725 | | - if (!attemptToEnterPowerSaveModeForModem(30000)) { |
| 764 | + if (!attemptToEnterPowerSaveModeForModem(45000)) { |
726 | 765 | Log.error( |
727 | 766 | "Failed to put cellular modem in sleep. Power save functionality " |
728 | 767 | "might not be available for your operator."); |
|
0 commit comments