This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA2SX: Extending the TIDL OD usecase to multichannel usecase

Part Number: TDA2SX

chains_tidlOD_hlos.c
/******************************************************************************
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 "chains_tidlOD_hlos_priv.h"
#include <src/hlos/adas/include/chains.h>
#include <src/include/chains_common.h>
#include <src/include/chains_common_tidl.h>
#include <src/include/chains_common_osal.h>
#include "itidl_ti.h"
//#include <src/hlos/common/chains_common.h>
//#include <src/rtos/utils_common/include/utils_cbuf_ocmc.h>

//#include <src/rtos/utils_common/include/utils_cbuf_ocmc.h>
typedef enum
{
    UTILS_OCMC_RAM1 = 0U,

    UTILS_OCMC_RAM2,

    UTILS_OCMC_RAM3
}Utils_OcmcInstanceId;

/*******************************************************************************
 *  DEFINES
 *******************************************************************************
 */
#define TIDL_OD_INPUT_WIDTH          (768)
#define TIDL_OD_INPUT_HEIGHT         (320)
//#define TIDL_OD_INPUT_WIDTH          (1280)
//#define TIDL_OD_INPUT_HEIGHT         (720)
#define DEC_OUT_WIDTH               (768)
#define DEC_OUT_HEIGHT              (320)
//#define DEC_OUT_WIDTH               (1280)
//#define DEC_OUT_HEIGHT              (720)
#define TIDL_OD_DISPLAY_WIDTH        (TIDL_OD_INPUT_WIDTH*2)
#define TIDL_OD_DISPLAY_HEIGHT       (TIDL_OD_INPUT_HEIGHT*2)
#define TIDL_OD_DISPLAY_STARTX       (1920 - TIDL_OD_DISPLAY_WIDTH)/2
#define TIDL_OD_DISPLAY_STARTY       (64)

/* Num of TIDL processing pipelines */
#define NUM_PIPELINES               (4)

/* Semantic Segmenation input fps */
/* This should be based on the TIDL performance on 4 EVEs */
/* It should be less than the cumulative TIDL performance on 4 EVEs */
/* For eg if each TIDL is giving performace of 3 fps then it should be less than (4 x 3)*/
#define TIDL_OD_FPS_OPPHIGH          (NUM_PIPELINES * 6)

#define TIDL_OD_FPS_OPPNOM           (NUM_PIPELINES * 5)

#define OPP_HIGH_FREQUENCY          (650U)

/* Palettes used for color look up */
#define MAX_NUM_PALETTE             (10)

#define SYNC_DELTA                  (10)

/* The threshold should be more than the TIDL process time */
/* For eg. if TIDL process time is 400 msec then this should be more than 400 msec */
#define SYNC_THRESHOLD              (600)

/* OCMC */
#define OCMC_1_BASE_ADDRESS         (0)
#define OCMC_1_SIZE                 (512 * 1024)

#define OCMC_2_BASE_ADDRESS         (0)
#define OCMC_2_SIZE                 (1024 * 1024)

#define OCMC_3_BASE_ADDRESS          (0)
#define OCMC_3_SIZE                 (1024 * 1024)

//#define NET_BIN_FILE                "NET_OD.BIN"
//#define PARAMS_BIN_FILE             "PRM_OD.BIN"

#define NET_BIN_FILE 				"net_od.bin"
#define PARAMS_BIN_FILE 			"prm_od.bin"


/* DSP */
#define TIDL_COREID_DSP1            (1)
#define TIDL_LAYER_GROUPID_DSP1     (2)
#define TIDL_COREID_DSP2            (1)
#define TIDL_LAYER_GROUPID_DSP2     (2)

/* EVE */
#define TIDL_COREID_EVE1            (1)
#define TIDL_LAYER_GROUPID_EVE1     (1)
#define TIDL_COREID_EVE2            (1)
#define TIDL_LAYER_GROUPID_EVE2     (1)
#define TIDL_COREID_EVE3            (1)
#define TIDL_LAYER_GROUPID_EVE3     (1)
#define TIDL_COREID_EVE4            (1)
#define TIDL_LAYER_GROUPID_EVE4     (1)

/* Graphics window is just below the video window */
#define GRAPHICS_WIDTH              (1920)
#define GRAPHICS_HEIGHT             (1080 - TIDL_OD_DISPLAY_STARTY - TIDL_OD_DISPLAY_HEIGHT)

extern int errno;

/*******************************************************************************
 *  STRUCTURES
 *******************************************************************************
 */

/**
 *******************************************************************************
 *
 *  \brief  chains_tidlODAppObj
 *
 *        This structure contains all the LinksId's and create Params.
 *        The same is passed to all create, start, stop functions.
 *
 *******************************************************************************
*/
typedef struct
{
	chains_tidlOD_hlosObj ucObj;
    UInt32 displayWidth;
    UInt32 displayHeight;
    Chains_Ctrl *chainsCfg;
    TIDL_CreateParams *pAlgCreateParams;

} chains_tidlOD_hlosAppObj;

//chains_tidlOD_hlosAppObj gChainsObjtidlOD;

/*******************************************************************************
 *  GLOBALS
 *******************************************************************************
 */
static char tidlODRunTimeMenu[] = {
"\n "
"\n ===================="
"\n Chains Run-time Menu"
"\n ===================="
"\n "
"\n 0: Stop Chain"
"\n "
"\n 1: Pause Chain"
"\n 2: Resume Chain"
"\n "
"\n p: Print Statistics"
"\n "
"\n Enter Choice: "
"\n "
};

Void setSelectParams(SelectLink_CreateParams *pPrm){
	pPrm->numOutQue = 1U;
        pPrm->outQueChInfo[0].outQueId = 0;
        pPrm->outQueChInfo[0].numOutCh = 1;
	pPrm->outQueChInfo[0].inChNum[0] = 0;

}
Void ChainsCommon_SetFileRxPrms(
                        NullSrcLink_CreateParams *pPrm,
                        DecLink_CreateParams *pDecPrm,
                        UInt32 maxWidth,
                        UInt32 maxHeight,
                        UInt32 numCh,
                        UInt32 fps /* in msecs */
                        )
{
    UInt32 chId;
    DecLink_ChCreateParams *decPrm;
    System_LinkChInfo *pChInfo;

    pPrm->outQueInfo.numCh = numCh;



    pPrm->outQueInfo.numCh = 1;

    pPrm->timerPeriodMilliSecs = (1000/fps);

    for (chId = 0; chId < pPrm->outQueInfo.numCh; chId++)
    {
        pPrm->channelParams[chId].numBuffers = 4;

        pChInfo = &pPrm->outQueInfo.chInfo[chId];

        pChInfo->flags = System_Link_Ch_Info_Set_Flag_Data_Format(pChInfo->flags,
                                                    SYSTEM_DF_YUV420SP_UV);
        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*/
                                               SYSTEM_BUFFER_TYPE_BITSTREAM);
        pChInfo->width = maxWidth;
        pChInfo->height = maxHeight;
        pChInfo->startX = 0;
        pChInfo->startY = 0;
        pChInfo->pitch[0] = SystemUtils_align(pChInfo->width, 32);
        pChInfo->pitch[1] = SystemUtils_align(pChInfo->width, 32);

        pPrm->channelParams[chId].fileReadMode = NULLSRC_LINK_FILEREAD_RUN_TIME;

        strncpy(pPrm->channelParams[chId].nameDataFile, "input.h264", 260);
        strncpy(pPrm->channelParams[chId].nameIndexFile, "input.hdr", 260);
	printf("filepath : %s\n", pPrm->channelParams[chId].nameDataFile);
	//strncpy(pPrm->channelParams[chId].nameDataFile, "/home/srv_file/right_cam.h264", 260);
	//strncpy(pPrm->channelParams[chId].nameIndexFile, "/home/srv_file/right_cam.hdr", 260);

    }

    pPrm->dataRxMode = NULLSRC_LINK_DATA_RX_MODE_FILE;

    if(pDecPrm)
    {
        for (chId = 0; chId < numCh; chId++)
        {
            UTILS_assert (chId < DEC_LINK_MAX_CH);
            decPrm = &pDecPrm->chCreateParams[chId];

            decPrm->dpbBufSizeInFrames  = DEC_LINK_DPB_SIZE_IN_FRAMES_DEFAULT;
            decPrm->algCreateStatus     = DEC_LINK_ALG_CREATE_STATUS_CREATE;
            decPrm->decodeFrameType     = DEC_LINK_DECODE_ALL;

            decPrm->processCallLevel    = DEC_LINK_FRAMELEVELPROCESSCALL;
            decPrm->targetMaxWidth      = maxWidth;
            decPrm->targetMaxHeight     = maxHeight;
            decPrm->numBufPerCh         = 8;
            decPrm->defaultDynamicParams.targetBitRate = 10*1000*1000;
            decPrm->defaultDynamicParams.targetFrameRate = fps;
            decPrm->fieldMergeDecodeEnable = FALSE;

            /* H.264 */
            decPrm->format = SYSTEM_IVIDEO_H264HP;
            decPrm->profile = 3;
            decPrm->displayDelay = 0;
        }
   //     ChainsCommon_Sfm_SetDecLinkCallback(pDecPrm);
    }
}


Int32 Chains_tidlReadNet(sTIDL_Network_t *net, char *netFile)
{
    Int32 fp;
    UInt32 readSize;

    fp = ChainsCommon_Osal_fileOpen(
                            netFile,
                            CHAINSCOMMON_OSAL_FILEMODE_READ_BIN);

    printf("netfile=%s ,fp=%d",netFile,fp);
    UTILS_assert(-1 != fp);
     printf("dg0");
    ChainsCommon_Osal_fileRead(
                            fp,
                            (UInt8*)net,
                            sizeof(sTIDL_Network_t),
                            &readSize);
    UTILS_assert(readSize == sizeof(sTIDL_Network_t));
    printf("dg1");
    ChainsCommon_Osal_fileClose(fp);

    return SYSTEM_LINK_STATUS_SOK;
}

Int32 Chains_tidlAllocNetParamsMem(sTIDL_Network_t *net)
{
    Int32 i;

    for(i = 0; i < net->numLayers; i++)
    {
        if((TIDL_ConvolutionLayer == net->TIDLLayers[i].layerType) ||
           (TIDL_Deconv2DLayer == net->TIDLLayers[i].layerType))
        {
            sTIDL_ConvParams_t *conv2dPrms = \
                                            &net->TIDLLayers[i].layerParams.convParams;
            conv2dPrms->weights.bufSize = \
                net->weightsElementSize * (conv2dPrms->kernelW * conv2dPrms->kernelH *
                conv2dPrms->numInChannels * conv2dPrms->numOutChannels)
                /conv2dPrms->numGroups;
            conv2dPrms->weights.ptr = \
                ChainsCommon_Osal_memAlloc(conv2dPrms->weights.bufSize, 32);

            conv2dPrms->bias.bufSize = net->biasElementSize * conv2dPrms->numOutChannels;
            conv2dPrms->bias.ptr = \
                ChainsCommon_Osal_memAlloc(conv2dPrms->bias.bufSize, 32);
        }
        else if(TIDL_BiasLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_BiasParams_t *biasPrms = &net->TIDLLayers[i].layerParams.biasParams;
            biasPrms->bias.bufSize = net->biasElementSize * biasPrms->numChannels;
            biasPrms->bias.ptr = \
                ChainsCommon_Osal_memAlloc(biasPrms->bias.bufSize, 32);
        }
        else if(TIDL_BatchNormLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_BatchNormParams_t *batchNormPrms = \
                &net->TIDLLayers[i].layerParams.batchNormParams;
            batchNormPrms->weights.bufSize = \
                 net->weightsElementSize * batchNormPrms->numChannels;
            batchNormPrms->weights.ptr =
                ChainsCommon_Osal_memAlloc(batchNormPrms->weights.bufSize, 32);

            batchNormPrms->bias.bufSize = \
                net->biasElementSize * batchNormPrms->numChannels;
            batchNormPrms->bias.ptr =
                ChainsCommon_Osal_memAlloc(batchNormPrms->bias.bufSize, 32);

            batchNormPrms->reluParams.slope.bufSize =
                net->slopeElementSize * batchNormPrms->numChannels;
            if(TIDL_PRelU == batchNormPrms->reluParams.reluType)
            {
                batchNormPrms->reluParams.slope.ptr = \
                    ChainsCommon_Osal_memAlloc(
                            batchNormPrms->reluParams.slope.bufSize, 32);
            }
        }
        else if(TIDL_InnerProductLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_InnerProductParams_t *ipPrms = \
                                    &net->TIDLLayers[i].layerParams.innerProductParams;
            ipPrms->bias.bufSize =  net->biasElementSize * ipPrms->numOutNodes;
            ipPrms->bias.ptr = \
                ChainsCommon_Osal_memAlloc(
                    SystemUtils_align(ipPrms->bias.bufSize, 128), 32);

            ipPrms->weights.bufSize = \
                net->weightsElementSize* ipPrms->numInNodes * ipPrms->numOutNodes;
            ipPrms->weights.ptr = \
                ChainsCommon_Osal_memAlloc(
                    SystemUtils_align((ipPrms->weights.bufSize + 16 * \
                        net->TIDLLayers[i].layerParams.innerProductParams.numInNodes),
                            1024), 32);
        }
        else if(TIDL_DetectionOutputLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_DetectOutputParams_t *detectPrms = \
                             &net->TIDLLayers[i].layerParams.detectOutParams;
            detectPrms->priorBox.bufSize =  detectPrms->priorBoxSize * sizeof(float);
            detectPrms->priorBox.ptr = ChainsCommon_Osal_memAlloc(
                        SystemUtils_align(detectPrms->priorBoxSize *
                                            detectPrms->priorBox.bufSize, 128), 32);
        }
    }

    return SYSTEM_LINK_STATUS_SOK;
}

/**
 *******************************************************************************
 *
 * \brief   This function Reset the statCollector registers
 *          SYSTEM_COMMON_CMD_RESET_STAT_COLL send to only IPU1_0 core.
 *
 * \return  SYSTEM_LINK_STATUS_SOK on success
 *******************************************************************************
*/
Void Chains_sparseConv2dCoffesS8(Int8 *ptr, Int32 n, UInt8 thr)
{
    Int32 i0;

    for(i0 = 0; i0 < n; i0++)
    {
        if(((UInt8)(rand() & 0xFF)) > thr)
        {
            ptr[i0] =  0;
        }
    }
}

/**
 *******************************************************************************
 *
 * \brief   This function Reset the statCollector registers
 *          SYSTEM_COMMON_CMD_RESET_STAT_COLL send to only IPU1_0 core.
 *
 * \return  SYSTEM_LINK_STATUS_SOK on success
 *******************************************************************************
*/
Void Chains_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   This function Reset the statCollector registers
 *          SYSTEM_COMMON_CMD_RESET_STAT_COLL send to only IPU1_0 core.
 *
 * \return  SYSTEM_LINK_STATUS_SOK on success
 *******************************************************************************
*/
Void Chains_createRandPatternS8(Int8 *ptr, Int16 roi, Int16 n,
                                Int16 width, Int16 height, Int16 pitch,
                                Int32 chOffset)
{
    Int16 val;
    Int32   i0, i1, i2, i3;

    for(i3 = 0; i3 < roi; i3++)
    {
        for(i0 = 0; i0 < n; i0++)
        {
            for(i1 = 0; i1 < height; i1++)
            {
                for(i2 = 0; i2 < width; i2++)
                {
                    val = rand() & 0x7F;
                    ptr[i3 * n * chOffset + i0 * chOffset + i1 * pitch +i2] = \
                        (rand() & 1) ? val : -val;
                }
            }
        }
    }
}

/**
 *******************************************************************************
 *
 * \brief   This function Reset the statCollector registers
 *          SYSTEM_COMMON_CMD_RESET_STAT_COLL send to only IPU1_0 core.
 *
 * \return  SYSTEM_LINK_STATUS_SOK on success
 *******************************************************************************
*/
Int32 Chains_tidlFillNetParamsMem(sTIDL_Network_t *net, char *prmFile)
{
    Int32 i;
    Int32 fp;
    UInt32 dataSize, readSize;
  //  ENTER_TRACE();

    fp = ChainsCommon_Osal_fileOpen(
            prmFile,
            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))
        {
            sTIDL_ConvParams_t *conv2dPrms = &net->TIDLLayers[i].layerParams.convParams;

            dataSize = (conv2dPrms->numInChannels * conv2dPrms->numOutChannels *
                    conv2dPrms->kernelW * conv2dPrms->kernelH)/conv2dPrms->numGroups;

            /* Read weights based on its size */
            if(net->weightsElementSize == 2)
            {
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->weights.ptr)),
                        (dataSize * 2),
                        &readSize);
                UTILS_assert(readSize == (dataSize * 2));
            }
            else
            {
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->weights.ptr)),
                        dataSize,
                        &readSize);
                UTILS_assert(readSize == dataSize);
            }

            if(NO_ZERO_COEFF_PERCENT < 100)
            {
                Chains_sparseConv2dCofesS8((Int8 *)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->weights.ptr)),
                        conv2dPrms->weights.bufSize,
                        NO_ZERO_COEFF_PERCENT * 2.55);
            }

            if(conv2dPrms->enableBias)
            {
                dataSize = conv2dPrms->numOutChannels;
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->bias.ptr)),
                        (dataSize * net->biasElementSize),
                        &readSize);
                UTILS_assert(readSize == (dataSize * 2));
            }
            else
            {
                memset(
                        (Int8 *)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->bias.ptr)),0,conv2dPrms->numOutChannels * net->biasElementSize);
            }

            /* Cache Wb of the buffers*/
            dataSize = (conv2dPrms->numInChannels * conv2dPrms->numOutChannels *
                    conv2dPrms->kernelW * conv2dPrms->kernelH)/conv2dPrms->numGroups;
            if(net->weightsElementSize == 2)
            {
                dataSize *= 2;
            }
            ChainsCommon_Osal_cacheWb(
                    (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->weights.ptr)),
                    dataSize);

            dataSize = conv2dPrms->numOutChannels;
            ChainsCommon_Osal_cacheWb(
                    (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)conv2dPrms->bias.ptr)),
                    dataSize * net->biasElementSize);
        }
        else if(TIDL_BiasLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_BiasParams_t *biasPrms =&net->TIDLLayers[i].layerParams.biasParams;
            dataSize = biasPrms->numChannels;
            ChainsCommon_Osal_fileRead(
                    fp,
                    (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)biasPrms->bias.ptr)),
                    (dataSize * net->biasElementSize),
                    &readSize);
            UTILS_assert(readSize == (dataSize * net->biasElementSize));
            ChainsCommon_Osal_cacheWb(
                    (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)biasPrms->bias.ptr)),
                    (dataSize * net->biasElementSize));
        }
        else if(TIDL_BatchNormLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_BatchNormParams_t *bNPrms = \
                    &net->TIDLLayers[i].layerParams.batchNormParams;
            dataSize = bNPrms->numChannels;
            if(net->weightsElementSize == 2)
            {
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->weights.ptr)),
                        (dataSize * 2),
                        &readSize);
                UTILS_assert(readSize == (dataSize * 2));
                ChainsCommon_Osal_cacheWb(
                        (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->weights.ptr)),
                        (dataSize * 2));
            }
            else
            {
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->weights.ptr)),
                        dataSize,
                        &readSize);
                UTILS_assert(readSize == dataSize);
                ChainsCommon_Osal_cacheWb(
                        (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->weights.ptr)),
                        dataSize);
            }

            ChainsCommon_Osal_fileRead(
                    fp,
                    (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->bias.ptr)),
                    (dataSize * net->biasElementSize),
                    &readSize);
            UTILS_assert(readSize == (dataSize * net->biasElementSize));
            ChainsCommon_Osal_cacheWb(
                    (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->bias.ptr)),
                    (dataSize * net->biasElementSize));

            if(TIDL_PRelU == bNPrms->reluParams.reluType)
            {
                if(net->slopeElementSize == 2)
                {
                    ChainsCommon_Osal_fileRead(
                            fp,
                            (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->reluParams.slope.ptr)),
                            (dataSize * 2),
                            &readSize);
                    UTILS_assert(readSize == (dataSize * 2));
                    ChainsCommon_Osal_cacheWb(
                            (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->reluParams.slope.ptr)),
                            (dataSize * 2));
                }
                else
                {
                    ChainsCommon_Osal_fileRead(
                            fp,
                            (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->reluParams.slope.ptr)),
                            dataSize,
                            &readSize);
                    UTILS_assert(readSize == dataSize);
                    ChainsCommon_Osal_cacheWb(
                            (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)bNPrms->reluParams.slope.ptr)),
                            dataSize);
                }
            }
        }
        else if(TIDL_InnerProductLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_InnerProductParams_t *ipPrms = \
                    &net->TIDLLayers[i].layerParams.innerProductParams;
            dataSize = ipPrms->numInNodes * ipPrms->numOutNodes;
            /* Read weights based on its size */
            if(net->weightsElementSize == 2)
            {
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)ipPrms->weights.ptr)),
                        (dataSize * 2),
                        &readSize);
                UTILS_assert(readSize == (dataSize * 2));
                ChainsCommon_Osal_cacheWb(
                        (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)ipPrms->weights.ptr)),
                        (dataSize * 2));
            }
            else
            {
                ChainsCommon_Osal_fileRead(
                        fp,
                        (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)ipPrms->weights.ptr)),
                        dataSize,
                        &readSize);
                UTILS_assert(readSize == dataSize);
                ChainsCommon_Osal_cacheWb(
                        (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)ipPrms->weights.ptr)),
                        dataSize);
            }

            dataSize = ipPrms->numOutNodes;
            ChainsCommon_Osal_fileRead(
                    fp,
                    (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)ipPrms->bias.ptr)),
                    (dataSize * net->biasElementSize),
                    &readSize);
            UTILS_assert(readSize == (dataSize * net->biasElementSize));
            ChainsCommon_Osal_cacheWb(
                    (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)ipPrms->bias.ptr)),
                    (dataSize * net->biasElementSize));
        }
        else if(TIDL_DetectionOutputLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_DetectOutputParams_t *detectPrms = \
                    &net->TIDLLayers[i].layerParams.detectOutParams;
            dataSize = detectPrms->priorBoxSize;
            ChainsCommon_Osal_fileRead(
                    fp,
                    (UInt8*)(ChainsCommon_Osal_getVirtAddr((UInt32)detectPrms->priorBox.ptr)),
                    (dataSize * 4),
                    &readSize);
            UTILS_assert(readSize == (dataSize * 4));
            ChainsCommon_Osal_cacheWb(
                    (UInt32)(ChainsCommon_Osal_getVirtAddr((UInt32)detectPrms->priorBox.ptr)),
                    (dataSize * 4));
        }
    }

    ChainsCommon_Osal_fileClose(fp);

    //Cache wb since it is read on EVE and DSP
    Vps_printf("Cache WB for sTIDL_Network_t\n");
    ChainsCommon_Osal_cacheWb(
            (UInt32)net,
            sizeof(sTIDL_Network_t));

 //   EXIT_TRACE();
    return SYSTEM_LINK_STATUS_SOK;
}
/**
 *******************************************************************************
 *
 * \brief   This function Reset the statCollector registers
 *          SYSTEM_COMMON_CMD_RESET_STAT_COLL send to only IPU1_0 core.
 *
 * \return  SYSTEM_LINK_STATUS_SOK on success
 *******************************************************************************
*/
Int32 Chains_tidlFreeNetParamsMem(sTIDL_Network_t *net)
{
    Int32 i;

    for(i = 0; i < net->numLayers; i++)
    {
        if((TIDL_ConvolutionLayer == net->TIDLLayers[i].layerType) ||
           (TIDL_Deconv2DLayer == net->TIDLLayers[i].layerType))
        {
            sTIDL_ConvParams_t *conv2dPrms = \
                                            &net->TIDLLayers[i].layerParams.convParams;
            conv2dPrms->weights.bufSize = \
                net->weightsElementSize * (conv2dPrms->kernelW * conv2dPrms->kernelH *
                conv2dPrms->numInChannels * conv2dPrms->numOutChannels)
                /conv2dPrms->numGroups;
            ChainsCommon_Osal_memFree(
                                conv2dPrms->weights.ptr, conv2dPrms->weights.bufSize);

            conv2dPrms->bias.bufSize = net->biasElementSize * conv2dPrms->numOutChannels;
            ChainsCommon_Osal_memFree(
                    conv2dPrms->bias.ptr, conv2dPrms->bias.bufSize);
        }
        else if(TIDL_BiasLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_BiasParams_t *biasPrms = &net->TIDLLayers[i].layerParams.biasParams;
            biasPrms->bias.bufSize = net->biasElementSize * biasPrms->numChannels;
            ChainsCommon_Osal_memFree(
                    biasPrms->bias.ptr, biasPrms->bias.bufSize);
        }
        else if(TIDL_BatchNormLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_BatchNormParams_t *batchNormPrms = \
                &net->TIDLLayers[i].layerParams.batchNormParams;
            batchNormPrms->weights.bufSize = \
                 net->weightsElementSize * batchNormPrms->numChannels;
            ChainsCommon_Osal_memFree(
                    batchNormPrms->weights.ptr, batchNormPrms->weights.bufSize);

            batchNormPrms->bias.bufSize = \
                net->biasElementSize * batchNormPrms->numChannels;
            ChainsCommon_Osal_memFree(
                    batchNormPrms->bias.ptr, batchNormPrms->bias.bufSize);

            batchNormPrms->reluParams.slope.bufSize =
                net->slopeElementSize * batchNormPrms->numChannels;
            if(TIDL_PRelU == batchNormPrms->reluParams.reluType)
            {
                ChainsCommon_Osal_memFree(
                        batchNormPrms->reluParams.slope.ptr,
                        batchNormPrms->reluParams.slope.bufSize);
            }
        }
        else if(TIDL_InnerProductLayer == net->TIDLLayers[i].layerType)
        {
            sTIDL_InnerProductParams_t *ipPrms = \
                                    &net->TIDLLayers[i].layerParams.innerProductParams;
            ipPrms->bias.bufSize =  net->biasElementSize * ipPrms->numOutNodes;
            ChainsCommon_Osal_memFree(
                    ipPrms->bias.ptr, SystemUtils_align(ipPrms->bias.bufSize, 128));


            ipPrms->weights.bufSize = \
                net->weightsElementSize* ipPrms->numInNodes * ipPrms->numOutNodes;
            ChainsCommon_Osal_memFree(
                    ipPrms->weights.ptr,
                    SystemUtils_align((ipPrms->weights.bufSize + 16 * \
                        net->TIDLLayers[i].layerParams.innerProductParams.numInNodes),
                            1024));
        }
    }

    return SYSTEM_LINK_STATUS_SOK;
}


static Void chains_tidlOD_hlos_SetVPEPrms(
                    VpeLink_CreateParams *pPrm,
                    UInt32 numCh,
                    UInt32 displayWidth,
                    UInt32 displayHeight,
                    UInt32 inputWidth,
                    UInt32 inputHeight
                    )
{
    UInt16 chId;

    pPrm->enableOut[0] = TRUE;

    for(chId = 0; chId < numCh; chId++)
    {
        pPrm->chParams[chId].outParams[0].numBufsPerCh = 6;

        pPrm->chParams[chId].outParams[0].width = displayWidth;
        pPrm->chParams[chId].outParams[0].height = displayHeight;
        pPrm->chParams[chId].outParams[0].dataFormat = SYSTEM_DF_YUV420SP_UV;

        pPrm->chParams[chId].scCfg.bypass       = FALSE;
        pPrm->chParams[chId].scCfg.nonLinear    = FALSE;
        pPrm->chParams[chId].scCfg.stripSize    = 0;

        pPrm->chParams[chId].scCropCfg.cropStartX = 32;
        pPrm->chParams[chId].scCropCfg.cropStartY = 24;
        pPrm->chParams[chId].scCropCfg.cropWidth = inputWidth-32;
        pPrm->chParams[chId].scCropCfg.cropHeight = inputHeight-24;
    }
}

static Void tidlODInit(chains_tidlOD_hlosAppObj *pObj)
{
    /* Read the network file */
    printf("debug0\n");
    Chains_tidlReadNet(&pObj->pAlgCreateParams->net, NET_BIN_FILE);
    printf("debug1\n");
    /* Allocate memory for the net */
    Chains_tidlAllocNetParamsMem(&pObj->pAlgCreateParams->net);
    printf("debug2\n");
    /* Fill the new parameters */
    Chains_tidlFillNetParamsMem(&pObj->pAlgCreateParams->net, PARAMS_BIN_FILE);
    printf("debug3\n");
    /* Init all the 3 instances of the OCMC */
    //Utils_cbufOcmcInit(UTILS_OCMC_RAM1);
    //Utils_cbufOcmcInit(UTILS_OCMC_RAM2);
    //Utils_cbufOcmcInit(UTILS_OCMC_RAM3);
}


static Void tidlODDeInit(chains_tidlOD_hlosAppObj *pObj)
{
    /* Free the net memories */
    Chains_tidlFreeNetParamsMem(&pObj->pAlgCreateParams->net);
}

/**
 *******************************************************************************
 *
 * \brief   Start the capture display Links
 *
 *          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_tidlOD_hlosAppObj
 *
 * \return  SYSTEM_LINK_STATUS_SOK on success
 *
 *******************************************************************************
*/
Void chains_tidlOD_hlos_StartApp(chains_tidlOD_hlosAppObj *pObj)
{
 //   Chains_memPrintHeapStatus();
	ChainsCommon_memPrintHeapStatus();
 //   ChainsCommon_StartDisplayDevice(pObj->chainsCfg->displayType);
    chains_tidlOD_hlos_Start(&pObj->ucObj);
    ChainsCommon_prfLoadCalcEnable(TRUE, FALSE, FALSE);
}

/**
 *******************************************************************************
 *
 * \brief   Delete the capture display Links
 *
 *          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_tidlOD_hlosAppObj
 *
 *******************************************************************************
*/
Void chains_tidlOD_hlos_StopAndDelete(chains_tidlOD_hlosAppObj *pObj)
{
    chains_tidlOD_hlos_Stop(&pObj->ucObj);
    chains_tidlOD_hlos_Delete(&pObj->ucObj);

    ChainsCommon_StopDisplayCtrl();
 //   ChainsCommon_StopDisplayDevice(pObj->chainsCfg->displayType);

    /* Print the HWI, SWI and all tasks load */
    /* Reset the accumulated timer ticks */
    ChainsCommon_prfLoadCalcEnable(FALSE, TRUE, TRUE);
}


static Void ChainsCommon_tidlODSetObjectDrawPrms(
            AlgorithmLink_ObjectDrawCreateParams *pOdDrawPrm)
{

    pOdDrawPrm->imgFrameStartX   = 0;
    pOdDrawPrm->imgFrameStartY   = 0;
    pOdDrawPrm->imgFrameWidth   = TIDL_OD_INPUT_WIDTH;
    pOdDrawPrm->imgFrameHeight  = TIDL_OD_INPUT_HEIGHT;
    pOdDrawPrm->numOutBuffers    = 3;
    pOdDrawPrm->objectRectThickness = 1;
    pOdDrawPrm->objectTsrDrawTrafficSigns = FALSE;
    pOdDrawPrm->laneThickness = 2;
    pOdDrawPrm->laneDrawLines = FALSE;
    pOdDrawPrm->laneScaleX = 2.0;
    pOdDrawPrm->laneScaleY = 2.0;
    pOdDrawPrm->drawOption = ALGORITHM_LINK_OBJECT_DETECT_DRAW_ALL;
    pOdDrawPrm->numDrawAlg = 0;
    pOdDrawPrm->scoreThreshold = 0.4;
    pOdDrawPrm->drawAlgId[pOdDrawPrm->numDrawAlg]
            = ALGORITHM_LINK_OBJECT_DETECT_DRAW_ALG_TIDL_OD;
    pOdDrawPrm->numDrawAlg++;
}
/**
 *******************************************************************************
 *
 * \brief   Semantic Segmentation
 *
 *          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_tidlOD_hlos_SetAppPrms(chains_tidlOD_hlosObj *pUcObj, Void *appObj)
{
    UInt32 frequency =  0;
    UInt32 FileReadFps = TIDL_OD_FPS_OPPNOM;

    chains_tidlOD_hlosAppObj *pObj = (chains_tidlOD_hlosAppObj*)appObj;

//    frequency = Utils_getClkHz(UTILS_CLK_ID_EVE) / 1000000U;

    /*
     * Set the framerate according to the frequency
     */
    if (frequency >= OPP_HIGH_FREQUENCY)
    {
        FileReadFps = TIDL_OD_FPS_OPPHIGH;
    }
    else
    {
        FileReadFps = TIDL_OD_FPS_OPPNOM;
    }

    ChainsCommon_GetDisplayWidthHeight(
                                pObj->chainsCfg->displayType,
                                &pObj->displayWidth,
                                &pObj->displayHeight);
    setSelectParams(&pUcObj->Select_pass1Prm);
    setSelectParams(&pUcObj->Select_pass2Prm);
    setSelectParams(&pUcObj->Select_pass3Prm);
    setSelectParams(&pUcObj->Select_pass4Prm);

    ChainsCommon_SetFileRxPrms(
                        &pUcObj->NullSourcePrm,
                        &pUcObj->DecodePrm,
                        DEC_OUT_WIDTH,
                        DEC_OUT_HEIGHT,
                        1,                  /* numCh */
                        25);        /* fps */

    /* SetFileRxPrm sets the file open to inHeader and inData overriding the same*/
   // strncpy(pUcObj->NullSourcePrm.channelParams[0].nameDataFile, "inData_OD", 260);
   // strncpy(pUcObj->NullSourcePrm.channelParams[0].nameIndexFile, "inHeader_OD", 260);

    strncpy(pUcObj->NullSourcePrm.channelParams[0].nameDataFile, "/opt/vision_sdk/input.h264", 260);
    strncpy(pUcObj->NullSourcePrm.channelParams[0].nameIndexFile, "/opt/vision_sdk/input.hdr", 260);
    printf("filepath2 : %s\n", pUcObj->NullSourcePrm.channelParams[0].nameDataFile);
    chains_tidlOD_hlos_SetVPEPrms(
                    &pUcObj->VPEPrm,
                    1,
                    DEC_OUT_WIDTH,
                    DEC_OUT_HEIGHT,
                    DEC_OUT_WIDTH,
                    DEC_OUT_HEIGHT
                    );

    /* YUV420SP to planar RGB conversion */
    pUcObj->Alg_tidlpreprocPrm.outPad = TIDL_MAX_PAD_SIZE;
    pUcObj->Alg_tidlpreprocPrm.numOutputQueues = NUM_PIPELINES;
    pUcObj->Alg_tidlpreprocPrm.procMode = TIDLPREPROC_LINK_PROCMODE_Y2R;

    /* TIDL on EVE1 */
    pUcObj->Alg_tidl_Eve1Prm.cacheInvInBuf = 0;
    pUcObj->Alg_tidl_Eve1Prm.cacheWbOutBuf = 0;
    pUcObj->Alg_tidl_Eve1Prm.pAlgCreateParams = pObj->pAlgCreateParams;
    pUcObj->Alg_tidl_Eve1Prm.curCoreId = TIDL_COREID_EVE1;
    pUcObj->Alg_tidl_Eve1Prm.currLayersGroupId = TIDL_LAYER_GROUPID_EVE1;
//    pUcObj->Alg_tidl_Eve1Prm.ocmcAddr = OCMC_3_BASE_ADDRESS;
    pUcObj->Alg_tidl_Eve1Prm.ocmcAddr = 0;
    /* TIDL on EVE2 */
    pUcObj->Alg_tidl_Eve2Prm.cacheInvInBuf = 0;
    pUcObj->Alg_tidl_Eve2Prm.cacheWbOutBuf = 0;
    pUcObj->Alg_tidl_Eve2Prm.pAlgCreateParams = pObj->pAlgCreateParams;
    pUcObj->Alg_tidl_Eve2Prm.curCoreId = TIDL_COREID_EVE2;
    pUcObj->Alg_tidl_Eve2Prm.currLayersGroupId = TIDL_LAYER_GROUPID_EVE2;
   // pUcObj->Alg_tidl_Eve2Prm.ocmcAddr = OCMC_3_BASE_ADDRESS + (OCMC_3_SIZE/2);
    pUcObj->Alg_tidl_Eve2Prm.ocmcAddr = 0;
    /* TIDL on EVE3 */
    pUcObj->Alg_tidl_Eve3Prm.cacheInvInBuf = 0;
    pUcObj->Alg_tidl_Eve3Prm.cacheWbOutBuf = 0;
    pUcObj->Alg_tidl_Eve3Prm.pAlgCreateParams = pObj->pAlgCreateParams;
    pUcObj->Alg_tidl_Eve3Prm.curCoreId = TIDL_COREID_EVE3;
    pUcObj->Alg_tidl_Eve3Prm.currLayersGroupId = TIDL_LAYER_GROUPID_EVE3;
   // pUcObj->Alg_tidl_Eve3Prm.ocmcAddr = OCMC_1_BASE_ADDRESS;
    pUcObj->Alg_tidl_Eve3Prm.ocmcAddr = 0;
    /* TIDL on EVE4 */
    pUcObj->Alg_tidl_Eve4Prm.cacheInvInBuf = 0;
    pUcObj->Alg_tidl_Eve4Prm.cacheWbOutBuf = 0;
    pUcObj->Alg_tidl_Eve4Prm.pAlgCreateParams = pObj->pAlgCreateParams;
    pUcObj->Alg_tidl_Eve4Prm.curCoreId = TIDL_COREID_EVE4;
    pUcObj->Alg_tidl_Eve4Prm.currLayersGroupId = TIDL_LAYER_GROUPID_EVE4;
    //pUcObj->Alg_tidl_Eve4Prm.ocmcAddr = OCMC_2_BASE_ADDRESS;
    pUcObj->Alg_tidl_Eve4Prm.ocmcAddr = 0;

    /* TIDL on DSP */
    pUcObj->Alg_tidl_DspPrm.cacheInvInBuf = 1;
    pUcObj->Alg_tidl_DspPrm.cacheWbOutBuf = 1;
    pUcObj->Alg_tidl_DspPrm.pAlgCreateParams = pObj->pAlgCreateParams;
    pUcObj->Alg_tidl_DspPrm.curCoreId = TIDL_COREID_DSP1;
    pUcObj->Alg_tidl_DspPrm.currLayersGroupId = TIDL_LAYER_GROUPID_DSP1;

    /* Sync parameters */
    pUcObj->SyncPrm.syncDelta = SYNC_DELTA;
    pUcObj->SyncPrm.syncThreshold = SYNC_THRESHOLD;

    ChainsCommon_tidlODSetObjectDrawPrms(&pUcObj->Alg_ObjectDrawPrm);
    ChainsCommon_SetDisplayPrms(
                                &pUcObj->DisplayPrm,
                                NULL,
                                pObj->chainsCfg->displayType,
                                pObj->displayWidth,
                                pObj->displayHeight);

    pUcObj->DisplayPrm.rtParams.tarWidth = TIDL_OD_DISPLAY_WIDTH;
    pUcObj->DisplayPrm.rtParams.tarHeight = TIDL_OD_DISPLAY_HEIGHT;
    pUcObj->DisplayPrm.rtParams.posX = TIDL_OD_DISPLAY_STARTX;
    pUcObj->DisplayPrm.rtParams.posY = TIDL_OD_DISPLAY_STARTY;
    pUcObj->DisplayPrm.displayId = DISPLAY_LINK_INST_DSS_VID1;

    ChainsCommon_StartDisplayCtrl(
                                pObj->chainsCfg->displayType,
                                pObj->displayWidth,
                                pObj->displayHeight);

    /* Graphics source parameters */
    pUcObj->GrpxSrcPrm.grpxBufInfo.dataFormat = SYSTEM_DF_BGR16_565;
    pUcObj->GrpxSrcPrm.grpxBufInfo.width = GRAPHICS_WIDTH;
    pUcObj->GrpxSrcPrm.grpxBufInfo.height = GRAPHICS_HEIGHT;
    pUcObj->GrpxSrcPrm.tidlOdOverlay = TRUE;
    pUcObj->GrpxSrcPrm.captureWidth = TIDL_OD_INPUT_WIDTH;
    pUcObj->GrpxSrcPrm.captureHeight = TIDL_OD_INPUT_HEIGHT;

    /* Graphics Display parameters */
    /* Graphics display will be at the end of the video display window */
    pUcObj->Display_GrpxPrm.rtParams.tarWidth = GRAPHICS_WIDTH;
    pUcObj->Display_GrpxPrm.rtParams.tarHeight = GRAPHICS_HEIGHT;
    pUcObj->Display_GrpxPrm.rtParams.posX = 0;
    pUcObj->Display_GrpxPrm.rtParams.posY = \
            (pUcObj->DisplayPrm.rtParams.posY + TIDL_OD_DISPLAY_HEIGHT);
    pUcObj->Display_GrpxPrm.displayId = DISPLAY_LINK_INST_DSS_GFX1;
}

static Void pausetidlOD(chains_tidlOD_hlosAppObj *pObj)
{
    Int32 status;

    status = System_linkControl(
                    pObj->ucObj.NullSourceLinkID,
                    NULL_SRC_LINK_CMD_PAUSE,
                    NULL,
                    0,
                    TRUE);
    UTILS_assert (SYSTEM_LINK_STATUS_SOK == status);
}

static Void resumetidlOD(chains_tidlOD_hlosAppObj *pObj)
{
    Int32 status;

    status = System_linkControl(
                    pObj->ucObj.NullSourceLinkID,
                    NULL_SRC_LINK_CMD_RESUME,
                    NULL,
                    0,
                    TRUE);
    UTILS_assert (SYSTEM_LINK_STATUS_SOK == status);
}

/**
 *******************************************************************************
 *
 * \brief   Semantic Segmentation
 *
 *          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_tidlOD_hlos(Chains_Ctrl *chainsCfg)
{
    char ch;
chains_tidlOD_hlosAppObj *gChainsObjtidlOD = (chains_tidlOD_hlosAppObj *)ChainsCommon_Osal_memAlloc(sizeof(chains_tidlOD_hlosAppObj),32);

    Bool done = FALSE;
    gChainsObjtidlOD = (chains_tidlOD_hlosAppObj *)ChainsCommon_Osal_getVirtAddr((UInt32)gChainsObjtidlOD);
    chainsCfg->ucAppObj = gChainsObjtidlOD;
    gChainsObjtidlOD->chainsCfg = chainsCfg;

    /* Allocate the Algorithm create structure */
    gChainsObjtidlOD->pAlgCreateParams = (TIDL_CreateParams *)ChainsCommon_Osal_memAlloc(
                                        sizeof(TIDL_CreateParams),
                                        32);
    gChainsObjtidlOD->pAlgCreateParams = ChainsCommon_Osal_getVirtAddr((UInt32)gChainsObjtidlOD->pAlgCreateParams);
    UTILS_assert(NULL != gChainsObjtidlOD->pAlgCreateParams);

    /* Semantic Segmentation Init */
    tidlODInit(gChainsObjtidlOD);
	    ChainsCommon_Osal_cacheWb((UInt32)(gChainsObjtidlOD->pAlgCreateParams), sizeof(TIDL_CreateParams));
    gChainsObjtidlOD->pAlgCreateParams = ChainsCommon_Osal_getPhysAddr((UInt32)gChainsObjtidlOD->pAlgCreateParams);

    chains_tidlOD_hlos_Create(&gChainsObjtidlOD->ucObj, gChainsObjtidlOD);

    chains_tidlOD_hlos_StartApp(gChainsObjtidlOD);
    
    do
    {
        Vps_printf(tidlODRunTimeMenu);
        ch = Chains_readChar();

        switch(ch)
        {
            case '0':
                done = TRUE;
                break;

            case '1':
                pausetidlOD(gChainsObjtidlOD);
                break;

            case '2':
                resumetidlOD(gChainsObjtidlOD);
                break;

            case 'p':
            case 'P':
                ChainsCommon_PrintStatistics();
                chains_tidlOD_hlos_printStatistics(&gChainsObjtidlOD->ucObj);
                break;

            default:
                break;
        }
    }while(FALSE == done);
//     gChainsObjtidlOD->pAlgCreateParams = ChainsCommon_Osal_getPhysAddr((UInt32)gChainsObjtidlOD->pAlgCreateParams);
    chains_tidlOD_hlos_StopAndDelete(gChainsObjtidlOD);

    /* Semantic Segmentation DeInit */
    tidlODDeInit(gChainsObjtidlOD);

    /* Free the Algorithm create structure */
    ChainsCommon_Osal_memFree(
                gChainsObjtidlOD->pAlgCreateParams,
                sizeof(TIDL_CreateParams));
    // ChainsCommon_Osal_cacheWb((UInt32)(gChainsObjtidlOD.pAlgCreateParams), sizeof(TIDL_CreateParams));
    //gChainsObjtidlOD.pAlgCreateParams = ChainsCommon_Osal_getPhysAddr((UInt32)gChainsObjtidlOD.pAlgCreateParams);

}

Hi Team,

We are able to run the TIDL object detection usecase with single channel successfully, but when we are trying to extend the same to multichannel, we are unable to do so. We are able to build it, but during runtime we can see that only one channel is created. We tried clean make for the same but still unsuccessful. Kindly help us regarding the same. I have attached the logs as well as the code.