📄 dpx_api.c
字号:
sysDuplexMemset((VOID *)&(psDpxDdb->sIntEnbls),
DPX_INACTIVE_LOW, sizeof(sDPX_INT_ENBLS));
/* initialize all Duplex callback functions to DPX_NULL */
psDpxDdb->indNotify = DPX_NULL;
psDpxDdb->indRxBOC = DPX_NULL;
psDpxDdb->indRxBOC = DPX_NULL;
psDpxDdb->pCellTypeFn = DPX_NULL;
psDpxDdb->u4Reserved = 0x00;
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexInstallIndFn
** ___________________________________________________________________________
**
** DESCRIPTION: install the user-defined indication callback routines that
** are invoked by duplexDPR. The function pointer is stored in
** the device context structure DDB.
**
** VALID STATES: DPX_INIT
**
** SIDE EFFECTS: None.
**
** INPUTS: duplex - device handle used by the driver to access DDB
** eCbType - identifies the callback being installed.
** pCbFn - callback function being installed.
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_CB_TYPE (invalid callback type)
**
*******************************************************************************/
INT4 duplexInstallIndFn(DUPLEX duplex, eDPX_CB_TYPE eCbType,
DPX_IND_CB_FN pCbFn)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
sDPX_DDB *psDpxDdb;
psDpxDdb = (sDPX_DDB *)duplex;
/* validating the device handler */
ErrorCode = duplexFindDev(psDpxDdb, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
if(psDpxDdb->eDevState == DPX_INIT)
{
switch (eCbType)
{
case DPX_CB_NOTIFY:
psDpxDdb->indNotify = pCbFn;
break;
case DPX_CB_RX_BOC:
psDpxDdb->indRxBOC = pCbFn;
break;
case DPX_CB_RX_CELL:
psDpxDdb->indRxCell = pCbFn;
break;
default:
ErrorCode = DPX_ERR_INVALID_CB_TYPE;
break;
}
}
else
{
ErrorCode = DPX_ERR_INVALID_STATE;
}
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexRemoveIndFn
** ___________________________________________________________________________
**
** DESCRIPTION: Remove the user-defined indication callback routines that
** are invoked by duplexDPR.
**
** VALID STATES: DPX_INIT
**
** SIDE EFFECTS: The driver will no longer be able to process events reported
** by the device.
**
** INPUTS: duplex - device handle used by the driver to access DDB
** eCbType - identifies the callback being installed.
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_CB_TYPE (invalid callback type)
**
*******************************************************************************/
INT4 duplexRemoveIndFn(DUPLEX duplex, eDPX_CB_TYPE eCbType)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
sDPX_DDB *psDpxDdb;
psDpxDdb = (sDPX_DDB *)duplex;
/* validating the device handler */
ErrorCode = duplexFindDev(psDpxDdb, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
if(psDpxDdb->eDevState == DPX_INIT)
{
switch (eCbType)
{
case DPX_CB_NOTIFY:
psDpxDdb->indNotify = DPX_NULL;
break;
case DPX_CB_RX_BOC:
psDpxDdb->indRxBOC = DPX_NULL;
break;
case DPX_CB_RX_CELL:
psDpxDdb->indRxCell = DPX_NULL;
break;
default:
ErrorCode = DPX_ERR_INVALID_CB_TYPE;
break;
}
}
else
{
ErrorCode = DPX_ERR_INVALID_STATE;
}
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexActivate
** ___________________________________________________________________________
**
** DESCRIPTION: Activates the DUPLEX device by preparing it for normal
** operation. This involves enabling device interrupts and other
** global enables, e.g. HSS transmitter and receiver.
** Note that interrupt service routine should be installed before
** call this routine.
**
** VALID STATES: DPX_INIT
**
** SIDE EFFECTS: Puts the device in DPX_ACTIVE state
**
** INPUTS: duplex: pointer to DDB, or device handler
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (invalid state)
**
*******************************************************************************/
INT4 duplexActivate(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)
{
#if CSW_PV_FLAG /* allowing PV to activate a device without initVector */
if(psDpxDdb->eDevState != DPX_ACTIVE)
#else
if(psDpxDdb->eDevState == DPX_INIT)
#endif
{
/* enable HSS transmitter */
duplexClearRegBits(psDpxDdb->u4BaseAddr, DPX_REG_SER_LNK_MNT,
(DPX_MASK_SER_LNK_MNT_TXDIS1 | DPX_MASK_SER_LNK_MNT_TXDIS2));
/* Install Interrupt handler */
ErrorCode = sysDuplexIntInstallHandler(duplex);
if(ErrorCode != DPX_SUCCESS)
return ErrorCode;
#if DPX_CSW_INTERRUPT_MODE
/* enable the master interrupt */
duplexHWtoggleMastIntEn(psDpxDdb->u4BaseAddr,DPX_ACTIVE_HIGH);
#endif
/* update the state */
psDpxDdb->eDevState = DPX_ACTIVE;
psDpxDdb->sIntEnbls.u1MasterEn = DPX_ACTIVE_HIGH;
}
else
{
ErrorCode = DPX_ERR_INVALID_STATE;
}
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexDeactivate
** ___________________________________________________________________________
**
** DESCRIPTION: De-ctivates the DUPLEX device and remove it from normal
** operation. This involes disabling device interrupts and
** other global disables.
**
** VALID STATES: DPX_ACTIVE
**
** SIDE EFFECTS: Puts the device in DPX_INIT state
**
** INPUTS: duplex: pointer to DDB, or device handler
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (invalid state)
**
*******************************************************************************/
INT4 duplexDeactivate(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)
{
if(psDpxDdb->eDevState == DPX_ACTIVE)
{
/* disable the master interrupt */
duplexHWtoggleMastIntEn(psDpxDdb->u4BaseAddr, DPX_INACTIVE_LOW );
/* Remove Interrupt handler */
sysDuplexIntRemoveHandler(duplex);
/* disable HSS transmitter (register 0x05) */
duplexSetRegBits(psDpxDdb->u4BaseAddr, DPX_REG_SER_LNK_MNT,
(DPX_MASK_SER_LNK_MNT_TXDIS1 | DPX_MASK_SER_LNK_MNT_TXDIS2));
/* update the state */
psDpxDdb->eDevState = DPX_INIT;
psDpxDdb->sIntEnbls.u1MasterEn = DPX_INACTIVE_LOW;
}
else
{
ErrorCode = DPX_ERR_INVALID_STATE;
}
}
return(ErrorCode);
}
/*******************************************************************************
**
** duplexRegisterTest
** ___________________________________________________________________________
**
** DESCRIPTION: Verifies the correectness of the microprocessor's access to
** the device register by writing to and reading back values.
**
** VALID STATES: DPX_PRESENT
**
** SIDE EFFECTS: Puts the device in DPX_PRESENT state after the test. So the
** device should be reset and initialized after calling the
** function.
**
** INPUTS: duplex: pointer to DDB, or device handler
**
** OUTPUTS: None
**
** RETURN CODES:
** DPX_SUCCESS
** DPX_ERR_INVALID_DEVICE (invalid device handle)
** DPX_ERR_INVALID_STATE (invalid state)
** DPX_ERR_FAILURE (test failed)
**
*******************************************************************************/
INT4 duplexRegisterTest(DUPLEX duplex)
{
UINT1 u1DdbIdx;
INT4 ErrorCode;
sDPX_DDB *psDpxDdb;
UINT1 u1TestValue = DPX_REGISTER_TEST_VALUE;
UINT1 *pBaseAddr;
eDPX_MODE eDpxMode;
psDpxDdb = (sDPX_DDB *)duplex;
/* validating the device handler */
ErrorCode = duplexFindDev(psDpxDdb, (UINT1*)&u1DdbIdx);
if(ErrorCode == DPX_SUCCESS)
{
if(psDpxDdb->eDevState != DPX_PRESENT)
{
return(DPX_ERR_INVALID_STATE);
}
eDpxMode = psDpxDdb->eDevMode;
pBaseAddr = (UINT1 *)(psDpxDdb->u4BaseAddr) ;
/* write to all writable registers with Master Interrupt MINTE cleared */
sysDuplexRawWrite(pBaseAddr + DPX_REG_MASTER_CFG, u1TestValue);
sysDuplexRawWrite(pBaseAddr + DPX_REG_SER_LNK_MNT, u1TestValue);
if(eDpxMode != DPX_CLK_BIT_SER)
{
/* PHY interface */
sysDuplexRawWrite(pBaseAddr + DPX_REG_EXT_ADDR_MATCH_LSB,u1TestValue);
sysDuplexRawWrite(pBaseAddr + DPX_REG_EXT_ADDR_MATCH_MSB, u1TestValue
& 0x07);
sysDuplexRawWrite(pBaseAddr + DPX_REG_EXT_ADDR_MASK_LSB, u1TestValue);
sysDuplexRawWrite(pBaseAddr + DPX_REG_EXT_ADDR_MASK_MSB, u1TestValue
& 0x07);
sysDuplexRawWrite(pBaseAddr + DPX_REG_OUTPUT_ADDR_MATCH, u1TestValue
& 0x3F);
sysDuplexRawWrite(pBaseAddr + DPX_REG_PHY_INPUT_CFG2, u1TestValue
& 0x7F);
sysDuplexRawWrite(pBaseAddr + DPX_REG_INPUT_CELL_AV_EN_LSB,
u1TestValue);
sysDuplexRawWrite(pBaseAddr + DPX_REG_INPUT_CELL_AV_EN_2ND,
u1TestValue);
sysDuplexRawWrite(pBaseAddr + DPX_REG_INPUT_CELL_AV_EN_3RD,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -