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

📄 dvr_ref1.c

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

/******************************************************************************/
static tmLibdevErr_t dvr_ref1_VI_SetBrightness(UInt val)
{
    return tw98SetBrightness(&dvr_ref1_vi.vDec, val);
}

/******************************************************************************/
static tmLibdevErr_t dvr_ref1_VI_SetContrast(UInt val)
{
    return tw98SetContrast(&dvr_ref1_vi.vDec, val);
}

/******************************************************************************/
static tmLibdevErr_t dvr_ref1_VI_SetHue(UInt val)
{
    return tw98SetHue(&dvr_ref1_vi.vDec, val);
}

/********************** flash functions *************************************/
volatile static UInt32  *flashBaseAddress;
static Bool             flashInitialized = False;

/***********************************************************************/
static UInt32 findFlashBank(UInt32 address)
{
    UInt32 i;
    UInt32 b;
    
    for (i = 0; i < 4; i ++)
    {
        b = i * DVR_REV1_FLASH_BANK_SIZE;
        if ((b <= address) && (address < (b + DVR_REV1_FLASH_BANK_SIZE)))
            return i;
    }
    
    return i;
}
/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashInit(void)
{
    flashBaseAddress = (UInt32 *) DVR_REV1_FLASH_BASE;

    flashInitialized = True;
    
    return TMLIBDEV_OK;
}

/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashReadWord(UInt32 address, UInt32 * data)
{
    UInt32        d = 0;
    UInt32        a = address << 2;
    Int           j;

    tmAssert(data, FLASH_ERR_NULL_POINTER);
    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

#ifdef __BIG_ENDIAN__
    for (j = 3; j >= 1; j--)
#else
    for (j = 0; j < 3; j++)
#endif
    {
        d |= flashBaseAddress[a + j] & 0xff000000;
        d >>= 8;
    }
    d |= flashBaseAddress[a + j] & 0xff000000;
    
    *data = d;

    return TMLIBDEV_OK;
}

/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashWriteWord(UInt32 address, UInt32 data)
{
    UInt32        d = data;
    UInt32        b, a;
    UInt32        i = 0;
    Int           j;
    
    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    a = address << 2;
    b = findFlashBank(a) * DVR_REV1_FLASH_BANK_SIZE;

#ifdef __BIG_ENDIAN__
    for (j = 3; j >= 0; j--)
#else
    for (j = 0; j < 4; j++)
#endif
    {
        /* get flash into write state */
        flashBaseAddress[b + 0x555] = 0xaa000000;
        flashBaseAddress[b + 0x2aa] = 0x55000000;
        flashBaseAddress[b + 0x555] = 0xa0000000;

        flashBaseAddress[a + j] = d << 24;

        while (((UInt8) ((flashBaseAddress[a + j] >> 24) & 0xff)) != (UInt8) d)
        {
            if (i++ > 100000)
            {
               return FLASH_ERR_WRITE;
            }
        }
        
        d >>= 8;
    }

    return TMLIBDEV_OK;
}

/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashReadBlock(UInt32 address, UInt32 * data, UInt32 numberOfWords)
{
    UInt32        d = 0;
    UInt32        a = address << 2;
    Int           j, i;

    tmAssert(data, FLASH_ERR_NULL_POINTER);
    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    for (i = 0; i < numberOfWords; i++)
    {
#ifdef __BIG_ENDIAN__
        for (j = 3; j >= 1; j--)
#else
        for (j = 0; j < 3; j++)
#endif
        {
            d |= flashBaseAddress[a + j] & 0xff000000;
            d >>= 8;
        }
        d |= flashBaseAddress[a + j] & 0xff000000;
    
        *data++ = d;
        d = 0;
        a += 4;
    }

    return TMLIBDEV_OK;
}

/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashWriteBlock(UInt32 address, UInt32 * data, UInt32 numberOfWords)
{
    UInt32        d;
    UInt32        b, a;
    UInt32        i = 0;
    Int           j, k;
    
    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    a = address << 2;
    b = findFlashBank(a) * DVR_REV1_FLASH_BANK_SIZE;
    d = *data;

    for (k = 0; k < numberOfWords; k++)
    {
#ifdef __BIG_ENDIAN__
        for (j = 3; j >= 0; j--)
#else
        for (j = 0; j < 4; j++)
#endif
        {
            /* get flash into write state */
            flashBaseAddress[b + 0x555] = 0xaa000000;
            flashBaseAddress[b + 0x2aa] = 0x55000000;
            flashBaseAddress[b + 0x555] = 0xa0000000;

            flashBaseAddress[a + j] = d << 24;

            while (((UInt8) ((flashBaseAddress[a + j] >> 24) & 0xff)) != (UInt8) d)
            {
                if (i++ > 100000)
                {
                    return FLASH_ERR_WRITE;
                }
            }
        
            d >>= 8;
        }
        a += 4;
        d = data[k+1];
        i = 0;
        b = findFlashBank(a) * DVR_REV1_FLASH_BANK_SIZE;
    }

    return TMLIBDEV_OK;
}

/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashEraseSector(UInt32 sector)
{
    UInt32        i = 0;
    UInt32        s, b;

    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    if (sector >= DVR_REV1_FLASH_SECTOR_NR)
        return FLASH_ERR_INVALID_SECTOR_NR;
    
    s = (sector * DVR_REV1_FLASH_SECTOR_SIZE) << 2;
    b = findFlashBank(s) * DVR_REV1_FLASH_BANK_SIZE;
    flashBaseAddress[b + 0x555] = 0xaa000000;
    flashBaseAddress[b + 0x2aa] = 0x55000000;
    flashBaseAddress[b + 0x555] = 0x80000000;
    flashBaseAddress[b + 0x555] = 0xaa000000;
    flashBaseAddress[b + 0x2aa] = 0x55000000;
    flashBaseAddress[s]         = 0x30000000;
    /* wait 50 microseconds (sector erase timeout) */
    microsleep(50);
    /* wait max. 8s until sector is erased (typ. time should be 1s per sector) */
    while ((flashBaseAddress[s] >> 24)!= 0xff)
    {
        if (i++ > 8000000)
            return FLASH_ERR_ERASE_TIMEOUT;
        microsleep(1);
    }
    
    return TMLIBDEV_OK;
}

static tmLibdevErr_t eraseBank(UInt32 bank)
{
    UInt32        i = 0;
    UInt32        b;

    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    b = bank * DVR_REV1_FLASH_BANK_SIZE;
    flashBaseAddress[b + 0x555] = 0xaa000000;
    flashBaseAddress[b + 0x2aa] = 0x55000000;
    flashBaseAddress[b + 0x555] = 0x80000000;
    flashBaseAddress[b + 0x555] = 0xaa000000;
    flashBaseAddress[b + 0x2aa] = 0x55000000;
    flashBaseAddress[b + 0x555] = 0x10000000;
    /* wait max. 100s until chip is erased */
    while ((flashBaseAddress[b] >> 24)!= 0xff)
    {
        if (i++ > 100000)
            return FLASH_ERR_ERASE_TIMEOUT;
        microsleep(1000);
    }
    
    return TMLIBDEV_OK;
}

/***********************************************************************/
static tmLibdevErr_t dvr_ref1FlashEraseAll(void)
{
    tmLibdevErr_t err = TMLIBDEV_OK;
    
    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    err = eraseBank(0);

    return err;    
}

/******************** dvr_ref1_board_init *******************************
 *  The dvr_ref1 board comes up with peripherals reset.
 *  This function takes the board out of reset and leaves
 *  it in a good state.
 */
static tmLibdevErr_t dvr_ref1_board_init(void)
{

    L1_DP(("dvr_ref1_board_init\n"));

    /* set up XIO parameters */
    MMIO(XIO_CTL) = DVR_REV1_XIO_BASE_ADDRESS | 0x79f;

    /* should write all important registers to a known value here */
    dvr_ref1ResetVideo();
    dvr_ref1ResetAudio();
    microsleep(10);
    dvr_ref1EnableVideo();
    dvr_ref1EnableAudio();
    microsleep(1000);

    /* Now choose clock and data from TM1300 */
    dvr_ref1SelectVideoClockTM();
    dvr_ref1SelectVideoDataTMVo();
    dvr_ref1DisableVPXOut();
    dvr_ref1EnableTechwellData();
    
    /* disable PCI access to protect XIO against speculative loads */
    pciSetDC_LOCK(PCI_DC_LOCK_CTL_PDS);

    return TMLIBDEV_OK;
}                /* end of dvr_ref1_board_init() */

/******************** dvr_ref1_board_detect *******************************
 * Returns TMLIBDEV_OK if the hardware appears to be a Philips DVR_REV1 board.
 * This function reads subsystem ID and subsystem vendor ID from the boot
 * EEPROM and compares those to the values reserved for the Philips DVR_REV1 board.
 */
static tmLibdevErr_t dvr_ref1_board_detect(void)
{
    Int     line, error;
    UInt    d1;
    UInt    boardID;    
    UInt    mfgID;      
    UInt8   eepromData[8];

    L1_DP(("dvr_ref1_board_detect\n"));

    /* read boot EEPROM */
    for (line = 0; line < 8; line++)
    {
        error = iicReadReg(IIC_EEPROM_ADDRESS, line, &d1);
        if (error)
        {
            TRY(iicReadReg(IIC_EEPROM_ADDRESS, line, &d1));
        }
        eepromData[line] = d1;
    }

    /* get subsystem vendor ID */
    mfgID   = (eepromData[3] << 8) + eepromData[4];
    /* get subsystem ID */
    boardID = (eepromData[1] << 8) + eepromData[2];
    
    L1_DP(("Read in IIC: mfgID = %d / boardID = %d\n", mfgID, boardID ));

    /* check if this is a Philips board */
    if (mfgID != BOARD_ID_PHILIPS_MFG_ID)
        return BOARD_ERR_UNKNOWN_BOARD;

    /* check if this is an DVR_REV1 board */
    if (boardID == BOARD_VERSION_DVR_REF_1AB)
        return TMLIBDEV_OK;
   
    /* board not recognized, return error */      
    return BOARD_ERR_UNKNOWN_BOARD;
}

static tmLibdevErr_t dvr_ref1_board_register(pcomponent_t comp)
{
    UInt32 ID = BOARD_VERSION_DVR_REF_1AB;
    
    L1_DP(("dvr_ref1_board_register\n"));
    
    TRY(tsaBoardRegisterBoard(ID, "Philips DVR_REF1"));

    /* now register all the capabilities of the board : */
    /* AO, AI, VO, VI, SSI, etc */
    L1_DP(("Board registered\n"));

    TRY(tsaBoardRegisterAO(0,  &dvr_ref1_ao));
    TRY(tsaBoardRegisterAI(0,  &dvr_ref1_ai));
    TRY(tsaBoardRegisterVO(0,  &dvr_ref1_vo));
    TRY(tsaBoardRegisterVI(0,  &dvr_ref1_vi));
    TRY(tsaBoardRegisterFlash(0, &dvr_ref1Flash));

    L1_DP(("Interfaces registered\n"));

    return TMLIBDEV_OK;
}

static tmLibdevErr_t dvr_ref1_board_activate(pcomponent_t comp)
{
    TRY(dvr_ref1_board_detect());
    
    TRY(dvr_ref1_board_init());
    
    TRY(dvr_ref1_board_register(comp));

    return TMLIBDEV_OK;
}

 

/******************************************************************************/

TSA_COMP_DEF_O_COMPONENT( Philips_dvr_ref1, 
                          TSA_COMP_BUILD_ARG_LIST_1("bsp/boardID"), 
                          dvr_ref1_board_activate);

⌨️ 快捷键说明

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