rfal_rf.h 71 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688
  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_REMV | \
  108. (uint32_t)RFAL_TXRX_FLAGS_NFCIP1_OFF | (uint32_t)RFAL_TXRX_FLAGS_AGC_ON | \
  109. (uint32_t)RFAL_TXRX_FLAGS_PAR_RX_REMV | (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);
  495. /*! Callback to be executed after a Transceive */
  496. typedef void (*rfalPostTxRxCallback)(void);
  497. /*******************************************************************************/
  498. /* ISO14443A */
  499. /*******************************************************************************/
  500. /*! RFAL ISO 14443A Short Frame Command */
  501. typedef enum {
  502. RFAL_14443A_SHORTFRAME_CMD_WUPA = 0x52, /*!< ISO14443A WUPA / NFC-A ALL_REQ */
  503. RFAL_14443A_SHORTFRAME_CMD_REQA = 0x26 /*!< ISO14443A REQA / NFC-A SENS_REQ */
  504. } rfal14443AShortFrameCmd;
  505. /*******************************************************************************/
  506. /*******************************************************************************/
  507. /* FeliCa */
  508. /*******************************************************************************/
  509. #define RFAL_FELICA_LEN_LEN \
  510. 1U /*!< FeliCa LEN byte length */
  511. #define RFAL_FELICA_POLL_REQ_LEN \
  512. (RFAL_FELICA_LEN_LEN + 1U + 2U + 1U + \
  513. 1U) /*!< FeliCa Poll Request length (LEN + CMD + SC + RC + TSN) */
  514. #define RFAL_FELICA_POLL_RES_LEN \
  515. (RFAL_FELICA_LEN_LEN + 1U + 8U + 8U + \
  516. 2U) /*!< Maximum FeliCa Poll Response length (LEN + CMD + NFCID2 + PAD + RD) */
  517. #define RFAL_FELICA_POLL_MAX_SLOTS \
  518. 16U /*!< Maximum number of slots (TSN) on FeliCa Poll */
  519. /*! NFC-F RC (Request Code) codes NFC Forum Digital 1.1 Table 42 */
  520. enum {
  521. RFAL_FELICA_POLL_RC_NO_REQUEST =
  522. 0x00, /*!< RC: No System Code information requested */
  523. RFAL_FELICA_POLL_RC_SYSTEM_CODE =
  524. 0x01, /*!< RC: System Code information requested */
  525. RFAL_FELICA_POLL_RC_COM_PERFORMANCE =
  526. 0x02 /*!< RC: Advanced protocol features supported */
  527. };
  528. /*! NFC-F TSN (Time Slot Number) codes NFC Forum Digital 1.1 Table 43 */
  529. typedef enum {
  530. RFAL_FELICA_1_SLOT = 0, /*!< TSN with number of Time Slots: 1 */
  531. RFAL_FELICA_2_SLOTS = 1, /*!< TSN with number of Time Slots: 2 */
  532. RFAL_FELICA_4_SLOTS = 3, /*!< TSN with number of Time Slots: 4 */
  533. RFAL_FELICA_8_SLOTS = 7, /*!< TSN with number of Time Slots: 8 */
  534. RFAL_FELICA_16_SLOTS = 15 /*!< TSN with number of Time Slots: 16 */
  535. } rfalFeliCaPollSlots;
  536. /*! NFCF Poll Response NFC Forum Digital 1.1 Table 44 */
  537. typedef uint8_t rfalFeliCaPollRes[RFAL_FELICA_POLL_RES_LEN];
  538. /*******************************************************************************/
  539. /*******************************************************************************/
  540. /* Listen Mode */
  541. /*******************************************************************************/
  542. /*! RFAL Listen Mode NFCID Length */
  543. typedef enum {
  544. RFAL_LM_NFCID_LEN_04 = RFAL_NFCID1_SINGLE_LEN, /*!< Listen mode indicates 4 byte NFCID */
  545. RFAL_LM_NFCID_LEN_07 = RFAL_NFCID1_DOUBLE_LEN, /*!< Listen mode indicates 7 byte NFCID */
  546. RFAL_LM_NFCID_LEN_10 = RFAL_NFCID1_TRIPLE_LEN, /*!< Listen mode indicates 10 byte NFCID */
  547. } rfalLmNfcidLen;
  548. /*! RFAL Listen Mode States */
  549. typedef enum {
  550. RFAL_LM_STATE_NOT_INIT = 0x00, /*!< Not Initialized state */
  551. RFAL_LM_STATE_POWER_OFF = 0x01, /*!< Power Off state */
  552. RFAL_LM_STATE_IDLE = 0x02, /*!< Idle state Activity 1.1 5.2 */
  553. RFAL_LM_STATE_READY_A = 0x03, /*!< Ready A state Activity 1.1 5.3 5.4 & 5.5 */
  554. RFAL_LM_STATE_READY_B = 0x04, /*!< Ready B state Activity 1.1 5.11 5.12 */
  555. RFAL_LM_STATE_READY_F = 0x05, /*!< Ready F state Activity 1.1 5.15 */
  556. RFAL_LM_STATE_ACTIVE_A = 0x06, /*!< Active A state Activity 1.1 5.6 */
  557. RFAL_LM_STATE_CARDEMU_4A = 0x07, /*!< Card Emulation 4A state Activity 1.1 5.10 */
  558. RFAL_LM_STATE_CARDEMU_4B = 0x08, /*!< Card Emulation 4B state Activity 1.1 5.14 */
  559. RFAL_LM_STATE_CARDEMU_3 = 0x09, /*!< Card Emulation 3 state Activity 1.1 5.18 */
  560. RFAL_LM_STATE_TARGET_A = 0x0A, /*!< Target A state Activity 1.1 5.9 */
  561. RFAL_LM_STATE_TARGET_F = 0x0B, /*!< Target F state Activity 1.1 5.17 */
  562. RFAL_LM_STATE_SLEEP_A = 0x0C, /*!< Sleep A state Activity 1.1 5.7 */
  563. RFAL_LM_STATE_SLEEP_B = 0x0D, /*!< Sleep B state Activity 1.1 5.13 */
  564. RFAL_LM_STATE_READY_Ax = 0x0E, /*!< Ready A* state Activity 1.1 5.3 5.4 & 5.5 */
  565. RFAL_LM_STATE_ACTIVE_Ax = 0x0F, /*!< Active A* state Activity 1.1 5.6 */
  566. RFAL_LM_STATE_SLEEP_AF = 0x10, /*!< Sleep AF state Activity 1.1 5.19 */
  567. } rfalLmState;
  568. /*! RFAL Listen Mode Passive A configs */
  569. typedef struct {
  570. rfalLmNfcidLen nfcidLen; /*!< NFCID Len (4, 7 or 10 bytes) */
  571. uint8_t nfcid[RFAL_NFCID1_TRIPLE_LEN]; /*!< NFCID */
  572. uint8_t SENS_RES[RFAL_LM_SENS_RES_LEN]; /*!< NFC-106k; SENS_REQ Response */
  573. uint8_t SEL_RES; /*!< SEL_RES (SAK) with complete NFCID1 (UID) */
  574. } rfalLmConfPA;
  575. /*! RFAL Listen Mode Passive B configs */
  576. typedef struct {
  577. uint8_t SENSB_RES[RFAL_LM_SENSB_RES_LEN]; /*!< SENSF_RES */
  578. } rfalLmConfPB;
  579. /*! RFAL Listen Mode Passive F configs */
  580. typedef struct {
  581. uint8_t SC[RFAL_LM_SENSF_SC_LEN]; /*!< System Code to listen for */
  582. uint8_t SENSF_RES[RFAL_LM_SENSF_RES_LEN]; /*!< SENSF_RES */
  583. } rfalLmConfPF;
  584. /*******************************************************************************/
  585. /*******************************************************************************/
  586. /* Wake-Up Mode */
  587. /*******************************************************************************/
  588. #define RFAL_WUM_REFERENCE_AUTO 0xFFU /*!< Indicates new reference is set by the driver*/
  589. /*! RFAL Wake-Up Mode States */
  590. typedef enum {
  591. RFAL_WUM_STATE_NOT_INIT = 0x00, /*!< Not Initialized state */
  592. RFAL_WUM_STATE_ENABLED = 0x01, /*!< Wake-Up mode is enabled */
  593. RFAL_WUM_STATE_ENABLED_WOKE = 0x02, /*!< Wake-Up mode enabled and has received IRQ(s)*/
  594. } rfalWumState;
  595. /*! RFAL Wake-Up Period/Timer */
  596. typedef enum {
  597. RFAL_WUM_PERIOD_10MS = 0x00, /*!< Wake-Up timer 10ms */
  598. RFAL_WUM_PERIOD_20MS = 0x01, /*!< Wake-Up timer 20ms */
  599. RFAL_WUM_PERIOD_30MS = 0x02, /*!< Wake-Up timer 30ms */
  600. RFAL_WUM_PERIOD_40MS = 0x03, /*!< Wake-Up timer 40ms */
  601. RFAL_WUM_PERIOD_50MS = 0x04, /*!< Wake-Up timer 50ms */
  602. RFAL_WUM_PERIOD_60MS = 0x05, /*!< Wake-Up timer 60ms */
  603. RFAL_WUM_PERIOD_70MS = 0x06, /*!< Wake-Up timer 70ms */
  604. RFAL_WUM_PERIOD_80MS = 0x07, /*!< Wake-Up timer 80ms */
  605. RFAL_WUM_PERIOD_100MS = 0x10, /*!< Wake-Up timer 100ms */
  606. RFAL_WUM_PERIOD_200MS = 0x11, /*!< Wake-Up timer 200ms */
  607. RFAL_WUM_PERIOD_300MS = 0x12, /*!< Wake-Up timer 300ms */
  608. RFAL_WUM_PERIOD_400MS = 0x13, /*!< Wake-Up timer 400ms */
  609. RFAL_WUM_PERIOD_500MS = 0x14, /*!< Wake-Up timer 500ms */
  610. RFAL_WUM_PERIOD_600MS = 0x15, /*!< Wake-Up timer 600ms */
  611. RFAL_WUM_PERIOD_700MS = 0x16, /*!< Wake-Up timer 700ms */
  612. RFAL_WUM_PERIOD_800MS = 0x17, /*!< Wake-Up timer 800ms */
  613. } rfalWumPeriod;
  614. /*! RFAL Wake-Up Period/Timer */
  615. typedef enum {
  616. RFAL_WUM_AA_WEIGHT_4 = 0x00, /*!< Wake-Up Auto Average Weight 4 */
  617. RFAL_WUM_AA_WEIGHT_8 = 0x01, /*!< Wake-Up Auto Average Weight 8 */
  618. RFAL_WUM_AA_WEIGHT_16 = 0x02, /*!< Wake-Up Auto Average Weight 16 */
  619. RFAL_WUM_AA_WEIGHT_32 = 0x03, /*!< Wake-Up Auto Average Weight 32 */
  620. } rfalWumAAWeight;
  621. /*! RFAL Wake-Up Mode configuration */
  622. typedef struct {
  623. rfalWumPeriod period; /*!< Wake-Up Timer period;how often measurement(s) is performed */
  624. bool irqTout; /*!< IRQ at every timeout will refresh the measurement(s) */
  625. bool swTagDetect; /*!< Use SW Tag Detection instead of HW Wake-Up mode */
  626. struct {
  627. bool enabled; /*!< Inductive Amplitude measurement enabled */
  628. uint8_t delta; /*!< Delta between the reference and measurement to wake-up */
  629. uint16_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */
  630. bool autoAvg; /*!< Use the HW Auto Averaging feature */
  631. bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */
  632. rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */
  633. } indAmp; /*!< Inductive Amplitude Configuration */
  634. struct {
  635. bool enabled; /*!< Inductive Phase measurement enabled */
  636. uint8_t delta; /*!< Delta between the reference and measurement to wake-up */
  637. uint16_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */
  638. bool autoAvg; /*!< Use the HW Auto Averaging feature */
  639. bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */
  640. rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */
  641. } indPha; /*!< Inductive Phase Configuration */
  642. struct {
  643. bool enabled; /*!< Capacitive measurement enabled */
  644. uint8_t delta; /*!< Delta between the reference and measurement to wake-up */
  645. uint16_t reference; /*!< Reference to be used;RFAL_WUM_REFERENCE_AUTO sets it auto */
  646. bool autoAvg; /*!< Use the HW Auto Averaging feature */
  647. bool aaInclMeas; /*!< When AutoAvg is enabled, include IRQ measurement */
  648. rfalWumAAWeight aaWeight; /*!< When AutoAvg is enabled, last measure weight */
  649. } cap; /*!< Capacitive Configuration */
  650. } rfalWakeUpConfig;
  651. /*******************************************************************************/
  652. /*
  653. ******************************************************************************
  654. * GLOBAL FUNCTION PROTOTYPES
  655. ******************************************************************************
  656. */
  657. /*!
  658. *****************************************************************************
  659. * \brief RFAL Initialize
  660. *
  661. * Initializes RFAL layer and the ST25R391x
  662. * Ensures that ST25R391x is properly connected and returns error if any problem
  663. * is detected
  664. *
  665. * \warning rfalAnalogConfigInitialize() should be called before so that
  666. * the Analog config table has been previously initialized.
  667. *
  668. * \return ERR_HW_MISMATCH : Expected HW do not match or communication error
  669. * \return ERR_NONE : No error
  670. *****************************************************************************
  671. */
  672. ReturnCode rfalInitialize(void);
  673. /*!
  674. *****************************************************************************
  675. * \brief RFAL Calibrate
  676. *
  677. * Performs necessary calibration of RF chip in case it is indicated by current
  678. * register settings. E.g. antenna calibration and regulator calibration
  679. *
  680. * \return ERR_WRONG_STATE : RFAL not initialized
  681. * \return ERR_NONE : No error
  682. *
  683. *****************************************************************************
  684. */
  685. ReturnCode rfalCalibrate(void);
  686. /*!
  687. *****************************************************************************
  688. * \brief RFAL Adjust Regulators
  689. *
  690. * Adjusts ST25R391x regulators
  691. *
  692. * \param[out] result : the result of the calibrate antenna in mV
  693. * NULL if result not requested
  694. *
  695. * \return ERR_WRONG_STATE : RFAL not initialized
  696. * \return ERR_NONE : No error
  697. *
  698. *****************************************************************************
  699. */
  700. ReturnCode rfalAdjustRegulators(uint16_t* result);
  701. /*!
  702. *****************************************************************************
  703. * \brief RFAL Set System Callback
  704. *
  705. * Sets a callback for the driver to call when an event has occurred that
  706. * may require the system to be notified
  707. *
  708. * \param[in] pFunc : method pointer for the upper layer callback
  709. *
  710. *****************************************************************************
  711. */
  712. void rfalSetUpperLayerCallback(rfalUpperLayerCallback pFunc);
  713. /*!
  714. *****************************************************************************
  715. * \brief RFAL Set Pre Tx Callback
  716. *
  717. * Sets a callback for the driver to call before a Transceive
  718. *
  719. * \param[in] pFunc : method pointer for the Pre Tx callback
  720. *
  721. *****************************************************************************
  722. */
  723. void rfalSetPreTxRxCallback(rfalPreTxRxCallback pFunc);
  724. /*!
  725. *****************************************************************************
  726. * \brief RFAL Set Post Tx Callback
  727. *
  728. * Sets a callback for the driver to call after a Transceive
  729. *
  730. * \param[in] pFunc : method pointer for the Post Tx callback
  731. *
  732. *****************************************************************************
  733. */
  734. void rfalSetPostTxRxCallback(rfalPostTxRxCallback pFunc);
  735. /*!
  736. *****************************************************************************
  737. * \brief RFAL Deinitialize
  738. *
  739. * Deinitializes RFAL layer and the ST25R391x
  740. *
  741. * \return ERR_NONE : No error
  742. *
  743. *****************************************************************************
  744. */
  745. ReturnCode rfalDeinitialize(void);
  746. /*!
  747. *****************************************************************************
  748. * \brief RFAL Set Mode
  749. *
  750. * Sets the mode that RFAL will operate on the following communications.
  751. * Proper initializations will be performed on the ST25R391x
  752. *
  753. * \warning bit rate value RFAL_BR_KEEP is not allowed, only in rfalSetBitRate()
  754. *
  755. * \warning the mode will be applied immediately on the RFchip regardless of
  756. * any ongoing operations like Transceive, ListenMode
  757. *
  758. * \param[in] mode : mode for the RFAL/RFchip to perform
  759. * \param[in] txBR : transmit bit rate
  760. * \param[in] rxBR : receive bit rate
  761. *
  762. * \see rfalIsGTExpired
  763. * \see rfalMode
  764. *
  765. * \return ERR_WRONG_STATE : RFAL not initialized
  766. * \return ERR_PARAM : Invalid parameter
  767. * \return ERR_NONE : No error
  768. *
  769. *****************************************************************************
  770. */
  771. ReturnCode rfalSetMode(rfalMode mode, rfalBitRate txBR, rfalBitRate rxBR);
  772. /*!
  773. *****************************************************************************
  774. * \brief RFAL Get Mode
  775. *
  776. * Gets the mode that RFAL is set to operate
  777. *
  778. * \see rfalMode
  779. *
  780. * \return rfalMode : The current RFAL mode
  781. *****************************************************************************
  782. */
  783. rfalMode rfalGetMode(void);
  784. /*!
  785. *****************************************************************************
  786. * \brief RFAL Set Bit Rate
  787. *
  788. * Sets the Tx and Rx bit rates with the given values
  789. * The bit rate change is applied on the RF chip remaining in the same
  790. * mode previous defined with rfalSetMode()
  791. *
  792. * If no mode is defined bit rates will not be applied and an error
  793. * is returned
  794. *
  795. * \param[in] txBR : transmit bit rate
  796. * \param[in] rxBR : receive bit rate
  797. *
  798. * \see rfalSetMode
  799. * \see rfalMode
  800. * \see rfalBitRate
  801. *
  802. * \return ERR_WRONG_STATE : RFAL not initialized
  803. * \return ERR_PARAM : Invalid parameter
  804. * \return ERR_NOT_IMPLEMENTED : Mode not implemented
  805. * \return ERR_NONE : No error
  806. *
  807. *****************************************************************************
  808. */
  809. ReturnCode rfalSetBitRate(rfalBitRate txBR, rfalBitRate rxBR);
  810. /*!
  811. *****************************************************************************
  812. * \brief RFAL Get Bit Rate
  813. *
  814. * Gets the Tx and Rx current bit rates
  815. *
  816. * If RFAL is not initialized or mode not set the bit rates return will
  817. * be invalid RFAL_BR_KEEP
  818. *
  819. * \param[out] txBR : RFAL's current Tx Bit Rate
  820. * \param[out] rxBR : RFAL's current Rx Bit Rate
  821. *
  822. * \see rfalSetBitRate
  823. * \see rfalBitRate
  824. *
  825. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  826. * \return ERR_NONE : No error
  827. *****************************************************************************
  828. */
  829. ReturnCode rfalGetBitRate(rfalBitRate* txBR, rfalBitRate* rxBR);
  830. /*!
  831. *****************************************************************************
  832. * \brief Set Error Handling Mode
  833. *
  834. * Sets the error handling mode to be used by the RFAL
  835. *
  836. * \param[in] eHandling : the error handling mode
  837. *
  838. *****************************************************************************
  839. */
  840. void rfalSetErrorHandling(rfalEHandling eHandling);
  841. /*!
  842. *****************************************************************************
  843. * \brief Get Error Handling Mode
  844. *
  845. * Gets the error handling mode currently used by the RFAL
  846. *
  847. * \return rfalEHandling : Current error handling mode
  848. *****************************************************************************
  849. */
  850. rfalEHandling rfalGetErrorHandling(void);
  851. /*!
  852. *****************************************************************************
  853. * \brief Set Observation Mode
  854. *
  855. * Sets ST25R391x observation modes for RF debug purposes
  856. *
  857. * \param[in] txMode : the observation mode to be used during transmission
  858. * \param[in] rxMode : the observation mode to be used during reception
  859. *
  860. * \warning The Observation Mode is an advanced feature and should be set
  861. * according to the documentation of the part number in use.
  862. * Please refer to the corresponding Datasheet or Application Note(s)
  863. *****************************************************************************
  864. */
  865. void rfalSetObsvMode(uint8_t txMode, uint8_t rxMode);
  866. /*!
  867. *****************************************************************************
  868. * \brief Get Observation Mode
  869. *
  870. * Gets ST25R391x the current configured observation modes
  871. *
  872. * \param[in] txMode : the current observation mode configured for transmission
  873. * \param[in] rxMode : the current observation mode configured for reception
  874. *
  875. *****************************************************************************
  876. */
  877. void rfalGetObsvMode(uint8_t* txMode, uint8_t* rxMode);
  878. /*!
  879. *****************************************************************************
  880. * \brief Disable Observation Mode
  881. *
  882. * Disables the ST25R391x observation mode
  883. *****************************************************************************
  884. */
  885. void rfalDisableObsvMode(void);
  886. /*!
  887. *****************************************************************************
  888. * \brief RFAL Set FDT Poll
  889. *
  890. * Sets the Frame Delay Time (FDT) to be used on the following
  891. * communications.
  892. *
  893. * FDT Poll is the minimum time following a Poll Frame during
  894. * which no subsequent Poll Frame can be sent (without a response from
  895. * the Listener in between)
  896. * FDTx,PP,MIN - Digital 1.1 6.10.2 & 7.9.2 & 8.7.2
  897. *
  898. * \param[in] FDTPoll : Frame Delay Time in 1/fc cycles
  899. *
  900. *****************************************************************************
  901. */
  902. void rfalSetFDTPoll(uint32_t FDTPoll);
  903. /*!
  904. *****************************************************************************
  905. * \brief RFAL Set FDT Poll
  906. *
  907. * Gets the current Frame Delay Time (FDT)
  908. *
  909. * FDT Poll is the minimum time following a Poll Frame during
  910. * which no subsequent Poll Frame can be sent (without a response from
  911. * the Listener in between)
  912. * FDTx,PP,MIN - Digital 1.1 6.10.2 & 7.9.2 & 8.7.2
  913. *
  914. * \return FDT : current FDT value in 1/fc cycles
  915. *
  916. *****************************************************************************
  917. */
  918. uint32_t rfalGetFDTPoll(void);
  919. /*!
  920. *****************************************************************************
  921. * \brief RFAL Set FDT Listen
  922. *
  923. * Sets the Frame Delay Time (FDT) Listen minimum to be used on the
  924. * following communications.
  925. *
  926. * FDT Listen is the minimum time between a Poll Frame and a Listen Frame
  927. * FDTx,LISTEN,MIN - Digital 1.1 6.10.1 & 7.9.1 & 8.7.1
  928. *
  929. * \param[in] FDTListen : Frame Delay Time in 1/fc cycles
  930. *
  931. *****************************************************************************
  932. */
  933. void rfalSetFDTListen(uint32_t FDTListen);
  934. /*!
  935. *****************************************************************************
  936. * \brief RFAL Set FDT Listen
  937. *
  938. * Gets the Frame Delay Time (FDT) Listen minimum
  939. *
  940. * FDT Listen is the minimum time between a Poll Frame and a Listen Frame
  941. * FDTx,LISTEN,MIN - Digital 1.1 6.10.1 & 7.9.1 & 8.7.1
  942. *
  943. * \return FDT : current FDT value in 1/fc cycles
  944. *
  945. *****************************************************************************
  946. */
  947. uint32_t rfalGetFDTListen(void);
  948. /*!
  949. *****************************************************************************
  950. * \brief RFAL Get GT
  951. *
  952. * Gets the current Guard Time (GT)
  953. *
  954. * GT is the minimum time when a device in Listen Mode is exposed to an
  955. * unmodulated carrier
  956. *
  957. * \return GT : Guard Time in 1/fc cycles
  958. *
  959. *****************************************************************************
  960. */
  961. uint32_t rfalGetGT(void);
  962. /*!
  963. *****************************************************************************
  964. * \brief RFAL Set GT
  965. *
  966. * Sets the Guard Time (GT) to be used on the following communications.
  967. *
  968. * GT is the minimum time when a device in Listen Mode is exposed to an
  969. * unmodulated carrier
  970. *
  971. * \param[in] GT : Guard Time in 1/fc cycles
  972. * RFAL_GT_NONE if no GT should be applied
  973. *
  974. *****************************************************************************
  975. */
  976. void rfalSetGT(uint32_t GT);
  977. /*!
  978. *****************************************************************************
  979. * \brief RFAL Is GT expired
  980. *
  981. * Checks whether the GT timer has expired
  982. *
  983. * \return true : GT has expired or not running
  984. * \return false : GT is still running
  985. *
  986. *****************************************************************************
  987. */
  988. bool rfalIsGTExpired(void);
  989. /*!
  990. *****************************************************************************
  991. * \brief RFAL Turn Field On and Start GT
  992. *
  993. * Turns the Field On, performing Initial Collision Avoidance
  994. *
  995. * After Field On, if GT was set before, it starts the GT timer to be
  996. * used on the following communications.
  997. *
  998. * \return ERR_RF_COLLISION : External field detected
  999. * \return ERR_NONE : Field turned On
  1000. *
  1001. *****************************************************************************
  1002. */
  1003. ReturnCode rfalFieldOnAndStartGT(void);
  1004. /*!
  1005. *****************************************************************************
  1006. * \brief RFAL Turn Field Off
  1007. *
  1008. * Turns the Field Off
  1009. *
  1010. * \return ERR_NONE : Field turned Off
  1011. *****************************************************************************
  1012. */
  1013. ReturnCode rfalFieldOff(void);
  1014. /*****************************************************************************
  1015. * Transceive *
  1016. *****************************************************************************/
  1017. /*!
  1018. *****************************************************************************
  1019. * \brief RFAL Set transceive context
  1020. *
  1021. * Set the context that will be used for the following Transceive
  1022. * Output and input buffers have to be passed and all other details prior to
  1023. * the Transceive itself has been started
  1024. *
  1025. * This method only sets the context, once set rfalWorker has
  1026. * to be executed until is done
  1027. *
  1028. * \param[in] ctx : the context for the following Transceive
  1029. *
  1030. * \see rfalWorker
  1031. * \see rfalGetTransceiveStatus
  1032. *
  1033. * \return ERR_NONE : Done with no error
  1034. * \return ERR_WRONG_STATE : Not initialized properly
  1035. * \return ERR_PARAM : Invalid parameter or configuration
  1036. *****************************************************************************
  1037. */
  1038. ReturnCode rfalStartTransceive(const rfalTransceiveContext* ctx);
  1039. /*!
  1040. *****************************************************************************
  1041. * \brief Get Transceive State
  1042. *
  1043. * Gets current Transceive internal State
  1044. *
  1045. * \return rfalTransceiveState : the current Transceive internal State
  1046. *****************************************************************************
  1047. */
  1048. rfalTransceiveState rfalGetTransceiveState(void);
  1049. /*!
  1050. *****************************************************************************
  1051. * \brief Get Transceive Status
  1052. *
  1053. * Gets current Transceive status
  1054. *
  1055. * \return ERR_NONE : Transceive done with no error
  1056. * \return ERR_BUSY : Transceive ongoing
  1057. * \return ERR_XXXX : Error occurred
  1058. * \return ERR_TIMEOUT : No response
  1059. * \return ERR_FRAMING : Framing error detected
  1060. * \return ERR_PAR : Parity error detected
  1061. * \return ERR_CRC : CRC error detected
  1062. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1063. * \return ERR_RF_COLLISION : Collision detected
  1064. * \return ERR_IO : Internal error
  1065. *****************************************************************************
  1066. */
  1067. ReturnCode rfalGetTransceiveStatus(void);
  1068. /*!
  1069. *****************************************************************************
  1070. * \brief Is Transceive in Tx
  1071. *
  1072. * Checks if Transceive is in Transmission state
  1073. *
  1074. * \return true Transmission ongoing
  1075. * \return false Not in transmission state
  1076. *****************************************************************************
  1077. */
  1078. bool rfalIsTransceiveInTx(void);
  1079. /*!
  1080. *****************************************************************************
  1081. * \brief Is Transceive in Rx
  1082. *
  1083. * Checks if Transceive is in Reception state
  1084. *
  1085. * \return true Transmission done/reception ongoing
  1086. * \return false Not in reception state
  1087. *****************************************************************************
  1088. */
  1089. bool rfalIsTransceiveInRx(void);
  1090. /*!
  1091. *****************************************************************************
  1092. * \brief Get Transceive RSSI
  1093. *
  1094. * Gets the RSSI value of the last executed Transceive in mV
  1095. *
  1096. * \param[out] rssi : RSSI value
  1097. *
  1098. * \return ERR_NOTSUPP : Feature not supported
  1099. * \return ERR_PARAM : Invalid parameter
  1100. * \return ERR_NONE : No error
  1101. *****************************************************************************
  1102. */
  1103. ReturnCode rfalGetTransceiveRSSI(uint16_t* rssi);
  1104. /*!
  1105. *****************************************************************************
  1106. * \brief RFAL Worker
  1107. *
  1108. * This runs RFAL layer, which drives the actual Transceive procedure
  1109. * It MUST be executed frequently in order to execute the RFAL internal
  1110. * states and perform the requested operations
  1111. *
  1112. *****************************************************************************
  1113. */
  1114. void rfalWorker(void);
  1115. /*****************************************************************************
  1116. * ISO1443A *
  1117. *****************************************************************************/
  1118. /*!
  1119. *****************************************************************************
  1120. * \brief Transceives an ISO14443A ShortFrame
  1121. *
  1122. * Sends REQA to detect if there is any PICC in the field
  1123. *
  1124. * \param[in] txCmd: Command to be sent:
  1125. * 0x52 WUPA / ALL_REQ
  1126. * 0x26 REQA / SENS_REQ
  1127. *
  1128. * \param[in] txCmd : type of short frame to be sent REQA or WUPA
  1129. * \param[out] rxBuf : buffer to place the response
  1130. * \param[in] rxBufLen : length of rxBuf
  1131. * \param[out] rxRcvdLen: received length
  1132. * \param[in] fwt : Frame Waiting Time in 1/fc
  1133. *
  1134. * \warning If fwt is set to RFAL_FWT_NONE it will make endlessly for
  1135. * a response, which on a blocking method may not be the
  1136. * desired usage
  1137. *
  1138. * \return ERR_NONE if there is response
  1139. * \return ERR_TIMEOUT if there is no response
  1140. * \return ERR_COLLISION collision has occurred
  1141. *
  1142. *****************************************************************************
  1143. */
  1144. ReturnCode rfalISO14443ATransceiveShortFrame(
  1145. rfal14443AShortFrameCmd txCmd,
  1146. uint8_t* rxBuf,
  1147. uint8_t rxBufLen,
  1148. uint16_t* rxRcvdLen,
  1149. uint32_t fwt);
  1150. /*!
  1151. *****************************************************************************
  1152. * \brief Sends an ISO14443A Anticollision Frame
  1153. *
  1154. * This is use to perform ISO14443A anti-collision.
  1155. * \note Anticollision is sent without CRC
  1156. *
  1157. *
  1158. * \param[in] buf : reference to ANTICOLLISION command (with known UID if any) to be sent (also out param)
  1159. * reception will be place on this buf after bytesToSend
  1160. * \param[in] bytesToSend: reference number of full bytes to be sent (including CMD byte and SEL_PAR)
  1161. * if a collision occurs will contain the number of clear bytes
  1162. * \param[in] bitsToSend : reference to number of bits (0-7) to be sent; and received (also out param)
  1163. * if a collision occurs will indicate the number of clear bits (also out param)
  1164. * \param[out] rxLength : reference to the return the received length
  1165. * \param[in] fwt : Frame Waiting Time in 1/fc
  1166. *
  1167. * \return ERR_NONE if there is no error
  1168. *****************************************************************************
  1169. */
  1170. ReturnCode rfalISO14443ATransceiveAnticollisionFrame(
  1171. uint8_t* buf,
  1172. uint8_t* bytesToSend,
  1173. uint8_t* bitsToSend,
  1174. uint16_t* rxLength,
  1175. uint32_t fwt);
  1176. /*****************************************************************************
  1177. * FeliCa *
  1178. *****************************************************************************/
  1179. /*!
  1180. *****************************************************************************
  1181. * \brief FeliCa Poll
  1182. *
  1183. * Sends a Poll Request and collects all Poll Responses according to the
  1184. * given slots
  1185. *
  1186. *
  1187. * \param[in] slots : number of slots for the Poll Request
  1188. * \param[in] sysCode : system code (SC) for the Poll Request
  1189. * \param[in] reqCode : request code (RC) for the Poll Request
  1190. * \param[out] pollResList : list of all responses
  1191. * \param[in] pollResListSize : number of responses that can be placed in pollResList
  1192. * \param[out] devicesDetected : number of cards found
  1193. * \param[out] collisionsDetected: number of collisions detected
  1194. *
  1195. * \return ERR_NONE if there is no error
  1196. * \return ERR_TIMEOUT if there is no response
  1197. *****************************************************************************
  1198. */
  1199. ReturnCode rfalFeliCaPoll(
  1200. rfalFeliCaPollSlots slots,
  1201. uint16_t sysCode,
  1202. uint8_t reqCode,
  1203. rfalFeliCaPollRes* pollResList,
  1204. uint8_t pollResListSize,
  1205. uint8_t* devicesDetected,
  1206. uint8_t* collisionsDetected);
  1207. /*****************************************************************************
  1208. * ISO15693 *
  1209. *****************************************************************************/
  1210. /*!
  1211. *****************************************************************************
  1212. * \brief Sends an ISO15693 Anticollision Frame
  1213. *
  1214. * This send the Anticollision|Inventory frame (INVENTORY_REQ)
  1215. *
  1216. * \warning rxBuf must be able to contain the payload and CRC
  1217. *
  1218. * \param[in] txBuf : Buffer where outgoing message is located
  1219. * \param[in] txBufLen : Length of the outgoing message in bytes
  1220. * \param[out] rxBuf : Buffer where incoming message will be placed
  1221. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1222. * \param[out] actLen : Actual received length in bits
  1223. *
  1224. * \return ERR_NONE : Transceive done with no error
  1225. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  1226. * \return ERR_IO : Internal error
  1227. *****************************************************************************
  1228. */
  1229. ReturnCode rfalISO15693TransceiveAnticollisionFrame(
  1230. uint8_t* txBuf,
  1231. uint8_t txBufLen,
  1232. uint8_t* rxBuf,
  1233. uint8_t rxBufLen,
  1234. uint16_t* actLen);
  1235. /*!
  1236. *****************************************************************************
  1237. * \brief Sends an ISO15693 Anticollision EOF
  1238. *
  1239. * This sends the Anticollision|Inventory EOF used as a slot marker
  1240. *
  1241. * \warning rxBuf must be able to contain the payload and CRC
  1242. *
  1243. * \param[out] rxBuf : Buffer where incoming message will be placed
  1244. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1245. * \param[out] actLen : Actual received length in bits
  1246. *
  1247. * \return ERR_NONE : Transceive done with no error
  1248. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  1249. * \return ERR_IO : Internal error
  1250. *****************************************************************************
  1251. */
  1252. ReturnCode
  1253. rfalISO15693TransceiveEOFAnticollision(uint8_t* rxBuf, uint8_t rxBufLen, uint16_t* actLen);
  1254. /*!
  1255. *****************************************************************************
  1256. * \brief Sends an ISO15693 EOF
  1257. *
  1258. * This is method sends an ISO15693 (EoF) used for a Write operation
  1259. *
  1260. * \warning rxBuf must be able to contain the payload and CRC
  1261. *
  1262. * \param[out] rxBuf : Buffer where incoming message will be placed
  1263. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1264. * \param[out] actLen : Actual received length in bytes
  1265. *
  1266. * \return ERR_NONE : Transceive done with no error
  1267. * \return ERR_IO : Internal error
  1268. *****************************************************************************
  1269. */
  1270. ReturnCode rfalISO15693TransceiveEOF(uint8_t* rxBuf, uint8_t rxBufLen, uint16_t* actLen);
  1271. /*!
  1272. *****************************************************************************
  1273. * \brief Transceive Blocking Tx
  1274. *
  1275. * This is method triggers a Transceive and executes it blocking until the
  1276. * Tx has been completed
  1277. *
  1278. * \param[in] txBuf : Buffer where outgoing message is located
  1279. * \param[in] txBufLen : Length of the outgoing message in bytes
  1280. * \param[out] rxBuf : Buffer where incoming message will be placed
  1281. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1282. * \param[out] actLen : Actual received length in bits
  1283. * \param[in] flags : TransceiveFlags indication special handling
  1284. * \param[in] fwt : Frame Waiting Time in 1/fc
  1285. *
  1286. * \return ERR_NONE : Transceive done with no error
  1287. * \return ERR_BUSY : Transceive ongoing
  1288. * \return ERR_XXXX : Error occurred
  1289. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1290. * \return ERR_RF_COLLISION : Collision detected
  1291. * \return ERR_IO : Internal error
  1292. *****************************************************************************
  1293. */
  1294. ReturnCode rfalTransceiveBlockingTx(
  1295. uint8_t* txBuf,
  1296. uint16_t txBufLen,
  1297. uint8_t* rxBuf,
  1298. uint16_t rxBufLen,
  1299. uint16_t* actLen,
  1300. uint32_t flags,
  1301. uint32_t fwt);
  1302. /*!
  1303. *****************************************************************************
  1304. * \brief Transceive Blocking Rx
  1305. *
  1306. * This is method executes the reception of an ongoing Transceive triggered
  1307. * before by rfalTransceiveBlockingTx()
  1308. *
  1309. * \return ERR_NONE : Transceive done with no error
  1310. * \return ERR_BUSY : Transceive ongoing
  1311. * \return ERR_XXXX : Error occurred
  1312. * \return ERR_TIMEOUT : No response
  1313. * \return ERR_FRAMING : Framing error detected
  1314. * \return ERR_PAR : Parity error detected
  1315. * \return ERR_CRC : CRC error detected
  1316. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1317. * \return ERR_RF_COLLISION : Collision detected
  1318. * \return ERR_IO : Internal error
  1319. *****************************************************************************
  1320. */
  1321. ReturnCode rfalTransceiveBlockingRx(void);
  1322. /*!
  1323. *****************************************************************************
  1324. * \brief Transceive Blocking
  1325. *
  1326. * This is method triggers a Transceive and executes it blocking until it
  1327. * has been completed
  1328. *
  1329. * \param[in] txBuf : Buffer where outgoing message is located
  1330. * \param[in] txBufLen : Length of the outgoing message in bytes
  1331. * \param[out] rxBuf : Buffer where incoming message will be placed
  1332. * \param[in] rxBufLen : Maximum length of the incoming message in bytes
  1333. * \param[out] actLen : Actual received length in bytes
  1334. * \param[in] flags : TransceiveFlags indication special handling
  1335. * \param[in] fwt : Frame Waiting Time in 1/fc
  1336. *
  1337. * \return ERR_NONE : Transceive done with no error
  1338. * \return ERR_BUSY : Transceive ongoing
  1339. * \return ERR_XXXX : Error occurred
  1340. * \return ERR_TIMEOUT : No response
  1341. * \return ERR_FRAMING : Framing error detected
  1342. * \return ERR_PAR : Parity error detected
  1343. * \return ERR_CRC : CRC error detected
  1344. * \return ERR_LINK_LOSS : Link Loss - External Field is Off
  1345. * \return ERR_RF_COLLISION : Collision detected
  1346. * \return ERR_IO : Internal error
  1347. *****************************************************************************
  1348. */
  1349. ReturnCode rfalTransceiveBlockingTxRx(
  1350. uint8_t* txBuf,
  1351. uint16_t txBufLen,
  1352. uint8_t* rxBuf,
  1353. uint16_t rxBufLen,
  1354. uint16_t* actLen,
  1355. uint32_t flags,
  1356. uint32_t fwt);
  1357. /*****************************************************************************
  1358. * Listen Mode *
  1359. *****************************************************************************/
  1360. /*!
  1361. *****************************************************************************
  1362. * \brief Is external Field On
  1363. *
  1364. * Checks if external field (other peer/device) is on/detected
  1365. *
  1366. * \return true External field is On
  1367. * \return false No external field is detected
  1368. *
  1369. *****************************************************************************
  1370. */
  1371. bool rfalIsExtFieldOn(void);
  1372. /*!
  1373. *****************************************************************************
  1374. * \brief Listen Mode start
  1375. *
  1376. * Configures RF Chip to go into listen mode enabling the given technologies
  1377. *
  1378. *
  1379. * \param[in] lmMask: mask with the enabled/disabled listen modes
  1380. * use: RFAL_LM_MASK_NFCA ; RFAL_LM_MASK_NFCB ;
  1381. * RFAL_LM_MASK_NFCF ; RFAL_LM_MASK_ACTIVE_P2P
  1382. * \param[in] confA: pointer to Passive A configurations (NULL if disabled)
  1383. * \param[in] confB: pointer to Passive B configurations (NULL if disabled)
  1384. * \param[in] confF: pointer to Passive F configurations (NULL if disabled)
  1385. * \param[in] rxBuf: buffer to place incoming data
  1386. * \param[in] rxBufLen: length in bits of rxBuf
  1387. * \param[in] rxLen: pointer to write the data length in bits placed into rxBuf
  1388. *
  1389. *
  1390. * \return ERR_PARAM Invalid parameter
  1391. * \return ERR_REQUEST Invalid listen mode mask
  1392. * \return ERR_NONE Done with no error
  1393. *
  1394. *****************************************************************************
  1395. */
  1396. ReturnCode rfalListenStart(
  1397. uint32_t lmMask,
  1398. const rfalLmConfPA* confA,
  1399. const rfalLmConfPB* confB,
  1400. const rfalLmConfPF* confF,
  1401. uint8_t* rxBuf,
  1402. uint16_t rxBufLen,
  1403. uint16_t* rxLen);
  1404. /*!
  1405. *****************************************************************************
  1406. * \brief Listen Mode start Sleeping
  1407. *
  1408. *
  1409. *****************************************************************************
  1410. */
  1411. ReturnCode
  1412. rfalListenSleepStart(rfalLmState sleepSt, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t* rxLen);
  1413. /*!
  1414. *****************************************************************************
  1415. * \brief Listen Mode Stop
  1416. *
  1417. * Disables the listen mode on the RF Chip
  1418. *
  1419. * \warning the listen mode will be disabled immediately on the RFchip regardless
  1420. * of any ongoing operations like Transceive
  1421. *
  1422. * \return ERR_NONE Done with no error
  1423. *
  1424. *****************************************************************************
  1425. */
  1426. ReturnCode rfalListenStop(void);
  1427. /*!
  1428. *****************************************************************************
  1429. * \brief Listen Mode get state
  1430. *
  1431. * Sets the new state of the Listen Mode and applies the necessary changes
  1432. * on the RF Chip
  1433. *
  1434. * \param[out] dataFlag: indicates that Listen Mode has rcvd data and caller
  1435. * must process it. The received message is located
  1436. * at the rxBuf passed on rfalListenStart().
  1437. * rfalListenSetState() will clear this flag
  1438. * if NULL output parameter will no be written/returned
  1439. * \param[out] lastBR: bit rate detected of the last initiator request
  1440. * if NULL output parameter will no be written/returned
  1441. *
  1442. * \return rfalLmState RFAL_LM_STATE_NOT_INIT : LM not initialized properly
  1443. * Any Other : LM State
  1444. *
  1445. *****************************************************************************
  1446. */
  1447. rfalLmState rfalListenGetState(bool* dataFlag, rfalBitRate* lastBR);
  1448. /*!
  1449. *****************************************************************************
  1450. * \brief Listen Mode set state
  1451. *
  1452. * Sets the new state of the Listen Mode and applies the necessary changes
  1453. * on the RF Chip
  1454. *
  1455. * \param[in] newSt : New state to go to
  1456. *
  1457. * \return ERR_WRONG_STATE : Not initialized properly
  1458. * \return ERR_PARAM : Invalid parameter
  1459. * \return ERR_NONE : Done with no error
  1460. *
  1461. *****************************************************************************
  1462. */
  1463. ReturnCode rfalListenSetState(rfalLmState newSt);
  1464. /*****************************************************************************
  1465. * Wake-Up Mode *
  1466. *****************************************************************************/
  1467. /*!
  1468. *****************************************************************************
  1469. * \brief Wake-Up Mode Start
  1470. *
  1471. * Sets the RF Chip in Low Power Wake-Up Mode according to the given
  1472. * configuration.
  1473. *
  1474. * \param[in] config : Generic Wake-Up configuration provided by lower
  1475. * layers. If NULL will automatically configure the
  1476. * Wake-Up mode
  1477. *
  1478. * \return ERR_WRONG_STATE : Not initialized properly
  1479. * \return ERR_PARAM : Invalid parameter
  1480. * \return ERR_NONE : Done with no error
  1481. *
  1482. *****************************************************************************
  1483. */
  1484. ReturnCode rfalWakeUpModeStart(const rfalWakeUpConfig* config);
  1485. /*!
  1486. *****************************************************************************
  1487. * \brief Wake-Up Has Woke
  1488. *
  1489. * Returns true if the Wake-Up mode is enabled and it has already received
  1490. * the indication from the RF Chip that the surrounding environment has changed
  1491. * and flagged at least one wake-Up interrupt
  1492. *
  1493. * \return true : Wake-Up mode enabled and has received a wake-up IRQ
  1494. * \return false : no Wake-Up IRQ has been received
  1495. *
  1496. *****************************************************************************
  1497. */
  1498. bool rfalWakeUpModeHasWoke(void);
  1499. /*!
  1500. *****************************************************************************
  1501. * \brief Wake-Up Mode Stop
  1502. *
  1503. * Stops the Wake-Up Mode
  1504. *
  1505. * \return ERR_WRONG_STATE : Not initialized properly
  1506. * \return ERR_PARAM : Invalid parameter
  1507. * \return ERR_NONE : Done with no error
  1508. *
  1509. *****************************************************************************
  1510. */
  1511. ReturnCode rfalWakeUpModeStop(void);
  1512. /*!
  1513. *****************************************************************************
  1514. * \brief Low Power Mode Start
  1515. *
  1516. * Sets the RF Chip in Low Power Mode.
  1517. * In this mode the RF Chip is placed in Low Power Mode, similar to Wake-up
  1518. * mode but no operation nor period measurement is performed.
  1519. * Mode must be terminated by rfalLowPowerModeStop()
  1520. *
  1521. * \return ERR_WRONG_STATE : Not initialized properly
  1522. * \return ERR_PARAM : Invalid parameter
  1523. * \return ERR_NONE : Done with no error
  1524. *
  1525. *****************************************************************************
  1526. */
  1527. ReturnCode rfalLowPowerModeStart(void);
  1528. /*!
  1529. *****************************************************************************
  1530. * \brief Low Power Mode Stop
  1531. *
  1532. * Stops the Low Power Mode re-enabling the device
  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 rfalLowPowerModeStop(void);
  1541. #endif /* RFAL_RF_H */
  1542. /**
  1543. * @}
  1544. *
  1545. * @}
  1546. *
  1547. * @}
  1548. */