text:
/** \file
* RD700 specific HAL-Component of Reader Library Framework.
* $Author: santosh.araballi $
* $Revision: 1.113 $
* $Date: Wed Oct 31 14:40:18 2012 $
*
* History:
*  CHu: Generated 19. May 2009
*
*/
#include <ph_Status.h>
#include <phbalReg.h>
#include <phhalHw.h>
#include <ph_RefDefs.h>

#ifdef NXPBUILD__PH_KEYSTORE
#include <phKeyStore.h>
#endif

#ifdef NXPBUILD__PHHAL_HW_RD70X

#include "phhalHw_Rd70x.h"
#include "phhalHw_Rd70x_Int.h"
#include <phhalHw_Rd70x_Cmd.h>

/* Default shadow for ISO14443-3A Mode */
static const uint16_t PH_MEMLOC_CONST_ROM wRd70x_DefaultShadow_14443a[][2] =
{
    {PHHAL_HW_CONFIG_PARITY,                PH_ON},
    {PHHAL_HW_CONFIG_TXCRC,                 PH_OFF},
    {PHHAL_HW_CONFIG_RXCRC,                 PH_OFF},
    {PHHAL_HW_CONFIG_RXDEAFBITS,            0x0008},
    {PHHAL_HW_CONFIG_TXDATARATE,            PHHAL_HW_RF_DATARATE_106},
    {PHHAL_HW_CONFIG_RXDATARATE,            PHHAL_HW_RF_DATARATE_106},
    {PHHAL_HW_CONFIG_ASK100,                PH_ON}
};

/* Default shadow for ISO14443-3B Mode */
static const uint16_t PH_MEMLOC_CONST_ROM wRd70x_DefaultShadow_14443b[][2] =
{
    {PHHAL_HW_CONFIG_PARITY,                PH_OFF},
    {PHHAL_HW_CONFIG_TXCRC,                 PH_ON},
    {PHHAL_HW_CONFIG_RXCRC,                 PH_ON},
    {PHHAL_HW_CONFIG_RXDEAFBITS,            0x0003},
    {PHHAL_HW_CONFIG_TXDATARATE,            PHHAL_HW_RF_DATARATE_106},
    {PHHAL_HW_CONFIG_RXDATARATE,            PHHAL_HW_RF_DATARATE_106},
    {PHHAL_HW_CONFIG_MODINDEX,              PHHAL_HW_RD70X_MODINDEX_I14443B},
    {PHHAL_HW_CONFIG_ASK100,                PH_OFF}
};

/* Default shadow for ISO15693 Mode */
static const uint16_t PH_MEMLOC_CONST_ROM wRd70x_DefaultShadow_15693[][2] =
{
    {PHHAL_HW_CONFIG_TXCRC,                 PH_ON},
    {PHHAL_HW_CONFIG_RXCRC,                 PH_ON},
    {PHHAL_HW_CONFIG_RXDEAFBITS,            0x0003},
    {PHHAL_HW_CONFIG_TXDATARATE,            PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_4},
    {PHHAL_HW_CONFIG_RXDATARATE,            PHHAL_HW_RF_RX_DATARATE_HIGH},
    {PHHAL_HW_CONFIG_ASK100,                PH_ON}
};

/* Default shadow for ICode EPC/UID Mode */
static const uint16_t PH_MEMLOC_CONST_ROM wRd70x_DefaultShadow_ICodeEpcUid[][2] =
{
    {PHHAL_HW_CONFIG_TXCRC,                 PH_OFF},
    {PHHAL_HW_CONFIG_RXCRC,                 PH_OFF},
    {PHHAL_HW_CONFIG_RXDEAFBITS,            0x0006},
    {PHHAL_HW_CONFIG_MODINDEX,              PHHAL_HW_RD70X_MODINDEX_EPCUID},
    {PHHAL_HW_CONFIG_ASK100,                PH_OFF}
};

phStatus_t phhalHw_Rd70x_Init(
                              phhalHw_Rd70x_DataParams_t * pDataParams,
                              uint16_t wSizeOfDataParams,
                              phbalReg_Rd70xUsbWin_DataParams_t * pBalDataParams,
                              uint8_t * pTxBuffer,
                              uint16_t wTxBufSize,
                              uint8_t * pRxBuffer,
                              uint16_t wRxBufSize
                              )
{
    if (sizeof(phhalHw_Rd70x_DataParams_t) != wSizeOfDataParams)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_HAL);
    }
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pBalDataParams);
    PH_ASSERT_NULL (pTxBuffer);
    PH_ASSERT_NULL (pRxBuffer);

    /* Init. private data */
    pDataParams->wId                    = PH_COMP_HAL | PHHAL_HW_RD70X_ID;
    pDataParams->pBalDataParams         = pBalDataParams;
    pDataParams->pTxBuffer              = pTxBuffer;
    pDataParams->wTxBufSize             = wTxBufSize;
    pDataParams->wTxBufLen              = 0;
    pDataParams->pRxBuffer              = pRxBuffer;
    pDataParams->wRxBufSize             = wRxBufSize;
    pDataParams->wRxBufLen              = 0;
    pDataParams->wRxBufStartPos         = 0;
    pDataParams->wTxBufStartPos         = 0;
    pDataParams->bCardType              = PHHAL_HW_CARDTYPE_ISO14443A;
    pDataParams->wTimingMode            = PHHAL_HW_TIMING_MODE_OFF;
    pDataParams->dwTimeoutUs            = PHHAL_HW_RD70X_DEFAULT_TIMEOUT_MS * 1000;
    pDataParams->dwTimingUs             = 0;
    pDataParams->wAdditionalInfo        = 0;
    pDataParams->wTxRxStartBackup       = 0;
    pDataParams->wFieldOffTime          = PHHAL_HW_FIELD_OFF_DEFAULT;
    pDataParams->wFieldRecoveryTime     = PHHAL_HW_FIELD_RECOVERY_DEFAULT;
    pDataParams->bSymbolStart           = PH_OFF;
    pDataParams->bSymbolEnd             = PH_OFF;
    pDataParams->bDisablePcdReset       = PH_OFF;
    pDataParams->bFlags                 = 0;
    pDataParams->bProtBufferLen         = 0;
    pDataParams->wProtRxBufReadPos      = 0;
    pDataParams->bRfResetAfterTo        = PH_OFF;

    /* Verify exchange buffers */
    if (wTxBufSize == 0 || wRxBufSize == 0)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_Exchange(
                                  phhalHw_Rd70x_DataParams_t * pDataParams,
                                  uint16_t wOption,
                                  uint8_t * pTxBuffer,
                                  uint16_t wTxLength,
                                  uint8_t ** ppRxBuffer,
                                  uint16_t * pRxLength
                                  )
{
    phStatus_t  PH_MEMLOC_REM status;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint16_t    PH_MEMLOC_REM wPosition;
    uint8_t     PH_MEMLOC_REM bOption;
    uint8_t     PH_MEMLOC_REM bReg;
    uint32_t    PH_MEMLOC_REM dwTimeoutEtu;
    uint32_t    PH_MEMLOC_REM dwTimingSingle;
    uint8_t     PH_MEMLOC_REM bRxLastBits = 0;
    uint16_t    PH_MEMLOC_REM RxLength;
    uint8_t *    PH_MEMLOC_REM pRxBuffer;

    /* Check options */
    if ((wOption & (uint16_t)~(uint16_t)(PH_EXCHANGE_BUFFERED_BIT | PH_EXCHANGE_LEAVE_BUFFER_BIT)) != 0x0000)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    /* Check if caller has provided valid RxBuffer */
    if (ppRxBuffer == NULL)
    {
        ppRxBuffer = &pRxBuffer;
    }
    if (pRxLength == NULL)
    {
        pRxLength = &RxLength;
    }

    /* clear internal buffer if requested */
    if (!(wOption & PH_EXCHANGE_LEAVE_BUFFER_BIT))
    {
        pDataParams->wTxBufLen = 0;
    }

    /* Calculate start position */
    wPosition = PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + pDataParams->wTxBufStartPos + pDataParams->wTxBufLen;

    /* Buffer overflow check */
    if ((wPosition + wTxLength) > pDataParams->wTxBufSize)
    {
        pDataParams->wTxBufLen = 0;
        return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_HAL);
    }

    /* Copy transmit buffer*/
    memcpy(&pDataParams->pTxBuffer[wPosition], pTxBuffer, wTxLength);  /* PRQA S 3200 */
    pDataParams->wTxBufLen = pDataParams->wTxBufLen + wTxLength;

    /* Shall we already perform the Exchange? */
    if (wOption & PH_EXCHANGE_BUFFERED_BIT)
    {
        return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
    }

    /* Prepare timing measurement */
    if ((pDataParams->wTimingMode & (uint16_t)~(uint16_t)PHHAL_HW_TIMING_MODE_OPTION_MASK) == PHHAL_HW_TIMING_MODE_COMM)
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_HostTransTmrSetCMDCount(pDataParams, 1));
    }

    /* Perform the actual exchange */
    switch (pDataParams->bCardType)
    {
    case PHHAL_HW_CARDTYPE_ISO15693:

        /* Read Coder-Control register*/
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(
            pDataParams,
            PHHAL_HW_RD70X_REG_CODER_CONTROL,
            &bReg));

        /* Enable SendOnePulse if requested */
        if (pDataParams->bSymbolStart == PH_OFF)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
                pDataParams,
                PHHAL_HW_RD70X_REG_CODER_CONTROL,
                bReg | PHHAL_HW_RD70X_BIT_SENDONEPULSE));
        }

        /* Perform actual exchange */
        status = phhalHw_Rd70x_Cmd_ISO15693_Exchange(
            pDataParams,
            NULL,
            pDataParams->wTxBufLen,
            ppRxBuffer,
            pRxLength);

        /* Disable SendOnePulse if enabled before */
        if (pDataParams->bSymbolStart == PH_OFF)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
                pDataParams,
                PHHAL_HW_RD70X_REG_CODER_CONTROL,
                (bReg & (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_SENDONEPULSE)));
        }

        break;

    case PHHAL_HW_CARDTYPE_ICODEEPCUID:

        /* Evaluate start symbol */
        switch (pDataParams->bSymbolStart)
        {
        case PHHAL_HW_SYMBOL_ICODEEPCUID_SSOF:
            bOption = PHHAL_HW_RD70X_EPCUID_OPTION_SSOF;
            break;
        case PHHAL_HW_SYMBOL_ICODEEPCUID_LSOF:
            bOption = PHHAL_HW_RD70X_EPCUID_OPTION_LSOF;
            break;
        case PHHAL_HW_SYMBOL_ICODEEPCUID_CS:
            bOption = PHHAL_HW_RD70X_EPCUID_OPTION_CS;
            break;
        default:
            return PH_ADD_COMPCODE(PH_ERR_INTERNAL_ERROR, PH_COMP_HAL);
        }

        status = phhalHw_Rd70x_Cmd_EPCUID_Exchange(
            pDataParams,
            bOption,
            NULL,
            pDataParams->wTxBufLen,
            (uint8_t)pDataParams->wCfgShadow[PHHAL_HW_CONFIG_TXLASTBITS],
            ppRxBuffer,
            pRxLength);

        break;

    case PHHAL_HW_CARDTYPE_ISO14443A:
    case PHHAL_HW_CARDTYPE_ISO14443B:
        /* Calculate timeout in ETUs */
        dwTimeoutEtu = (uint32_t)((float32_t)pDataParams->dwTimeoutUs / (PHHAL_HW_RD70X_ETU_106 / (float32_t)(pDataParams->wCfgShadow[PHHAL_HW_CONFIG_RXDATARATE] + 1)));
        if (dwTimeoutEtu == 0)
        {
            ++dwTimeoutEtu;
        }

        /* Perform actual exchange*/
        if (pDataParams->bRfResetAfterTo == PH_ON)
        {
            status = phhalHw_Rd70x_Cmd_PiccExchgBitByteRfCycle(
                pDataParams,
                NULL,
                pDataParams->wTxBufLen,
                (uint8_t)pDataParams->wCfgShadow[PHHAL_HW_CONFIG_TXLASTBITS],
                ppRxBuffer,
                pRxLength,
                &bRxLastBits,
                pDataParams->bFlags,
                dwTimeoutEtu);
        }
        else
        {
            status = phhalHw_Rd70x_Cmd_PiccExchgBitByte(
                pDataParams,
                NULL,
                pDataParams->wTxBufLen,
                (uint8_t)pDataParams->wCfgShadow[PHHAL_HW_CONFIG_TXLASTBITS],
                ppRxBuffer,
                pRxLength,
                &bRxLastBits,
                pDataParams->bFlags,
                dwTimeoutEtu);
        }

        /* Save RxLastBits */
        pDataParams->wAdditionalInfo = (uint16_t)bRxLastBits;
        break;

    default:
        return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
    }

    /* Retrieve timing */
    if ((pDataParams->wTimingMode & (uint16_t)~(uint16_t)PHHAL_HW_TIMING_MODE_OPTION_MASK) == PHHAL_HW_TIMING_MODE_COMM)
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_HostGetExecutionTime(pDataParams, &dwTimingSingle));

        if (pDataParams->wTimingMode & PHHAL_HW_TIMING_MODE_OPTION_AUTOCLEAR)
        {
            pDataParams->dwTimingUs = dwTimingSingle;
        }
        else
        {
            /* Check for overflow */
            if ((0xFFFFFFFF - pDataParams->dwTimingUs) < dwTimingSingle)
            {
                pDataParams->dwTimingUs = 0xFFFFFFFF;
            }
            /* Update global timing value */
            else
            {
                pDataParams->dwTimingUs = pDataParams->dwTimingUs + dwTimingSingle;
            }
        }
    }

    /* Return correct data length */
    *ppRxBuffer -= pDataParams->wRxBufStartPos;
    *pRxLength = *pRxLength + pDataParams->wRxBufStartPos;

    /* Store RxBufLen in DataParams */
    pDataParams->wRxBufLen = *pRxLength;

    /* Reset TxLastBits */
    pDataParams->wCfgShadow[PHHAL_HW_CONFIG_TXLASTBITS] = 0;

    /* Reset buffered bytes */
    pDataParams->wTxBufLen = 0;

    /* Incomplete byte check */
    if (((status & PH_ERR_MASK) == PH_ERR_SUCCESS) && (bRxLastBits != 0))
    {
        status = PH_ADD_COMPCODE(PH_ERR_SUCCESS_INCOMPLETE_BYTE, PH_COMP_HAL);
    }

    /* Buffer Overflow mapping */
    if ((status & PH_ERR_MASK) == PH_ERR_BUFFER_OVERFLOW)
    {
        status = PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_HAL);
    }

    /* Firmware only has 1ms recovery-time, wait the remaining time */
    if ((status & PH_ERR_MASK) == PH_ERR_IO_TIMEOUT)
    {
        if ((pDataParams->bRfResetAfterTo != PH_OFF) && (pDataParams->wFieldRecoveryTime > 1))
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Wait(
                pDataParams,
                PHHAL_HW_TIME_MILLISECONDS,
                pDataParams->wFieldRecoveryTime - 1));
        }
    }

    return status;
}

phStatus_t phhalHw_Rd70x_WriteRegister(
                                       phhalHw_Rd70x_DataParams_t * pDataParams,
                                       uint8_t bAddress,
                                       uint8_t bValue
                                       )
{
    return phhalHw_Rd70x_Cmd_WriteRC(pDataParams, bAddress, bValue);
}

phStatus_t phhalHw_Rd70x_ReadRegister(
                                      phhalHw_Rd70x_DataParams_t * pDataParams,
                                      uint8_t bAddress,
                                      uint8_t * pValue
                                      )
{
    return phhalHw_Rd70x_Cmd_ReadRC(pDataParams, bAddress, pValue);
}

phStatus_t phhalHw_Rd70x_ApplyProtocolSettings(
    phhalHw_Rd70x_DataParams_t * pDataParams,
    uint8_t bCardType
    )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint16_t    PH_MEMLOC_COUNT wIndex;
    uint16_t *  PH_MEMLOC_REM pShadowDefault;
    uint16_t    PH_MEMLOC_REM wShadowCount;
    uint8_t     PH_MEMLOC_REM bUseDefaultShadow;
    uint16_t    PH_MEMLOC_REM wConfig;
    uint8_t     PH_MEMLOC_REM bSerialNo[4];

    /* Store new card type */
    if (bCardType != PHHAL_HW_CARDTYPE_CURRENT)
    {
        pDataParams->bCardType = bCardType;
        bUseDefaultShadow = 1;
    }
    else
    {
        bUseDefaultShadow = 0;
    }

    /* configure reader IC for current card */
    switch (pDataParams->bCardType)
    {
        /* configure hardware for ISO 14443 */
    case PHHAL_HW_CARDTYPE_ISO14443A:
    case PHHAL_HW_CARDTYPE_ISO14443B:

        if (!pDataParams->bDisablePcdReset)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdConfig(pDataParams));
            if (bCardType != PHHAL_HW_CARDTYPE_CURRENT)
            {
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdGetSnr(pDataParams, bSerialNo));
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdEnableHighBaudRates(pDataParams, bSerialNo));
            }
        }

        /* TypeA specific */
        if (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443A)
        {
            /* Use 14443a default shadow */
            pShadowDefault = (uint16_t*)wRd70x_DefaultShadow_14443a;
            wShadowCount = sizeof(wRd70x_DefaultShadow_14443a) / (sizeof(uint16_t) * 2);

            /* Write CRCPreset(LSB) Register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
                pDataParams,
                PHHAL_HW_RD70X_REG_CRC_PRESET_LSB,
                0x63));

            /* Write CRCPreset(MSB) Register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
                pDataParams,
                PHHAL_HW_RD70X_REG_CRC_PRESET_MSB,
                0x63));
        }
        /* TypeB specific */
        else
        {
            /* Use 14443b default shadow */
            pShadowDefault = (uint16_t*)wRd70x_DefaultShadow_14443b;
            wShadowCount = sizeof(wRd70x_DefaultShadow_14443b) / (sizeof(uint16_t) * 2);

            /* Write CRCPreset(LSB) Register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
                pDataParams,
                PHHAL_HW_RD70X_REG_CRC_PRESET_LSB,
                0xFF));

            /* Write CRCPreset(MSB) Register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
                pDataParams,
                PHHAL_HW_RD70X_REG_CRC_PRESET_MSB,
                0xFF));
        }
        break;

    case PHHAL_HW_CARDTYPE_ISO15693:

        if (!pDataParams->bDisablePcdReset)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_I1PcdConfig(pDataParams));
        }

        /* Use 15693 default shadow */
        pShadowDefault = (uint16_t*)wRd70x_DefaultShadow_15693;
        wShadowCount = sizeof(wRd70x_DefaultShadow_15693) / (sizeof(uint16_t) * 2);

        /* Set default SOF */
        pDataParams->bSymbolStart = PHHAL_HW_SYMBOL_I15693_SOF;

        break;

    case PHHAL_HW_CARDTYPE_ICODEEPCUID:

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_I1PcdConfig(pDataParams));
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_UIDPcdConfig(pDataParams));

        /* Use ICode EPC/UID default shadow */
        pShadowDefault = (uint16_t*)wRd70x_DefaultShadow_ICodeEpcUid;
        wShadowCount = sizeof(wRd70x_DefaultShadow_ICodeEpcUid) / (sizeof(uint16_t) * 2);

        /* Set default SOF */
        pDataParams->bSymbolStart = PHHAL_HW_SYMBOL_ICODEEPCUID_SSOF;

        break;

    default:

        return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
    }

    /* Initialize config shadow */
    if (bCardType != PHHAL_HW_CARDTYPE_CURRENT)
    {
        memset(pDataParams->wCfgShadow, 0x00, PHHAL_HW_RD70X_SHADOW_COUNT);  /* PRQA S 3200 */
    }

    /* Apply shadowed registers */
    for (wIndex = 0; wIndex < wShadowCount; ++wIndex)
    {
        /* Get wConfig */
        wConfig = pShadowDefault[wIndex << 1];

        /* Default shadow: */
        if (bUseDefaultShadow)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_SetConfig(pDataParams, wConfig, pShadowDefault[(wIndex << 1) + 1]));
        }
        /* Current shadow: */
        else
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_SetConfig(pDataParams, wConfig, pDataParams->wCfgShadow[wConfig]));
        }
    }

    /* Apply default timeout if neccessary */
    if (bUseDefaultShadow)
    {
        pDataParams->dwTimeoutUs = PHHAL_HW_RD70X_DEFAULT_TIMEOUT_MS * 1000;
    }

    /* MIFARE Crypto1 state is disabled by default */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams, PHHAL_HW_CONFIG_DISABLE_MF_CRYPTO1, PH_ON));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_SetConfig(
                                   phhalHw_Rd70x_DataParams_t * pDataParams,
                                   uint16_t wConfig,
                                   uint16_t wValue
                                   )
{

    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bBackup;
    uint8_t     PH_MEMLOC_REM bValue;
    uint16_t    PH_MEMLOC_REM wOtherDataRate;

    switch (wConfig)
    {
    case PHHAL_HW_CONFIG_PARITY:

        /* Update the flags (enabled is disabled in this case) */
        if (wValue == PH_OFF)
        {
            pDataParams->bFlags |= PHHAL_HW_RD70X_BIT_ENABLE_PARITY;
        }
        else
        {
            pDataParams->bFlags &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ENABLE_PARITY;
        }

        /* Directly change the the register for protocols which are not using ExchangeBitByte with flags */
        if ((pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO14443A) && (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO14443B))
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_CHANNEL_REDUND, &bBackup));

            if (wValue == PH_OFF)
            {
                bValue = bBackup & (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ENABLE_PARITY;
            }
            else
            {
                bValue = bBackup | PHHAL_HW_RD70X_BIT_ENABLE_PARITY;
            }

            /* Only perform the operation, if the new value is different */
            if (bValue != bBackup)
            {
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_CHANNEL_REDUND, bBackup));
            }
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        break;

    case PHHAL_HW_CONFIG_TXCRC:

        /* Update the flags (enabled is disabled in this case) */
        if (wValue == PH_OFF)
        {
            pDataParams->bFlags |= PHHAL_HW_RD70X_BIT_ENABLE_TXCRC;
        }
        else
        {
            pDataParams->bFlags &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ENABLE_TXCRC;
        }

        /* Directly change the the register for protocols which are not using ExchangeBitByte with flags */
        if ((pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO14443A) && (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO14443B))
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_CHANNEL_REDUND, &bBackup));

            if (wValue == PH_OFF)
            {
                bValue = bBackup & (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ENABLE_TXCRC;
            }
            else
            {
                bValue = bBackup | PHHAL_HW_RD70X_BIT_ENABLE_TXCRC;
            }

            /* Only perform the operation, if the new value is different */
            if (bValue != bBackup)
            {
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_CHANNEL_REDUND, bBackup));
            }
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        break;

    case PHHAL_HW_CONFIG_RXCRC:

        /* Update the flags (enabled is disabled in this case) */
        if (wValue == PH_OFF)
        {
            pDataParams->bFlags |= PHHAL_HW_RD70X_BIT_ENABLE_RXCRC;
        }
        else
        {
            pDataParams->bFlags &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ENABLE_RXCRC;
        }

        /* Directly change the the register for protocols which are not using ExchangeBitByte with flags */
        if ((pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO14443A) && (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO14443B))
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_CHANNEL_REDUND, &bBackup));

            if (wValue == PH_OFF)
            {
                bValue = bBackup & (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ENABLE_RXCRC;
            }
            else
            {
                bValue = bBackup | PHHAL_HW_RD70X_BIT_ENABLE_RXCRC;
            }

            /* Only perform the operation, if the new value is different */
            if (bValue != bBackup)
            {
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_CHANNEL_REDUND, bBackup));
            }
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        break;

    case PHHAL_HW_CONFIG_TXLASTBITS:

        /* check parameter */
        if (wValue > 7)
        {
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        break;

    case PHHAL_HW_CONFIG_RXALIGN:

        /* check parameter */
        if (wValue > 7)
        {
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_BIT_FRAMING, &bBackup));

        /* adjust register */
        bBackup &= (uint8_t)~(uint8_t)0x70;
        bBackup |= (uint8_t)(wValue << 4);

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_BIT_FRAMING, bBackup));

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        break;

    case PHHAL_HW_CONFIG_RXDEAFBITS:

        /* check parameter */
        if (wValue > 0xFF)
        {
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_WAIT, (uint8_t)wValue));

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        break;

    case PHHAL_HW_CONFIG_CLEARBITSAFTERCOLL:

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_DECODER_CONTROL, &bBackup));

        if (wValue)
        {
            bValue = bBackup | PHHAL_HW_RD70X_BIT_ZEROAFTERCOLL;
        }
        else
        {
            bValue = bBackup & (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_ZEROAFTERCOLL;
        }

        /* Only perform the operation, if the new value is different */
        if (bValue != bBackup)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_DECODER_CONTROL, bBackup));
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;
        break;

    case PHHAL_HW_CONFIG_TXDATARATE:

        if (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO15693)
        {
            switch (wValue)
            {
            case PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_256:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_I2init_StdMode_15693(pDataParams));
                break;
            case PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_4:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_I2init_FastMode_15693(pDataParams));
                break;
            case PHHAL_HW_RF_DATARATE_106:
            case PHHAL_HW_RF_DATARATE_212:
            case PHHAL_HW_RF_DATARATE_424:
            case PHHAL_HW_RF_DATARATE_848:
                return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
            default:
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }
        }
        else if (
            (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443A) ||
            (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443B))
        {
            switch (wValue)
            {
            case PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_256:
            case PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_4:
            case PHHAL_HW_RF_RX_DATARATE_LOW:
            case PHHAL_HW_RF_RX_DATARATE_HIGH:
            case PHHAL_HW_RF_RX_DATARATE_FAST_LOW:
            case PHHAL_HW_RF_RX_DATARATE_FAST_HIGH:
                return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
            case PHHAL_HW_RF_DATARATE_106:
            case PHHAL_HW_RF_DATARATE_212:
            case PHHAL_HW_RF_DATARATE_424:
            case PHHAL_HW_RF_DATARATE_848:
                wOtherDataRate = pDataParams->wCfgShadow[PHHAL_HW_CONFIG_RXDATARATE];
                if (wOtherDataRate > PHHAL_HW_RF_DATARATE_848)
                {
                    wOtherDataRate = wValue;
                }
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdSetAttrib(
                    pDataParams,
                    (uint8_t)wOtherDataRate,
                    (uint8_t)wValue));
                break;
            default:
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }
        }
        else
        {
            return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        /* Set TypeB Registers */
        if (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443B)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_SetTypeBRegs(pDataParams));
        }
        break;

    case PHHAL_HW_CONFIG_RXDATARATE:

        if (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO15693)
        {
            switch (wValue)
            {
                /* Fast data-rate */
            case PHHAL_HW_RF_RX_DATARATE_FAST_HIGH:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, &bValue));
                bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_MASK_SUBCPULSES;
                bValue |= PHHAL_HW_RD70X_BITS_SUBCPULSES_8;
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, bValue));
                break;
                /* High data-rate */
            case PHHAL_HW_RF_RX_DATARATE_HIGH:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, &bValue));
                bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_MASK_SUBCPULSES;
                bValue |= PHHAL_HW_RD70X_BITS_SUBCPULSES_16;
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, bValue));
                break;
                /* Pegoda does not support 15693 Low Datarate*/
            case PHHAL_HW_RF_RX_DATARATE_LOW:
            case PHHAL_HW_RF_RX_DATARATE_FAST_LOW:
                return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
            case PHHAL_HW_RF_DATARATE_106:
            case PHHAL_HW_RF_DATARATE_212:
            case PHHAL_HW_RF_DATARATE_424:
            case PHHAL_HW_RF_DATARATE_848:
                return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
            default:
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }
        }
        else if (
            (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443A) ||
            (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443B))
        {
            switch (wValue)
            {
            case PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_256:
            case PHHAL_HW_RF_TX_DATARATE_1_OUT_OF_4:
            case PHHAL_HW_RF_RX_DATARATE_LOW:
            case PHHAL_HW_RF_RX_DATARATE_HIGH:
            case PHHAL_HW_RF_RX_DATARATE_FAST_LOW:
            case PHHAL_HW_RF_RX_DATARATE_FAST_HIGH:
                return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
            case PHHAL_HW_RF_DATARATE_106:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, &bValue));
                bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_MASK_SUBCPULSES;
                bValue |= PHHAL_HW_RD70X_BITS_SUBCPULSES_8;
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, bValue));
                break;
            case PHHAL_HW_RF_DATARATE_212:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, &bValue));
                bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_MASK_SUBCPULSES;
                bValue |= PHHAL_HW_RD70X_BITS_SUBCPULSES_4;
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, bValue));
                break;
            case PHHAL_HW_RF_DATARATE_424:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, &bValue));
                bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_MASK_SUBCPULSES;
                bValue |= PHHAL_HW_RD70X_BITS_SUBCPULSES_2;
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, bValue));
                break;
            case PHHAL_HW_RF_DATARATE_848:
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, &bValue));
                bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_MASK_SUBCPULSES;
                bValue |= PHHAL_HW_RD70X_BITS_SUBCPULSES_1;
                PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_RX_CONTROL1, bValue));
                break;
            default:
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }

            /* Perform SetAttrib */
            wOtherDataRate = pDataParams->wCfgShadow[PHHAL_HW_CONFIG_TXDATARATE];
            if (wOtherDataRate > PHHAL_HW_RF_DATARATE_848)
            {
                wOtherDataRate = wValue;
            }
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdSetAttrib(
                pDataParams,
                (uint8_t)wValue,
                (uint8_t)wOtherDataRate));
        }
        else
        {
            return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
        }

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;

        /* Set TypeB Registers */
        if (pDataParams->bCardType == PHHAL_HW_CARDTYPE_ISO14443B)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_SetTypeBRegs(pDataParams));
        }
        break;

    case PHHAL_HW_CONFIG_MODINDEX:

        /* Set ModConductance register */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(
            pDataParams,
            PHHAL_HW_RD70X_REG_MOD_COND,
            (uint8_t)(wValue & 0x3F)));

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;
        break;

    case PHHAL_HW_CONFIG_ASK100:

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_TXCONTROL, &bValue));

        /* switch on 100% ASK */
        if (wValue != PH_OFF)
        {
            bValue |= PHHAL_HW_RD70X_BIT_FORCE_100ASK;
        }
        /* switch off 100% ASK */
        else
        {
            bValue &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_FORCE_100ASK;
        }

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TXCONTROL, bValue));

        /* Write config data into shadow */
        pDataParams->wCfgShadow[wConfig] = wValue;
        break;

    case PHHAL_HW_CONFIG_TIMEOUT_VALUE_US:

        pDataParams->dwTimeoutUs = (uint32_t)wValue;
        break;

    case PHHAL_HW_CONFIG_TIMEOUT_VALUE_MS:

        pDataParams->dwTimeoutUs = (uint32_t)(wValue * 1000);
        break;

    case PHHAL_HW_CONFIG_TIMING_MODE:

        /* Check supported option bits */
        switch (wValue & PHHAL_HW_TIMING_MODE_OPTION_MASK)
        {
        case PHHAL_HW_TIMING_MODE_OPTION_DEFAULT:
        case PHHAL_HW_TIMING_MODE_OPTION_AUTOCLEAR:
            break;
        default:
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        /* Check supported timing modes */
        switch (wValue & (uint16_t)~(uint16_t)PHHAL_HW_TIMING_MODE_OPTION_MASK)
        {
        case PHHAL_HW_TIMING_MODE_OFF:
        case PHHAL_HW_TIMING_MODE_COMM:
            pDataParams->dwTimingUs = 0;
            pDataParams->wTimingMode = wValue;
            break;
        case PHHAL_HW_TIMING_MODE_FDT:
            return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
        default:
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        break;

    case PHHAL_HW_CONFIG_FIELD_OFF_TIME:

        /* Parameter Check */
        if (wValue == 0)
        {
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        /* Store config data */
        pDataParams->wFieldOffTime = wValue;
        break;

    case PHHAL_HW_CONFIG_FIELD_RECOVERY_TIME:

        /* Store config data */
        pDataParams->wFieldRecoveryTime = wValue;
        break;

    case PHHAL_HW_CONFIG_SYMBOL_START:

        /* Parameter check */
        if ((pDataParams->bCardType != PHHAL_HW_CARDTYPE_ICODEEPCUID) &&
            (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO15693))
        {
            return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
        }

        /* Parameter check #2 */
        switch (wValue)
        {
        case PHHAL_HW_SYMBOL_ICODEEPCUID_SSOF:
        case PHHAL_HW_SYMBOL_ICODEEPCUID_LSOF:
        case PHHAL_HW_SYMBOL_ICODEEPCUID_CS:
            if (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ICODEEPCUID)
            {
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }
            break;
        case PHHAL_HW_SYMBOL_I15693_SOF:
            if (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ISO15693)
            {
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }
            break;
        case PH_OFF:
            break;
        default:
            return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
        }

        /* Store Start-Symbol */
        pDataParams->bSymbolStart = (uint8_t)wValue;
        break;

    case PHHAL_HW_CONFIG_SYMBOL_END:

        /* Parameter check */
        if (pDataParams->bCardType != PHHAL_HW_CARDTYPE_ICODEEPCUID)
        {
            return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_HAL);
        }

        /* Parameter check #2 */
        switch (wValue)
        {
        case PHHAL_HW_SYMBOL_ICODEEPCUID_CEOF:
        case PH_OFF:
            break;
        default:
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
        }

        /* Store End-Symbol */
        pDataParams->bSymbolEnd = (uint8_t)wValue;
        break;

    case PHHAL_HW_CONFIG_SUBCARRIER:

        if (wValue != PHHAL_HW_SUBCARRIER_SINGLE)
        {
            if (wValue > PHHAL_HW_SUBCARRIER_QUAD)
            {
                return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
            }
            else
            {
                return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
            }
        }
        break;

    case PHHAL_HW_CONFIG_RXBUFFER_STARTPOS:

        /* Boundary check */
        if ((PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + wValue) >= pDataParams->wRxBufSize)
        {
            return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_HAL);
        }

        /* Set start position */
        pDataParams->wRxBufStartPos = wValue;
        pDataParams->wRxBufLen = wValue;

        /* Preserve RxBuffer contents if needed */
        if (pDataParams->pTxBuffer == pDataParams->pRxBuffer)
        {
            pDataParams->wTxBufStartPos = pDataParams->wRxBufStartPos;
        }
        else
        {
            pDataParams->wTxBufStartPos = 0;
        }
        break;

    case PHHAL_HW_CONFIG_TXBUFFER_LENGTH:

        /* Check parameter */
        if ((pDataParams->wTxBufStartPos + PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + wValue) > pDataParams->wTxBufSize)
        {
            return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_HAL);
        }

        /* set buffer length */
        pDataParams->wTxBufLen = wValue;
        break;

    case PHHAL_HW_CONFIG_TXBUFFER:

        /* Check additional info parameter */
        if ((pDataParams->wTxBufStartPos + PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + pDataParams->wAdditionalInfo) >= pDataParams->wTxBufSize)
        {
            return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_HAL);
        }

        /* Modify TxBuffer byte */
        pDataParams->pTxBuffer[pDataParams->wTxBufStartPos + PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + pDataParams->wAdditionalInfo] = (uint8_t)wValue;
        break;

    case PHHAL_HW_CONFIG_DISABLE_MF_CRYPTO1:

        /* Disable crypto, enabling is not supported */
        if (wValue != PH_OFF)
        {
            /* Retrieve Control register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_CONTROL, &bBackup));

            /* Clear Crypto1On bit */
            bBackup &= (uint8_t)~(uint8_t)PHHAL_HW_RD70X_BIT_CRYPTO1ON;

            /* Write Control register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_CONTROL, bBackup));
        }

        break;

    case PHHAL_HW_CONFIG_ADDITIONAL_INFO:

        /* Modify additional info parameter */
        pDataParams->wAdditionalInfo = wValue;
        break;

    case PHHAL_HW_CONFIG_RFRESET_ON_TIMEOUT:

        if (wValue == PH_OFF)
        {
            pDataParams->bRfResetAfterTo = PH_OFF;
        }
        else
        {
            pDataParams->bRfResetAfterTo = PH_ON;
        }
        break;

    case PHHAL_HW_RD70X_CONFIG_DISABLE_PCDRESET:

        pDataParams->bDisablePcdReset = (uint8_t)wValue;
        break;

    case PHHAL_HW_CONFIG_SETMINFDT:

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_SetMinFDT(pDataParams, wValue));
        break;

    default:
        return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_GetConfig(
                                   phhalHw_Rd70x_DataParams_t * pDataParams,
                                   uint16_t wConfig,
                                   uint16_t * pValue
                                   )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bRegister;

    switch (wConfig)
    {
    case PHHAL_HW_CONFIG_PARITY:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_TXCRC:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_RXCRC:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_TXLASTBITS:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_ADDITIONAL_INFO:
    case PHHAL_HW_CONFIG_RXLASTBITS:

        *pValue = pDataParams->wAdditionalInfo;
        break;

    case PHHAL_HW_CONFIG_RXDEAFBITS:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_CLEARBITSAFTERCOLL:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_TXDATARATE:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_RXDATARATE:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_MODINDEX:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_ASK100:

        /* Read config from shadow */
        *pValue = pDataParams->wCfgShadow[wConfig];
        break;

    case PHHAL_HW_CONFIG_TIMEOUT_VALUE_US:

        /* Overflow check */
        if (pDataParams->dwTimeoutUs > 0xFFFF)
        {
            return PH_ADD_COMPCODE(PH_ERR_PARAMETER_OVERFLOW, PH_COMP_HAL);
        }
        *pValue = (uint16_t)pDataParams->dwTimeoutUs;
        break;

    case PHHAL_HW_CONFIG_TIMEOUT_VALUE_MS:

        /* Return parameter */
        *pValue = (uint16_t)(pDataParams->dwTimeoutUs / 1000);
        break;

    case PHHAL_HW_CONFIG_TIMING_MODE:

        /* Return parameter */
        *pValue = pDataParams->wTimingMode;
        break;

    case PHHAL_HW_CONFIG_TIMING_US:

        if (pDataParams->dwTimingUs > 0xFFFF)
        {
            return PH_ADD_COMPCODE(PH_ERR_PARAMETER_OVERFLOW, PH_COMP_HAL);
        }

        *pValue = (uint16_t)pDataParams->dwTimingUs;
        pDataParams->dwTimingUs = 0;
        break;

    case PHHAL_HW_CONFIG_TIMING_MS:

        if (pDataParams->dwTimingUs > (0xFFFF * 1000))
        {
            pDataParams->dwTimingUs = 0;
            return PH_ADD_COMPCODE(PH_ERR_PARAMETER_OVERFLOW, PH_COMP_HAL);
        }

        *pValue = (uint16_t)(pDataParams->dwTimingUs / 1000);
        pDataParams->dwTimingUs = 0;
        break;

    case PHHAL_HW_CONFIG_FIELD_OFF_TIME:

        /* Return parameter */
        *pValue = pDataParams->wFieldOffTime;
        break;

    case PHHAL_HW_CONFIG_FIELD_RECOVERY_TIME:

        /* Return parameter */
        *pValue = pDataParams->wFieldRecoveryTime;
        break;

    case PHHAL_HW_CONFIG_SYMBOL_START:

        /* Return parameter */
        *pValue = pDataParams->bSymbolStart;
        break;

    case PHHAL_HW_CONFIG_SYMBOL_END:

        /* Return parameter */
        *pValue = pDataParams->bSymbolEnd;
        break;

    case PHHAL_HW_CONFIG_SUBCARRIER:

        /* Return parameter */
        *pValue = PHHAL_HW_SUBCARRIER_SINGLE;
        break;

    case PHHAL_HW_CONFIG_RXBUFFER_STARTPOS:

        /* Return parameter */
        *pValue = pDataParams->wRxBufStartPos;
        break;

    case PHHAL_HW_CONFIG_RXBUFFER_BUFSIZE:

        /* Return parameter */
        *pValue = pDataParams->wRxBufSize - PHHAL_HW_RD70X_RESERVED_BUFFER_LEN;
        break;

    case PHHAL_HW_CONFIG_TXBUFFER_BUFSIZE:

        /* Return parameter */
        *pValue = pDataParams->wTxBufSize - PHHAL_HW_RD70X_RESERVED_BUFFER_LEN - pDataParams->wTxBufStartPos;
        break;

    case PHHAL_HW_CONFIG_TXBUFFER_LENGTH:

        /* Return parameter */
        *pValue = pDataParams->wTxBufLen;
        break;

    case PHHAL_HW_CONFIG_TXBUFFER:

        /* Check additional info parameter */
        if ((pDataParams->wTxBufStartPos + PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + pDataParams->wAdditionalInfo) >= pDataParams->wTxBufSize)
        {
            return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_HAL);
        }

        /* Retrieve TxBuffer byte */
        *pValue = (uint16_t)pDataParams->pTxBuffer[pDataParams->wTxBufStartPos + PHHAL_HW_RD70X_RESERVED_BUFFER_LEN + pDataParams->wAdditionalInfo];
        break;

    case PHHAL_HW_CONFIG_DISABLE_MF_CRYPTO1:

        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_CONTROL, &bRegister));

        /* Clear Crypto1On bit */
        if (bRegister & PHHAL_HW_RD70X_BIT_CRYPTO1ON)
        {
            *pValue = PH_OFF;
        }
        else
        {
            *pValue = PH_ON;
        }
        break;

    case PHHAL_HW_CONFIG_RFRESET_ON_TIMEOUT:

        *pValue = (uint16_t)pDataParams->bRfResetAfterTo;
        break;

    case PHHAL_HW_RD70X_CONFIG_DISABLE_PCDRESET:

        *pValue = (uint16_t)pDataParams->bDisablePcdReset;
        break;

    default:
        return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_FieldOn(
                                 phhalHw_Rd70x_DataParams_t * pDataParams
                                 )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bTxControlReg;

    /* Retrieve the content of the TxControl register */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_TXCONTROL, &bTxControlReg));

    /* Switch on the field again */
    bTxControlReg |= PHHAL_HW_RD70X_BIT_TX1RFEN | PHHAL_HW_RD70X_BIT_TX2RFEN;
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TXCONTROL, bTxControlReg));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_FieldOff(
                                  phhalHw_Rd70x_DataParams_t * pDataParams
                                  )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bTxControlReg;

    /* Retrieve the content of the TxControl register */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_TXCONTROL, &bTxControlReg));

    /* Switch off the field */
    bTxControlReg &= (uint8_t)~(uint8_t)(PHHAL_HW_RD70X_BIT_TX1RFEN | PHHAL_HW_RD70X_BIT_TX2RFEN);
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TXCONTROL, bTxControlReg));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_FieldReset(
                                    phhalHw_Rd70x_DataParams_t * pDataParams
                                    )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint16_t    PH_MEMLOC_REM wFieldOffTmp;

    /* Pegoda Rf-Reset is about 14% too long, so correct the Off-Time */
    if (pDataParams->wFieldOffTime > 1)
    {
        wFieldOffTmp = (uint16_t)((float32_t)pDataParams->wFieldOffTime * 0.86);
    }
    else
    {
        wFieldOffTmp = 1;
    }

    switch (pDataParams->bCardType)
    {
    case PHHAL_HW_CARDTYPE_ISO14443A:

        /* perfrom RF-Reset */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdRfReset(pDataParams, wFieldOffTmp));
        break;

    case PHHAL_HW_CARDTYPE_ISO14443B:

        /* perfrom RF-Reset */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_PcdRfReset(pDataParams, wFieldOffTmp));
        /* Set TypeB Registers */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_SetTypeBRegs(pDataParams));
        break;

    case PHHAL_HW_CARDTYPE_ISO15693:
    case PHHAL_HW_CARDTYPE_ICODEEPCUID:

        /* perfrom RF-Reset */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_I1PcdRfReset(pDataParams, wFieldOffTmp));
        break;

    default:

        return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_PARAMETER, PH_COMP_HAL);
    }

    /* Firmware only has 1ms recovery-time, wait the remaining time */
    if (pDataParams->wFieldRecoveryTime > 1)
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Wait(
            pDataParams,
            PHHAL_HW_TIME_MILLISECONDS,
            pDataParams->wFieldRecoveryTime - 1));
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_Wait(
                              phhalHw_Rd70x_DataParams_t * pDataParams,
                              uint8_t bUnit,
                              uint16_t wTimeout
                              )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bRegTimerClock;
    uint8_t     PH_MEMLOC_REM bRegTimerReload;
    uint8_t     PH_MEMLOC_REM bRegTimerControl;
    uint8_t     PH_MEMLOC_REM bTmp;
    uint16_t    PH_MEMLOC_REM wPrescaler;
    uint16_t    PH_MEMLOC_REM wReload;
    float32_t   PH_MEMLOC_REM fTimeoutUs;
    float32_t   PH_MEMLOC_REM fTemp;

    /* Parameter check */
    if ((bUnit != PHHAL_HW_TIME_MICROSECONDS) && (bUnit != PHHAL_HW_TIME_MILLISECONDS))
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    /* Backup Rd70x register contents */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_CLOCK, &bRegTimerClock));
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_RELOAD, &bRegTimerReload));
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_CONTROL, &bRegTimerControl));

    /* do as long as we have an overflow in the IC timer */
    do
    {
        /* Handle timeout in microseconds */
        if (bUnit == PHHAL_HW_TIME_MICROSECONDS)
        {
            fTimeoutUs = (float32_t)wTimeout;
            wTimeout = 0;
        }
        else
        {
            fTimeoutUs = (float32_t)wTimeout * 1000.0f;

            /* Max. timeout check */
            if (fTimeoutUs > PHHAL_HW_RD70X_TIMER_MAX_VALUE_US)
            {
                fTimeoutUs = PHHAL_HW_RD70X_TIMER_MAX_VALUE_US;
                wTimeout = wTimeout - ((uint16_t)(PHHAL_HW_RD70X_TIMER_MAX_VALUE_US / 1000.0f) + 1);
            }
            else
            {
                wTimeout = 0;
            }
        }

        /* Calculate the prescaler value */
        /* [timeout[us]  = (2 ^ n) / 13.56] */
        fTemp = (float32_t)(log((fTimeoutUs * PHHAL_HW_RD70X_TIMER_FREQ) / 255.0f) / log(2));

        /* Evaluate prescaler value */
        if (fTemp > 1.0f)
        {
            if (fTemp < 21.0f)
            {
                wPrescaler = (uint16_t)(fTemp + 1);
            }
            else
            {
                wPrescaler = 21;
            }
        }
        else
        {
            wPrescaler = 1;
        }

        /* Calculate the reload value */
        fTemp = (fTimeoutUs * PHHAL_HW_RD70X_TIMER_FREQ) / (float32_t)(1 << wPrescaler);

        /* Except for a special case, the float value will have some commas
        and therefore needs to be "ceiled" */
        if (fTemp > (float32_t)(uint16_t)fTemp)
        {
            wReload = (uint16_t)(fTemp + 1);
        }
        else
        {
            wReload = (uint16_t)fTemp;
        }

        /* stop a probably running command */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_COMMAND, 0x00));

        /* Set new timeout value */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_CLOCK, (uint8_t)wPrescaler));
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_RELOAD, (uint8_t)wReload));
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_CONTROL, 0x00));

        /* Start the timer */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_CONTROL, &bTmp));
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_CONTROL, bTmp | PHHAL_HW_RD70X_BIT_TSTARTNOW));

        /* wait for timer */
        do
        {
            /* Read secondary status register */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_SECONDARY_STATUS, &bTmp));
        }
        while (bTmp & PHHAL_HW_RD70X_BIT_TRUNNING);
    }
    while (wTimeout > 0);

    /* Restore Rd70x register contents */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_CLOCK, bRegTimerClock));
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_RELOAD, bRegTimerReload));
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_WriteRegister(pDataParams, PHHAL_HW_RD70X_REG_TIMER_CONTROL, bRegTimerControl));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_MfcAuthenticateKeyNo(
    phhalHw_Rd70x_DataParams_t * pDataParams,
    uint8_t bBlockNo,
    uint8_t bKeyType,
    uint16_t wKeyNo,
    uint16_t wKeyVersion,
    uint8_t * pUid
    )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bAuthMode;

    /* Evaluate which key to use */
    if ((bKeyType & 0x7F) == PHHAL_HW_MFC_KEYA)
    {
        bAuthMode = PHHAL_HW_RD70X_AUTHMODE_KEYA;
    }
    else if ((bKeyType & 0x7F) == PHHAL_HW_MFC_KEYB)
    {
        bAuthMode = PHHAL_HW_RD70X_AUTHMODE_KEYB;
    }
    else
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    /* check key version */
    if (wKeyVersion != 0)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    /* check key number */
    if (wKeyNo > PHHAL_HW_RD70X_MAX_NUM_KEYS)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    /* Perform authentication */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_MfPiccAuthE2(
        pDataParams,
        bAuthMode,
        pUid,
        (uint8_t)wKeyNo,
        bBlockNo
        ));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_MfcAuthenticate(
    phhalHw_Rd70x_DataParams_t * pDataParams,
    uint8_t bBlockNo,
    uint8_t bKeyType,
    uint8_t * pKey,
    uint8_t * pUid
    )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bAuthMode;
    uint8_t     PH_MEMLOC_REM bKey[PHHAL_HW_MFC_KEY_LENGTH * 2];

    /* Evaluate which key to use */
    if ((bKeyType & 0x7F) == PHHAL_HW_MFC_KEYA)
    {
        bAuthMode = PHHAL_HW_RD70X_AUTHMODE_KEYA;
    }
    else if ((bKeyType & 0x7F) == PHHAL_HW_MFC_KEYB)
    {
        bAuthMode = PHHAL_HW_RD70X_AUTHMODE_KEYB;
    }
    else
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_HAL);
    }

    /* Code the key */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_HostCodeKey(
        pDataParams,
        pKey,
        bKey));

    /* Perform authentication */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_Cmd_MfPiccAuthKey(
        pDataParams,
        bAuthMode,
        pUid,
        bKey,
        bBlockNo
        ));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);
}

phStatus_t phhalHw_Rd70x_SetMinFDT(
    phhalHw_Rd70x_DataParams_t * pDataParams,
    uint16_t wValue
    )
{
    phStatus_t    PH_MEMLOC_REM status = 0;
    uint16_t    PH_MEMLOC_REM wTimer = 0;
    uint16_t    PH_MEMLOC_REM wTxRate = 0;
    uint8_t     PH_MEMLOC_REM bRegTimerControl = 0;

    if (wValue == PH_ON)
    {
        /*Backup the old Timer Control values and enable the timer for FDT*/
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_ReadRegister(pDataParams,
            PHHAL_HW_RD70X_REG_TIMER_CONTROL, &bRegTimerControl));
        pDataParams->bTimerControlPc = bRegTimerControl;
        bRegTimerControl = 0x06;
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_WriteRegister(pDataParams,
            PHHAL_HW_RD70X_REG_TIMER_CONTROL, bRegTimerControl));
        /*Backup the old Timer values and set min FDT*/
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_GetConfig(pDataParams,
                PHHAL_HW_CONFIG_TIMEOUT_VALUE_MS, &wTimer));
        pDataParams->dwFdtPc = wTimer;
        /* Get the data rate */
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_GetConfig(pDataParams,
                PHHAL_HW_CONFIG_TXDATARATE, &wTxRate));
        switch(wTxRate)
        {
            case PHHAL_HW_RF_DATARATE_106:
                wTimer = PHHAL_HW_MINFDT_106_US;
                break;
            case PHHAL_HW_RF_DATARATE_212:
                wTimer = PHHAL_HW_MINFDT_212_US;
                break;
            case PHHAL_HW_RF_DATARATE_424:
                wTimer = PHHAL_HW_MINFDT_424_US;
                break;
            case PHHAL_HW_RF_DATARATE_848:
                wTimer = PHHAL_HW_MINFDT_848_US;
                break;
            default:
                break;
        }
        /* Calculate values for Microsecond values */
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_SetConfig(pDataParams,
        PHHAL_HW_CONFIG_TIMEOUT_VALUE_US, wTimer));
    }
    else if (wValue == PH_OFF)
    {
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_WriteRegister(pDataParams,
                PHHAL_HW_RD70X_REG_TIMER_CONTROL, pDataParams->bTimerControlPc));
        PH_CHECK_SUCCESS_FCT(status, phhalHw_Rd70x_SetConfig(pDataParams,
                PHHAL_HW_CONFIG_TIMEOUT_VALUE_MS, pDataParams->dwFdtPc));
    }
    else
    {
        /* Do nothing*/
    }
    return status;
}

#endif /* NXPBUILD__PHHAL_HW_RD70X */


text:
using UnityEngine;
using System.Collections;

public class BringToFront : MonoBehaviour {

    //when element is enabled, set it as last sibling
    void OnEnable()
    {
        transform.SetAsLastSibling();
    }
	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {

	}
}

redpajama_set_name: RedPajamaGithub


text:
shared_examples 'commentable with Disqus' do
  let(:data_tags) {
    data_tags = {
      'data-disqus-shortname' => Settings.disqus.shortname,
      'data-disqus-identifier' => entity.friendly_id,
      'data-disqus-title' => entity.title,
      'data-disqus-url' => 'test.com'
    }
  }

  before :each do
    allow(controller.request).to receive(:url).and_return('test.com')
  end

  it 'renders Disqus_thread with parameters for Document' do
    render
    expect(rendered).to have_selector('#disqus_thread', data_tags)
  end

  it 'embeds single-sign-on script if user is logged in' do
    allow(view).to receive(:current_user).and_return(stub_model(User))
    allow(view).to receive(:user_signed_in?).and_return(true)
    render
    expect(rendered).to have_selector('script#disqus-sso')
  end
end


text:
package edu.cmu.hcii.ssui.flashcards.db;

import java.util.ArrayList;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import edu.cmu.hcii.ssui.flashcards.Card;
import edu.cmu.hcii.ssui.flashcards.Deck;
import edu.cmu.hcii.ssui.flashcards.db.CardContract.CardTable;
import edu.cmu.hcii.ssui.flashcards.db.CardContract.DeckTable;
import edu.cmu.hcii.ssui.flashcards.db.CardContract.Tables;

/**
 * Database access object providing methods to interact with the cards and
 * decks stored in persistent storage.
 *
 * @author Shannon Lee
 */
public class CardDatabase {
    private static final String TAG = CardDatabase.class.getSimpleName();

    private CardDbHelper mDbHelper;
    private SQLiteDatabase mDb;

    public CardDatabase(Context context) {
        mDbHelper = CardDbHelper.getInstance(context);
    }

    /**
     * Opens the database for access.
     *
     * @throws SQLException
     */
    public void open() throws SQLException {
        mDb = mDbHelper.getWritableDatabase();
    }

    /**
     * Closes the connection to the database.
     */
    public void close() {
        if (mDb != null) {
            mDb.close();
        }
    }

    /**
     * Inserts a {@link Card} into the database. The information of that card
     * cannot be {@code null}.
     *
     * @param card the {@link Card} to be inserted into the database
     */
    public long insertCard(Card card) {
        return insertCard(card.getDeckId(), card.getFront(), card.getBack());
    }

    public long insertCard(long deckId, String front, String back) {
        Log.i(TAG, "Adding new Card '" + front + "/" + back + "' to the database.");

        ContentValues values = new ContentValues();
        values.put(CardTable.DECK_ID, deckId);
        values.put(CardTable.FRONT, front);
        values.put(CardTable.BACK, back);

        return mDb.insert(Tables.CARDS, null, values);
    }

    /**
     * Inserts a {@link Deck} into the database. The information of that deck
     * cannot be {@code null}.
     *
     * @param deck the {@link Deck} to be inserted into the database
     */
    public long insertDeck(Deck deck) {
        return insertDeck(deck.getName(), deck.getDescription());
    }

    public long insertDeck(String name, String description) {
        Log.i(TAG, "Adding new Deck '" + name + "' to the database.");

        ContentValues values = new ContentValues();
        values.put(DeckTable.NAME, name);
        values.put(DeckTable.DESCRIPTION, description);

        return mDb.insert(Tables.DECKS, null, values);
    }

    public List<Deck> getDecks() {
        // "SELECT * FROM " + Tables.DECKS
        Cursor cursor = mDb.query(true, Tables.DECKS, null, null, null, null, null, null, null);

        List<Deck> decks = new ArrayList<Deck>();

        // Iterate through the decks.
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            Deck deck = cursorToDeck(cursor);
            decks.add(deck);
            cursor.moveToNext();
        }
        cursor.close();
        return decks;
    }

    public List<Card> getCardsByDeck(Deck deck) {
        // "SELECT * FROM " + Tables.CARDS + " WHERE " + CardTable.DECK_ID +
        // " = " + deck.getId()
        Cursor cursor = mDb.query(true, Tables.CARDS, null, CardTable.DECK_ID + " = ?",
                new String[] { String.valueOf(deck.getId()) }, null, null, null, null);

        List<Card> cards = new ArrayList<Card>();

        // Iterate through the cards.
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            Card card = cursorToCard(cursor);
            cards.add(card);
            cursor.moveToNext();
        }
        cursor.close();

        return cards;
    }

    public void deleteCard(long id) {
        mDb.delete(Tables.CARDS, CardTable._ID + " = ?", new String[] { String.valueOf(id) });
    }

    public void deleteCard(Card card) {
        long id = card.getId();
        deleteCard(id);
    }

    public void deleteDeck(long id) {
        mDb.delete(Tables.DECKS, DeckTable._ID + " = ?", new String[] { String.valueOf(id) });
    }

    public void deleteDeck(Deck deck) {
        long id = deck.getId();
        deleteCard(id);
    }

    private Card cursorToCard(Cursor cursor) {
        long id = cursor.getLong(0);
        long deckId = cursor.getLong(1);
        String front = cursor.getString(2);
        String back = cursor.getString(3);
        return new Card(id, deckId, front, back);
    }

    private Deck cursorToDeck(Cursor cursor) {
        long id = cursor.getLong(0);
        String name = cursor.getString(1);
        String description = cursor.getString(2);
        return new Deck(id, name, description);
    }

}


text:
.class Landroid/support/v4/view/ViewCompat$JbMr1ViewCompatImpl;
.super Landroid/support/v4/view/ViewCompat$JBViewCompatImpl;
.source "ViewCompat.java"

# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Landroid/support/v4/view/ViewCompat;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x8
    name = "JbMr1ViewCompatImpl"
.end annotation

# direct methods
.method constructor <init>()V
    .locals 0

    .prologue
    .line 1407
    invoke-direct {p0}, Landroid/support/v4/view/ViewCompat$JBViewCompatImpl;-><init>()V

    return-void
.end method

# virtual methods
.method public getLabelFor(Landroid/view/View;)I
    .locals 1
    .param p1, "view"    # Landroid/view/View;

    .prologue
    .line 1411
    invoke-static {p1}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->getLabelFor(Landroid/view/View;)I

    move-result v0

    return v0
.end method

.method public getLayoutDirection(Landroid/view/View;)I
    .locals 1
    .param p1, "view"    # Landroid/view/View;

    .prologue
    .line 1426
    invoke-static {p1}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->getLayoutDirection(Landroid/view/View;)I

    move-result v0

    return v0
.end method

.method public getPaddingEnd(Landroid/view/View;)I
    .locals 1
    .param p1, "view"    # Landroid/view/View;

    .prologue
    .line 1441
    invoke-static {p1}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->getPaddingEnd(Landroid/view/View;)I

    move-result v0

    return v0
.end method

.method public getPaddingStart(Landroid/view/View;)I
    .locals 1
    .param p1, "view"    # Landroid/view/View;

    .prologue
    .line 1436
    invoke-static {p1}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->getPaddingStart(Landroid/view/View;)I

    move-result v0

    return v0
.end method

.method public getWindowSystemUiVisibility(Landroid/view/View;)I
    .locals 1
    .param p1, "view"    # Landroid/view/View;

    .prologue
    .line 1451
    invoke-static {p1}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->getWindowSystemUiVisibility(Landroid/view/View;)I

    move-result v0

    return v0
.end method

.method public isPaddingRelative(Landroid/view/View;)Z
    .locals 1
    .param p1, "view"    # Landroid/view/View;

    .prologue
    .line 1456
    invoke-static {p1}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->isPaddingRelative(Landroid/view/View;)Z

    move-result v0

    return v0
.end method

.method public setLabelFor(Landroid/view/View;I)V
    .locals 0
    .param p1, "view"    # Landroid/view/View;
    .param p2, "id"    # I

    .prologue
    .line 1416
    invoke-static {p1, p2}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->setLabelFor(Landroid/view/View;I)V

    .line 1415
    return-void
.end method

.method public setLayerPaint(Landroid/view/View;Landroid/graphics/Paint;)V
    .locals 0
    .param p1, "view"    # Landroid/view/View;
    .param p2, "paint"    # Landroid/graphics/Paint;

    .prologue
    .line 1421
    invoke-static {p1, p2}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->setLayerPaint(Landroid/view/View;Landroid/graphics/Paint;)V

    .line 1420
    return-void
.end method

.method public setLayoutDirection(Landroid/view/View;I)V
    .locals 0
    .param p1, "view"    # Landroid/view/View;
    .param p2, "layoutDirection"    # I

    .prologue
    .line 1431
    invoke-static {p1, p2}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->setLayoutDirection(Landroid/view/View;I)V

    .line 1430
    return-void
.end method

.method public setPaddingRelative(Landroid/view/View;IIII)V
    .locals 0
    .param p1, "view"    # Landroid/view/View;
    .param p2, "start"    # I
    .param p3, "top"    # I
    .param p4, "end"    # I
    .param p5, "bottom"    # I

    .prologue
    .line 1446
    invoke-static {p1, p2, p3, p4, p5}, Landroid/support/v4/view/ViewCompatJellybeanMr1;->setPaddingRelative(Landroid/view/View;IIII)V

    .line 1445
    return-void
.end method


text:
<?php

namespace Flarum\BBCode\Listeners;

use Flarum\Events\RegisterLocales;
use Flarum\Events\BuildClientView;
use Illuminate\Contracts\Events\Dispatcher;

class AddClientAssets
{
    public function subscribe(Dispatcher $events)
    {
        $events->listen(RegisterLocales::class, [$this, 'addLocale']);
        $events->listen(BuildClientView::class, [$this, 'addAssets']);
    }

    public function addLocale(RegisterLocales $event)
    {
        $event->addTranslations('en', __DIR__.'/../../locale/en.yml');
    }

    public function addAssets(BuildClientView $event)
    {
        $event->forumAssets([
            __DIR__.'/../../js/forum/dist/extension.js',
            __DIR__.'/../../less/forum/extension.less'
        ]);

        $event->forumBootstrapper('bbcode/main');

        $event->forumTranslations([
            // 'bbcode.hello_world'
        ]);
    }
}


text:
    (defined(__GLIBCXX__) && __GLIBCXX__ == CR_GLIBCXX_5_0_0)
#define CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX
#endif

// This hacks around using gcc with libc++ which has some incompatibilies.
// - is_trivially_* doesn't work: https://llvm.org/bugs/show_bug.cgi?id=27538
// TODO(danakj): Remove this when android builders are all using a newer version
// of gcc, or the android ndk is updated to a newer libc++ that works with older
// gcc versions.
#if !defined(__clang__) && defined(_LIBCPP_VERSION)
#define CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX
#endif

namespace base {

template <class T> struct is_non_const_reference : std::false_type {};
template <class T> struct is_non_const_reference<T&> : std::true_type {};
template <class T> struct is_non_const_reference<const T&> : std::false_type {};

namespace internal {

// Implementation detail of base::void_t below.
template <typename...>
struct make_void {
  using type = void;
};

}  // namespace internal

// base::void_t is an implementation of std::void_t from C++17.
//
// We use |base::internal::make_void| as a helper struct to avoid a C++14
// defect:
//   http://en.cppreference.com/w/cpp/types/void_t
//   http://open-std.org/JTC1/SC22/WG21/docs/cwg_defects.html#1558
template <typename... Ts>
using void_t = typename ::base::internal::make_void<Ts...>::type;

namespace internal {

// Uses expression SFINAE to detect whether using operator<< would work.
template <typename T, typename = void>
struct SupportsOstreamOperator : std::false_type {};
template <typename T>
struct SupportsOstreamOperator<T,
                               decltype(void(std::declval<std::ostream&>()
                                             << std::declval<T>()))>
    : std::true_type {};

// Used to detech whether the given type is an iterator.  This is normally used
// with std::enable_if to provide disambiguation for functions that take
// templatzed iterators as input.
template <typename T, typename = void>
struct is_iterator : std::false_type {};

template <typename T>
struct is_iterator<T,
                   void_t<typename std::iterator_traits<T>::iterator_category>>
    : std::true_type {};

}  // namespace internal

// is_trivially_copyable is especially hard to get right.
// - Older versions of libstdc++ will fail to have it like they do for other
//   type traits. This has become a subset of the second point, but used to be
//   handled independently.
// - An experimental release of gcc includes most of type_traits but misses
//   is_trivially_copyable, so we still have to avoid using libstdc++ in this
//   case, which is covered by CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX.
// - When compiling libc++ from before r239653, with a gcc compiler, the
//   std::is_trivially_copyable can fail. So we need to work around that by not
//   using the one in libc++ in this case. This is covered by the
//   CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX define, and is discussed in
//   https://llvm.org/bugs/show_bug.cgi?id=27538#c1 where they point out that
//   in libc++'s commit r239653 this is fixed by libc++ checking for gcc 5.1.
// - In both of the above cases we are using the gcc compiler. When defining
//   this ourselves on compiler intrinsics, the __is_trivially_copyable()
//   intrinsic is not available on gcc before version 5.1 (see the discussion in
//   https://llvm.org/bugs/show_bug.cgi?id=27538#c1 again), so we must check for
//   that version.
// - When __is_trivially_copyable() is not available because we are on gcc older
//   than 5.1, we need to fall back to something, so we use __has_trivial_copy()
//   instead based on what was done one-off in bit_cast() previously.

// TODO(crbug.com/554293): Remove this when all platforms have this in the std
// namespace and it works with gcc as needed.
#if defined(CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX) || \
    defined(CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX)
template <typename T>
struct is_trivially_copyable {
// TODO(danakj): Remove this when android builders are all using a newer version
// of gcc, or the android ndk is updated to a newer libc++ that does this for
// us.
#if _GNUC_VER >= 501
  static constexpr bool value = __is_trivially_copyable(T);
#else
  static constexpr bool value =
      __has_trivial_copy(T) && __has_trivial_destructor(T);
#endif
};
#else
template <class T>
using is_trivially_copyable = std::is_trivially_copyable<T>;
#endif

#ifdef STARBOARD
template <typename T>
struct is_trivially_copy_constructible : std::is_trivially_destructible<T> {};
#else
#if defined(__GNUC__) && !defined(__clang__) && __GNUC__ <= 7
// Workaround for g++7 and earlier family.
// Due to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80654, without this
// Optional<std::vector<T>> where T is non-copyable causes a compile error.
// As we know it is not trivially copy constructible, explicitly declare so.
template <typename T>
struct is_trivially_copy_constructible
    : std::is_trivially_copy_constructible<T> {};

template <typename... T>
struct is_trivially_copy_constructible<std::vector<T...>> : std::false_type {};
#else
// Otherwise use std::is_trivially_copy_constructible as is.
template <typename T>
using is_trivially_copy_constructible = std::is_trivially_copy_constructible<T>;
#endif
#endif  // STARBOARD

}  // namespace base

#undef CR_USE_FALLBACKS_FOR_GCC_WITH_LIBCXX
#undef CR_USE_FALLBACKS_FOR_OLD_EXPERIMENTAL_GLIBCXX

#endif  // BASE_TEMPLATE_UTIL_H_


text:
<DOCTYPE html>

  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Insert Pet </title>
  <link rel="stylesheet" href="<?php echo base_url("assets/css/bootstrap.css"); ?>">
    <link rel="stylesheet" href="<?php echo base_url("assets/css/style.css"); ?>">

      <a class="navbar-brand" href="<?php echo base_url(); ?>home">HOME
      <a class="navbar-brand" href="<?php echo base_url(); ?>">My Pets Veterinary Center

<a href="<?php echo base_url(); ?>users/logout" class="logoutBtn">Logout

Welcome <?php echo $user['name']; ?>!

            <form style="padding:5px; cursor:pointer;   width:300px; margin: 10px 10px 10px 10px; text-align:left;" action="<?php echo base_url() ?>insertPet/<?php ?>" method="post">

                        <input type="text" class="form-control" name="cod_mascota" placeholder="COD PET" required="" value="">
                        <?php echo form_error('cod_mascota','',''); ?>

                      <select  id="combobox_owner" name="combobox_owner" class="form-control " >
                          <?php foreach($owner as $each){ ?>
                              <option  value="<?php echo $each->id?>"><?php echo  $each->id?></option>';
                          <?php } ?>
                      </select>

                        <input type="text" class="form-control" name="nombre" placeholder="NOM" required="" value="">
                        <?php echo form_error('nombre','',''); ?>

                        <input type="date" class="form-control" name="fecha_nacimiento" placeholder="BIRTH DATE" required="" value="" required>
                        <?php echo form_error('fecha_nacimiento','',''); ?>

                      <select  id="combobox_vaccine" name="combobox_race" class="form-control">
                          <?php foreach($race as $each){ ?>
                              <option  value="<?php echo $each->cod_raza?>"><?php echo  $each->cod_raza?></option>';
                          <?php } ?>
                      </select>

                      <input  style="background-color: #20B2AA;" type="submit" class="btn btn-success" name="SumitPet" value="Guardar" />
                        <a class="btn btn-danger" href="<?php echo base_url() ?>pet"> Cancelar

        </form>


text:
=pod

=head1 NAME

RAND_set_rand_method, RAND_get_rand_method, RAND_OpenSSL - select RAND method

=head1 SYNOPSIS

 #include <openssl/rand.h>

Deprecated since OpenSSL 3.0, can be hidden entirely by defining
B<OPENSSL_API_COMPAT> with a suitable version value, see
L<openssl_user_macros(7)>:

 RAND_METHOD *RAND_OpenSSL(void);

 int RAND_set_rand_method(const RAND_METHOD *meth);

 const RAND_METHOD *RAND_get_rand_method(void);

=head1 DESCRIPTION

All of the functions described on this page are deprecated.
Applications should instead use L<RAND_set_DRBG_type(3)>,
L<EVP_RAND(3)> and L<EVP_RAND(7)>.

A B<RAND_METHOD> specifies the functions that OpenSSL uses for random number
generation.

RAND_OpenSSL() returns the default B<RAND_METHOD> implementation by OpenSSL.
This implementation ensures that the PRNG state is unique for each thread.

If an B<ENGINE> is loaded that provides the RAND API, however, it will
be used instead of the method returned by RAND_OpenSSL().  This is deprecated
in OpenSSL 3.0.

RAND_set_rand_method() makes B<meth> the method for PRNG use.  If an
ENGINE was providing the method, it will be released first.

RAND_get_rand_method() returns a pointer to the current B<RAND_METHOD>.

=head1 THE RAND_METHOD STRUCTURE

 typedef struct rand_meth_st {
     int (*seed)(const void *buf, int num);
     int (*bytes)(unsigned char *buf, int num);
     void (*cleanup)(void);
     int (*add)(const void *buf, int num, double entropy);
     int (*pseudorand)(unsigned char *buf, int num);
     int (*status)(void);
 } RAND_METHOD;

The fields point to functions that are used by, in order,
RAND_seed(), RAND_bytes(), internal RAND cleanup, RAND_add(), RAND_pseudo_rand()
and RAND_status().
Each pointer may be NULL if the function is not implemented.

=head1 RETURN VALUES

RAND_set_rand_method() returns 1 on success and 0 on failure.
RAND_get_rand_method() and RAND_OpenSSL() return pointers to the respective
methods.

=head1 SEE ALSO

L<EVP_RAND(3)>,
L<RAND_set_DRBG_type(3)>,
L<RAND_bytes(3)>,
L<ENGINE_by_id(3)>,
L<EVP_RAND(7)>,
L<RAND(7)>

=head1 HISTORY

All of these functions were deprecated in OpenSSL 3.0.

=head1 COPYRIGHT

Copyright 2000-2021 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License").  You may not use
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.

=cut


text:
// --------------------------------------------------------------------------------------------------------------------
//  <copyright file="TaskContinuationSequencer.cs" company="No lock... no deadlock" product="Michonne">
//     Copyright 2014 Olivier COANET (@ocoanet)
//     Licensed under the Apache License, Version 2.0 (the "License");
//     you may not use this file except in compliance with the License.
//     You may obtain a copy of the License at
//         http://www.apache.org/licenses/LICENSE-2.0
//     Unless required by applicable law or agreed to in writing, software
//     distributed under the License is distributed on an "AS IS" BASIS,
//     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//     See the License for the specific language governing permissions and
//     limitations under the License.
//   </copyright>
//   --------------------------------------------------------------------------------------------------------------------
namespace Seq
{
    using System;
    using System.Threading.Tasks;

    using Michonne.Interfaces;
    using Michonne.Tests;

    public class TaskContinuationSequencer : ISequencer
    {
        private readonly object _lock = new object();
        private readonly TaskScheduler scheduler;

        private Task task = Task.FromResult(0);

        public TaskContinuationSequencer(IExecutor executor)
        {
            this.scheduler = new TaskSchedulerAdapter(executor);
        }

        /// <summary>
        ///     Gets the unit of executions factory.
        /// </summary>
        public IExecutorFactory ExecutorFactory => null;

        public void Dispatch(Action action)
        {
            lock (this._lock)
            {
                this.task = this.task.ContinueWith(_ => action(), this.scheduler);
            }
        }
    }
}


text:
package org.apache.syncope.core.provisioning.api;

import java.util.Set;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.tuple.Pair;

public class UserWorkflowResult<T> extends WorkflowResult<T> {

    private final PropagationByResource<Pair<String, String>> propByLinkedAccount;

    public UserWorkflowResult(
            final T result,
            final PropagationByResource<String> propByRes,
            final PropagationByResource<Pair<String, String>> propByLinkedAccount,
            final String performedTask) {

        super(result, propByRes, performedTask);
        this.propByLinkedAccount = propByLinkedAccount;
    }

    public UserWorkflowResult(
            final T result,
            final PropagationByResource<String> propByRes,
            final PropagationByResource<Pair<String, String>> propByLinkedAccount,
            final Set<String> performedTasks) {

        super(result, propByRes, performedTasks);
        this.propByLinkedAccount = propByLinkedAccount;
    }

    public PropagationByResource<Pair<String, String>> getPropByLinkedAccount() {
        return propByLinkedAccount;
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder().
                appendSuper(super.hashCode()).
                append(propByLinkedAccount).
                build();
    }

    @Override
    public boolean equals(final Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        @SuppressWarnings("unchecked")
        final UserWorkflowResult<T> other = (UserWorkflowResult<T>) obj;
        return new EqualsBuilder().
                appendSuper(true).
                append(propByLinkedAccount, other.propByLinkedAccount).
                build();
    }

    @Override
    public String toString() {
        return new ToStringBuilder(this).
                appendSuper(super.toString()).
                append(propByLinkedAccount).
                build();
    }
}


text:
/*
 * @(#)PolyLineFigure.java 5.1
 *
 */

package CH.ifa.draw.figures;

import java.awt.*;
import java.util.*;
import java.io.*;
import java.net.*;
import CH.ifa.draw.framework.*;
import CH.ifa.draw.standard.*;
import CH.ifa.draw.util.*;

/**
 * A poly line figure consists of a list of points.
 * It has an optional line decoration at the start and end.
 *
 * @see LineDecoration
 */
public  class PolyLineFigure extends AbstractFigure {

    public final static int ARROW_TIP_NONE  = 0;
    public final static int ARROW_TIP_START = 1;
    public final static int ARROW_TIP_END   = 2;
    public final static int ARROW_TIP_BOTH  = 3;

    protected Vector              fPoints;
    protected LineDecoration      fStartDecoration = null;
    protected LineDecoration      fEndDecoration = null;
    protected Color               fFrameColor = Color.black;

    /*
     * Serialization support.
     */
    private static final long serialVersionUID = -7951352179906577773L;
    private int polyLineFigureSerializedDataVersion = 1;

    public PolyLineFigure() {
        fPoints = new Vector(4);
    }

    public PolyLineFigure(int size) {
        fPoints = new Vector(size);
    }

    public PolyLineFigure(int x, int y) {
	fPoints = new Vector();
	fPoints.addElement(new Point(x, y));
    }

    public Rectangle displayBox() {
        Enumeration k = points();
        Rectangle r = new Rectangle((Point) k.nextElement());

        while (k.hasMoreElements())
            r.add((Point) k.nextElement());

        return r;
    }

    public boolean isEmpty() {
        return (size().width < 3) && (size().height < 3);
    }

    public Vector handles() {
        Vector handles = new Vector(fPoints.size());
        for (int i = 0; i < fPoints.size(); i++)
            handles.addElement(new PolyLineHandle(this, locator(i), i));
        return handles;
    }

    public void basicDisplayBox(Point origin, Point corner) {
    }

    /**
     * Adds a node to the list of points.
     */
    public void addPoint(int x, int y) {
        fPoints.addElement(new Point(x, y));
        changed();
    }

    public Enumeration points() {
        return fPoints.elements();
    }

    public int pointCount() {
        return fPoints.size();
    }

    protected void basicMoveBy(int dx, int dy) {
        Enumeration k = fPoints.elements();
        while (k.hasMoreElements())
            ((Point) k.nextElement()).translate(dx, dy);
    }

    /**
     * Changes the position of a node.
     */
    public void setPointAt(Point p, int i) {
        willChange();
        fPoints.setElementAt(p, i);
        changed();
    }

    /**
     * Insert a node at the given point.
     */
    public void insertPointAt(Point p, int i) {
        fPoints.insertElementAt(p, i);
        changed();
    }

    public void removePointAt(int i) {
        willChange();
        fPoints.removeElementAt(i);
        changed();
    }

    /**
     * Splits the segment at the given point if a segment was hit.
     * @return the index of the segment or -1 if no segment was hit.
     */
    public int splitSegment(int x, int y) {
        int i = findSegment(x, y);
        if (i != -1)
            insertPointAt(new Point(x, y), i+1);
        return i+1;
    }

    public Point pointAt(int i) {
        return (Point)fPoints.elementAt(i);
    }

    /**
     * Joins to segments into one if the given point hits a node
     * of the polyline.
     * @return true if the two segments were joined.
     */
    public boolean joinSegments(int x, int y) {
        for (int i= 1; i < fPoints.size()-1; i++) {
            Point p = pointAt(i);
            if (Geom.length(x, y, p.x, p.y) < 3) {
                removePointAt(i);
                return true;
            }
        }
        return false;
    }

    public Connector connectorAt(int x, int y) {
        return new PolyLineConnector(this);
    }

    /**
     * Sets the start decoration.
     */
    public void setStartDecoration(LineDecoration l) {
        fStartDecoration = l;
    }

    /**
     * Sets the end decoration.
     */
    public void setEndDecoration(LineDecoration l) {
        fEndDecoration = l;
    }

    public void draw(Graphics g, boolean showGuides) {
        g.setColor(getFrameColor());
        Point p1, p2;
        for (int i = 0; i < fPoints.size()-1; i++) {
            p1 = (Point) fPoints.elementAt(i);
            p2 = (Point) fPoints.elementAt(i+1);
            g.drawLine(p1.x, p1.y, p2.x, p2.y);
        }
        decorate(g);
	if (showGuides) {
	    drawURL(g);
	}
    }

    private void drawURL(Graphics g) {
	String sensitive = (String)getAttribute("Sensitive");
	if (sensitive == null || sensitive.length() == 0)
	    return;
	int i;
	if (fPoints.size() < 3)
	    i = 0;
	else
	    i =  fPoints.size() / 2 - 1;
	Point p1, p2;

	if ((fPoints.size() & 1) == 1) {
	    p2 = p1 = (Point) fPoints.elementAt(i+1);
	} else {
	    p1 = (Point) fPoints.elementAt(i);
	    p2 = (Point) fPoints.elementAt(i+1);
	}
	g.setColor(Color.red);
	g.setFont(dialogFont);
	g.drawString("url=" + sensitive, (p1.x + p2.x) / 2,
		     (p1.y + p2.y) / 2);
    }

    public boolean containsPoint(int x, int y) {
        Rectangle bounds = displayBox();
        bounds.grow(4,4);
        if (!bounds.contains(x, y))
            return false;

        Point p1, p2;
        for (int i = 0; i < fPoints.size()-1; i++) {
            p1 = (Point) fPoints.elementAt(i);
            p2 = (Point) fPoints.elementAt(i+1);
            if (Geom.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, x, y))
                return true;
        }
        return false;
    }

    /**
     * Gets the segment of the polyline that is hit by
     * the given point.
     * @return the index of the segment or -1 if no segment was hit.
     */
    public int findSegment(int x, int y) {
        Point p1, p2;
        for (int i = 0; i < fPoints.size()-1; i++) {
            p1 = (Point) fPoints.elementAt(i);
            p2 = (Point) fPoints.elementAt(i+1);
            if (Geom.lineContainsPoint(p1.x, p1.y, p2.x, p2.y, x, y))
                return i;
        }
        return -1;
    }

    private void decorate(Graphics g) {
        if (fStartDecoration != null) {
            Point p1 = (Point)fPoints.elementAt(0);
            Point p2 = (Point)fPoints.elementAt(1);
            fStartDecoration.draw(g, p1.x, p1.y, p2.x, p2.y);
        }
        if (fEndDecoration != null) {
            Point p3 = (Point)fPoints.elementAt(fPoints.size()-2);
            Point p4 = (Point)fPoints.elementAt(fPoints.size()-1);
            fEndDecoration.draw(g, p4.x, p4.y, p3.x, p3.y);
        }
    }

    /**
     * Gets the attribute with the given name.
     * PolyLineFigure maps "ArrowMode"to a
     * line decoration.
     */
    public Object getAttribute(String name) {
        if (name.equals("FrameColor")) {
            return getFrameColor();
        } else if (name.equals("ArrowMode")) {
            int value = 0;
            if (fStartDecoration != null)
                value |= ARROW_TIP_START;
            if (fEndDecoration != null)
                value |= ARROW_TIP_END;
            return new Integer(value);
	}
        return super.getAttribute(name);
    }

    /**
     * Sets the attribute with the given name.
     * PolyLineFigure interprets "ArrowMode"to set
     * the line decoration.
     */
    public void setAttribute(String name, Object value) {
        if (name.equals("FrameColor")) {
            setFrameColor((Color)value);
            changed();
        } else if (name.equals("ArrowMode")) {
            Integer intObj = (Integer) value;
            if (intObj != null) {
                int decoration = intObj.intValue();
                if ((decoration & ARROW_TIP_START) != 0)
                    fStartDecoration = new ArrowTip();
                else
                    fStartDecoration = null;
                if ((decoration & ARROW_TIP_END) != 0)
                    fEndDecoration = new ArrowTip();
                else
                    fEndDecoration = null;
            }
            changed();
	} else {
            super.setAttribute(name, value);
	    changed();
	}
    }

    public void write(StorableOutput dw) {
        super.write(dw);
        dw.writeInt(fPoints.size());
        Enumeration k = fPoints.elements();
        while (k.hasMoreElements()) {
            Point p = (Point) k.nextElement();
            dw.writeInt(p.x);
            dw.writeInt(p.y);
        }
        dw.writeStorable(fStartDecoration);
        dw.writeStorable(fEndDecoration);
        dw.writeColor(fFrameColor);
    }

    public String getMap() {
	String sensitive = (String)getAttribute("Sensitive");
	if (sensitive == null || sensitive.length() == 0)
	    return "";
	try {
		sensitive = URLDecoder.decode(sensitive);
	} catch (Exception e) {}
	Enumeration k = fPoints.elements();
	boolean first  = true;
	String forwards = "", backwards = "";
        for (int i = 1; i < fPoints.size(); i++) {
            Point p1 = (Point)fPoints.elementAt(i-1);
            Point p2 = (Point)fPoints.elementAt(i);
	    double l = Math.sqrt((p2.x-p1.x) * (p2.x-p1.x) +
				 (p2.y-p1.y) * (p2.y-p1.y));
	    int x = (int)(4 * (p2.y-p1.y) / l);
	    int y = (int)(4 * (p2.x-p1.x) / l);
	    if (!first) {
		forwards += ",";
		backwards = "," + backwards;
	    }
	    first = false;
	    forwards += (p1.x + x) + "," + (p1.y + y) + "," +
		(p2.x + x) + "," + (p2.y + y);
	    backwards = (p2.x - x) + "," + (p2.y - y) + "," +
		(p1.x - x) + "," + (p1.y - y) + backwards;
        }
	return "<area shape=\"poly\" coords=\"" +
	    forwards + "," + backwards + "\" href=\"" +
	    sensitive + "\" />\n";
    }

    public void read(StorableInput dr) throws IOException {
	// test for the next token being a number to allow us to
	// skip attribute reading which. Old-format files don't
	// have attributes on connections.
	super.read(dr);
        int size = dr.readInt();
	if (size == -1) {
	    // Temp for files created during devt. Remove when we're sure
	    // they are all gone
	    String s = dr.readString();
	    setAttribute("Sensitive", s);
	    size = dr.readInt();
	}
        fPoints = new Vector(size);
        for (int i=0; i<size; i++) {
            int x = dr.readInt();
            int y = dr.readInt();
            fPoints.addElement(new Point(x,y));
        }
        fStartDecoration = (LineDecoration)dr.readStorable();
        fEndDecoration = (LineDecoration)dr.readStorable();
        fFrameColor = dr.readColor();
    }

    /**
     * Creates a locator for the point with the given index.
     */
    public static Locator locator(int pointIndex) {
        return new PolyLineLocator(pointIndex);
    }

    protected Color getFrameColor() {
        return fFrameColor;
    }

    protected void setFrameColor(Color c) {
        fFrameColor = c;
    }
}


text:
'use strict';

var _babelTypes = require('babel-types');

var t = _interopRequireWildcard(_babelTypes);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

function isRequire(node) {
  return t.isCallExpression(node) && node.arguments[0] && (node.arguments[0].value === 'react' || node.arguments[0].value === 'react/addons');
}

var isCorrectImport = function isCorrectImport(node) {
  return t.isImportDeclaration(node) && (node.source.value === 'react' || node.source.value === 'react/addons');
};

function isImport(node, scope) {
  if (t.isImportSpecifier(node) || t.isImportDefaultSpecifier(node)) {
    var binding = scope.getBinding(node.local.name);
    node = binding.path.parent;
  }

  return isCorrectImport(node);
}

function isGlobal(node) {
  return t.isMemberExpression(node) && (node.object.name === 'window' || node.object.name === 'global') && node.property.name === 'React';
}

module.exports = function (node, scope) {
  return isRequire(node, scope) || isImport(node, scope) || isGlobal(node, scope);
};


text:
/**
 *
 *
 */
define(['lodash', 'eventemitter2'], function (_, EventEmitter2) {

    var ee = new EventEmitter2({
        wildcard: true, // should the event emitter use wildcards.
        delimiter: ':', // the delimiter used to segment namespaces, defaults to `.`.
        newListener: false, // if you want to emit the newListener event set to true.
        maxListeners: 10 // the max number of listeners that can be assigned to an event, defaults to 10.
    });

    /**
     * @class MuskepeerModule
     * @constructor
     */
    function Module() {
        var self = this;
        this.extend = function (obj) {
            return _.extend(self, obj);
        };
        this.emit = ee.emit;
        this.on = ee.on;
        this.off = ee.off;
        this.onAny = ee.onAny;
        this.offAny = ee.offAny;
        this.removeAllListeners = ee.removeAllListeners;
    }

    return Module;

});