]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/commitdiff
[J7200][LPM]: Remove Race condition in IO retention app
authorChandru Dhavamani <chandru@ti.com>
Thu, 8 Dec 2022 06:41:45 +0000 (12:11 +0530)
committerChandru Dhavamani <chandru@ti.com>
Fri, 9 Dec 2022 08:14:10 +0000 (13:44 +0530)
Remove race condition which results in dead-sleep condition

Signed-off-by: Chandru Dhavamani <chandru@ti.com>
packages/ti/drv/lpm/examples/lpm_io_retention/src/main_rtos.c
packages/ti/drv/lpm/src/lpm_pmic.c

index c568bc10aac2cbfabb84b2b912108036e54f7da6..43ba0530bbab4041234be177705403ed83f15e73 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *
-* Copyright (c) 2021 Texas Instruments Incorporated
+* Copyright (c) 2021-22 Texas Instruments Incorporated
 *
 * All rights reserved not granted herein.
 *
@@ -89,6 +89,8 @@ Board_I2cInitCfg_t boardI2cInitCfg = {0, BOARD_SOC_DOMAIN_WKUP, false};
 /**< Stack required for the stack */
 #define MAIN_APP_TASK_PRIORITY          (2)
 
+/* Enable to pause before entering the low power mode and check the PADCONF values*/
+#define PAUSE_BEFORE_ENTERING_LPM        (0)
 
 /*********************************  *************************************
  ************************** Internal functions ************************
@@ -369,13 +371,13 @@ void wkup_configure_can_uart_lock_dmsc()
     *mkptr(CSL_STD_FW_WKUP_DMSC0_PWRCTRL_0_DMSC_PWR_MMR_PWR_START, DMSC_CM_LOCK0_KICK0) = 0x0;
     *mkptr(CSL_STD_FW_WKUP_DMSC0_PWRCTRL_0_DMSC_PWR_MMR_PWR_START, DMSC_CM_LOCK0_KICK1) = 0x0;
 
-/* Pause before entering the low power mode and check the PADCONF values*/
-#if 0
-    UART_printf("PADCONFIG52 (0x4301c0d0) immediately after entering IO retention : 0x%x\n", *mkptr(CSL_WKUP_CTRL_MMR0_CFG0_BASE, 0x1c0d0);
-    AppUtils_Printf(MSG_NORMAL, "Press enter key to send I2C commands to PMIC to enter low power mode... ");
-    int c;
-    UART_scanFmt("%d", &c);
-#endif
+    if(PAUSE_BEFORE_ENTERING_LPM)
+    {
+        int c;
+        UART_printf("PADCONFIG52 (0x4301c0d0) immediately after entering IO retention : 0x%x\n", *mkptr(CSL_WKUP_CTRL_MMR0_CFG0_BASE, 0x1c0d0));
+        AppUtils_Printf(MSG_NORMAL, "Press enter key to send I2C commands to PMIC to enter low power mode... ");
+        UART_scanFmt("%d", &c);
+    }
 }
 
 
index c3e1691722325daaa4fe54dd4d54a25d3e84febb..95a95e3efe5cca250c09bcc6dd958f8f288cdff1 100644 (file)
@@ -1,6 +1,6 @@
 /*
 *
-* Copyright (c) 2021 Texas Instruments Incorporated
+* Copyright (c) 2021-22 Texas Instruments Incorporated
 *
 * All rights reserved not granted herein.
 *
@@ -2228,6 +2228,7 @@ void Lpm_pmicStateChangeActiveToIORetention(void)
      */
 
     uint8_t dataToSlave[2];
+       uint8_t dataFromSlave[2];
 
     if(loopPMICStateChangeActiveToIORetention == 0xFEEDFACE)
     {
@@ -2268,25 +2269,70 @@ void Lpm_pmicStateChangeActiveToIORetention(void)
     dataToSlave[1] = 0xF7;
     Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x48, dataToSlave, 2, NULL, 0);
     AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME "Write MASK_GPIO1_8_FALL = 0x%x\n", dataToSlave[1]);
+       
+       /* Pause after unmask GPIO4 but before read 0x3F for nINT */
+    {
+        int c;
+        AppUtils_Printf(MSG_NORMAL, "Lpm_pmicStateChangeActiveToIORetention: Press enter key to send I2C commands to PMIC to enter low power mode...before STEP4A ");
+        /* Using UART_scanFmt control will wait till user enters key
+         Unmask of GPIO4 can be checked */
+        UART_scanFmt("%d", &c);
+    }
 
+    /* Read back Register 0x3F from PMIC A, check bit 3 if low then exit (to be implemented) */        
+       dataToSlave[0] = 0x3F;
+    Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x48, dataToSlave, 1, dataFromSlave, 1);
+    AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME "PMICA_REG_0x3F = 0x%x\n", dataFromSlave[0]);
+       
+    /* clear nINT to allow PMIC go to IORET */
+    {
+        int c;
+        AppUtils_Printf(MSG_NORMAL, "Lpm_pmicStateChangeActiveToIORetention: Press enter key to clear nINT ");
+        /*Check the nINT beofre clear at this point */
+        UART_scanFmt("%d", &c);
+        dataToSlave[0] = 0x64;
+        dataToSlave[1] = 0x08;
+        Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x48, dataToSlave, 2, NULL, 0);
+    }
     /* Change FSM_I2C_TRIGGERS */
     dataToSlave[0] = 0x85;
     dataToSlave[1] = 0x40;
     Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x48, dataToSlave, 2, NULL, 0);
     AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME "Write FSM_I2C_TRIGGERS = 0x%x\n", dataToSlave[1]);
-
+       
     /* Change FSM_I2C_TRIGGERS - PMICB */
     dataToSlave[0] = 0x85;
     dataToSlave[1] = 0x40;
     Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x4C, dataToSlave, 2, NULL, 0);
     AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME "Write FSM_NSLEEP_TRIGGERS = 0x%x\n", dataToSlave[1]);
 
+    /* Pause before send I2C commands to PMIC to enter low power mode. */
+    {
+        int c;
+        AppUtils_Printf(MSG_NORMAL, "Lpm_pmicStateChangeActiveToIORetention: Press enter key to send I2C commands to PMIC to enter low power mode...immediately before STEP6 (gotoioret)");
+        /* Wait till user enter key Memory values before sending I@C commands can be checked */
+        UART_scanFmt("%d", &c);
+    }
+
     /* Change FSM_NSLEEP_TRIGGERS */
     dataToSlave[0] = 0x86;
     dataToSlave[1] = 0x00;
     Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x48, dataToSlave, 2, NULL, 0);
     AppUtils_Printf(MSG_NORMAL, MSG_APP_NAME "Write FSM_NSLEEP_TRIGGERS = 0x%x\n", dataToSlave[1]);
 
+    /* JWTBD clear nINT to allow PMIC go to IORET, if there is pre-existing interrupt on GPIO4 */
+    {
+        int c;
+        AppUtils_Printf(MSG_NORMAL, "GPIO4 interrupt PENDING, device can not go into IORET: Press any key to clear... ");
+        UART_scanFmt("%d", &c);
+        AppUtils_Printf(MSG_NORMAL, "Clearing GPIO4 pending interrupt to allow entering IORET: Good Night!");
+        dataToSlave[0] = 0x64;
+        dataToSlave[1] = 0x08;
+        Lpm_setupI2CTransfer(gLpmPmicI2cHandle, 0x48, dataToSlave, 2, NULL, 0);
+        AppUtils_Printf(MSG_NORMAL, "signing off!"); //this line should not execute
+    }
+
     return;
 }
 #endif