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