ST Expansion SW Team / RFAL

Dependents:   mbed-os-nfc05a1

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers rfal_nfcv.h Source File

rfal_nfcv.h

Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003   * @attention
00004   *
00005   * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
00006   *
00007   * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
00008   * You may not use this file except in compliance with the License.
00009   * You may obtain a copy of the License at:
00010   *
00011   *        http://www.st.com/myliberty
00012   *
00013   * Unless required by applicable law or agreed to in writing, software
00014   * distributed under the License is distributed on an "AS IS" BASIS,
00015   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
00016   * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
00017   * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00018   * See the License for the specific language governing permissions and
00019   * limitations under the License.
00020   *
00021 ******************************************************************************/
00022 
00023 /*
00024  *      PROJECT:   ST25R391x firmware
00025  *      $Revision: $
00026  *      LANGUAGE:  ISO C99
00027  */
00028 
00029 /*! \file rfal_nfcv.h
00030  *
00031  *  \author Gustavo Patricio
00032  *
00033  *  \brief Implementation of NFC-V Poller (ISO15693) device
00034  *
00035  *  The definitions and helpers methods provided by this module
00036  *  are aligned with NFC-V Digital 2.0 (Candidate)
00037  *
00038  *
00039  * @addtogroup RFAL
00040  * @{
00041  *
00042  * @addtogroup RFAL-AL
00043  * @brief RFAL Abstraction Layer
00044  * @{
00045  *
00046  * @addtogroup NFC-V
00047  * @brief RFAL NFC-V Module
00048  * @{
00049  *
00050  */
00051 
00052 #ifndef RFAL_NFCV_H
00053 #define RFAL_NFCV_H
00054 
00055 /*
00056  ******************************************************************************
00057  * INCLUDES
00058  ******************************************************************************
00059  */
00060 #include "platform1.h"
00061 #include "st_errno.h"
00062 #include "rfal_rf.h"
00063 
00064 /*
00065  ******************************************************************************
00066  * GLOBAL DEFINES
00067  ******************************************************************************
00068  */
00069 #define RFAL_NFCV_UID_LEN                           8    /*!< NFC-V UID length  */
00070 #define RFAL_NFCV_MAX_BLOCK_LEN           32    /*!< Max Block size: can be of up to 256 bits  ISO 15693 2000  5       */
00071 
00072 
00073 
00074 /*! NFC-V RequestFlags   ISO15693 2000 7.3.1 */
00075 enum{
00076     RFAL_NFCV_REQ_FLAG_DEFAULT            = 0x02,       /*!< Default Request Flags           */
00077     RFAL_NFCV_REQ_FLAG_SUB_CARRIER        = 0x01,       /*!< Sub Carrier flag                */
00078     RFAL_NFCV_REQ_FLAG_DATA_RATE          = 0x02,       /*!< Data Rate flag                  */
00079     RFAL_NFCV_REQ_FLAG_INVENTORY          = 0x04,       /*!< Inventory flag                  */
00080     RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT       = 0x08,       /*!< Protocol Extension flag         */
00081     RFAL_NFCV_REQ_FLAG_SELECT             = 0x10,       /*!< Select flag                     */
00082     RFAL_NFCV_REQ_FLAG_ADDRESS            = 0x20,       /*!< Address flag                    */
00083     RFAL_NFCV_REQ_FLAG_OPTION             = 0x40,       /*!< Option flag                     */
00084     RFAL_NFCV_REQ_FLAG_RFU                = 0x80,       /*!< RFU flag                        */
00085     RFAL_NFCV_REQ_FLAG_AFI                = 0x10,       /*!< AFI flag                        */
00086     RFAL_NFCV_REQ_FLAG_NB_SLOTS           = 0x20,       /*!< Number of Slots flag            */
00087 };
00088 
00089 /*! NFC-V Response Flags   ISO15693 2000 7.4.1 */
00090 enum{
00091     RFAL_NFCV_RES_FLAG_ERROR              = 0x01,       /*!< Error flag                      */
00092     RFAL_NFCV_RES_FLAG_RFU1               = 0x02,       /*!< RFU flag                        */
00093     RFAL_NFCV_RES_FLAG_RFU2               = 0x04,       /*!< RFU flag                        */
00094     RFAL_NFCV_RES_FLAG_EXTENSION          = 0x08,       /*!< Extension flag                  */
00095     RFAL_NFCV_RES_FLAG_RFU3               = 0x10,       /*!< RFU flag                        */
00096     RFAL_NFCV_RES_FLAG_RFU4               = 0x20,       /*!< RFU flag                        */
00097     RFAL_NFCV_RES_FLAG_RFU5               = 0x40,       /*!< RFU flag                        */
00098     RFAL_NFCV_RES_FLAG_RFU6               = 0x80,       /*!< RFU flag                        */
00099 };
00100 
00101 /*! NFC-V Error code  ISO15693 2000 7.4.2 */
00102 enum{
00103     RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED     = 0x01,       /*!< The command is not supported, code is not recognised */
00104     RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED    = 0x02,       /*!< The command is not recognised, format error occurred */
00105     RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED  = 0x03,       /*!< The option is not supported                          */
00106     RFAL_NFCV_ERROR_UNKNOWN               = 0x0F,       /*!< Unknown error                                        */
00107     RFAL_NFCV_ERROR_BLOCK_NOT_AVALIABLE   = 0x10,       /*!< The specified block is not available                 */
00108     RFAL_NFCV_ERROR_BLOCK_ALREDY_LOCKED   = 0x11,       /*!< The specified block is already locked                */
00109     RFAL_NFCV_ERROR_BLOCK_LOCKED          = 0x12,       /*!< The specified block is locked                        */
00110     RFAL_NFCV_ERROR_WRITE_FAILED          = 0x13,       /*!< The specified block was not successfully programmed  */
00111     RFAL_NFCV_ERROR_BLOCK_FAILED          = 0x14,       /*!< The specified block was not successfully locked      */
00112 };
00113 
00114 
00115 /*! NFC-V command set   ISO15693 2000 9.1 */
00116 enum
00117 {
00118     RFAL_NFCF_CMD_INVENTORY               = 0x01,      /*!< INVENTORY_REQ (Inventory) command                            */
00119     RFAL_NFCF_CMD_SLPV                    = 0x02,      /*!< SLPV_REQ (Stay quiet) command                                */
00120     RFAL_NFCF_CMD_READ_SINGLE_BLOCK       = 0x20,      /*!< Read single block command                                    */
00121     RFAL_NFCF_CMD_WRITE_SINGLE_BLOCK      = 0x21,      /*!< Write single block command                                   */
00122     RFAL_NFCF_CMD_LOCK_BLOCK              = 0x22,      /*!< Lock block command                                           */
00123     RFAL_NFCF_CMD_READ_MULTIPLE_BLOCKS    = 0x23,      /*!< Read multiple blocks command                                 */
00124     RFAL_NFCF_CMD_WRITE_MULTIPLE_BLOCKS   = 0x24,      /*!< Write multiple blocks command                                */
00125     RFAL_NFCF_CMD_SELECT                  = 0x25,      /*!< Select command                                               */
00126     RFAL_NFCF_CMD_RESET_TO_READY          = 0x26,      /*!< Reset To Ready command                                       */
00127     RFAL_NFCF_CMD_GET_SYS_INFO            = 0x2B,      /*!< Get System Information command                               */
00128     RFAL_NFCF_CMD_EXTENDED_GET_SYS_INFO   = 0x2B       /*!< Extended Get System Information command (ST Proprietary)     */
00129 };
00130 
00131 /*
00132  ******************************************************************************
00133  * GLOBAL MACROS
00134  ******************************************************************************
00135  */
00136 
00137 
00138 /*
00139 ******************************************************************************
00140 * GLOBAL TYPES
00141 ******************************************************************************
00142 */
00143 
00144 /*! NFC-V Number of slots  Digital 2.0  9.6.1 */
00145 typedef enum
00146 {
00147     RFAL_NFCV_NUM_SLOTS_1     =  0x20,   /*!< Number of slots: 1 */
00148     RFAL_NFCV_NUM_SLOTS_16    =  0x00,   /*!< Number of slots: 16 */
00149 } rfalNfcvNumSlots ;
00150 
00151 
00152 /*! NFC-V INVENTORY_RES format   Digital 2.0  9.6.2 */
00153 typedef struct
00154 {
00155     uint8_t RES_FLAG ;                   /*!< Response Flags                 */
00156     uint8_t DSFID ;                      /*!< Data Storage Format Identifier */
00157     uint8_t UID[RFAL_NFCV_UID_LEN];     /*!< NFC-V device UID               */
00158     uint8_t crc[RFAL_CRC_LEN];          /*!< CRC                            */
00159 } rfalNfcvInventoryRes ;
00160 
00161 
00162 /*! NFC-V listener device (VICC) struct  */
00163 typedef struct
00164 {
00165     rfalNfcvInventoryRes     InvRes ;     /*!< INVENTORY_RES                  */
00166     bool                    isSleep ;    /*!< Device sleeping flag           */
00167 } rfalNfcvListenDevice ;
00168 
00169 
00170 /*
00171 ******************************************************************************
00172 * GLOBAL FUNCTION PROTOTYPES
00173 ******************************************************************************
00174 */
00175 
00176 /*!
00177  *****************************************************************************
00178  * \brief  Initialize NFC-V Poller mode
00179  *
00180  * This methods configures RFAL RF layer to perform as a
00181  * NFC-F Poller/RW (ISO15693) including all default timings
00182  *
00183  * \return ERR_WRONG_STATE  : RFAL not initialized or mode not set
00184  * \return ERR_PARAM        : Incorrect bitrate
00185  * \return ERR_NONE         : No error
00186  *****************************************************************************
00187  */
00188 ReturnCode rfalNfcvPollerInitialize( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00189 
00190 /*!
00191  *****************************************************************************
00192  * \brief  NFC-V Poller Check Presence
00193  *
00194  * This method checks if a NFC-V Listen device (VICC) is present on the field
00195  * by sending an Inventory (INVENTORY_REQ)
00196  *
00197  * \param[out] invRes : If received, the INVENTORY_RES
00198  *
00199  * \return ERR_WRONG_STATE  : RFAL not initialized or incorrect mode
00200  * \return ERR_PARAM        : Invalid parameters
00201  * \return ERR_IO           : Generic internal error
00202  * \return ERR_TIMEOUT      : Timeout error, no listener device detectedd
00203  * \return ERR_NONE         : No error, one or more device in the field
00204  *****************************************************************************
00205  */
00206 ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes  *invRes, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00207 
00208 /*!
00209  *****************************************************************************
00210  * \brief NFC-F Poller Poll
00211  *
00212  * This function sends to all VICCs in field the INVENTORY command with the
00213  * given number of slots
00214  *
00215  * If more than one slot is used the following EOF need to be handled
00216  * by the caller using rfalISO15693TransceiveAnticollisionEOF()
00217  *
00218  * \param[in]  nSlots  : Number of Slots to be sent (1 or 16)
00219  * \param[in]  maskLen : Number bits on the Mask value
00220  * \param[in]  maskVal : location of the Mask value
00221  * \param[out] invRes  : location to place the INVENTORY_RES
00222  * \param[out] rcvdLen : number of bits received (without collision)
00223  *
00224  * \return ERR_WRONG_STATE  : RFAL not initialized or incorrect mode
00225  * \return ERR_PARAM        : Invalid parameters
00226  * \return ERR_IO           : Generic internal error
00227  * \return ERR_RF_COLLISION : Collision detected
00228  * \return ERR_CRC          : CRC error detected
00229  * \return ERR_PROTO        : Protocol error detected
00230  * \return ERR_NONE         : No error
00231  *****************************************************************************
00232  */
00233 ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots  nSlots, uint8_t maskLen, uint8_t *maskVal, rfalNfcvInventoryRes  *invRes, uint16_t* rcvdLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00234 
00235 /*!
00236  *****************************************************************************
00237  * \brief  NFC-V Poller Full Collision Resolution
00238  *
00239  * Performs a full Collision resolution as defined in Activity 2.0   9.3.7
00240  * Once done, the devCnt will indicate how many (if any) devices have
00241  * been identified and their details are contained on nfcvDevList
00242  *
00243  * \param[in]  devLimit     : device limit value, and size nfcaDevList
00244  * \param[out] nfcvDevList  : NFC-v listener devices list
00245  * \param[out] devCnt       : Devices found counter
00246  * \param[out] colPending   : It indicates if collsion(s) are still pending
00247  *
00248  * \return ERR_WRONG_STATE  : RFAL not initialized or mode not set
00249  * \return ERR_PARAM        : Invalid parameters
00250  * \return ERR_IO           : Generic internal error
00251  * \return ERR_NONE         : No error
00252  *****************************************************************************
00253  */
00254 ReturnCode rfalNfcvPollerCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice  *nfcvDevList, uint8_t *devCnt, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00255 
00256 /*!
00257  *****************************************************************************
00258  * \brief  NFC-V Poller Sleep
00259  *
00260  * This function is used to send the SLPV_REQ (Stay Quiet) command to put the VICC
00261  * with the given UID to state QUIET so that they do not reply to more Inventory
00262  *
00263  * \param[in]  uid          : UID of the device to be put to Sleep
00264  *
00265  * \return ERR_WRONG_STATE  : RFAL not initialized or incorrect mode
00266  * \return ERR_PARAM        : Invalid parameters
00267  * \return ERR_IO           : Generic internal error
00268  * \return ERR_NONE         : No error
00269  *****************************************************************************
00270  */
00271 ReturnCode rfalNfvPollerSleep( uint8_t flags, uint8_t* uid, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00272 
00273 /*!
00274  *****************************************************************************
00275  * \brief  NFC-V Poller Select
00276  *
00277  * Selects a device (VICC) by its UID
00278  *
00279  * \param[in]  flags        : Flags to be used: Sub-carrier; Data_rate; Option
00280  *                            for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
00281  * \param[in]  uid          : UID of the device to be put to be Selected
00282  *
00283  * \return ERR_WRONG_STATE  : RFAL not initialized or incorrect mode
00284  * \return ERR_PARAM        : Invalid parameters
00285  * \return ERR_IO           : Generic internal error
00286  * \return ERR_CRC          : CRC error detected
00287  * \return ERR_FRAMING      : Framing error detected
00288  * \return ERR_PROTO        : Protocol error detected
00289  * \return ERR_TIMEOUT      : Timeout error
00290  * \return ERR_NONE         : No error
00291  *****************************************************************************
00292  */
00293 ReturnCode rfalNfvPollerSelect( uint8_t flags, uint8_t* uid );
00294 
00295 /*!
00296  *****************************************************************************
00297  * \brief  NFC-V Poller Read Single Block
00298  *
00299  * Reads a Single Block from a device (VICC)
00300  *
00301  * \param[in]  flags        : Flags to be used: Sub-carrier; Data_rate; Option
00302  *                            for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
00303  * \param[in]  uid          : UID of the device to be put to be read
00304  *                             if not provided Select mode will be used
00305  * \param[in]  blockNum     : Number of the block to read
00306  * \param[out] rxBuf        : buffer to store response (also with RES_FLAGS)
00307  * \param[in]  rxBufLen     : length of rxBuf
00308  * \param[out] rcvLen       : number of bytes received
00309  *
00310  * \return ERR_WRONG_STATE  : RFAL not initialized or incorrect mode
00311  * \return ERR_PARAM        : Invalid parameters
00312  * \return ERR_IO           : Generic internal error
00313  * \return ERR_CRC          : CRC error detected
00314  * \return ERR_FRAMING      : Framing error detected
00315  * \return ERR_PROTO        : Protocol error detected
00316  * \return ERR_TIMEOUT      : Timeout error
00317  * \return ERR_NONE         : No error
00318  *****************************************************************************
00319  */
00320 ReturnCode rfalNfvPollerReadSingleBlock( uint8_t flags, uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
00321 
00322 /*!
00323  *****************************************************************************
00324  * \brief  NFC-V Poller Write Single Block
00325  *
00326  * Writes a Single Block from a device (VICC)
00327  *
00328  * \param[in]  flags        : Flags to be used: Sub-carrier; Data_rate; Option
00329  *                            for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
00330  * \param[in]  uid          : UID of the device to be put to be read
00331  *                             if not provided Select mode will be used
00332  * \param[in]  blockNum     : Number of the block to read
00333  * \param[in]  wrData       : data to be written on the given block
00334  * \param[in]  blockLen     : number of bytes of a block
00335  *
00336  * \return ERR_WRONG_STATE  : RFAL not initialized or incorrect mode
00337  * \return ERR_PARAM        : Invalid parameters
00338  * \return ERR_IO           : Generic internal error
00339  * \return ERR_CRC          : CRC error detected
00340  * \return ERR_FRAMING      : Framing error detected
00341  * \return ERR_PROTO        : Protocol error detected
00342  * \return ERR_TIMEOUT      : Timeout error
00343  * \return ERR_NONE         : No error
00344  *****************************************************************************
00345  */
00346 ReturnCode rfalNfvPollerWriteSingleBlock( uint8_t flags, uint8_t* uid, uint8_t blockNum, uint8_t* wrData, uint8_t blockLen );
00347 
00348 /*!
00349  *****************************************************************************
00350  * \brief  NFC-V Poller Read Multiple Blocks
00351  *
00352  * Reads Multiple Blocks from a device (VICC)
00353  *
00354  * \param[in]  flags          : Flags to be used: Sub-carrier; Data_rate; Option
00355  *                              for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
00356  * \param[in]  uid            : UID of the device to be put to be read
00357  *                               if not provided Select mode will be used
00358  * \param[in]  firstBlockNum  : first block to be read
00359  * \param[out] rxBuf          : buffer to store response (also with RES_FLAGS)
00360  * \param[in]  rxBufLen       : length of rxBuf
00361  * \param[out] rcvLen         : number of bytes received
00362  *
00363  * \return ERR_WRONG_STATE    : RFAL not initialized or incorrect mode
00364  * \return ERR_PARAM          : Invalid parameters
00365  * \return ERR_IO             : Generic internal error
00366  * \return ERR_CRC            : CRC error detected
00367  * \return ERR_FRAMING        : Framing error detected
00368  * \return ERR_PROTO          : Protocol error detected
00369  * \return ERR_TIMEOUT        : Timeout error
00370  * \return ERR_NONE           : No error
00371  *****************************************************************************
00372  */
00373 ReturnCode rfalNfvPollerReadMultipleBlocks( uint8_t flags, uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00374 
00375 ReturnCode rfalNfvSelect( uint8_t flags, uint8_t* uid, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00376 ReturnCode rfalNfvReadSingleBlock( uint8_t flags, uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00377 ReturnCode rfalNfvWriteSingleBlock( uint8_t flags, uint8_t* uid, uint8_t blockNum, uint8_t* wrData, uint8_t blockLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00378 ReturnCode rfalNfvReadMultipleBlocks( uint8_t flags, uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00379 #endif /* RFAL_NFCV_H */
00380 
00381 /**
00382   * @}
00383   *
00384   * @}
00385   *
00386   * @}
00387   */
00388