📄 txc_hw_platform.c
字号:
/*--------------------------------------------------------------------------
******* ****
* ***** ** * * * * * * ***** **** * *
* * * * * ** * * * * * * * * * *
* * * * * * * * **** * * * * * ******
* ***** ****** * * * * * ** * * * * * *
* * * * * * ** * * ** ** * * * * * *
* * * * * * * **** * * * * **** * *
Proprietary and Confidential
This program is made available only to customers and prospective customers
of TranSwitch Corporation under license and may be used only with TranSwitch
semi-conductor products.
Copyright(c) 2004 TranSwitch Inc.
---------------------------------------------------------------------
| TranSwitch Source Code |
|--------------------------------------------------------------------|
| |
| Workfile: txc_hw_platform.c |
| |
| Description: the basic access to hardware platform |
| |
----------------------------------------------------------------------
Revision History
----------------------------------------------------------------------
Rev # Date Author Description
----- ------ ------- -----------
1.0 01.Aug.2K J. Esposito Initial Version
1.1 10.Jun.02 R. Ruchandani Add 16 bit reg access
1.2 04.Oct.02 J. Federici Add debug capability.
1.3 03.Jan.03 J. Federici Add 32 bit register access.
--------------------------------------------------------------------*/
/******************************************************************
Include-Files
*******************************************************************/
#include <txc_platform.h>
#include <txc_error.h>
#include <txc_generic.h>
#include <txc_os_sem.h>
#include <txc_hw_platform.h>
/******************************************************************
Global Variables
*******************************************************************/
#ifdef TXC_HW_DEBUG
int debugTrace16Bit = 0;
int debugTrace32Bit = 0;
#endif
/*******************************************************************
Code Section
*******************************************************************/
/******************************************************************************
FUNCTION: TXC_BatchRegWrite
DESCRIPTION: Writes a batch of registers under semaphore control
INPUTS: a pointer to the structure TXC_BATCH_REG_ACCESS to register write
RETURNS: TXC_NO_ERR, TXC_OS_RESOURCE_ERR, TXC_WRITE_ERR
CAVEATS: This function is called by byte based Registered Devices only.
REVISION HISTORY:
Date Author Description
-------------------------------------------------------------------------
01.Aug.2k J. Esposito Initial Revision
*****************************************************************************/
int TXC_BatchRegWrite (TXC_BATCH_REG_ACCESS_STRUCT * batchWriteDataPtr)
{
int rtosError, writeFailCnt, writeError;
TXC_REG temp1, temp2;
TXC_REG_ACCESS_STRUCT * localRegDataPtr;
TXC_S16BIT i;
/* first, get the semaphore if required. Immediately return on failure */
if (batchWriteDataPtr->semId != 0)
{
rtosError = TXC_SemWait (batchWriteDataPtr->semId, TXC_OS_SEM_WAIT_FOREVER);
if (rtosError != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
/* initialize some locals */
writeFailCnt = 0;
localRegDataPtr = batchWriteDataPtr->regDataPtr;
/* loop thru all registers in the batch */
for (i = 0; i < batchWriteDataPtr->regCount; i ++)
{
/* skip if no address */
if (localRegDataPtr->addr != TXC_NULL)
{
/* first, remove unwanted bits from the calling data */
localRegDataPtr->data &= localRegDataPtr->mask;
/* read the register & modify (mask out bits to leave, OR-in new) */
temp1 = readReg (localRegDataPtr->addr);
temp1 &= ~(localRegDataPtr->mask);
temp1 |= localRegDataPtr->data;
/* write the new data, read back and compare */
writeReg (localRegDataPtr->addr, temp1);
if (batchWriteDataPtr->writeVerifyFlag != TXC_FALSE)
{ temp2 = readReg (localRegDataPtr->addr);
if ((temp1 & localRegDataPtr->mask) != (temp2 & localRegDataPtr->mask))
writeFailCnt ++;
}
} /* end of if addr != 0 */
/* next set of register data */
localRegDataPtr ++;
} /* end of for loop */
/* release the semaphore */
if (batchWriteDataPtr->semId != 0)
{
rtosError = TXC_SemPost (batchWriteDataPtr->semId);
if (rtosError != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
/* now test for write verify */
writeError = TXC_NO_ERR;
if ( (batchWriteDataPtr->writeVerifyFlag != TXC_FALSE) && (writeFailCnt != 0) )
writeError = TXC_DEVICE_WRITE_ERR;
/* return the error */
return writeError;
}
/******************************************************************************
FUNCTION: TXC_BatchRegRead
DESCRIPTION: this function reads a batch of registers and returns the masked value
INPUTS: a pointer to the structure TXC_BATCH_REG_ACCESS to register read
RETURNS: TXC_NO_ERR or TXC_OS_RESOURCE_ERR
CAVEATS: none
REVISION HISTORY:
Date Author Description
-------------------------------------------------------------------------
01.Aug.2k J. Esposito Initial Revision
*****************************************************************************/
int TXC_BatchRegRead (TXC_BATCH_REG_ACCESS_STRUCT * batchReadDataPtr)
{
int rtosError;
TXC_REG_ACCESS_STRUCT * localRegDataPtr;
TXC_S16BIT i;
/* first, get the semaphore if required. Immediately return on failure */
if (batchReadDataPtr->semId != 0)
{
rtosError = TXC_SemWait (batchReadDataPtr->semId, TXC_OS_SEM_WAIT_FOREVER);
if (rtosError != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
/* initialize some locals */
localRegDataPtr = batchReadDataPtr->regDataPtr;
/* loop thru all registers in the batch */
for (i = 0; i < batchReadDataPtr->regCount; i ++)
{
/* skip if no address */
if (localRegDataPtr->addr != TXC_NULL)
{
/* read the register */
localRegDataPtr->data = readReg (localRegDataPtr->addr);
localRegDataPtr->data &= localRegDataPtr->mask;
}
/* next set of register data */
localRegDataPtr ++;
} /* end of for loop */
/* release the semaphore */
if (batchReadDataPtr->semId != 0)
{
rtosError = TXC_SemPost (batchReadDataPtr->semId);
if (rtosError != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
/* if the semaphore did not fail, then alway return TXC_NO_ERR */
return TXC_NO_ERR;
}
/******************************************************************************
FUNCTION: TXC_BatchReg16BitWrite
DESCRIPTION: Writes a batch of 16 bit registers under semaphore control
INPUTS: a pointer to the structure TXC_BATCH_REG_16BIT_ACCESS to register write
RETURNS: TXC_NO_ERR, TXC_OS_RESOURCE_ERR, TXC_WRITE_ERR
CAVEATS: This function is called by byte based Registered Devices only.
REVISION HISTORY:
Date Author Description
-------------------------------------------------------------------------
10.Jun.02 R.Ruchandani Initial Version
*****************************************************************************/
int TXC_BatchReg16BitWrite (TXC_BATCH_REG_ACCESS_16BIT_STRUCT * batch16BitWriteDataPtr)
{
int rtosError, writeFailCnt, writeError;
TXC_REG_16 temp1, temp2;
TXC_REG_ACCESS_16BIT_STRUCT * localRegDataPtr;
TXC_S16BIT i;
/* first, get the semaphore if required. Immediately return on failure */
if (batch16BitWriteDataPtr->semId != 0)
{
rtosError = TXC_SemWait (batch16BitWriteDataPtr->semId, TXC_OS_SEM_WAIT_FOREVER);
if (rtosError != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
/* initialize some locals */
writeFailCnt = 0;
localRegDataPtr = batch16BitWriteDataPtr->regDataPtr;
#ifdef TXC_HW_DEBUG
if (debugTrace16Bit)
{
/* print the header */
printf (" ++ Writing to the Device - 16 Bit ++\n");
printf (" addr data mask\n");
}
#endif
/* loop thru all registers in the batch */
for (i = 0; i < batch16BitWriteDataPtr->regCount; i ++)
{
/* skip if no address */
if (localRegDataPtr->addr != TXC_NULL)
{
/* first, remove unwanted bits from the calling data */
localRegDataPtr->data &= localRegDataPtr->mask;
/* read the register & modify (mask out bits to leave, OR-in new) */
temp1 = read16BitReg (localRegDataPtr->addr);
temp1 &= ~(localRegDataPtr->mask);
temp1 |= localRegDataPtr->data;
#ifdef TXC_HW_DEBUG
if (debugTrace16Bit)
{
/* print the offset, data, & mask */
printf (" 0x%08x, 0x%04x, 0x%04x\n", localRegDataPtr->addr,
localRegDataPtr->data, localRegDataPtr->mask);
}
#endif
/* write the new data, read back and compare */
write16BitReg (localRegDataPtr->addr, temp1);
if (batch16BitWriteDataPtr->writeVerifyFlag != TXC_FALSE)
{
temp2 = read16BitReg (localRegDataPtr->addr);
if ((temp1 & localRegDataPtr->mask) != (temp2 & localRegDataPtr->mask))
writeFailCnt ++;
}
} /* end of if no address */
/* next set of register data */
localRegDataPtr ++;
} /* end of for loop */
#ifdef TXC_HW_DEBUG
if (debugTrace16Bit)
{
/* print the trailer */
printf (" ++ End of writing to the Device ++\n\n");
}
#endif
/* release the semaphore */
if (batch16BitWriteDataPtr->semId != 0)
{
rtosError = TXC_SemPost (batch16BitWriteDataPtr->semId);
if (rtosError != TXC_NO_ERR)
return TXC_OS_RESOURCE_ERR;
}
/* now test for write verify */
writeError = TXC_NO_ERR;
if ( (batch16BitWriteDataPtr->writeVerifyFlag != TXC_FALSE) && (writeFailCnt != 0) )
writeError = TXC_DEVICE_WRITE_ERR;
/* return the error */
return writeError;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -