diff src/cs/layer1/cust0/l1_cust.c @ 148:c47e2dc10134

l1_pwmgr.c & l1_cust.c: sleep logic changes from Magnetite
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 06 Feb 2019 23:15:04 +0000
parents b6a5e36de839
children
line wrap: on
line diff
--- a/src/cs/layer1/cust0/l1_cust.c	Wed Feb 06 23:00:51 2019 +0000
+++ b/src/cs/layer1/cust0/l1_cust.c	Wed Feb 06 23:15:04 2019 +0000
@@ -254,68 +254,58 @@
 #ifdef RVM_FCHG_SWE
   extern T_PWR_CTRL_BLOCK *pwr_ctrl;
 #endif
+  extern SYS_BOOL uart_sleep_timer_enabled;
 
 #if (CODE_VERSION != SIMULATION)
-#if (L2_L3_SIMUL == 0)
+
+    //cut ARMIO and UWIRE clocks in big sleep
+    l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT;
 
 #ifdef RVM_FCHG_SWE
     // Forbig deep sleep when charging
     if (pwr_ctrl && pwr_ctrl->state >= FCHG_STATE_I2V_CAL_1 &&
         pwr_ctrl->state <= FCHG_STATE_CV_CHARGING)
     {
-      //cut ARMIO and UWIRE clocks in big sleep
-      l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ;
       why_big_sleep = BIG_SLEEP_DUE_TO_CHARGING;
       return(FRAME_STOP);  // BIG sleep
     }
 #endif
 
     // Forbid deep sleep if the light is on
-    if(LT_Status())
+    if (LT_Status())
     {
-      //cut ARMIO and UWIRE clocks in big sleep
-      l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ;
       why_big_sleep = BIG_SLEEP_DUE_TO_LIGHT_ON;
       return(FRAME_STOP);  // BIG sleep
     }
 
     // Forbid deep sleep if the SIM and UARTs not ready
-    if(SIM_SleepStatus())
+    if (!SIM_SleepStatus())
+    {
+      why_big_sleep = BIG_SLEEP_DUE_TO_SIM;
+      return(FRAME_STOP);  // BIG sleep
+    }
+
+    /* FreeCalypso: check UART activity timer */
+    if (uart_sleep_timer_enabled)
     {
-#endif
+      why_big_sleep = BIG_SLEEP_DUE_TO_UART;
+      return(FRAME_STOP);  // BIG sleep
+    }
+
+    if ((l1s.pw_mgr.mode_authorized == DEEP_SLEEP) ||
+        (l1s.pw_mgr.mode_authorized == ALL_SLEEP))
+    {
       if(SER_UartSleepStatus()) 
-      {
         return(CLOCK_STOP);   // DEEP sleep
-      }
-      else why_big_sleep = BIG_SLEEP_DUE_TO_UART;
-#if (L2_L3_SIMUL == 0)
-   }
-   else why_big_sleep = BIG_SLEEP_DUE_TO_SIM;
-#endif
-        // cut ARMIO and UWIRE clocks in big sleep
-        l1s.pw_mgr.modules_status = ARMIO_CLK_CUT | UWIRE_CLK_CUT ;
-	/*
-	 * FreeCalypso change: in TI's original code, whenever
-	 * this Cust_check_system() function returns FRAME_STOP
-	 * instead of CLOCK_STOP, l1s_sleep_manager() would
-	 * abstain from all sleep and not just from deep sleep.
-	 * The comments there say that the intent is to avoid
-	 * big sleep when there is UART or SIM activity,
-	 * but the result is that when we tell L1 to do big sleep
-	 * instead of deep sleep because of the backlight or
-	 * charging, it doesn't sleep at all, except small sleep
-	 * via Nucleus idle loop.
-	 *
-	 * Our change preserves TI's abstention from big sleep
-	 * due to UART or SIM activity, but allows big sleep when
-	 * the cause is light or charging.  We've changed this
-	 * Cust_check_system() function to return DO_NOT_SLEEP
-	 * instead of FRAME_STOP for UART and SIM, while still
-	 * returning FRAME_STOP for light and charging, and
-	 * changed the code in l1s_sleep_manager() to do big sleep
-	 * when this Cust_check_system() function returns FRAME_STOP.
-	 */
-        return(DO_NOT_SLEEP);  // NO sleep
+      else
+        return(DO_NOT_SLEEP); /* wait another frame or two */
+    }
+    else
+    {
+      why_big_sleep = BIG_SLEEP_DUE_TO_SLEEP_MODE;
+      return(FRAME_STOP);  // BIG sleep
+    }
+
 #else // Simulation part
   return(CLOCK_STOP);   // DEEP sleep
 #endif