Fork of the GitHub
rfal_nfcv.cpp@0:75fc82583a41, 2019-11-14 (annotated)
- Committer:
- DiegoOstuni
- Date:
- Thu Nov 14 14:34:50 2019 +0000
- Revision:
- 0:75fc82583a41
Add files
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
DiegoOstuni | 0:75fc82583a41 | 1 | |
DiegoOstuni | 0:75fc82583a41 | 2 | /****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 3 | * @attention |
DiegoOstuni | 0:75fc82583a41 | 4 | * |
DiegoOstuni | 0:75fc82583a41 | 5 | * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> |
DiegoOstuni | 0:75fc82583a41 | 6 | * |
DiegoOstuni | 0:75fc82583a41 | 7 | * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License"); |
DiegoOstuni | 0:75fc82583a41 | 8 | * You may not use this file except in compliance with the License. |
DiegoOstuni | 0:75fc82583a41 | 9 | * You may obtain a copy of the License at: |
DiegoOstuni | 0:75fc82583a41 | 10 | * |
DiegoOstuni | 0:75fc82583a41 | 11 | * http://www.st.com/myliberty |
DiegoOstuni | 0:75fc82583a41 | 12 | * |
DiegoOstuni | 0:75fc82583a41 | 13 | * Unless required by applicable law or agreed to in writing, software |
DiegoOstuni | 0:75fc82583a41 | 14 | * distributed under the License is distributed on an "AS IS" BASIS, |
DiegoOstuni | 0:75fc82583a41 | 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, |
DiegoOstuni | 0:75fc82583a41 | 16 | * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY, |
DiegoOstuni | 0:75fc82583a41 | 17 | * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. |
DiegoOstuni | 0:75fc82583a41 | 18 | * See the License for the specific language governing permissions and |
DiegoOstuni | 0:75fc82583a41 | 19 | * limitations under the License. |
DiegoOstuni | 0:75fc82583a41 | 20 | * |
DiegoOstuni | 0:75fc82583a41 | 21 | ******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 22 | |
DiegoOstuni | 0:75fc82583a41 | 23 | /* |
DiegoOstuni | 0:75fc82583a41 | 24 | * PROJECT: ST25R391x firmware |
DiegoOstuni | 0:75fc82583a41 | 25 | * $Revision: $ |
DiegoOstuni | 0:75fc82583a41 | 26 | * LANGUAGE: ISO C99 |
DiegoOstuni | 0:75fc82583a41 | 27 | */ |
DiegoOstuni | 0:75fc82583a41 | 28 | |
DiegoOstuni | 0:75fc82583a41 | 29 | /*! \file rfal_nfcv.c |
DiegoOstuni | 0:75fc82583a41 | 30 | * |
DiegoOstuni | 0:75fc82583a41 | 31 | * \author Gustavo Patricio |
DiegoOstuni | 0:75fc82583a41 | 32 | * |
DiegoOstuni | 0:75fc82583a41 | 33 | * \brief Implementation of NFC-V Poller (ISO15693) device |
DiegoOstuni | 0:75fc82583a41 | 34 | * |
DiegoOstuni | 0:75fc82583a41 | 35 | * The definitions and helpers methods provided by this module are |
DiegoOstuni | 0:75fc82583a41 | 36 | * aligned with NFC-V (ISO15693) |
DiegoOstuni | 0:75fc82583a41 | 37 | * |
DiegoOstuni | 0:75fc82583a41 | 38 | */ |
DiegoOstuni | 0:75fc82583a41 | 39 | |
DiegoOstuni | 0:75fc82583a41 | 40 | /* |
DiegoOstuni | 0:75fc82583a41 | 41 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 42 | * INCLUDES |
DiegoOstuni | 0:75fc82583a41 | 43 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 44 | */ |
DiegoOstuni | 0:75fc82583a41 | 45 | #include <platform1.h> |
DiegoOstuni | 0:75fc82583a41 | 46 | #include "rfal_nfcv.h" |
DiegoOstuni | 0:75fc82583a41 | 47 | #include "utils.h" |
DiegoOstuni | 0:75fc82583a41 | 48 | |
DiegoOstuni | 0:75fc82583a41 | 49 | /* |
DiegoOstuni | 0:75fc82583a41 | 50 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 51 | * ENABLE SWITCH |
DiegoOstuni | 0:75fc82583a41 | 52 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 53 | */ |
DiegoOstuni | 0:75fc82583a41 | 54 | |
DiegoOstuni | 0:75fc82583a41 | 55 | #ifndef RFAL_FEATURE_NFCV |
DiegoOstuni | 0:75fc82583a41 | 56 | #error " RFAL: Module configuration missing. Please enable/disable NFC-V module by setting: RFAL_FEATURE_NFCV " |
DiegoOstuni | 0:75fc82583a41 | 57 | #endif |
DiegoOstuni | 0:75fc82583a41 | 58 | |
DiegoOstuni | 0:75fc82583a41 | 59 | #if RFAL_FEATURE_NFCV |
DiegoOstuni | 0:75fc82583a41 | 60 | |
DiegoOstuni | 0:75fc82583a41 | 61 | /* |
DiegoOstuni | 0:75fc82583a41 | 62 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 63 | * GLOBAL DEFINES |
DiegoOstuni | 0:75fc82583a41 | 64 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 65 | */ |
DiegoOstuni | 0:75fc82583a41 | 66 | |
DiegoOstuni | 0:75fc82583a41 | 67 | #define RFAL_NFCV_INV_REQ_FLAG 0x06 /*!< INVENTORY_REQ INV_FLAG Digital 2.0 9.6.1 */ |
DiegoOstuni | 0:75fc82583a41 | 68 | #define RFAL_NFCV_INV_REQ_FLAG 0x06 /*!< INVENTORY_REQ INV_FLAG Digital 2.0 9.6.1 */ |
DiegoOstuni | 0:75fc82583a41 | 69 | #define RFAL_NFCV_MASKVAL_MAX_LEN 8 /*!< Mask value max length: 64 bits (UID length) */ |
DiegoOstuni | 0:75fc82583a41 | 70 | #define RFAL_NFCV_MASKVAL_MAX_1SLOT_LEN 64 /*!< Mask value max length in 1 Slot mode in bits Digital 2.0 9.6.1.6 */ |
DiegoOstuni | 0:75fc82583a41 | 71 | #define RFAL_NFCV_MASKVAL_MAX_16SLOT_LEN 60 /*!< Mask value max length in 16 Slot mode in bits Digital 2.0 9.6.1.6 */ |
DiegoOstuni | 0:75fc82583a41 | 72 | #define RFAL_NFCV_INV_REQ_HEADER_LEN 3 /*!< INVENTORY_REQ header length (INV_FLAG, CMD, MASK_LEN) */ |
DiegoOstuni | 0:75fc82583a41 | 73 | #define RFAL_NFCV_INV_RES_LEN 10 /*!< INVENTORY_RES length */ |
DiegoOstuni | 0:75fc82583a41 | 74 | #define RFAL_NFCV_CRC_LEN 2 /*!< NFC-V CRC length */ |
DiegoOstuni | 0:75fc82583a41 | 75 | #define RFAL_NFCV_MAX_SLOTS 16 /*!< NFC-V max number of Slots */ |
DiegoOstuni | 0:75fc82583a41 | 76 | #define RFAL_NFCV_MAX_GEN_DATA_LEN (RFAL_NFCV_MAX_BLOCK_LEN + RFAL_NFCV_UID_LEN) /*!< Max number of generic data*/ |
DiegoOstuni | 0:75fc82583a41 | 77 | |
DiegoOstuni | 0:75fc82583a41 | 78 | #define RFAL_CMD_LEN 1 /*!< Commandbyte length */ |
DiegoOstuni | 0:75fc82583a41 | 79 | #define RFAL_NFCV_FLAG_LEN 1 /*!< Flag byte length */ |
DiegoOstuni | 0:75fc82583a41 | 80 | #define RFAL_NFCV_DSFI_LEN 1 /*!< DSFID length */ |
DiegoOstuni | 0:75fc82583a41 | 81 | #define RFAL_NFCV_SLPREQ_REQ_FLAG 0x22 /*!< SLPV_REQ request flags Digital 2.0 (Candidate) 9.7.1.1 */ |
DiegoOstuni | 0:75fc82583a41 | 82 | |
DiegoOstuni | 0:75fc82583a41 | 83 | #define RFAL_NFCV_MAX_COLL_SUPPORTED 16 /*!< Maximum number of collisions supported by the Anticollision loop */ |
DiegoOstuni | 0:75fc82583a41 | 84 | |
DiegoOstuni | 0:75fc82583a41 | 85 | #define RFAL_FDT_POLL_MAX rfalConvMsTo1fc(20) /*!< */ |
DiegoOstuni | 0:75fc82583a41 | 86 | |
DiegoOstuni | 0:75fc82583a41 | 87 | |
DiegoOstuni | 0:75fc82583a41 | 88 | |
DiegoOstuni | 0:75fc82583a41 | 89 | /*! Time between EOFs - ISO 15693 defines t3min depending on modulation depth and data rate |
DiegoOstuni | 0:75fc82583a41 | 90 | * - NFC Forum defines FDTV,EOF = [10 ; 20]ms ISO15693 2000 8.4 Digital 2.0 9.7.4 */ |
DiegoOstuni | 0:75fc82583a41 | 91 | #define RFAL_NFCV_FDT_EOF 5 |
DiegoOstuni | 0:75fc82583a41 | 92 | |
DiegoOstuni | 0:75fc82583a41 | 93 | |
DiegoOstuni | 0:75fc82583a41 | 94 | |
DiegoOstuni | 0:75fc82583a41 | 95 | /* |
DiegoOstuni | 0:75fc82583a41 | 96 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 97 | * GLOBAL MACROS |
DiegoOstuni | 0:75fc82583a41 | 98 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 99 | */ |
DiegoOstuni | 0:75fc82583a41 | 100 | |
DiegoOstuni | 0:75fc82583a41 | 101 | |
DiegoOstuni | 0:75fc82583a41 | 102 | /* |
DiegoOstuni | 0:75fc82583a41 | 103 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 104 | * GLOBAL TYPES |
DiegoOstuni | 0:75fc82583a41 | 105 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 106 | */ |
DiegoOstuni | 0:75fc82583a41 | 107 | |
DiegoOstuni | 0:75fc82583a41 | 108 | /*! NFC-V INVENTORY_REQ format Digital 2.0 9.6.1 */ |
DiegoOstuni | 0:75fc82583a41 | 109 | typedef struct |
DiegoOstuni | 0:75fc82583a41 | 110 | { |
DiegoOstuni | 0:75fc82583a41 | 111 | uint8_t INV_FLAG; /*!< Inventory Flags */ |
DiegoOstuni | 0:75fc82583a41 | 112 | uint8_t CMD; /*!< Command code: 01h */ |
DiegoOstuni | 0:75fc82583a41 | 113 | uint8_t MASK_LEN; /*!< Mask Value Length */ |
DiegoOstuni | 0:75fc82583a41 | 114 | uint8_t MASK_VALUE[RFAL_NFCV_MASKVAL_MAX_LEN]; /*!< Mask Value */ |
DiegoOstuni | 0:75fc82583a41 | 115 | } rfalNfcvInventoryReq; |
DiegoOstuni | 0:75fc82583a41 | 116 | |
DiegoOstuni | 0:75fc82583a41 | 117 | |
DiegoOstuni | 0:75fc82583a41 | 118 | /*! NFC-V SLP_REQ format Digital 2.0 (Candidate) 9.7.1 */ |
DiegoOstuni | 0:75fc82583a41 | 119 | typedef struct |
DiegoOstuni | 0:75fc82583a41 | 120 | { |
DiegoOstuni | 0:75fc82583a41 | 121 | uint8_t REQ_FLAG; /*!< Request Flags */ |
DiegoOstuni | 0:75fc82583a41 | 122 | uint8_t CMD; /*!< Command code: 02h */ |
DiegoOstuni | 0:75fc82583a41 | 123 | uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */ |
DiegoOstuni | 0:75fc82583a41 | 124 | } rfalNfcvSlpvReq; |
DiegoOstuni | 0:75fc82583a41 | 125 | |
DiegoOstuni | 0:75fc82583a41 | 126 | |
DiegoOstuni | 0:75fc82583a41 | 127 | /*! NFC-V Generic Req format */ |
DiegoOstuni | 0:75fc82583a41 | 128 | typedef struct |
DiegoOstuni | 0:75fc82583a41 | 129 | { |
DiegoOstuni | 0:75fc82583a41 | 130 | uint8_t REQ_FLAG; /*!< Request Flags */ |
DiegoOstuni | 0:75fc82583a41 | 131 | uint8_t CMD; /*!< Command code */ |
DiegoOstuni | 0:75fc82583a41 | 132 | union { |
DiegoOstuni | 0:75fc82583a41 | 133 | uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */ |
DiegoOstuni | 0:75fc82583a41 | 134 | uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */ |
DiegoOstuni | 0:75fc82583a41 | 135 | }payload; |
DiegoOstuni | 0:75fc82583a41 | 136 | } rfalNfcvGenericReq; |
DiegoOstuni | 0:75fc82583a41 | 137 | |
DiegoOstuni | 0:75fc82583a41 | 138 | |
DiegoOstuni | 0:75fc82583a41 | 139 | /*! NFC-V Generic Response format */ |
DiegoOstuni | 0:75fc82583a41 | 140 | typedef struct |
DiegoOstuni | 0:75fc82583a41 | 141 | { |
DiegoOstuni | 0:75fc82583a41 | 142 | uint8_t RES_FLAG; /*!< Response Flags */ |
DiegoOstuni | 0:75fc82583a41 | 143 | uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */ |
DiegoOstuni | 0:75fc82583a41 | 144 | } rfalNfcvGenericRes; |
DiegoOstuni | 0:75fc82583a41 | 145 | |
DiegoOstuni | 0:75fc82583a41 | 146 | |
DiegoOstuni | 0:75fc82583a41 | 147 | /*! Container for a collision found during Anticollsion loop */ |
DiegoOstuni | 0:75fc82583a41 | 148 | typedef struct |
DiegoOstuni | 0:75fc82583a41 | 149 | { |
DiegoOstuni | 0:75fc82583a41 | 150 | uint8_t maskLen; |
DiegoOstuni | 0:75fc82583a41 | 151 | uint8_t maskVal[RFAL_NFCV_MASKVAL_MAX_LEN]; |
DiegoOstuni | 0:75fc82583a41 | 152 | }rfalNfcvCollision; |
DiegoOstuni | 0:75fc82583a41 | 153 | |
DiegoOstuni | 0:75fc82583a41 | 154 | |
DiegoOstuni | 0:75fc82583a41 | 155 | /* |
DiegoOstuni | 0:75fc82583a41 | 156 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 157 | * LOCAL FUNCTION PROTOTYPES |
DiegoOstuni | 0:75fc82583a41 | 158 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 159 | */ |
DiegoOstuni | 0:75fc82583a41 | 160 | static ReturnCode rfalNfvParseError( uint8_t err ); |
DiegoOstuni | 0:75fc82583a41 | 161 | |
DiegoOstuni | 0:75fc82583a41 | 162 | /* |
DiegoOstuni | 0:75fc82583a41 | 163 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 164 | * LOCAL VARIABLES |
DiegoOstuni | 0:75fc82583a41 | 165 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 166 | */ |
DiegoOstuni | 0:75fc82583a41 | 167 | |
DiegoOstuni | 0:75fc82583a41 | 168 | /* |
DiegoOstuni | 0:75fc82583a41 | 169 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 170 | * LOCAL FUNCTIONS |
DiegoOstuni | 0:75fc82583a41 | 171 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 172 | */ |
DiegoOstuni | 0:75fc82583a41 | 173 | |
DiegoOstuni | 0:75fc82583a41 | 174 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 175 | static ReturnCode rfalNfvParseError( uint8_t err ) |
DiegoOstuni | 0:75fc82583a41 | 176 | { |
DiegoOstuni | 0:75fc82583a41 | 177 | switch(err) |
DiegoOstuni | 0:75fc82583a41 | 178 | { |
DiegoOstuni | 0:75fc82583a41 | 179 | case RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED: |
DiegoOstuni | 0:75fc82583a41 | 180 | case RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED: |
DiegoOstuni | 0:75fc82583a41 | 181 | return ERR_NOTSUPP; |
DiegoOstuni | 0:75fc82583a41 | 182 | |
DiegoOstuni | 0:75fc82583a41 | 183 | case RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED: |
DiegoOstuni | 0:75fc82583a41 | 184 | return ERR_PROTO; |
DiegoOstuni | 0:75fc82583a41 | 185 | |
DiegoOstuni | 0:75fc82583a41 | 186 | case RFAL_NFCV_ERROR_WRITE_FAILED: |
DiegoOstuni | 0:75fc82583a41 | 187 | return ERR_WRITE; |
DiegoOstuni | 0:75fc82583a41 | 188 | |
DiegoOstuni | 0:75fc82583a41 | 189 | default: |
DiegoOstuni | 0:75fc82583a41 | 190 | return ERR_REQUEST; |
DiegoOstuni | 0:75fc82583a41 | 191 | } |
DiegoOstuni | 0:75fc82583a41 | 192 | } |
DiegoOstuni | 0:75fc82583a41 | 193 | |
DiegoOstuni | 0:75fc82583a41 | 194 | /* |
DiegoOstuni | 0:75fc82583a41 | 195 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 196 | * GLOBAL FUNCTIONS |
DiegoOstuni | 0:75fc82583a41 | 197 | ****************************************************************************** |
DiegoOstuni | 0:75fc82583a41 | 198 | */ |
DiegoOstuni | 0:75fc82583a41 | 199 | |
DiegoOstuni | 0:75fc82583a41 | 200 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 201 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 202 | { |
DiegoOstuni | 0:75fc82583a41 | 203 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 204 | |
DiegoOstuni | 0:75fc82583a41 | 205 | EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCV, RFAL_BR_26p48, RFAL_BR_26p48, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ); |
DiegoOstuni | 0:75fc82583a41 | 206 | rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); |
DiegoOstuni | 0:75fc82583a41 | 207 | |
DiegoOstuni | 0:75fc82583a41 | 208 | rfalSetGT( RFAL_GT_NFCV_ADJUSTED ); |
DiegoOstuni | 0:75fc82583a41 | 209 | rfalSetFDTListen( RFAL_FDT_LISTEN_NFCV_POLLER ); |
DiegoOstuni | 0:75fc82583a41 | 210 | rfalSetFDTPoll( RFAL_FDT_POLL_NFCV_POLLER ); |
DiegoOstuni | 0:75fc82583a41 | 211 | |
DiegoOstuni | 0:75fc82583a41 | 212 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 213 | } |
DiegoOstuni | 0:75fc82583a41 | 214 | |
DiegoOstuni | 0:75fc82583a41 | 215 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 216 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 217 | { |
DiegoOstuni | 0:75fc82583a41 | 218 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 219 | |
DiegoOstuni | 0:75fc82583a41 | 220 | /* INVENTORY_REQ with 1 slot and no Mask Activity 2.0 (Candidate) 9.2.3.32 */ |
DiegoOstuni | 0:75fc82583a41 | 221 | ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, 0, NULL, invRes, NULL, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 222 | |
DiegoOstuni | 0:75fc82583a41 | 223 | if( (ret == ERR_RF_COLLISION) || (ret == ERR_CRC) || |
DiegoOstuni | 0:75fc82583a41 | 224 | (ret == ERR_FRAMING) || (ret == ERR_PROTO) ) |
DiegoOstuni | 0:75fc82583a41 | 225 | { |
DiegoOstuni | 0:75fc82583a41 | 226 | ret = ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 227 | } |
DiegoOstuni | 0:75fc82583a41 | 228 | |
DiegoOstuni | 0:75fc82583a41 | 229 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 230 | } |
DiegoOstuni | 0:75fc82583a41 | 231 | |
DiegoOstuni | 0:75fc82583a41 | 232 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 233 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 234 | { |
DiegoOstuni | 0:75fc82583a41 | 235 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 236 | rfalNfcvInventoryReq invReq; |
DiegoOstuni | 0:75fc82583a41 | 237 | uint16_t rxLen; |
DiegoOstuni | 0:75fc82583a41 | 238 | |
DiegoOstuni | 0:75fc82583a41 | 239 | if( ((maskVal == NULL) && (maskLen != 0)) || (invRes == NULL) ) |
DiegoOstuni | 0:75fc82583a41 | 240 | { |
DiegoOstuni | 0:75fc82583a41 | 241 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 242 | } |
DiegoOstuni | 0:75fc82583a41 | 243 | |
DiegoOstuni | 0:75fc82583a41 | 244 | invReq.INV_FLAG = (RFAL_NFCV_INV_REQ_FLAG | nSlots); |
DiegoOstuni | 0:75fc82583a41 | 245 | invReq.CMD = RFAL_NFCF_CMD_INVENTORY; |
DiegoOstuni | 0:75fc82583a41 | 246 | invReq.MASK_LEN = MIN( maskLen, ((nSlots == RFAL_NFCV_NUM_SLOTS_1) ? RFAL_NFCV_MASKVAL_MAX_1SLOT_LEN : RFAL_NFCV_MASKVAL_MAX_16SLOT_LEN) ); /* Digital 2.0 9.6.1.6 */ |
DiegoOstuni | 0:75fc82583a41 | 247 | ST_MEMCPY( invReq.MASK_VALUE, maskVal, rfalConvBitsToBytes(invReq.MASK_LEN) ); |
DiegoOstuni | 0:75fc82583a41 | 248 | |
DiegoOstuni | 0:75fc82583a41 | 249 | ret = rfalISO15693TransceiveAnticollisionFrame( (uint8_t*)&invReq, (RFAL_NFCV_INV_REQ_HEADER_LEN + rfalConvBitsToBytes(invReq.MASK_LEN)), (uint8_t*)invRes, sizeof(rfalNfcvInventoryRes), &rxLen, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 250 | |
DiegoOstuni | 0:75fc82583a41 | 251 | /* Check for optional output parameter */ |
DiegoOstuni | 0:75fc82583a41 | 252 | if( rcvdLen != NULL ) |
DiegoOstuni | 0:75fc82583a41 | 253 | { |
DiegoOstuni | 0:75fc82583a41 | 254 | *rcvdLen = rxLen; |
DiegoOstuni | 0:75fc82583a41 | 255 | } |
DiegoOstuni | 0:75fc82583a41 | 256 | |
DiegoOstuni | 0:75fc82583a41 | 257 | if( ret == ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 258 | { |
DiegoOstuni | 0:75fc82583a41 | 259 | if( rxLen != rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) ) |
DiegoOstuni | 0:75fc82583a41 | 260 | { |
DiegoOstuni | 0:75fc82583a41 | 261 | return ERR_PROTO; |
DiegoOstuni | 0:75fc82583a41 | 262 | } |
DiegoOstuni | 0:75fc82583a41 | 263 | } |
DiegoOstuni | 0:75fc82583a41 | 264 | |
DiegoOstuni | 0:75fc82583a41 | 265 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 266 | } |
DiegoOstuni | 0:75fc82583a41 | 267 | |
DiegoOstuni | 0:75fc82583a41 | 268 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 269 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 270 | { |
DiegoOstuni | 0:75fc82583a41 | 271 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 272 | uint8_t slotNum; |
DiegoOstuni | 0:75fc82583a41 | 273 | uint16_t rcvdLen; |
DiegoOstuni | 0:75fc82583a41 | 274 | uint8_t colIt; |
DiegoOstuni | 0:75fc82583a41 | 275 | uint8_t colCnt; |
DiegoOstuni | 0:75fc82583a41 | 276 | /* bool colPending; */ |
DiegoOstuni | 0:75fc82583a41 | 277 | rfalNfcvCollision colFound[RFAL_NFCV_MAX_COLL_SUPPORTED]; |
DiegoOstuni | 0:75fc82583a41 | 278 | |
DiegoOstuni | 0:75fc82583a41 | 279 | /* NO_WARNING(colPending); */ |
DiegoOstuni | 0:75fc82583a41 | 280 | |
DiegoOstuni | 0:75fc82583a41 | 281 | if( (nfcvDevList == NULL) || (devCnt == NULL) ) |
DiegoOstuni | 0:75fc82583a41 | 282 | { |
DiegoOstuni | 0:75fc82583a41 | 283 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 284 | } |
DiegoOstuni | 0:75fc82583a41 | 285 | |
DiegoOstuni | 0:75fc82583a41 | 286 | /* Initialize parameters */ |
DiegoOstuni | 0:75fc82583a41 | 287 | *devCnt = 0; |
DiegoOstuni | 0:75fc82583a41 | 288 | colIt = 0; |
DiegoOstuni | 0:75fc82583a41 | 289 | colCnt = 0; |
DiegoOstuni | 0:75fc82583a41 | 290 | /* colPending = false; */ |
DiegoOstuni | 0:75fc82583a41 | 291 | ST_MEMSET(nfcvDevList, 0x00, (sizeof(rfalNfcvListenDevice)*devLimit) ); |
DiegoOstuni | 0:75fc82583a41 | 292 | ST_MEMSET(colFound, 0x00, (sizeof(rfalNfcvCollision)*RFAL_NFCV_MAX_COLL_SUPPORTED) ); |
DiegoOstuni | 0:75fc82583a41 | 293 | |
DiegoOstuni | 0:75fc82583a41 | 294 | |
DiegoOstuni | 0:75fc82583a41 | 295 | /* Send INVENTORY_REQ with one slot Activity 2.0 9.3.7.1 (Symbol 0) */ |
DiegoOstuni | 0:75fc82583a41 | 296 | ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, 0, NULL, &nfcvDevList->InvRes, NULL, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 297 | |
DiegoOstuni | 0:75fc82583a41 | 298 | if( ret == ERR_TIMEOUT ) /* Exit if no device found Activity 2.0 9.3.7.2 (Symbol 1) */ |
DiegoOstuni | 0:75fc82583a41 | 299 | { |
DiegoOstuni | 0:75fc82583a41 | 300 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 301 | } |
DiegoOstuni | 0:75fc82583a41 | 302 | if( ret == ERR_NONE ) /* Device found without transmission error/collision Activity 2.0 9.3.7.3 (Symbol 2) */ |
DiegoOstuni | 0:75fc82583a41 | 303 | { |
DiegoOstuni | 0:75fc82583a41 | 304 | (*devCnt)++; |
DiegoOstuni | 0:75fc82583a41 | 305 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 306 | } |
DiegoOstuni | 0:75fc82583a41 | 307 | |
DiegoOstuni | 0:75fc82583a41 | 308 | /* A Collision has been identified Activity 2.0 9.3.7.2 (Symbol 3) */ |
DiegoOstuni | 0:75fc82583a41 | 309 | /* colPending = true; */ |
DiegoOstuni | 0:75fc82583a41 | 310 | |
DiegoOstuni | 0:75fc82583a41 | 311 | /* Check if the Collision Resolution is set to perform only Collision detection Activity 2.0 9.3.7.5 (Symbol 4)*/ |
DiegoOstuni | 0:75fc82583a41 | 312 | if( devLimit == 0 ) |
DiegoOstuni | 0:75fc82583a41 | 313 | { |
DiegoOstuni | 0:75fc82583a41 | 314 | return ERR_RF_COLLISION; |
DiegoOstuni | 0:75fc82583a41 | 315 | } |
DiegoOstuni | 0:75fc82583a41 | 316 | |
DiegoOstuni | 0:75fc82583a41 | 317 | |
DiegoOstuni | 0:75fc82583a41 | 318 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 319 | /* Collisions pending, Anticollision loop must be executed */ |
DiegoOstuni | 0:75fc82583a41 | 320 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 321 | |
DiegoOstuni | 0:75fc82583a41 | 322 | /* Execute until all collisions are resolved Activity 2.0 9.3.7.16 (Symbol 17) */ |
DiegoOstuni | 0:75fc82583a41 | 323 | do |
DiegoOstuni | 0:75fc82583a41 | 324 | { |
DiegoOstuni | 0:75fc82583a41 | 325 | /* Activity 2.0 9.3.7.5 (Symbol 6) */ |
DiegoOstuni | 0:75fc82583a41 | 326 | slotNum = 0; |
DiegoOstuni | 0:75fc82583a41 | 327 | /* colPending = false; */ |
DiegoOstuni | 0:75fc82583a41 | 328 | |
DiegoOstuni | 0:75fc82583a41 | 329 | |
DiegoOstuni | 0:75fc82583a41 | 330 | /* Send INVENTORY_REQ with 16 slots Activity 2.0 9.3.7.7 (Symbol 8) */ |
DiegoOstuni | 0:75fc82583a41 | 331 | ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_16, colFound[colIt].maskLen, colFound[colIt].maskVal, &nfcvDevList[(*devCnt)].InvRes, &rcvdLen, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 332 | |
DiegoOstuni | 0:75fc82583a41 | 333 | /* If collision have already been found, move to next one */ |
DiegoOstuni | 0:75fc82583a41 | 334 | if( colCnt > 0 ) |
DiegoOstuni | 0:75fc82583a41 | 335 | { |
DiegoOstuni | 0:75fc82583a41 | 336 | colIt++; |
DiegoOstuni | 0:75fc82583a41 | 337 | } |
DiegoOstuni | 0:75fc82583a41 | 338 | |
DiegoOstuni | 0:75fc82583a41 | 339 | do |
DiegoOstuni | 0:75fc82583a41 | 340 | { |
DiegoOstuni | 0:75fc82583a41 | 341 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 342 | if( ret != ERR_TIMEOUT ) |
DiegoOstuni | 0:75fc82583a41 | 343 | { |
DiegoOstuni | 0:75fc82583a41 | 344 | if( ret == ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 345 | { |
DiegoOstuni | 0:75fc82583a41 | 346 | /* Check if the device found is already on the list and its response is a valid INVENTORY_RES */ |
DiegoOstuni | 0:75fc82583a41 | 347 | if( rcvdLen == rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) ) |
DiegoOstuni | 0:75fc82583a41 | 348 | { |
DiegoOstuni | 0:75fc82583a41 | 349 | /* Activity 2.0 9.3.7.15 (Symbol 16) */ |
DiegoOstuni | 0:75fc82583a41 | 350 | (*devCnt)++; |
DiegoOstuni | 0:75fc82583a41 | 351 | } |
DiegoOstuni | 0:75fc82583a41 | 352 | } |
DiegoOstuni | 0:75fc82583a41 | 353 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 354 | else if(ret == ERR_RF_COLLISION) |
DiegoOstuni | 0:75fc82583a41 | 355 | { |
DiegoOstuni | 0:75fc82583a41 | 356 | /* Activity 2.0 9.3.7.15 (Symbol 16) */ |
DiegoOstuni | 0:75fc82583a41 | 357 | /* colPending = true; */ |
DiegoOstuni | 0:75fc82583a41 | 358 | |
DiegoOstuni | 0:75fc82583a41 | 359 | /* Ensure that the frame received has at least the FLAGS + DSFI */ |
DiegoOstuni | 0:75fc82583a41 | 360 | if( rcvdLen <= rfalConvBytesToBits( RFAL_NFCV_FLAG_LEN + RFAL_NFCV_DSFI_LEN ) ) |
DiegoOstuni | 0:75fc82583a41 | 361 | { |
DiegoOstuni | 0:75fc82583a41 | 362 | return ERR_RF_COLLISION; |
DiegoOstuni | 0:75fc82583a41 | 363 | } |
DiegoOstuni | 0:75fc82583a41 | 364 | |
DiegoOstuni | 0:75fc82583a41 | 365 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 366 | /* Ensure that this collision still fits on the container */ |
DiegoOstuni | 0:75fc82583a41 | 367 | if( colCnt < RFAL_NFCV_MAX_COLL_SUPPORTED ) |
DiegoOstuni | 0:75fc82583a41 | 368 | { |
DiegoOstuni | 0:75fc82583a41 | 369 | /* Store this collision on the container to be resolved later */ |
DiegoOstuni | 0:75fc82583a41 | 370 | colFound[colCnt].maskLen = ( rcvdLen - rfalConvBytesToBits( RFAL_NFCV_FLAG_LEN + RFAL_NFCV_DSFI_LEN ) ); |
DiegoOstuni | 0:75fc82583a41 | 371 | ST_MEMCPY(colFound[colCnt].maskVal, nfcvDevList[(*devCnt)].InvRes.UID, RFAL_NFCV_UID_LEN); |
DiegoOstuni | 0:75fc82583a41 | 372 | colCnt++; |
DiegoOstuni | 0:75fc82583a41 | 373 | } |
DiegoOstuni | 0:75fc82583a41 | 374 | } |
DiegoOstuni | 0:75fc82583a41 | 375 | } |
DiegoOstuni | 0:75fc82583a41 | 376 | |
DiegoOstuni | 0:75fc82583a41 | 377 | /* Check if devices found have reached device limit Activity 2.0 9.3.7.15 (Symbol 16) */ |
DiegoOstuni | 0:75fc82583a41 | 378 | if( *devCnt >= devLimit ) |
DiegoOstuni | 0:75fc82583a41 | 379 | { |
DiegoOstuni | 0:75fc82583a41 | 380 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 381 | } |
DiegoOstuni | 0:75fc82583a41 | 382 | |
DiegoOstuni | 0:75fc82583a41 | 383 | platformDelay(RFAL_NFCV_FDT_EOF); /* Fulfil FDT EOF */ |
DiegoOstuni | 0:75fc82583a41 | 384 | ret = rfalISO15693TransceiveAnticollisionEOF( (uint8_t*)&nfcvDevList[(*devCnt)].InvRes, sizeof(rfalNfcvInventoryRes), &rcvdLen, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 385 | slotNum++; |
DiegoOstuni | 0:75fc82583a41 | 386 | |
DiegoOstuni | 0:75fc82583a41 | 387 | } |
DiegoOstuni | 0:75fc82583a41 | 388 | while( slotNum < RFAL_NFCV_MAX_SLOTS ); /* Slot loop */ |
DiegoOstuni | 0:75fc82583a41 | 389 | }while( colIt < colCnt ); /* Collisions found loop */ |
DiegoOstuni | 0:75fc82583a41 | 390 | |
DiegoOstuni | 0:75fc82583a41 | 391 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 392 | } |
DiegoOstuni | 0:75fc82583a41 | 393 | |
DiegoOstuni | 0:75fc82583a41 | 394 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 395 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 396 | { |
DiegoOstuni | 0:75fc82583a41 | 397 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 398 | rfalNfcvSlpvReq slpReq; |
DiegoOstuni | 0:75fc82583a41 | 399 | uint8_t rxBuf; /* dummy buffer, just to perform Rx */ |
DiegoOstuni | 0:75fc82583a41 | 400 | |
DiegoOstuni | 0:75fc82583a41 | 401 | if( uid == NULL ) |
DiegoOstuni | 0:75fc82583a41 | 402 | { |
DiegoOstuni | 0:75fc82583a41 | 403 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 404 | } |
DiegoOstuni | 0:75fc82583a41 | 405 | |
DiegoOstuni | 0:75fc82583a41 | 406 | /* Compute SLPV_REQ */ |
DiegoOstuni | 0:75fc82583a41 | 407 | slpReq.REQ_FLAG = (flags | RFAL_NFCV_REQ_FLAG_ADDRESS); /* Should be with UID according Digital 2.0 (Candidate) 9.7.1.1 */ |
DiegoOstuni | 0:75fc82583a41 | 408 | slpReq.CMD = RFAL_NFCF_CMD_SLPV; |
DiegoOstuni | 0:75fc82583a41 | 409 | ST_MEMCPY( slpReq.UID, uid, RFAL_NFCV_UID_LEN ); |
DiegoOstuni | 0:75fc82583a41 | 410 | |
DiegoOstuni | 0:75fc82583a41 | 411 | /* NFC Forum device SHALL wait at least FDTVpp to consider the SLPV acknowledged (FDTVpp = FDTVpoll) Digital 2.0 (Candidate) 9.7 9.8.2 */ |
DiegoOstuni | 0:75fc82583a41 | 412 | ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slpReq, sizeof(rfalNfcvSlpvReq), &rxBuf, sizeof(rxBuf), NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_NFCV_POLLER, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 413 | if( ret != ERR_TIMEOUT ) |
DiegoOstuni | 0:75fc82583a41 | 414 | { |
DiegoOstuni | 0:75fc82583a41 | 415 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 416 | } |
DiegoOstuni | 0:75fc82583a41 | 417 | |
DiegoOstuni | 0:75fc82583a41 | 418 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 419 | } |
DiegoOstuni | 0:75fc82583a41 | 420 | |
DiegoOstuni | 0:75fc82583a41 | 421 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 422 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 423 | { |
DiegoOstuni | 0:75fc82583a41 | 424 | uint16_t rcvLen; |
DiegoOstuni | 0:75fc82583a41 | 425 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 426 | rfalNfcvGenericReq req; |
DiegoOstuni | 0:75fc82583a41 | 427 | rfalNfcvGenericRes res; |
DiegoOstuni | 0:75fc82583a41 | 428 | |
DiegoOstuni | 0:75fc82583a41 | 429 | if( uid == NULL ) |
DiegoOstuni | 0:75fc82583a41 | 430 | { |
DiegoOstuni | 0:75fc82583a41 | 431 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 432 | } |
DiegoOstuni | 0:75fc82583a41 | 433 | |
DiegoOstuni | 0:75fc82583a41 | 434 | /* Compute Request Command */ |
DiegoOstuni | 0:75fc82583a41 | 435 | req.REQ_FLAG = (flags | RFAL_NFCV_REQ_FLAG_ADDRESS); |
DiegoOstuni | 0:75fc82583a41 | 436 | req.CMD = RFAL_NFCF_CMD_SELECT; |
DiegoOstuni | 0:75fc82583a41 | 437 | ST_MEMCPY( req.payload.UID, uid, RFAL_NFCV_UID_LEN ); |
DiegoOstuni | 0:75fc82583a41 | 438 | |
DiegoOstuni | 0:75fc82583a41 | 439 | ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, (RFAL_CMD_LEN + RFAL_NFCV_FLAG_LEN + RFAL_NFCV_UID_LEN), (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 440 | if( ret != ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 441 | { |
DiegoOstuni | 0:75fc82583a41 | 442 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 443 | } |
DiegoOstuni | 0:75fc82583a41 | 444 | |
DiegoOstuni | 0:75fc82583a41 | 445 | /* Check if the response minimum length has been received */ |
DiegoOstuni | 0:75fc82583a41 | 446 | if( rcvLen < RFAL_NFCV_FLAG_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 447 | { |
DiegoOstuni | 0:75fc82583a41 | 448 | return ERR_PROTO; |
DiegoOstuni | 0:75fc82583a41 | 449 | } |
DiegoOstuni | 0:75fc82583a41 | 450 | |
DiegoOstuni | 0:75fc82583a41 | 451 | /* Check if an error has been signalled */ |
DiegoOstuni | 0:75fc82583a41 | 452 | if( res.RES_FLAG & RFAL_NFCV_RES_FLAG_ERROR ) |
DiegoOstuni | 0:75fc82583a41 | 453 | { |
DiegoOstuni | 0:75fc82583a41 | 454 | return rfalNfvParseError( *res.data ); |
DiegoOstuni | 0:75fc82583a41 | 455 | } |
DiegoOstuni | 0:75fc82583a41 | 456 | |
DiegoOstuni | 0:75fc82583a41 | 457 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 458 | } |
DiegoOstuni | 0:75fc82583a41 | 459 | |
DiegoOstuni | 0:75fc82583a41 | 460 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 461 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 462 | { |
DiegoOstuni | 0:75fc82583a41 | 463 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 464 | rfalNfcvGenericReq req; |
DiegoOstuni | 0:75fc82583a41 | 465 | rfalNfcvGenericRes *res; |
DiegoOstuni | 0:75fc82583a41 | 466 | uint8_t msgIt; |
DiegoOstuni | 0:75fc82583a41 | 467 | |
DiegoOstuni | 0:75fc82583a41 | 468 | msgIt = 0; |
DiegoOstuni | 0:75fc82583a41 | 469 | res = (rfalNfcvGenericRes*)rxBuf; |
DiegoOstuni | 0:75fc82583a41 | 470 | |
DiegoOstuni | 0:75fc82583a41 | 471 | /* Compute Request Command */ |
DiegoOstuni | 0:75fc82583a41 | 472 | req.REQ_FLAG = (flags & (~RFAL_NFCV_REQ_FLAG_ADDRESS & ~RFAL_NFCV_REQ_FLAG_SELECT)); |
DiegoOstuni | 0:75fc82583a41 | 473 | req.CMD = RFAL_NFCF_CMD_READ_SINGLE_BLOCK; |
DiegoOstuni | 0:75fc82583a41 | 474 | |
DiegoOstuni | 0:75fc82583a41 | 475 | /* Check if request is to be sent in Addressed or Selected mode */ |
DiegoOstuni | 0:75fc82583a41 | 476 | if( uid != NULL ) |
DiegoOstuni | 0:75fc82583a41 | 477 | { |
DiegoOstuni | 0:75fc82583a41 | 478 | req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_ADDRESS; |
DiegoOstuni | 0:75fc82583a41 | 479 | ST_MEMCPY( req.payload.UID, uid, RFAL_NFCV_UID_LEN ); |
DiegoOstuni | 0:75fc82583a41 | 480 | msgIt += RFAL_NFCV_UID_LEN; |
DiegoOstuni | 0:75fc82583a41 | 481 | req.payload.data[ (RFAL_NFCV_UID_LEN + msgIt++) ] = blockNum; |
DiegoOstuni | 0:75fc82583a41 | 482 | } |
DiegoOstuni | 0:75fc82583a41 | 483 | else |
DiegoOstuni | 0:75fc82583a41 | 484 | { |
DiegoOstuni | 0:75fc82583a41 | 485 | req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_SELECT; |
DiegoOstuni | 0:75fc82583a41 | 486 | req.payload.data[msgIt++] = blockNum; |
DiegoOstuni | 0:75fc82583a41 | 487 | } |
DiegoOstuni | 0:75fc82583a41 | 488 | |
DiegoOstuni | 0:75fc82583a41 | 489 | /* Transceive Command */ |
DiegoOstuni | 0:75fc82583a41 | 490 | ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, (RFAL_CMD_LEN + RFAL_NFCV_FLAG_LEN + msgIt), rxBuf, rxBufLen, rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 491 | if( ret != ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 492 | { |
DiegoOstuni | 0:75fc82583a41 | 493 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 494 | } |
DiegoOstuni | 0:75fc82583a41 | 495 | |
DiegoOstuni | 0:75fc82583a41 | 496 | /* Check if the response minimum length has been received */ |
DiegoOstuni | 0:75fc82583a41 | 497 | if( (*rcvLen) < RFAL_NFCV_FLAG_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 498 | { |
DiegoOstuni | 0:75fc82583a41 | 499 | return ERR_PROTO; |
DiegoOstuni | 0:75fc82583a41 | 500 | } |
DiegoOstuni | 0:75fc82583a41 | 501 | |
DiegoOstuni | 0:75fc82583a41 | 502 | /* Check if an error has been signalled */ |
DiegoOstuni | 0:75fc82583a41 | 503 | if( res->RES_FLAG & RFAL_NFCV_RES_FLAG_ERROR ) |
DiegoOstuni | 0:75fc82583a41 | 504 | { |
DiegoOstuni | 0:75fc82583a41 | 505 | return rfalNfvParseError( *(res->data) ); |
DiegoOstuni | 0:75fc82583a41 | 506 | } |
DiegoOstuni | 0:75fc82583a41 | 507 | |
DiegoOstuni | 0:75fc82583a41 | 508 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 509 | } |
DiegoOstuni | 0:75fc82583a41 | 510 | |
DiegoOstuni | 0:75fc82583a41 | 511 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 512 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 513 | { |
DiegoOstuni | 0:75fc82583a41 | 514 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 515 | uint16_t rcvLen; |
DiegoOstuni | 0:75fc82583a41 | 516 | rfalNfcvGenericReq req; |
DiegoOstuni | 0:75fc82583a41 | 517 | rfalNfcvGenericRes res; |
DiegoOstuni | 0:75fc82583a41 | 518 | uint8_t msgIt; |
DiegoOstuni | 0:75fc82583a41 | 519 | |
DiegoOstuni | 0:75fc82583a41 | 520 | if( blockLen > RFAL_NFCV_MAX_BLOCK_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 521 | { |
DiegoOstuni | 0:75fc82583a41 | 522 | return ERR_PARAM; |
DiegoOstuni | 0:75fc82583a41 | 523 | } |
DiegoOstuni | 0:75fc82583a41 | 524 | |
DiegoOstuni | 0:75fc82583a41 | 525 | msgIt = 0; |
DiegoOstuni | 0:75fc82583a41 | 526 | |
DiegoOstuni | 0:75fc82583a41 | 527 | /* Compute Request Command */ |
DiegoOstuni | 0:75fc82583a41 | 528 | req.REQ_FLAG = (flags & (~RFAL_NFCV_REQ_FLAG_ADDRESS & ~RFAL_NFCV_REQ_FLAG_SELECT)); |
DiegoOstuni | 0:75fc82583a41 | 529 | req.CMD = RFAL_NFCF_CMD_WRITE_SINGLE_BLOCK; |
DiegoOstuni | 0:75fc82583a41 | 530 | |
DiegoOstuni | 0:75fc82583a41 | 531 | /* Check if request is to be sent in Addressed or Selected mode */ |
DiegoOstuni | 0:75fc82583a41 | 532 | if( uid != NULL ) |
DiegoOstuni | 0:75fc82583a41 | 533 | { |
DiegoOstuni | 0:75fc82583a41 | 534 | req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_ADDRESS; |
DiegoOstuni | 0:75fc82583a41 | 535 | ST_MEMCPY( req.payload.UID, uid, RFAL_NFCV_UID_LEN ); |
DiegoOstuni | 0:75fc82583a41 | 536 | msgIt += RFAL_NFCV_UID_LEN; |
DiegoOstuni | 0:75fc82583a41 | 537 | req.payload.data[msgIt++] = blockNum; |
DiegoOstuni | 0:75fc82583a41 | 538 | ST_MEMCPY( &req.payload.data[msgIt], wrData, blockLen ); |
DiegoOstuni | 0:75fc82583a41 | 539 | msgIt += blockLen; |
DiegoOstuni | 0:75fc82583a41 | 540 | } |
DiegoOstuni | 0:75fc82583a41 | 541 | else |
DiegoOstuni | 0:75fc82583a41 | 542 | { |
DiegoOstuni | 0:75fc82583a41 | 543 | req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_SELECT; |
DiegoOstuni | 0:75fc82583a41 | 544 | req.payload.data[msgIt++] = blockNum; |
DiegoOstuni | 0:75fc82583a41 | 545 | ST_MEMCPY( &req.payload.data[msgIt], wrData, blockLen ); |
DiegoOstuni | 0:75fc82583a41 | 546 | msgIt += blockLen; |
DiegoOstuni | 0:75fc82583a41 | 547 | } |
DiegoOstuni | 0:75fc82583a41 | 548 | |
DiegoOstuni | 0:75fc82583a41 | 549 | /* Transceive Command */ |
DiegoOstuni | 0:75fc82583a41 | 550 | ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, (RFAL_CMD_LEN + RFAL_NFCV_FLAG_LEN + msgIt), (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 551 | |
DiegoOstuni | 0:75fc82583a41 | 552 | if( ret != ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 553 | { |
DiegoOstuni | 0:75fc82583a41 | 554 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 555 | } |
DiegoOstuni | 0:75fc82583a41 | 556 | |
DiegoOstuni | 0:75fc82583a41 | 557 | /* Check if the response minimum length has been received */ |
DiegoOstuni | 0:75fc82583a41 | 558 | if( rcvLen < RFAL_NFCV_FLAG_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 559 | { |
DiegoOstuni | 0:75fc82583a41 | 560 | return ERR_PROTO; |
DiegoOstuni | 0:75fc82583a41 | 561 | } |
DiegoOstuni | 0:75fc82583a41 | 562 | |
DiegoOstuni | 0:75fc82583a41 | 563 | /* Check if an error has been signalled */ |
DiegoOstuni | 0:75fc82583a41 | 564 | if( res.RES_FLAG & RFAL_NFCV_RES_FLAG_ERROR ) |
DiegoOstuni | 0:75fc82583a41 | 565 | { |
DiegoOstuni | 0:75fc82583a41 | 566 | return rfalNfvParseError( *res.data ); |
DiegoOstuni | 0:75fc82583a41 | 567 | } |
DiegoOstuni | 0:75fc82583a41 | 568 | |
DiegoOstuni | 0:75fc82583a41 | 569 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 570 | } |
DiegoOstuni | 0:75fc82583a41 | 571 | |
DiegoOstuni | 0:75fc82583a41 | 572 | /*******************************************************************************/ |
DiegoOstuni | 0:75fc82583a41 | 573 | 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 ) |
DiegoOstuni | 0:75fc82583a41 | 574 | { |
DiegoOstuni | 0:75fc82583a41 | 575 | ReturnCode ret; |
DiegoOstuni | 0:75fc82583a41 | 576 | rfalNfcvGenericReq req; |
DiegoOstuni | 0:75fc82583a41 | 577 | rfalNfcvGenericRes *res; |
DiegoOstuni | 0:75fc82583a41 | 578 | uint8_t msgIt; |
DiegoOstuni | 0:75fc82583a41 | 579 | |
DiegoOstuni | 0:75fc82583a41 | 580 | msgIt = 0; |
DiegoOstuni | 0:75fc82583a41 | 581 | res = (rfalNfcvGenericRes*)rxBuf; |
DiegoOstuni | 0:75fc82583a41 | 582 | |
DiegoOstuni | 0:75fc82583a41 | 583 | /* Compute Request Command */ |
DiegoOstuni | 0:75fc82583a41 | 584 | req.REQ_FLAG = (flags & (~RFAL_NFCV_REQ_FLAG_ADDRESS & ~RFAL_NFCV_REQ_FLAG_SELECT)); |
DiegoOstuni | 0:75fc82583a41 | 585 | req.CMD = RFAL_NFCF_CMD_READ_MULTIPLE_BLOCKS; |
DiegoOstuni | 0:75fc82583a41 | 586 | |
DiegoOstuni | 0:75fc82583a41 | 587 | /* Check if request is to be sent in Addressed or Selected mode */ |
DiegoOstuni | 0:75fc82583a41 | 588 | if( uid != NULL ) |
DiegoOstuni | 0:75fc82583a41 | 589 | { |
DiegoOstuni | 0:75fc82583a41 | 590 | req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_ADDRESS; |
DiegoOstuni | 0:75fc82583a41 | 591 | ST_MEMCPY( req.payload.UID, uid, RFAL_NFCV_UID_LEN ); |
DiegoOstuni | 0:75fc82583a41 | 592 | msgIt += RFAL_NFCV_UID_LEN; |
DiegoOstuni | 0:75fc82583a41 | 593 | req.payload.data[ (RFAL_NFCV_UID_LEN + msgIt++) ] = firstBlockNum; |
DiegoOstuni | 0:75fc82583a41 | 594 | req.payload.data[ (RFAL_NFCV_UID_LEN + msgIt++) ] = numOfBlocks; |
DiegoOstuni | 0:75fc82583a41 | 595 | } |
DiegoOstuni | 0:75fc82583a41 | 596 | else |
DiegoOstuni | 0:75fc82583a41 | 597 | { |
DiegoOstuni | 0:75fc82583a41 | 598 | req.REQ_FLAG |= RFAL_NFCV_REQ_FLAG_SELECT; |
DiegoOstuni | 0:75fc82583a41 | 599 | req.payload.data[msgIt++] = firstBlockNum; |
DiegoOstuni | 0:75fc82583a41 | 600 | req.payload.data[msgIt++] = numOfBlocks; |
DiegoOstuni | 0:75fc82583a41 | 601 | } |
DiegoOstuni | 0:75fc82583a41 | 602 | |
DiegoOstuni | 0:75fc82583a41 | 603 | /* Transceive Command */ |
DiegoOstuni | 0:75fc82583a41 | 604 | ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, (RFAL_CMD_LEN + RFAL_NFCV_FLAG_LEN + msgIt), rxBuf, rxBufLen, rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ; |
DiegoOstuni | 0:75fc82583a41 | 605 | if( ret != ERR_NONE ) |
DiegoOstuni | 0:75fc82583a41 | 606 | { |
DiegoOstuni | 0:75fc82583a41 | 607 | return ret; |
DiegoOstuni | 0:75fc82583a41 | 608 | } |
DiegoOstuni | 0:75fc82583a41 | 609 | |
DiegoOstuni | 0:75fc82583a41 | 610 | /* Check if the response minimum length has been received */ |
DiegoOstuni | 0:75fc82583a41 | 611 | if( (*rcvLen) < RFAL_NFCV_FLAG_LEN ) |
DiegoOstuni | 0:75fc82583a41 | 612 | { |
DiegoOstuni | 0:75fc82583a41 | 613 | return ERR_PROTO; |
DiegoOstuni | 0:75fc82583a41 | 614 | } |
DiegoOstuni | 0:75fc82583a41 | 615 | |
DiegoOstuni | 0:75fc82583a41 | 616 | /* Check if an error has been signalled */ |
DiegoOstuni | 0:75fc82583a41 | 617 | if( res->RES_FLAG & RFAL_NFCV_RES_FLAG_ERROR ) |
DiegoOstuni | 0:75fc82583a41 | 618 | { |
DiegoOstuni | 0:75fc82583a41 | 619 | return rfalNfvParseError( *(res->data) ); |
DiegoOstuni | 0:75fc82583a41 | 620 | } |
DiegoOstuni | 0:75fc82583a41 | 621 | |
DiegoOstuni | 0:75fc82583a41 | 622 | return ERR_NONE; |
DiegoOstuni | 0:75fc82583a41 | 623 | } |
DiegoOstuni | 0:75fc82583a41 | 624 | |
DiegoOstuni | 0:75fc82583a41 | 625 | #endif /* RFAL_FEATURE_NFCV */ |