ST Expansion SW Team / eeprom_driver

Dependents:   mbed-os-example-nfc-EEPROM

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers st25dv.cpp Source File

st25dv.cpp

00001 /**
00002   ******************************************************************************
00003   * @file    st25dv.c 
00004   * @author  MMY Application Team
00005   * @version $Revision: 3308 $
00006   * @date    $Date: 2017-01-13 11:19:33 +0100 (Fri, 13 Jan 2017) $
00007   * @brief   This file provides set of driver functions to manage communication 
00008   *          between BSP and ST25DV chip.
00009   ******************************************************************************
00010   * @attention
00011   *
00012   * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
00013   *
00014   * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
00015   * You may not use this file except in compliance with the License.
00016   * You may obtain a copy of the License at:
00017   *
00018   *        http://www.st.com/myliberty  
00019   *
00020   * Unless required by applicable law or agreed to in writing, software 
00021   * distributed under the License is distributed on an "AS IS" BASIS, 
00022   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
00023   * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
00024   * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00025   * See the License for the specific language governing permissions and
00026   * limitations under the License.
00027   *
00028   ******************************************************************************
00029   */ 
00030 
00031 /* Includes ------------------------------------------------------------------*/
00032 #include "st25dv.h"
00033 
00034 #include "st25dv_driver.h"
00035 
00036 
00037 
00038 
00039 /** @addtogroup BSP
00040   * @{
00041   */
00042 
00043 /** @defgroup ST25DV ST25DV driver
00044   * @brief    This module implements the functions to drive the ST25DV NFC dynamic tag.
00045   * @details  As recommended by the STM32 Cube methodology, this driver provides a standard structure to expose the NFC tag standard API.\n
00046   *           It also provides an extended API through its extended driver structure.\n
00047   *           To be usable on any MCU, this driver calls several IOBus functions.
00048   *           The IOBus functions are implemented outside this driver, and are in charge of accessing the MCU peripherals used for the communication with the tag.
00049   * @{
00050   */
00051 
00052 /* External variables --------------------------------------------------------*/
00053 /* Private typedef -----------------------------------------------------------*/
00054 /* Private defines -----------------------------------------------------------*/
00055 /** @brief This component driver only supports 1 instance of the component */
00056 #define ST25DV_MAX_INSTANCE         1
00057 
00058   
00059 /* Private macros ------------------------------------------------------------*/
00060 /* Private function prototypes -----------------------------------------------*/
00061 NFCTAG_StatusTypeDef ST25DV_i2c_Init( I2C * mi2cChannel, DigitalOut* mLPD );
00062 NFCTAG_StatusTypeDef ST25DV_i2c_ReadID( uint8_t * const pICRef, I2C * mi2cChannel );
00063 NFCTAG_StatusTypeDef ST25DV_i2c_ReadICRev( uint8_t * const pICRev, I2C * mi2cChannel );
00064 NFCTAG_StatusTypeDef ST25DV_i2c_IsDeviceReady( const uint32_t Trials, I2C * mi2cChannel);
00065 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPOStatus( uint16_t * const pGPOStatus, I2C * mi2cChannel );
00066 NFCTAG_StatusTypeDef ST25DV_i2c_ConfigureGPO( const uint16_t ITConf, I2C * mi2cChannel );
00067 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITPulse( ST25DV_PULSE_DURATION * const pITtime, I2C * mi2cChannel);
00068 NFCTAG_StatusTypeDef ST25DV_i2c_WriteITPulse( const ST25DV_PULSE_DURATION ITtime, I2C * mi2cChannel );
00069 NFCTAG_StatusTypeDef ST25DV_i2c_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
00070 NFCTAG_StatusTypeDef ST25DV_i2c_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
00071 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDataCurrentAddr( uint8_t * const pData, const uint16_t NbByte, I2C * mi2cChannel );
00072 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte , I2C * mi2cChannel);
00073 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
00074 NFCTAG_StatusTypeDef ST25DV_i2c_ReadUID( ST25DV_UID * const pUid, I2C * mi2cChannel);
00075 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDSFID( uint8_t * const pDsfid, I2C * mi2cChannel );
00076 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDsfidRFProtection( ST25DV_LOCK_STATUS * const pLockDsfid, I2C * mi2cChannel );
00077 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAFI( uint8_t * const pAfi, I2C * mi2cChannel );
00078 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAfiRFProtection( ST25DV_LOCK_STATUS * const pLockAfi, I2C * mi2cChannel );
00079 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CProtectZone( ST25DV_I2C_PROT_ZONE * const pProtZone, I2C * mi2cChannel );
00080 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CProtectZonex( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_PROTECTION_CONF ReadWriteProtection, I2C * mi2cChannel );
00081 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCCFile( ST25DV_LOCK_CCFILE * const pLockCCFile, I2C * mi2cChannel );
00082 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCCFile( const ST25DV_CCFILE_BLOCK NbBlockCCFile, const ST25DV_LOCK_STATUS LockCCFile, I2C * mi2cChannel );
00083 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCFG( ST25DV_LOCK_STATUS * const pLockCfg, I2C * mi2cChannel );
00084 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCFG( const ST25DV_LOCK_STATUS LockCfg, I2C * mi2cChannel );
00085 NFCTAG_StatusTypeDef ST25DV_i2c_PresentI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel );
00086 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel );
00087 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFZxSS( const ST25DV_PROTECTION_ZONE Zone, ST25DV_RF_PROT_ZONE * const pRfprotZone, I2C * mi2cChannel );
00088 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFZxSS( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_RF_PROT_ZONE RfProtZone , I2C * mi2cChannel);
00089 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEndZonex( const ST25DV_END_ZONE EndZone, uint8_t * const pEndZ, I2C * mi2cChannel );
00090 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEndZonex( const ST25DV_END_ZONE EndZone, const uint8_t EndZ, I2C * mi2cChannel );
00091 NFCTAG_StatusTypeDef ST25DV_i2c_InitEndZone( I2C * mi2cChannel );
00092 NFCTAG_StatusTypeDef ST25DV_i2c_CreateUserZone( uint16_t Zone1Length, uint16_t Zone2Length, uint16_t Zone3Length, uint16_t Zone4Length, I2C * mi2cChannel );
00093 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMemSize( ST25DV_MEM_SIZE * const pSizeInfo, I2C * mi2cChannel );
00094 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHMode( ST25DV_EH_MODE_STATUS * const pEH_mode, I2C * mi2cChannel );
00095 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEHMode( const ST25DV_EH_MODE_STATUS EH_mode, I2C * mi2cChannel );
00096 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel );
00097 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt( const uint8_t Rfmngt, I2C * mi2cChannel );
00098 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel );
00099 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable( I2C * mi2cChannel );
00100 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable( I2C * mi2cChannel );
00101 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel );
00102 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep( I2C * mi2cChannel );
00103 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep( I2C * mi2cChannel );
00104 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBMode( ST25DV_EN_STATUS * const pMB_mode, I2C * mi2cChannel );
00105 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBMode( const ST25DV_EN_STATUS MB_mode, I2C * mi2cChannel );
00106 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBWDG( uint8_t * const pWdgDela, I2C * mi2cChannely );
00107 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBWDG( const uint8_t WdgDelay, I2C * mi2cChannel );
00108 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
00109 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxData( const uint8_t * const pData, const uint16_t NbByte, I2C * mi2cChannel );
00110 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
00111 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel );
00112 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CSecuritySession_Dyn( ST25DV_I2CSSO_STATUS * const pSession, I2C * mi2cChannel );
00113 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITSTStatus_Dyn( uint8_t * const pITStatus, I2C * mi2cChannel );
00114 NFCTAG_StatusTypeDef ST25DV_i2c_ReadGPO_Dyn( uint8_t *GPOConfig, I2C * mi2cChannel );
00115 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPO_en_Dyn( ST25DV_EN_STATUS * const pGPO_en, I2C * mi2cChannel );
00116 NFCTAG_StatusTypeDef ST25DV_i2c_SetGPO_en_Dyn( I2C * mi2cChannel );
00117 NFCTAG_StatusTypeDef ST25DV_i2c_ResetGPO_en_Dyn( I2C * mi2cChannel );
00118 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHCtrl_Dyn( ST25DV_EH_CTRL * const pEH_CTRL, I2C * mi2cChannel );
00119 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHENMode_Dyn( ST25DV_EN_STATUS * const pEH_Val, I2C * mi2cChannel );
00120 NFCTAG_StatusTypeDef ST25DV_i2c_SetEHENMode_Dyn( I2C * mi2cChannel );
00121 NFCTAG_StatusTypeDef ST25DV_i2c_ResetEHENMode_Dyn( I2C * mi2cChannel );
00122 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHON_Dyn( ST25DV_EN_STATUS * const pEHON, I2C * mi2cChannel );
00123 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFField_Dyn( ST25DV_FIELD_STATUS * const pRF_Field, I2C * mi2cChannel );
00124 NFCTAG_StatusTypeDef ST25DV_i2c_GetVCC_Dyn( ST25DV_VCC_STATUS * const pVCC, I2C * mi2cChannel );
00125 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt_Dyn( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel );
00126 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt_Dyn( const uint8_t RF_Mngt, I2C * mi2cChannel );
00127 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable_Dyn( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel );
00128 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable_Dyn( I2C * mi2cChannel );
00129 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable_Dyn( I2C * mi2cChannel );
00130 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep_Dyn( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel );
00131 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep_Dyn( I2C * mi2cChannel );
00132 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep_Dyn( I2C * mi2cChannel );
00133 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBCtrl_Dyn( ST25DV_MB_CTRL_DYN_STATUS * const pCtrlStatus, I2C * mi2cChannel );
00134 NFCTAG_StatusTypeDef ST25DV_i2c_GetMBEN_Dyn( ST25DV_EN_STATUS * const pMBEN, I2C * mi2cChannel);
00135 NFCTAG_StatusTypeDef ST25DV_i2c_SetMBEN_Dyn( I2C * mi2cChannel );
00136 NFCTAG_StatusTypeDef ST25DV_i2c_ResetMBEN_Dyn( I2C * mi2cChannel );
00137 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBLength_Dyn( uint8_t * const pMBLength, I2C * mi2cChannel );
00138 
00139 /* Global variables ---------------------------------------------------------*/
00140 /**
00141   * @brief    Standard NFC tag driver API for the ST25DV.
00142   * @details  Provides a generic way to access the ST25DV implementation of the NFC tag standard driver functions. 
00143   */
00144 NFCTAG_DrvTypeDef St25Dv_i2c_Drv =
00145 {
00146   ST25DV_i2c_Init,
00147   ST25DV_i2c_ReadID,
00148   ST25DV_i2c_IsDeviceReady,
00149   ST25DV_i2c_GetGPOStatus,
00150   ST25DV_i2c_ConfigureGPO,
00151   ST25DV_i2c_ReadData,
00152   ST25DV_i2c_WriteData,
00153   ST25DV_i2c_ReadRegister,
00154   ST25DV_i2c_WriteRegister,
00155   NULL
00156 };
00157 
00158 /**
00159   * @brief    Extended NFC tag driver API for the ST25DV.
00160   * @details  Provides a generic way to access the ST25DV extended driver functions. 
00161   */
00162 NFCTAG_ExtDrvTypeDef St25Dv_i2c_ExtDrv =
00163 {
00164   ST25DV_i2c_ReadICRev,
00165   ST25DV_i2c_WriteITPulse,
00166   ST25DV_i2c_ReadITPulse,
00167   ST25DV_i2c_ReadDataCurrentAddr,
00168   ST25DV_i2c_ReadUID,
00169   ST25DV_i2c_ReadDSFID,
00170   ST25DV_i2c_ReadDsfidRFProtection,
00171   ST25DV_i2c_ReadAFI,
00172   ST25DV_i2c_ReadAfiRFProtection,
00173   ST25DV_i2c_ReadI2CProtectZone,
00174   ST25DV_i2c_WriteI2CProtectZonex,
00175   ST25DV_i2c_ReadLockCCFile,
00176   ST25DV_i2c_WriteLockCCFile,
00177   ST25DV_i2c_ReadLockCFG,
00178   ST25DV_i2c_WriteLockCFG,
00179   ST25DV_i2c_PresentI2CPassword,
00180   ST25DV_i2c_WriteI2CPassword,
00181   ST25DV_i2c_ReadRFZxSS,
00182   ST25DV_i2c_WriteRFZxSS,
00183   ST25DV_i2c_ReadEndZonex,
00184   ST25DV_i2c_WriteEndZonex,
00185   ST25DV_i2c_InitEndZone,
00186   ST25DV_i2c_CreateUserZone,
00187   ST25DV_i2c_ReadMemSize,
00188   ST25DV_i2c_ReadEHMode,
00189   ST25DV_i2c_WriteEHMode,
00190   ST25DV_i2c_ReadRFMngt,
00191   ST25DV_i2c_WriteRFMngt,
00192   ST25DV_i2c_GetRFDisable,
00193   ST25DV_i2c_SetRFDisable,
00194   ST25DV_i2c_ResetRFDisable,
00195   ST25DV_i2c_GetRFSleep,
00196   ST25DV_i2c_SetRFSleep,
00197   ST25DV_i2c_ResetRFSleep,
00198   ST25DV_i2c_ReadMBMode,
00199   ST25DV_i2c_WriteMBMode,
00200   ST25DV_i2c_ReadMBWDG,
00201   ST25DV_i2c_WriteMBWDG,
00202   ST25DV_i2c_ReadMailboxData,
00203   ST25DV_i2c_WriteMailboxData,
00204   ST25DV_i2c_ReadMailboxRegister,
00205   ST25DV_i2c_WriteMailboxRegister,
00206   ST25DV_i2c_ReadI2CSecuritySession_Dyn,
00207   ST25DV_i2c_ReadITSTStatus_Dyn,
00208   ST25DV_i2c_ReadGPO_Dyn,
00209   ST25DV_i2c_GetGPO_en_Dyn,
00210   ST25DV_i2c_SetGPO_en_Dyn,
00211   ST25DV_i2c_ResetGPO_en_Dyn,
00212   ST25DV_i2c_ReadEHCtrl_Dyn,
00213   ST25DV_i2c_GetEHENMode_Dyn,
00214   ST25DV_i2c_SetEHENMode_Dyn,
00215   ST25DV_i2c_ResetEHENMode_Dyn,
00216   ST25DV_i2c_GetEHON_Dyn,
00217   ST25DV_i2c_GetRFField_Dyn,
00218   ST25DV_i2c_GetVCC_Dyn,
00219   ST25DV_i2c_ReadRFMngt_Dyn,
00220   ST25DV_i2c_WriteRFMngt_Dyn,
00221   ST25DV_i2c_GetRFDisable_Dyn,
00222   ST25DV_i2c_SetRFDisable_Dyn,
00223   ST25DV_i2c_ResetRFDisable_Dyn,
00224   ST25DV_i2c_GetRFSleep_Dyn,
00225   ST25DV_i2c_SetRFSleep_Dyn,
00226   ST25DV_i2c_ResetRFSleep_Dyn,
00227   ST25DV_i2c_ReadMBCtrl_Dyn,
00228   ST25DV_i2c_GetMBEN_Dyn,
00229   ST25DV_i2c_SetMBEN_Dyn,
00230   ST25DV_i2c_ResetMBEN_Dyn,
00231   ST25DV_i2c_ReadMBLength_Dyn
00232 };
00233 
00234 
00235 /** @brief ST25DV instances by address. */
00236 uint8_t aSt25Dv[ST25DV_MAX_INSTANCE] = {0};
00237 
00238 
00239 /* Public functions ---------------------------------------------------------*/
00240 /**
00241   * @brief  ST25DV nfctag Initialization.
00242   * @param mi2cChannel : I2C channel
00243   * @return NFCTAG_StatusTypeDef enum status.
00244   */
00245 NFCTAG_StatusTypeDef ST25DV_i2c_Init( I2C* mi2cChannel, DigitalOut * mLPD )
00246 {
00247   /* Configure the low level interface */
00248   return ST25DV_IO_Init( mi2cChannel, mLPD );
00249 }
00250 
00251 /**
00252   * @brief  Reads the ST25DV ID.
00253   * @param  pICRef Pointeron a uint8_t used to return the ST25DV ID.
00254   * @param mi2cChannel : I2C channel
00255   * @return NFCTAG_StatusTypeDef enum status.
00256   */
00257 NFCTAG_StatusTypeDef ST25DV_i2c_ReadID( uint8_t * const pICRef, I2C * mi2cChannel )
00258 {
00259   /* Read ICRef on device */
00260   return ST25DV_i2c_ReadRegister( pICRef, ST25DV_ICREF_REG, 1, mi2cChannel );
00261 }
00262 
00263 /**
00264   * @brief  Reads the ST25DV IC Revision.
00265   * @param  pICRev Pointer on the uint8_t used to return the ST25DV IC Revision number.
00266   * @param mi2cChannel : I2C channel
00267   * @return NFCTAG_StatusTypeDef enum status.
00268   */
00269 NFCTAG_StatusTypeDef ST25DV_i2c_ReadICRev( uint8_t * const pICRev, I2C * mi2cChannel )
00270 {
00271   /* Read ICRev on device */
00272   return ST25DV_i2c_ReadRegister( pICRev, ST25DV_ICREV_REG, 1, mi2cChannel );
00273 }
00274 
00275 /**
00276   * @brief    Checks the ST25DV availability.
00277   * @details  The ST25DV I2C is NACKed when a RF communication is on-going.
00278   *           This function determines if the ST25DV is ready to answer an I2C request. 
00279   * @param    Trials Max number of tentative.
00280   * @param mi2cChannel : I2C channel
00281   * @retval   NFCTAG_StatusTypeDef enum status.
00282   */
00283 NFCTAG_StatusTypeDef ST25DV_i2c_IsDeviceReady( const uint32_t Trials, I2C * mi2cChannel)
00284 {
00285   /* Test communication with device */
00286   return ST25DV_IO_IsDeviceReady( ST25DV_ADDR_DATA_I2C, Trials, mi2cChannel);
00287 }
00288 
00289 /**
00290   * @brief  Reads the ST25DV GPO configuration.
00291   * @param  pGPOStatus  Pointer on a uint16_t used to return the current GPO consiguration, as:
00292   *                     - RFUSERSTATE = 0x01
00293   *                     - RFBUSY = 0x02
00294   *                     - RFINTERRUPT = 0x04
00295   *                     - FIELDFALLING = 0x08
00296   *                     - FIELDRISING = 0x10
00297   *                     - RFPUTMSG = 0x20
00298   *                     - RFGETMSG = 0x40
00299   *                     - RFWRITE = 0x80
00300   * @param mi2cChannel : I2C channel
00301   * @retval   NFCTAG_StatusTypeDef enum status.
00302   */
00303 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPOStatus( uint16_t * const pGPOStatus, I2C * mi2cChannel )
00304 {
00305   uint8_t reg_value;
00306   NFCTAG_StatusTypeDef status;
00307   
00308   /* Read value of GPO register */
00309   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_GPO_REG, 1, mi2cChannel );
00310   if( status != NFCTAG_OK )
00311     return status;
00312 
00313   /* Extract GPO configuration */
00314   *pGPOStatus = (uint16_t)reg_value;
00315   
00316   return NFCTAG_OK;
00317 }
00318 
00319 /**
00320   * @brief    Configures the ST25DV GPO.
00321   * @details  Needs the I2C Password presentation to be effective.
00322   * @param    ITConf Provides the GPO configuration to apply:
00323   *           - RFUSERSTATE = 0x01
00324   *           - RFBUSY = 0x02
00325   *           - RFINTERRUPT = 0x04
00326   *           - FIELDFALLING = 0x08
00327   *           - FIELDRISING = 0x10
00328   *           - RFPUTMSG = 0x20
00329   *           - RFGETMSG = 0x40
00330   *           - RFWRITE = 0x80
00331   *
00332   * @param mi2cChannel : I2C channel
00333   *
00334   * @retval   NFCTAG_StatusTypeDef enum status.
00335   */
00336 NFCTAG_StatusTypeDef ST25DV_i2c_ConfigureGPO( const uint16_t ITConf, I2C * mi2cChannel )
00337 {
00338   /* Write GPO configuration to register */
00339   return ST25DV_i2c_WriteRegister( (uint8_t *)&ITConf, ST25DV_GPO_REG, 1, mi2cChannel );
00340 }
00341 
00342 
00343 /**
00344   * @brief  Reads the ST25DV ITtime duration for the GPO pulses.
00345   * @param  pITtime Pointer used to return the coefficient for the GPO Pulse duration (Pulse duration = 302,06 us - ITtime * 512 / fc).
00346   * @param  mi2cChannel  I2C channel
00347   * @return NFCTAG_StatusTypeDef enum status.
00348   */
00349 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITPulse( ST25DV_PULSE_DURATION * const pITtime, I2C * mi2cChannel )
00350 {
00351   uint8_t reg_value;
00352   NFCTAG_StatusTypeDef status;
00353   
00354   /* Read ITtime register value */
00355   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_ITTIME_REG, 1,  mi2cChannel );
00356   if( status != NFCTAG_OK )
00357   {
00358     return status;
00359   }
00360   
00361   /* Extract delay coefficient value */
00362   *pITtime = (ST25DV_PULSE_DURATION)reg_value;
00363   
00364   return NFCTAG_OK;
00365 }
00366 
00367 /**
00368   * @brief    Configures the ST25DV ITtime duration for the GPO pulse.
00369   * @details  Needs the I2C Password presentation to be effective.
00370   * @param    ITtime Coefficient for the Pulse duration to be written (Pulse duration = 302,06 us - ITtime * 512 / fc)
00371   * @param    mi2cChannel  I2C channel
00372   * @retval   NFCTAG_StatusTypeDef enum status.
00373   */
00374 NFCTAG_StatusTypeDef ST25DV_i2c_WriteITPulse( const ST25DV_PULSE_DURATION ITtime, I2C * mi2cChannel )
00375 {
00376   uint8_t reg_value;
00377   
00378   /* prepare data to write */
00379   reg_value = (uint8_t)ITtime;
00380   
00381   /* Write value for ITtime register */
00382   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_ITTIME_REG, 1, mi2cChannel );
00383 }
00384 
00385 /**
00386   * @brief  Reads N bytes of Data, starting from the specified I2C address.
00387   * @param  pData   Pointer used to return the read data.
00388   * @param  TarAddr I2C data memory address to read.
00389   * @param  NbByte  Number of bytes to be read.
00390   * @param  mi2cChannel I2C channel
00391   * @return NFCTAG_StatusTypeDef enum status.
00392   */
00393 NFCTAG_StatusTypeDef ST25DV_i2c_ReadData( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel)
00394 {
00395   /* Read Data in user memory */
00396   return ST25DV_IO_MemRead( pData, ST25DV_ADDR_DATA_I2C, TarAddr, NbByte, mi2cChannel );
00397 }
00398 
00399 /**
00400   * @brief  Writes N bytes of Data starting from the specified I2C Address.
00401   * @param  pData   Pointer on the data to be written.
00402   * @param  TarAddr I2C data memory address to be written.
00403   * @param  NbByte  Number of bytes to be written.
00404   * @param mi2cChannel I2C channel
00405   * @return NFCTAG_StatusTypeDef enum status.
00406   */
00407 NFCTAG_StatusTypeDef ST25DV_i2c_WriteData( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C* mi2cChannel )
00408 { 
00409   NFCTAG_StatusTypeDef ret;
00410   NFCTAG_StatusTypeDef pollstatus;
00411   uint16_t split_data_nb;
00412   const uint8_t *pdata_index = (const uint8_t *)pData;
00413 
00414   uint16_t bytes_to_write = NbByte;
00415   uint16_t mem_addr = TarAddr;
00416   
00417   /* ST25DV can write a maximum of 256 bytes in EEPROM per i2c communication */
00418   do
00419   {
00420     /* Split write if data to write is superior of max write bytes for ST25DV */
00421     if( bytes_to_write > ST25DV_MAX_WRITE_BYTE )
00422     {
00423       /* DataSize higher than max page write, copy data by page */
00424       split_data_nb = (uint16_t)ST25DV_MAX_WRITE_BYTE;
00425     }
00426     else
00427     {
00428       /* DataSize lower or equal to max page write, copy only last bytes */
00429       split_data_nb = bytes_to_write;
00430     }
00431     /* Write split_data_nb bytes in memory */
00432     ret = ST25DV_IO_MemWrite( pdata_index, ST25DV_ADDR_DATA_I2C, mem_addr, split_data_nb, mi2cChannel);
00433 
00434     Timer t;
00435     /* POLLING, NEW CODE */
00436     if( ret == 0 )
00437     {
00438       /* Poll until EEPROM is available */
00439 
00440       int ms = 0;
00441       /* Wait until ST25DV is ready or timeout occurs */
00442       do
00443       {
00444         t.start();
00445         pollstatus = ST25DV_IO_IsDeviceReady( ST25DV_ADDR_DATA_I2C , 1, mi2cChannel);
00446         ms = t.read_ms();
00447         t.stop();
00448       } while( ( ms  < ST25DV_I2C_TIMEOUT) && (pollstatus != NFCTAG_OK) );
00449 
00450 
00451       if( pollstatus != NFCTAG_OK )
00452       {
00453         return NFCTAG_TIMEOUT;
00454       }
00455     }
00456 
00457     /* update index, dest address, size for next write */
00458     pdata_index += split_data_nb;
00459     mem_addr += split_data_nb;
00460     bytes_to_write -= split_data_nb;
00461   }
00462   while( ( bytes_to_write > 0 ) && ( ret == NFCTAG_OK ) );
00463   
00464   return ret;
00465 }
00466 
00467 /**
00468   * @brief  Reads N bytes of Data, starting at current address.
00469   * @param  pData   Pointer used to return the read data.
00470   * @param  NbByte  Number of bytes to be read.
00471   * @param mi2cChannel : I2C channel
00472   * @return NFCTAG_StatusTypeDef enum status.
00473   */
00474 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDataCurrentAddr( uint8_t * const pData, const uint16_t NbByte, I2C* mi2cChannel )
00475 {
00476   /* Read Data in user memory */
00477   return ST25DV_IO_Read( pData, ST25DV_ADDR_DATA_I2C, NbByte, mi2cChannel );
00478 }
00479 
00480 /**
00481   * @brief  Reads N bytes from Registers, starting at the specified I2C address.
00482   * @param  pData   Pointer used to return the read data.
00483   * @param  TarAddr I2C memory address to be read.
00484   * @param  NbByte  Number of bytes to be read.
00485   * @param  mi2cChannel I2C channel
00486   * @return NFCTAG_StatusTypeDef enum status.
00487   */
00488 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
00489 {  
00490   /* Read Data in system memory */
00491   return ST25DV_IO_MemRead( pData, ST25DV_ADDR_SYST_I2C, TarAddr, NbByte, mi2cChannel );
00492 }
00493 
00494 /**
00495   * @brief    Writes N bytes to the specified register.
00496   * @details  Needs the I2C Password presentation to be effective.
00497   * @param    pData   Pointer on the data to be written.
00498   * @param    TarAddr I2C register address to written.
00499   * @param    NbByte  Number of bytes to be written.
00500   * @param    mi2cChannel I2C channel
00501   * @return   NFCTAG_StatusTypeDef enum status.
00502   */
00503 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
00504 { 
00505   NFCTAG_StatusTypeDef ret;
00506   NFCTAG_StatusTypeDef pollstatus;
00507   uint8_t split_data_nb;
00508   uint16_t bytes_to_write = NbByte;
00509   uint16_t mem_addr = TarAddr;
00510   const uint8_t *pdata_index = (const uint8_t *)pData;
00511   
00512   /* ST25DV can write a maximum of 256 bytes in EEPROM per i2c communication */
00513   do
00514   {
00515     /* Split write if data to write is superior of max write bytes for ST25DV */
00516     if( bytes_to_write > ST25DV_MAX_WRITE_BYTE )
00517     {
00518       /* DataSize higher than max page write, copy data by page */
00519       split_data_nb = (uint8_t)ST25DV_MAX_WRITE_BYTE;
00520     }
00521     else
00522     {
00523       /* DataSize lower or equal to max page write, copy only last bytes */
00524       split_data_nb = bytes_to_write;
00525     }
00526     /* Write split_data_nb bytes in register */
00527     ret = ST25DV_IO_MemWrite( pdata_index, ST25DV_ADDR_SYST_I2C, mem_addr, split_data_nb, mi2cChannel);
00528 
00529     Timer t;
00530     /* POLLING, NEW CODE */
00531     if( ret == 0 )
00532     {
00533         int ms = 0;
00534          /* Wait until ST25DV is ready or timeout occurs */
00535          do
00536          {
00537            t.start();
00538            pollstatus = ST25DV_IO_IsDeviceReady( ST25DV_ADDR_DATA_I2C , 1, mi2cChannel);
00539            ms = t.read_ms();
00540            t.stop();
00541          } while( ( ms  < ST25DV_I2C_TIMEOUT) && (pollstatus != NFCTAG_OK) );
00542 
00543       if( pollstatus != NFCTAG_OK )
00544       {
00545         return NFCTAG_TIMEOUT;
00546       }
00547     }
00548 
00549 
00550     /* update index, dest address, size for next write */
00551     pdata_index += split_data_nb;
00552     mem_addr += split_data_nb;
00553     bytes_to_write -= split_data_nb;
00554   }
00555   while( ( bytes_to_write > 0 ) && ( ret == NFCTAG_OK ) );
00556   
00557 
00558 
00559   return ret;
00560 }
00561 
00562 /**
00563   * @brief  Reads the ST25DV UID.
00564   * @param  pUid Pointer used to return the ST25DV UID value.
00565   * @param  mi2cChannel I2C channel
00566   * @return NFCTAG_StatusTypeDef enum status.
00567   */
00568 NFCTAG_StatusTypeDef ST25DV_i2c_ReadUID( ST25DV_UID * const pUid, I2C * mi2cChannel )
00569 {
00570   uint8_t reg_value[8];
00571   uint8_t i;
00572   NFCTAG_StatusTypeDef status;
00573   
00574   /* Read value of UID registers */
00575   status = ST25DV_i2c_ReadRegister( reg_value, ST25DV_UID_REG, 8,  mi2cChannel );
00576   if( status != NFCTAG_OK )
00577   {
00578     return status;
00579   }
00580   
00581   /* Store information in 2 WORD */
00582   pUid->MsbUid = 0;
00583   
00584   for( i = 0; i < 4; i++ )
00585   {
00586     pUid->MsbUid = (pUid->MsbUid << 8) | reg_value[7 - i];
00587   }
00588   
00589   pUid->LsbUid = 0;
00590   
00591   for( i = 0; i < 4; i++ )
00592   {
00593     pUid->LsbUid = (pUid->LsbUid << 8) | reg_value[3 - i];
00594   }
00595   
00596   return NFCTAG_OK;
00597 }
00598 
00599 /**
00600   * @brief  Reads the ST25DV DSFID.
00601   * @param  pDsfid Pointer used to return the ST25DV DSFID value.
00602   * @return NFCTAG_StatusTypeDef enum status.
00603   */
00604 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDSFID( uint8_t * const pDsfid, I2C * mi2cChannel )
00605 {
00606   /* Read DSFID register */
00607   return ST25DV_i2c_ReadRegister( pDsfid, ST25DV_DSFID_REG, 1, mi2cChannel );
00608 }
00609 
00610 /**
00611   * @brief  Reads the ST25DV DSFID RF Lock state.
00612   * @param  pLockDsfid Pointer on a ST25DV_LOCK_STATUS used to return the DSFID lock state.
00613   * @param  mi2cChannel I2C channel
00614   * @return NFCTAG_StatusTypeDef enum status.
00615   */
00616 NFCTAG_StatusTypeDef ST25DV_i2c_ReadDsfidRFProtection( ST25DV_LOCK_STATUS * const pLockDsfid, I2C * mi2cChannel)
00617 {
00618   uint8_t reg_value;
00619   NFCTAG_StatusTypeDef status;
00620   
00621   /* Read register */
00622   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKDSFID_REG, 1 , mi2cChannel);
00623   if( status != NFCTAG_OK )
00624   {
00625     return status;
00626   }
00627   
00628   /* Extract Lock Status */
00629   if( reg_value == 0 )
00630   {
00631     *pLockDsfid = ST25DV_UNLOCKED;
00632   }
00633   else
00634   {
00635     *pLockDsfid = ST25DV_LOCKED;
00636   }
00637   return NFCTAG_OK;
00638 }
00639 
00640 /**
00641   * @brief  Reads the ST25DV AFI.
00642   * @param  pAfi Pointer used to return the ST25DV AFI value.
00643   * @param  mi2cChannel I2C channel
00644   * @return NFCTAG_StatusTypeDef enum status.
00645   */
00646 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAFI( uint8_t * const pAfi, I2C * mi2cChannel )
00647 {
00648   /* Read AFI register */
00649   return ST25DV_i2c_ReadRegister( pAfi, ST25DV_AFI_REG, 1 , mi2cChannel);
00650 }
00651 
00652 /**
00653   * @brief  Reads the AFI RF Lock state.
00654   * @param  pLockAfi Pointer on a ST25DV_LOCK_STATUS used to return the ASFID lock state.
00655   * @param  mi2cChannel I2C channel
00656   * @return NFCTAG_StatusTypeDef enum status.
00657   */
00658 NFCTAG_StatusTypeDef ST25DV_i2c_ReadAfiRFProtection( ST25DV_LOCK_STATUS * const pLockAfi, I2C * mi2cChannel )
00659 {
00660   uint8_t reg_value;
00661   NFCTAG_StatusTypeDef status;
00662   
00663   /* Read register */
00664   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKAFI_REG, 1,  mi2cChannel );
00665   if( status != NFCTAG_OK )
00666   {
00667     return status;
00668   }
00669   
00670   /* Extract Lock Status */
00671   if( reg_value == 0 )
00672   {
00673     *pLockAfi = ST25DV_UNLOCKED;
00674   }
00675   else
00676   {
00677     *pLockAfi = ST25DV_LOCKED;
00678   }
00679   return NFCTAG_OK;
00680 }
00681 
00682 /**
00683   * @brief  Reads the I2C Protected Area state.
00684   * @param  pProtZone Pointer on a ST25DV_I2C_PROT_ZONE structure used to return the Protected Area state.
00685   * @param  mi2cChannel I2C channel
00686   * @return NFCTAG_StatusTypeDef enum status.
00687   */
00688 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CProtectZone( ST25DV_I2C_PROT_ZONE * const pProtZone, I2C * mi2cChannel )
00689 {
00690   uint8_t reg_value;
00691   NFCTAG_StatusTypeDef status;
00692   
00693   /* Read value of I2c Protected Zone register */
00694   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_I2CZSS_REG, 1,  mi2cChannel );
00695   if( status != NFCTAG_OK )
00696   {
00697     return status;
00698   }
00699   
00700   /* Dispatch information to corresponding struct member */
00701   pProtZone->ProtectZone1 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ1_MASK) >> ST25DV_I2CZSS_PZ1_SHIFT );
00702   pProtZone->ProtectZone2 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ2_MASK) >> ST25DV_I2CZSS_PZ2_SHIFT );
00703   pProtZone->ProtectZone3 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ3_MASK) >> ST25DV_I2CZSS_PZ3_SHIFT );
00704   pProtZone->ProtectZone4 = (ST25DV_PROTECTION_CONF)( (reg_value & ST25DV_I2CZSS_PZ4_MASK) >> ST25DV_I2CZSS_PZ4_SHIFT );
00705   
00706   return NFCTAG_OK;
00707 }
00708 
00709 /**
00710   * @brief    Sets the I2C write-protected state to an EEPROM Area.
00711   * @details  Needs the I2C Password presentation to be effective.
00712   * @param    Zone                ST25DV_PROTECTION_ZONE value coresponding to the area to protect.
00713   * @param    ReadWriteProtection ST25DV_PROTECTION_CONF value corresponding to the protection to be set.
00714   * @param  mi2cChannel I2C channel
00715   * @return   NFCTAG_StatusTypeDef enum status.
00716   */
00717 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CProtectZonex( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_PROTECTION_CONF ReadWriteProtection, I2C * mi2cChannel )
00718 {
00719   NFCTAG_StatusTypeDef status;
00720   uint8_t reg_value = 0;
00721   
00722   /* Read actual i2c Zone Security Status */
00723   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_I2CZSS_REG, 1, mi2cChannel);
00724   if( status != NFCTAG_OK )
00725     return status;
00726   
00727   /* Compute and update new i2c Zone Security Status */
00728   switch( Zone )
00729   {
00730     case ST25DV_PROT_ZONE1:
00731       reg_value &= ST25DV_I2CZSS_PZ1_FIELD;
00732       /* Read protection is not allowed for Zone 1 */
00733       reg_value |= (ReadWriteProtection & 0x01) << ST25DV_I2CZSS_PZ1_SHIFT;
00734       break;
00735     case ST25DV_PROT_ZONE2:
00736       reg_value &= ST25DV_I2CZSS_PZ2_FIELD;
00737       reg_value |= ReadWriteProtection << ST25DV_I2CZSS_PZ2_SHIFT;
00738       break;
00739     case ST25DV_PROT_ZONE3:
00740       reg_value &= ST25DV_I2CZSS_PZ3_FIELD;
00741       reg_value |= ReadWriteProtection << ST25DV_I2CZSS_PZ3_SHIFT;
00742       break;
00743     case ST25DV_PROT_ZONE4:
00744       reg_value &= ST25DV_I2CZSS_PZ4_FIELD;
00745       reg_value |= ReadWriteProtection << ST25DV_I2CZSS_PZ4_SHIFT;
00746       break;
00747     
00748     default:
00749       return NFCTAG_ERROR;
00750   }
00751   
00752   /* Write I2CZSS register */
00753   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_I2CZSS_REG, 1, mi2cChannel );
00754 }
00755 
00756 /**
00757   * @brief  Reads the CCile protection state.
00758   * @param  pLockCCFile Pointer on a ST25DV_LOCK_CCFILE value corresponding to the lock state of the CCFile.
00759   * @param  mi2cChannel I2C channel
00760   * @return NFCTAG_StatusTypeDef enum status.
00761   */
00762 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCCFile( ST25DV_LOCK_CCFILE * const pLockCCFile, I2C * mi2cChannel )
00763 {
00764   uint8_t reg_value;
00765   NFCTAG_StatusTypeDef status;
00766   
00767   /* Get actual LOCKCCFILE register value */
00768   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKCCFILE_REG, 1, mi2cChannel );
00769   if( status != NFCTAG_OK )
00770   {
00771     return status;
00772   }
00773   
00774   /* Extract CCFile block information */
00775   if( (reg_value & ST25DV_LOCKCCFILE_BLCK0_MASK)  == ST25DV_LOCKCCFILE_BLCK0_MASK )
00776   {
00777     pLockCCFile->LckBck0 = ST25DV_LOCKED;
00778   }
00779   else
00780   {
00781     pLockCCFile->LckBck0 = ST25DV_UNLOCKED;
00782   }
00783   
00784   if( (reg_value & ST25DV_LOCKCCFILE_BLCK1_MASK)  == ST25DV_LOCKCCFILE_BLCK1_MASK )
00785   {
00786     pLockCCFile->LckBck1 = ST25DV_LOCKED;
00787   }
00788   else
00789   {
00790     pLockCCFile->LckBck1 = ST25DV_UNLOCKED;
00791   }
00792   
00793   return status;
00794 }
00795 
00796 /**
00797   * @brief  Locks the CCile to prevent any RF write access.
00798   * @details  Needs the I2C Password presentation to be effective.
00799   * @param  NbBlockCCFile ST25DV_CCFILE_BLOCK value corresponding to the number of blocks to be locked.
00800   * @param  LockCCFile    ST25DV_LOCK_CCFILE value corresponding to the lock state to apply on the CCFile.
00801   * @param  mi2cChannel I2C channel
00802   * @return NFCTAG_StatusTypeDef enum status.
00803   */
00804 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCCFile( const ST25DV_CCFILE_BLOCK NbBlockCCFile, const ST25DV_LOCK_STATUS LockCCFile, I2C * mi2cChannel )
00805 {
00806   uint8_t reg_value;
00807   
00808   /* Configure value to write on register */
00809   if( NbBlockCCFile == ST25DV_CCFILE_1BLCK )
00810   {
00811     if( LockCCFile == ST25DV_LOCKED )
00812     {
00813       reg_value = ST25DV_LOCKCCFILE_BLCK0_MASK;
00814     }
00815     else
00816     {
00817       reg_value = 0x00;
00818     }
00819   }
00820   else
00821   {
00822     if( LockCCFile == ST25DV_LOCKED )
00823     {
00824       reg_value = ST25DV_LOCKCCFILE_BLCK0_MASK | ST25DV_LOCKCCFILE_BLCK1_MASK;
00825     }
00826     else
00827     {
00828       reg_value = 0x00;
00829     }
00830   }
00831   
00832   /* Write LOCKCCFILE register */
00833   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_LOCKCCFILE_REG, 1, mi2cChannel );
00834 }
00835 
00836 /**
00837   * @brief  Reads the Cfg registers protection.
00838   * @param  pLockCfg Pointer on a ST25DV_LOCK_STATUS value corresponding to the Cfg registers lock state.
00839   * @param  mi2cChannel I2C channel
00840   * @return NFCTAG_StatusTypeDef enum status.
00841   */
00842 NFCTAG_StatusTypeDef ST25DV_i2c_ReadLockCFG( ST25DV_LOCK_STATUS * const pLockCfg, I2C * mi2cChannel )
00843 {
00844   uint8_t reg_value;
00845   NFCTAG_StatusTypeDef status;
00846   
00847   /* Get actual LOCKCCFILE register value */
00848   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_LOCKCFG_REG, 1, mi2cChannel );
00849   if( status != NFCTAG_OK )
00850   {
00851     return status;
00852   }
00853 
00854   /* Extract LOCKCFG block information */
00855   if( (reg_value & ST25DV_LOCKCFG_B0_MASK) == ST25DV_LOCKCFG_B0_MASK )
00856   {
00857     *pLockCfg = ST25DV_LOCKED;
00858   }
00859   else
00860   {
00861     *pLockCfg = ST25DV_UNLOCKED;
00862   }
00863   return NFCTAG_OK;  
00864 }
00865 
00866 /**
00867   * @brief  Lock/Unlock the Cfg registers, to prevent any RF write access.
00868   * @details  Needs the I2C Password presentation to be effective.
00869   * @param  LockCfg ST25DV_LOCK_STATUS value corresponding to the lock state to be written.
00870   * @param  mi2cChannel I2C channel
00871   * @return NFCTAG_StatusTypeDef enum status.
00872   */
00873 NFCTAG_StatusTypeDef ST25DV_i2c_WriteLockCFG( const ST25DV_LOCK_STATUS LockCfg, I2C * mi2cChannel )
00874 {
00875   uint8_t reg_value;
00876   
00877   /* Configure value to write on register */
00878   reg_value = (uint8_t)LockCfg;
00879   
00880   /* Write LOCKCFG register */
00881   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_LOCKCFG_REG, 1,  mi2cChannel );
00882 }
00883 
00884 /**
00885   * @brief  Presents I2C password, to authorize the I2C writes to protected areas.
00886   * @param  PassWord Password value on 32bits
00887   * @param  mi2cChannel I2C channel
00888   * @return NFCTAG_StatusTypeDef enum status.
00889   */
00890 NFCTAG_StatusTypeDef ST25DV_i2c_PresentI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel )
00891 {
00892   uint8_t ai2c_message[17] = {0};
00893   uint8_t i;
00894   
00895   /* Build I2C Message with Password + Validation code 0x09 + Password */
00896   ai2c_message[8] = 0x09;
00897   for( i = 0; i < 4; i++ )
00898   {
00899     ai2c_message[i] = ( PassWord.MsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
00900     ai2c_message[i + 4] = ( PassWord.LsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
00901     ai2c_message[i + 9] = ai2c_message[i];
00902     ai2c_message[i + 13] = ai2c_message[i + 4];
00903   };
00904   
00905   /* Present password to ST25DV */
00906   return ST25DV_i2c_WriteRegister( ai2c_message, ST25DV_I2CPASSWD_REG, 17, mi2cChannel );
00907 }
00908 
00909 /**
00910   * @brief  Writes a new I2C password.
00911   * @details  Needs the I2C Password presentation to be effective.
00912   * @param  PassWord New I2C PassWord value on 32bits.
00913   * @param  mi2cChannel I2C channel
00914   * @return NFCTAG_StatusTypeDef enum status.
00915   */
00916 NFCTAG_StatusTypeDef ST25DV_i2c_WriteI2CPassword( const ST25DV_PASSWD PassWord, I2C * mi2cChannel )
00917 {
00918   uint8_t ai2c_message[17] = {0};
00919   uint8_t i;
00920   
00921   /* Build I2C Message with Password + Validation code 0x07 + Password */
00922   ai2c_message[8] = 0x07;
00923 
00924   for( i = 0; i < 4; i++ )
00925   {
00926     ai2c_message[i] = ( PassWord.MsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
00927     ai2c_message[i + 4] = ( PassWord.LsbPasswd >> ( (3 - i) * 8) ) & 0xFF;
00928     ai2c_message[i + 9] = ai2c_message[i];
00929     ai2c_message[i + 13] = ai2c_message[i + 4];
00930   };
00931   
00932   /* Write new password in I2CPASSWD register */
00933   return ST25DV_i2c_WriteRegister( ai2c_message, ST25DV_I2CPASSWD_REG, 17, mi2cChannel );
00934 }
00935 
00936 /**
00937   * @brief  Reads the RF Zone Security Status (defining the allowed RF accesses).
00938   * @param  Zone        ST25DV_PROTECTION_ZONE value coresponding to the protected area.
00939   * @param  pRfprotZone Pointer on a ST25DV_RF_PROT_ZONE value corresponding to the area protection state.
00940   * @param  mi2cChannel I2C channel
00941   * @return NFCTAG_StatusTypeDef enum status.
00942   */
00943 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFZxSS( const ST25DV_PROTECTION_ZONE Zone, ST25DV_RF_PROT_ZONE * const pRfprotZone, I2C * mi2cChannel )
00944 {
00945   uint8_t reg_value;
00946   NFCTAG_StatusTypeDef status;
00947   uint16_t sector_security_addr;
00948   
00949   /* Select Sector Security register address */
00950   switch( Zone )
00951   {
00952     case ST25DV_PROT_ZONE1:
00953       sector_security_addr = ST25DV_RFZ1SS_REG;
00954       break;
00955     case ST25DV_PROT_ZONE2:
00956       sector_security_addr = ST25DV_RFZ2SS_REG;
00957       break;
00958     case ST25DV_PROT_ZONE3:
00959       sector_security_addr = ST25DV_RFZ3SS_REG;
00960       break;
00961     case ST25DV_PROT_ZONE4:
00962       sector_security_addr = ST25DV_RFZ4SS_REG;
00963       break;
00964     
00965     default:
00966       return NFCTAG_ERROR;
00967   }
00968   
00969   /* Read actual value of Sector Security Status register */
00970   status = ST25DV_i2c_ReadRegister( &reg_value, sector_security_addr, 1, mi2cChannel );
00971   if( status != NFCTAG_OK )
00972   {
00973     return status;
00974   }
00975   
00976   /* Extract Sector Security Status configuration */
00977   pRfprotZone->PasswdCtrl = (ST25DV_PASSWD_PROT_STATUS)((reg_value & ST25DV_RFZSS_PWDCTRL_MASK) >> ST25DV_RFZSS_PWDCTRL_SHIFT);
00978   pRfprotZone->RWprotection = (ST25DV_PROTECTION_CONF)((reg_value & ST25DV_RFZSS_RWPROT_MASK) >> ST25DV_RFZSS_RWPROT_SHIFT);
00979   
00980   return NFCTAG_OK;
00981 }
00982 
00983 /**
00984   * @brief  Writes the RF Zone Security Status (defining the allowed RF accesses)
00985   * @details  Needs the I2C Password presentation to be effective.
00986   * @param  Zone        ST25DV_PROTECTION_ZONE value corresponding to the area on which to set the RF protection.
00987   * @param  RfProtZone  Pointer on a ST25DV_RF_PROT_ZONE value defininf the protection to be set on the area.
00988   * @param  mi2cChannel I2C channel
00989   * @return NFCTAG_StatusTypeDef enum status.
00990   */
00991 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFZxSS( const ST25DV_PROTECTION_ZONE Zone, const ST25DV_RF_PROT_ZONE RfProtZone, I2C * mi2cChannel )
00992 {
00993   uint8_t reg_value;
00994   uint16_t sector_security_addr;
00995   
00996   /* Select Sector Security register address */
00997   switch( Zone )
00998   {
00999     case ST25DV_PROT_ZONE1:
01000       sector_security_addr = ST25DV_RFZ1SS_REG;
01001       break;
01002     case ST25DV_PROT_ZONE2:
01003       sector_security_addr = ST25DV_RFZ2SS_REG;
01004       break;
01005     case ST25DV_PROT_ZONE3:
01006       sector_security_addr = ST25DV_RFZ3SS_REG;
01007       break;
01008     case ST25DV_PROT_ZONE4:
01009       sector_security_addr = ST25DV_RFZ4SS_REG;
01010       break;
01011     
01012     default:
01013       return NFCTAG_ERROR;
01014   }
01015   
01016   /* Update Sector Security Status */
01017   reg_value = (RfProtZone.RWprotection << ST25DV_RFZSS_RWPROT_SHIFT) & ST25DV_RFZSS_RWPROT_MASK;
01018   reg_value |= ((RfProtZone.PasswdCtrl << ST25DV_RFZSS_PWDCTRL_SHIFT) & ST25DV_RFZSS_PWDCTRL_MASK);
01019   
01020   /* Write Sector Security register */
01021   return ST25DV_i2c_WriteRegister( &reg_value, sector_security_addr, 1,  mi2cChannel );
01022 }
01023 
01024 /**
01025   * @brief  Reads the value of the an area end address.
01026   * @param  EndZone ST25DV_END_ZONE value corresponding to an area end address.
01027   * @param  pEndZ   Pointer used to return the end address of the area.
01028   * @param  mi2cChannel I2C channel
01029   * @return NFCTAG_StatusTypeDef enum status.
01030   */
01031 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEndZonex( const ST25DV_END_ZONE EndZone, uint8_t * const pEndZ, I2C * mi2cChannel )
01032 {
01033   uint16_t mem_addr;
01034   
01035   /* End zone register address to read */
01036   switch( EndZone )
01037   {
01038     case ST25DV_ZONE_END1:
01039       mem_addr = ST25DV_END1_REG;
01040       break;
01041     case ST25DV_ZONE_END2:
01042       mem_addr = ST25DV_END2_REG;
01043       break;
01044     case ST25DV_ZONE_END3:
01045       mem_addr = ST25DV_END3_REG;
01046       break;
01047     
01048     default:
01049       return NFCTAG_ERROR;
01050   }
01051   
01052   /* Read the corresponding End zone */ 
01053   return ST25DV_i2c_ReadRegister( pEndZ, mem_addr, 1,  mi2cChannel );
01054 }
01055 
01056 /**
01057   * @brief    Sets the end address of an area.
01058   * @details  Needs the I2C Password presentation to be effective.
01059   * @note     The ST25DV answers a NACK when setting the EndZone2 & EndZone3 to same value than repectively EndZone1 & EndZone2.\n
01060   *           These NACKs are ok.
01061   * @param  EndZone ST25DV_END_ZONE value corresponding to an area.
01062   * @param  EndZ   End zone value to be written.
01063   * @param  mi2cChannel I2C channel
01064   * @return NFCTAG_StatusTypeDef enum status.
01065   */
01066 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEndZonex( const ST25DV_END_ZONE EndZone, const uint8_t EndZ , I2C * mi2cChannel)
01067 {
01068   uint16_t mem_addr;
01069   NFCTAG_StatusTypeDef ret;
01070   
01071   /* End zone register address to write */
01072   switch( EndZone )
01073   {
01074     case ST25DV_ZONE_END1:
01075       mem_addr = ST25DV_END1_REG;
01076       break;
01077     case ST25DV_ZONE_END2:
01078       mem_addr = ST25DV_END2_REG;
01079       break;
01080     case ST25DV_ZONE_END3:
01081       mem_addr = ST25DV_END3_REG;
01082       break;
01083     
01084     default:
01085       return NFCTAG_ERROR;
01086   }
01087 
01088   /* Write the corresponding End zone value in register */
01089   ret = ST25DV_i2c_WriteRegister( &EndZ, mem_addr, 1,mi2cChannel );
01090   
01091   return ret;
01092 }
01093 
01094 /**
01095   * @brief  Initializes the end address of the ST25DV areas with their default values (end of memory).
01096   * @details  Needs the I2C Password presentation to be effective..
01097   *           The ST25DV answers a NACK when setting the EndZone2 & EndZone3 to same value than repectively EndZone1 & EndZone2.
01098   *           These NACKs are ok.
01099   * @param  mi2cChannel I2C channel
01100   * @return NFCTAG_StatusTypeDef enum status.
01101   */
01102 NFCTAG_StatusTypeDef ST25DV_i2c_InitEndZone( I2C * mi2cChannel )
01103 {
01104   uint8_t endval = 0xFF;
01105   uint32_t maxmemlength;
01106   ST25DV_MEM_SIZE memsize;
01107   NFCTAG_StatusTypeDef ret;
01108   
01109   memsize.Mem_Size = 0;
01110   memsize.BlockSize = 0;
01111 
01112   /* Get EEPROM mem size */
01113   ST25DV_i2c_ReadMemSize( &memsize, mi2cChannel );
01114   maxmemlength = (memsize.Mem_Size + 1) * (memsize.BlockSize + 1);
01115   
01116   /* Compute Max value for endzone register */
01117   endval = (maxmemlength / 32) - 1;
01118   
01119   /* Write EndZone value to ST25DV registers */
01120   ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END3, endval, mi2cChannel );
01121   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01122   {
01123     return ret;
01124   }
01125 
01126   ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END2, endval, mi2cChannel );
01127   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01128   {
01129     return ret;
01130   }
01131 
01132   ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END1, endval, mi2cChannel );
01133   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01134   {
01135     return ret;
01136   }
01137   
01138   return ret;
01139 }
01140 
01141 /**
01142   * @brief  Creates user areas with defined lengths.
01143   * @details  Needs the I2C Password presentation to be effective.
01144   * @param  Zone1Length Length of area1 in bytes (32 to 8192, 0x20 to 0x2000)
01145   * @param  Zone2Length Length of area2 in bytes (0 to 8128, 0x00 to 0x1FC0)
01146   * @param  Zone3Length Length of area3 in bytes (0 to 8064, 0x00 to 0x1F80)
01147   * @param  Zone4Length Length of area4 in bytes (0 to 8000, 0x00 to 0x1F40)
01148   * @param  mi2cChannel I2C channel
01149   * @return NFCTAG_StatusTypeDef enum status.
01150   */
01151 NFCTAG_StatusTypeDef ST25DV_i2c_CreateUserZone( uint16_t Zone1Length, uint16_t Zone2Length, uint16_t Zone3Length, uint16_t Zone4Length, I2C * mi2cChannel )
01152 {
01153   uint8_t EndVal;
01154   ST25DV_MEM_SIZE memsize;
01155   uint16_t maxmemlength = 0;
01156   NFCTAG_StatusTypeDef ret;
01157   
01158   memsize.Mem_Size = 0;
01159   memsize.BlockSize = 0;
01160 
01161   ST25DV_i2c_ReadMemSize( &memsize, mi2cChannel );
01162   
01163   maxmemlength = (memsize.Mem_Size + 1) * (memsize.BlockSize + 1);
01164   
01165   /* Checks that values of different zones are in bounds */
01166   if( ( Zone1Length < 32 ) || ( Zone1Length > maxmemlength ) || ( Zone2Length > (maxmemlength - 32) ) 
01167       || ( Zone3Length > (maxmemlength - 64) ) || ( Zone4Length > (maxmemlength - 96) ) )
01168   {
01169     return NFCTAG_ERROR;
01170   }
01171 
01172   /* Checks that the total is less than the authorised maximum */
01173   if( ( Zone1Length + Zone2Length + Zone3Length + Zone4Length ) > maxmemlength )
01174   {
01175     return NFCTAG_ERROR;
01176   }
01177   
01178   /* if The value for each Length is not a multiple of 64 correct it. */
01179   if( (Zone1Length % 32) != 0 )
01180   {
01181     Zone1Length = Zone1Length - ( Zone1Length % 32 );
01182   }
01183   
01184   if( (Zone2Length % 32) != 0 )
01185   {
01186     Zone2Length = Zone2Length - ( Zone2Length % 32 );
01187   }
01188   
01189   if( (Zone3Length % 32) != 0 )
01190   {
01191     Zone3Length = Zone3Length - ( Zone3Length % 32 );
01192   }
01193   
01194   /* First right 0xFF in each Endx value */
01195   ret = ST25DV_i2c_InitEndZone( mi2cChannel );
01196   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01197   {
01198     return ret;
01199   }
01200   
01201   /* Then Write corresponding value for each zone */
01202   EndVal = (uint8_t)( (Zone1Length / 32 ) - 1 );
01203   ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END1, EndVal, mi2cChannel );
01204   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01205   {
01206     return ret;
01207   }
01208   
01209   EndVal = (uint8_t)( ((Zone1Length + Zone2Length) / 32 ) - 1 );
01210   ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END2, EndVal, mi2cChannel );
01211   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01212   {
01213     return ret;
01214   }
01215   
01216   EndVal = (uint8_t)( ((Zone1Length + Zone2Length + Zone3Length) / 32 ) - 1 );
01217   ret = ST25DV_i2c_WriteEndZonex( ST25DV_ZONE_END3, EndVal, mi2cChannel );
01218   if( (ret != NFCTAG_OK) && (ret != NFCTAG_NACK) )
01219   {
01220     return ret;
01221   }
01222   
01223   return NFCTAG_OK;
01224 }
01225 
01226 /**
01227   * @brief  Reads the ST25DV Memory Size.
01228   * @param  pSizeInfo Pointer on a ST25DV_MEM_SIZE structure used to return the Memory size information.
01229   * @param  mi2cChannel I2C channel
01230   * @return NFCTAG_StatusTypeDef enum status.
01231   */
01232 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMemSize( ST25DV_MEM_SIZE * const pSizeInfo, I2C * mi2cChannel )
01233 {
01234   uint8_t reg_value[3];
01235   NFCTAG_StatusTypeDef status;
01236   
01237   /* Read actual value of MEM_SIZE register,cheeeeeeeeeeeeeck*/
01238   status = ST25DV_i2c_ReadRegister( reg_value, ST25DV_MEM_SIZE_REG, 1, mi2cChannel );
01239   status = ST25DV_i2c_ReadRegister( reg_value + 1, ST25DV_MEM_SIZE_REG + 1, 1, mi2cChannel );
01240   status = ST25DV_i2c_ReadRegister( reg_value + 2, ST25DV_MEM_SIZE_REG + 2, 1, mi2cChannel );
01241 
01242 
01243   if( status != NFCTAG_OK )
01244     return status;
01245   
01246   /* Extract Memory information */
01247   pSizeInfo->BlockSize = reg_value[2];
01248   pSizeInfo->Mem_Size = reg_value[1];
01249   pSizeInfo->Mem_Size = (pSizeInfo->Mem_Size << 8) | reg_value[0];
01250   return NFCTAG_OK;
01251 }
01252 
01253 /**
01254   * @brief  Reads the Energy harvesting mode.
01255   * @param  pEH_mode Pointer on a ST25DV_EH_MODE_STATUS value corresponding to the Energy Harvesting state.
01256   * @param  mi2cChannel I2C channel
01257   * @return NFCTAG_StatusTypeDef enum status.
01258   */
01259 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHMode( ST25DV_EH_MODE_STATUS * const pEH_mode, I2C * mi2cChannel )
01260 {
01261   uint8_t reg_value;
01262   NFCTAG_StatusTypeDef status;
01263   
01264   /* Read actual value of EH_MODE register */
01265   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_EH_MODE_REG, 1, mi2cChannel );
01266   if( status != NFCTAG_OK )
01267     return status;
01268   
01269   /* Extract EH_mode configuration */
01270   if( (reg_value & ST25DV_EH_MODE_MASK) == ST25DV_EH_MODE_MASK )
01271   {
01272     *pEH_mode = ST25DV_EH_ON_DEMAND;
01273   }
01274   else
01275   {
01276     *pEH_mode = ST25DV_EH_ACTIVE_AFTER_BOOT;
01277   }
01278   
01279   return NFCTAG_OK;
01280 }
01281 
01282 /**
01283   * @brief  Sets the Energy harvesting mode.
01284   * @details  Needs the I2C Password presentation to be effective.
01285   * @param  EH_mode ST25DV_EH_MODE_STATUS value for the Energy harvesting mode to be set.
01286   * @param  mi2cChannel I2C channel
01287   * @return NFCTAG_StatusTypeDef enum status.
01288   */
01289 NFCTAG_StatusTypeDef ST25DV_i2c_WriteEHMode( const ST25DV_EH_MODE_STATUS EH_mode, I2C * mi2cChannel )
01290 {
01291   uint8_t reg_value;
01292   
01293   /* Update EH_mode */
01294   reg_value = (uint8_t)EH_mode;
01295   
01296   /* Write EH_MODE register */
01297   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_EH_MODE_REG, 1, mi2cChannel );
01298 }
01299 
01300 /**
01301   * @brief  Reads the RF Management configuration.
01302   * @param  pRF_Mngt Pointer on a ST25DV_RF_MNGT structure used to return the RF Management configuration.
01303   * @param  mi2cChannel I2C channel
01304   * @return NFCTAG_StatusTypeDef enum status.
01305   */
01306 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel )
01307 {
01308   NFCTAG_StatusTypeDef status;
01309   uint8_t reg_value = 0;
01310   
01311   /* Read actual value of RF_MNGT register */
01312   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1,  mi2cChannel );
01313 
01314   if( status == NFCTAG_OK )
01315   {
01316     /* Extract RF Disable information */
01317     if( (reg_value & ST25DV_RF_MNGT_RFDIS_MASK) == ST25DV_RF_MNGT_RFDIS_MASK )
01318     {
01319       pRF_Mngt->RfDisable = ST25DV_ENABLE;
01320     }
01321     else
01322     {
01323       pRF_Mngt->RfDisable = ST25DV_DISABLE;
01324     }
01325     
01326     /* Extract RF Sleep information */
01327     if( (reg_value & ST25DV_RF_MNGT_RFSLEEP_MASK) == ST25DV_RF_MNGT_RFSLEEP_MASK )
01328     {
01329       pRF_Mngt->RfSleep = ST25DV_ENABLE;
01330     }
01331     else
01332     {
01333       pRF_Mngt->RfSleep = ST25DV_DISABLE;
01334     }
01335   }
01336   
01337   return status;
01338 }
01339 
01340 /**
01341   * @brief  Sets the RF Management configuration.
01342   * @details  Needs the I2C Password presentation to be effective.
01343   * @param  Rfmngt Value of the RF Management configuration to be written.
01344   * @param  mi2cChannel I2C channel
01345   * @return NFCTAG_StatusTypeDef enum status.
01346   */
01347 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt( const uint8_t Rfmngt, I2C * mi2cChannel )
01348 {
01349   /* Write RF_MNGT register */
01350   return ST25DV_i2c_WriteRegister( &Rfmngt, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01351 }
01352 
01353 /**
01354   * @brief  Reads the RFDisable register information.
01355   * @param  pRFDisable Pointer on a ST25DV_EN_STATUS value corresponding to the RF Disable status.
01356   * @param  mi2cChannel I2C channel
01357   * @return NFCTAG_StatusTypeDef enum status.
01358   */
01359 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel )
01360 {
01361   NFCTAG_StatusTypeDef status;
01362   uint8_t reg_value = 0;
01363   
01364   /* Read actual value of RF_MNGT register */
01365   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01366   
01367   /* Extract RFDisable information */
01368   if( status == NFCTAG_OK )
01369   {
01370     if( (reg_value & ST25DV_RF_MNGT_RFDIS_MASK) == ST25DV_RF_MNGT_RFDIS_MASK )
01371     {
01372       *pRFDisable = ST25DV_ENABLE;
01373     }
01374     else
01375     {
01376       *pRFDisable = ST25DV_DISABLE;
01377     }
01378     return NFCTAG_OK;
01379   }
01380   
01381   return status;
01382 }
01383 
01384 /**
01385   * @brief  Sets the RF Disable configuration.
01386   * @details  Needs the I2C Password presentation to be effective.7
01387   * @param  mi2cChannel I2C channel
01388   * @return NFCTAG_StatusTypeDef enum status.
01389   */
01390 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable( I2C * mi2cChannel )
01391 {
01392   NFCTAG_StatusTypeDef status;
01393   uint8_t reg_value = 0;
01394   
01395   /* Read actual value of RF_RMNGT register */
01396   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01397   if( status != NFCTAG_OK )
01398   {
01399     return status;
01400   }
01401   
01402   /* Update RF Disable field configuration */
01403   reg_value |= ST25DV_RF_MNGT_RFDIS_MASK;
01404   
01405   /* Write RF_MNGT register */
01406   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01407 }
01408 
01409 /**
01410   * @brief  Resets the RF Disable configuration
01411   * @details  Needs the I2C Password presentation to be effective.
01412   * @param  mi2cChannel I2C channel
01413   * @return NFCTAG_StatusTypeDef enum status.
01414   */
01415 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable( I2C * mi2cChannel )
01416 {
01417   NFCTAG_StatusTypeDef status;
01418   uint8_t reg_value = 0;
01419   
01420   /* Read actual value of RF_RMNGT register */
01421   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01422   if( status != NFCTAG_OK )
01423   {
01424     return status;
01425   }
01426   
01427   /* Update RF Disable field configuration */
01428   reg_value &= ST25DV_RF_MNGT_RFDIS_FIELD;
01429   
01430   /* Write RF_MNGT register */
01431   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1,  mi2cChannel );
01432 }
01433 
01434 /**
01435   * @brief  Reads the RFSleep register information.
01436   * @param  pRFSleep Pointer on a ST25DV_EN_STATUS value corresponding to the RF Sleep status.
01437   * @param  mi2cChannel I2C channel
01438   * @return NFCTAG_StatusTypeDef enum status.
01439   */
01440 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel )
01441 {
01442   NFCTAG_StatusTypeDef status;
01443   uint8_t reg_value = 0;
01444   
01445   /* Read actual value of RF_MNGT register */
01446   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01447   
01448   /* Extract RFSleep information */
01449   if( status == NFCTAG_OK )
01450   {
01451     if( (reg_value & ST25DV_RF_MNGT_RFDIS_MASK) == ST25DV_RF_MNGT_RFDIS_MASK )
01452     {
01453       *pRFSleep = ST25DV_ENABLE;
01454     }
01455     else
01456     {
01457       *pRFSleep = ST25DV_DISABLE;
01458     }
01459     return NFCTAG_OK;
01460   }
01461   
01462   return status;
01463 }
01464 
01465 /**
01466   * @brief  Sets the RF Sleep configuration.
01467   * @details  Needs the I2C Password presentation to be effective.
01468   * @param  mi2cChannel I2C channel
01469   * @return NFCTAG_StatusTypeDef enum status.
01470   */
01471 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep( I2C * mi2cChannel )
01472 {
01473   NFCTAG_StatusTypeDef status;
01474   uint8_t reg_value = 0;
01475   
01476   /* Read actual value of RF_RMNGT register */
01477   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01478   if( status != NFCTAG_OK )
01479   {
01480     return status;
01481   }
01482   
01483   /* Update RF Sleep field configuration */
01484   reg_value |= ST25DV_RF_MNGT_RFSLEEP_MASK;
01485   
01486   /* Write RF_MNGT register */
01487   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1,mi2cChannel );
01488 }
01489 
01490 /**
01491   * @brief  Resets the RF Sleep configuration.
01492   * @details  Needs the I2C Password presentation to be effective.
01493   * @param  mi2cChannel I2C channel
01494   * @return NFCTAG_StatusTypeDef enum status.
01495   */
01496 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep( I2C * mi2cChannel )
01497 {
01498   NFCTAG_StatusTypeDef status;
01499   uint8_t reg_value = 0;
01500   
01501   /* Read actual value of RF_RMNGT register */
01502   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01503   if( status != NFCTAG_OK )
01504   {
01505     return status;
01506   }
01507   
01508   /* Update RF Sleep field configuration */
01509   reg_value &= ST25DV_RF_MNGT_RFSLEEP_FIELD;
01510   
01511   /* Write RF_MNGT register */
01512   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_RF_MNGT_REG, 1, mi2cChannel );
01513 }
01514 
01515 /**
01516   * @brief  Reads the Mailbox mode.
01517   * @param  pMB_mode Pointer on a ST25DV_EH_MODE_STATUS value used to return the Mailbox mode.
01518   * @param  mi2cChannel I2C channel
01519   * @return NFCTAG_StatusTypeDef enum status.
01520   */
01521 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBMode( ST25DV_EN_STATUS * const pMB_mode, I2C * mi2cChannel )
01522 {
01523   uint8_t reg_value;
01524   NFCTAG_StatusTypeDef status;
01525   
01526   /* Read actual value of MB_MODE register */
01527   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_MB_MODE_REG, 1,  mi2cChannel );
01528   if( status != NFCTAG_OK )
01529   {
01530     return status;
01531   }
01532   
01533   /* Extract Mailbox mode status */
01534   if( (reg_value & ST25DV_MB_MODE_RW_MASK) == ST25DV_MB_MODE_RW_MASK )
01535   {
01536     *pMB_mode = ST25DV_ENABLE;
01537   }
01538   else
01539   {
01540     *pMB_mode = ST25DV_DISABLE;
01541   }
01542   
01543   return NFCTAG_OK;
01544 }
01545 
01546 /**
01547   * @brief  Sets the Mailbox mode.
01548   * @details  Needs the I2C Password presentation to be effective.
01549   * @param  MB_mode ST25DV_EN_STATUS value corresponding to the Mailbox mode to be set.
01550   * @param  mi2cChannel I2C channel
01551   * @return NFCTAG_StatusTypeDef enum status.
01552   */
01553 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBMode( const ST25DV_EN_STATUS MB_mode, I2C * mi2cChannel )
01554 {
01555   uint8_t reg_value;
01556   
01557   /* Update Mailbox mode status */
01558   reg_value = (uint8_t)MB_mode;
01559   
01560   /* Write MB_MODE register */
01561   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_MB_MODE_REG, 1, mi2cChannel );
01562 }
01563 
01564 /**
01565   * @brief  Reads the Mailbox watchdog duration coefficient.
01566   * @param  pWdgDelay Pointer on a uint8_t used to return the watchdog duration coefficient.
01567   * @param  mi2cChannel I2C channel
01568   * @return NFCTAG_StatusTypeDef enum status.
01569   */
01570 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBWDG( uint8_t * const pWdgDelay, I2C * mi2cChannel )
01571 {
01572   uint8_t reg_value;
01573   NFCTAG_StatusTypeDef status;
01574   
01575   /* Read actual value of MB_WDG register */
01576   status = ST25DV_i2c_ReadRegister( &reg_value, ST25DV_MB_WDG_REG, 1 , mi2cChannel);
01577   if( status != NFCTAG_OK )
01578   {
01579     return status;
01580   }
01581   
01582   /* Extract watchdog coefficient delay configuration */
01583   *pWdgDelay = (reg_value & ST25DV_MB_WDG_DELAY_MASK) >> ST25DV_MB_WDG_DELAY_SHIFT;
01584   
01585   return NFCTAG_OK;
01586 }
01587 
01588 /**
01589   * @brief  Writes the Mailbox watchdog coefficient delay
01590   * @details  Needs the I2C Password presentation to be effective.
01591   * @param  WdgDelay Watchdog duration coefficient to be written (Watch dog duration = MB_WDG*30 ms +/- 6%).
01592   * @param  mi2cChannel I2C channel
01593   * @return NFCTAG_StatusTypeDef enum status.
01594   */
01595 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMBWDG( const uint8_t WdgDelay, I2C * mi2cChannel )
01596 {
01597   uint8_t reg_value;
01598   
01599   /* Set Watchdog coefficient delay */
01600   reg_value = WdgDelay & ST25DV_MB_WDG_DELAY_MASK;
01601   
01602   /* Write MB_MODE register */
01603   return ST25DV_i2c_WriteRegister( &reg_value, ST25DV_MB_WDG_REG, 1, mi2cChannel );
01604 }
01605 
01606 /**
01607   * @brief  Reads N bytes of data from the Mailbox, starting at the specified byte offset.
01608   * @param  pData   Pointer on the buffer used to return the read data.
01609   * @param  Offset  Offset in the Mailbox memory, byte number to start the read.
01610   * @param  NbByte  Number of bytes to be read.
01611   * @param  mi2cChannel I2C channel
01612   * @return NFCTAG_StatusTypeDef enum status.
01613   */
01614 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxData( uint8_t * const pData, const uint16_t Offset, const uint16_t NbByte, I2C * mi2cChannel )
01615 {
01616   if( Offset > ST25DV_MAX_MAILBOX_LENGTH )
01617   {
01618     return NFCTAG_ERROR;
01619   }
01620   
01621   /* Read Data in user memory */
01622   return ST25DV_IO_MemRead( pData, ST25DV_ADDR_DATA_I2C, ST25DV_MAILBOX_RAM_REG + Offset, NbByte,  mi2cChannel );
01623 }
01624 
01625 /**
01626   * @brief  Writes N bytes of data in the Mailbox, starting from first Mailbox Address.
01627   * @param  pData   Pointer to the buffer containing the data to be written.
01628   * @param  NbByte  Number of bytes to be written.
01629   * @param  mi2cChannel I2C channel
01630   * @return NFCTAG_StatusTypeDef enum status.
01631   */
01632 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxData( const uint8_t * const pData, const uint16_t NbByte, I2C * mi2cChannel )
01633 { 
01634   NFCTAG_StatusTypeDef status;
01635   
01636   /* ST25DV can write a maximum of 256 bytes in Mailbox */
01637   if( NbByte < ST25DV_MAX_MAILBOX_LENGTH )
01638   {
01639     /* Write NbByte data in memory */
01640     status = ST25DV_IO_MemWrite( pData, ST25DV_ADDR_DATA_I2C, ST25DV_MAILBOX_RAM_REG, NbByte,  mi2cChannel);
01641   }
01642   else
01643   {
01644     status = NFCTAG_ERROR;
01645   }
01646   
01647   return status;
01648 }
01649 
01650 /**
01651   * @brief  Reads N bytes from the mailbox registers, starting at the specified I2C address.
01652   * @param  pData   Pointer on the buffer used to return the data.
01653   * @param  TarAddr I2C memory address to be read.
01654   * @param  NbByte  Number of bytes to be read.
01655   * @param  mi2cChannel I2C channel
01656   * @return NFCTAG_StatusTypeDef enum status.
01657   */
01658 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMailboxRegister( uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
01659 { 
01660   if( (TarAddr < ST25DV_GPO_DYN_REG) || (TarAddr > ST25DV_MBLEN_DYN_REG) )
01661   {
01662     return NFCTAG_ERROR;
01663   }
01664   
01665   return ST25DV_IO_MemRead( pData, ST25DV_ADDR_DATA_I2C, TarAddr, NbByte,  mi2cChannel );
01666 }
01667 
01668 /**
01669   * @brief  Writes N bytes to the specified mailbox register.
01670   * @param  pData   Pointer on the data to be written.
01671   * @param  TarAddr I2C register address to be written.
01672   * @param  NbByte  Number of bytes to be written.
01673   * @param  mi2cChannel I2C channel
01674   * @return NFCTAG_StatusTypeDef enum status.
01675   */
01676 NFCTAG_StatusTypeDef ST25DV_i2c_WriteMailboxRegister( const uint8_t * const pData, const uint16_t TarAddr, const uint16_t NbByte, I2C * mi2cChannel )
01677 { 
01678   NFCTAG_StatusTypeDef status;
01679   
01680   if( (TarAddr < ST25DV_GPO_DYN_REG) || (TarAddr > ST25DV_MBLEN_DYN_REG) )
01681   {
01682     return NFCTAG_ERROR;
01683   }
01684   
01685   /* ST25DV can write a maximum of 256 bytes in Mailbox */
01686   if( NbByte < ST25DV_MAX_MAILBOX_LENGTH )
01687   {
01688     /* Write NbByte data in memory */
01689     status = ST25DV_IO_MemWrite( pData, ST25DV_ADDR_DATA_I2C, TarAddr, NbByte, mi2cChannel);
01690   }
01691   else
01692   {
01693     status = NFCTAG_ERROR;
01694   }
01695   
01696   return status;
01697 }
01698 
01699 /**
01700   * @brief  Reads the status of the security session open register.
01701   * @param  pSession Pointer on a ST25DV_I2CSSO_STATUS value used to return the session status.
01702   * @param  mi2cChannel I2C channel
01703   * @return NFCTAG_StatusTypeDef enum status.
01704   */
01705 NFCTAG_StatusTypeDef ST25DV_i2c_ReadI2CSecuritySession_Dyn( ST25DV_I2CSSO_STATUS * const pSession, I2C * mi2cChannel )
01706 {
01707   uint8_t reg_value;
01708   NFCTAG_StatusTypeDef status;
01709 
01710   /* Read actual value of I2C_SSO_DYN register */
01711   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_I2C_SSO_DYN_REG, 1, mi2cChannel );
01712   if( status != NFCTAG_OK )
01713   {
01714     return status;
01715   }
01716   
01717   /* Extract Open session information */
01718   if( (reg_value & ST25DV_I2C_SSO_DYN_I2CSSO_MASK) == ST25DV_I2C_SSO_DYN_I2CSSO_MASK )
01719   {
01720     *pSession = ST25DV_SESSION_OPEN;
01721   }
01722   else
01723   {
01724     *pSession = ST25DV_SESSION_CLOSED;
01725   }
01726   
01727   return NFCTAG_OK;
01728 }
01729 
01730 /**
01731   * @brief  Reads the IT status register from the ST25DV.
01732   * @param  pITStatus Pointer on uint8_t, used to return the IT status, such as:
01733   *                       - RFUSERSTATE = 0x01
01734   *                       - RFBUSY = 0x02
01735   *                       - RFINTERRUPT = 0x04
01736   *                       - FIELDFALLING = 0x08
01737   *                       - FIELDRISING = 0x10
01738   *                       - RFPUTMSG = 0x20
01739   *                       - RFGETMSG = 0x40
01740   *                       - RFWRITE = 0x80
01741   * @param  mi2cChannel I2C channel
01742   * @return NFCTAG_StatusTypeDef enum status.
01743   */
01744 NFCTAG_StatusTypeDef ST25DV_i2c_ReadITSTStatus_Dyn( uint8_t * const pITStatus, I2C * mi2cChannel )
01745 {
01746   /* Read value of ITStatus register */
01747   return ST25DV_i2c_ReadMailboxRegister( pITStatus, ST25DV_ITSTS_DYN_REG, 1,  mi2cChannel );
01748 }
01749 
01750 /**
01751   * @brief  Read value of dynamic GPO register configuration.
01752   * @param  pGPO ST25DV_GPO pointer of the dynamic GPO configuration to store.
01753   * @param  mi2cChannel I2C channel
01754   * @retval NFCTAG enum status.
01755   */
01756 NFCTAG_StatusTypeDef ST25DV_i2c_ReadGPO_Dyn( uint8_t *GPOConfig, I2C * mi2cChannel )
01757 {
01758   /* Read actual value of ST25DV_GPO_DYN_REG register */
01759   return ST25DV_i2c_ReadMailboxRegister( GPOConfig, ST25DV_GPO_DYN_REG, 1,  mi2cChannel );
01760 }
01761 
01762 
01763 /**
01764   * @brief  Get dynamique GPO enable status
01765   * @param  pGPO_en ST25DV_EN_STATUS pointer of the GPO enable status to store
01766   * @param  mi2cChannel I2C channel
01767   * @retval NFCTAG enum status
01768   */
01769 NFCTAG_StatusTypeDef ST25DV_i2c_GetGPO_en_Dyn( ST25DV_EN_STATUS * const pGPO_en, I2C * mi2cChannel )
01770 {
01771   uint8_t reg_value;
01772   NFCTAG_StatusTypeDef status;
01773   /* Read actual value of GPO_DYN register */
01774   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1,  mi2cChannel );
01775   if( status != NFCTAG_OK )
01776   {
01777     return status;
01778   }
01779   
01780   /* Extract GPO enable status information */
01781   if( (reg_value & ST25DV_GPO_DYN_ENABLE_MASK) == ST25DV_GPO_DYN_ENABLE_MASK )
01782   {
01783     *pGPO_en = ST25DV_ENABLE;
01784   }
01785   else
01786   {
01787     *pGPO_en = ST25DV_DISABLE;
01788   }
01789   
01790   return NFCTAG_OK;
01791 }
01792 
01793 /**
01794   * @brief  Set dynamique GPO enable configuration.
01795   * @param  None No parameters.
01796   * @param  mi2cChannel I2C channel
01797   * @retval NFCTAG enum status.
01798   */
01799 NFCTAG_StatusTypeDef ST25DV_i2c_SetGPO_en_Dyn( I2C * mi2cChannel )
01800 {
01801   uint8_t reg_value;
01802   NFCTAG_StatusTypeDef status;
01803   
01804   /* Read actual value of GPO_DYN register */
01805   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
01806   if( status != NFCTAG_OK )
01807   {
01808     return status;
01809   }
01810   
01811   /* Update GPO enable configuration */
01812   reg_value |= ST25DV_GPO_DYN_ENABLE_MASK;
01813   
01814   /* Write GPO_DYN Register */
01815   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1,  mi2cChannel );
01816 }
01817 
01818 /**
01819   * @brief  Reset dynamique GPO enable configuration.
01820   * @param  None No parameters.
01821   * @param  mi2cChannel I2C channel
01822   * @retval NFCTAG enum status.
01823   */
01824 NFCTAG_StatusTypeDef ST25DV_i2c_ResetGPO_en_Dyn( I2C * mi2cChannel )
01825 {
01826   uint8_t reg_value;
01827   NFCTAG_StatusTypeDef status;
01828   
01829   /* Read actual value of GPO_DYN register */
01830   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
01831   if( status != NFCTAG_OK )
01832   {
01833     return status;
01834   }
01835   
01836   /* Update GPO enable configuration */
01837   reg_value &= ST25DV_GPO_DYN_ENABLE_FIELD;
01838   
01839   /* Write GPO_DYN Register */
01840   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_GPO_DYN_REG, 1, mi2cChannel );
01841 }
01842 
01843 /**
01844   * @brief  Read value of dynamic EH Ctrl register configuration
01845   * @param  pEH_CTRL : ST25DV_EH_CTRL pointer of the dynamic EH Ctrl configuration to store
01846   * @param  mi2cChannel I2C channel
01847   * @retval NFCTAG enum status
01848   */
01849 NFCTAG_StatusTypeDef ST25DV_i2c_ReadEHCtrl_Dyn( ST25DV_EH_CTRL * const pEH_CTRL, I2C * mi2cChannel )
01850 {
01851   NFCTAG_StatusTypeDef status;
01852   uint8_t reg_value = 0;
01853   
01854   /* Read actual value of ST25DV_EH_CTRL_DYN_REG register */
01855   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1,  mi2cChannel );
01856   
01857   if( status == NFCTAG_OK )
01858   {
01859     /* Extract EH EN Mode configuration */
01860     if( (reg_value & ST25DV_EH_CTRL_DYN_EH_EN_MASK) == ST25DV_EH_CTRL_DYN_EH_EN_MASK )
01861     {
01862       pEH_CTRL->EH_EN_Mode = ST25DV_ENABLE;
01863     }
01864     else
01865     {
01866       pEH_CTRL->EH_EN_Mode = ST25DV_DISABLE;
01867     }
01868     
01869     /* Extract EH_ON configuration */
01870     if( (reg_value & ST25DV_EH_CTRL_DYN_EH_ON_MASK) == ST25DV_EH_CTRL_DYN_EH_ON_MASK )
01871     {
01872       pEH_CTRL->EH_on = ST25DV_ENABLE;
01873     }
01874     else
01875     {
01876       pEH_CTRL->EH_on = ST25DV_DISABLE;
01877     }
01878     
01879     /* Extract FIELD_ON configuration */
01880     if( (reg_value & ST25DV_EH_CTRL_DYN_FIELD_ON_MASK) == ST25DV_EH_CTRL_DYN_FIELD_ON_MASK )
01881     {
01882       pEH_CTRL->Field_on = ST25DV_ENABLE;
01883     }
01884     else
01885     {
01886       pEH_CTRL->Field_on = ST25DV_DISABLE;
01887     }
01888     
01889     /* Extract VCC_ON configuration */
01890     if( (reg_value & ST25DV_EH_CTRL_DYN_VCC_ON_MASK) == ST25DV_EH_CTRL_DYN_VCC_ON_MASK )
01891     {
01892       pEH_CTRL->VCC_on = ST25DV_ENABLE;
01893     }
01894     else
01895     {
01896       pEH_CTRL->VCC_on = ST25DV_DISABLE;
01897     }
01898     
01899     return NFCTAG_OK;
01900   }
01901   
01902   return status;
01903 }
01904 
01905 /**
01906   * @brief  Reads the Energy Harvesting dynamic status.
01907   * @param  pEH_Val Pointer on a ST25DV_EN_STATUS value used to return the Energy Harvesting dynamic status.
01908   * @param  mi2cChannel I2C channel
01909   * @return NFCTAG_StatusTypeDef enum status.
01910   */
01911 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHENMode_Dyn( ST25DV_EN_STATUS * const pEH_Val, I2C * mi2cChannel )
01912 {
01913   uint8_t reg_value;
01914   NFCTAG_StatusTypeDef status;
01915   
01916   /* Read actual value of EH_CTRL_DYN register */
01917   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1,  mi2cChannel );
01918   if( status != NFCTAG_OK )
01919   {
01920     return status;
01921   }
01922   
01923   /* Extract Energy Harvesting status information */
01924   if( (reg_value & ST25DV_EH_CTRL_DYN_EH_EN_MASK) == ST25DV_EH_CTRL_DYN_EH_EN_MASK )
01925   {
01926     *pEH_Val = ST25DV_ENABLE;
01927   }
01928   else
01929   {
01930     *pEH_Val = ST25DV_DISABLE;
01931   }
01932   
01933   return NFCTAG_OK;
01934 }
01935 
01936 /**
01937   * @brief  Dynamically sets the Energy Harvesting mode.
01938   * @param  mi2cChannel I2C channel
01939   * @return NFCTAG_StatusTypeDef enum status.
01940   */
01941 NFCTAG_StatusTypeDef ST25DV_i2c_SetEHENMode_Dyn(  I2C * mi2cChannel )
01942 {
01943   uint8_t reg_value;
01944   NFCTAG_StatusTypeDef status;
01945   
01946   /* Read actual value of EH_CTRL_DYN register */
01947   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
01948   if( status != NFCTAG_OK )
01949   {
01950     return status;
01951   }
01952   
01953   /* Update Energy Harvesting configuration */
01954   reg_value |= ST25DV_EH_CTRL_DYN_EH_EN_MASK;
01955   
01956   /* Write EH_CTRL_DYN Register */
01957   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
01958 }
01959 
01960 /**
01961   * @brief  Dynamically unsets the Energy Harvesting mode.
01962   * @param  mi2cChannel I2C channel
01963   * @return NFCTAG_StatusTypeDef enum status.
01964   */
01965 NFCTAG_StatusTypeDef ST25DV_i2c_ResetEHENMode_Dyn( I2C * mi2cChannel )
01966 {
01967   uint8_t reg_value;
01968   NFCTAG_StatusTypeDef status;
01969   
01970   /* Read actual value of EH_CTRL_DYN register */
01971   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
01972   if( status != NFCTAG_OK )
01973   {
01974     return status;
01975   }
01976   
01977   /* Update Energy Harvesting configuration */
01978   reg_value &= ST25DV_EH_CTRL_DYN_EH_EN_FIELD;
01979   
01980   /* Write EH_CTRL_DYN Register */
01981   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
01982 }
01983 
01984 /**
01985   * @brief  Reads the EH_ON status from the EH_CTRL_DYN register.
01986   * @param  pEHON Pointer on a ST25DV_EN_STATUS value used to return the EHON status.
01987   * @param  mi2cChannel I2C channel
01988   * @return NFCTAG_StatusTypeDef enum status.
01989   */
01990 NFCTAG_StatusTypeDef ST25DV_i2c_GetEHON_Dyn( ST25DV_EN_STATUS * const pEHON, I2C * mi2cChannel )
01991 {
01992   NFCTAG_StatusTypeDef status;
01993   uint8_t reg_value = 0;
01994   
01995   /* Read actual value of EH_CTRL_DYN register */
01996   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
01997   
01998   /* Extract RF Field information */
01999   if( status == NFCTAG_OK )
02000   {
02001     if( (reg_value & ST25DV_EH_CTRL_DYN_EH_ON_MASK) == ST25DV_EH_CTRL_DYN_EH_ON_MASK )
02002     {
02003       *pEHON = ST25DV_ENABLE;
02004     }
02005     else
02006     {
02007       *pEHON = ST25DV_DISABLE;
02008     }
02009     return NFCTAG_OK;
02010   }
02011   
02012   return status;
02013 }
02014 
02015 /**
02016   * @brief  Checks if RF Field is present in front of the ST25DV.
02017   * @param  pRF_Field Pointer on a ST25DV_FIELD_STATUS value used to return the field presence.
02018   * @param  mi2cChannel I2C channel
02019   * @return NFCTAG_StatusTypeDef enum status.
02020   */
02021 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFField_Dyn( ST25DV_FIELD_STATUS * const pRF_Field, I2C * mi2cChannel )
02022 {
02023   NFCTAG_StatusTypeDef status;
02024   uint8_t reg_value = 0;
02025   
02026   /* Read actual value of EH_CTRL_DYN register */
02027   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
02028   
02029   /* Extract RF Field information */
02030   if( status == NFCTAG_OK )
02031   {
02032     if( (reg_value & ST25DV_EH_CTRL_DYN_FIELD_ON_MASK) == ST25DV_EH_CTRL_DYN_FIELD_ON_MASK )
02033     {
02034       *pRF_Field = ST25DV_FIELD_ON;
02035     }
02036     else
02037     {
02038       *pRF_Field = ST25DV_FIELD_OFF;
02039     }
02040     return NFCTAG_OK;
02041   }
02042   
02043   return status;
02044 }
02045 
02046 /**
02047   * @brief  Check if VCC is supplying the ST25DV.
02048   * @param  pVCC ST25DV_VCC_STATUS pointer of the VCC status to store
02049   * @param  mi2cChannel I2C channel
02050   * @retval NFCTAG enum status.
02051   */
02052 NFCTAG_StatusTypeDef ST25DV_i2c_GetVCC_Dyn( ST25DV_VCC_STATUS * const pVCC, I2C * mi2cChannel )
02053 {
02054   NFCTAG_StatusTypeDef status;
02055   uint8_t reg_value = 0;
02056   
02057   /* Read actual value of EH_CTRL_DYN register */
02058   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_EH_CTRL_DYN_REG, 1, mi2cChannel );
02059   
02060   /* Extract VCC information */
02061   if( status == NFCTAG_OK )
02062   {
02063     if( (reg_value & ST25DV_EH_CTRL_DYN_VCC_ON_MASK) == ST25DV_EH_CTRL_DYN_VCC_ON_MASK )
02064     {
02065       *pVCC = ST25DV_VCC_ON;
02066     }
02067     else
02068     {
02069       *pVCC = ST25DV_VCC_OFF;
02070     }
02071     return NFCTAG_OK;
02072   }
02073   
02074   return status;
02075 }
02076 
02077 /**
02078   * @brief  Read value of dynamic RF Management configuration
02079   * @param  pRF_Mngt : ST25DV_RF_MNGT pointer of the dynamic RF Management configuration to store
02080   * @param  mi2cChannel I2C channel
02081   * @retval NFCTAG enum status
02082   */
02083 NFCTAG_StatusTypeDef ST25DV_i2c_ReadRFMngt_Dyn( ST25DV_RF_MNGT * const pRF_Mngt, I2C * mi2cChannel )
02084 {
02085   NFCTAG_StatusTypeDef status;
02086   uint8_t reg_value = 0;
02087   
02088   /* Read actual value of RF_MNGT_DYN register */
02089   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02090   
02091   if( status == NFCTAG_OK )
02092   {
02093     /* Extract RF Disable configuration */
02094     if( (reg_value & ST25DV_RF_MNGT_DYN_RFDIS_MASK) == ST25DV_RF_MNGT_DYN_RFDIS_MASK )
02095     {
02096       pRF_Mngt->RfDisable = ST25DV_ENABLE;
02097     }
02098     else
02099     {
02100       pRF_Mngt->RfDisable = ST25DV_DISABLE;
02101     }
02102     
02103     /* Extract RF Sleep configuration */
02104     if( (reg_value & ST25DV_RF_MNGT_DYN_RFSLEEP_MASK) == ST25DV_RF_MNGT_DYN_RFSLEEP_MASK )
02105     {
02106       pRF_Mngt->RfSleep = ST25DV_ENABLE;
02107     }
02108     else
02109     {
02110       pRF_Mngt->RfSleep = ST25DV_DISABLE;
02111     }
02112     
02113     return NFCTAG_OK;
02114   }
02115   
02116   return status;
02117 }
02118 
02119 /**
02120   * @brief  Writes a value to the RF Management dynamic register.
02121   * @param  RF_Mngt Value to be written to the RF Management dynamic register.
02122   * @param  mi2cChannel I2C channel
02123   * @return NFCTAG_StatusTypeDef enum status.
02124   */
02125 NFCTAG_StatusTypeDef ST25DV_i2c_WriteRFMngt_Dyn( const uint8_t RF_Mngt, I2C * mi2cChannel )
02126 {
02127   /* Write value to RF_MNGT_DYN register */
02128   return ST25DV_i2c_WriteMailboxRegister( &RF_Mngt, ST25DV_RF_MNGT_DYN_REG, 1,  mi2cChannel );
02129 }
02130 
02131 /**
02132   * @brief  Reads the RFDisable dynamic register information.
02133   * @param  pRFDisable Pointer on a ST25DV_EN_STATUS value used to return the RF Disable state.
02134   * @param  mi2cChannel I2C channel
02135   * @return NFCTAG_StatusTypeDef enum status.
02136   */
02137 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFDisable_Dyn( ST25DV_EN_STATUS * const pRFDisable, I2C * mi2cChannel )
02138 {
02139   NFCTAG_StatusTypeDef status;
02140   uint8_t reg_value = 0;
02141   
02142   /* Read actual value of RF_MNGT_DYN register */
02143   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02144   
02145   /* Extract RFDisable information */
02146   if( status == NFCTAG_OK )
02147   {
02148     if( (reg_value & ST25DV_RF_MNGT_DYN_RFDIS_MASK) == ST25DV_RF_MNGT_DYN_RFDIS_MASK )
02149     {
02150       *pRFDisable = ST25DV_ENABLE;
02151     }
02152     else
02153     {
02154       *pRFDisable = ST25DV_DISABLE;
02155     }
02156     return NFCTAG_OK;
02157   }
02158   
02159   return status;
02160 }
02161 
02162 /**
02163   * @brief  Sets the RF Disable dynamic configuration.
02164   * @param  mi2cChannel I2C channel
02165   * @return NFCTAG_StatusTypeDef enum status.
02166   */
02167 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFDisable_Dyn( I2C * mi2cChannel )
02168 {
02169   NFCTAG_StatusTypeDef status;
02170   uint8_t reg_value = 0;
02171   
02172   /* Read actual value of RF_MNGT_DYN register */
02173   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02174   if( status != NFCTAG_OK )
02175   {
02176     return status;
02177   }
02178   
02179   /* Update dynamic RF Disable field */
02180   reg_value |= ST25DV_RF_MNGT_DYN_RFDIS_MASK;
02181   
02182   /* Write RF_MNGT_DYN register */
02183   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1,  mi2cChannel );
02184 }
02185 
02186 /**
02187   * @brief  Unsets the RF Disable dynamic configuration.
02188   * @param  mi2cChannel I2C channel
02189   * @return NFCTAG_StatusTypeDef enum status.
02190   */
02191 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFDisable_Dyn( I2C * mi2cChannel )
02192 {
02193   NFCTAG_StatusTypeDef status;
02194   uint8_t reg_value = 0;
02195   
02196   /* Read actual value of RF_MNGT_DYN register */
02197   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02198   if( status != NFCTAG_OK )
02199   {
02200     return status;
02201   }
02202   
02203   /* Update dynamic RF Disable field configuration */
02204   reg_value &= ST25DV_RF_MNGT_DYN_RFDIS_FIELD;
02205   
02206   /* Write RF_MNGT_DYN register */
02207   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02208 }
02209 
02210 /**
02211   * @brief  Reads the RFSleep dynamic register information.
02212   * @param  pRFSleep Pointer on a ST25DV_EN_STATUS values used to return the RF Sleep state.
02213   * @param  mi2cChannel I2C channel
02214   * @return NFCTAG_StatusTypeDef enum status.
02215   */
02216 NFCTAG_StatusTypeDef ST25DV_i2c_GetRFSleep_Dyn( ST25DV_EN_STATUS * const pRFSleep, I2C * mi2cChannel )
02217 {
02218   NFCTAG_StatusTypeDef status;
02219   uint8_t reg_value = 0;
02220   
02221   /* Read actual value of RF_MNGT_DYN register */
02222   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1,  mi2cChannel );
02223   
02224   /* Extract RFSleep information */
02225   if( status == NFCTAG_OK )
02226   {
02227     if( (reg_value & ST25DV_RF_MNGT_DYN_RFDIS_MASK) == ST25DV_RF_MNGT_DYN_RFDIS_MASK )
02228     {
02229       *pRFSleep = ST25DV_ENABLE;
02230     }
02231     else
02232     {
02233       *pRFSleep = ST25DV_DISABLE;
02234     }
02235     return NFCTAG_OK;
02236   }
02237   
02238   return status;
02239 }
02240 
02241 /**
02242   * @brief  Sets the RF Sleep dynamic configuration.
02243   * @param  mi2cChannel I2C channel
02244   * @return NFCTAG_StatusTypeDef enum status.
02245   */
02246 NFCTAG_StatusTypeDef ST25DV_i2c_SetRFSleep_Dyn( I2C * mi2cChannel )
02247 {
02248   NFCTAG_StatusTypeDef status;
02249   uint8_t reg_value = 0;
02250   
02251   /* Read actual value of RF_MNGT_DYN register */
02252   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02253   if( status != NFCTAG_OK )
02254   {
02255     return status;
02256   }
02257   
02258   /* Update dynamic RF Disable field configuration */
02259   reg_value |= ST25DV_RF_MNGT_DYN_RFSLEEP_MASK;
02260   
02261   /* Write RF_MNGT_DYN register */
02262   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02263 }
02264 
02265 /**
02266   * @brief  Unsets the RF Sleep dynamic configuration.
02267   * @param  mi2cChannel I2C channel
02268   * @return NFCTAG_StatusTypeDef enum status.
02269   */
02270 NFCTAG_StatusTypeDef ST25DV_i2c_ResetRFSleep_Dyn( I2C * mi2cChannel )
02271 {
02272   NFCTAG_StatusTypeDef status;
02273   uint8_t reg_value = 0;
02274   
02275   /* Read actual value of RF_MNGT_DYN register */
02276   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02277   if( status != NFCTAG_OK )
02278   {
02279     return status;
02280   }
02281   
02282   /* Update dynamic RF Disable field configuration */
02283   reg_value &= ST25DV_RF_MNGT_DYN_RFSLEEP_FIELD;
02284   
02285   /* Write RF_MNGT_DYN register */
02286   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_RF_MNGT_DYN_REG, 1, mi2cChannel );
02287 }
02288 
02289 /**
02290   * @brief  Reads the Mailbox ctrl dynamic register.
02291   * @param  pCtrlStatus Pointer on a ST25DV_MB_CTRL_DYN_STATUS structure used to return the dynamic Mailbox ctrl information.
02292   * @param  mi2cChannel I2C channel
02293   * @return NFCTAG_StatusTypeDef enum status.
02294   */
02295 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBCtrl_Dyn( ST25DV_MB_CTRL_DYN_STATUS * const pCtrlStatus, I2C * mi2cChannel )
02296 {
02297   uint8_t reg_value;
02298   NFCTAG_StatusTypeDef status;
02299   
02300   /* Read MB_CTRL_DYN register */
02301   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
02302   if( status != NFCTAG_OK )
02303   {
02304     return status;
02305   }
02306   
02307   /* Extract Mailbox ctrl information */
02308   pCtrlStatus->MbEnable = (reg_value & ST25DV_MB_CTRL_DYN_MBEN_MASK) >> ST25DV_MB_CTRL_DYN_MBEN_SHIFT;
02309   pCtrlStatus->HostPutMsg = (reg_value & ST25DV_MB_CTRL_DYN_HOSTPUTMSG_MASK) >> ST25DV_MB_CTRL_DYN_HOSTPUTMSG_SHIFT;
02310   pCtrlStatus->RfPutMsg = (reg_value & ST25DV_MB_CTRL_DYN_RFPUTMSG_MASK) >> ST25DV_MB_CTRL_DYN_RFPUTMSG_SHIFT;
02311   pCtrlStatus->HostMissMsg = (reg_value & ST25DV_MB_CTRL_DYN_HOSTMISSMSG_MASK) >> ST25DV_MB_CTRL_DYN_HOSTMISSMSG_SHIFT;
02312   pCtrlStatus->RFMissMsg = (reg_value & ST25DV_MB_CTRL_DYN_RFMISSMSG_MASK) >> ST25DV_MB_CTRL_DYN_RFMISSMSG_SHIFT;
02313   pCtrlStatus->CurrentMsg = (ST25DV_CURRENT_MSG)((reg_value & ST25DV_MB_CTRL_DYN_CURRENTMSG_MASK) >> ST25DV_MB_CTRL_DYN_CURRENTMSG_SHIFT);
02314   
02315   return NFCTAG_OK;
02316 }
02317 
02318 /**
02319   * @brief  Reads the Mailbox Enable dynamic configuration.
02320   * @param  mi2cChannel I2C channel
02321   * @return NFCTAG_StatusTypeDef enum status.
02322   */
02323 NFCTAG_StatusTypeDef ST25DV_i2c_GetMBEN_Dyn( ST25DV_EN_STATUS * const pMBEN, I2C * mi2cChannel )
02324 {
02325   uint8_t reg_value;
02326   NFCTAG_StatusTypeDef status;
02327   
02328   /* Read MB_CTRL_DYN register */
02329   status = ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
02330   if( status != NFCTAG_OK )
02331   {
02332     return status;
02333   }
02334   
02335   if( (reg_value & ST25DV_MB_MODE_RW_MASK ) == ST25DV_MB_MODE_RW_MASK )
02336   {
02337     *pMBEN = ST25DV_ENABLE;
02338   }
02339   else
02340   {
02341     *pMBEN = ST25DV_DISABLE;
02342   }
02343   
02344   return NFCTAG_OK;
02345 }
02346 
02347 /**
02348   * @brief  Sets the Mailbox Enable dynamic configuration.
02349   * @param  mi2cChannel I2C channel
02350   * @return NFCTAG_StatusTypeDef enum status.
02351   */
02352 NFCTAG_StatusTypeDef ST25DV_i2c_SetMBEN_Dyn( I2C * mi2cChannel )
02353 {
02354   uint8_t reg_value;
02355   
02356   /* Set dynamic Mailbox enable */
02357   reg_value = ST25DV_MB_CTRL_DYN_MBEN_MASK;
02358   
02359   /* Write MB_CTRL_DYN register */
02360   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
02361 }
02362 
02363 /**
02364   * @brief  Unsets the Mailbox Enable dynamic configuration.
02365   * @param  mi2cChannel I2C channel
02366   * @return NFCTAG_StatusTypeDef enum status.
02367   */
02368 NFCTAG_StatusTypeDef ST25DV_i2c_ResetMBEN_Dyn( I2C * mi2cChannel )
02369 {
02370   uint8_t reg_value;
02371 
02372   
02373   /* Set dynamic Mailbox disable */
02374   reg_value = 0;
02375   
02376   /* Write MB_CTRL_DYN register */
02377   ST25DV_i2c_ReadMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
02378   return ST25DV_i2c_WriteMailboxRegister( &reg_value, ST25DV_MB_CTRL_DYN_REG, 1, mi2cChannel );
02379 
02380 }
02381 
02382 /**
02383   * @brief  Reads the Mailbox message length dynamic register.
02384   * @param  pMBLength Pointer on a uint8_t used to return the Mailbox message length.
02385   * @param  mi2cChannel I2C channel
02386   * @return NFCTAG_StatusTypeDef enum status.
02387   */
02388 NFCTAG_StatusTypeDef ST25DV_i2c_ReadMBLength_Dyn( uint8_t * const pMBLength, I2C * mi2cChannel )
02389 {
02390   /* Read actual value of MBLEN_DYN register */
02391   return ST25DV_i2c_ReadMailboxRegister( pMBLength, ST25DV_MBLEN_DYN_REG, 1, mi2cChannel );
02392 }
02393 
02394 /**
02395  * @}
02396  */
02397 
02398 /**
02399  * @}
02400  */
02401 
02402 
02403 /******************* (C) COPYRIGHT 2016 STMicroelectronics *****END OF FILE****/