comparison src/cs/layer1/cfile/l1_pwmgr.c @ 561:dc1e0a1c100f

sleep logic change: allow big sleep when UART or SIM is blocking deep sleep
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 06 Jan 2019 21:12:51 +0000
parents daddb933047d
children b24d42baa30d
comparison
equal deleted inserted replaced
560:d380b62e1019 561:dc1e0a1c100f
780 WORD32 afc_fix; 780 WORD32 afc_fix;
781 static UWORD32 previous_sleep = CLOCK_STOP; 781 static UWORD32 previous_sleep = CLOCK_STOP;
782 #if (W_A_CALYPSO_PLUS_SPR_19599 == 1) 782 #if (W_A_CALYPSO_PLUS_SPR_19599 == 1)
783 BOOL extended_page_mode_state = 0; //Store state of extended page mode 783 BOOL extended_page_mode_state = 0; //Store state of extended page mode
784 #endif 784 #endif
785 WORD32 time_from_last_wakeup=0; 785 WORD32 time_from_last_wakeup, min_time_from_last_wakeup;
786 UWORD32 sleep_mode; 786 UWORD32 sleep_mode;
787 787
788 #if (OP_BT == 1) 788 #if (OP_BT == 1)
789 WORD32 hci_ll_status; 789 WORD32 hci_ll_status;
790 #endif 790 #endif
791 791
792 // init for trace and debug 792 // init for trace and debug
793 why_big_sleep = BIG_SLEEP_DUE_TO_UNDEFINED; 793 why_big_sleep = BIG_SLEEP_DUE_TO_UNDEFINED;
794 wakeup_type = WAKEUP_FOR_UNDEFINED; 794 wakeup_type = WAKEUP_FOR_UNDEFINED;
795 795
796 /*
797 * FreeCalypso change: TI's original code implemented logic to
798 * suppress both big and deep sleep (i.e., retry on the next frame)
799 * if less than 7 frames have elapsed since the last wakeup and
800 * if the previous sleep cycle was CLOCK_STOP. We are changing
801 * this logic in two ways: the check has been moved up here
802 * (originally the check code was way down, wasting work on other
803 * logic if there will be no sleep anyway), and we additionally
804 * suppress both big and deep sleep (effecting retry on the next
805 * frame) if the previous sleep cycle was FRAME_STOP and less than
806 * 5 frames have elapsed since wakeup. The reason for the latter
807 * addition is that we now allow big sleep while UART and/or SIM
808 * activity timers are running (suppressing deep sleep), and
809 * holding off for 5 frames before going into another big sleep
810 * keeps us from fluttering in and out of big sleep as the external
811 * host or the SIM is trying to talk to us.
812 */
796 time_from_last_wakeup = (sleep_time - last_wakeup + 42432) % 42432; 813 time_from_last_wakeup = (sleep_time - last_wakeup + 42432) % 42432;
814
815 if (previous_sleep == CLOCK_STOP)
816 min_time_from_last_wakeup = 7;
817 else
818 min_time_from_last_wakeup = 5;
819
820 if (time_from_last_wakeup < min_time_from_last_wakeup)
821 return;
797 822
798 //================================================= 823 //=================================================
799 // check System (SIM, UART, LDC ..... ) 824 // check System (SIM, UART, LDC ..... )
800 //================================================= 825 //=================================================
801 sleep_mode = Cust_check_system(); 826 sleep_mode = Cust_check_system();
842 // 0 means immediate activity 867 // 0 means immediate activity
843 // in case big sleep is choosen (sleep mode == FRAME_STOP) because of UART or SIM, 868 // in case big sleep is choosen (sleep mode == FRAME_STOP) because of UART or SIM,
844 // return and wait end of this activity (few TDMA frames) then check on next TDMA frames 869 // return and wait end of this activity (few TDMA frames) then check on next TDMA frames
845 // if MS can go in deep sleep 870 // if MS can go in deep sleep
846 /* 871 /*
847 * FreeCalypso change: the abstention from big sleep because of UART or SIM 872 * FreeCalypso change: we no longer abstain from big sleep because of UART
848 * has been moved into Cust_check_system(), which now returns DO_NOT_SLEEP 873 * and SIM activity timers, i.e., when deep sleep is suppressed because of
849 * in these cases, while still returning FRAME_STOP if the cause is 874 * either of those, we go into big sleep instead. We also do big sleep
850 * the backlight or charging. 875 * if deep sleep is disallowed because of the backlight or charging.
876 * However, if the UART issue is not the running activity timer, but some
877 * output being drained from the Tx FIFO, for that case our new code in
878 * Cust_check_system() will return DO_NOT_SLEEP (checked above), causing
879 * us to retry on the next frame and hopefully go into deep sleep after
880 * another frame or two.
851 */ 881 */
852 if ( !min_time 882 if ( !min_time
853 || !HWtimer 883 || !HWtimer
854 || !min_time_gauging 884 || !min_time_gauging
855 #if 0 /* FreeCalypso change */ 885 #if 0 /* FreeCalypso change */
931 if ( ((l1s.pw_mgr.mode_authorized == BIG_SLEEP) && (sleep_mode >= FRAME_STOP)) || 961 if ( ((l1s.pw_mgr.mode_authorized == BIG_SLEEP) && (sleep_mode >= FRAME_STOP)) ||
932 ((l1s.pw_mgr.mode_authorized >= DEEP_SLEEP) && (sleep_mode == FRAME_STOP)) ) 962 ((l1s.pw_mgr.mode_authorized >= DEEP_SLEEP) && (sleep_mode == FRAME_STOP)) )
933 l1s.pw_mgr.sleep_performed = FRAME_STOP; 963 l1s.pw_mgr.sleep_performed = FRAME_STOP;
934 964
935 965
966 /* FreeCalypso change: check moved up and extended */
967 #if 0
936 if ((previous_sleep == CLOCK_STOP) && (time_from_last_wakeup < 7)) 968 if ((previous_sleep == CLOCK_STOP) && (time_from_last_wakeup < 7))
937 { 969 {
938 #if (CODE_VERSION != SIMULATION) 970 #if (CODE_VERSION != SIMULATION)
939 OS_system_Unprotect(); // free System structure 971 OS_system_Unprotect(); // free System structure
940 INT_EnableIRQ(); // Enable all IRQ 972 INT_EnableIRQ(); // Enable all IRQ
942 SER_WakeUpUarts(); // Wake up Uarts 974 SER_WakeUpUarts(); // Wake up Uarts
943 975
944 #endif // NOT SIMULATION 976 #endif // NOT SIMULATION
945 return; 977 return;
946 } 978 }
979 #endif
947 980
948 // update previous sleep 981 // update previous sleep
949 previous_sleep = l1s.pw_mgr.sleep_performed; 982 previous_sleep = l1s.pw_mgr.sleep_performed;
950 983
951 984