--- ./vision_sdk/apps/src/rtos/usecases/tidl/chains_tidl_tda3.c	1970-01-01 03:00:00.000000000 +0300
+++ ./vision_sdk/apps/src/rtos/usecases/tidl/chains_tidl_tda3.c	2017-08-01 15:23:05.336891400 +0300
@@ -0,0 +1,1292 @@
+/******************************************************************************
+Copyright (c) [2012 - 2017] Texas Instruments Incorporated
+
+All rights reserved not granted herein.
+
+Limited License.
+
+ Texas Instruments Incorporated grants a world-wide, royalty-free, non-exclusive
+ license under copyrights and patents it now or hereafter owns or controls to
+ make,  have made, use, import, offer to sell and sell ("Utilize") this software
+ subject to the terms herein.  With respect to the foregoing patent license,
+ such license is granted  solely to the extent that any such patent is necessary
+ to Utilize the software alone.  The patent license shall not apply to any
+ combinations which include this software, other than combinations with devices
+ manufactured by or for TI ("TI Devices").  No hardware patent is licensed
+ hereunder.
+
+ Redistributions must preserve existing copyright notices and reproduce this
+ license (including the above copyright notice and the disclaimer and
+ (if applicable) source code license limitations below) in the documentation
+ and/or other materials provided with the distribution
+
+ Redistribution and use in binary form, without modification, are permitted
+ provided that the following conditions are met:
+
+ * No reverse engineering, decompilation, or disassembly of this software
+   is permitted with respect to any software provided in binary form.
+
+ * Any redistribution and use are licensed by TI for use only with TI Devices.
+
+ * Nothing shall obligate TI to provide you with source code for the software
+   licensed and provided to you in object code.
+
+ If software source code is provided to you, modification and redistribution of
+ the source code are permitted provided that the following conditions are met:
+
+ * Any redistribution and use of the source code, including any resulting
+   derivative works, are licensed by TI for use only with TI Devices.
+
+ * Any redistribution and use of any object code compiled from the source code
+   and any resulting derivative works, are licensed by TI for use only with TI
+   Devices.
+
+ Neither the name of Texas Instruments Incorporated nor the names of its
+ suppliers may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ DISCLAIMER.
+
+ THIS SOFTWARE IS PROVIDED BY TI AND TI’S LICENSORS "AS IS" AND ANY EXPRESS OR
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ IN NO EVENT SHALL TI AND TI’S LICENSORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+******************************************************************************/
+
+/*******************************************************************************
+ *  INCLUDE FILES
+ *******************************************************************************
+ */
+#include <src/include/chains_common.h>
+#include <src/include/chains_common_osal.h>
+#include "itidl_ti.h"
+#include <src/rtos/utils_common/include/utils_cbuf_ocmc.h>
+#include <src/rtos/utils_common/include/utils_tsk.h>
+#include "UsecaseDsp_tda3/chains_tidlDsp_priv.h"
+#include "chains_tidl.h"
+
+/*******************************************************************************
+ *  DEFINES
+ *******************************************************************************
+ */
+
+#define TIDL_FILEWRITE_TASK_STACK_SIZE      (32 * KB)
+
+/*******************************************************************************
+ *  GLOBALS
+ *******************************************************************************
+ */
+
+chains_tidlAppObj gChainsObj;
+
+#pragma DATA_ALIGN(fileWriteTaskStack, 32)
+#pragma DATA_SECTION(fileWriteTaskStack, ".bss:taskStackSection")
+static UInt8 fileWriteTaskStack[TIDL_FILEWRITE_TASK_STACK_SIZE];
+
+static char tidlCoreMenu[] = {
+"\n "
+"\n ===================="
+"\n Core Menu"
+"\n ===================="
+"\n "
+"\n 1: DSP"
+"\n 2: EVE (is not supported)"
+"\n "
+"\n Enter Choice: "
+"\n "
+};
+
+static char tidlUseCaseModeMenu[] = {
+"\n "
+"\n ===================="
+"\n Use case Mode"
+"\n ===================="
+"\n "
+"\n 1: Dump Output Frames to file"
+"\n 2: Free Run (Output Frames are not dumped)"
+"\n "
+"\n Enter Choice: "
+"\n "
+};
+
+static char tidlRunTimeMenu[] = {
+"\n "
+"\n ===================="
+"\n Chains Run-time Menu"
+"\n ===================="
+"\n "
+"\n 0: Stop Chain"
+"\n "
+"\n p: Print Statistics"
+"\n "
+"\n Enter Choice: "
+"\n "
+};
+
+/*******************************************************************************
+ *  GLOBALS
+ *******************************************************************************
+ */
+/**
+ *******************************************************************************
+ *
+ * \brief   TI Deep Learning Init
+ *
+ * \param   pObj  [IN] chains_tidlAppObj
+ *
+ * \return  SYSTEM_LINK_STATUS_SOK on success
+ *
+ *******************************************************************************
+*/
+static Int32 tidlReadNet(chains_tidlAppObj *pObj)
+{
+    Int32 fp;
+    UInt32 readSize;
+
+    Vps_printf(">>>>>> tidlReadNet()");
+
+    sTIDL_Network_t *net = &pObj->pAlgCreateParams->net;
+
+    fp = ChainsCommon_Osal_fileOpen(
+                            pObj->netFileName,
+                            CHAINSCOMMON_OSAL_FILEMODE_READ_BIN);
+    UTILS_assert(-1 != fp);
+
+    ChainsCommon_Osal_fileRead(
+                            fp,
+                            (UInt8*)net,
+                            sizeof(sTIDL_Network_t),
+                            &readSize);
+    UTILS_assert(readSize == sizeof(sTIDL_Network_t));
+
+    ChainsCommon_Osal_fileClose(fp);
+
+    return SYSTEM_LINK_STATUS_SOK;
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   Allocation of Memory for Network parameters
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Int32 tidlAllocNetParamsMem(chains_tidlAppObj *pObj)
+{
+    Int32 i;
+    sTIDL_Network_t *net = &pObj->pAlgCreateParams->net;
+
+    Vps_printf(">>>>>> tidlAllocNetParamsMem()");
+
+    for(i = 0; i < net->numLayers; i++)
+    {
+        if((TIDL_ConvolutionLayer == net->TIDLLayers[i].layerType) ||
+           (TIDL_Deconv2DLayer == net->TIDLLayers[i].layerType))
+        {
+            net->TIDLLayers[i].layerParams.convParams.weights.bufSize = \
+                net->weightsElementSize * \
+                (net->TIDLLayers[i].layerParams.convParams.kernelW * \
+                    net->TIDLLayers[i].layerParams.convParams.kernelH * \
+                    net->TIDLLayers[i].layerParams.convParams.numInChannels * \
+                    net->TIDLLayers[i].layerParams.convParams.numOutChannels);
+
+            net->TIDLLayers[i].layerParams.convParams.weights.ptr = \
+                ChainsCommon_Osal_memAlloc(
+                    net->TIDLLayers[i].layerParams.convParams.weights.bufSize,
+                    32);
+
+            net->TIDLLayers[i].layerParams.convParams.bias.bufSize = \
+                net->biasElementSize * \
+                    net->TIDLLayers[i].layerParams.convParams.numOutChannels;
+
+            net->TIDLLayers[i].layerParams.convParams.bias.ptr = \
+                ChainsCommon_Osal_memAlloc(
+                    net->TIDLLayers[i].layerParams.convParams.bias.bufSize,
+                    32);
+        }
+        else if(TIDL_BiasLayer == net->TIDLLayers[i].layerType)
+        {
+            net->TIDLLayers[i].layerParams.biasParams.bias.bufSize = \
+                net->biasElementSize * \
+                    net->TIDLLayers[i].layerParams.biasParams.numChannels;
+
+            net->TIDLLayers[i].layerParams.biasParams.bias.ptr = \
+                ChainsCommon_Osal_memAlloc(
+                    net->TIDLLayers[i].layerParams.biasParams.bias.bufSize,
+                    32);
+        }
+    }
+
+    return SYSTEM_LINK_STATUS_SOK;
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   sparseConv2dCoffesS8
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Void sparseConv2dCoffesS8(Int8 *ptr, Int32 n, UInt8 thr)
+{
+    Int32 i0;
+
+    for(i0 = 0; i0 < n; i0++)
+    {
+        if(((UInt8)(rand() & 0xFF)) > thr)
+        {
+            ptr[i0] =  0;
+        }
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   createRandPatternS16
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Void createRandPatternS16(Int16 *ptr, Int16 n, Int16 width, Int16 height, Int16 pitch, Int32 chOffset)
+{
+    Int16 val;
+    Int32 i0, i1, i2;
+    for(i0 = 0; i0 < n; i0++)
+    {
+        for(i1 = 0; i1 < height; i1++)
+        {
+            for(i2 = 0; i2 < width; i2++)
+            {
+                val = rand() & 0x7FFF;
+                ptr[i0 * chOffset + i1 * pitch + i2] = (rand() & 1) ? val : -val;
+            }
+        }
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   tidlFillNetParamsMem
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Int32 tidlFillNetParamsMem(chains_tidlAppObj *pObj)
+{
+    Int32 i;
+    Int32 fp;
+    UInt32 dataSize, readSize;
+    sTIDL_Network_t *net = &pObj->pAlgCreateParams->net;
+
+    Vps_printf(">>>>>> tidlFillNetParamsMem()");
+
+    fp = ChainsCommon_Osal_fileOpen(
+                        pObj->paramFileName,
+                        CHAINSCOMMON_OSAL_FILEMODE_READ_BIN);
+    UTILS_assert(-1 != fp);
+
+    for(i = 0; i < net->numLayers; i++)
+    {
+        if((TIDL_ConvolutionLayer == net->TIDLLayers[i].layerType) ||
+           (TIDL_Deconv2DLayer == net->TIDLLayers[i].layerType))
+        {
+            dataSize = \
+                (net->TIDLLayers[i].layerParams.convParams.numInChannels * \
+                    net->TIDLLayers[i].layerParams.convParams.numOutChannels * \
+                    net->TIDLLayers[i].layerParams.convParams.kernelW * \
+                    net->TIDLLayers[i].layerParams.convParams.kernelH)/ \
+                    net->TIDLLayers[i].layerParams.convParams.numGroups;
+
+            ChainsCommon_Osal_fileRead(
+                fp,
+                (UInt8*)net->TIDLLayers[i].layerParams.convParams.weights.ptr,
+                dataSize,
+                &readSize);
+            UTILS_assert(readSize == dataSize);
+
+            if(NO_ZERO_COEFF_PERCENT < 100)
+            {
+                sparseConv2dCoffesS8(
+                   (Int8*)net->TIDLLayers[i].layerParams.convParams.weights.ptr,
+                   net->TIDLLayers[i].layerParams.convParams.weights.bufSize,
+                   NO_ZERO_COEFF_PERCENT * 2.55);
+            }
+
+            /* Cache wb since it is read on EVE and DSP */
+            Cache_wb(
+                (UInt8*)net->TIDLLayers[i].layerParams.convParams.weights.ptr,
+                dataSize,
+                Cache_Type_ALLD,
+                TRUE);
+
+            if(net->TIDLLayers[i].layerParams.convParams.enableBias)
+            {
+                dataSize = \
+                    net->TIDLLayers[i].layerParams.convParams.numOutChannels;
+
+                ChainsCommon_Osal_fileRead(
+                    fp,
+                    (UInt8*)net->TIDLLayers[i].layerParams.convParams.bias.ptr,
+                    dataSize * 2,
+                    &readSize);
+                UTILS_assert(readSize == (dataSize * 2));
+
+                /* Cache wb since it is read on EVE and DSP */
+                Cache_wb(
+                    (UInt8*)net->TIDLLayers[i].layerParams.convParams.bias.ptr,
+                    dataSize * 2,
+                    Cache_Type_ALLD,
+                    TRUE);
+            }
+            else
+            {
+                memset(
+                (UInt8*)net->TIDLLayers[i].layerParams.convParams.bias.ptr,
+                0x00,
+                net->TIDLLayers[i].layerParams.convParams.numOutChannels * 2);
+            }
+        }
+        else if(TIDL_BiasLayer == net->TIDLLayers[i].layerType)
+        {
+            dataSize = net->TIDLLayers[i].layerParams.biasParams.numChannels;
+
+            if(1 == RANDOM_INPUT)
+            {
+                createRandPatternS16(
+                    (Int16*)net->TIDLLayers[i].layerParams.biasParams.bias.ptr,
+                    1,
+                    dataSize,
+                    1,
+                    1,
+                    1);
+            }
+            else
+            {
+                ChainsCommon_Osal_fileRead(
+                    fp,
+                    (UInt8*)net->TIDLLayers[i].layerParams.biasParams.bias.ptr,
+                    dataSize * 2,
+                    &readSize);
+                UTILS_assert(readSize == (dataSize * 2));
+            }
+
+            /* Cache wb since it is read on EVE and DSP */
+            Cache_wb(
+                (UInt8*)net->TIDLLayers[i].layerParams.biasParams.bias.ptr,
+                dataSize * 2,
+                Cache_Type_ALLD,
+                TRUE);
+        }
+    }
+
+    ChainsCommon_Osal_fileClose(fp);
+
+    /* Cache wb since it is read on EVE and DSP */
+    Cache_wb(
+        (UInt8*)net,
+        sizeof(sTIDL_Network_t),
+        Cache_Type_ALLD,
+        TRUE);
+
+    return SYSTEM_LINK_STATUS_SOK;
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   TIDL Init
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Void tidlInit(chains_tidlAppObj *pObj)
+{
+    /* Read the network file */
+    Vps_printf(">>>>>> tidlInit(): call 'tidlReadNet'");
+    tidlReadNet(pObj);
+
+    /* Allocate memory for the net */
+    Vps_printf(">>>>>> tidlInit(): call 'tidlAllocNetParamsMem'");
+    tidlAllocNetParamsMem(pObj);
+
+    /* Fill the new parameters */
+    Vps_printf(">>>>>> tidlInit(): call 'tidlFillNetParamsMem'");
+    tidlFillNetParamsMem(pObj);
+
+    /* Init all the 3 instances of the OCMC */
+    Vps_printf(">>>>>> tidlInit(): call 'Utils_cbufOcmcInit(UTILS_OCMC_RAM1)'");
+    Utils_cbufOcmcInit(UTILS_OCMC_RAM1);
+    Vps_printf(">>>>>> tidlInit(): call 'Utils_cbufOcmcInit(UTILS_OCMC_RAM2)'");
+    Utils_cbufOcmcInit(UTILS_OCMC_RAM2);
+    Vps_printf(">>>>>> tidlInit(): call 'Utils_cbufOcmcInit(UTILS_OCMC_RAM3)'");
+    Utils_cbufOcmcInit(UTILS_OCMC_RAM3);
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   tidlFreeNetParamsMem
+ *
+ * \param   pObj  [IN] chains_tidlAppObj
+ *
+ * \return  SYSTEM_LINK_STATUS_SOK on success
+ *
+ *******************************************************************************
+*/
+static Int32 tidlFreeNetParamsMem(chains_tidlAppObj *pObj)
+{
+    Int32 i;
+    UInt32 dataSize;
+    sTIDL_Network_t *net = &pObj->pAlgCreateParams->net;
+
+    Vps_printf(">>>>>> tidlFreeNetParamsMem()");
+
+    for(i = 0; i < net->numLayers; i++)
+    {
+        if((TIDL_ConvolutionLayer == net->TIDLLayers[i].layerType) ||
+           (TIDL_Deconv2DLayer == net->TIDLLayers[i].layerType))
+        {
+            dataSize = \
+                net->weightsElementSize * \
+                (net->TIDLLayers[i].layerParams.convParams.kernelW * \
+                    net->TIDLLayers[i].layerParams.convParams.kernelH * \
+                    net->TIDLLayers[i].layerParams.convParams.numInChannels * \
+                    net->TIDLLayers[i].layerParams.convParams.numOutChannels);
+
+            ChainsCommon_Osal_memFree(
+                net->TIDLLayers[i].layerParams.convParams.weights.ptr,
+                dataSize);
+
+            dataSize = \
+                net->biasElementSize * \
+                    net->TIDLLayers[i].layerParams.convParams.numOutChannels;
+
+            ChainsCommon_Osal_memFree(
+                net->TIDLLayers[i].layerParams.convParams.bias.ptr,
+                dataSize);
+        }
+        else if(TIDL_BiasLayer == net->TIDLLayers[i].layerType)
+        {
+            dataSize = \
+                net->biasElementSize * \
+                    net->TIDLLayers[i].layerParams.biasParams.numChannels;
+
+            ChainsCommon_Osal_memFree(
+                net->TIDLLayers[i].layerParams.biasParams.bias.ptr,
+                dataSize);
+        }
+    }
+
+    return SYSTEM_LINK_STATUS_SOK;
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   Deinit TIDL
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Void tidlDeInit(chains_tidlAppObj *pObj)
+{
+    /* Free the net memories */
+    tidlFreeNetParamsMem(pObj);
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   Parse the TIDL config file
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Int32 parseCfg(chains_tidlAppObj *pObj)
+{
+    Int32 fd;
+    char string[256U];
+    char *pArg, *pVal;
+    UInt32 numArg = 0;
+
+    Vps_printf(">>>>>> parseCfg()");
+
+    fd = ChainsCommon_Osal_fileOpen(
+                    TIDL_UC_CFG_FILE,
+                    CHAINSCOMMON_OSAL_FILEMODE_READ);
+    if(-1 != fd)
+    {
+        while(NULL != File_gets(string, 256U, fd))
+        {
+            pArg = strtok(string, "=");
+            pVal = strtok(NULL, "\0");
+            if(NULL != pArg)
+            {
+                if(0 == strcmp(pArg,"inputWidth"))
+                {
+                    pObj->inWidth = atoi(pVal);
+                    numArg ++;
+                }
+                else if(0 == strcmp(pArg,"inputHeight"))
+                {
+                    pObj->inHeight = atoi(pVal);
+                    numArg ++;
+                }
+                else if(0 == strcmp(pArg,"inputFile"))
+                {
+                    strcpy(pObj->inFileName,pVal);
+                    numArg ++;
+                }
+                else if(0 == strcmp(pArg,"outputFile"))
+                {
+                    strcpy(pObj->outFileName,pVal);
+                    numArg ++;
+                }
+                else if(0 == strcmp(pArg,"netFileName"))
+                {
+                    strcpy(pObj->netFileName,pVal);
+                    numArg ++;
+                }
+                else if(0 == strcmp(pArg,"paramFileName"))
+                {
+                    strcpy(pObj->paramFileName,pVal);
+                    numArg ++;
+                }
+            }
+        }
+
+        ChainsCommon_Osal_fileClose(fd);
+
+        if(TIDL_NUM_ARGS != numArg)
+        {
+            Vps_printf(" TIDL: Insufficient no of configuration parameters ...");
+            return SYSTEM_LINK_STATUS_EFAIL;
+        }
+        else
+        {
+            Vps_printf(" TIDL Configuration parameters");
+            Vps_printf(" -----------------------------");
+            Vps_printf(" inputWidth         = %d\n",pObj->inWidth);
+            Vps_printf(" inputHeight        = %d\n",pObj->inHeight);
+            Vps_printf(" inputFile          = %s\n",pObj->inFileName);
+            Vps_printf(" outputFile         = %s\n",pObj->outFileName);
+            Vps_printf(" netFileName        = %s\n",pObj->netFileName);
+            Vps_printf(" paramFileName      = %s\n",pObj->paramFileName);
+            Vps_printf(" -----------------------------");
+
+            return SYSTEM_LINK_STATUS_SOK;
+        }
+    }
+    else
+    {
+        Vps_printf(" Use case config file (%s) is NOT present ...",\
+                                                        TIDL_UC_CFG_FILE);
+        return SYSTEM_LINK_STATUS_EFAIL;
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chains_tidl_CreateApp
+ *
+ *          Function sends a control command to capture and display link to
+ *          to Start all the required links . Links are started in reverce
+ *          order as information of next link is required to connect.
+ *          System_linkStart is called with LinkId to start the links.
+ *
+ * \param   pObj  [IN] chains_tidlAppObj
+ *
+ * \return  SYSTEM_LINK_STATUS_SOK on success
+ *
+ *******************************************************************************
+*/
+Void chains_tidl_CreateApp(chains_tidlAppObj *pObj)
+{
+
+    Vps_printf(">>>>>> chains_tidl_CreateApp()");
+
+    switch(pObj->tidlCore)
+    {
+        case TIDL_CORE_DSP:
+            chains_tidlDsp_Create(&pObj->dspUcObj, pObj);
+            break;
+
+        default:
+        case TIDL_CORE_EVE:
+//            chains_tidlEve_Create(&pObj->eveUcObj, pObj);
+            break;
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chains_tidl_StartApp
+ *
+ *          Function sends a control command to capture and display link to
+ *          to Start all the required links . Links are started in reverce
+ *          order as information of next link is required to connect.
+ *          System_linkStart is called with LinkId to start the links.
+ *
+ * \param   pObj  [IN] chains_tidlAppObj
+ *
+ * \return  SYSTEM_LINK_STATUS_SOK on success
+ *
+ *******************************************************************************
+*/
+Void chains_tidl_StartApp(chains_tidlAppObj *pObj)
+{
+
+    Vps_printf(">>>>>> chains_tidl_StartApp()");
+
+    Chains_memPrintHeapStatus();
+
+    switch(pObj->tidlCore)
+    {
+        case TIDL_CORE_DSP:
+            chains_tidlDsp_Start(&pObj->dspUcObj);
+            break;
+
+        default:
+        case TIDL_CORE_EVE:
+//            chains_tidlEve_Start(&pObj->eveUcObj);
+            break;
+    }
+
+    Chains_prfLoadCalcEnable(TRUE, FALSE, FALSE);
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chains_tidl_StopAndDelete
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+Void chains_tidl_StopAndDelete(chains_tidlAppObj *pObj)
+{
+    switch(pObj->tidlCore)
+    {
+        case TIDL_CORE_DSP:
+            chains_tidlDsp_Stop(&pObj->dspUcObj);
+            chains_tidlDsp_Delete(&pObj->dspUcObj);
+            break;
+
+        default:
+        case TIDL_CORE_EVE:
+//            chains_tidlEve_Stop(&pObj->eveUcObj);
+//            chains_tidlEve_Delete(&pObj->eveUcObj);
+            break;
+    }
+
+    /* Print the HWI, SWI and all tasks load */
+    /* Reset the accumulated timer ticks */
+    Chains_prfLoadCalcEnable(FALSE, TRUE, TRUE);
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chains_tidl_printStatisticsApp
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+Void chains_tidl_printStatisticsApp(chains_tidlAppObj *pObj)
+{
+    switch(pObj->tidlCore)
+    {
+        case TIDL_CORE_DSP:
+            chains_tidlDsp_printStatistics(&pObj->dspUcObj);
+            break;
+
+        default:
+        case TIDL_CORE_EVE:
+//            chains_tidlEve_printStatistics(&pObj->eveUcObj);
+            break;
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   inputEofCb
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Void inputEofCb(UInt32 numFrames)
+{
+    /* End of input file reached */
+    Vps_printf(" No of input frames = %d\n",numFrames);
+    gChainsObj.outNumFrames = numFrames;
+    BspOsal_semPost(gChainsObj.eofSem);
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   setNullSrcPrm
+ *
+ *          Function sends a control command to capture and display link to
+ *          to delete all the prior created links
+ *          System_linkDelete is called with LinkId to delete the links.
+ *
+ * \param   pObj   [IN]   chains_tidlAppObj
+ *
+ *******************************************************************************
+*/
+static Void setNullSrcPrm(chains_tidlAppObj *pObj)
+{
+    System_LinkChInfo *pChInfo;
+    NullSrcLink_CreateParams *pNullSrcPrm;
+
+
+    Vps_printf(">>>>>> setNullSrcPrm()");
+
+    switch(pObj->tidlCore)
+    {
+        case TIDL_CORE_DSP:
+            pNullSrcPrm = &pObj->dspUcObj.NullSourcePrm;
+            break;
+
+        default:
+        case TIDL_CORE_EVE:
+//            pNullSrcPrm = &pObj->eveUcObj.NullSourcePrm;
+            break;
+    }
+
+    NullSrcLink_CreateParams_Init(pNullSrcPrm);
+
+    if(TRUE == pObj->enableOutFileWrite)
+    {
+        /*  For the file write mode the Null source latency is high
+            to allow for file write delays */
+        pNullSrcPrm->timerPeriodMilliSecs = NULLSRC_TIMER_PERIOD_FW;
+    }
+    else
+    {
+        pNullSrcPrm->timerPeriodMilliSecs = NULLSRC_TIMER_PERIOD;
+    }
+    pNullSrcPrm->outQueInfo.numCh = 1;
+    pNullSrcPrm->channelParams[0].numBuffers = 4;
+
+    pChInfo = &pNullSrcPrm->outQueInfo.chInfo[0];
+
+    pChInfo->flags = System_Link_Ch_Info_Set_Flag_Data_Format(pChInfo->flags,
+                                            SYSTEM_DF_BGR24_888);
+    pChInfo->flags = System_Link_Ch_Info_Set_Flag_Scan_Format(pChInfo->flags,
+                                            SYSTEM_SF_PROGRESSIVE);
+    pChInfo->flags = System_Link_Ch_Info_Set_Flag_Buf_Type(pChInfo->flags,
+                                            SYSTEM_BUFFER_TYPE_VIDEO_FRAME);
+    pChInfo->width = pObj->inWidth;
+    pChInfo->height = pObj->inHeight;
+    pChInfo->startX = 0;
+    pChInfo->startY = 0;
+    pChInfo->pitch[0] = SystemUtils_align(pChInfo->width * 3, 32);
+    pChInfo->pitch[1] = SystemUtils_align(pChInfo->width * 3, 32);
+
+    pNullSrcPrm->channelParams[0].fileReadMode = NULLSRC_LINK_FILEREAD_RUN_TIME;
+    strncpy(pNullSrcPrm->channelParams[0].nameDataFile, pObj->inFileName, 260);
+
+    if(TRUE == pObj->enableOutFileWrite)
+    {
+        pNullSrcPrm->inEofCb = inputEofCb;
+    }
+    else
+    {
+        pNullSrcPrm->inEofCb = NULL;
+    }
+}
+
+
+static Void dumpOutCb(System_LinkChInfo *pChInfo, Void *pBuf, Void *arg)
+{
+    Int32 status;
+    UInt32 inBufOffset;
+    System_Buffer *pFrameBuf = (System_Buffer*)pBuf;
+    System_MetaDataBuffer *pMetaDataBuf = \
+                                (System_MetaDataBuffer*)pFrameBuf->payload;
+    chains_tidlAppObj *pObj = (chains_tidlAppObj*)arg;
+    Utils_DmaCopyFill2D dmaPrm;
+
+    pObj->curOutputBufAddr = pObj->outputBuf[pObj->curOutBuf];
+    pObj->curOutBuf = (pObj->curOutBuf == 0)?1:0;
+    pObj->curQue = pFrameBuf->chNum;
+
+    Cache_inv(
+        pMetaDataBuf->bufAddr[0],
+        ((pObj->inWidth + (2 * TIDL_MAX_PAD_SIZE)) * \
+                                (pObj->inHeight + (2 * TIDL_MAX_PAD_SIZE))),
+        Cache_Type_ALL,
+        TRUE);
+
+    /* Remove the padding */
+    dmaPrm.srcPitch[0] = (pObj->inWidth + (2 * TIDL_MAX_PAD_SIZE));
+    inBufOffset = \
+                ((dmaPrm.srcPitch[0] * TIDL_MAX_PAD_SIZE) + TIDL_MAX_PAD_SIZE);
+    dmaPrm.dataFormat = SYSTEM_DF_RAW08;
+    dmaPrm.destAddr[0] = (Ptr)(pObj->curOutputBufAddr);
+    dmaPrm.destAddr[1] = NULL;
+    dmaPrm.destPitch[0] = pObj->inWidth;
+    dmaPrm.destPitch[1] = 0;
+    dmaPrm.destStartX = 0;
+    dmaPrm.destStartY = 0;
+    dmaPrm.width = pObj->inWidth;
+    dmaPrm.height = pObj->inHeight;
+    dmaPrm.srcAddr[0] = (Ptr)((UInt32)pMetaDataBuf->bufAddr[0] + inBufOffset);
+    dmaPrm.srcAddr[1] = NULL;
+    dmaPrm.srcPitch[1] = 0;
+    dmaPrm.srcStartX = 0;
+    dmaPrm.srcStartY = 0;
+
+    status = Utils_dmaCopy2D(&pObj->dumpFramesDmaObj, &dmaPrm, 1U);
+    UTILS_assert(SYSTEM_LINK_STATUS_SOK == status);
+
+    Cache_wb(
+        (Ptr)pObj->curOutputBufAddr,
+        (pObj->inWidth * pObj->inHeight),
+        Cache_Type_ALL,
+        TRUE);
+
+    /* Post file write sem */
+    BspOsal_semPost(pObj->fileWriteSem);
+}
+
+/* Background low priority task for writing the output frame to file */
+Void fileWriteTaskMain(UArg arg1, UArg arg2)
+{
+    Bool dump;
+    chains_tidlAppObj *pObj = (chains_tidlAppObj*)arg1;
+
+    while(1)
+    {
+        BspOsal_semWait(pObj->fileWriteSem, BSP_OSAL_WAIT_FOREVER);
+
+        dump = TRUE;
+        if(0 != pObj->outNumFrames)
+        {
+            if(pObj->outFrameNum == pObj->outNumFrames)
+            {
+                /* All the frames are dumped */
+                dump = FALSE;
+            }
+        }
+
+        if(TRUE == dump)
+        {
+            /* Write the output buffer to file */
+            ChainsCommon_Osal_fileWrite(
+                            pObj->outFp,
+                            (UInt8*)pObj->curOutputBufAddr,
+                            (pObj->inWidth * pObj->inHeight));
+            Vps_printf(" ########## FRAME # %d, QUEUE = %d ###########\n",\
+                                            pObj->outFrameNum++,pObj->curQue);
+        }
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chains_tidlEve_SetAppPrms
+ *
+ *          This function configure, creates, link various links to establish
+ *          usecase.
+ *
+ *          Further in a while loop displays run time menu and waits
+ *          for user inputs to print the statistics or to end the demo.
+ *
+ *          Once the user inputs end of demo stop and delete
+ *          functions are executed.
+ *
+ * \param   chainsCfg       [IN]   Chains_Ctrl
+ *
+ *******************************************************************************
+*/
+/*
+Void chains_tidlEve_SetAppPrms(chains_tidlEveObj *pUcObj, Void *appObj)
+{
+    chains_tidlAppObj *pObj = (chains_tidlAppObj*)appObj;
+
+    // Null Source Parameters
+    setNullSrcPrm(pObj);
+
+    // TIDL Pre Process
+    pUcObj->Alg_tidlpreprocPrm.outPad = TIDL_MAX_PAD_SIZE;
+    pUcObj->Alg_tidlpreprocPrm.numOutputQueues = NUM_PIPELINES;
+    pUcObj->Alg_tidlpreprocPrm.procMode = TIDLPREPROC_LINK_PROCMODE_RGBPAD;
+
+    //
+    //  Set the TIDL algorithm parameters for all the 'NUM_PIPELINES' instances.
+    //  Make sure to distribute the OCMC instance across the algorithm
+    //  instances like OCMC_1 for TIDL_1 and OCMC_2 for TIDL_2
+    //
+
+    // TIDL on EVE1
+    pUcObj->Alg_tidl_1Prm.cacheInvInBuf = 0;
+    pUcObj->Alg_tidl_1Prm.cacheWbOutBuf = 0;
+    pUcObj->Alg_tidl_1Prm.pAlgCreateParams = pObj->pAlgCreateParams;
+    pUcObj->Alg_tidl_1Prm.curCoreId = TIDL_COREID_EVE1;
+    pUcObj->Alg_tidl_1Prm.currLayersGroupId = TIDL_LAYER_GROUPID_EVE1;
+    pUcObj->Alg_tidl_1Prm.ocmcAddr = OCMC_1_BASE_ADDRESS;
+
+    // Null Link
+    if(TRUE == pObj->enableOutFileWrite)
+    {
+        pUcObj->NullPrm.appCb = dumpOutCb;
+        pUcObj->NullPrm.appCbArg = pObj;
+    }
+    else
+    {
+        pUcObj->NullPrm.appCb = NULL;
+        pUcObj->NullPrm.appCbArg = NULL;
+    }
+}
+*/
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chains_tidlDsp_SetAppPrms
+ *
+ *          This function configure, creates, link various links to establish
+ *          usecase.
+ *
+ *          Further in a while loop displays run time menu and waits
+ *          for user inputs to print the statistics or to end the demo.
+ *
+ *          Once the user inputs end of demo stop and delete
+ *          functions are executed.
+ *
+ * \param   chainsCfg       [IN]   Chains_Ctrl
+ *
+ *******************************************************************************
+*/
+Void chains_tidlDsp_SetAppPrms(chains_tidlDspObj *pUcObj, Void *appObj)
+{
+    chains_tidlAppObj *pObj = (chains_tidlAppObj*)appObj;
+
+
+    Vps_printf(">>>>>> chains_tidlDsp_SetAppPrms()");
+
+    /* Null Source Parameters */
+    setNullSrcPrm(pObj);
+
+    /* TIDL Pre Process */
+    pUcObj->Alg_tidlpreprocPrm.outPad = TIDL_MAX_PAD_SIZE;
+    pUcObj->Alg_tidlpreprocPrm.numOutputQueues = NUM_PIPELINES;
+    pUcObj->Alg_tidlpreprocPrm.procMode = TIDLPREPROC_LINK_PROCMODE_RGBPAD;
+
+    /*
+     *  Set the TIDL algorithm parameters for all the 'NUM_PIPELINES' instances.
+     */
+
+    /* TIDL on DSP1 */
+    pUcObj->Alg_tidl_1Prm.cacheInvInBuf = 1;
+    pUcObj->Alg_tidl_1Prm.cacheWbOutBuf = 1;
+    pUcObj->Alg_tidl_1Prm.pAlgCreateParams = pObj->pAlgCreateParams;
+    pUcObj->Alg_tidl_1Prm.curCoreId = TIDL_COREID_EVE1;
+    pUcObj->Alg_tidl_1Prm.currLayersGroupId = TIDL_LAYER_GROUPID_EVE1;
+    pUcObj->Alg_tidl_1Prm.ocmcAddr = NULL;
+
+    /* Null Link */
+    if(TRUE == pObj->enableOutFileWrite)
+    {
+        pUcObj->NullPrm.appCb = dumpOutCb;
+        pUcObj->NullPrm.appCbArg = pObj;
+    }
+    else
+    {
+        pUcObj->NullPrm.appCb = NULL;
+        pUcObj->NullPrm.appCbArg = NULL;
+    }
+}
+
+/**
+ *******************************************************************************
+ *
+ * \brief   chanis_tidl
+ *
+ *          This function configure, creates, link various links to establish
+ *          usecase.
+ *
+ *          Further in a while loop displays run time menu and waits
+ *          for user inputs to print the statistics or to end the demo.
+ *
+ *          Once the user inputs end of demo stop and delete
+ *          functions are executed.
+ *
+ * \param   chainsCfg       [IN]   Chains_Ctrl
+ *
+ *******************************************************************************
+*/
+Void chanis_tidl(Chains_Ctrl *chainsCfg)
+{
+    char ch;
+    Bool done = FALSE;
+    Int32 status;
+    Utils_DmaChCreateParams dmaParams;
+    UInt32 nullSourceLinkID;
+
+    /* Parse the Use Case Config file */
+    if(SYSTEM_LINK_STATUS_SOK == parseCfg(&gChainsObj))
+    {
+        gChainsObj.chainsCfg = chainsCfg;
+
+        /*  TIDL Core selection
+            DSP/EVE */
+        Vps_printf(tidlCoreMenu);
+        ch = Chains_readChar();
+
+        switch(ch)
+        {
+            case '1':
+                gChainsObj.tidlCore = TIDL_CORE_DSP;
+                break;
+//            default:
+//            case '2':
+//                gChainsObj.tidlCore = TIDL_CORE_EVE;
+//                break;
+        }
+
+        /*  TIDL Use case Mode selection
+            File Dump/Free Run */
+        Vps_printf(tidlUseCaseModeMenu);
+        ch = Chains_readChar();
+
+        switch(ch)
+        {
+            default:
+            case '1':
+                gChainsObj.enableOutFileWrite = TRUE;
+                break;
+            case '2':
+                gChainsObj.enableOutFileWrite = FALSE;
+                break;
+        }
+
+        /* Allocate the Algorithm create structure */
+        gChainsObj.pAlgCreateParams = ChainsCommon_Osal_memAlloc(
+                                            sizeof(TIDL_CreateParams),
+                                            32);
+        UTILS_assert(NULL != gChainsObj.pAlgCreateParams);
+
+        if(TRUE == gChainsObj.enableOutFileWrite)
+        {
+            /* EDMA channel for dumping the frame */
+            Utils_DmaChCreateParams_Init(&dmaParams);
+            status = Utils_dmaCreateCh(&gChainsObj.dumpFramesDmaObj, &dmaParams);
+            UTILS_assert(status == SYSTEM_LINK_STATUS_SOK);
+
+            /* Semaphore to flag end of input */
+            gChainsObj.eofSem = BspOsal_semCreate(0, (Bool) TRUE);
+            UTILS_assert(NULL != gChainsObj.eofSem);
+
+            /* Allocate buffer to copy the output frame after removing the padding */
+            gChainsObj.outputBuf[0] = (UInt32)ChainsCommon_Osal_memAlloc(
+                                        (gChainsObj.inWidth * gChainsObj.inHeight),
+                                        32);
+            UTILS_assert(NULL != gChainsObj.outputBuf[0]);
+
+            gChainsObj.outputBuf[1] = (UInt32)ChainsCommon_Osal_memAlloc(
+                                        (gChainsObj.inWidth * gChainsObj.inHeight),
+                                        32);
+            UTILS_assert(NULL != gChainsObj.outputBuf[1]);
+
+            /* Open the output file */
+            gChainsObj.outFp = ChainsCommon_Osal_fileOpen(
+                                        gChainsObj.outFileName,
+                                        CHAINSCOMMON_OSAL_FILEMODE_WRITE_BIN);
+            UTILS_assert(-1 != gChainsObj.outFp);
+
+            /* File Writer Task */
+            gChainsObj.fileWriteTask = BspOsal_taskCreate(
+                                            (BspOsal_TaskFuncPtr)fileWriteTaskMain,
+                                           "ChainsCommon_TIDL_FileWriteTsk",
+                                            TIDL_UC_FILEWRITE_TSK_PRI,
+                                            fileWriteTaskStack,
+                                            sizeof(fileWriteTaskStack),
+                                            &gChainsObj,
+                                            UTILS_TSK_AFFINITY_CORE0);
+            UTILS_assert(NULL != gChainsObj.fileWriteTask);
+
+            /* Semaphore for file write sync */
+            gChainsObj.fileWriteSem = BspOsal_semCreate(0, (Bool) TRUE);
+            UTILS_assert(NULL != gChainsObj.fileWriteSem);
+
+            gChainsObj.outFrameNum = 0;
+            gChainsObj.outNumFrames = 0;
+            gChainsObj.curOutBuf = 0;
+        }
+
+        /* TIDL init */
+        Vps_printf(">>>>>> chanis_tidl(): call 'tidlInit'");
+        tidlInit(&gChainsObj);
+
+        Vps_printf(">>>>>> chanis_tidl(): call 'chains_tidl_CreateApp'");
+        chains_tidl_CreateApp(&gChainsObj);
+        Vps_printf(">>>>>> chanis_tidl(): call 'chains_tidl_StartApp'");
+        chains_tidl_StartApp(&gChainsObj);
+
+        if(TRUE == gChainsObj.enableOutFileWrite)
+        {
+            Vps_printf(">>>>>> chanis_tidl(): gChainsObj.enableOutFileWrite is TRUE");
+            /* Wait for processing of all the frames */
+            BspOsal_semWait(gChainsObj.eofSem, BSP_OSAL_WAIT_FOREVER);
+
+            ChainsCommon_PrintStatistics();
+            chains_tidl_printStatisticsApp(&gChainsObj);
+
+            switch(gChainsObj.tidlCore)
+            {
+                case TIDL_CORE_DSP:
+                    nullSourceLinkID = gChainsObj.dspUcObj.NullSourceLinkID;
+                    break;
+
+                default:
+                case TIDL_CORE_EVE:
+//                    nullSourceLinkID = gChainsObj.eveUcObj.NullSourceLinkID;
+                    break;
+            }
+
+            /* Pause the Null Source Link */
+            status = System_linkControl(
+                            nullSourceLinkID,
+                            NULL_SRC_LINK_CMD_PAUSE,
+                            NULL,
+                            0,
+                            TRUE);
+            UTILS_assert (SYSTEM_LINK_STATUS_SOK == status);
+
+            /* Wait till all the output frames are dumped */
+            while(gChainsObj.outFrameNum < gChainsObj.outNumFrames)
+            {
+                Task_sleep(500);
+            }
+        }
+        else
+        {
+            Vps_printf(">>>>>> chanis_tidl(): gChainsObj.enableOutFileWrite is FALSE");
+            do
+            {
+                Vps_printf(tidlRunTimeMenu);
+                ch = Chains_readChar();
+
+                switch(ch)
+                {
+                    case '0':
+                        done = TRUE;
+                        break;
+
+                    case 'p':
+                    case 'P':
+                        ChainsCommon_PrintStatistics();
+                        chains_tidl_printStatisticsApp(&gChainsObj);
+                        break;
+
+                    default:
+                        break;
+                }
+            }while(FALSE == done);
+        }
+
+        Vps_printf(">>>>>> chanis_tidl(): call 'chains_tidl_StopAndDelete'");
+        chains_tidl_StopAndDelete(&gChainsObj);
+
+        /* TIDL DeInit */
+        Vps_printf(">>>>>> chanis_tidl(): call 'tidlDeInit'");
+        tidlDeInit(&gChainsObj);
+
+        if(TRUE == gChainsObj.enableOutFileWrite)
+        {
+            ChainsCommon_Osal_fileClose(gChainsObj.outFp);
+
+            BspOsal_taskDelete(&gChainsObj.fileWriteTask);
+
+            BspOsal_semDelete(&gChainsObj.fileWriteSem);
+
+            BspOsal_semDelete(&gChainsObj.eofSem);
+
+            Utils_dmaDeleteCh(&gChainsObj.dumpFramesDmaObj);
+
+            ChainsCommon_Osal_memFree(
+                        (Ptr)gChainsObj.outputBuf[0],
+                        (gChainsObj.inWidth * gChainsObj.inHeight));
+
+            ChainsCommon_Osal_memFree(
+                        (Ptr)gChainsObj.outputBuf[1],
+                        (gChainsObj.inWidth * gChainsObj.inHeight));
+        }
+
+        /* Free the Algorithm create structure */
+        Vps_printf(">>>>>> chanis_tidl(): call 'ChainsCommon_Osal_memFree'");
+        ChainsCommon_Osal_memFree(
+                    gChainsObj.pAlgCreateParams,
+                    sizeof(TIDL_CreateParams));
+    }
+
+    Vps_printf(" ############## END OF TIDL FILE I/O USE CASE ###############");
+}
