]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/blobdiff - packages/ti/osal/src/nonos/timer/v1/TimerP_nonos.c
[PDK-6649] OSAL: nonos: Fix TimerP_delete to update gTimerAnyMask
[processor-sdk/pdk.git] / packages / ti / osal / src / nonos / timer / v1 / TimerP_nonos.c
old mode 100644 (file)
new mode 100755 (executable)
index 70d23a0..d9c5b83
@@ -101,7 +101,7 @@ typedef struct TimerP_Struct_s
  * The TimerP_Struct pool servers to get an available timer
  * handle during timer create API call.
  */
-TimerP_Struct gTimerStructs[OSAL_NONOS_CONFIGNUM_TIMER];
+TimerP_Struct gTimerStructs[OSAL_NONOS_CONFIGNUM_TIMER] = {0U};
 static        uint32_t    gTimerInitDone = 0U;
 static        uint32_t    gTimerAnyMask;
 #if defined (BUILD_MCU)
@@ -544,7 +544,7 @@ static TimerP_Status TimerP_dmTimerInstanceInit(TimerP_Struct *timer, uint32_t i
 
     HwiP_restore(key);
 
-    if (tempId == 0xffffU) {
+    if ((tempId == 0xffffU) || (0x0 == baseAddr)) {
       ret = TimerP_NOT_AVAILABLE;
     }
   }
@@ -559,6 +559,15 @@ static TimerP_Status TimerP_dmTimerInstanceInit(TimerP_Struct *timer, uint32_t i
   {
     if (timer->tickFxn != (TimerP_Fxn) NULL_PTR)
     {
+      /* PDK-6534 If the timers were indeed running (left running from previous)
+            op. The provided ISR could be invoked at un-expected time.
+            Ensure to reset the timer */
+
+      /* tiocpCfg is populated by tiocpCfg */
+      if ((timer->tiocpCfg & TIMERP_DM_TIOCP_CFG_SOFTRESET_FLAG) > 0U) {
+       (void)TIMERReset(baseAddr);
+      }
+
       intNum          = timer->intNum;
       /* Initialize with defaults */
       Osal_RegisterInterrupt_initParams(&interruptRegParams);
@@ -569,7 +578,7 @@ static TimerP_Status TimerP_dmTimerInstanceInit(TimerP_Struct *timer, uint32_t i
       interruptRegParams.corepacConfig.isrRoutine=TimerP_dmTimerStub;
 
 #if defined (__ARM_ARCH_7A__) || defined (__aarch64__) || defined (__TI_ARM_V7R4__)
-#if defined(SOC_AM335x) || defined(SOC_AM437x) || defined(SOC_AM65XX) || defined(SOC_J721E) || defined(SOC_J7200)
+#if defined(SOC_AM335x) || defined(SOC_AM437x) || defined(SOC_AM65XX) || defined(SOC_J721E) || defined(SOC_J7200) || defined(SOC_AM64X)
       interruptRegParams.corepacConfig.triggerSensitivity =  (uint32_t)OSAL_ARM_GIC_TRIG_TYPE_HIGH_LEVEL;
       interruptRegParams.corepacConfig.priority = 0x20U;
 #else
@@ -725,31 +734,48 @@ TimerP_Status TimerP_delete(TimerP_Handle handle)
 {
     /* Release or free the memory */
     uint32_t key;
+    uint32_t id;
     uint32_t index = (uint32_t)(( ((uintptr_t) handle) - ((uintptr_t) gTimerStructs) )/sizeof(TimerP_Struct)); /* struct subtraction */
     TimerP_Status ret = TimerP_OK;
     TimerP_Struct *timer = (TimerP_Struct *) handle;
     TIMOSAL_Assert((handle == NULL_PTR));
 
-    if(timer != NULL_PTR)
+    key = (uint32_t)HwiP_disable();
+
+    if((timer != NULL_PTR) && ((gTimerStructs[index].used) == (bool)true))
     {
       /* clear the ISR that was set before */
-      (void)HwiP_delete(timer->hwi);
-
-      key = (uint32_t)HwiP_disable();
+      if(timer->hwi != NULL_PTR) 
+      {
+        (void)HwiP_delete(timer->hwi);
+      }
+      
+      /* reset the timer's bit field in the mask and clear the used flag */
       gTimerStructs[index].used = (bool)false;
+      id = gTimerStructs[index].timerId;
+      uint32_t shift = ((uint32_t) 1u) << id;
+      if(((gTimerAnyMask & shift)) == 0U)
+      {
+        gTimerAnyMask |= shift;
+      }
+      else
+      {
+        ret = TimerP_FAILURE;  
+      }
+
       /* Found the osal timer object to delete */
       if (gOsalTimerAllocCnt > 0U)
       {
         gOsalTimerAllocCnt--;
       }
-      HwiP_restore(key);
-      ret = TimerP_OK; 
     } 
     else
     {
       ret = TimerP_FAILURE;    
     }
 
+    HwiP_restore(key);
+
     return (ret);
 }
 
@@ -764,7 +790,7 @@ TimerP_Status TimerP_start(TimerP_Handle handle)
   TimerP_Struct *timer = (TimerP_Struct *) handle;
   uint32_t max_period = (uint32_t) 0xffffffffU;
   TimerP_Status retVal = TimerP_OK;
-  
+  uint32_t  eventId;
   uint32_t baseAddr = TimerP_getTimerBaseAddr(timer->timerId);
 
   if (baseAddr == 0U) {
@@ -795,8 +821,16 @@ TimerP_Status TimerP_start(TimerP_Handle handle)
   } while (status != (uint32_t) 0u);
 
   if(timer->hwi != NULL_PTR) {
-    HwiP_clearInterrupt(timer->intNum);
-    HwiP_enableInterrupt(timer->intNum);
+#if defined (_TMS320C6X)
+    eventId = timer->eventId;
+#else
+    eventId = 0u;
+#endif
+    Osal_ClearInterrupt(eventId, timer->intNum);
+    Osal_EnableInterrupt(eventId, timer->intNum);
+  }
+  else {
+      retVal = TimerP_FAILURE;
   }
 
   if (timer->runMode == (uint32_t)TimerP_RunMode_CONTINUOUS) {
@@ -809,14 +843,15 @@ TimerP_Status TimerP_start(TimerP_Handle handle)
       runMode = TIMERP_DM_TCLR_START_DYNAMIC;
   }
 
-  (void)TIMERModeConfigure(baseAddr, runMode);
-
-  do {
-    status = (TIMERWritePostedStatusGet(baseAddr) & TIMERP_DM_TWPS_W_PEND_TCLR);
-  } while (status != (uint32_t) 0u);
+  if (retVal == TimerP_OK) {
+      (void)TIMERModeConfigure(baseAddr, runMode);
 
-  (void)TIMEREnable(baseAddr);
+      do {
+        status = (TIMERWritePostedStatusGet(baseAddr) & TIMERP_DM_TWPS_W_PEND_TCLR);
+      } while (status != (uint32_t) 0u);
 
+      (void)TIMEREnable(baseAddr);
+  }
   HwiP_restore(key);
   }
   return (retVal);
@@ -832,7 +867,7 @@ TimerP_Status TimerP_stop(TimerP_Handle handle)
   uint32_t  tisr, status;
   TimerP_Struct *timer = (TimerP_Struct *) handle;
   TimerP_Status retVal = TimerP_OK;
-  
+  uint32_t eventId;
   uint32_t baseAddr = TimerP_getTimerBaseAddr(timer->timerId);
 
   if (baseAddr == 0U) {
@@ -849,9 +884,23 @@ TimerP_Status TimerP_stop(TimerP_Handle handle)
 
     tisr = TIMERIntStatusGet(baseAddr);
 
+
     if(tisr > 0U) {
-    /* Clear all pending interrupts */
-    (void)TIMERIntStatusClear(baseAddr, tisr);
+      /* Clear all pending interrupts */
+      (void)TIMERIntStatusClear(baseAddr, tisr);
+    }
+
+    if(timer->hwi != NULL_PTR) {
+#if defined (_TMS320C6X)
+      eventId = timer->eventId;
+#else
+      eventId = 0u;
+#endif
+      Osal_ClearInterrupt(eventId, timer->intNum);
+      Osal_DisableInterrupt(eventId, timer->intNum);
+    }
+    else {
+        retVal = TimerP_FAILURE;
     }
   }
   return(retVal);
@@ -876,7 +925,7 @@ uint64_t TimerP_getTimeInUsecs(void)
 {
     TimeStamp_Struct timestamp64;
     uint64_t         cur_ts, freq;
-    uint32_t             tsFreqKHz;
+    uint32_t         tsFreqKHz;
 
     /* Get the timestamp */
     osalArch_TimestampGet64(&timestamp64);