rfal_rf.h 72 KB

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