rfal_st25tb.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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_st25tb.h
  27. *
  28. * \author Gustavo Patricio
  29. *
  30. * \brief Implementation of ST25TB interface
  31. *
  32. *
  33. * \addtogroup RFAL
  34. * @{
  35. *
  36. * \addtogroup RFAL-AL
  37. * \brief RFAL Abstraction Layer
  38. * @{
  39. *
  40. * \addtogroup ST25TB
  41. * \brief RFAL ST25TB Module
  42. * @{
  43. *
  44. */
  45. #ifndef RFAL_ST25TB_H
  46. #define RFAL_ST25TB_H
  47. /*
  48. ******************************************************************************
  49. * INCLUDES
  50. ******************************************************************************
  51. */
  52. #include "../platform.h"
  53. #include "../st_errno.h"
  54. #include "rfal_rf.h"
  55. #include "rfal_nfcb.h"
  56. /*
  57. ******************************************************************************
  58. * GLOBAL DEFINES
  59. ******************************************************************************
  60. */
  61. #define RFAL_ST25TB_CHIP_ID_LEN 1U /*!< ST25TB chip ID length */
  62. #define RFAL_ST25TB_CRC_LEN 2U /*!< ST25TB CRC length */
  63. #define RFAL_ST25TB_UID_LEN 8U /*!< ST25TB Unique ID length */
  64. #define RFAL_ST25TB_BLOCK_LEN 4U /*!< ST25TB Data Block length */
  65. /*
  66. ******************************************************************************
  67. * GLOBAL MACROS
  68. ******************************************************************************
  69. */
  70. /*
  71. ******************************************************************************
  72. * GLOBAL TYPES
  73. ******************************************************************************
  74. */
  75. typedef uint8_t rfalSt25tbUID[RFAL_ST25TB_UID_LEN]; /*!< ST25TB UID type */
  76. typedef uint8_t rfalSt25tbBlock[RFAL_ST25TB_BLOCK_LEN]; /*!< ST25TB Block type */
  77. /*! ST25TB listener device (PICC) struct */
  78. typedef struct {
  79. uint8_t chipID; /*!< Device's session Chip ID */
  80. rfalSt25tbUID UID; /*!< Device's UID */
  81. bool isDeselected; /*!< Device deselect flag */
  82. } rfalSt25tbListenDevice;
  83. /*
  84. ******************************************************************************
  85. * GLOBAL FUNCTION PROTOTYPES
  86. ******************************************************************************
  87. */
  88. /*!
  89. *****************************************************************************
  90. * \brief Initialize ST25TB Poller mode
  91. *
  92. * This methods configures RFAL RF layer to perform as a
  93. * ST25TB Poller/RW including all default timings
  94. *
  95. * \return ERR_WRONG_STATE : RFAL not initialized or mode not set
  96. * \return ERR_NONE : No error
  97. *****************************************************************************
  98. */
  99. ReturnCode rfalSt25tbPollerInitialize(void);
  100. /*!
  101. *****************************************************************************
  102. * \brief ST25TB Poller Check Presence
  103. *
  104. * This method checks if a ST25TB Listen device (PICC) is present on the field
  105. * by sending an Initiate command
  106. *
  107. * \param[out] chipId : if successfully retrieved, the device's chip ID
  108. *
  109. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  110. * \return ERR_PARAM : Invalid parameters
  111. * \return ERR_IO : Generic internal error
  112. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  113. * \return ERR_RF_COLLISION : Collision detected one or more device in the field
  114. * \return ERR_PROTO : Protocol error detected
  115. * \return ERR_NONE : No error
  116. *****************************************************************************
  117. */
  118. ReturnCode rfalSt25tbPollerCheckPresence(uint8_t* chipId);
  119. /*!
  120. *****************************************************************************
  121. * \brief ST25TB Poller Collision Resolution
  122. *
  123. * This method performs ST25TB Collision resolution, selects the each device,
  124. * retrieves its UID and then deselects.
  125. * In case only one device is identified the ST25TB device is left in select
  126. * state.
  127. *
  128. * \param[in] devLimit : device limit value, and size st25tbDevList
  129. * \param[out] st25tbDevList : ST35TB listener device info
  130. * \param[out] devCnt : Devices found counter
  131. *
  132. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  133. * \return ERR_PARAM : Invalid parameters
  134. * \return ERR_IO : Generic internal error
  135. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  136. * \return ERR_RF_COLLISION : Collision detected one or more device in the field
  137. * \return ERR_PROTO : Protocol error detected
  138. * \return ERR_NONE : No error
  139. *****************************************************************************
  140. */
  141. ReturnCode rfalSt25tbPollerCollisionResolution(
  142. uint8_t devLimit,
  143. rfalSt25tbListenDevice* st25tbDevList,
  144. uint8_t* devCnt);
  145. /*!
  146. *****************************************************************************
  147. * \brief ST25TB Poller Initiate
  148. *
  149. * This method sends an Initiate command
  150. *
  151. * If a single device responds the chip ID will be retrieved
  152. *
  153. * \param[out] chipId : chip ID of the device
  154. *
  155. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  156. * \return ERR_PARAM : Invalid parameters
  157. * \return ERR_IO : Generic internal error
  158. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  159. * \return ERR_PROTO : Protocol error detected
  160. * \return ERR_NONE : No error
  161. *****************************************************************************
  162. */
  163. ReturnCode rfalSt25tbPollerInitiate(uint8_t* chipId);
  164. /*!
  165. *****************************************************************************
  166. * \brief ST25TB Poller Pcall
  167. *
  168. * This method sends a Pcall command
  169. * If successful the device's chip ID will be retrieved
  170. *
  171. * \param[out] chipId : Chip ID of the device
  172. *
  173. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  174. * \return ERR_PARAM : Invalid parameters
  175. * \return ERR_IO : Generic internal error
  176. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  177. * \return ERR_PROTO : Protocol error detected
  178. * \return ERR_NONE : No error
  179. *****************************************************************************
  180. */
  181. ReturnCode rfalSt25tbPollerPcall(uint8_t* chipId);
  182. /*!
  183. *****************************************************************************
  184. * \brief ST25TB Poller Slot Marker
  185. *
  186. * This method sends a Slot Marker
  187. *
  188. * If a single device responds the chip ID will be retrieved
  189. *
  190. * \param[in] slotNum : Slot Number
  191. * \param[out] chipIdRes : Chip ID of the device
  192. *
  193. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  194. * \return ERR_PARAM : Invalid parameters
  195. * \return ERR_IO : Generic internal error
  196. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  197. * \return ERR_PROTO : Protocol error detected
  198. * \return ERR_NONE : No error
  199. *****************************************************************************
  200. */
  201. ReturnCode rfalSt25tbPollerSlotMarker(uint8_t slotNum, uint8_t* chipIdRes);
  202. /*!
  203. *****************************************************************************
  204. * \brief ST25TB Poller Select
  205. *
  206. * This method sends a ST25TB Select command with the given chip ID.
  207. *
  208. * If the device is already in Selected state and receives an incorrect chip
  209. * ID, it goes into Deselected state
  210. *
  211. * \param[in] chipId : chip ID of the device to be selected
  212. *
  213. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  214. * \return ERR_PARAM : Invalid parameters
  215. * \return ERR_IO : Generic internal error
  216. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  217. * \return ERR_PROTO : Protocol error detected
  218. * \return ERR_NONE : No error
  219. *****************************************************************************
  220. */
  221. ReturnCode rfalSt25tbPollerSelect(uint8_t chipId);
  222. /*!
  223. *****************************************************************************
  224. * \brief ST25TB Get UID
  225. *
  226. * This method sends a Get_UID command
  227. *
  228. * If a single device responds the chip UID will be retrieved
  229. *
  230. * \param[out] UID : UID of the found device
  231. *
  232. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  233. * \return ERR_PARAM : Invalid parameters
  234. * \return ERR_IO : Generic internal error
  235. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  236. * \return ERR_PROTO : Protocol error detected
  237. * \return ERR_NONE : No error
  238. *****************************************************************************
  239. */
  240. ReturnCode rfalSt25tbPollerGetUID(rfalSt25tbUID* UID);
  241. /*!
  242. *****************************************************************************
  243. * \brief ST25TB Poller Read Block
  244. *
  245. * This method reads a block of the ST25TB
  246. *
  247. * \param[in] blockAddress : address of the block to be read
  248. * \param[out] blockData : location to place the data read from block
  249. *
  250. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  251. * \return ERR_PARAM : Invalid parameters
  252. * \return ERR_IO : Generic internal error
  253. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  254. * \return ERR_PROTO : Protocol error detected
  255. * \return ERR_NONE : No error
  256. *****************************************************************************
  257. */
  258. ReturnCode rfalSt25tbPollerReadBlock(uint8_t blockAddress, rfalSt25tbBlock* blockData);
  259. /*!
  260. *****************************************************************************
  261. * \brief ST25TB Poller Write Block
  262. *
  263. * This method writes a block of the ST25TB
  264. *
  265. * \param[in] blockAddress : address of the block to be written
  266. * \param[in] blockData : data to be written on the block
  267. *
  268. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  269. * \return ERR_PARAM : Invalid parameters
  270. * \return ERR_IO : Generic internal error
  271. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  272. * \return ERR_PROTO : Protocol error detected
  273. * \return ERR_NONE : No error
  274. *****************************************************************************
  275. */
  276. ReturnCode rfalSt25tbPollerWriteBlock(uint8_t blockAddress, const rfalSt25tbBlock* blockData);
  277. /*!
  278. *****************************************************************************
  279. * \brief ST25TB Poller Completion
  280. *
  281. * This method sends a completion command to the ST25TB. After the
  282. * completion the card no longer will reply to any command.
  283. *
  284. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  285. * \return ERR_PARAM : Invalid parameters
  286. * \return ERR_IO : Generic internal error
  287. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  288. * \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received
  289. * \return ERR_NONE : No error
  290. *****************************************************************************
  291. */
  292. ReturnCode rfalSt25tbPollerCompletion(void);
  293. /*!
  294. *****************************************************************************
  295. * \brief ST25TB Poller Reset to Inventory
  296. *
  297. * This method sends a Reset to Inventory command to the ST25TB.
  298. *
  299. * \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
  300. * \return ERR_PARAM : Invalid parameters
  301. * \return ERR_IO : Generic internal error
  302. * \return ERR_TIMEOUT : Timeout error, no listener device detected
  303. * \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received
  304. * \return ERR_NONE : No error
  305. *****************************************************************************
  306. */
  307. ReturnCode rfalSt25tbPollerResetToInventory(void);
  308. #endif /* RFAL_ST25TB_H */
  309. /**
  310. * @}
  311. *
  312. * @}
  313. *
  314. * @}
  315. */