]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/pdk.git/commitdiff
[PDK-9289] OSAL: KW Issues Fix
authorDon Dominic <a0486429@ti.com>
Thu, 24 Jun 2021 15:03:09 +0000 (20:33 +0530)
committerAnkur <ankurbaranwal@ti.com>
Fri, 25 Jun 2021 08:13:50 +0000 (03:13 -0500)
Signed-off-by: Don Dominic <a0486429@ti.com>
packages/ti/osal/src/freertos/ClockP_freertos.c
packages/ti/osal/src/freertos/MutexP_freertos.c
packages/ti/osal/src/tirtos/ClockP_tirtos.c
packages/ti/osal/src/tirtos/HeapP_tirtos.c
packages/ti/osal/src/tirtos/MailboxP_tirtos.c
packages/ti/osal/src/tirtos/MutexP_tirtos.c

index 7f0f580f11464e9296466cdbb5ec60496c6a4f17..c8074a9a83a071babb469af4673e423b615ae4be 100644 (file)
@@ -72,7 +72,7 @@ void ClockP_timerCallbackFunction(TimerHandle_t xTimer)
 {
     ClockP_freertos *pTimer = (ClockP_freertos *)pvTimerGetTimerID(xTimer);
 
-    if(pTimer->callback && pTimer != NULL_PTR)
+    if(pTimer != NULL_PTR && pTimer->callback)
     {
         pTimer->callback(pTimer->arg);
     }
index c3efa7cc705a96803161506258d43947375f676b..3a040e303a323c7d28a535d74de0e2d1c7232b1c 100644 (file)
@@ -65,7 +65,8 @@ static MutexP_freertos gOsalMutexPFreeRtosPool[OSAL_FREERTOS_CONFIGNUM_MUTEX];
 MutexP_Handle MutexP_create(MutexP_Object *mutexObj)
 {
     MutexP_Handle ret_handle = NULL;
-    MutexP_freertos *handle, * mutexPool;
+    MutexP_freertos *handle = (MutexP_freertos *) NULL_PTR;
+    MutexP_freertos *mutexPool;
     uint32_t i;
     uintptr_t key;
     uint32_t maxMutex;
index cb9d7892004202bdfb71de61135cfcc8ba93d97a..1d68fda5a56d8f9a14bad08e771ca18ef9b953ac 100644 (file)
@@ -59,7 +59,7 @@ void ClockP_Params_init(ClockP_Params *params)
 ClockP_Handle ClockP_create(void *clockfxn,
                             const ClockP_Params *params)
 {
-    Clock_Handle clockHandle;
+    Clock_Handle clockHandle = NULL_PTR;
     Clock_Params clockParams;
     Error_Block  *pErrBlk = (Error_Block *) NULL_PTR;
 
@@ -78,14 +78,14 @@ ClockP_Handle ClockP_create(void *clockfxn,
         }
         clockParams.arg = (xdc_UArg)params->arg;
         pErrBlk = (Error_Block *) params->pErrBlk;
-    }
 
-    if (pErrBlk !=  NULL_PTR)
-    {
-        Error_init(pErrBlk);
-    }
+        if (pErrBlk !=  NULL_PTR)
+        {
+            Error_init(pErrBlk);
+        }
 
-    clockHandle = Clock_create((Clock_FuncPtr)clockfxn, params->period, &clockParams, pErrBlk);
+        clockHandle = Clock_create((Clock_FuncPtr)clockfxn, params->period, &clockParams, pErrBlk);
+    }
 
     return ((ClockP_Handle)clockHandle);
 }
index b2b7216f8160ca2673429ac47f9b381f8b7675fd..42cc1d47da687a76b531168d6b7de85e41916c59 100755 (executable)
@@ -82,7 +82,7 @@ void HeapP_Params_init(HeapP_Params *params)
  */\r
 HeapP_Handle HeapP_create(const HeapP_Params *params)\r
 {\r
-    HeapP_Handle     ret_handle; \r
+    HeapP_Handle     ret_handle = NULL_PTR\r
     HeapP_tiRtos     *handle = (HeapP_tiRtos *) NULL_PTR;\r
     HeapP_tiRtos     *heapPool;\r
     uint32_t         i;\r
@@ -90,57 +90,56 @@ HeapP_Handle HeapP_create(const HeapP_Params *params)
     uint32_t         maxHeap;\r
     HeapMem_Params   heapMemPrm;\r
 \r
-    HEAPOSAL_Assert(params == NULL_PTR);\r
-    HEAPOSAL_Assert(params->buf == NULL_PTR);\r
-    HEAPOSAL_Assert(params->size == 0U);\r
-\r
-    /* Pick up the internal static memory block */\r
-    heapPool       = (HeapP_tiRtos *) &gOsalHeapPTiRtosPool[0];\r
-    maxHeap        = OSAL_TIRTOS_CONFIGNUM_HEAP;\r
-    \r
-    if(gOsalHeapAllocCnt==0U) \r
+    if ((params != NULL_PTR) && (params->buf != NULL_PTR) && (params->size != 0U))\r
     {\r
-        (void)memset( (void *)gOsalHeapPTiRtosPool,0,sizeof(gOsalHeapPTiRtosPool));\r
-    }\r
+        /* Pick up the internal static memory block */\r
+        heapPool       = (HeapP_tiRtos *) &gOsalHeapPTiRtosPool[0];\r
+        maxHeap        = OSAL_TIRTOS_CONFIGNUM_HEAP;\r
+        \r
+        if(gOsalHeapAllocCnt==0U) \r
+        {\r
+            (void)memset( (void *)gOsalHeapPTiRtosPool,0,sizeof(gOsalHeapPTiRtosPool));\r
+        }\r
 \r
-    key = HwiP_disable();\r
-\r
-     for (i = 0; i < maxHeap; i++)\r
-     {\r
-         if (heapPool[i].used == FALSE)\r
-         {\r
-             heapPool[i].used = TRUE;\r
-             /* Update statistics */\r
-             gOsalHeapAllocCnt++;\r
-             if (gOsalHeapAllocCnt > gOsalHeapPeak)\r
-             {\r
-                 gOsalHeapPeak = gOsalHeapAllocCnt;\r
-             }\r
-             break;\r
-         }\r
-     }\r
-    HwiP_restore(key);\r
-\r
-    if (i < maxHeap)\r
-    {\r
-        /* Grab the memory */\r
-        handle = (HeapP_tiRtos *) &heapPool[i];\r
-    }\r
+        key = HwiP_disable();\r
 \r
-    if (handle == NULL_PTR) {\r
-        ret_handle = NULL_PTR;\r
-    }\r
-    else\r
-    {\r
-        HeapMem_Params_init(&heapMemPrm);\r
-        heapMemPrm.buf           = params->buf;\r
-        heapMemPrm.size          = params->size;\r
-        heapMemPrm.minBlockAlign = HeapP_BYTE_ALIGNMENT;\r
+        for (i = 0; i < maxHeap; i++)\r
+        {\r
+            if (heapPool[i].used == FALSE)\r
+            {\r
+                heapPool[i].used = TRUE;\r
+                /* Update statistics */\r
+                gOsalHeapAllocCnt++;\r
+                if (gOsalHeapAllocCnt > gOsalHeapPeak)\r
+                {\r
+                    gOsalHeapPeak = gOsalHeapAllocCnt;\r
+                }\r
+                break;\r
+            }\r
+        }\r
+        HwiP_restore(key);\r
+\r
+        if (i < maxHeap)\r
+        {\r
+            /* Grab the memory */\r
+            handle = (HeapP_tiRtos *) &heapPool[i];\r
+        }\r
 \r
-        HeapMem_construct(&handle->heapStruct, &heapMemPrm);\r
-        handle->heapHandle = HeapMem_handle(&handle->heapStruct);\r
+        if (handle == NULL_PTR) {\r
+            ret_handle = NULL_PTR;\r
+        }\r
+        else\r
+        {\r
+            HeapMem_Params_init(&heapMemPrm);\r
+            heapMemPrm.buf           = params->buf;\r
+            heapMemPrm.size          = params->size;\r
+            heapMemPrm.minBlockAlign = HeapP_BYTE_ALIGNMENT;\r
 \r
-        ret_handle = ((HeapP_Handle)handle);\r
+            HeapMem_construct(&handle->heapStruct, &heapMemPrm);\r
+            handle->heapHandle = HeapMem_handle(&handle->heapStruct);\r
+\r
+            ret_handle = ((HeapP_Handle)handle);\r
+        }\r
     }\r
 \r
     return ret_handle;\r
index 1d463ecd40fe95fa9a6c9f5be4130643bb5c5019..e35ade9427890f20840f19283c8226c31966e2a3 100644 (file)
@@ -58,7 +58,7 @@ void MailboxP_Params_init(MailboxP_Params *params)
 
 MailboxP_Handle MailboxP_create(const MailboxP_Params *params)
 {
-    Mailbox_Handle mboxHandle;
+    Mailbox_Handle mboxHandle = NULL_PTR;
     Mailbox_Params mboxParams;
     Error_Block  *pErrBlk = (Error_Block *) NULL_PTR;
 
@@ -74,14 +74,14 @@ MailboxP_Handle MailboxP_create(const MailboxP_Params *params)
         {
             mboxParams.buf = (Ptr)params->buf;
         }
-    }
 
-    if (pErrBlk !=  NULL_PTR)
-    {
-        Error_init(pErrBlk);
-    }
+        if (pErrBlk !=  NULL_PTR)
+        {
+            Error_init(pErrBlk);
+        }
 
-    mboxHandle = Mailbox_create(params->size, params->count, &mboxParams, pErrBlk);
+        mboxHandle = Mailbox_create(params->size, params->count, &mboxParams, pErrBlk);
+    }
 
     return ((MailboxP_Handle)mboxHandle);
 }
index f34dbb0203857818e7cc1598d97fbf11b15ff1d5..8aa8b6b2325ddd25ba85d8aed6378a05093104ec 100644 (file)
@@ -67,7 +67,7 @@ static MutexP_tiRtos gOsalMutexPTiRtosPool[OSAL_TIRTOS_CONFIGNUM_MUTEX];
 
 MutexP_Handle MutexP_create(MutexP_Object *mutexObj)
 {
-    MutexP_Handle ret_handle = NULL;
+    MutexP_Handle ret_handle = NULL_PTR;
     MutexP_tiRtos *handle = (MutexP_tiRtos *) NULL_PTR;
     GateMutexPri_Params mutexParams;
     uint32_t i;
@@ -75,57 +75,55 @@ MutexP_Handle MutexP_create(MutexP_Object *mutexObj)
     MutexP_tiRtos *mutexPool;
     uint32_t maxMutex;
 
-    if (mutexObj == NULL)
+    if (mutexObj != NULL_PTR)
     {
-        return NULL;
-    }
-
-    /* Pick up the internal static memory block */
-    mutexPool = (MutexP_tiRtos *) &gOsalMutexPTiRtosPool[0];
-    maxMutex  = OSAL_TIRTOS_CONFIGNUM_MUTEX;
+        /* Pick up the internal static memory block */
+        mutexPool = (MutexP_tiRtos *) &gOsalMutexPTiRtosPool[0];
+        maxMutex  = OSAL_TIRTOS_CONFIGNUM_MUTEX;
 
-    if(gOsalMutexAllocCnt==0U) 
-    {
-        (void)memset((void *)gOsalMutexPTiRtosPool,0,sizeof(gOsalMutexPTiRtosPool));
-    }
+        if(gOsalMutexAllocCnt==0U) 
+        {
+            (void)memset((void *)gOsalMutexPTiRtosPool,0,sizeof(gOsalMutexPTiRtosPool));
+        }
 
-    key = HwiP_disable();
+        key = HwiP_disable();
 
-    for (i = 0; i < maxMutex; i++)
-    {
-        if (mutexPool[i].used == FALSE)
+        for (i = 0; i < maxMutex; i++)
         {
-            mutexPool[i].used = TRUE;
-            /* Update statistics */
-            gOsalMutexAllocCnt++;
-            if (gOsalMutexAllocCnt > gOsalMutexPeak)
+            if (mutexPool[i].used == FALSE)
             {
-                gOsalMutexPeak = gOsalMutexAllocCnt;
+                mutexPool[i].used = TRUE;
+                /* Update statistics */
+                gOsalMutexAllocCnt++;
+                if (gOsalMutexAllocCnt > gOsalMutexPeak)
+                {
+                    gOsalMutexPeak = gOsalMutexAllocCnt;
+                }
+                break;
             }
-            break;
         }
-    }
-    HwiP_restore(key);
+        HwiP_restore(key);
 
-    if (i < maxMutex)
-    {
-        /* Grab the memory */
-        handle = (MutexP_tiRtos *) &mutexPool[i];
-    }
+        if (i < maxMutex)
+        {
+            /* Grab the memory */
+            handle = (MutexP_tiRtos *) &mutexPool[i];
+        }
 
-    if (handle == NULL_PTR) {
-        ret_handle = NULL_PTR;
-    }
-    else
-    {
-        GateMutexPri_Params_init(&mutexParams);
+        if (handle == NULL_PTR) {
+            ret_handle = NULL_PTR;
+        }
+        else
+        {
+            GateMutexPri_Params_init(&mutexParams);
 
-        GateMutexPri_construct(&handle->mutexStruct, &mutexParams);
-        handle->mutexHandle = GateMutexPri_handle(&handle->mutexStruct);
+            GateMutexPri_construct(&handle->mutexStruct, &mutexParams);
+            handle->mutexHandle = GateMutexPri_handle(&handle->mutexStruct);
 
-        mutexObj->object = (void *)handle;
-        mutexObj->key = 0;
-        ret_handle = (MutexP_Handle)mutexObj;
+            mutexObj->object = (void *)handle;
+            mutexObj->key = 0;
+            ret_handle = (MutexP_Handle)mutexObj;
+        }
     }
 
     return ret_handle;
@@ -133,30 +131,31 @@ MutexP_Handle MutexP_create(MutexP_Object *mutexObj)
 
 MutexP_Status MutexP_delete(MutexP_Handle handle)
 {
-    MUTEXOSAL_Assert(handle == NULL_PTR);
 
-    uintptr_t   key;
-    MutexP_Status ret = MutexP_OK;
-    MutexP_Object *mutexObj = (MutexP_Object *)handle;
-    MutexP_tiRtos *mutex = (MutexP_tiRtos *)mutexObj->object;
+    uintptr_t   key;    
+    MutexP_Status ret = MutexP_FAILURE;
+    MutexP_Object *mutexObj;
+    MutexP_tiRtos *mutex;
 
-    if ((mutex != NULL_PTR) && (mutex->used == TRUE))
+    if (handle != NULL_PTR)
     {
-        GateMutexPri_destruct(&mutex->mutexStruct);
+        mutexObj = (MutexP_Object *)handle;
+        mutex = (MutexP_tiRtos *)mutexObj->object;
 
-        key = HwiP_disable();
-        mutex->used = FALSE;
-        /* Found the osal semaphore object to delete */
-        if (gOsalMutexAllocCnt > 0U)
+        if ((mutex != NULL_PTR) && (mutex->used == TRUE))
         {
-            gOsalMutexAllocCnt--;
+            GateMutexPri_destruct(&mutex->mutexStruct);
+
+            key = HwiP_disable();
+            mutex->used = FALSE;
+            /* Found the osal semaphore object to delete */
+            if (gOsalMutexAllocCnt > 0U)
+            {
+                gOsalMutexAllocCnt--;
+            }
+            HwiP_restore(key);
+            ret = MutexP_OK;
         }
-        HwiP_restore(key);
-        ret = MutexP_OK;
-    }
-    else
-    {
-       ret = MutexP_FAILURE;
     }
     return ret;
 }
@@ -164,41 +163,41 @@ MutexP_Status MutexP_delete(MutexP_Handle handle)
 MutexP_Status MutexP_lock(MutexP_Handle handle,
                           uint32_t timeout)
 {
-    MUTEXOSAL_Assert(handle == NULL_PTR);
-
-    MutexP_Status ret = MutexP_OK;
-    MutexP_Object *mutexObj = (MutexP_Object *)handle;
-    MutexP_tiRtos *mutex = (MutexP_tiRtos *)mutexObj->object;
+    MutexP_Status ret = MutexP_FAILURE;
+    MutexP_Object *mutexObj;
+    MutexP_tiRtos *mutex;
 
-    if ((mutex != NULL_PTR) && (mutex->used == TRUE))
-    {
-        mutexObj->key = GateMutexPri_enter(mutex->mutexHandle);
-        ret = MutexP_OK;
-    }
-    else
+    if (handle != NULL_PTR)
     {
-       ret = MutexP_FAILURE;
+        mutexObj = (MutexP_Object *)handle;
+        mutex = (MutexP_tiRtos *)mutexObj->object;
+
+        if ((mutex != NULL_PTR) && (mutex->used == TRUE))
+        {
+            /* Note: timeout is not used */
+            mutexObj->key = GateMutexPri_enter(mutex->mutexHandle);
+            ret = MutexP_OK;
+        }
     }
     return ret;
 }
 
 MutexP_Status MutexP_unlock(MutexP_Handle handle)
 {
-    MUTEXOSAL_Assert(handle == NULL_PTR);
+    MutexP_Status ret = MutexP_FAILURE;
+    MutexP_Object *mutexObj;
+    MutexP_tiRtos *mutex;
 
-    MutexP_Status ret = MutexP_OK;
-    MutexP_Object *mutexObj = (MutexP_Object *)handle;
-    MutexP_tiRtos *mutex = (MutexP_tiRtos *)mutexObj->object;
-    /* Note: timeout is not use */
-
-    if ((mutex != NULL_PTR) && (mutex->used == TRUE))
+    if (handle != NULL_PTR)
     {
-        GateMutexPri_leave(mutex->mutexHandle, mutexObj->key);
-        ret = MutexP_OK;
-    }
-    else
-    {
-       ret = MutexP_FAILURE;
+        mutexObj = (MutexP_Object *)handle;
+        mutex = (MutexP_tiRtos *)mutexObj->object;
+
+        if ((mutex != NULL_PTR) && (mutex->used == TRUE))
+        {
+            GateMutexPri_leave(mutex->mutexHandle, mutexObj->key);
+            ret = MutexP_OK;
+        }
     }
     return ret;
 }