Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
rfal_t1t.cpp
00001 00002 /****************************************************************************** 00003 * @attention 00004 * 00005 * <h2><center>© 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_t1t.c 00030 * 00031 * \author Gustavo Patricio 00032 * 00033 * \brief Provides NFC-A T1T convenience methods and definitions 00034 * 00035 * This module provides an interface to perform as a NFC-A Reader/Writer 00036 * to handle a Type 1 Tag T1T (Topaz) 00037 * 00038 */ 00039 00040 /* 00041 ****************************************************************************** 00042 * INCLUDES 00043 ****************************************************************************** 00044 */ 00045 #include "rfal_t1t.h" 00046 #include "utils.h" 00047 #include "platform1.h" 00048 00049 /* 00050 ****************************************************************************** 00051 * ENABLE SWITCH 00052 ****************************************************************************** 00053 */ 00054 00055 #ifndef RFAL_FEATURE_T1T 00056 #error " RFAL: Module configuration missing. Please enable/disable T1T module by setting: RFAL_FEATURE_T1T " 00057 #endif 00058 00059 #if RFAL_FEATURE_T1T 00060 00061 /* 00062 ****************************************************************************** 00063 * GLOBAL DEFINES 00064 ****************************************************************************** 00065 */ 00066 00067 #define RFAL_T1T_DRD_READ (1236*2)/*!< DRD for Reads with n=9 => 1236/fc ~= 91 us T1T 1.2 4.4.2 */ 00068 #define RFAL_T1T_DRD_WRITE 36052 /*!< DRD for Write with n=281 => 36052/fc ~= 2659 us T1T 1.2 4.4.2 */ 00069 #define RFAL_T1T_DRD_WRITE_E 70996 /*!< DRD for Write/Erase with n=554 => 70996/fc ~= 5236 us T1T 1.2 4.4.2 */ 00070 00071 #define RFAL_T1T_RID_RES_HR0_VAL 0x10 /*!< HR0 indicating NDEF support Digital 2.0 (Candidate) 11.6.2.1 */ 00072 #define RFAL_T1T_RID_RES_HR0_MASK 0xF0 /*!< HR0 most significant nibble mask */ 00073 00074 /* 00075 ****************************************************************************** 00076 * GLOBAL TYPES 00077 ****************************************************************************** 00078 */ 00079 00080 /*! NFC-A T1T (Topaz) RID_REQ Digital 1.1 10.6.1 & Table 49 */ 00081 typedef struct 00082 { 00083 uint8_t cmd; /*!< T1T cmd: RID */ 00084 uint8_t add; /*!< ADD: undefined value */ 00085 uint8_t data; /*!< DATA: undefined value */ 00086 uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID-echo: undefined value */ 00087 } rfalT1TRidReq; 00088 00089 00090 /*! NFC-A T1T (Topaz) RALL_REQ T1T 1.2 Table 4 */ 00091 typedef struct 00092 { 00093 uint8_t cmd; /*!< T1T cmd: RALL */ 00094 uint8_t add1; /*!< ADD: 0x00 */ 00095 uint8_t add0; /*!< ADD: 0x00 */ 00096 uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */ 00097 } rfalT1TRallReq; 00098 00099 00100 /*! NFC-A T1T (Topaz) WRITE_REQ T1T 1.2 Table 4 */ 00101 typedef struct 00102 { 00103 uint8_t cmd; /*!< T1T cmd: RALL */ 00104 uint8_t add; /*!< ADD */ 00105 uint8_t data; /*!< DAT */ 00106 uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */ 00107 } rfalT1TWriteReq; 00108 00109 00110 /*! NFC-A T1T (Topaz) WRITE_RES T1T 1.2 Table 4 */ 00111 typedef struct 00112 { 00113 uint8_t add; /*!< ADD */ 00114 uint8_t data; /*!< DAT */ 00115 } rfalT1TWriteRes; 00116 00117 /* 00118 ****************************************************************************** 00119 * LOCAL FUNCTION PROTOTYPES 00120 ****************************************************************************** 00121 */ 00122 00123 /* 00124 ****************************************************************************** 00125 * GLOBAL FUNCTIONS 00126 ****************************************************************************** 00127 */ 00128 00129 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 ) 00130 { 00131 ReturnCode ret; 00132 00133 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 ) ); 00134 rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC ); 00135 00136 rfalSetGT( RFAL_GT_NONE ); /* T1T should only be initialized after NFC-A mode, therefore the GT has been fulfilled */ 00137 rfalSetFDTListen( RFAL_FDT_LISTEN_NFCA_POLLER ); /* T1T uses NFC-A FDT Listen with n=9 Digital 1.1 10.7.2 */ 00138 rfalSetFDTPoll( RFAL_FDT_POLL_NFCA_T1T_POLLER ); 00139 00140 return ERR_NONE; 00141 } 00142 00143 00144 /*******************************************************************************/ 00145 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 ) 00146 { 00147 ReturnCode ret; 00148 rfalT1TRidReq ridReq; 00149 uint16_t rcvdLen; 00150 00151 if( ridRes == NULL ) 00152 { 00153 return ERR_PARAM; 00154 } 00155 00156 /* Compute RID command and set Undefined Values to 0x00 Digital 1.1 10.6.1 */ 00157 ST_MEMSET( &ridReq, 0x00, sizeof(rfalT1TRidReq) ); 00158 ridReq.cmd = RFAL_T1T_CMD_RID ; 00159 00160 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 ) ); 00161 00162 /* Check expected RID response length and the HR0 Digital 2.0 (Candidate) 11.6.2.1 */ 00163 if( rcvdLen != sizeof(rfalT1TRidRes ) || (ridRes->hr0 & RFAL_T1T_RID_RES_HR0_MASK) != RFAL_T1T_RID_RES_HR0_VAL ) 00164 { 00165 return ERR_PROTO; 00166 } 00167 00168 return ERR_NONE; 00169 } 00170 00171 00172 /*******************************************************************************/ 00173 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 ) 00174 { 00175 rfalT1TRallReq rallReq; 00176 00177 if( (rxBuf == NULL) || (uid == NULL) || (rxRcvdLen == NULL) ) 00178 { 00179 return ERR_PARAM; 00180 } 00181 00182 /* Compute RALL command and set Add to 0x00 */ 00183 ST_MEMSET( &rallReq, 0x00, sizeof(rfalT1TRallReq) ); 00184 rallReq.cmd = RFAL_T1T_CMD_RALL ; 00185 ST_MEMCPY(rallReq.uid, uid, RFAL_T1T_UID_LEN); 00186 00187 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 ) ; 00188 } 00189 00190 00191 /*******************************************************************************/ 00192 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 ) 00193 { 00194 rfalT1TWriteReq writeReq; 00195 rfalT1TWriteRes writeRes; 00196 uint16_t rxRcvdLen; 00197 ReturnCode err; 00198 00199 if( uid == NULL ) 00200 { 00201 return ERR_PARAM; 00202 } 00203 00204 writeReq.cmd = RFAL_T1T_CMD_WRITE_E ; 00205 writeReq.add = address; 00206 writeReq.data = data; 00207 ST_MEMCPY(writeReq.uid, uid, RFAL_T1T_UID_LEN); 00208 00209 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 ) ; 00210 00211 if( err == ERR_NONE ) 00212 { 00213 if( (writeReq.add != writeRes.add) || (writeReq.data != writeRes.data) || (rxRcvdLen != sizeof(rfalT1TWriteRes)) ) 00214 { 00215 return ERR_PROTO; 00216 } 00217 } 00218 return err; 00219 } 00220 00221 #endif /* RFAL_FEATURE_T1T */
Generated on Sat Jul 16 2022 13:00:53 by
1.7.2