⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tmvi.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
    return TMLIBDEV_OK;
}



/*
 * Function         : Set/change instance setup parameters Raw operation mode.
 *                    Assumes viInstanceSetup is already called.
 * Parameters       : instance (I)  instance to set parameters for
 *                    setup    (I)  pointer to buffer
 *                                  holding new parameters
 * Function Result  : resulting error condition
 */

extern tmLibdevErr_t
viRawSetup(Int instance, viRawSetup_t * setup)
{
    Int             vi_ctl;
    pviInstVars_t   pinst = (pviInstVars_t)instance;
    boardVIConfig_t *boardVIConfig = pinst->boardVIConfig;

    IS_VALID(instance);
    tmAssert(setup != Null, TMLIBDEV_ERR_NULL_PARAMETER);

    viSetSIZE__CHECKM(boardVIConfig->mmioBase, setup->size);
    viSetBASE1__CHECKM(boardVIConfig->mmioBase, (UInt) setup->base1);
    viSetBASE2__CHECKM(boardVIConfig->mmioBase, (UInt) setup->base2);

    vi_ctl = MMIO(boardVIConfig->mmioBase + VI_CTL_OFFSET);

    viInsertBUF1FULL_IEN__CHECK(vi_ctl, setup->buf1fullEnable);
    viInsertBUF2FULL_IEN__CHECK(vi_ctl, setup->buf2fullEnable);
    viInsertOVF_IEN__CHECK(vi_ctl, setup->overflowEnable);
    viInsertOVR_IEN__CHECK(vi_ctl, setup->overrunEnable);
    viInsertMODE__CHECK(vi_ctl, setup->mode);

    MMIO(boardVIConfig->mmioBase + VI_CTL_OFFSET) = vi_ctl;
    
    pinst->setupCalled = viRawSetupCalled;
    return TMLIBDEV_OK;
}

/*--------------------- open/close functions ---------------------------------*/

/*
 * Function         : Assigns a unique video in instance for the caller.
 * Parameters       : instance  (O)  pointer to result variable
 * Function Result  : resulting error condition
 */

extern tmLibdevErr_t
viOpen(Int * instance)
{
    tmLibdevErr_t err;
    err = viOpenM(instance, unit0);
    return err;
}

extern          tmLibdevErr_t
viOpenM(Int * instance, unitSelect_t unitName)
{
    gpioInstanceSetup_t gpioSetup;
    tmLibdevErr_t       err = TMLIBDEV_OK;
    boardVIConfig_t    *viBoardConfig;
    pviInstVars_t       pinst;
    UInt32              i;
    Int                 unitIndex;
    
    tmAssert(instance != Null, TMLIBDEV_ERR_NULL_PARAMETER);
    err = tsaBoardGetVI(unitName, &viBoardConfig);
    if (err != TMLIBDEV_OK)
        return TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;

    AppModel_suspend_scheduling();

    /* make sure that the capabilities are valid */
    err = prepareCapabilities();
    if (err != TMLIBDEV_OK)
        goto viOpenExit;

    if (getUnitIndex(unitName, &unitIndex))
    {
        err = TMLIBDEV_ERR_NOT_AVAILABLE_IN_HW;
        goto viOpenExit;
    }
    
    if (capabilities.unitCapabilities[unitIndex].numCurrentInstances >= 
        capabilities.unitCapabilities[unitIndex].numSupportedInstances)
    {
        err = TMLIBDEV_ERR_NO_MORE_INSTANCES;
        goto viOpenExit;
    }
    
    pinst = (pviInstVars_t)malloc(sizeof(viInstVars_t));
    if (pinst == Null)
    {
        err = TMLIBDEV_ERR_MEMALLOC_FAILED;
        goto viOpenExit;
    }
    
    if (err = intOpen(viBoardConfig->intNumber)) 
    {
        free(pinst);
        goto viOpenExit;
    }

    viAckRESETM(viBoardConfig->mmioBase);

    if (err = setup_isr(viBoardConfig->intNumber, Null, intPRIO_0)) 
    {
        free(pinst);
        intClose(viBoardConfig->intNumber);
        goto viOpenExit;
    }

    pinst->magic         = VI_MAGIC;
    pinst->setupCalled   = viNoSetupCalled;
    pinst->unitName      = unitName;
    pinst->unitIndex     = unitIndex;
    pinst->boardVIConfig = viBoardConfig;
    pinst->gpioInstance  = 0;
    
    if (gpioOpen(&(pinst->gpioInstance)) == TMLIBDEV_OK)
    {
        /* Get the default instance setup */
        gpioGetInstanceSetup(pinst->gpioInstance, &gpioSetup);
        for (i = viBoardConfig->gpioFirstPin; i <= viBoardConfig->gpioLastPin; i++)
        {
            gpioInsertMode(gpioSetup.pinMode[i >> 4], 
                           i - (viBoardConfig->gpioFirstPin & 0xfffffff0), 
                           gpioRegularMode);
            gpioInsertPin(gpioSetup.pinMask[i >> 5], 
                          i - (viBoardConfig->gpioFirstPin & 0xffffffe0), 1);
        }
        err = gpioInstanceSetup(pinst->gpioInstance, &gpioSetup);
        if (err != TMLIBDEV_OK)
        {
            gpioClose(pinst->gpioInstance);
            intClose(viBoardConfig->intNumber);
            free(pinst);
            goto viOpenExit;
        }
    }

    *instance = (Int) pinst;

    capabilities.unitCapabilities[unitIndex].numCurrentInstances++;

viOpenExit:
    AppModel_resume_scheduling();
    return err;
}

/*
 * Function         : Deallocates the video in instance,
 *                    and uninstall its handler when it has one.
 * Parameters       : instance  (I)  instance to give up
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viClose(Int instance)
{
    tmLibdevErr_t   err = TMLIBDEV_OK, err2;
    pviInstVars_t   pinst = (pviInstVars_t)instance;

    IS_VALID(instance);

    AppModel_suspend_scheduling();
    
    viAckRESETM(pinst->boardVIConfig->mmioBase);
    err = intClose(pinst->boardVIConfig->intNumber);

    if (pinst->gpioInstance != 0)
    {
        gpioClose(pinst->gpioInstance);
    }

    if (pinst->boardVIConfig->term_func)
    {
        err2 = pinst->boardVIConfig->term_func();
        if (err == TMLIBDEV_OK) err = err2;
    }
    /* we do not return BOARD_ERR_NULL_FUNCTION if there is no term function */
    /* because IREF does not have a term function, and this is the normal    */
    /* behavior. Perhaps, we should add a dummy term function for IREF ???   */
    
    capabilities.unitCapabilities[pinst->unitIndex].numCurrentInstances--;
    pinst->magic = 0;

    AppModel_resume_scheduling();
    if (pinst)
        free(pinst);   
    return err;
}

/*--------------------- general action functions -----------------------------*/

/*
 * Function         : Start or stop video in unit.
 * Parameters       : instance  (I)  instance to start/stop
 *                    start     (I)  if True, video in unit will be started
 *                                   if False, video in unit will be stopped
 * Function Result  : resulting error condition
 * NB               : this function is redundant, since its
 *                    effects can also be achieved using timInstanceControl
 */

extern          tmLibdevErr_t
viStart(Int instance)
{
    pviInstVars_t pinst = (pviInstVars_t)instance;
    
    IS_VALID(instance);

    if (pinst->setupCalled == viNoSetupCalled)
        return VI_ERR_INITIALIZATION_NOT_COMPLETE;

    viEnableENABLEM(pinst->boardVIConfig->mmioBase);
    return TMLIBDEV_OK;
}

extern          tmLibdevErr_t
viStop(Int instance)
{
    pviInstVars_t pinst = (pviInstVars_t)instance;

    IS_VALID(instance);

    viDisableENABLEM(pinst->boardVIConfig->mmioBase);
    return TMLIBDEV_OK;
}

/*------------------------- decoder related functions -----------------------*/

/*
 * Function         : Configure decoder according to the data passed in.
 * Parameters       : instance (I)  calling user's instance
 *                    subaddr  (I)  iicsubaddress of the decoder.
 *                    value    (I)  new value.
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viConfigureDecoder(Int instance, UInt32 subaddr, UInt32 value)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->Configure)
        return boardVIConfig->Configure(subaddr, value);
    else
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Get Video Standard of the decoder.
 * Parameters       : instance      (I) instance
 *                    videoStandard (O) video standard detected
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viGetVideoStandard(Int instance, tmVideoAnalogStandard_t * videoStandard)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);

    *videoStandard = vasNone;
    if (boardVIConfig->GetStandard)
        return boardVIConfig->GetStandard(videoStandard);
    else 
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Get Color Standard of a specific adapter on the decoder.
 * Parameters       : instance      (I) instance 
 *                    adapterType   (I) video input adapter type (CVBS, S-Video)
 *                    adapterNum    (I) unit number of adapter
 *                    colorStandard (O) the color standard detected,
 *                                      when the function is not implemented
 *                                      this will be vasNone
 * Function Result  : resulting error condition
 */

extern tmLibdevErr_t 
viGetAdapterVideoStandard(Int instance, tmVideoAnalogAdapter_t  adapter, UInt adapterNum, tmVideoAnalogStandard_t *videoStandard)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);

    *videoStandard = vasNone;
    if (boardVIConfig->getAdapterVideoStandard)
        return boardVIConfig->getAdapterVideoStandard(&boardVIConfig->vDec, adapter, adapterNum, videoStandard);
    else 
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Set brightness of the decoder.
 * Parameters       : instance    (I) instance
 *                    Level       (I) brightness level
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viSetBrightness(Int instance, UInt level)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->setBrightness)
        return boardVIConfig->setBrightness(level);
    else
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Set Contrast of the decoder.
 * Parameters       : instance  (I) instance
 *                    Level     (I) contrast level
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viSetContrast(Int instance, UInt level)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->setContrast)
        return boardVIConfig->setContrast(level);
    else
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Set hue of the decoder.
 * Parameters       : instance  (I) instance
 *                    Level     (I) hue level
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viSetHue(Int instance, UInt level)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;
    
    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->setHue)
        return boardVIConfig->setHue(level);
    else
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Set saturation of the decoder.
 * Parameters       : instance  (I) instance
 *                    Level     (I) saturation level
 * Function Result  : resulting error condition
 */

extern          tmLibdevErr_t
viSetSaturation(Int instance, UInt level)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;
    
    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->setSaturation)
        return boardVIConfig->setSaturation(level);
    else
        return BOARD_ERR_NULL_FUNCTION;
}


/*
 * Function         : Get the line number in which the falling edge of VSync occurs 
 * Parameters       : instance      (I) instance
 *                    lineNumber    (O) receives the line number
 * Function Result  : resulting error condition
 */

extern tmLibdevErr_t
viGetVSyncFallingEdge(Int instance, UInt *lineNumber)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->getVSyncFallingEdge)
        return boardVIConfig->getVSyncFallingEdge(&boardVIConfig->vDec, lineNumber);
    else
        return BOARD_ERR_NULL_FUNCTION;
}


/*
 * Function         : Extract sliced VBI data from planar buffers
 * Parameters       : instance      (I) instance
 *                    Y             (I) pointer to Y data
 *                    U             (I) pointer to U data
 *                    Y             (I) pointer to V data
 *                    service       (I) teletext data service to extract
 *                    sizeY         (I) size of Y data
 *                    data          (I) buffer to write extracted data into
 *                    dataSize      (O) receives the number of extracted data bytes
 * Function Result  : resulting error condition
 */

extern tmLibdevErr_t
viGetSlicedData(Int instance, UInt8 *Y, UInt8 *U, UInt8 *V, tmVideoDataService_t service, UInt sizeY, UInt8 *data, UInt8 *dataSize)
{
    boardVIConfig_t *boardVIConfig = ((pviInstVars_t)instance)->boardVIConfig;

    IS_VALID(instance);
    tmAssert(boardVIConfig != Null, VI_ERR_UNINIT_DECODER);

    if (boardVIConfig->getSlicedData)
        return boardVIConfig->getSlicedData(&boardVIConfig->vDec, Y, U, V, service, sizeY, data, dataSize);
    else
        return BOARD_ERR_NULL_FUNCTION;
}

/*
 * Function         : Get information about the decoder's status (lock, field ID, etc.)
 * Parameters       : instance      (I) instance

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -