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

📄 philips_dtv_ref5.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    UInt32        d = data;
    UInt32        b, a;
    UInt32        i = 0;
    Int           j;
    
    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    a = address << 2;
    b = findFlashBank(a) * DTV_REF5_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 dtvRef5FlashReadBlock(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 dtvRef5FlashWriteBlock(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) * DTV_REF5_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) * DTV_REF5_FLASH_BANK_SIZE;
    }

    return TMLIBDEV_OK;
}

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

    tmAssert(flashInitialized, FLASH_ERR_NOT_INITIALIZED);

    if (sector >= DTV_REF5_FLASH_SECTOR_NR)
        return FLASH_ERR_INVALID_SECTOR_NR;
    
    s = (sector * DTV_REF5_FLASH_SECTOR_SIZE) << 2;
    b = findFlashBank(s) * DTV_REF5_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 * DTV_REF5_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 (typ. time should be 64s per chip) */
    while ((flashBaseAddress[b] >> 24)!= 0xff)
    {
        if (i++ > 100000)
            return FLASH_ERR_ERASE_TIMEOUT;
        microsleep(1000);
    }
    
    return TMLIBDEV_OK;
}

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

    err = eraseBank(0);

    return err;    
}

static Int gpioInstance;
/***********************************************************************/
static tmLibdevErr_t dtvRef5_board_activate(pcomponent_t comp)
{
    DP(("dtvRef5_board_activate\n"));

    TRY(dtvRef5_board_detect());
    DP(("  after detect\n"));

    TRY(dtvRef5_board_init());
    DP(("  after init\n"));
    
    /* the board has to be registered now */
    TRY(dtvRef5_board_register(comp));
    DP(("  after register\n"));

    return TMLIBDEV_OK;
}

static tmLibdevErr_t dtvRef5_board_init(void)
{
    pprocCapabilities_t procCap;
    Int                 i;
    UInt                * volatile gpioBase;
    iicDirectionParam_t iicDirectionParams;
    UInt32              temp;
    tmLibdevErr_t       err;
    gpioInstanceSetup_t gpioSetup;

    DP_R5(("dtvRef5_board_init\n"));
    
    TRY(procGetCapabilities(&procCap));

    iicDirectionParams.directionSwitchFunction = dtvRef5DirectionSwitch;
    iicDirectionParams.defaultDirection        = IIC_DIRECTION_BOOT_ROM;
    TRY(iicDirectionInit(&iicDirectionParams));

    /* initialize XIO (used for flash memory) */
    MMIO(XIO_CTL)  = DTV_REF5_XIO_BASE | 0x0000079f ;
    
    /* initialize and register GPIO */
    TRY(gpioInit());

    /* disable all GPIO interrupts */
    gpioBase = &(MMIO(GPIO_EV1));
    for (i=0; i<16; i+=2)
        gpioBase[i] = 0xFF000000;

    /* open and initialize all GPIO J pins (0 - 19) that are used in the BSP */
    err = gpioOpen(&gpioInstance);
    if (err)
        return err;

    err = gpioGetInstanceSetup(gpioInstance, &gpioSetup);
    if (err)
    {
        gpioClose(gpioInstance);
        return err;
    }

    for (i = GPIO_GPIOJ00; i <= GPIO_GPIOJ03; i++)
    {
        gpioInsertMode(gpioSetup.pinMode[i >> 4], i - (GPIO_GPIOJ00 & 0xfffffff0), gpioDisabledTriStateDriver);
        gpioInsertPin(gpioSetup.pinMask[i >> 5], i - (GPIO_GPIOJ00 & 0xffffffe0), 1);
    }

    gpioInsertMode(gpioSetup.pinMode[i >> 4], i - (GPIO_GPIOJ00 & 0xfffffff0), gpioEnabledTriStateDriver);
    gpioInsertPin(gpioSetup.pinMask[i >> 5], i - (GPIO_GPIOJ00 & 0xffffffe0), 1);
    i++;

    for (; i <= GPIO_GPIOJ07; i++)
    {
        gpioInsertMode(gpioSetup.pinMode[i >> 4], i - (GPIO_GPIOJ00 & 0xfffffff0), gpioDisabledTriStateDriver);
        gpioInsertPin(gpioSetup.pinMask[i >> 5], i - (GPIO_GPIOJ00 & 0xffffffe0), 1);
    }

    for (; i <= GPIO_GPIOJ17; i++)
    {
        gpioInsertMode(gpioSetup.pinMode[i >> 4], i - (GPIO_GPIOJ00 & 0xfffffff0), gpioEnabledTriStateDriver);
        gpioInsertPin(gpioSetup.pinMask[i >> 5], i - (GPIO_GPIOJ00 & 0xffffffe0), 1);
    }

    for (; i <= GPIO_GPIOJ19; i++)
    {
        gpioInsertMode(gpioSetup.pinMode[i >> 4], i - (GPIO_GPIOJ00 & 0xfffffff0), gpioDisabledTriStateDriver);
        gpioInsertPin(gpioSetup.pinMask[i >> 5], i - (GPIO_GPIOJ00 & 0xffffffe0), 1);
    }

    err = gpioInstanceSetup(gpioInstance, &gpioSetup);
    if (err)
    {
        gpioClose(gpioInstance);
        return err;
    }

    /* set GPIO output pins to default values
        4 - front panel LED - low (LED on)
        8 - iic select - low, IIC goes to boot eprom
        9 - audio L3 clock 4 - low
       10 - audio L3 clock 1 - low
       11 - NIM L3 clock -low
       12 - NIM L3 strobe - low
       13 - L3 data - low
       14 - L3 mode low
       15 - NIM reset, high to get it out of reset 
       16 - SAA7125 reset low (to keep it in reset)
       17 - SAA7167 reset low (to keep it in reset)
    */ 
    temp = MMIO(GPIOJ_OUT);
    temp &= 0xfffc7fef;
    MMIO(GPIOJ_OUT) = temp;
    microsleep(50);
    temp |= 0x00008000;
    MMIO(GPIOJ_OUT) = temp;

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


/******************** dtvRef5_board_detect *******************************
 * Returns true if the hardware appears to be a Philips DTV Ref. 5 board.
 */
static tmLibdevErr_t dtvRef5_board_detect(void)
{
    Int   line, error;
    UInt  d1, d2, mfgID;
    UInt8 eepromData[8];

    DP_R5(("dtvRef5_board_detect\n"));
    
    for (line = 0; line < 8; line++) {
        error = iicReadReg(IIC_EEPROM_ADDRESS, line, &d1);
        if (error) 
        {
            TRY(iicReadReg(IIC_EEPROM_ADDRESS, line, &d1));
        }
        error = iicReadReg(IIC_EEPROM_ADDRESS, line, &d2);
        if (error)
        {
            TRY(iicReadReg(IIC_EEPROM_ADDRESS, line, &d2));
        }
        eepromData[line] = d1;
    }
    mfgID   = (eepromData[3] << 8) + eepromData[4];
    boardID = (eepromData[1] << 8) + eepromData[2];

    if (mfgID != BOARD_ID_PHILIPS_MFG_ID)
    {
        DP(("  unknown mfgID %#x\n", mfgID));
        return BOARD_ERR_UNKNOWN_BOARD;
    }

    if (boardID == BOARD_VERSION_PHILIPS_DTV_REF5) 
        return TMLIBDEV_OK;

    DP(("  unknown boardID %#x\n", boardID));

    return BOARD_ERR_UNKNOWN_BOARD;
}

static tmLibdevErr_t dtvRef5_board_register(pcomponent_t comp)
{
    DP_R5(("dtvRef5_board_register\n"));

    TRY(tsaBoardRegisterFlash(0, &dtvRef5Flash));
    TRY(tsaBoardRegisterAO(0, &dtvRef5_ao_1));
    TRY(tsaBoardRegisterHDVO(0,  &dtvRef5_hdvo));
    TRY(tsaBoardRegisterMP(0, &dtvRef5_mp));
    TRY(tsaBoardRegisterPIC(0,  &dtvRef5PIC));
    TRY(tsaBoardRegisterIR(0,  &dtvRef5IR));

    /* register the DTV REF 5 (Jupiter) */
    if (boardID == BOARD_VERSION_PHILIPS_DTV_REF5)
        TRY(tsaBoardRegisterBoard(boardID, "DTV REF 5"));

    return TMLIBDEV_OK;
}

TSA_COMP_DEF_O_COMPONENT( Philips_dtvRef5, 
                          TSA_COMP_BUILD_ARG_LIST_1("bsp/boardID"), 
                          dtvRef5_board_activate);
                          


⌨️ 快捷键说明

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