From 065b68075814ec1398a306a2c85ad30461c29338 Mon Sep 17 00:00:00 2001
From: Vishal Mahaveer <vishalm@ti.com>
Date: Wed, 27 May 2020 18:34:19 -0500
Subject: [PATCH 1/4] mcuss_demos: profiling: can: enable clocks explictly

---
 mcuss_demos/profiling/can/main_tirtos.c | 55 +++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/mcuss_demos/profiling/can/main_tirtos.c b/mcuss_demos/profiling/can/main_tirtos.c
index 32c0542..f59c6ab 100644
--- a/mcuss_demos/profiling/can/main_tirtos.c
+++ b/mcuss_demos/profiling/can/main_tirtos.c
@@ -88,6 +88,8 @@
 #include "can_profile.h"
 #include "CanIf.h"
 
+#include <ti/drv/sciclient/sciclient.h>
+
 /* ========================================================================== */
 /*                           Macros & Typedefs                                */
 /* ========================================================================== */
@@ -135,8 +137,61 @@ extern uint32 CanIf_DrvStatus;
 /*                          Function Definitions                              */
 /* ========================================================================== */
 
+
+/* Local API for enabling MCAN clocks.
+   Copied from board library.
+ */
+int32_t local_moduleClockEnable(uint32_t moduleId)
+{
+    int32_t retVal = 0;
+    int32_t status = -1;
+    uint32_t moduleState = 0U;
+    uint32_t resetState = 0U;
+    uint32_t contextLossState = 0U;
+
+    /* Get the module state.
+       No need to change the module state if it
+       is already ON
+     */
+    status = Sciclient_pmGetModuleState(moduleId,
+                                        &moduleState,
+                                        &resetState,
+                                        &contextLossState,
+                                        SCICLIENT_SERVICE_WAIT_FOREVER);
+    if(moduleState == TISCI_MSG_VALUE_DEVICE_HW_STATE_OFF)
+    {
+        status = Sciclient_pmSetModuleState(moduleId,
+                                            TISCI_MSG_VALUE_DEVICE_SW_STATE_ON,
+                                            (TISCI_MSG_FLAG_AOP |
+                                             TISCI_MSG_FLAG_DEVICE_RESET_ISO),
+                                             SCICLIENT_SERVICE_WAIT_FOREVER);
+        if (status == 0)
+        {
+            status = Sciclient_pmSetModuleRst (moduleId,
+                                               0x0U,
+                                               SCICLIENT_SERVICE_WAIT_FOREVER);
+            if (status != 0)
+            {
+                retVal = -1;
+            }
+        }
+        else
+        {
+            retVal = -1;
+        }
+    }
+
+    return retVal;
+}
+
 int main(void)
 {
+    /* Enable MCAN clocks */
+    local_moduleClockEnable(TISCI_DEV_MCAN0);
+    local_moduleClockEnable(TISCI_DEV_MCAN4);
+    local_moduleClockEnable(TISCI_DEV_MCAN9);
+    local_moduleClockEnable(TISCI_DEV_MCAN11);
+
     Task_Handle task;
     Error_Block eb;
     Task_Params taskParams;
-- 
2.26.2

