Fork of the GitHub

Committer:
DiegoOstuni
Date:
Thu Nov 14 14:34:50 2019 +0000
Revision:
0:75fc82583a41
Add files

Who changed what in which revision?

UserRevisionLine numberNew 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>&copy; 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_t1t.c
DiegoOstuni 0:75fc82583a41 30 *
DiegoOstuni 0:75fc82583a41 31 * \author Gustavo Patricio
DiegoOstuni 0:75fc82583a41 32 *
DiegoOstuni 0:75fc82583a41 33 * \brief Provides NFC-A T1T convenience methods and definitions
DiegoOstuni 0:75fc82583a41 34 *
DiegoOstuni 0:75fc82583a41 35 * This module provides an interface to perform as a NFC-A Reader/Writer
DiegoOstuni 0:75fc82583a41 36 * to handle a Type 1 Tag T1T (Topaz)
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 "rfal_t1t.h"
DiegoOstuni 0:75fc82583a41 46 #include "utils.h"
DiegoOstuni 0:75fc82583a41 47 #include "platform1.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_T1T
DiegoOstuni 0:75fc82583a41 56 #error " RFAL: Module configuration missing. Please enable/disable T1T module by setting: RFAL_FEATURE_T1T "
DiegoOstuni 0:75fc82583a41 57 #endif
DiegoOstuni 0:75fc82583a41 58
DiegoOstuni 0:75fc82583a41 59 #if RFAL_FEATURE_T1T
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_T1T_DRD_READ (1236*2)/*!< DRD for Reads with n=9 => 1236/fc ~= 91 us T1T 1.2 4.4.2 */
DiegoOstuni 0:75fc82583a41 68 #define RFAL_T1T_DRD_WRITE 36052 /*!< DRD for Write with n=281 => 36052/fc ~= 2659 us T1T 1.2 4.4.2 */
DiegoOstuni 0:75fc82583a41 69 #define RFAL_T1T_DRD_WRITE_E 70996 /*!< DRD for Write/Erase with n=554 => 70996/fc ~= 5236 us T1T 1.2 4.4.2 */
DiegoOstuni 0:75fc82583a41 70
DiegoOstuni 0:75fc82583a41 71 #define RFAL_T1T_RID_RES_HR0_VAL 0x10 /*!< HR0 indicating NDEF support Digital 2.0 (Candidate) 11.6.2.1 */
DiegoOstuni 0:75fc82583a41 72 #define RFAL_T1T_RID_RES_HR0_MASK 0xF0 /*!< HR0 most significant nibble mask */
DiegoOstuni 0:75fc82583a41 73
DiegoOstuni 0:75fc82583a41 74 /*
DiegoOstuni 0:75fc82583a41 75 ******************************************************************************
DiegoOstuni 0:75fc82583a41 76 * GLOBAL TYPES
DiegoOstuni 0:75fc82583a41 77 ******************************************************************************
DiegoOstuni 0:75fc82583a41 78 */
DiegoOstuni 0:75fc82583a41 79
DiegoOstuni 0:75fc82583a41 80 /*! NFC-A T1T (Topaz) RID_REQ Digital 1.1 10.6.1 & Table 49 */
DiegoOstuni 0:75fc82583a41 81 typedef struct
DiegoOstuni 0:75fc82583a41 82 {
DiegoOstuni 0:75fc82583a41 83 uint8_t cmd; /*!< T1T cmd: RID */
DiegoOstuni 0:75fc82583a41 84 uint8_t add; /*!< ADD: undefined value */
DiegoOstuni 0:75fc82583a41 85 uint8_t data; /*!< DATA: undefined value */
DiegoOstuni 0:75fc82583a41 86 uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID-echo: undefined value */
DiegoOstuni 0:75fc82583a41 87 } rfalT1TRidReq;
DiegoOstuni 0:75fc82583a41 88
DiegoOstuni 0:75fc82583a41 89
DiegoOstuni 0:75fc82583a41 90 /*! NFC-A T1T (Topaz) RALL_REQ T1T 1.2 Table 4 */
DiegoOstuni 0:75fc82583a41 91 typedef struct
DiegoOstuni 0:75fc82583a41 92 {
DiegoOstuni 0:75fc82583a41 93 uint8_t cmd; /*!< T1T cmd: RALL */
DiegoOstuni 0:75fc82583a41 94 uint8_t add1; /*!< ADD: 0x00 */
DiegoOstuni 0:75fc82583a41 95 uint8_t add0; /*!< ADD: 0x00 */
DiegoOstuni 0:75fc82583a41 96 uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */
DiegoOstuni 0:75fc82583a41 97 } rfalT1TRallReq;
DiegoOstuni 0:75fc82583a41 98
DiegoOstuni 0:75fc82583a41 99
DiegoOstuni 0:75fc82583a41 100 /*! NFC-A T1T (Topaz) WRITE_REQ T1T 1.2 Table 4 */
DiegoOstuni 0:75fc82583a41 101 typedef struct
DiegoOstuni 0:75fc82583a41 102 {
DiegoOstuni 0:75fc82583a41 103 uint8_t cmd; /*!< T1T cmd: RALL */
DiegoOstuni 0:75fc82583a41 104 uint8_t add; /*!< ADD */
DiegoOstuni 0:75fc82583a41 105 uint8_t data; /*!< DAT */
DiegoOstuni 0:75fc82583a41 106 uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */
DiegoOstuni 0:75fc82583a41 107 } rfalT1TWriteReq;
DiegoOstuni 0:75fc82583a41 108
DiegoOstuni 0:75fc82583a41 109
DiegoOstuni 0:75fc82583a41 110 /*! NFC-A T1T (Topaz) WRITE_RES T1T 1.2 Table 4 */
DiegoOstuni 0:75fc82583a41 111 typedef struct
DiegoOstuni 0:75fc82583a41 112 {
DiegoOstuni 0:75fc82583a41 113 uint8_t add; /*!< ADD */
DiegoOstuni 0:75fc82583a41 114 uint8_t data; /*!< DAT */
DiegoOstuni 0:75fc82583a41 115 } rfalT1TWriteRes;
DiegoOstuni 0:75fc82583a41 116
DiegoOstuni 0:75fc82583a41 117 /*
DiegoOstuni 0:75fc82583a41 118 ******************************************************************************
DiegoOstuni 0:75fc82583a41 119 * LOCAL FUNCTION PROTOTYPES
DiegoOstuni 0:75fc82583a41 120 ******************************************************************************
DiegoOstuni 0:75fc82583a41 121 */
DiegoOstuni 0:75fc82583a41 122
DiegoOstuni 0:75fc82583a41 123 /*
DiegoOstuni 0:75fc82583a41 124 ******************************************************************************
DiegoOstuni 0:75fc82583a41 125 * GLOBAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 126 ******************************************************************************
DiegoOstuni 0:75fc82583a41 127 */
DiegoOstuni 0:75fc82583a41 128
DiegoOstuni 0:75fc82583a41 129 ReturnCode rfalT1TPollerInitialize( 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 130 {
DiegoOstuni 0:75fc82583a41 131 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 132
DiegoOstuni 0:75fc82583a41 133 EXIT_ON_ERR(ret, rfalSetMode( RFAL_MODE_POLL_NFCA_T1T, RFAL_BR_106, RFAL_BR_106, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 134 rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC );
DiegoOstuni 0:75fc82583a41 135
DiegoOstuni 0:75fc82583a41 136 rfalSetGT( RFAL_GT_NONE ); /* T1T should only be initialized after NFC-A mode, therefore the GT has been fulfilled */
DiegoOstuni 0:75fc82583a41 137 rfalSetFDTListen( RFAL_FDT_LISTEN_NFCA_POLLER ); /* T1T uses NFC-A FDT Listen with n=9 Digital 1.1 10.7.2 */
DiegoOstuni 0:75fc82583a41 138 rfalSetFDTPoll( RFAL_FDT_POLL_NFCA_T1T_POLLER );
DiegoOstuni 0:75fc82583a41 139
DiegoOstuni 0:75fc82583a41 140 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 141 }
DiegoOstuni 0:75fc82583a41 142
DiegoOstuni 0:75fc82583a41 143
DiegoOstuni 0:75fc82583a41 144 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 145 ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes,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 146 {
DiegoOstuni 0:75fc82583a41 147 ReturnCode ret;
DiegoOstuni 0:75fc82583a41 148 rfalT1TRidReq ridReq;
DiegoOstuni 0:75fc82583a41 149 uint16_t rcvdLen;
DiegoOstuni 0:75fc82583a41 150
DiegoOstuni 0:75fc82583a41 151 if( ridRes == NULL )
DiegoOstuni 0:75fc82583a41 152 {
DiegoOstuni 0:75fc82583a41 153 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 154 }
DiegoOstuni 0:75fc82583a41 155
DiegoOstuni 0:75fc82583a41 156 /* Compute RID command and set Undefined Values to 0x00 Digital 1.1 10.6.1 */
DiegoOstuni 0:75fc82583a41 157 ST_MEMSET( &ridReq, 0x00, sizeof(rfalT1TRidReq) );
DiegoOstuni 0:75fc82583a41 158 ridReq.cmd = RFAL_T1T_CMD_RID;
DiegoOstuni 0:75fc82583a41 159
DiegoOstuni 0:75fc82583a41 160 EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&ridReq, sizeof(rfalT1TRidReq), (uint8_t*)ridRes, sizeof(rfalT1TRidRes), &rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_READ, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 161
DiegoOstuni 0:75fc82583a41 162 /* Check expected RID response length and the HR0 Digital 2.0 (Candidate) 11.6.2.1 */
DiegoOstuni 0:75fc82583a41 163 if( rcvdLen != sizeof(rfalT1TRidRes) || (ridRes->hr0 & RFAL_T1T_RID_RES_HR0_MASK) != RFAL_T1T_RID_RES_HR0_VAL )
DiegoOstuni 0:75fc82583a41 164 {
DiegoOstuni 0:75fc82583a41 165 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 166 }
DiegoOstuni 0:75fc82583a41 167
DiegoOstuni 0:75fc82583a41 168 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 169 }
DiegoOstuni 0:75fc82583a41 170
DiegoOstuni 0:75fc82583a41 171
DiegoOstuni 0:75fc82583a41 172 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 173 ReturnCode rfalT1TPollerRall( uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen,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 174 {
DiegoOstuni 0:75fc82583a41 175 rfalT1TRallReq rallReq;
DiegoOstuni 0:75fc82583a41 176
DiegoOstuni 0:75fc82583a41 177 if( (rxBuf == NULL) || (uid == NULL) || (rxRcvdLen == NULL) )
DiegoOstuni 0:75fc82583a41 178 {
DiegoOstuni 0:75fc82583a41 179 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 180 }
DiegoOstuni 0:75fc82583a41 181
DiegoOstuni 0:75fc82583a41 182 /* Compute RALL command and set Add to 0x00 */
DiegoOstuni 0:75fc82583a41 183 ST_MEMSET( &rallReq, 0x00, sizeof(rfalT1TRallReq) );
DiegoOstuni 0:75fc82583a41 184 rallReq.cmd = RFAL_T1T_CMD_RALL;
DiegoOstuni 0:75fc82583a41 185 ST_MEMCPY(rallReq.uid, uid, RFAL_T1T_UID_LEN);
DiegoOstuni 0:75fc82583a41 186
DiegoOstuni 0:75fc82583a41 187 return rfalTransceiveBlockingTxRx( (uint8_t*)&rallReq, sizeof(rfalT1TRallReq), (uint8_t*)rxBuf, rxBufLen, rxRcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_READ, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 188 }
DiegoOstuni 0:75fc82583a41 189
DiegoOstuni 0:75fc82583a41 190
DiegoOstuni 0:75fc82583a41 191 /*******************************************************************************/
DiegoOstuni 0:75fc82583a41 192 ReturnCode rfalT1TPollerWrite( uint8_t* uid, uint8_t address, uint8_t data,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 193 {
DiegoOstuni 0:75fc82583a41 194 rfalT1TWriteReq writeReq;
DiegoOstuni 0:75fc82583a41 195 rfalT1TWriteRes writeRes;
DiegoOstuni 0:75fc82583a41 196 uint16_t rxRcvdLen;
DiegoOstuni 0:75fc82583a41 197 ReturnCode err;
DiegoOstuni 0:75fc82583a41 198
DiegoOstuni 0:75fc82583a41 199 if( uid == NULL )
DiegoOstuni 0:75fc82583a41 200 {
DiegoOstuni 0:75fc82583a41 201 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 202 }
DiegoOstuni 0:75fc82583a41 203
DiegoOstuni 0:75fc82583a41 204 writeReq.cmd = RFAL_T1T_CMD_WRITE_E;
DiegoOstuni 0:75fc82583a41 205 writeReq.add = address;
DiegoOstuni 0:75fc82583a41 206 writeReq.data = data;
DiegoOstuni 0:75fc82583a41 207 ST_MEMCPY(writeReq.uid, uid, RFAL_T1T_UID_LEN);
DiegoOstuni 0:75fc82583a41 208
DiegoOstuni 0:75fc82583a41 209 err = rfalTransceiveBlockingTxRx( (uint8_t*)&writeReq, sizeof(rfalT1TWriteReq), (uint8_t*)&writeRes, sizeof(rfalT1TWriteRes), &rxRcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_WRITE_E, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) ;
DiegoOstuni 0:75fc82583a41 210
DiegoOstuni 0:75fc82583a41 211 if( err == ERR_NONE )
DiegoOstuni 0:75fc82583a41 212 {
DiegoOstuni 0:75fc82583a41 213 if( (writeReq.add != writeRes.add) || (writeReq.data != writeRes.data) || (rxRcvdLen != sizeof(rfalT1TWriteRes)) )
DiegoOstuni 0:75fc82583a41 214 {
DiegoOstuni 0:75fc82583a41 215 return ERR_PROTO;
DiegoOstuni 0:75fc82583a41 216 }
DiegoOstuni 0:75fc82583a41 217 }
DiegoOstuni 0:75fc82583a41 218 return err;
DiegoOstuni 0:75fc82583a41 219 }
DiegoOstuni 0:75fc82583a41 220
DiegoOstuni 0:75fc82583a41 221 #endif /* RFAL_FEATURE_T1T */