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

📄 tmtp.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
    if (pinst->instanceSetupCalled)
        return TP_ERR_ALREADY_SETUP;
    
    /* call board support function */
    if (boardTPConfig->initFunc) 
    {
        if (err = boardTPConfig->initFunc())
            goto tpInstanceSetupExit;
    }
    
    if (err = setup_isr(boardTPConfig->intNumber, setup->isr, setup->interruptPriority)) {
        goto tpInstanceSetupExit;
    }

    pinst->pidFilterInitial = setup->pidFilterInitial;
    
    tpSetSIZE(pinst->boardTPConfig->mmioBase, setup->size);
    tpSetBASE1(pinst->boardTPConfig->mmioBase, (UInt32)setup->base1);
    tpSetBASE2(pinst->boardTPConfig->mmioBase, (UInt32)setup->base2);

    ctl = MMIO(pinst->boardTPConfig->mmioBase + TP_CTL_OFFSET);
#ifdef __BIG_ENDIAN__
    tpInsertLITTLE_ENDIAN(ctl, 0);
#else
    tpInsertLITTLE_ENDIAN(ctl, 1);
#endif


    if (setup->hbeEnable)
        tpInsertHBE_INTEN(ctl, 1);
    else tpInsertHBE_INTEN(ctl, 0);
    
    if (setup->buf1FullEnable)
         tpInsertBUF1_INTEN(ctl, 1);
    else tpInsertBUF1_INTEN(ctl, 0);
    
    if (setup->buf2FullEnable)
         tpInsertBUF2_INTEN(ctl, 1);
    else tpInsertBUF2_INTEN(ctl, 0);
    
    if (setup->overrunEnable)
         tpInsertOVR_INTEN(ctl, 1);
    else tpInsertOVR_INTEN(ctl, 0);
    
   if (setup->lenErrEnable)
         tpInsertLEN_INTEN(ctl, 1);
    else tpInsertLEN_INTEN(ctl, 0);

    if (setup->error1Enable)
         tpInsertERR1_INTEN(ctl, 1);
    else tpInsertERR1_INTEN(ctl, 0);
    
    if (setup->error2Enable)
         tpInsertERR2_INTEN(ctl, 1);
    else tpInsertERR2_INTEN(ctl, 0);
    
    if (setup->error3Enable)
         tpInsertERR3_INTEN(ctl, 1);
    else tpInsertERR3_INTEN(ctl, 0);
    
    if (setup->doPidFiltering)
         tpInsertPID_FILTER_ENABLE(ctl, 1);
    else tpInsertPID_FILTER_ENABLE(ctl, 0);
    
    if (setup->doNegatedPidFiltering)
         tpInsertPID_FILTER_NEG_ENABLE(ctl, 1);
    else tpInsertPID_FILTER_NEG_ENABLE(ctl, 0);
    
    for (i = 0 ; i < TP_NROF_FILTERED_PIDS; i++) {
        tpSetPID_TABLE(pinst->boardTPConfig->mmioBase + i * sizeof(UInt32), setup->pidFilterInitial);
        pinst->filterInUse[i] = False;
        pinst->filterPids[i]  = pinst->pidFilterInitial;
    }
    
    if (setup->skipTPEIPackets)
         tpInsertTPEI_FILTER_ENABLE(ctl, 1);
    else tpInsertTPEI_FILTER_ENABLE(ctl, 0);
    
    if (setup->skipErrorPinPackets)
         tpInsertERROR_PIN_FILTER_ENABLE(ctl, 1);
    else tpInsertERROR_PIN_FILTER_ENABLE(ctl, 0);

    if (setup->dvalidEnable)
         tpInsertDVALID_ENABLE(ctl, 1);
    else tpInsertDVALID_ENABLE(ctl, 1);

    if (boardTPConfig->onlySampleDvalidBytes)
        tpInsertDVALID_ENABLE(ctl, 1);
    else tpInsertDVALID_ENABLE(ctl, 1);

    if (boardTPConfig->sampleOnNegativeEdge)
        ctl |= TP_NEG_EDGE;
    else
        ctl = ctl & ~TP_NEG_EDGE;

    MMIO(pinst->boardTPConfig->mmioBase + TP_CTL_OFFSET) = ctl;
    
    pinst->instanceSetupCalled = True;
    return TMLIBDEV_OK;
    
tpInstanceSetupExit:
    return err;   
}

extern tmLibdevErr_t
tpClose(Int instance)
{
    ptpInstVars_t    pinst = (ptpInstVars_t)instance;
    boardTPConfig_t *boardTPConfig = pinst->boardTPConfig;
    tmLibdevErr_t    err, err2;
    UInt32           i;
    Bool             instancesOpened;

    tpCheck(pinst, TMLIBDEV_ERR_NOT_OWNER);
    
    AppModel_suspend_scheduling();
    
    caps.unitCapabilities[pinst->unitName].numCurrentInstances--;
    tpAckRESET(pinst->boardTPConfig->mmioBase);

    err = intClose(pinst->boardTPConfig->intNumber);

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

    if (boardTPConfig->termFunc)
    {
        err2 = boardTPConfig->termFunc();
        if (err != TMLIBDEV_OK) err = err2;
    }

#ifdef LATER
    err2 = tmDevMgrRelease();
    if (err != TMLIBDEV_OK) err = err2;
#endif
    pinst->magic = 0;


    /* free the caps structure if need be */
    i=0; instancesOpened = False;
    
    while (i < caps.numberOfUnits)
    {
        if (caps.unitCapabilities[i].numCurrentInstances != 0)
        {
            instancesOpened = True;
            break;
        }
        i++;
    }
    
    if (instancesOpened == False)
    {
        free(caps.unitCapabilities);
        caps.unitCapabilities = Null;
    }

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

extern tmLibdevErr_t
tpStart(Int instance)
{
    ptpInstVars_t   pinst = (ptpInstVars_t)instance;

    tpCheck(pinst, TMLIBDEV_ERR_NOT_OWNER);
    
    if (!pinst->instanceSetupCalled)
        return TP_ERR_INITIALIZATION_NOT_COMPLETE;
    
    tmAssert((tpGetSIZE(pinst->boardTPConfig->mmioBase) % (3 * 64)) == 0, TP_ERR_BASE_SIZE);
    tmAssert((tpGetBASE1(pinst->boardTPConfig->mmioBase) % 64) == 0, TP_ERR_BASE_ALIGNMENT);
    tmAssert((tpGetBASE2(pinst->boardTPConfig->mmioBase) % 64) == 0, TP_ERR_BASE_ALIGNMENT);
    
    tpEnableENABLE(pinst->boardTPConfig->mmioBase);
    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
tpStop(Int instance)
{
    ptpInstVars_t   pinst = (ptpInstVars_t)instance;

    tpCheck(pinst, TMLIBDEV_ERR_NOT_OWNER);
    
    tpDisableENABLE(pinst->boardTPConfig->mmioBase);
    return TMLIBDEV_OK;
}

extern tmLibdevErr_t
tpConfig(Int instance, ptpConfig_t config)
{
    ptpInstVars_t    pinst = (ptpInstVars_t)instance;
    boardTPConfig_t *boardTPConfig = pinst->boardTPConfig;
    tmLibdevErr_t    rval = TMLIBDEV_OK;
    Int              i, freeIndex;
    UInt32           ctl;
    
    tpCheck(pinst, TMLIBDEV_ERR_NOT_OWNER);
    
    AppModel_suspend_scheduling();
    
    switch (config->command) {

    case TP_CMD_DO_PID_FILTERING:
    case TP_CMD_DO_NEGATED_PID_FILTERING:
        ctl = MMIO(pinst->boardTPConfig->mmioBase + TP_CTL_OFFSET);
        
        tpInsertPID_FILTER_ENABLE(ctl, 1);
        
        for (i = 0 ; i < TP_NROF_FILTERED_PIDS; i++) {
            tpSetPID_TABLE(pinst->boardTPConfig->mmioBase + i * sizeof(UInt32), pinst->pidFilterInitial);
            pinst->filterPids[i]  = pinst->pidFilterInitial;
            pinst->filterInUse[i] = False;
        }

        if (config->command == TP_CMD_DO_PID_FILTERING)
            tpInsertPID_FILTER_NEG_ENABLE(ctl, 0);
        else 
            tpInsertPID_FILTER_NEG_ENABLE(ctl, 1);
       
        MMIO(pinst->boardTPConfig->mmioBase + TP_CTL_OFFSET) = ctl;
        break;
        
    case TP_CMD_STOP_PID_FILTERING:
        tpDisablePID_FILTER_ENABLE(pinst->boardTPConfig->mmioBase);
        break;

    case TP_CMD_ADD_PID:
        /* search for the pid, make it unique in the table */
        for (freeIndex = -1, i = 0; i < TP_NROF_FILTERED_PIDS; i++) {
            if (pinst->filterInUse[i]) {
                if (pinst->filterPids[i] == (UInt16) config->value) {
                    /* already filtered */
                    goto tpConfigExit;
                }
            }
            else {
                freeIndex = i;
            }
        }

        if (freeIndex == -1) {
            rval = TP_ERR_NO_MORE_PID_FILTERS;
            break;
        }

        tmAssert((config->value & 0xffffe000) == 0, TP_ERR_INVALID_REQUESTED_PID);
        tpSetPID_TABLE(pinst->boardTPConfig->mmioBase + freeIndex * sizeof(UInt32), (UInt16) config->value);
        pinst->filterInUse[freeIndex] = True;
        pinst->filterPids [freeIndex] = config->value;
        break;

    case TP_CMD_DELETE_PID:
        if (pinst->pidFilterInitial == config->value) {
            rval = TP_ERR_INVALID_REQUESTED_PID;
            goto tpConfigExit;
        }

        for (i = 0; i < TP_NROF_FILTERED_PIDS; i++) {
            if (pinst->filterPids[i] == config->value)
                break;
        }
        if (i != TP_NROF_FILTERED_PIDS) {
            pinst->filterInUse[i] = False;
            tpSetPID_TABLE(pinst->boardTPConfig->mmioBase + i * sizeof(UInt32), pinst->pidFilterInitial);
        }
        break;
        
    default: 
        if (boardTPConfig != Null && boardTPConfig->configFunc)
            rval =  boardTPConfig->configFunc(config->command, config->value);
        else
            rval = BOARD_ERR_NULL_FUNCTION;
        break;
    }
    
tpConfigExit:
    AppModel_resume_scheduling();
    
    return rval;
}


⌨️ 快捷键说明

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