st25r3916.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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: ST25R3916 firmware
  23. * Revision:
  24. * LANGUAGE: ISO C99
  25. */
  26. /*! \file
  27. *
  28. * \author Gustavo Patricio
  29. *
  30. * \brief ST25R3916 high level interface
  31. *
  32. *
  33. * \addtogroup RFAL
  34. * @{
  35. *
  36. * \addtogroup RFAL-HAL
  37. * \brief RFAL Hardware Abstraction Layer
  38. * @{
  39. *
  40. * \addtogroup ST25R3916
  41. * \brief RFAL ST25R3916 Driver
  42. * @{
  43. *
  44. * \addtogroup ST25R3916_Driver
  45. * \brief RFAL ST25R3916 Driver
  46. * @{
  47. *
  48. */
  49. #ifndef ST25R3916_H
  50. #define ST25R3916_H
  51. /*
  52. ******************************************************************************
  53. * INCLUDES
  54. ******************************************************************************
  55. */
  56. #include "platform.h"
  57. #include "st_errno.h"
  58. #include "st25r3916_com.h"
  59. /*
  60. ******************************************************************************
  61. * GLOBAL DATATYPES
  62. ******************************************************************************
  63. */
  64. /*! Struct to represent all regs on ST25R3916 */
  65. typedef struct {
  66. uint8_t RsA[(
  67. ST25R3916_REG_IC_IDENTITY + 1U)]; /*!< Registers contained on ST25R3916 space A (Rs-A) */
  68. uint8_t
  69. RsB[ST25R3916_SPACE_B_REG_LEN]; /*!< Registers contained on ST25R3916 space B (Rs-B) */
  70. } t_st25r3916Regs;
  71. /*! Parameters how the stream mode should work */
  72. struct st25r3916StreamConfig {
  73. uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */
  74. uint8_t din; /*!< Divider for the in subcarrier frequency: fc/2^din */
  75. uint8_t dout; /*!< Divider for the in subcarrier frequency fc/2^dout */
  76. uint8_t report_period_length; /*!< Length of the reporting period 2^report_period_length*/
  77. };
  78. /*
  79. ******************************************************************************
  80. * GLOBAL DEFINES
  81. ******************************************************************************
  82. */
  83. /* ST25R3916 direct commands */
  84. #define ST25R3916_CMD_SET_DEFAULT \
  85. 0xC1U /*!< Puts the chip in default state (same as after power-up) */
  86. #define ST25R3916_CMD_STOP 0xC2U /*!< Stops all activities and clears FIFO */
  87. #define ST25R3916_CMD_TRANSMIT_WITH_CRC \
  88. 0xC4U /*!< Transmit with CRC */
  89. #define ST25R3916_CMD_TRANSMIT_WITHOUT_CRC \
  90. 0xC5U /*!< Transmit without CRC */
  91. #define ST25R3916_CMD_TRANSMIT_REQA \
  92. 0xC6U /*!< Transmit REQA */
  93. #define ST25R3916_CMD_TRANSMIT_WUPA \
  94. 0xC7U /*!< Transmit WUPA */
  95. #define ST25R3916_CMD_INITIAL_RF_COLLISION \
  96. 0xC8U /*!< NFC transmit with Initial RF Collision Avoidance */
  97. #define ST25R3916_CMD_RESPONSE_RF_COLLISION_N \
  98. 0xC9U /*!< NFC transmit with Response RF Collision Avoidance */
  99. #define ST25R3916_CMD_GOTO_SENSE \
  100. 0xCDU /*!< Passive target logic to Sense/Idle state */
  101. #define ST25R3916_CMD_GOTO_SLEEP \
  102. 0xCEU /*!< Passive target logic to Sleep/Halt state */
  103. #define ST25R3916_CMD_MASK_RECEIVE_DATA \
  104. 0xD0U /*!< Mask receive data */
  105. #define ST25R3916_CMD_UNMASK_RECEIVE_DATA \
  106. 0xD1U /*!< Unmask receive data */
  107. #define ST25R3916_CMD_AM_MOD_STATE_CHANGE \
  108. 0xD2U /*!< AM Modulation state change */
  109. #define ST25R3916_CMD_MEASURE_AMPLITUDE \
  110. 0xD3U /*!< Measure singal amplitude on RFI inputs */
  111. #define ST25R3916_CMD_RESET_RXGAIN \
  112. 0xD5U /*!< Reset RX Gain */
  113. #define ST25R3916_CMD_ADJUST_REGULATORS \
  114. 0xD6U /*!< Adjust regulators */
  115. #define ST25R3916_CMD_CALIBRATE_DRIVER_TIMING \
  116. 0xD8U /*!< Starts the sequence to adjust the driver timing */
  117. #define ST25R3916_CMD_MEASURE_PHASE \
  118. 0xD9U /*!< Measure phase between RFO and RFI signal */
  119. #define ST25R3916_CMD_CLEAR_RSSI \
  120. 0xDAU /*!< Clear RSSI bits and restart the measurement */
  121. #define ST25R3916_CMD_CLEAR_FIFO \
  122. 0xDBU /*!< Clears FIFO, Collision and IRQ status */
  123. #define ST25R3916_CMD_TRANSPARENT_MODE \
  124. 0xDCU /*!< Transparent mode */
  125. #define ST25R3916_CMD_CALIBRATE_C_SENSOR \
  126. 0xDDU /*!< Calibrate the capacitive sensor */
  127. #define ST25R3916_CMD_MEASURE_CAPACITANCE \
  128. 0xDEU /*!< Measure capacitance */
  129. #define ST25R3916_CMD_MEASURE_VDD \
  130. 0xDFU /*!< Measure power supply voltage */
  131. #define ST25R3916_CMD_START_GP_TIMER \
  132. 0xE0U /*!< Start the general purpose timer */
  133. #define ST25R3916_CMD_START_WUP_TIMER \
  134. 0xE1U /*!< Start the wake-up timer */
  135. #define ST25R3916_CMD_START_MASK_RECEIVE_TIMER \
  136. 0xE2U /*!< Start the mask-receive timer */
  137. #define ST25R3916_CMD_START_NO_RESPONSE_TIMER \
  138. 0xE3U /*!< Start the no-response timer */
  139. #define ST25R3916_CMD_START_PPON2_TIMER \
  140. 0xE4U /*!< Start PPon2 timer */
  141. #define ST25R3916_CMD_STOP_NRT \
  142. 0xE8U /*!< Stop No Response Timer */
  143. #define ST25R3916_CMD_SPACE_B_ACCESS \
  144. 0xFBU /*!< Enable R/W access to the test registers */
  145. #define ST25R3916_CMD_TEST_ACCESS \
  146. 0xFCU /*!< Enable R/W access to the test registers */
  147. #define ST25R3916_THRESHOLD_DO_NOT_SET \
  148. 0xFFU /*!< Indicates not to change this Threshold */
  149. #define ST25R3916_BR_DO_NOT_SET \
  150. 0xFFU /*!< Indicates not to change this Bit Rate */
  151. #define ST25R3916_BR_106 0x00U /*!< ST25R3916 Bit Rate 106 kbit/s (fc/128) */
  152. #define ST25R3916_BR_212 0x01U /*!< ST25R3916 Bit Rate 212 kbit/s (fc/64) */
  153. #define ST25R3916_BR_424 0x02U /*!< ST25R3916 Bit Rate 424 kbit/s (fc/32) */
  154. #define ST25R3916_BR_848 0x03U /*!< ST25R3916 Bit Rate 848 kbit/s (fc/16) */
  155. #define ST25R3916_BR_1695 0x04U /*!< ST25R3916 Bit Rate 1696 kbit/s (fc/8) */
  156. #define ST25R3916_BR_3390 0x05U /*!< ST25R3916 Bit Rate 3390 kbit/s (fc/4) */
  157. #define ST25R3916_BR_6780 0x07U /*!< ST25R3916 Bit Rate 6780 kbit/s (fc/2) */
  158. #define ST25R3916_FIFO_DEPTH 512U /*!< Depth of FIFO */
  159. #define ST25R3916_TOUT_OSC_STABLE \
  160. 10U /*!< Max timeout for Oscillator to get stable DS: 700us */
  161. /*
  162. ******************************************************************************
  163. * GLOBAL MACROS
  164. ******************************************************************************
  165. */
  166. /*! Enables the Transmitter (Field On) and Receiver */
  167. #define st25r3916TxRxOn() \
  168. st25r3916SetRegisterBits( \
  169. ST25R3916_REG_OP_CONTROL, \
  170. (ST25R3916_REG_OP_CONTROL_rx_en | ST25R3916_REG_OP_CONTROL_tx_en))
  171. /*! Disables the Transmitter (Field Off) and Receiver */
  172. #define st25r3916TxRxOff() \
  173. st25r3916ClrRegisterBits( \
  174. ST25R3916_REG_OP_CONTROL, \
  175. (ST25R3916_REG_OP_CONTROL_rx_en | ST25R3916_REG_OP_CONTROL_tx_en))
  176. /*! Disables the Transmitter (Field Off) */
  177. #define st25r3916TxOff() \
  178. st25r3916ClrRegisterBits(ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_tx_en)
  179. /*! Checks if General Purpose Timer is still running by reading gpt_on flag */
  180. #define st25r3916IsGPTRunning() \
  181. st25r3916CheckReg( \
  182. ST25R3916_REG_NFCIP1_BIT_RATE, \
  183. ST25R3916_REG_NFCIP1_BIT_RATE_gpt_on, \
  184. ST25R3916_REG_NFCIP1_BIT_RATE_gpt_on)
  185. /*! Checks if External Filed is detected by reading ST25R3916 External Field Detector output */
  186. #define st25r3916IsExtFieldOn() \
  187. st25r3916CheckReg( \
  188. ST25R3916_REG_AUX_DISPLAY, \
  189. ST25R3916_REG_AUX_DISPLAY_efd_o, \
  190. ST25R3916_REG_AUX_DISPLAY_efd_o)
  191. /*! Checks if Transmitter is enabled (Field On) */
  192. #define st25r3916IsTxEnabled() \
  193. st25r3916CheckReg( \
  194. ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_tx_en, ST25R3916_REG_OP_CONTROL_tx_en)
  195. /*! Checks if NRT is in EMV mode */
  196. #define st25r3916IsNRTinEMV() \
  197. st25r3916CheckReg( \
  198. ST25R3916_REG_TIMER_EMV_CONTROL, \
  199. ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv, \
  200. ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv_on)
  201. /*! Checks if last FIFO byte is complete */
  202. #define st25r3916IsLastFIFOComplete() \
  203. st25r3916CheckReg(ST25R3916_REG_FIFO_STATUS2, ST25R3916_REG_FIFO_STATUS2_fifo_lb_mask, 0)
  204. /*! Checks if the Oscillator is enabled */
  205. #define st25r3916IsOscOn() \
  206. st25r3916CheckReg( \
  207. ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_en, ST25R3916_REG_OP_CONTROL_en)
  208. /*
  209. ******************************************************************************
  210. * GLOBAL FUNCTION PROTOTYPES
  211. ******************************************************************************
  212. */
  213. /*!
  214. *****************************************************************************
  215. * \brief Initialise ST25R3916 driver
  216. *
  217. * This function initialises the ST25R3916 driver.
  218. *
  219. * \return ERR_NONE : Operation successful
  220. * \return ERR_HW_MISMATCH : Expected HW do not match or communication error
  221. * \return ERR_IO : Error during communication selftest. Check communication interface
  222. * \return ERR_TIMEOUT : Timeout during IRQ selftest. Check IRQ handling
  223. * \return ERR_SYSTEM : Failure during oscillator activation or timer error
  224. *
  225. *****************************************************************************
  226. */
  227. ReturnCode st25r3916Initialize(void);
  228. /*!
  229. *****************************************************************************
  230. * \brief Deinitialize ST25R3916 driver
  231. *
  232. * Calling this function deinitializes the ST25R3916 driver.
  233. *
  234. *****************************************************************************
  235. */
  236. void st25r3916Deinitialize(void);
  237. /*!
  238. *****************************************************************************
  239. * \brief Turn on Oscillator and Regulator
  240. *
  241. * This function turn on oscillator and regulator and waits for the
  242. * oscillator to become stable
  243. *
  244. * \return ERR_SYSTEM : Failure dusring Oscillator activation
  245. * \return ERR_NONE : No error, Oscillator is active and stable, Regulator is on
  246. *
  247. *****************************************************************************
  248. */
  249. ReturnCode st25r3916OscOn(void);
  250. /*!
  251. *****************************************************************************
  252. * \brief Sets the bitrate
  253. *
  254. * This function sets the bitrates for rx and tx
  255. *
  256. * \param txrate : speed is 2^txrate * 106 kb/s
  257. * 0xff : don't set txrate (ST25R3916_BR_DO_NOT_SET)
  258. * \param rxrate : speed is 2^rxrate * 106 kb/s
  259. * 0xff : don't set rxrate (ST25R3916_BR_DO_NOT_SET)
  260. *
  261. * \return ERR_PARAM: At least one bit rate was invalid
  262. * \return ERR_NONE : No error, both bit rates were set
  263. *
  264. *****************************************************************************
  265. */
  266. ReturnCode st25r3916SetBitrate(uint8_t txrate, uint8_t rxrate);
  267. /*!
  268. *****************************************************************************
  269. * \brief Adjusts supply regulators according to the current supply voltage
  270. *
  271. * This function the power level is measured in maximum load conditions and
  272. * the regulated voltage reference is set to 250mV below this level.
  273. * Execution of this function lasts arround 5ms.
  274. *
  275. * The regulated voltages will be set to the result of Adjust Regulators
  276. *
  277. * \param [out] result_mV : Result of calibration in milliVolts
  278. *
  279. * \return ERR_IO : Error during communication with ST25R3916
  280. * \return ERR_NONE : No error
  281. *
  282. *****************************************************************************
  283. */
  284. ReturnCode st25r3916AdjustRegulators(uint16_t* result_mV);
  285. /*!
  286. *****************************************************************************
  287. * \brief Measure Amplitude
  288. *
  289. * This function measured the amplitude on the RFI inputs and stores the
  290. * result in parameter \a result.
  291. *
  292. * \param[out] result: result of RF measurement.
  293. *
  294. * \return ERR_PARAM : Invalid parameter
  295. * \return ERR_NONE : No error
  296. *
  297. *****************************************************************************
  298. */
  299. ReturnCode st25r3916MeasureAmplitude(uint8_t* result);
  300. /*!
  301. *****************************************************************************
  302. * \brief Measure Power Supply
  303. *
  304. * This function executes Measure Power Supply and returns the raw value
  305. *
  306. * \param[in] mpsv : one of ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd
  307. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_rf
  308. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_a
  309. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_d
  310. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_am
  311. *
  312. * \return the measured voltage in raw format.
  313. *
  314. *****************************************************************************
  315. */
  316. uint8_t st25r3916MeasurePowerSupply(uint8_t mpsv);
  317. /*!
  318. *****************************************************************************
  319. * \brief Measure Voltage
  320. *
  321. * This function measures the voltage on one of VDD and VDD_* and returns
  322. * the result in mV
  323. *
  324. * \param[in] mpsv : one of ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd
  325. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_rf
  326. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_a
  327. * ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_d
  328. * or ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_am
  329. *
  330. * \return the measured voltage in mV
  331. *
  332. *****************************************************************************
  333. */
  334. uint16_t st25r3916MeasureVoltage(uint8_t mpsv);
  335. /*!
  336. *****************************************************************************
  337. * \brief Measure Phase
  338. *
  339. * This function performs a Phase measurement.
  340. * The result is stored in the \a result parameter.
  341. *
  342. * \param[out] result: 8 bit long result of the measurement.
  343. *
  344. * \return ERR_PARAM : Invalid parameter
  345. * \return ERR_NONE : No error
  346. *
  347. *****************************************************************************
  348. */
  349. ReturnCode st25r3916MeasurePhase(uint8_t* result);
  350. /*!
  351. *****************************************************************************
  352. * \brief Measure Capacitance
  353. *
  354. * This function performs the capacitance measurement and stores the
  355. * result in parameter \a result.
  356. *
  357. * \param[out] result: 8 bit long result of RF measurement.
  358. *
  359. * \return ERR_PARAM : Invalid parameter
  360. * \return ERR_NONE : No error
  361. *
  362. *****************************************************************************
  363. */
  364. ReturnCode st25r3916MeasureCapacitance(uint8_t* result);
  365. /*!
  366. *****************************************************************************
  367. * \brief Calibrates Capacitive Sensor
  368. *
  369. * This function performs automatic calibration of the capacitive sensor
  370. * and stores the result in parameter \a result.
  371. *
  372. * \warning To avoid interference with Xtal oscillator and reader magnetic
  373. * field, it is strongly recommended to perform calibration
  374. * in Power-down mode only.
  375. * This method does not modify the Oscillator nor transmitter state,
  376. * these should be configured before by user.
  377. *
  378. * \param[out] result: 5 bit long result of the calibration.
  379. * Binary weighted, step 0.1 pF, max 3.1 pF
  380. *
  381. * \return ERR_PARAM : Invalid parameter
  382. * \return ERR_IO : The calibration was not successful
  383. * \return ERR_NONE : No error
  384. *
  385. *****************************************************************************
  386. */
  387. ReturnCode st25r3916CalibrateCapacitiveSensor(uint8_t* result);
  388. /*!
  389. *****************************************************************************
  390. * \brief Get NRT time
  391. *
  392. * This returns the last value set on the NRT
  393. *
  394. * \warning it does not read chip register, just the sw var that contains the
  395. * last value set before
  396. *
  397. * \return the value of the NRT in 64/fc
  398. */
  399. uint32_t st25r3916GetNoResponseTime(void);
  400. /*!
  401. *****************************************************************************
  402. * \brief Set NRT time
  403. *
  404. * This function sets the No Response Time with the given value
  405. *
  406. * \param [in] nrt_64fcs : no response time in steps of 64/fc (4.72us)
  407. *
  408. * \return ERR_PARAM : Invalid parameter (time is too large)
  409. * \return ERR_NONE : No error
  410. *
  411. *****************************************************************************
  412. */
  413. ReturnCode st25r3916SetNoResponseTime(uint32_t nrt_64fcs);
  414. /*!
  415. *****************************************************************************
  416. * \brief Set and Start NRT
  417. *
  418. * This function sets the No Response Time with the given value and
  419. * immediately starts it
  420. * Used when needs to add more time before timeout without performing Tx
  421. *
  422. * \param [in] nrt_64fcs : no response time in steps of 64/fc (4.72us)
  423. *
  424. * \return ERR_PARAM : Invalid parameter
  425. * \return ERR_NONE : No error
  426. *
  427. *****************************************************************************
  428. */
  429. ReturnCode st25r3916SetStartNoResponseTimer(uint32_t nrt_64fcs);
  430. /*!
  431. *****************************************************************************
  432. * \brief Set GPT time
  433. *
  434. * This function sets the General Purpose Timer time registers
  435. *
  436. * \param [in] gpt_8fcs : general purpose timer timeout in steps of 8/fc (590ns)
  437. *
  438. *****************************************************************************
  439. */
  440. void st25r3916SetGPTime(uint16_t gpt_8fcs);
  441. /*!
  442. *****************************************************************************
  443. * \brief Set and Start GPT
  444. *
  445. * This function sets the General Purpose Timer with the given timeout and
  446. * immediately starts it ONLY if the trigger source is not set to none.
  447. *
  448. * \param [in] gpt_8fcs : general purpose timer timeout in steps of8/fc (590ns)
  449. * \param [in] trigger_source : no trigger, start of Rx, end of Rx, end of Tx in NFC mode
  450. *
  451. * \return ERR_PARAM : Invalid parameter
  452. * \return ERR_NONE : No error
  453. *
  454. *****************************************************************************
  455. */
  456. ReturnCode st25r3916SetStartGPTimer(uint16_t gpt_8fcs, uint8_t trigger_source);
  457. /*!
  458. *****************************************************************************
  459. * \brief Sets the number Tx Bits
  460. *
  461. * Sets ST25R3916 internal registers with correct number of complete bytes and
  462. * bits to be sent
  463. *
  464. * \param [in] nBits : number of bits to be set/transmitted
  465. *
  466. *****************************************************************************
  467. */
  468. void st25r3916SetNumTxBits(uint16_t nBits);
  469. /*!
  470. *****************************************************************************
  471. * \brief Get amount of bytes in FIFO
  472. *
  473. * Gets the number of bytes currently in the FIFO
  474. *
  475. * \return the number of bytes currently in the FIFO
  476. *
  477. *****************************************************************************
  478. */
  479. uint16_t st25r3916GetNumFIFOBytes(void);
  480. /*!
  481. *****************************************************************************
  482. * \brief Get amount of bits of the last FIFO byte if incomplete
  483. *
  484. * Gets the number of bits of the last FIFO byte if incomplete
  485. *
  486. * \return the number of bits of the last FIFO byte if incomplete, 0 if
  487. * the last byte is complete
  488. *
  489. *****************************************************************************
  490. */
  491. uint8_t st25r3916GetNumFIFOLastBits(void);
  492. /*!
  493. *****************************************************************************
  494. * \brief Perform Collision Avoidance
  495. *
  496. * Performs Collision Avoidance with the given threshold and with the
  497. * n number of TRFW
  498. *
  499. * \param[in] FieldONCmd : Field ON command to be executed ST25R3916_CMD_INITIAL_RF_COLLISION
  500. * or ST25R3916_CMD_RESPONSE_RF_COLLISION_N
  501. * \param[in] pdThreshold : Peer Detection Threshold (ST25R3916_REG_FIELD_THRESHOLD_trg_xx)
  502. * 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
  503. * \param[in] caThreshold : Collision Avoidance Threshold (ST25R3916_REG_FIELD_THRESHOLD_rfe_xx)
  504. * 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
  505. * \param[in] nTRFW : Number of TRFW
  506. *
  507. * \return ERR_PARAM : Invalid parameter
  508. * \return ERR_RF_COLLISION : Collision detected
  509. * \return ERR_NONE : No collision detected
  510. *
  511. *****************************************************************************
  512. */
  513. ReturnCode st25r3916PerformCollisionAvoidance(
  514. uint8_t FieldONCmd,
  515. uint8_t pdThreshold,
  516. uint8_t caThreshold,
  517. uint8_t nTRFW);
  518. /*!
  519. *****************************************************************************
  520. * \brief Check Identity
  521. *
  522. * Checks if the chip ID is as expected.
  523. *
  524. * 5 bit IC type code for ST25R3916: 00101
  525. * The 3 lsb contain the IC revision code
  526. *
  527. * \param[out] rev : the IC revision code
  528. *
  529. * \return true when IC type is as expected
  530. * \return false otherwise
  531. */
  532. bool st25r3916CheckChipID(uint8_t* rev);
  533. /*!
  534. *****************************************************************************
  535. * \brief Retrieves all internal registers from ST25R3916
  536. *
  537. * \param[out] regDump : pointer to the struct/buffer where the reg dump
  538. * will be written
  539. *
  540. * \return ERR_PARAM : Invalid parameter
  541. * \return ERR_NONE : No error
  542. *****************************************************************************
  543. */
  544. ReturnCode st25r3916GetRegsDump(t_st25r3916Regs* regDump);
  545. /*!
  546. *****************************************************************************
  547. * \brief Check if command is valid
  548. *
  549. * Checks if the given command is a valid ST25R3916 command
  550. *
  551. * \param[in] cmd: Command to check
  552. *
  553. * \return true if is a valid command
  554. * \return false otherwise
  555. *
  556. *****************************************************************************
  557. */
  558. bool st25r3916IsCmdValid(uint8_t cmd);
  559. /*!
  560. *****************************************************************************
  561. * \brief Configure the stream mode of ST25R3916
  562. *
  563. * This function initializes the stream with the given parameters
  564. *
  565. * \param[in] config : all settings for bitrates, type, etc.
  566. *
  567. * \return ERR_PARAM : Invalid parameter
  568. * \return ERR_NONE : No error, stream mode driver initialized
  569. *
  570. *****************************************************************************
  571. */
  572. ReturnCode st25r3916StreamConfigure(const struct st25r3916StreamConfig* config);
  573. /*!
  574. *****************************************************************************
  575. * \brief Executes a direct command and returns the result
  576. *
  577. * This function executes the direct command given by \a cmd waits for
  578. * \a sleeptime for I_dct and returns the result read from register \a resreg.
  579. * The value of cmd is not checked.
  580. *
  581. * \param[in] cmd : direct command to execute
  582. * \param[in] resReg: address of the register containing the result
  583. * \param[in] tout : time in milliseconds to wait before reading the result
  584. * \param[out] result: result
  585. *
  586. * \return ERR_NONE : No error
  587. *
  588. *****************************************************************************
  589. */
  590. ReturnCode
  591. st25r3916ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resReg, uint8_t tout, uint8_t* result);
  592. /*!
  593. *****************************************************************************
  594. * \brief Gets the RSSI values
  595. *
  596. * This function gets the RSSI value of the previous reception taking into
  597. * account the gain reductions that were used.
  598. * RSSI value for both AM and PM channel can be retrieved.
  599. *
  600. * \param[out] amRssi: the RSSI on the AM channel expressed in mV
  601. * \param[out] pmRssi: the RSSI on the PM channel expressed in mV
  602. *
  603. * \return ERR_PARAM : Invalid parameter
  604. * \return ERR_NONE : No error
  605. *
  606. *****************************************************************************
  607. */
  608. ReturnCode st25r3916GetRSSI(uint16_t* amRssi, uint16_t* pmRssi);
  609. #endif /* ST25R3916_H */
  610. /**
  611. * @}
  612. *
  613. * @}
  614. *
  615. * @}
  616. *
  617. * @}
  618. */