rfal_rf.h 72 KB

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