Update ESM test app to call Sciclient_init REL.CORESDK.07.03.00.25
authorAngela Stegmaier <angelabaker@ti.com>
Fri, 19 Mar 2021 22:01:41 +0000 (17:01 -0500)
committerSujith Shivalingappa <sujith.s@ti.com>
Tue, 23 Mar 2021 06:13:46 +0000 (01:13 -0500)
ESM test app was calling Sciclient APIs without first calling
Sciclient_init. This led to a failure being returned from
Sciclient_rmGetModuleClkFreq and incorrectly calculated minimum
time interval for the error pin.

This patch fixes the error checking around the Sciclient_* calls
in the test app, and also adds the call to Sciclient_init.

Signed-off-by: Angela Stegmaier <angelabaker@ti.com>
packages/ti/diag/examples/esm_example_app/esm.c
packages/ti/diag/examples/esm_example_app/event_trig.c

index 86397d1aad2ff98cb818ba9bcb20905b1de24c3d..fa14f9fbb988c7486c18f08572fbc42826de7f97 100644 (file)
 /* For interrupt ID numbers */
 #include <ti/csl/soc/cslr_soc_intr.h>
 
+/* Sciclient */
+#include <ti/csl/csl_types.h>
+#include <ti/drv/sciclient/sciclient.h>
+
 /* Diagnostic example utility functions, e.g. print outputs */
 #include <diag_utils.h>
 #include <sdr_esm.h>
@@ -216,6 +220,7 @@ extern volatile uint8_t  currUseCase;
 int32_t ESM_Example_init (void)
 {
     int32_t retValue=0;
+    Sciclient_ConfigPrms_t config;
     SDR_Result result;
 
 #ifdef UART_PRINTF
@@ -225,6 +230,18 @@ int32_t ESM_Example_init (void)
 
     DIAG_printf("\nESM_Example_init: UART ready to print, proceeding with ESM Example init \n");
 
+    if (retValue == 0) {
+        /* Initialize Sciclient */
+        retValue = Sciclient_configPrmsInit(&config);
+        if (retValue == CSL_PASS) {
+            retValue = Sciclient_init(&config);
+        }
+        if (retValue != CSL_PASS) {
+            DIAG_printf("ESM_Example_init: Error initializing Sciclient: result = %d\n", retValue);
+            retValue = -1;
+        }
+    }
+
     if (retValue == 0) {
         /* Initialize MCU ESM module */
         result = SDR_ESM_init(SDR_ESM_INSTANCE_MCU, &ESM_Example_esmInitConfig_MCU);
index 2a1b2af83a241a73d2d254a8f699fef6d5394e09..bd2aee6f471dc39436a9846f159f64358516118d 100644 (file)
@@ -165,30 +165,39 @@ int32_t esmPinTimeInit(uint32_t pinClearTime)
                                           clkId,
                                           &esmInputClk,
                                           SCICLIENT_SERVICE_WAIT_FOREVER);
+    if (retVal == CSL_PASS) {
 #ifdef PRINT_DEBUG
-    DIAG_printf("  WKUP ESM input clock is %d\n", esmInputClk);
+        DIAG_printf("  WKUP ESM input clock is %d\n", esmInputClk);
 #endif
-    /* MCU ESM clock */
-    modId = TISCI_DEV_MCU_ESM0;
-    clkId = TISCI_DEV_MCU_ESM0_CLK;
-
-    retVal = Sciclient_pmGetModuleClkFreq(modId,
-                                          clkId,
-                                          &esmInputClk,
-                                          SCICLIENT_SERVICE_WAIT_FOREVER);
+        /* MCU ESM clock */
+        modId = TISCI_DEV_MCU_ESM0;
+        clkId = TISCI_DEV_MCU_ESM0_CLK;
+
+        retVal = Sciclient_pmGetModuleClkFreq(modId,
+                                              clkId,
+                                              &esmInputClk,
+                                              SCICLIENT_SERVICE_WAIT_FOREVER);
+        if (retVal == CSL_PASS) {
 #ifdef PRINT_DEBUG
-    DIAG_printf("  MCU ESM input clock is %d\n", esmInputClk);
+            DIAG_printf("  MCU ESM input clock is %d\n", esmInputClk);
 #endif
+        }
+    }
 
-    /* Translate Pin Timer Time (microseconds) into number of ESM cycles */
-    pinClearTimeCycles = (uint32_t)((float)pinClearTime /
-                         1000000 * (float)esmInputClk);
-    DIAG_printf("\n  Any clear of MCU_SAFETY_ERRORn pin will first wait " \
-                "%d usecs", pinClearTime);
-    /* Translate Minimum Time Interval (cycles) into time (microseconds)*/
-    esmPinMinIntervalUsec = (uint32_t)((float)esmPinMinIntervalCycles /
-                                       (float)esmInputClk * 1000000);
-    DIAG_printf("\n  Minimum Time Interval is %d usecs", esmPinMinIntervalUsec);
+    if (retVal == CSL_PASS) {
+        /* Translate Pin Timer Time (microseconds) into number of ESM cycles */
+        pinClearTimeCycles = (uint32_t)((float)pinClearTime /
+                             1000000 * (float)esmInputClk);
+        DIAG_printf("\n  Any clear of MCU_SAFETY_ERRORn pin will first wait " \
+                    "%d usecs", pinClearTime);
+        /* Translate Minimum Time Interval (cycles) into time (microseconds)*/
+        esmPinMinIntervalUsec = (uint32_t)((float)esmPinMinIntervalCycles /
+                                           (float)esmInputClk * 1000000);
+        DIAG_printf("\n  Minimum Time Interval is %d usecs", esmPinMinIntervalUsec);
+    }
+    else {
+        retVal = -1;
+    }
 
     /* If desired, ESMSetErrPinLowTimePreload can be used to change
      * minimum interval time here */
@@ -261,7 +270,10 @@ int32_t diag_esm_timerInit(void)
        return -1;
     }
 
-    esmPinTimeInit(PIN_CLEAR_PERIOD_USEC);
+    if (esmPinTimeInit(PIN_CLEAR_PERIOD_USEC) != 0) {
+       DIAG_printf("ERR: Pin Time Init failed\n");
+       return -1;
+    }
 
     DIAG_printf("\nESM example timer initialization complete\n");