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

📄 txc_hw_platform.c

📁 TranSwitch Envoy CE2 & Envoy CE4 设备驱动及编程指南
💻 C
📖 第 1 页 / 共 2 页
字号:

/******************************************************************************
 
  FUNCTION: TXC_BatchReg16BitRead

  DESCRIPTION: this function reads a batch of 16 Bit registers and returns the masked value

  INPUTS:  a pointer to the structure TXC_BATCH_REG_16BIT_ACCESS to register read

  RETURNS: TXC_NO_ERR or TXC_OS_RESOURCE_ERR

  CAVEATS: none

  REVISION HISTORY:
  
  Date       Author             Description
 -------------------------------------------------------------------------
 10.Jun.02   R.Ruchandani       Initial Revision

*****************************************************************************/

int TXC_BatchReg16BitRead (TXC_BATCH_REG_ACCESS_16BIT_STRUCT * batch16BitReadDataPtr)
{
    int rtosError;
    TXC_REG_ACCESS_16BIT_STRUCT * localRegDataPtr;
    TXC_S16BIT i;

    /* first, get the semaphore if required. Immediately return on failure */
    if (batch16BitReadDataPtr->semId != 0)
    {
        rtosError = TXC_SemWait (batch16BitReadDataPtr->semId, TXC_OS_SEM_WAIT_FOREVER);
        if (rtosError != TXC_NO_ERR)
            return TXC_OS_RESOURCE_ERR;
    }

    /* initialize some locals */
    localRegDataPtr = batch16BitReadDataPtr->regDataPtr;

#ifdef TXC_HW_DEBUG
    if (debugTrace16Bit)
    {
        /* print the header */
        printf (" ++ Reading to the Device - 16 Bit ++\n");
        printf ("    addr    data    mask\n");
    }
#endif

    /* loop thru all registers in the batch */  
    for (i = 0; i < batch16BitReadDataPtr->regCount; i ++)
    {
        /* skip if no address */
        if (localRegDataPtr->addr != TXC_NULL)
        {           

            /* read the register */
            localRegDataPtr->data = read16BitReg (localRegDataPtr->addr);
            localRegDataPtr->data &= localRegDataPtr->mask;

#ifdef TXC_HW_DEBUG
            if (debugTrace16Bit)
            {
                /* print the addr, data, & mask */
                printf ("   0x%08x, 0x%04x, 0x%04x\n", localRegDataPtr->addr,
                    localRegDataPtr->data, localRegDataPtr->mask);
            }
#endif
        }
                
        /* next set of register data */
        localRegDataPtr ++;

    } /* end of for loop */

#ifdef TXC_HW_DEBUG
    if (debugTrace16Bit)
    {
        /* print the trailer */
        printf (" ++ End of reading to the Device ++\n\n");
    }
#endif

    /* release the semaphore */
    if (batch16BitReadDataPtr->semId != 0)
    {
        rtosError = TXC_SemPost (batch16BitReadDataPtr->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_BatchReg32BitWrite

  DESCRIPTION: Writes a batch of 32 bit registers under semaphore control 

  INPUTS:   a pointer to the structure TXC_BATCH_REG_32BIT_ACCESS to register write           

  RETURNS: TXC_NO_ERR, TXC_OS_RESOURCE_ERR, TXC_WRITE_ERR

  CAVEATS: None.

  REVISION HISTORY:
  
  Date       Author             Description
 -------------------------------------------------------------------------
 10/17/02   J. Federici            Initial Version
 

*****************************************************************************/

int TXC_BatchReg32BitWrite (TXC_BATCH_REG_ACCESS_32BIT_STRUCT * batch32BitWriteDataPtr)
{
    int rtosError, writeFailCnt, writeError;
    TXC_REG_32 temp1, temp2;
    TXC_REG_ACCESS_32BIT_STRUCT * localRegDataPtr;
    TXC_S16BIT i;

    /* first, get the semaphore if required. Immediately return on failure */
    if (batch32BitWriteDataPtr->semId != 0)
    {
        rtosError = TXC_SemWait (batch32BitWriteDataPtr->semId, TXC_OS_SEM_WAIT_FOREVER);
        if (rtosError != TXC_NO_ERR)
            return TXC_OS_RESOURCE_ERR;
    }

    /* initialize some locals */
    writeFailCnt = 0;
    localRegDataPtr = batch32BitWriteDataPtr->regDataPtr;

#ifdef TXC_HW_DEBUG
    if (debugTrace32Bit)
    {
        /* print the header */
        printf (" ++ Writing to the Device - 32 Bit ++\n");
        printf ("    addr         data        mask\n");
    }
#endif

    /* loop thru all registers in the batch */  
    for (i = 0; i < batch32BitWriteDataPtr->regCount; i ++, localRegDataPtr ++)
    {
        /* skip if no address */
        if ((localRegDataPtr->addr == 0) || (localRegDataPtr->mask == 0))
            continue;
            
        /* 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 = read32BitReg (localRegDataPtr->addr);
        temp1 &= ~(localRegDataPtr->mask);
        temp1 |= localRegDataPtr->data;

#ifdef TXC_HW_DEBUG
            if (debugTrace32Bit)
            {
                /* print the offset, data, & mask */
                printf ("   0x%08x, 0x%08x, 0x%08x\n", localRegDataPtr->addr,
                    localRegDataPtr->data, localRegDataPtr->mask);
            }
#endif

        /* write the new data, read back and compare */
        write32BitReg (localRegDataPtr->addr, temp1);


    if (batch32BitWriteDataPtr->writeVerifyFlag != TXC_FALSE)
    {  /* Write and Read Verify */
       temp2 = read32BitReg (localRegDataPtr->addr);
       if ((temp1 & localRegDataPtr->mask) != (temp2 & localRegDataPtr->mask))
       {
            writeFailCnt ++;
            /* printf("Write Error ADDR=0x%08lx, 0x%08lx, 0x%08lx\n", localRegDataPtr->addr,temp1,temp2); */  

           }    
    }

    } /* end of for loop */

#ifdef TXC_HW_DEBUG
    if (debugTrace32Bit)
    {
        /* print the trailer */
        printf (" ++ End of writing to the Device ++\n\n");
    }
#endif

    /* release the semaphore */
    if (batch32BitWriteDataPtr->semId != 0)
    {
        rtosError = TXC_SemPost (batch32BitWriteDataPtr->semId);
        if (rtosError != TXC_NO_ERR)
            return TXC_OS_RESOURCE_ERR;
    }

    /* now test for write verify */
    writeError = TXC_NO_ERR;
    if ( (batch32BitWriteDataPtr->writeVerifyFlag != TXC_FALSE) && (writeFailCnt != 0) )
        writeError = TXC_DEVICE_WRITE_ERR;
    
    /* return the error */
    return writeError;

}

/******************************************************************************
 
  FUNCTION: TXC_BatchReg32BitRead

  DESCRIPTION: this function reads a batch of 32 Bit registers and returns 
               the masked value

  INPUTS:  a pointer to the structure TXC_BATCH_REG_32BIT_ACCESS to register read

  RETURNS: TXC_NO_ERR or TXC_OS_RESOURCE_ERR

  CAVEATS: None.

  REVISION HISTORY:
  
  Date       Author             Description
 -------------------------------------------------------------------------
 10/17/022   J. Federici            Initial Version

*****************************************************************************/

int TXC_BatchReg32BitRead (TXC_BATCH_REG_ACCESS_32BIT_STRUCT * batch32BitReadDataPtr)
{
    int rtosError;
    TXC_REG_ACCESS_32BIT_STRUCT * localRegDataPtr;
    TXC_S16BIT i;

    /* first, get the semaphore if required. Immediately return on failure */
    if (batch32BitReadDataPtr->semId != 0)
    {
        rtosError = TXC_SemWait (batch32BitReadDataPtr->semId, TXC_OS_SEM_WAIT_FOREVER);
        if (rtosError != TXC_NO_ERR)
            return TXC_OS_RESOURCE_ERR;
    }

    /* initialize some locals */
    localRegDataPtr = batch32BitReadDataPtr->regDataPtr;

#ifdef TXC_HW_DEBUG
    if (debugTrace32Bit)
    {
        /* print the header */
        printf (" ++ Reading to the Device - 32 Bit ++\n");
        printf ("    addr        data        mask\n");
    }
#endif

    /* loop thru all registers in the batch */  
    for (i = 0; i < batch32BitReadDataPtr->regCount; i ++, localRegDataPtr ++)
    {
        /* skip if no address */
        if (localRegDataPtr->addr == 0)
            continue;
            
        /* read the register */
        localRegDataPtr->data = read32BitReg (localRegDataPtr->addr);
        localRegDataPtr->data &= localRegDataPtr->mask;

#ifdef TXC_HW_DEBUG
        if (debugTrace32Bit)
        {
            /* print the addr, data, & mask */
            printf ("   0x%08x, 0x%08x, 0x%08x\n", localRegDataPtr->addr,
                localRegDataPtr->data, localRegDataPtr->mask);
        }
#endif  

    } /* end of for loop */

    /* release the semaphore */
    if (batch32BitReadDataPtr->semId != 0)
    {
        rtosError = TXC_SemPost (batch32BitReadDataPtr->semId);
        if (rtosError != TXC_NO_ERR)
            return TXC_OS_RESOURCE_ERR;
    }

#ifdef TXC_HW_DEBUG
    if (debugTrace32Bit)
    {
        /* print the trailer */
        printf (" ++ End of reading to the Device ++\n\n");
    }
#endif

    /* if the semaphore did not fail, then alway return TXC_NO_ERR */
    return TXC_NO_ERR;
}

/* the following functions allow the user to change the basic method of 
   register access without affecting the rest of the code.   */
    

void writeReg (TXC_REG * addr, TXC_REG data)
{
    *((volatile TXC_REG *)addr) = data;
}

TXC_REG readReg (TXC_REG * addr)
{
    return (*((volatile TXC_REG *)addr));
}

void write16BitReg (TXC_REG_16 * addr, TXC_REG_16 data)
{
    *((volatile TXC_REG_16 *)addr) = data;
}

TXC_REG_16 read16BitReg (TXC_REG_16 * addr)
{
    return (*((volatile TXC_REG_16 *)addr));
}

void write32BitReg (TXC_REG_32 * addr, TXC_REG_32 data)
{
    *((volatile TXC_REG_32 *)addr) = data;   
}

TXC_REG_32 read32BitReg (TXC_REG_32 * addr)
{
    return (*((volatile TXC_REG_32 *)addr));
}


/*******************************************************************
                     End of Module
*******************************************************************/

⌨️ 快捷键说明

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