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

📄 xioreg.c

📁 用于TM1300/PNX1300系列DSP(主要用于视频处理)的设备库的源码
💻 C
字号:
/*
 * Copyright (c) 1999 by TriMedia Technologies. 
 *
 * +------------------------------------------------------------------+
 * | This software is furnished under a license and may only be used  |
 * | and copied in accordance with the terms and conditions of  such  |
 * | a license and with the inclusion of this copyright notice. This  |
 * | software or any other copies of this software may not be provided|
 * | or otherwise made available to any other person.  The ownership  |
 * | and title of this software is not transferred.                   |
 * |                                                                  |
 * | The information in this software is subject  to change without   |
 * | any  prior notice and should not be construed as a commitment by |
 * | TriMedia Technologies.                                           |
 * |                                                                  |
 * | this code and information is provided "as is" without any        |
 * | warranty of any kind, either expressed or implied, including but |
 * | not limited to the implied warranties of merchantability and/or  |
 * | fitness for any particular purpose.                              |
 * +------------------------------------------------------------------+
 *
 *  Module name              : xioReg.c    1.5
 *
 *  Last update              : 18:43:52 - 00/11/09
 *
 *
 */


/* --------------------------- includes ----------------------------------- */
#include <tmlib/tmtypes.h>
#include <tmlib/dprintf.h>
#include <tm1/tmAssert.h>

#include "xioReg.h"

/* ---------------------------- defines ------------------------------------ */
#define NUM_SUPPORTED_REGS 16

/* ---------------------------- statics ------------------------------------ */
static UInt8            regImage[NUM_SUPPORTED_REGS];
static bankSwitchFunc_t bankSwitchFunc;
static UInt32           regBank;
static UInt32           numWriteRegs;
static Bool             xioRegInitDone = False;
volatile static UInt32 *regBaseAddress;

/*---------------------------- functions -----------------------------------*/
tmLibdevErr_t xioRegInit(pxioRegParam_t p)
{
    Int           i;
    UInt32        d;
    tmLibdevErr_t rVal;

    tmAssert(p, -1);
    tmAssert(p->bankSwitchFunc, -1);
    tmAssert((p->numWriteRegs <= NUM_SUPPORTED_REGS), -2);
    
    bankSwitchFunc = p->bankSwitchFunc;
    regBank        = p->bank;
    numWriteRegs   = p->numWriteRegs;
    regBaseAddress = p->baseAddress;
    xioRegInitDone = True;
    
    /* write default values to registers */
    rVal = bankSwitchFunc(regBank);
    tmAssert(rVal == TMLIBDEV_OK, rVal);
    for (i = 0; i < numWriteRegs; i++)
    {
        regImage[i] = p->defaultValues[i];
        d = (UInt32) regImage[i];
        xioSimpleWrite ( (UInt32)(&regBaseAddress[i]), d );
    }
    
    return rVal;
}

tmLibdevErr_t xioRegWriteBit(UInt32 address, UInt8 mask, Bool setBit)
{
    tmLibdevErr_t rVal;
    UInt32        d;
    
    rVal = bankSwitchFunc(regBank);
    tmAssert(rVal == TMLIBDEV_OK, rVal);
    
    regImage[address] &= ~mask;
    if (setBit)
    {
        regImage[address] |= mask;
    }
    
    d = (UInt32) regImage[address];
    xioSimpleWrite ( (UInt32)(&regBaseAddress[address]), d );

    return rVal;
}

tmLibdevErr_t xioRegWriteByte(UInt32 address, UInt8 data)
{
    tmLibdevErr_t rVal;
    UInt32        d;
    
    rVal = bankSwitchFunc(regBank);
    tmAssert(rVal == TMLIBDEV_OK, rVal);
    
    regImage[address] = data;

    d = (UInt32) regImage[address];
    xioSimpleWrite ( (UInt32)(&regBaseAddress[address]), d );
    DP(("regBaseAddress[address] = d: %x[%x] = %x\n", regBaseAddress, address, d));
    return rVal;
}

tmLibdevErr_t xioRegReadByte(UInt32 address, UInt8 * byte)
{
    tmLibdevErr_t rVal;
    UInt32        d;
    
    rVal = bankSwitchFunc(regBank);
    tmAssert(rVal == TMLIBDEV_OK, rVal);
    
    d = xioSimpleRead ( (UInt32)(&regBaseAddress[address]));
    regImage[address] = d;
    *byte = d;
    DP(("%x = regBaseAddress[address]: %x[%x]\n", d, regBaseAddress, address));
    
    return rVal;
}


/******************************************************************************/
unsigned char xioSimpleRead ( volatile UInt32 Addr)
{
    volatile UInt32 Data;
    volatile UInt32 *Address;

    UInt32 GlobalInterruptState;
    UInt32 DCLockCtlState;

    Address = (volatile UInt32* ) Addr;

    GlobalInterruptState = intCLEAR_IEN();
    DCLockCtlState = pciExtractDC_LOCK();
    pciSetDC_LOCK(PCI_DC_LOCK_CTL_HEN);

    Data = *Address;

    pciSetDC_LOCK(DCLockCtlState);
    intRESTORE_IEN(GlobalInterruptState);

    return (unsigned char)( ( Data >> 24 ) & 0x000000ff );
}

void xioSimpleWrite ( volatile UInt32 Addr, volatile UInt8 Data )
{
    volatile UInt32 *Address;

    UInt32 GlobalInterruptState;
    UInt32 DCLockCtlState;

    Address = (volatile UInt32* ) Addr;

    GlobalInterruptState = intCLEAR_IEN();
    DCLockCtlState = pciExtractDC_LOCK();
    pciSetDC_LOCK(PCI_DC_LOCK_CTL_HEN);

    *Address = (((UInt32)Data) << 24);

    pciSetDC_LOCK(DCLockCtlState);
    intRESTORE_IEN(GlobalInterruptState);

}

⌨️ 快捷键说明

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