@@ -436,11 +436,9 @@ static void restorePinState(void) {
436436 * @brief Sets the pin state in order to minimize the power consumption. Will
437437 * not enable LDO.
438438 *
439- * @param keep_ring_active Whether to keep ring line active (used in PSM).
439+ * @param keep_modem_active Whether to keep modem lines active (used in PSM).
440440 */
441- static void powerDownPeripherals (const bool keep_ring_active) {
442-
443- // TODO: might keep SW0 in order to not mess with interrupt
441+ static void powerDownPeripherals (const bool keep_modem_active) {
444442
445443 savePinState ();
446444
@@ -508,14 +506,26 @@ static void powerDownPeripherals(const bool keep_ring_active) {
508506
509507 PORTA.DIR = 0x00 ;
510508 PORTB.DIR = PIN3_bm | PIN4_bm;
511- PORTC.DIR = 0x00 ;
509+
510+ if (keep_modem_active) {
511+ PORTC.DIRCLR = PIN2_bm | PIN3_bm;
512+ } else {
513+ PORTC.DIR = 0x00 ;
514+ }
515+
512516 PORTD.DIR = 0x00 ;
513517 PORTE.DIR = 0x00 ;
514518 PORTF.DIR = 0x00 ;
515519
516520 PORTA.OUT = 0x00 ;
517521 PORTB.OUT = 0x00 ;
518- PORTC.OUT = 0x00 ;
522+
523+ if (keep_modem_active) {
524+ PORTC.OUTCLR = PIN2_bm | PIN3_bm;
525+ } else {
526+ PORTC.OUT = 0x00 ;
527+ }
528+
519529 PORTD.OUT = 0x00 ;
520530 PORTE.OUT = 0x00 ;
521531 PORTF.OUT = 0x00 ;
@@ -538,18 +548,17 @@ static void powerDownPeripherals(const bool keep_ring_active) {
538548 PORTB.PIN6CTRL = 0x0C ;
539549 PORTB.PIN7CTRL = 0x0C ;
540550
541- PORTC.PIN0CTRL = 0x0C ;
542- PORTC.PIN1CTRL = 0x0C ;
543551 PORTC.PIN2CTRL = 0x04 ;
544552 PORTC.PIN3CTRL = 0x04 ;
545- PORTC.PIN4CTRL = 0x0C ;
546- PORTC.PIN5CTRL = 0x04 ;
547- if (keep_ring_active) {
548- PORTC.PIN6CTRL = 0x01 ;
549- } else {
553+
554+ if (!keep_modem_active) {
555+ PORTC.PIN0CTRL = 0x0C ;
556+ PORTC.PIN1CTRL = 0x0C ;
557+ PORTC.PIN4CTRL = 0x0C ;
558+ PORTC.PIN5CTRL = 0x04 ;
550559 PORTC.PIN6CTRL = 0x04 ;
560+ PORTC.PIN7CTRL = 0x04 ;
551561 }
552- PORTC.PIN7CTRL = 0x04 ;
553562
554563 PORTD.PIN0CTRL = 0x0C ;
555564 PORTD.PIN1CTRL = 0x0C ;
@@ -688,9 +697,6 @@ void LowPowerClass::configurePeriodicPowerSave(
688697
689698void LowPowerClass::powerSave (void ) {
690699
691- const uint8_t cell_led_state = digitalRead (LedCtrl.getLedPin (Led::CELL));
692- const uint8_t con_led_state = digitalRead (LedCtrl.getLedPin (Led::CON));
693-
694700 if (!retrieved_period) {
695701 // Retrieve the proper sleep time set by the operator, which may
696702 // deviate from what we requested
@@ -712,7 +718,7 @@ void LowPowerClass::powerSave(void) {
712718
713719 // Retrieving the operator sleep time will call CEREG, which will
714720 // trigger led ctrl, so we just disable it again.
715- LedCtrl.off (Led::CELL, true );
721+ // LedCtrl.off(Led::CELL, true);
716722 }
717723 if (!attemptToEnterPowerSaveModeForModem (30000 )) {
718724 Log.error (
@@ -724,55 +730,36 @@ void LowPowerClass::powerSave(void) {
724730 powerDownPeripherals (true );
725731 SLPCTRL.CTRLA |= SLPCTRL_SMODE_PDOWN_gc | SLPCTRL_SEN_bm;
726732
727- // enableLDO();
733+ enableLDO ();
728734 sleep_cpu ();
729735
730736 // Will sleep here until we get the RING line activity and wake up
731- // disableLDO();
737+ disableLDO ();
732738
733739 SLPCTRL.CTRLA &= ~SLPCTRL_SEN_bm;
734740 powerUpPeripherals ();
735741
736742 modem_is_in_power_save = false ;
737743 }
738744
739- SequansController.setPowerSaveMode (0 , NULL );
740-
741- // Pins are active low
742- if (!cell_led_state) {
743- LedCtrl.on (Led::CELL, true );
744- } else {
745- LedCtrl.off (Led::CELL, true );
746- }
745+ // LedCtrl.on(Led::CELL, true);
747746
748- if (!con_led_state) {
749- LedCtrl.on (Led::CON, true );
750- } else {
751- LedCtrl.off (Led::CON, true );
752- }
747+ SequansController.setPowerSaveMode (0 , NULL );
753748}
754749
755750void LowPowerClass::powerDown (const uint32_t power_down_time_seconds) {
756751
757- const unsigned long start_time_ms = millis ();
758-
759752 SLPCTRL.CTRLA |= SLPCTRL_SMODE_PDOWN_gc | SLPCTRL_SEN_bm;
760753
761754 Lte.end ();
762755
763- uint32_t remaining_time_seconds =
764- power_down_time_seconds -
765- (uint32_t )(((millis () - start_time_ms) / 1000 .0f ));
766-
767- // Need to power down the peripherals here as we want to grab the time
768- // (millis()) from the timer before disabling it
756+ // TODO: somehow this prevents the modem to sleep...
769757 powerDownPeripherals (false );
770758
771759 enablePIT ();
772760 enableLDO ();
773761
774- // TODO: might want to just have the remaining time in seconds to be the
775- // power_down_time_seconds to prevent issues with millis() overflowing
762+ uint32_t remaining_time_seconds = power_down_time_seconds;
776763
777764 while (remaining_time_seconds > 0 ) {
778765
@@ -793,7 +780,6 @@ void LowPowerClass::powerDown(const uint32_t power_down_time_seconds) {
793780
794781 powerUpPeripherals ();
795782
796- // TODO: should we keep this here?
797783 while (!Lte.begin ()) {}
798784}
799785
0 commit comments