📄 dpx_api.c
字号:
/* the device through this handle */
*pDuplex = (void *)psDpxDDB;
/* Now locate the lowest index number for the empty DDBs */
for(u1Next=0; u1Next < DPX_MAX_NUM_DEVS; ++u1Next)
{
if(psDpxGdd->pDdb[u1Next] == DPX_NULL)
{
u1NextDev = u1Next;
break;
}
}
/* if it doesn't find one, something is terribly wrong */
if(u1NextDev == DPX_MAX_NUM_DEVS)
{
sysDuplexSemDelete(psDpxDDB->lockId);
sysDuplexMemFree(psDpxDDB);
ErrorCode = DPX_ERR_EXCEED_MAX_DEVS;
return (ErrorCode);
}
/* successfully added device, update GDD and increment device count */
psDpxGdd->pDdb[u1NextDev] = psDpxDDB;
(psDpxGdd->u1NumDevs)++;
/* do a software reset of the device */
/**************************************************************************
** For Rev.A, we need call the following function to work around the RAM
** initialization problem. This need be done only once after power up.
**************************************************************************/
if((u1DevIdType & DPX_MASK_MASTER_ID) == DUPLEX_DEV_ID_REV_A)
DpxRamInitFix(psDpxDDB->u4BaseAddr);
duplexHWReset(psDpxDDB->u4BaseAddr);
return (DPX_SUCCESS);
}
/*******************************************************************************
**
** duplexDelete
** ___________________________________________________________________________
**
** DESCRIPTION: This function is used to remove the specified device from the
** list of devices being controlled by the DUPLEX driver.
** Deleting a device involves de-allocating the DDB for that
** device.
**
** VALID STATES: DPX_PRESENT
**
** SIDE EFFECTS: The device state is changed to DPX_EMPTY.
**
** INPUTS: duplex - device handle used by the driver to access DDB
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (device is not in a valid state)
**
*******************************************************************************/
INT4 duplexDelete(DUPLEX duplex)
{
UINT1 u1NextDev;
INT4 ErrorCode = DPX_SUCCESS;
/* assume success, unless proven otherwise!! */
sDPX_DDB *psDpxDdb;
/* check if the module has been initilized or not */
if( psDpxGdd == DPX_NULL)
{
ErrorCode = DPX_ERR_MOD_NOT_INIT;
return (ErrorCode);
}
if(duplex == DPX_NULL)
{
ErrorCode = DPX_ERR_INVALID_DEVICE;
return (ErrorCode);
}
/* device not found, unless proven otherwise */
/*-------------------------------------------*/
ErrorCode = DPX_ERR_INVALID_DEVICE;
psDpxDdb = (sDPX_DDB *)duplex;
for(u1NextDev=0; u1NextDev < DPX_MAX_NUM_DEVS; ++u1NextDev)
{
if(psDpxDdb == psDpxGdd->pDdb[u1NextDev] )
{
if(psDpxDdb->eDevState == DPX_PRESENT)
{
/* delete entry and set error code to success */
/* and decrement DDB count */
/*----------------------------------------------*/
if(psDpxDdb->lockId != NULL)
sysDuplexSemDelete(psDpxDdb->lockId);
sysDuplexMemFree(psDpxDdb);
/* update GDD */
psDpxGdd->pDdb[u1NextDev] = DPX_NULL;
--(psDpxGdd->u1NumDevs);
ErrorCode = DPX_SUCCESS;
break;
}
else
{
ErrorCode = DPX_ERR_INVALID_STATE;
break;
}
}
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexRead
** ___________________________________________________________________________
**
** DESCRIPTION: This function can be used to read a register of a specific
** DUPLEX device by providing the register identifier. This
** function derives the actual address location based on the
** device handle and register identifier inputs. It then reads
** the contents of this address location using the system
** specific macro, sysDuplexRawRead.
**
** VALID STATES: DPX_ACTIVE or DPX_INIT or DPX_PRESENT
**
** SIDE EFFECTS: None
**
** INPUTS: duplex - device handle used by the driver to access DDB
** u2RegId : register identifier
**
** OUTPUTS: pu1Val : register value
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_EXCEED_REG_RANGE (exceed the DUPLEX register range)
**
*******************************************************************************/
INT4 duplexRead(DUPLEX duplex, UINT2 u2RegId, UINT1 *pu1Val)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
INT1 *pBaseAddr;
#if CSW_PV_FLAG /* allow PV to access CPLD Register without range check */
#else
/* check the register range */
if(u2RegId > DUPLEX_MAX_REG_ADDR)
{
return (DPX_ERR_EXCEED_REG_RANGE);
}
#endif
/* check to see if this is a valid device handle */
ErrorCode = duplexFindDev((sDPX_DDB*)duplex, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
pBaseAddr = (INT1 *)(psDpxGdd->pDdb[u1DdbIdx]->u4BaseAddr);
sysDuplexRawRead(pBaseAddr + u2RegId,*pu1Val);
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexWrite
** ___________________________________________________________________________
**
** DESCRIPTION: This function can be used to write to a register of a specific
** DUPLEX device by providing the register identifier. This
** function derives the actual address location based on the
** device handle and register identifier inputs. It then writes
** the contents of this address location using the system
** specific macro, sysVortexRawWrite.
**
** VALID STATES: DPX_ACTIVE or DPX_INIT or DPX_PRESENT
**
** SIDE EFFECTS: None
**
** INPUTS: duplex - device handle used by the driver to access DDB
** u2RegId : register identifier
** pu1Val : value to be written
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_EXCEED_REG_RANGE (exceed the DUPLEX register range)
**
*******************************************************************************/
INT4 duplexWrite(DUPLEX duplex, UINT2 u2RegId, UINT1 u1Val)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
INT1 *pBaseAddr;
#if CSW_PV_FLAG /* allow PV to access CPLD Register without range check */
#else
/* check the register range */
if(u2RegId > DUPLEX_MAX_REG_ADDR)
{
return (DPX_ERR_EXCEED_REG_RANGE);
}
#endif
/* check to see if this is a valid device handle */
ErrorCode = duplexFindDev((sDPX_DDB*)duplex, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
pBaseAddr = (INT1 *)psDpxGdd->pDdb[u1DdbIdx]->u4BaseAddr;
sysDuplexRawWrite(pBaseAddr + u2RegId, u1Val);
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexInit
** ___________________________________________________________________________
**
** DESCRIPTION: Initializes the device based on initialization vector passed
** by the user. This initialization vector is validated and
** stored by the driver in the device's DDB. The device
** registers are then configured accordingly. The device is put
** in INIT state.
**
** VALID STATES: DPX_PRESENT
**
** SIDE EFFECTS: The device enter DPX_INIT state.
**
** INPUTS: duplex - device handle used by the driver to access DDB
** sInitVector - initialization vector
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (device is not in a valid state)
** DPX_ERR_INVALID_INIT_VECTOR
** DPX_ERR_INDIRECT_CHANNEL_BUSY (timeout for indirect channel
** register access)
**
*******************************************************************************/
INT4 duplexInit(DUPLEX duplex, sDPX_INIT_VECTOR sInitVector)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
sDPX_DDB *psDpxDdb;
/* validating the device handler */
psDpxDdb = (sDPX_DDB *)duplex;
ErrorCode = duplexFindDev(psDpxDdb, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
if(psDpxDdb->eDevState == DPX_PRESENT)
{
/* validate vector and configure device */
ErrorCode = duplexValidateIV(psDpxDdb->eDevMode,&sInitVector);
if(ErrorCode != DPX_SUCCESS)
return (ErrorCode);
/* OK, copy it into device DDB */
psDpxDdb->sInitVector = sInitVector;
/* initialize callback fields */
psDpxDdb->indNotify = sInitVector.indNotify;
psDpxDdb->indRxBOC = sInitVector.indRxBOC;
psDpxDdb->indRxCell = sInitVector.indRxCell;
psDpxDdb->pCellTypeFn = sInitVector.pCellTypeFn;
/* configure the device registers */
ErrorCode = duplexHWCfgReg(psDpxDdb->u4BaseAddr, psDpxDdb->eDevMode,
&sInitVector);
if(ErrorCode != DPX_SUCCESS)
return (ErrorCode);
/* reset FIFOs */
duplexResetFifos(psDpxDdb->u4BaseAddr);
/* update the Device State */
psDpxDdb->eDevState = DPX_INIT;
}
else
{
ErrorCode = DPX_ERR_INVALID_STATE;
}
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexReset
** ___________________________________________________________________________
**
** DESCRIPTION: Resets the DUPLEX device and DDB contents (except for the
** initialization vector which is left unmodified).
**
** VALID STATES: All states
**
** SIDE EFFECTS: The device enter DPX_PRESENT state.
**
** INPUTS: duplex - device handle used by the driver to access DDB
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
**
*******************************************************************************/
INT4 duplexReset(DUPLEX duplex)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
sDPX_DDB *psDpxDdb;
psDpxDdb = (sDPX_DDB *)duplex;
/* validating the device handler */
ErrorCode = duplexFindDev(psDpxDdb, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
/* Deactivate the devuce first */
duplexDeactivate(duplex);
/* reset the DUPLEX chip and FIFOs */
duplexHWReset(psDpxDdb->u4BaseAddr);
duplexResetFifos(psDpxDdb->u4BaseAddr);
/* reset DDB contents except sInitVector, u4BaseAddr, eDevMode */
psDpxDdb->eDevState = DPX_PRESENT;
psDpxDdb->u1IntrProcEn = DPX_INACTIVE_LOW;
/* initialize snapshots of all DUPLEX interrupt flags to INACTIVE */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -