rfal_rf.h 74 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572
  1. /******************************************************************************
  2. * \attention
  3. *
  4. * <h2><center>&copy; COPYRIGHT 2020 STMicroelectronics</center></h2>
  5. *
  6. * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
  7. * You may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at:
  9. *
  10. * www.st.com/myliberty
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
  15. * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. *
  20. ******************************************************************************/
  21. /*
  22. * PROJECT: ST25R391x firmware
  23. * Revision:
  24. * LANGUAGE: ISO C99
  25. */
  26. /*! \file rfal_rf.h
  27. *
  28. * \author Gustavo Patricio
  29. *
  30. * \brief RF Abstraction Layer (RFAL)
  31. *
  32. * RFAL (RF Abstraction Layer) provides several functionalities required to
  33. * perform RF/NFC communications. <br>The RFAL encapsulates the different
  34. * RF ICs (ST25R3911, ST25R391x, etc) into a common and easy to use interface.
  35. *
  36. * It provides interfaces to configure the RF IC, set/get timings, modes, bit rates,
  37. * specific handlings, execute listen mode, etc.
  38. *
  39. * Furthermore it provides a common interface to perform a Transceive operations.
  40. * The Transceive can be executed in a blocking or non blocking way.<br>
  41. * Additionally few specific Transceive methods are available to cope with the
  42. * specifics of these particular operations.
  43. *
  44. * The most common interfaces are:
  45. * <br>&nbsp; rfalInitialize()
  46. * <br>&nbsp; rfalSetFDTPoll()
  47. * <br>&nbsp; rfalSetFDTListen()
  48. * <br>&nbsp; rfalSetGT()
  49. * <br>&nbsp; rfalSetBitRate()
  50. * <br>&nbsp; rfalSetMode()
  51. * <br>&nbsp; rfalFieldOnAndStartGT()
  52. * <br>&nbsp; rfalFieldOff()
  53. * <br>&nbsp; rfalStartTransceive()
  54. * <br>&nbsp; rfalGetTransceiveStatus()
  55. * <br>&nbsp; rfalTransceiveBlockingTxRx()
  56. *
  57. * An usage example is provided here: \ref exampleRfalPoller.c
  58. * \example exampleRfalPoller.c
  59. *
  60. * \addtogroup RFAL
  61. * @{
  62. *
  63. * \addtogroup RFAL-HAL
  64. * \brief RFAL Hardware Abstraction Layer
  65. * @{
  66. *
  67. * \addtogroup RF
  68. * \brief RFAL RF Abstraction Layer
  69. * @{
  70. *
  71. */
  72. #ifndef RFAL_RF_H
  73. #define RFAL_RF_H
  74. /*
  75. ******************************************************************************
  76. * INCLUDES
  77. ******************************************************************************
  78. */
  79. #include "platform.h"
  80. #include "st_errno.h"
  81. #include "rfal_features.h"
  82. /*
  83. ******************************************************************************
  84. * GLOBAL DEFINES
  85. ******************************************************************************
  86. */
  87. #define RFAL_VERSION 0x020200U /*!< RFAL Current Version: v2.2.0 */
  88. #define RFAL_FWT_NONE 0xFFFFFFFFU /*!< Disabled FWT: Wait forever for a response */
  89. #define RFAL_GT_NONE RFAL_TIMING_NONE /*!< Disabled GT: No GT will be applied after Field On */
  90. #define RFAL_TIMING_NONE 0x00U /*!< Timing disabled | Don't apply */
  91. #define RFAL_1FC_IN_4096FC (uint32_t)4096U /*!< Number of 1/fc cycles in one 4096/fc */
  92. #define RFAL_1FC_IN_512FC (uint32_t)512U /*!< Number of 1/fc cycles in one 512/fc */
  93. #define RFAL_1FC_IN_64FC (uint32_t)64U /*!< Number of 1/fc cycles in one 64/fc */
  94. #define RFAL_1FC_IN_8FC (uint32_t)8U /*!< Number of 1/fc cycles in one 8/fc */
  95. #define RFAL_US_IN_MS (uint32_t)1000U /*!< Number of us in one ms */
  96. #define RFAL_1MS_IN_1FC (uint32_t)13560U /*!< Number of 1/fc cycles in 1ms */
  97. #define RFAL_BITS_IN_BYTE (uint16_t)8U /*!< Number of bits in one byte */
  98. #define RFAL_CRC_LEN 2U /*!< RF CRC LEN */
  99. /*! Default TxRx flags: Tx CRC automatic, Rx CRC removed, NFCIP1 mode off, AGC On, Tx Parity automatic, Rx Parity removed */
  100. #define RFAL_TXRX_FLAGS_DEFAULT ( (uint32_t)RFAL_TXRX_FLAGS_CRC_TX_AUTO | (uint32_t)RFAL_TXRX_FLAGS_CRC_RX_REMV | (uint32_t)RFAL_TXRX_FLAGS_NFCIP1_OFF | (uint32_t)RFAL_TXRX_FLAGS_AGC_ON | (uint32_t)RFAL_TXRX_FLAGS_PAR_RX_REMV | (uint32_t)RFAL_TXRX_FLAGS_PAR_TX_AUTO | (uint32_t)RFAL_TXRX_FLAGS_NFCV_FLAG_AUTO)
  101. #define RFAL_LM_MASK_NFCA ((uint32_t)1U<<(uint8_t)RFAL_MODE_LISTEN_NFCA) /*!< Bitmask for Listen Mode enabling NFCA */
  102. #define RFAL_LM_MASK_NFCB ((uint32_t)1U<<(uint8_t)RFAL_MODE_LISTEN_NFCB) /*!< Bitmask for Listen Mode enabling NFCB */
  103. #define RFAL_LM_MASK_NFCF ((uint32_t)1U<<(uint8_t)RFAL_MODE_LISTEN_NFCF) /*!< Bitmask for Listen Mode enabling NFCF */
  104. #define RFAL_LM_MASK_ACTIVE_P2P ((uint32_t)1U<<(uint8_t)RFAL_MODE_LISTEN_ACTIVE_P2P) /*!< Bitmask for Listen Mode enabling AP2P */
  105. #define RFAL_LM_SENS_RES_LEN 2U /*!< NFC-A SENS_RES (ATQA) length */
  106. #define RFAL_LM_SENSB_RES_LEN 13U /*!< NFC-B SENSB_RES (ATQB) length */
  107. #define RFAL_LM_SENSF_RES_LEN 19U /*!< NFC-F SENSF_RES length */
  108. #define RFAL_LM_SENSF_SC_LEN 2U /*!< NFC-F System Code length */
  109. #define RFAL_NFCID3_LEN 10U /*!< NFCID3 length */
  110. #define RFAL_NFCID2_LEN 8U /*!< NFCID2 length */
  111. #define RFAL_NFCID1_TRIPLE_LEN 10U /*!< NFCID1 length */
  112. #define RFAL_NFCID1_DOUBLE_LEN 7U /*!< NFCID1 length */
  113. #define RFAL_NFCID1_SINGLE_LEN 4U /*!< NFCID1 length */
  114. /*
  115. ******************************************************************************
  116. * GLOBAL MACROS
  117. ******************************************************************************
  118. */
  119. /*! Returns the maximum supported bit rate for RW mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */
  120. #define rfalGetMaxBrRW() ( ((RFAL_SUPPORT_BR_RW_6780) ? RFAL_BR_6780 : ((RFAL_SUPPORT_BR_RW_3390) ? RFAL_BR_3390 : ((RFAL_SUPPORT_BR_RW_1695) ? RFAL_BR_1695 : ((RFAL_SUPPORT_BR_RW_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_RW_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_RW_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) ) ) ) )
  121. /*! Returns the maximum supported bit rate for AP2P mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */
  122. #define rfalGetMaxBrAP2P() ( ((RFAL_SUPPORT_BR_AP2P_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_AP2P_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_AP2P_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) )
  123. /*! Returns the maximum supported bit rate for CE-A mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */
  124. #define rfalGetMaxBrCEA() ( ((RFAL_SUPPORT_BR_CE_A_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_CE_A_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_CE_A_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) )
  125. /*! Returns the maximum supported bit rate for CE-B mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */
  126. #define rfalGetMaxBrCEB() ( ((RFAL_SUPPORT_BR_CE_B_848) ? RFAL_BR_848 : ((RFAL_SUPPORT_BR_CE_B_424) ? RFAL_BR_424 : ((RFAL_SUPPORT_BR_CE_B_212) ? RFAL_BR_212 : RFAL_BR_106 ) ) ) )
  127. /*! Returns the maximum supported bit rate for CE-F mode. Caller must check if mode is supported before, as even if mode is not supported will return the min */
  128. #define rfalGetMaxBrCEF() ( ((RFAL_SUPPORT_BR_CE_F_424) ? RFAL_BR_424 : RFAL_BR_212 ) )
  129. #define rfalIsModeActiveComm( md ) ( ((md) == RFAL_MODE_POLL_ACTIVE_P2P) || ((md) == RFAL_MODE_LISTEN_ACTIVE_P2P) ) /*!< Checks if mode md is Active Communication */
  130. #define rfalIsModePassiveComm( md ) ( !rfalIsModeActiveComm(md) ) /*!< Checks if mode md is Passive Communication */
  131. #define rfalIsModePassiveListen( md ) ( ((md) == RFAL_MODE_LISTEN_NFCA) || ((md) == RFAL_MODE_LISTEN_NFCB) || ((md) == RFAL_MODE_LISTEN_NFCF) ) /*!< Checks if mode md is Passive Listen */
  132. #define rfalIsModePassivePoll( md ) ( rfalIsModePassiveComm(md) && !rfalIsModePassiveListen(md) ) /*!< Checks if mode md is Passive Poll */
  133. #define rfalConv1fcTo8fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_8FC ) /*!< Converts the given t from 1/fc to 8/fc */
  134. #define rfalConv8fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_8FC ) /*!< Converts the given t from 8/fc to 1/fc */
  135. #define rfalConv1fcTo64fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_64FC ) /*!< Converts the given t from 1/fc to 64/fc */
  136. #define rfalConv64fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_64FC ) /*!< Converts the given t from 64/fc to 1/fc */
  137. #define rfalConv1fcTo512fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_512FC ) /*!< Converts the given t from 1/fc to 512/fc */
  138. #define rfalConv512fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_512FC ) /*!< Converts the given t from 512/fc to 1/fc */
  139. #define rfalConv1fcTo4096fc( t ) (uint32_t)( (uint32_t)(t) / RFAL_1FC_IN_4096FC ) /*!< Converts the given t from 1/fc to 4096/fc */
  140. #define rfalConv4096fcTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1FC_IN_4096FC ) /*!< Converts the given t from 4096/fc to 1/fc */
  141. #define rfalConv1fcToMs( t ) (uint32_t)( (uint32_t)(t) / RFAL_1MS_IN_1FC ) /*!< Converts the given t from 1/fc to ms */
  142. #define rfalConvMsTo1fc( t ) (uint32_t)( (uint32_t)(t) * RFAL_1MS_IN_1FC ) /*!< Converts the given t from ms to 1/fc */
  143. #define rfalConv1fcToUs( t ) (uint32_t)( ((uint32_t)(t) * RFAL_US_IN_MS) / RFAL_1MS_IN_1FC) /*!< Converts the given t from 1/fc to us */
  144. #define rfalConvUsTo1fc( t ) (uint32_t)( ((uint32_t)(t) * RFAL_1MS_IN_1FC) / RFAL_US_IN_MS) /*!< Converts the given t from us to 1/fc */
  145. #define rfalConv64fcToMs( t ) (uint32_t)( (uint32_t)(t) / (RFAL_1MS_IN_1FC / RFAL_1FC_IN_64FC) ) /*!< Converts the given t from 64/fc to ms */
  146. #define rfalConvMsTo64fc( t ) (uint32_t)( (uint32_t)(t) * (RFAL_1MS_IN_1FC / RFAL_1FC_IN_64FC) ) /*!< Converts the given t from ms to 64/fc */
  147. #define rfalConvBitsToBytes( n ) (uint16_t)( ((uint16_t)(n)+(RFAL_BITS_IN_BYTE-1U)) / (RFAL_BITS_IN_BYTE) ) /*!< Converts the given n from bits to bytes */
  148. #define rfalConvBytesToBits( n ) (uint32_t)( (uint32_t)(n) * (RFAL_BITS_IN_BYTE) ) /*!< Converts the given n from bytes to bits */
  149. /*! Computes a Transceive context \a ctx with default flags and the lengths
  150. * in bytes with the given arguments
  151. * \a ctx : Transceive context to be assigned
  152. * \a tB : txBuf the pointer to the buffer to be sent
  153. * \a tBL : txBuf length in bytes
  154. * \a rB : rxBuf the pointer to the buffer to place the received frame
  155. * \a rBL : rxBuf length in bytes
  156. * \a rBL : rxBuf length in bytes
  157. * \a t : FWT to be used on this transceive in 1/fc
  158. */
  159. #define rfalCreateByteTxRxContext( ctx, tB, tBL, rB, rBL, rdL, t ) \
  160. (ctx).txBuf = (uint8_t*)(tB); \
  161. (ctx).txBufLen = (uint16_t)rfalConvBytesToBits(tBL); \
  162. (ctx).rxBuf = (uint8_t*)(rB); \
  163. (ctx).rxBufLen = (uint16_t)rfalConvBytesToBits(rBL); \
  164. (ctx).rxRcvdLen = (uint16_t*)(rdL); \
  165. (ctx).flags = (uint32_t)RFAL_TXRX_FLAGS_DEFAULT; \
  166. (ctx).fwt = (uint32_t)(t);
  167. /*! Computes a Transceive context \a ctx using lengths in bytes
  168. * with the given flags and arguments
  169. * \a ctx : Transceive context to be assigned
  170. * \a tB : txBuf the pointer to the buffer to be sent
  171. * \a tBL : txBuf length in bytes
  172. * \a rB : rxBuf the pointer to the buffer to place the received frame
  173. * \a rBL : rxBuf length in bytes
  174. * \a rBL : rxBuf length in bytes
  175. * \a t : FWT to be used on this transceive in 1/fc
  176. */
  177. #define rfalCreateByteFlagsTxRxContext( ctx, tB, tBL, rB, rBL, rdL, fl, t ) \
  178. (ctx).txBuf = (uint8_t*)(tB); \
  179. (ctx).txBufLen = (uint16_t)rfalConvBytesToBits(tBL); \
  180. (ctx).rxBuf = (uint8_t*)(rB); \
  181. (ctx).rxBufLen = (uint16_t)rfalConvBytesToBits(rBL); \
  182. (ctx).rxRcvdLen = (uint16_t*)(rdL); \
  183. (ctx).flags = (uint32_t)(fl); \
  184. (ctx).fwt = (uint32_t)(t);
  185. #define rfalLogE(...) platformLog(__VA_ARGS__) /*!< Macro for the error log method */
  186. #define rfalLogW(...) platformLog(__VA_ARGS__) /*!< Macro for the warning log method */
  187. #define rfalLogI(...) platformLog(__VA_ARGS__) /*!< Macro for the info log method */
  188. #define rfalLogD(...) platformLog(__VA_ARGS__) /*!< Macro for the debug log method */
  189. /*
  190. ******************************************************************************
  191. * GLOBAL ENUMS
  192. ******************************************************************************
  193. */
  194. /* RFAL Guard Time (GT) default values */
  195. #define RFAL_GT_NFCA rfalConvMsTo1fc(5U) /*!< GTA Digital 2.0 6.10.4.1 & B.2 */
  196. #define RFAL_GT_NFCB rfalConvMsTo1fc(5U) /*!< GTB Digital 2.0 7.9.4.1 & B.3 */
  197. #define RFAL_GT_NFCF rfalConvMsTo1fc(20U) /*!< GTF Digital 2.0 8.7.4.1 & B.4 */
  198. #define RFAL_GT_NFCV rfalConvMsTo1fc(5U) /*!< GTV Digital 2.0 9.7.5.1 & B.5 */
  199. #define RFAL_GT_PICOPASS rfalConvMsTo1fc(1U) /*!< GT Picopass */
  200. #define RFAL_GT_AP2P rfalConvMsTo1fc(5U) /*!< TIRFG Ecma 340 11.1.1 */
  201. #define RFAL_GT_AP2P_ADJUSTED rfalConvMsTo1fc(5U+25U) /*!< Adjusted GT for greater interoperability (Sony XPERIA P, Nokia N9, Huawei P2) */
  202. /* RFAL Frame Delay Time (FDT) Listen default values */
  203. #define RFAL_FDT_LISTEN_NFCA_POLLER 1172U /*!< FDTA,LISTEN,MIN (n=9) Last bit: Logic "1" - tnn,min/2 Digital 1.1 6.10 ; EMV CCP Spec Book D v2.01 4.8.1.3 */
  204. #define RFAL_FDT_LISTEN_NFCB_POLLER 1008U /*!< TR0B,MIN Digital 1.1 7.1.3 & A.3 ; EMV CCP Spec Book D v2.01 4.8.1.3 & Table A.5 */
  205. #define RFAL_FDT_LISTEN_NFCF_POLLER 2672U /*!< TR0F,LISTEN,MIN Digital 1.1 8.7.1.1 & A.4 */
  206. #define RFAL_FDT_LISTEN_NFCV_POLLER 4310U /*!< FDTV,LISTEN,MIN t1 min Digital 2.1 B.5 ; ISO15693-3 2009 9.1 */
  207. #define RFAL_FDT_LISTEN_PICOPASS_POLLER 3400U /*!< ISO15693 t1 min - observed adjustment */
  208. #define RFAL_FDT_LISTEN_AP2P_POLLER 64U /*!< FDT AP2P No actual FDTListen is required as fields switch and collision avoidance */
  209. #define RFAL_FDT_LISTEN_NFCA_LISTENER 1172U /*!< FDTA,LISTEN,MIN Digital 1.1 6.10 */
  210. #define RFAL_FDT_LISTEN_NFCB_LISTENER 1024U /*!< TR0B,MIN Digital 1.1 7.1.3 & A.3 ; EMV CCP Spec Book D v2.01 4.8.1.3 & Table A.5 */
  211. #define RFAL_FDT_LISTEN_NFCF_LISTENER 2688U /*!< TR0F,LISTEN,MIN Digital 2.1 8.7.1.1 & B.4 */
  212. #define RFAL_FDT_LISTEN_AP2P_LISTENER 64U /*!< FDT AP2P No actual FDTListen exists as fields switch and collision avoidance */
  213. /* RFAL Frame Delay Time (FDT) Poll default values */
  214. #define RFAL_FDT_POLL_NFCA_POLLER 6780U /*!< FDTA,POLL,MIN Digital 1.1 6.10.3.1 & A.2 */
  215. #define RFAL_FDT_POLL_NFCA_T1T_POLLER 384U /*!< RRDDT1T,MIN,B1 Digital 1.1 10.7.1 & A.5 */
  216. #define RFAL_FDT_POLL_NFCB_POLLER 6780U /*!< FDTB,POLL,MIN = TR2B,MIN,DEFAULT Digital 1.1 7.9.3 & A.3 ; EMVCo 3.0 FDTB,PCD,MIN Table A.5 */
  217. #define RFAL_FDT_POLL_NFCF_POLLER 6800U /*!< FDTF,POLL,MIN Digital 2.1 8.7.3 & B.4 */
  218. #define RFAL_FDT_POLL_NFCV_POLLER 4192U /*!< FDTV,POLL Digital 2.1 9.7.3.1 & B.5 */
  219. #define RFAL_FDT_POLL_PICOPASS_POLLER 1790U /*!< FDT Max */
  220. #define RFAL_FDT_POLL_AP2P_POLLER 0U /*!< FDT AP2P No actual FDTPoll exists as fields switch and collision avoidance */
  221. /*
  222. ******************************************************************************
  223. * GLOBAL TYPES
  224. ******************************************************************************
  225. */
  226. /*! RFAL modes */
  227. typedef enum {
  228. RFAL_MODE_NONE = 0, /*!< No mode selected/defined */
  229. RFAL_MODE_POLL_NFCA = 1, /*!< Mode to perform as NFCA (ISO14443A) Poller (PCD) */
  230. RFAL_MODE_POLL_NFCA_T1T = 2, /*!< Mode to perform as NFCA T1T (Topaz) Poller (PCD) */
  231. RFAL_MODE_POLL_NFCB = 3, /*!< Mode to perform as NFCB (ISO14443B) Poller (PCD) */
  232. RFAL_MODE_POLL_B_PRIME = 4, /*!< Mode to perform as B' Calypso (Innovatron) (PCD) */
  233. RFAL_MODE_POLL_B_CTS = 5, /*!< Mode to perform as CTS Poller (PCD) */
  234. RFAL_MODE_POLL_NFCF = 6, /*!< Mode to perform as NFCF (FeliCa) Poller (PCD) */
  235. RFAL_MODE_POLL_NFCV = 7, /*!< Mode to perform as NFCV (ISO15963) Poller (PCD) */
  236. RFAL_MODE_POLL_PICOPASS = 8, /*!< Mode to perform as PicoPass / iClass Poller (PCD) */
  237. RFAL_MODE_POLL_ACTIVE_P2P = 9, /*!< Mode to perform as Active P2P (ISO18092) Initiator */
  238. RFAL_MODE_LISTEN_NFCA = 10, /*!< Mode to perform as NFCA (ISO14443A) Listener (PICC) */
  239. RFAL_MODE_LISTEN_NFCB = 11, /*!< Mode to perform as NFCA (ISO14443B) Listener (PICC) */
  240. RFAL_MODE_LISTEN_NFCF = 12, /*!< Mode to perform as NFCA (ISO15963) Listener (PICC) */
  241. RFAL_MODE_LISTEN_ACTIVE_P2P = 13 /*!< Mode to perform as Active P2P (ISO18092) Target */
  242. } rfalMode;
  243. /*! RFAL Bit rates */
  244. typedef enum {
  245. RFAL_BR_106 = 0, /*!< Bit Rate 106 kbit/s (fc/128) */
  246. RFAL_BR_212 = 1, /*!< Bit Rate 212 kbit/s (fc/64) */
  247. RFAL_BR_424 = 2, /*!< Bit Rate 424 kbit/s (fc/32) */
  248. RFAL_BR_848 = 3, /*!< Bit Rate 848 kbit/s (fc/16) */
  249. RFAL_BR_1695 = 4, /*!< Bit Rate 1695 kbit/s (fc/8) */
  250. RFAL_BR_3390 = 5, /*!< Bit Rate 3390 kbit/s (fc/4) */
  251. RFAL_BR_6780 = 6, /*!< Bit Rate 6780 kbit/s (fc/2) */
  252. RFAL_BR_13560 = 7, /*!< Bit Rate 13560 kbit/s (fc) */
  253. RFAL_BR_52p97 = 0xEB, /*!< Bit Rate 52.97 kbit/s (fc/256) Fast Mode VICC->VCD */
  254. RFAL_BR_26p48 = 0xEC, /*!< Bit Rate 26,48 kbit/s (fc/512) NFCV VICC->VCD & VCD->VICC 1of4 */
  255. RFAL_BR_1p66 = 0xED, /*!< Bit Rate 1,66 kbit/s (fc/8192) NFCV VCD->VICC 1of256 */
  256. RFAL_BR_KEEP = 0xFF /*!< Value indicating to keep the same previous bit rate */
  257. } rfalBitRate;
  258. /*! RFAL Compliance modes for upper modules */
  259. typedef enum {
  260. RFAL_COMPLIANCE_MODE_NFC, /*!< Perform with NFC Forum 1.1 compliance */
  261. RFAL_COMPLIANCE_MODE_EMV, /*!< Perform with EMVCo compliance */
  262. RFAL_COMPLIANCE_MODE_ISO /*!< Perform with ISO10373 compliance */
  263. }rfalComplianceMode;
  264. /*! RFAL main states flags */
  265. typedef enum {
  266. RFAL_STATE_IDLE = 0,
  267. RFAL_STATE_INIT = 1,
  268. RFAL_STATE_MODE_SET = 2,
  269. RFAL_STATE_TXRX = 3,
  270. RFAL_STATE_LM = 4,
  271. RFAL_STATE_WUM = 5
  272. } rfalState;
  273. /*! RFAL transceive states */
  274. typedef enum {
  275. RFAL_TXRX_STATE_IDLE = 0,
  276. RFAL_TXRX_STATE_INIT = 1,
  277. RFAL_TXRX_STATE_START = 2,
  278. RFAL_TXRX_STATE_TX_IDLE = 11,
  279. RFAL_TXRX_STATE_TX_WAIT_GT = 12,
  280. RFAL_TXRX_STATE_TX_WAIT_FDT = 13,
  281. RFAL_TXRX_STATE_TX_TRANSMIT = 14,
  282. RFAL_TXRX_STATE_TX_WAIT_WL = 15,
  283. RFAL_TXRX_STATE_TX_RELOAD_FIFO = 16,
  284. RFAL_TXRX_STATE_TX_WAIT_TXE = 17,
  285. RFAL_TXRX_STATE_TX_DONE = 18,
  286. RFAL_TXRX_STATE_TX_FAIL = 19,
  287. RFAL_TXRX_STATE_RX_IDLE = 81,
  288. RFAL_TXRX_STATE_RX_WAIT_EON = 82,
  289. RFAL_TXRX_STATE_RX_WAIT_RXS = 83,
  290. RFAL_TXRX_STATE_RX_WAIT_RXE = 84,
  291. RFAL_TXRX_STATE_RX_READ_FIFO = 85,
  292. RFAL_TXRX_STATE_RX_ERR_CHECK = 86,
  293. RFAL_TXRX_STATE_RX_READ_DATA = 87,
  294. RFAL_TXRX_STATE_RX_WAIT_EOF = 88,
  295. RFAL_TXRX_STATE_RX_DONE = 89,
  296. RFAL_TXRX_STATE_RX_FAIL = 90,
  297. } rfalTransceiveState;
  298. /*! RFAL transceive flags */
  299. enum {
  300. RFAL_TXRX_FLAGS_CRC_TX_AUTO = (0U<<0), /*!< CRC will be generated automatic upon transmission */
  301. RFAL_TXRX_FLAGS_CRC_TX_MANUAL = (1U<<0), /*!< CRC was calculated manually, included in txBuffer */
  302. RFAL_TXRX_FLAGS_CRC_RX_KEEP = (1U<<1), /*!< Upon Reception keep the CRC in rxBuffer (reflected on rcvd length) */
  303. RFAL_TXRX_FLAGS_CRC_RX_REMV = (0U<<1), /*!< Enable CRC check and remove the CRC from rxBuffer */
  304. RFAL_TXRX_FLAGS_NFCIP1_ON = (1U<<2), /*!< Enable NFCIP1 mode: Add SB(F0) and LEN bytes during Tx and skip SB(F0) byte during Rx */
  305. RFAL_TXRX_FLAGS_NFCIP1_OFF = (0U<<2), /*!< Disable NFCIP1 mode: do not append protocol bytes while Tx nor skip while Rx */
  306. RFAL_TXRX_FLAGS_AGC_OFF = (1U<<3), /*!< Disable Automatic Gain Control, improving multiple devices collision detection */
  307. RFAL_TXRX_FLAGS_AGC_ON = (0U<<3), /*!< Enable Automatic Gain Control, improving single device reception */
  308. RFAL_TXRX_FLAGS_PAR_RX_KEEP = (1U<<4), /*!< Disable Parity and CRC check and keep the Parity and CRC bits in the received buffer */
  309. RFAL_TXRX_FLAGS_PAR_RX_REMV = (0U<<0), /*!< Enable Parity check and remove the parity bits from the received buffer */
  310. RFAL_TXRX_FLAGS_PAR_TX_NONE = (1U<<5), /*!< Disable automatic Parity generation (ISO14443A) and use the one provided in the buffer*/
  311. RFAL_TXRX_FLAGS_PAR_TX_AUTO = (0U<<5), /*!< Enable automatic Parity generation (ISO14443A) */
  312. RFAL_TXRX_FLAGS_NFCV_FLAG_MANUAL = (1U<<6), /*!< Disable automatic adaption of flag byte (ISO15693) according to current comm params */
  313. RFAL_TXRX_FLAGS_NFCV_FLAG_AUTO = (0U<<6), /*!< Enable automatic adaption of flag byte (ISO115693) according to current comm params */
  314. };
  315. /*! RFAL error handling */
  316. typedef enum {
  317. RFAL_ERRORHANDLING_NONE = 0, /*!< No special error handling will be performed */
  318. RFAL_ERRORHANDLING_NFC = 1, /*!< Error handling set to perform as NFC compliant device */
  319. RFAL_ERRORHANDLING_EMVCO = 2 /*!< Error handling set to perform as EMVCo compliant device */
  320. } rfalEHandling;
  321. /*! Struct that holds all context to be used on a Transceive */
  322. typedef struct {
  323. uint8_t* txBuf; /*!< (In) Buffer where outgoing message is located */
  324. uint16_t txBufLen; /*!< (In) Length of the outgoing message in bits */
  325. uint8_t* rxBuf; /*!< (Out) Buffer where incoming message will be placed */
  326. uint16_t rxBufLen; /*!< (In) Maximum length of the incoming message in bits */
  327. uint16_t* rxRcvdLen; /*!< (Out) Actual received length in bits */
  328. uint32_t flags; /*!< (In) TransceiveFlags indication special handling */
  329. uint32_t fwt; /*!< (In) Frame Waiting Time in 1/fc */
  330. } rfalTransceiveContext;
  331. /*! System callback to indicate an event that requires a system reRun */
  332. typedef void (* rfalUpperLayerCallback)(void);
  333. /*! Callback to be executed before a Transceive */
  334. typedef void (* rfalPreTxRxCallback)(void);
  335. /*! Callback to be executed after a Transceive */
  336. typedef void (* rfalPostTxRxCallback)(void);
  337. /*******************************************************************************/
  338. /* ISO14443A */
  339. /*******************************************************************************/
  340. /*! RFAL ISO 14443A Short Frame Command */
  341. typedef enum
  342. {
  343. RFAL_14443A_SHORTFRAME_CMD_WUPA = 0x52, /*!< ISO14443A WUPA / NFC-A ALL_REQ */
  344. RFAL_14443A_SHORTFRAME_CMD_REQA = 0x26 /*!< ISO14443A REQA / NFC-A SENS_REQ */
  345. } rfal14443AShortFrameCmd;
  346. /*******************************************************************************/
  347. /*******************************************************************************/
  348. /* FeliCa */
  349. /*******************************************************************************/
  350. #define RFAL_FELICA_LEN_LEN 1U /*!< FeliCa LEN byte length */
  351. #define RFAL_FELICA_POLL_REQ_LEN (RFAL_FELICA_LEN_LEN + 1U + 2U + 1U + 1U) /*!< FeliCa Poll Request length (LEN + CMD + SC + RC + TSN) */
  352. #define RFAL_FELICA_POLL_RES_LEN (RFAL_FELICA_LEN_LEN + 1U + 8U + 8U + 2U) /*!< Maximum FeliCa Poll Response length (LEN + CMD + NFCID2 + PAD + RD) */
  353. #define RFAL_FELICA_POLL_MAX_SLOTS 16U /*!< Maximum number of slots (TSN) on FeliCa Poll */
  354. /*! NFC-F RC (Request Code) codes NFC Forum Digital 1.1 Table 42 */
  355. enum
  356. {
  357. RFAL_FELICA_POLL_RC_NO_REQUEST = 0x00, /*!< RC: No System Code information requested */
  358. RFAL_FELICA_POLL_RC_SYSTEM_CODE = 0x01, /*!< RC: System Code information requested */
  359. RFAL_FELICA_POLL_RC_COM_PERFORMANCE = 0x02 /*!< RC: Advanced protocol features supported */
  360. };
  361. /*! NFC-F TSN (Time Slot Number) codes NFC Forum Digital 1.1 Table 43 */
  362. typedef enum
  363. {
  364. RFAL_FELICA_1_SLOT = 0, /*!< TSN with number of Time Slots: 1 */
  365. RFAL_FELICA_2_SLOTS = 1, /*!< TSN with number of Time Slots: 2 */
  366. RFAL_FELICA_4_SLOTS = 3, /*!< TSN with number of Time Slots: 4 */
  367. RFAL_FELICA_8_SLOTS = 7, /*!< TSN with number of Time Slots: 8 */
  368. RFAL_FELICA_16_SLOTS = 15 /*!< TSN with number of Time Slots: 16 */
  369. } rfalFeliCaPollSlots;
  370. /*! NFCF Poll Response NFC Forum Digital 1.1 Table 44 */
  371. typedef uint8_t rfalFeliCaPollRes[RFAL_FELICA_POLL_RES_LEN];
  372. /*******************************************************************************/
  373. /*******************************************************************************/
  374. /* Listen Mode */
  375. /*******************************************************************************/
  376. /*! RFAL Listen Mode NFCID Length */
  377. typedef enum
  378. {
  379. RFAL_LM_NFCID_LEN_04 = RFAL_NFCID1_SINGLE_LEN, /*!< Listen mode indicates 4 byte NFCID */
  380. RFAL_LM_NFCID_LEN_07 = RFAL_NFCID1_DOUBLE_LEN, /*!< Listen mode indicates 7 byte NFCID */
  381. RFAL_LM_NFCID_LEN_10 = RFAL_NFCID1_TRIPLE_LEN, /*!< Listen mode indicates 10 byte NFCID */
  382. } rfalLmNfcidLen;
  383. /*! RFAL Listen Mode States */
  384. typedef enum
  385. {
  386. RFAL_LM_STATE_NOT_INIT = 0x00, /*!< Not Initialized state */
  387. RFAL_LM_STATE_POWER_OFF = 0x01, /*!< Power Off state */
  388. RFAL_LM_STATE_IDLE = 0x02, /*!< Idle state Activity 1.1 5.2 */
  389. RFAL_LM_STATE_READY_A = 0x03, /*!< Ready A state Activity 1.1 5.3 5.4 & 5.5 */
  390. RFAL_LM_STATE_READY_B = 0x04, /*!< Ready B state Activity 1.1 5.11 5.12 */
  391. RFAL_LM_STATE_READY_F = 0x05, /*!< Ready F state Activity 1.1 5.15 */
  392. RFAL_LM_STATE_ACTIVE_A = 0x06, /*!< Active A state Activity 1.1 5.6 */
  393. RFAL_LM_STATE_CARDEMU_4A = 0x07, /*!< Card Emulation 4A state Activity 1.1 5.10 */
  394. RFAL_LM_STATE_CARDEMU_4B = 0x08, /*!< Card Emulation 4B state Activity 1.1 5.14 */
  395. RFAL_LM_STATE_CARDEMU_3 = 0x09, /*!< Card Emulation 3 state Activity 1.1 5.18 */
  396. RFAL_LM_STATE_TARGET_A = 0x0A, /*!< Target A state Activity 1.1 5.9 */
  397. RFAL_LM_STATE_TARGET_F = 0x0B, /*!< Target F state Activity 1.1 5.17 */
  398. RFAL_LM_STATE_SLEEP_A = 0x0C, /*!< Sleep A state Activity 1.1 5.7 */
  399. RFAL_LM_STATE_SLEEP_B = 0x0D, /*!< Sleep B state Activity 1.1 5.13 */
  400. RFAL_LM_STATE_READY_Ax = 0x0E, /*!< Ready A* state Activity 1.1 5.3 5.4 & 5.5 */
  401. RFAL_LM_STATE_ACTIVE_Ax = 0x0F, /*!< Active A* state Activity 1.1 5.6 */
  402. RFAL_LM_STATE_SLEEP_AF = 0x10, /*!< Sleep AF state Activity 1.1 5.19 */
  403. } rfalLmState;
  404. /*! RFAL Listen Mode Passive A configs */
  405. typedef struct
  406. {
  407. rfalLmNfcidLen nfcidLen; /*!< NFCID Len (4, 7 or 10 bytes) */
  408. uint8_t nfcid[RFAL_NFCID1_TRIPLE_LEN]; /*!< NFCID */
  409. uint8_t SENS_RES[RFAL_LM_SENS_RES_LEN]; /*!< NFC-106k; SENS_REQ Response */
  410. uint8_t SEL_RES; /*!< SEL_RES (SAK) with complete NFCID1 (UID) */
  411. } rfalLmConfPA;
  412. /*! RFAL Listen Mode Passive B configs */
  413. typedef struct
  414. {
  415. uint8_t SENSB_RES[RFAL_LM_SENSB_RES_LEN]; /*!< SENSF_RES */
  416. } rfalLmConfPB;
  417. /*! RFAL Listen Mode Passive F configs */
  418. typedef struct
  419. {
  420. uint8_t SC[RFAL_LM_SENSF_SC_LEN]; /*!< System Code to listen for */
  421. uint8_t SENSF_RES[RFAL_LM_SENSF_RES_LEN]; /*!< SENSF_RES */
  422. } rfalLmConfPF;
  423. /*******************************************************************************/
  424. /*******************************************************************************/
  425. /* Wake-Up Mode */
  426. /*******************************************************************************/
  427. #define RFAL_WUM_REFERENCE_AUTO 0xFFU /*!< Indicates new reference is set by the driver*/
  428. /*! RFAL Wake-Up Mode States */
  429. typedef enum
  430. {
  431. RFAL_WUM_STATE_NOT_INIT = 0x00, /*!< Not Initialized state */
  432. RFAL_WUM_STATE_ENABLED = 0x01, /*!< Wake-Up mode is enabled */
  433. RFAL_WUM_STATE_ENABLED_WOKE = 0x02, /*!< Wake-Up mode enabled and has received IRQ(s)*/
  434. } rfalWumState;
  435. /*! RFAL Wake-Up Period/Timer */
  436. typedef enum
  437. {
  438. RFAL_WUM_PERIOD_10MS = 0x00, /*!< Wake-Up timer 10ms */
  439. RFAL_WUM_PERIOD_20MS = 0x01, /*!< Wake-Up timer 20ms */
  440. RFAL_WUM_PERIOD_30MS = 0x02, /*!< Wake-Up timer 30ms */
  441. RFAL_WUM_PERIOD_40MS = 0x03, /*!< Wake-Up timer 40ms */
  442. RFAL_WUM_PERIOD_50MS = 0x04, /*!< Wake-Up timer 50ms */
  443. RFAL_WUM_PERIOD_60MS = 0x05, /*!< Wake-Up timer 60ms */
  444. RFAL_WUM_PERIOD_70MS = 0x06, /*!< Wake-Up timer 70ms */
  445. RFAL_WUM_PERIOD_80MS = 0x07, /*!< Wake-Up timer 80ms */
  446. RFAL_WUM_PERIOD_100MS = 0x10, /*!< Wake-Up timer 100ms */
  447. RFAL_WUM_PERIOD_200MS = 0x11, /*!< Wake-Up timer 200ms */
  448. RFAL_WUM_PERIOD_300MS = 0x12, /*!< Wake-Up timer 300ms */
  449. RFAL_WUM_PERIOD_400MS = 0x13, /*!< Wake-Up timer 400ms */
  450. RFAL_WUM_PERIOD_500MS = 0x14, /*!< Wake-Up timer 500ms */
  451. RFAL_WUM_PERIOD_600MS = 0x15, /*!< Wake-Up timer 600ms */
  452. RFAL_WUM_PERIOD_700MS = 0x16, /*!< Wake-Up timer 700ms */
  453. RFAL_WUM_PERIOD_800MS = 0x17, /*!< Wake-Up timer 800ms */
  454. } rfalWumPeriod;
  455. /*! RFAL Wake-Up Period/Timer */
  456. typedef enum
  457. {
  458. RFAL_WUM_AA_WEIGHT_4 = 0x00, /*!< Wake-Up Auto Average Weight 4 */
  459. RFAL_WUM_AA_WEIGHT_8 = 0x01, /*!< Wake-Up Auto Average Weight 8 */
  460. RFAL_WUM_AA_WEIGHT_16 = 0x02, /*!< Wake-Up Auto Average Weight 16 */
  461. RFAL_WUM_AA_WEIGHT_32 = 0x03, /*!< Wake-Up Auto Average Weight 32 */
  462. } rfalWumAAWeight;
  463. /*! RFAL Wake-Up Mode configuration */
  464. typedef struct
  465. {
  466. rfalWumPeriod period; /*!< Wake-Up Timer period;how often measurement(s) is performed */
  467. bool irqTout; /*!< IRQ at every timeout will refresh the measurement(s) */
  468. bool swTagDetect;/*!< Use SW Tag Detection instead of HW Wake-Up mode */
  469. struct{
  470. bool enabled; /*!< Inductive Amplitude measurement enabled */
  471. uint8_t delta; /*!< Delta between the reference and measurement to wake-up */
  472. uint16_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */
  473. bool autoAvg; /*!< Use the HW Auto Averaging feature */
  474. bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */
  475. rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */
  476. }indAmp; /*!< Inductive Amplitude Configuration */
  477. struct{
  478. bool enabled; /*!< Inductive Phase measurement enabled */
  479. uint8_t delta; /*!< Delta between the reference and measurement to wake-up */
  480. uint16_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */
  481. bool autoAvg; /*!< Use the HW Auto Averaging feature */
  482. bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */
  483. rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */
  484. }indPha; /*!< Inductive Phase Configuration */
  485. struct{
  486. bool enabled; /*!< Capacitive measurement enabled */
  487. uint8_t delta; /*!< Delta between the reference and measurement to wake-up */
  488. uint16_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */
  489. bool autoAvg; /*!< Use the HW Auto Averaging feature */
  490. bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */
  491. rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */
  492. }cap; /*!< Capacitive Configuration */
  493. } rfalWakeUpConfig;
  494. /*******************************************************************************/
  495. /*
  496. ******************************************************************************
  497. * GLOBAL FUNCTION PROTOTYPES
  498. ******************************************************************************
  499. */
  500. /*!
  501. *****************************************************************************
  502. * \brief RFAL Initialize
  503. *
  504. * Initializes RFAL layer and the ST25R391x
  505. * Ensures that ST25R391x is properly connected and returns error if any problem
  506. * is detected
  507. *
  508. * \warning rfalAnalogConfigInitialize() should be called before so that
  509. * the Analog config table has been previously initialized.
  510. *
  511. * \return ERR_HW_MISMATCH : Expected HW do not match or communication error
  512. * \return ERR_NONE : No error
  513. *****************************************************************************
  514. */
  515. ReturnCode rfalInitialize( void );
  516. /*!
  517. *****************************************************************************
  518. * \brief RFAL Calibrate
  519. *
  520. * Performs necessary calibration of RF chip in case it is indicated by current
  521. * register settings. E.g. antenna calibration and regulator calibration
  522. *
  523. * \return ERR_WRONG_STATE : RFAL not initialized
  524. * \return ERR_NONE : No error
  525. *
  526. *****************************************************************************
  527. */
  528. ReturnCode rfalCalibrate( void );
  529. /*!
  530. *****************************************************************************
  531. * \brief RFAL Adjust Regulators
  532. *
  533. * Adjusts ST25R391x regulators
  534. *
  535. * \param[out] result : the result of the calibrate antenna in mV
  536. * NULL if result not requested
  537. *
  538. * \return ERR_WRONG_STATE : RFAL not initialized
  539. * \return ERR_NONE : No error
  540. *
  541. *****************************************************************************
  542. */
  543. ReturnCode rfalAdjustRegulators( uint16_t* result );
  544. /*!
  545. *****************************************************************************
  546. * \brief RFAL Set System Callback
  547. *
  548. * Sets a callback for the driver to call when an event has occurred that
  549. * may require the system to be notified
  550. *
  551. * \param[in] pFunc : method pointer for the upper layer callback
  552. *
  553. *****************************************************************************
  554. */
  555. void rfalSetUpperLayerCallback( rfalUpperLayerCallback pFunc );
  556. /*!
  557. *****************************************************************************
  558. * \brief RFAL Set Pre Tx Callback
  559. *
  560. * Sets a callback for the driver to call before a Transceive
  561. *
  562. * \param[in] pFunc : method pointer for the Pre Tx callback
  563. *
  564. *****************************************************************************
  565. */
  566. void rfalSetPreTxRxCallback( rfalPreTxRxCallback pFunc );
  567. /*!
  568. *****************************************************************************
  569. * \brief RFAL Set Post Tx Callback
  570. *
  571. * Sets a callback for the driver to call after a Transceive
  572. *
  573. * \param[in] pFunc : method pointer for the Post Tx callback
  574. *
  575. *****************************************************************************
  576. */
  577. void rfalSetPostTxRxCallback( rfalPostTxRxCallback pFunc );
  578. /*!
  579. *****************************************************************************
  580. * \brief RFAL Deinitialize
  581. *
  582. * Deinitializes RFAL layer and the ST25R391x
  583. *
  584. * \return ERR_NONE : No error
  585. *
  586. *****************************************************************************
  587. */
  588. ReturnCode rfalDeinitialize( void );
  589. /*!
  590. *****************************************************************************
  591. * \brief RFAL Set Mode
  592. *
  593. * Sets the mode that RFAL will operate on the following communications.
  594. * Proper initializations will be performed on the ST25R391x
  595. *
  596. * \warning bit rate value RFAL_BR_KEEP is not allowed, only in rfalSetBitRate()
  597. *
  598. * \warning the mode will be applied immediately on the RFchip regardless of
  599. * any ongoing operations like Transceive, ListenMode
  600. *
  601. * \param[in] mode : mode for the RFAL/RFchip to perform
  602. * \param[in] txBR : transmit bit rate
  603. * \param[in] rxBR : receive bit rate
  604. *
  605. * \see rfalIsGTExpired
  606. * \see rfalMode
  607. *
  608. * \return ERR_WRONG_STATE : RFAL not initialized
  609. * \return ERR_PARAM : Invalid parameter
  610. * \return ERR_NONE : No error
  611. *
  612. *****************************************************************************
  613. */
  614. ReturnCode rfalSetMode( rfalMode mode, rfalBitRate txBR, rfalBitRate rxBR );
  615. /*!
  616. *****************************************************************************
  617. * \brief RFAL Get Mode
  618. *
  619. * Gets the mode that RFAL is set to operate
  620. *
  621. * \see rfalMode
  622. *
  623. * \return rfalMode : The current RFAL mode
  624. *****************************************************************************
  625. */
  626. rfalMode rfalGetMode( void );
  627. /*!
  628. *****************************************************************************
  629. * \brief RFAL Set Bit Rate
  630. *
  631. * Sets the Tx and Rx bit rates with the given values
  632. * The bit rate change is applied on the RF chip remaining in the same
  633. * mode previous defined with rfalSetMode()
  634. *
  635. * If no mode is defined bit rates will not be applied and an error
  636. * is returned
  637. *
  638. * \param[in] txBR : transmit bit rate
  639. * \param[in] rxBR : receive bit rate
  640. *
  641. * \see rfalSetMode
  642. * \see rfalMode
  643. * \see rfalBitRate
  644. *
  645. * \return ERR_WRONG_STATE : RFAL not initialized
  646. * \return ERR_PARAM : Invalid parameter
  647. * \return ERR_NOT_IMPLEMENTED : Mode not implemented
  648. * \return ERR_NONE : No error
  649. *
  650. *****************************************************************************
  651. */
  652. ReturnCode rfalSetBitRate( rfalBitRate txBR, rfalBitRate rxBR );
  653. /*!
  654. *****************************************************************************
  655. * \brief RFAL Get Bit Rate
  656. *
  657. * Gets the Tx and Rx current bit rates
  658. *
  659. * If RFAL is not initialized or mode not set the bit rates return will
  660. * be invalid RFAL_BR_KEEP
  661. *
  662. * \param[out] txBR : RFAL's current Tx Bit Rate
  663. * \param[out] rxBR : RFAL's current Rx Bit Rate
  664. *
  665. * \see rfalSetBitRate
  666. * \see rfalBitRate
  667. *
  668. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  669. * \return ERR_NONE : No error
  670. *****************************************************************************
  671. */
  672. ReturnCode rfalGetBitRate( rfalBitRate *txBR, rfalBitRate *rxBR );
  673. /*!
  674. *****************************************************************************
  675. * \brief Set Error Handling Mode
  676. *
  677. * Sets the error handling mode to be used by the RFAL
  678. *
  679. * \param[in] eHandling : the error handling mode
  680. *
  681. *****************************************************************************
  682. */
  683. void rfalSetErrorHandling( rfalEHandling eHandling );
  684. /*!
  685. *****************************************************************************
  686. * \brief Get Error Handling Mode
  687. *
  688. * Gets the error handling mode currently used by the RFAL
  689. *
  690. * \return rfalEHandling : Current error handling mode
  691. *****************************************************************************
  692. */
  693. rfalEHandling rfalGetErrorHandling( void );
  694. /*!
  695. *****************************************************************************
  696. * \brief Set Observation Mode
  697. *
  698. * Sets ST25R391x observation modes for RF debug purposes
  699. *
  700. * \param[in] txMode : the observation mode to be used during transmission
  701. * \param[in] rxMode : the observation mode to be used during reception
  702. *
  703. * \warning The Observation Mode is an advanced feature and should be set
  704. * according to the documentation of the part number in use.
  705. * Please refer to the corresponding Datasheet or Application Note(s)
  706. *****************************************************************************
  707. */
  708. void rfalSetObsvMode( uint8_t txMode, uint8_t rxMode );
  709. /*!
  710. *****************************************************************************
  711. * \brief Get Observation Mode
  712. *
  713. * Gets ST25R391x the current configured observation modes
  714. *
  715. * \param[in] txMode : the current observation mode configured for transmission
  716. * \param[in] rxMode : the current observation mode configured for reception
  717. *
  718. *****************************************************************************
  719. */
  720. void rfalGetObsvMode( uint8_t* txMode, uint8_t* rxMode );
  721. /*!
  722. *****************************************************************************
  723. * \brief Disable Observation Mode
  724. *
  725. * Disables the ST25R391x observation mode
  726. *****************************************************************************
  727. */
  728. void rfalDisableObsvMode( void );
  729. /*!
  730. *****************************************************************************
  731. * \brief RFAL Set FDT Poll
  732. *
  733. * Sets the Frame Delay Time (FDT) to be used on the following
  734. * communications.
  735. *
  736. * FDT Poll is the minimum time following a Poll Frame during
  737. * which no subsequent Poll Frame can be sent (without a response from
  738. * the Listener in between)
  739. * FDTx,PP,MIN - Digital 1.1 6.10.2 & 7.9.2 & 8.7.2
  740. *
  741. * \param[in] FDTPoll : Frame Delay Time in 1/fc cycles
  742. *
  743. *****************************************************************************
  744. */
  745. void rfalSetFDTPoll( uint32_t FDTPoll );
  746. /*!
  747. *****************************************************************************
  748. * \brief RFAL Set FDT Poll
  749. *
  750. * Gets the current Frame Delay Time (FDT)
  751. *
  752. * FDT Poll is the minimum time following a Poll Frame during
  753. * which no subsequent Poll Frame can be sent (without a response from
  754. * the Listener in between)
  755. * FDTx,PP,MIN - Digital 1.1 6.10.2 & 7.9.2 & 8.7.2
  756. *
  757. * \return FDT : current FDT value in 1/fc cycles
  758. *
  759. *****************************************************************************
  760. */
  761. uint32_t rfalGetFDTPoll( void );
  762. /*!
  763. *****************************************************************************
  764. * \brief RFAL Set FDT Listen
  765. *
  766. * Sets the Frame Delay Time (FDT) Listen minimum to be used on the
  767. * following communications.
  768. *
  769. * FDT Listen is the minimum time between a Poll Frame and a Listen Frame
  770. * FDTx,LISTEN,MIN - Digital 1.1 6.10.1 & 7.9.1 & 8.7.1
  771. *
  772. * \param[in] FDTListen : Frame Delay Time in 1/fc cycles
  773. *
  774. *****************************************************************************
  775. */
  776. void rfalSetFDTListen( uint32_t FDTListen );
  777. /*!
  778. *****************************************************************************
  779. * \brief RFAL Set FDT Listen
  780. *
  781. * Gets the Frame Delay Time (FDT) Listen minimum
  782. *
  783. * FDT Listen is the minimum time between a Poll Frame and a Listen Frame
  784. * FDTx,LISTEN,MIN - Digital 1.1 6.10.1 & 7.9.1 & 8.7.1
  785. *
  786. * \return FDT : current FDT value in 1/fc cycles
  787. *
  788. *****************************************************************************
  789. */
  790. uint32_t rfalGetFDTListen( void );
  791. /*!
  792. *****************************************************************************
  793. * \brief RFAL Get GT
  794. *
  795. * Gets the current Guard Time (GT)
  796. *
  797. * GT is the minimum time when a device in Listen Mode is exposed to an
  798. * unmodulated carrier
  799. *
  800. * \return GT : Guard Time in 1/fc cycles
  801. *
  802. *****************************************************************************
  803. */
  804. uint32_t rfalGetGT( void );
  805. /*!
  806. *****************************************************************************
  807. * \brief RFAL Set GT
  808. *
  809. * Sets the Guard Time (GT) to be used on the following communications.
  810. *
  811. * GT is the minimum time when a device in Listen Mode is exposed to an
  812. * unmodulated carrier
  813. *
  814. * \param[in] GT : Guard Time in 1/fc cycles
  815. * RFAL_GT_NONE if no GT should be applied
  816. *
  817. *****************************************************************************
  818. */
  819. void rfalSetGT( uint32_t GT );
  820. /*!
  821. *****************************************************************************
  822. * \brief RFAL Is GT expired
  823. *
  824. * Checks whether the GT timer has expired
  825. *
  826. * \return true : GT has expired or not running
  827. * \return false : GT is still running
  828. *
  829. *****************************************************************************
  830. */
  831. bool rfalIsGTExpired( void );
  832. /*!
  833. *****************************************************************************
  834. * \brief RFAL Turn Field On and Start GT
  835. *
  836. * Turns the Field On, performing Initial Collision Avoidance
  837. *
  838. * After Field On, if GT was set before, it starts the GT timer to be
  839. * used on the following communications.
  840. *
  841. * \return ERR_RF_COLLISION : External field detected
  842. * \return ERR_NONE : Field turned On
  843. *
  844. *****************************************************************************
  845. */
  846. ReturnCode rfalFieldOnAndStartGT( void );
  847. /*!
  848. *****************************************************************************
  849. * \brief RFAL Turn Field Off
  850. *
  851. * Turns the Field Off
  852. *
  853. * \return ERR_NONE : Field turned Off
  854. *****************************************************************************
  855. */
  856. ReturnCode rfalFieldOff( void );
  857. /*****************************************************************************
  858. * Transceive *
  859. *****************************************************************************/
  860. /*!
  861. *****************************************************************************
  862. * \brief RFAL Set transceive context
  863. *
  864. * Set the context that will be used for the following Transceive
  865. * Output and input buffers have to be passed and all other details prior to
  866. * the Transceive itself has been started
  867. *
  868. * This method only sets the context, once set rfalWorker has
  869. * to be executed until is done
  870. *
  871. * \param[in] ctx : the context for the following Transceive
  872. *
  873. * \see rfalWorker
  874. * \see rfalGetTransceiveStatus
  875. *
  876. * \return ERR_NONE : Done with no error
  877. * \return ERR_WRONG_STATE : Not initialized properly
  878. * \return ERR_PARAM : Invalid parameter or configuration
  879. *****************************************************************************
  880. */
  881. ReturnCode rfalStartTransceive( const rfalTransceiveContext *ctx );
  882. /*!
  883. *****************************************************************************
  884. * \brief Get Transceive State
  885. *
  886. * Gets current Transceive internal State
  887. *
  888. * \return rfalTransceiveState : the current Transceive internal State
  889. *****************************************************************************
  890. */
  891. rfalTransceiveState rfalGetTransceiveState( void );
  892. /*!
  893. *****************************************************************************
  894. * \brief Get Transceive Status
  895. *
  896. * Gets current Transceive status
  897. *
  898. * \return ERR_NONE : Transceive done with no error
  899. * \return ERR_BUSY : Transceive ongoing
  900. * \return ERR_XXXX : Error occurred
  901. * \return ERR_TIMEOUT : No response
  902. * \return ERR_FRAMING : Framing error detected
  903. * \return ERR_PAR : Parity error detected
  904. * \return ERR_CRC : CRC error detected
  905. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  906. * \return ERR_RF_COLLISION : Collision detected
  907. * \return ERR_IO : Internal error
  908. *****************************************************************************
  909. */
  910. ReturnCode rfalGetTransceiveStatus( void );
  911. /*!
  912. *****************************************************************************
  913. * \brief Is Transceive in Tx
  914. *
  915. * Checks if Transceive is in Transmission state
  916. *
  917. * \return true Transmission ongoing
  918. * \return false Not in transmission state
  919. *****************************************************************************
  920. */
  921. bool rfalIsTransceiveInTx( void );
  922. /*!
  923. *****************************************************************************
  924. * \brief Is Transceive in Rx
  925. *
  926. * Checks if Transceive is in Reception state
  927. *
  928. * \return true Transmission done/reception ongoing
  929. * \return false Not in reception state
  930. *****************************************************************************
  931. */
  932. bool rfalIsTransceiveInRx( void );
  933. /*!
  934. *****************************************************************************
  935. * \brief Get Transceive RSSI
  936. *
  937. * Gets the RSSI value of the last executed Transceive in mV
  938. *
  939. * \param[out] rssi : RSSI value
  940. *
  941. * \return ERR_NOTSUPP : Feature not supported
  942. * \return ERR_PARAM : Invalid parameter
  943. * \return ERR_NONE : No error
  944. *****************************************************************************
  945. */
  946. ReturnCode rfalGetTransceiveRSSI( uint16_t *rssi );
  947. /*!
  948. *****************************************************************************
  949. * \brief RFAL Worker
  950. *
  951. * This runs RFAL layer, which drives the actual Transceive procedure
  952. * It MUST be executed frequently in order to execute the RFAL internal
  953. * states and perform the requested operations
  954. *
  955. *****************************************************************************
  956. */
  957. void rfalWorker( void );
  958. /*****************************************************************************
  959. * ISO1443A *
  960. *****************************************************************************/
  961. /*!
  962. *****************************************************************************
  963. * \brief Transceives an ISO14443A ShortFrame
  964. *
  965. * Sends REQA to detect if there is any PICC in the field
  966. *
  967. * \param[in] txCmd: Command to be sent:
  968. * 0x52 WUPA / ALL_REQ
  969. * 0x26 REQA / SENS_REQ
  970. *
  971. * \param[in] txCmd : type of short frame to be sent REQA or WUPA
  972. * \param[out] rxBuf : buffer to place the response
  973. * \param[in] rxBufLen : length of rxBuf
  974. * \param[out] rxRcvdLen: received length
  975. * \param[in] fwt : Frame Waiting Time in 1/fc
  976. *
  977. * \warning If fwt is set to RFAL_FWT_NONE it will make endlessly for
  978. * a response, which on a blocking method may not be the
  979. * desired usage
  980. *
  981. * \return ERR_NONE if there is response
  982. * \return ERR_TIMEOUT if there is no response
  983. * \return ERR_COLLISION collision has occurred
  984. *
  985. *****************************************************************************
  986. */
  987. ReturnCode rfalISO14443ATransceiveShortFrame( rfal14443AShortFrameCmd txCmd, uint8_t* rxBuf, uint8_t rxBufLen, uint16_t* rxRcvdLen, uint32_t fwt );
  988. /*!
  989. *****************************************************************************
  990. * \brief Sends an ISO14443A Anticollision Frame
  991. *
  992. * This is use to perform ISO14443A anti-collision.
  993. * \note Anticollision is sent without CRC
  994. *
  995. *
  996. * \param[in] buf : reference to ANTICOLLISION command (with known UID if any) to be sent (also out param)
  997. * reception will be place on this buf after bytesToSend
  998. * \param[in] bytesToSend: reference number of full bytes to be sent (including CMD byte and SEL_PAR)
  999. * if a collision occurs will contain the number of clear bytes
  1000. * \param[in] bitsToSend : reference to number of bits (0-7) to be sent; and received (also out param)
  1001. * if a collision occurs will indicate the number of clear bits (also out param)
  1002. * \param[out] rxLength : reference to the return the received length
  1003. * \param[in] fwt : Frame Waiting Time in 1/fc
  1004. *
  1005. * \return ERR_NONE if there is no error
  1006. *****************************************************************************
  1007. */
  1008. ReturnCode rfalISO14443ATransceiveAnticollisionFrame( uint8_t *buf, uint8_t *bytesToSend, uint8_t *bitsToSend, uint16_t *rxLength, uint32_t fwt );
  1009. /*****************************************************************************
  1010. * FeliCa *
  1011. *****************************************************************************/
  1012. /*!
  1013. *****************************************************************************
  1014. * \brief FeliCa Poll
  1015. *
  1016. * Sends a Poll Request and collects all Poll Responses according to the
  1017. * given slots
  1018. *
  1019. *
  1020. * \param[in] slots : number of slots for the Poll Request
  1021. * \param[in] sysCode : system code (SC) for the Poll Request
  1022. * \param[in] reqCode : request code (RC) for the Poll Request
  1023. * \param[out] pollResList : list of all responses
  1024. * \param[in] pollResListSize : number of responses that can be placed in pollResList
  1025. * \param[out] devicesDetected : number of cards found
  1026. * \param[out] collisionsDetected: number of collisions detected
  1027. *
  1028. * \return ERR_NONE if there is no error
  1029. * \return ERR_TIMEOUT if there is no response
  1030. *****************************************************************************
  1031. */
  1032. ReturnCode rfalFeliCaPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes* pollResList, uint8_t pollResListSize, uint8_t *devicesDetected, uint8_t *collisionsDetected );
  1033. /*****************************************************************************
  1034. * ISO15693 *
  1035. *****************************************************************************/
  1036. /*!
  1037. *****************************************************************************
  1038. * \brief Sends an ISO15693 Anticollision Frame
  1039. *
  1040. * This send the Anticollision|Inventory frame (INVENTORY_REQ)
  1041. *
  1042. * \warning rxBuf must be able to contain the payload and CRC
  1043. *
  1044. * \param[in] txBuf : Buffer where outgoing message is located
  1045. * \param[in] txBufLen : Length of the outgoing message in bytes
  1046. * \param[out] rxBuf : Buffer where incoming message will be placed
  1047. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1048. * \param[out] actLen : Actual received length in bits
  1049. *
  1050. * \return ERR_NONE : Transceive done with no error
  1051. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  1052. * \return ERR_IO : Internal error
  1053. *****************************************************************************
  1054. */
  1055. ReturnCode rfalISO15693TransceiveAnticollisionFrame( uint8_t *txBuf, uint8_t txBufLen, uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen );
  1056. /*!
  1057. *****************************************************************************
  1058. * \brief Sends an ISO15693 Anticollision EOF
  1059. *
  1060. * This sends the Anticollision|Inventory EOF used as a slot marker
  1061. *
  1062. * \warning rxBuf must be able to contain the payload and CRC
  1063. *
  1064. * \param[out] rxBuf : Buffer where incoming message will be placed
  1065. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1066. * \param[out] actLen : Actual received length in bits
  1067. *
  1068. * \return ERR_NONE : Transceive done with no error
  1069. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  1070. * \return ERR_IO : Internal error
  1071. *****************************************************************************
  1072. */
  1073. ReturnCode rfalISO15693TransceiveEOFAnticollision( uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen );
  1074. /*!
  1075. *****************************************************************************
  1076. * \brief Sends an ISO15693 EOF
  1077. *
  1078. * This is method sends an ISO15693 (EoF) used for a Write operation
  1079. *
  1080. * \warning rxBuf must be able to contain the payload and CRC
  1081. *
  1082. * \param[out] rxBuf : Buffer where incoming message will be placed
  1083. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1084. * \param[out] actLen : Actual received length in bytes
  1085. *
  1086. * \return ERR_NONE : Transceive done with no error
  1087. * \return ERR_IO : Internal error
  1088. *****************************************************************************
  1089. */
  1090. ReturnCode rfalISO15693TransceiveEOF( uint8_t *rxBuf, uint8_t rxBufLen, uint16_t *actLen );
  1091. /*!
  1092. *****************************************************************************
  1093. * \brief Transceive Blocking Tx
  1094. *
  1095. * This is method triggers a Transceive and executes it blocking until the
  1096. * Tx has been completed
  1097. *
  1098. * \param[in] txBuf : Buffer where outgoing message is located
  1099. * \param[in] txBufLen : Length of the outgoing message in bytes
  1100. * \param[out] rxBuf : Buffer where incoming message will be placed
  1101. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1102. * \param[out] actLen : Actual received length in bits
  1103. * \param[in] flags : TransceiveFlags indication special handling
  1104. * \param[in] fwt : Frame Waiting Time in 1/fc
  1105. *
  1106. * \return ERR_NONE : Transceive done with no error
  1107. * \return ERR_BUSY : Transceive ongoing
  1108. * \return ERR_XXXX : Error occurred
  1109. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1110. * \return ERR_RF_COLLISION : Collision detected
  1111. * \return ERR_IO : Internal error
  1112. *****************************************************************************
  1113. */
  1114. ReturnCode rfalTransceiveBlockingTx( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, uint32_t flags, uint32_t fwt );
  1115. /*!
  1116. *****************************************************************************
  1117. * \brief Transceive Blocking Rx
  1118. *
  1119. * This is method executes the reception of an ongoing Transceive triggered
  1120. * before by rfalTransceiveBlockingTx()
  1121. *
  1122. * \return ERR_NONE : Transceive done with no error
  1123. * \return ERR_BUSY : Transceive ongoing
  1124. * \return ERR_XXXX : Error occurred
  1125. * \return ERR_TIMEOUT : No response
  1126. * \return ERR_FRAMING : Framing error detected
  1127. * \return ERR_PAR : Parity error detected
  1128. * \return ERR_CRC : CRC error detected
  1129. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1130. * \return ERR_RF_COLLISION : Collision detected
  1131. * \return ERR_IO : Internal error
  1132. *****************************************************************************
  1133. */
  1134. ReturnCode rfalTransceiveBlockingRx( void );
  1135. /*!
  1136. *****************************************************************************
  1137. * \brief Transceive Blocking
  1138. *
  1139. * This is method triggers a Transceive and executes it blocking until it
  1140. * has been completed
  1141. *
  1142. * \param[in] txBuf : Buffer where outgoing message is located
  1143. * \param[in] txBufLen : Length of the outgoing message in bytes
  1144. * \param[out] rxBuf : Buffer where incoming message will be placed
  1145. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1146. * \param[out] actLen : Actual received length in bytes
  1147. * \param[in] flags : TransceiveFlags indication special handling
  1148. * \param[in] fwt : Frame Waiting Time in 1/fc
  1149. *
  1150. * \return ERR_NONE : Transceive done with no error
  1151. * \return ERR_BUSY : Transceive ongoing
  1152. * \return ERR_XXXX : Error occurred
  1153. * \return ERR_TIMEOUT : No response
  1154. * \return ERR_FRAMING : Framing error detected
  1155. * \return ERR_PAR : Parity error detected
  1156. * \return ERR_CRC : CRC error detected
  1157. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1158. * \return ERR_RF_COLLISION : Collision detected
  1159. * \return ERR_IO : Internal error
  1160. *****************************************************************************
  1161. */
  1162. ReturnCode rfalTransceiveBlockingTxRx( uint8_t* txBuf, uint16_t txBufLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* actLen, uint32_t flags, uint32_t fwt );
  1163. /*****************************************************************************
  1164. * Listen Mode *
  1165. *****************************************************************************/
  1166. /*!
  1167. *****************************************************************************
  1168. * \brief Is external Field On
  1169. *
  1170. * Checks if external field (other peer/device) is on/detected
  1171. *
  1172. * \return true External field is On
  1173. * \return false No external field is detected
  1174. *
  1175. *****************************************************************************
  1176. */
  1177. bool rfalIsExtFieldOn( void );
  1178. /*!
  1179. *****************************************************************************
  1180. * \brief Listen Mode start
  1181. *
  1182. * Configures RF Chip to go into listen mode enabling the given technologies
  1183. *
  1184. *
  1185. * \param[in] lmMask: mask with the enabled/disabled listen modes
  1186. * use: RFAL_LM_MASK_NFCA ; RFAL_LM_MASK_NFCB ;
  1187. * RFAL_LM_MASK_NFCF ; RFAL_LM_MASK_ACTIVE_P2P
  1188. * \param[in] confA: pointer to Passive A configurations (NULL if disabled)
  1189. * \param[in] confB: pointer to Passive B configurations (NULL if disabled)
  1190. * \param[in] confF: pointer to Passive F configurations (NULL if disabled)
  1191. * \param[in] rxBuf: buffer to place incoming data
  1192. * \param[in] rxBufLen: length in bits of rxBuf
  1193. * \param[in] rxLen: pointer to write the data length in bits placed into rxBuf
  1194. *
  1195. *
  1196. * \return ERR_PARAM Invalid parameter
  1197. * \return ERR_REQUEST Invalid listen mode mask
  1198. * \return ERR_NONE Done with no error
  1199. *
  1200. *****************************************************************************
  1201. */
  1202. ReturnCode rfalListenStart( uint32_t lmMask, const rfalLmConfPA *confA, const rfalLmConfPB *confB, const rfalLmConfPF *confF, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rxLen );
  1203. /*!
  1204. *****************************************************************************
  1205. * \brief Listen Mode start Sleeping
  1206. *
  1207. *
  1208. *****************************************************************************
  1209. */
  1210. ReturnCode rfalListenSleepStart( rfalLmState sleepSt, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rxLen );
  1211. /*!
  1212. *****************************************************************************
  1213. * \brief Listen Mode Stop
  1214. *
  1215. * Disables the listen mode on the RF Chip
  1216. *
  1217. * \warning the listen mode will be disabled immediately on the RFchip regardless
  1218. * of any ongoing operations like Transceive
  1219. *
  1220. * \return ERR_NONE Done with no error
  1221. *
  1222. *****************************************************************************
  1223. */
  1224. ReturnCode rfalListenStop( void );
  1225. /*!
  1226. *****************************************************************************
  1227. * \brief Listen Mode get state
  1228. *
  1229. * Sets the new state of the Listen Mode and applies the necessary changes
  1230. * on the RF Chip
  1231. *
  1232. * \param[out] dataFlag: indicates that Listen Mode has rcvd data and caller
  1233. * must process it. The received message is located
  1234. * at the rxBuf passed on rfalListenStart().
  1235. * rfalListenSetState() will clear this flag
  1236. * if NULL output parameter will no be written/returned
  1237. * \param[out] lastBR: bit rate detected of the last initiator request
  1238. * if NULL output parameter will no be written/returned
  1239. *
  1240. * \return rfalLmState RFAL_LM_STATE_NOT_INIT : LM not initialized properly
  1241. * Any Other : LM State
  1242. *
  1243. *****************************************************************************
  1244. */
  1245. rfalLmState rfalListenGetState( bool *dataFlag, rfalBitRate *lastBR );
  1246. /*!
  1247. *****************************************************************************
  1248. * \brief Listen Mode set state
  1249. *
  1250. * Sets the new state of the Listen Mode and applies the necessary changes
  1251. * on the RF Chip
  1252. *
  1253. * \param[in] newSt : New state to go to
  1254. *
  1255. * \return ERR_WRONG_STATE : Not initialized properly
  1256. * \return ERR_PARAM : Invalid parameter
  1257. * \return ERR_NONE : Done with no error
  1258. *
  1259. *****************************************************************************
  1260. */
  1261. ReturnCode rfalListenSetState( rfalLmState newSt );
  1262. /*****************************************************************************
  1263. * Wake-Up Mode *
  1264. *****************************************************************************/
  1265. /*!
  1266. *****************************************************************************
  1267. * \brief Wake-Up Mode Start
  1268. *
  1269. * Sets the RF Chip in Low Power Wake-Up Mode according to the given
  1270. * configuration.
  1271. *
  1272. * \param[in] config : Generic Wake-Up configuration provided by lower
  1273. * layers. If NULL will automatically configure the
  1274. * Wake-Up mode
  1275. *
  1276. * \return ERR_WRONG_STATE : Not initialized properly
  1277. * \return ERR_PARAM : Invalid parameter
  1278. * \return ERR_NONE : Done with no error
  1279. *
  1280. *****************************************************************************
  1281. */
  1282. ReturnCode rfalWakeUpModeStart( const rfalWakeUpConfig *config );
  1283. /*!
  1284. *****************************************************************************
  1285. * \brief Wake-Up Has Woke
  1286. *
  1287. * Returns true if the Wake-Up mode is enabled and it has already received
  1288. * the indication from the RF Chip that the surrounding environment has changed
  1289. * and flagged at least one wake-Up interrupt
  1290. *
  1291. * \return true : Wake-Up mode enabled and has received a wake-up IRQ
  1292. * \return false : no Wake-Up IRQ has been received
  1293. *
  1294. *****************************************************************************
  1295. */
  1296. bool rfalWakeUpModeHasWoke( void );
  1297. /*!
  1298. *****************************************************************************
  1299. * \brief Wake-Up Mode Stop
  1300. *
  1301. * Stops the Wake-Up Mode
  1302. *
  1303. * \return ERR_WRONG_STATE : Not initialized properly
  1304. * \return ERR_PARAM : Invalid parameter
  1305. * \return ERR_NONE : Done with no error
  1306. *
  1307. *****************************************************************************
  1308. */
  1309. ReturnCode rfalWakeUpModeStop( void );
  1310. /*!
  1311. *****************************************************************************
  1312. * \brief Low Power Mode Start
  1313. *
  1314. * Sets the RF Chip in Low Power Mode.
  1315. * In this mode the RF Chip is placed in Low Power Mode, similar to Wake-up
  1316. * mode but no operation nor period measurement is performed.
  1317. * Mode must be terminated by rfalLowPowerModeStop()
  1318. *
  1319. * \return ERR_WRONG_STATE : Not initialized properly
  1320. * \return ERR_PARAM : Invalid parameter
  1321. * \return ERR_NONE : Done with no error
  1322. *
  1323. *****************************************************************************
  1324. */
  1325. ReturnCode rfalLowPowerModeStart( void );
  1326. /*!
  1327. *****************************************************************************
  1328. * \brief Low Power Mode Stop
  1329. *
  1330. * Stops the Low Power Mode re-enabling the device
  1331. *
  1332. * \return ERR_WRONG_STATE : Not initialized properly
  1333. * \return ERR_PARAM : Invalid parameter
  1334. * \return ERR_NONE : Done with no error
  1335. *
  1336. *****************************************************************************
  1337. */
  1338. ReturnCode rfalLowPowerModeStop( void );
  1339. #endif /* RFAL_RF_H */
  1340. /**
  1341. * @}
  1342. *
  1343. * @}
  1344. *
  1345. * @}
  1346. */