rfal_st25tb.h 13 KB

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