rfal_analogConfig.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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_AnalogConfig.h
  27. *
  28. * \author bkam
  29. *
  30. * \brief RF Chip Analog Configuration Settings
  31. *
  32. *
  33. * \addtogroup RFAL
  34. * @{
  35. *
  36. * \addtogroup RFAL-HAL
  37. * \brief RFAL Hardware Abstraction Layer
  38. * @{
  39. *
  40. * \addtogroup AnalogConfig
  41. * \brief RFAL Analog Config Module
  42. * @{
  43. *
  44. */
  45. #ifndef RFAL_ANALOG_CONFIG_H
  46. #define RFAL_ANALOG_CONFIG_H
  47. /*
  48. ******************************************************************************
  49. * INCLUDES
  50. ******************************************************************************
  51. */
  52. #include "platform.h"
  53. #include "st_errno.h"
  54. #include "rfal_rf.h"
  55. /*
  56. ******************************************************************************
  57. * DEFINES
  58. ******************************************************************************
  59. */
  60. #define RFAL_ANALOG_CONFIG_LUT_SIZE (87U) /*!< Maximum number of Configuration IDs in the Loop Up Table */
  61. #define RFAL_ANALOG_CONFIG_LUT_NOT_FOUND (0xFFU) /*!< Index value indicating no Configuration IDs found */
  62. #define RFAL_ANALOG_CONFIG_TBL_SIZE (1024U) /*!< Maximum number of Register-Mask-Value in the Setting List */
  63. #define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK (0x8000U) /*!< Mask bit of Poll Mode in Analog Configuration ID */
  64. #define RFAL_ANALOG_CONFIG_TECH_MASK (0x7F00U) /*!< Mask bits for Technology in Analog Configuration ID */
  65. #define RFAL_ANALOG_CONFIG_BITRATE_MASK (0x00F0U) /*!< Mask bits for Bit rate in Analog Configuration ID */
  66. #define RFAL_ANALOG_CONFIG_DIRECTION_MASK (0x000FU) /*!< Mask bits for Direction in Analog Configuration ID */
  67. #define RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK (0x00FFU) /*!< Mask bits for Chip Specific Technology */
  68. #define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_SHIFT (15U) /*!< Shift value of Poll Mode in Analog Configuration ID */
  69. #define RFAL_ANALOG_CONFIG_TECH_SHIFT (8U) /*!< Shift value for Technology in Analog Configuration ID */
  70. #define RFAL_ANALOG_CONFIG_BITRATE_SHIFT (4U) /*!< Shift value for Technology in Analog Configuration ID */
  71. #define RFAL_ANALOG_CONFIG_DIRECTION_SHIFT (0U) /*!< Shift value for Direction in Analog Configuration ID */
  72. #define RFAL_ANALOG_CONFIG_POLL (0x0000U) /*!< Poll Mode bit setting in Analog Configuration ID */
  73. #define RFAL_ANALOG_CONFIG_LISTEN (0x8000U) /*!< Listen Mode bit setting in Analog Configuration ID */
  74. #define RFAL_ANALOG_CONFIG_TECH_CHIP (0x0000U) /*!< Chip-Specific bit setting in Analog Configuration ID */
  75. #define RFAL_ANALOG_CONFIG_TECH_NFCA (0x0100U) /*!< NFC-A Technology bits setting in Analog Configuration ID */
  76. #define RFAL_ANALOG_CONFIG_TECH_NFCB (0x0200U) /*!< NFC-B Technology bits setting in Analog Configuration ID */
  77. #define RFAL_ANALOG_CONFIG_TECH_NFCF (0x0400U) /*!< NFC-F Technology bits setting in Analog Configuration ID */
  78. #define RFAL_ANALOG_CONFIG_TECH_AP2P (0x0800U) /*!< AP2P Technology bits setting in Analog Configuration ID */
  79. #define RFAL_ANALOG_CONFIG_TECH_NFCV (0x1000U) /*!< NFC-V Technology bits setting in Analog Configuration ID */
  80. #define RFAL_ANALOG_CONFIG_TECH_RFU (0x2000U) /*!< RFU for Technology bits */
  81. #define RFAL_ANALOG_CONFIG_BITRATE_COMMON (0x0000U) /*!< Common settings for all bit rates in Analog Configuration ID */
  82. #define RFAL_ANALOG_CONFIG_BITRATE_106 (0x0010U) /*!< 106kbits/s settings in Analog Configuration ID */
  83. #define RFAL_ANALOG_CONFIG_BITRATE_212 (0x0020U) /*!< 212kbits/s settings in Analog Configuration ID */
  84. #define RFAL_ANALOG_CONFIG_BITRATE_424 (0x0030U) /*!< 424kbits/s settings in Analog Configuration ID */
  85. #define RFAL_ANALOG_CONFIG_BITRATE_848 (0x0040U) /*!< 848kbits/s settings in Analog Configuration ID */
  86. #define RFAL_ANALOG_CONFIG_BITRATE_1695 (0x0050U) /*!< 1695kbits/s settings in Analog Configuration ID */
  87. #define RFAL_ANALOG_CONFIG_BITRATE_3390 (0x0060U) /*!< 3390kbits/s settings in Analog Configuration ID */
  88. #define RFAL_ANALOG_CONFIG_BITRATE_6780 (0x0070U) /*!< 6780kbits/s settings in Analog Configuration ID */
  89. #define RFAL_ANALOG_CONFIG_BITRATE_1OF4 (0x00C0U) /*!< 1 out of 4 for NFC-V setting in Analog Configuration ID */
  90. #define RFAL_ANALOG_CONFIG_BITRATE_1OF256 (0x00D0U) /*!< 1 out of 256 for NFC-V setting in Analog Configuration ID */
  91. #define RFAL_ANALOG_CONFIG_NO_DIRECTION (0x0000U) /*!< No direction setting in Analog Conf ID (Chip Specific only) */
  92. #define RFAL_ANALOG_CONFIG_TX (0x0001U) /*!< Transmission bit setting in Analog Configuration ID */
  93. #define RFAL_ANALOG_CONFIG_RX (0x0002U) /*!< Reception bit setting in Analog Configuration ID */
  94. #define RFAL_ANALOG_CONFIG_ANTICOL (0x0003U) /*!< Anticollision setting in Analog Configuration ID */
  95. #define RFAL_ANALOG_CONFIG_DPO (0x0004U) /*!< DPO setting in Analog Configuration ID */
  96. #define RFAL_ANALOG_CONFIG_CHIP_INIT (0x0000U) /*!< Chip-Specific event: Startup;Reset;Initialize */
  97. #define RFAL_ANALOG_CONFIG_CHIP_DEINIT (0x0001U) /*!< Chip-Specific event: Deinitialize */
  98. #define RFAL_ANALOG_CONFIG_CHIP_FIELD_ON (0x0002U) /*!< Chip-Specific event: Field On */
  99. #define RFAL_ANALOG_CONFIG_CHIP_FIELD_OFF (0x0003U) /*!< Chip-Specific event: Field Off */
  100. #define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_ON (0x0004U) /*!< Chip-Specific event: Wake-up On */
  101. #define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_OFF (0x0005U) /*!< Chip-Specific event: Wake-up Off */
  102. #define RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON (0x0006U) /*!< Chip-Specific event: Listen On */
  103. #define RFAL_ANALOG_CONFIG_CHIP_LISTEN_OFF (0x0007U) /*!< Chip-Specific event: Listen Off */
  104. #define RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON (0x0008U) /*!< Chip-Specific event: Poll common */
  105. #define RFAL_ANALOG_CONFIG_CHIP_LISTEN_COMMON (0x0009U) /*!< Chip-Specific event: Listen common */
  106. #define RFAL_ANALOG_CONFIG_CHIP_LOWPOWER_ON (0x000AU) /*!< Chip-Specific event: Low Power On */
  107. #define RFAL_ANALOG_CONFIG_CHIP_LOWPOWER_OFF (0x000BU) /*!< Chip-Specific event: Low Power Off */
  108. #define RFAL_ANALOG_CONFIG_UPDATE_LAST (0x00U) /*!< Value indicating Last configuration set during update */
  109. #define RFAL_ANALOG_CONFIG_UPDATE_MORE (0x01U) /*!< Value indicating More configuration set coming during update */
  110. /*
  111. ******************************************************************************
  112. * GLOBAL MACROS
  113. ******************************************************************************
  114. */
  115. #define RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(id) (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK & (id)) /*!< Check if id indicates Listen mode */
  116. #define RFAL_ANALOG_CONFIG_ID_GET_TECH(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Get the technology of Configuration ID */
  117. #define RFAL_ANALOG_CONFIG_ID_IS_CHIP(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Check if ID indicates Chip-specific */
  118. #define RFAL_ANALOG_CONFIG_ID_IS_NFCA(id) (RFAL_ANALOG_CONFIG_TECH_NFCA & (id)) /*!< Check if ID indicates NFC-A */
  119. #define RFAL_ANALOG_CONFIG_ID_IS_NFCB(id) (RFAL_ANALOG_CONFIG_TECH_NFCB & (id)) /*!< Check if ID indicates NFC-B */
  120. #define RFAL_ANALOG_CONFIG_ID_IS_NFCF(id) (RFAL_ANALOG_CONFIG_TECH_NFCF & (id)) /*!< Check if ID indicates NFC-F */
  121. #define RFAL_ANALOG_CONFIG_ID_IS_AP2P(id) (RFAL_ANALOG_CONFIG_TECH_AP2P & (id)) /*!< Check if ID indicates AP2P */
  122. #define RFAL_ANALOG_CONFIG_ID_IS_NFCV(id) (RFAL_ANALOG_CONFIG_TECH_NFCV & (id)) /*!< Check if ID indicates NFC-V */
  123. #define RFAL_ANALOG_CONFIG_ID_GET_BITRATE(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Get Bitrate of Configuration ID */
  124. #define RFAL_ANALOG_CONFIG_ID_IS_COMMON(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Check if ID indicates common bitrate */
  125. #define RFAL_ANALOG_CONFIG_ID_IS_106(id) (RFAL_ANALOG_CONFIG_BITRATE_106 & (id)) /*!< Check if ID indicates 106kbits/s */
  126. #define RFAL_ANALOG_CONFIG_ID_IS_212(id) (RFAL_ANALOG_CONFIG_BITRATE_212 & (id)) /*!< Check if ID indicates 212kbits/s */
  127. #define RFAL_ANALOG_CONFIG_ID_IS_424(id) (RFAL_ANALOG_CONFIG_BITRATE_424 & (id)) /*!< Check if ID indicates 424kbits/s */
  128. #define RFAL_ANALOG_CONFIG_ID_IS_848(id) (RFAL_ANALOG_CONFIG_BITRATE_848 & (id)) /*!< Check if ID indicates 848kbits/s */
  129. #define RFAL_ANALOG_CONFIG_ID_IS_1695(id) (RFAL_ANALOG_CONFIG_BITRATE_1695 & (id)) /*!< Check if ID indicates 1695kbits/s */
  130. #define RFAL_ANALOG_CONFIG_ID_IS_3390(id) (RFAL_ANALOG_CONFIG_BITRATE_3390 & (id)) /*!< Check if ID indicates 3390kbits/s */
  131. #define RFAL_ANALOG_CONFIG_ID_IS_6780(id) (RFAL_ANALOG_CONFIG_BITRATE_6780 & (id)) /*!< Check if ID indicates 6780kbits/s */
  132. #define RFAL_ANALOG_CONFIG_ID_IS_1OF4(id) (RFAL_ANALOG_CONFIG_BITRATE_1OF4 & (id)) /*!< Check if ID indicates 1 out of 4 bitrate */
  133. #define RFAL_ANALOG_CONFIG_ID_IS_1OF256(id) (RFAL_ANALOG_CONFIG_BITRATE_1OF256 & (id)) /*!< Check if ID indicates 1 out of 256 bitrate */
  134. #define RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(id) (RFAL_ANALOG_CONFIG_DIRECTION_MASK & (id)) /*!< Get Direction of Configuration ID */
  135. #define RFAL_ANALOG_CONFIG_ID_IS_TX(id) (RFAL_ANALOG_CONFIG_TX & (id)) /*!< Check if id indicates TX */
  136. #define RFAL_ANALOG_CONFIG_ID_IS_RX(id) (RFAL_ANALOG_CONFIG_RX & (id)) /*!< Check if id indicates RX */
  137. #define RFAL_ANALOG_CONFIG_CONFIG_NUM(x) (sizeof(x)/sizeof((x)[0])) /*!< Get Analog Config number */
  138. /*! Set Analog Config ID value by: Mode, Technology, Bitrate and Direction */
  139. #define RFAL_ANALOG_CONFIG_ID_SET(mode, tech, br, direction) \
  140. ( RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(mode) \
  141. | RFAL_ANALOG_CONFIG_ID_GET_TECH(tech) \
  142. | RFAL_ANALOG_CONFIG_ID_GET_BITRATE(br) \
  143. | RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(direction) \
  144. )
  145. /*
  146. ******************************************************************************
  147. * GLOBAL DATA TYPES
  148. ******************************************************************************
  149. */
  150. typedef uint8_t rfalAnalogConfigMode; /*!< Polling or Listening Mode of Configuration */
  151. typedef uint8_t rfalAnalogConfigTech; /*!< Technology of Configuration */
  152. typedef uint8_t rfalAnalogConfigBitrate; /*!< Bitrate of Configuration */
  153. typedef uint8_t rfalAnalogConfigDirection; /*!< Transmit/Receive direction of Configuration */
  154. typedef uint8_t rfalAnalogConfigRegAddr[2]; /*!< Register Address to ST Chip */
  155. typedef uint8_t rfalAnalogConfigRegMask; /*!< Register Mask Value */
  156. typedef uint8_t rfalAnalogConfigRegVal; /*!< Register Value */
  157. typedef uint16_t rfalAnalogConfigId; /*!< Analog Configuration ID */
  158. typedef uint16_t rfalAnalogConfigOffset; /*!< Analog Configuration offset address in the table */
  159. typedef uint8_t rfalAnalogConfigNum; /*!< Number of Analog settings for the respective Configuration ID */
  160. /*! Struct that contain the Register-Mask-Value set. Make sure that the whole structure size is even and unaligned! */
  161. typedef struct {
  162. rfalAnalogConfigRegAddr addr; /*!< Register Address */
  163. rfalAnalogConfigRegMask mask; /*!< Register Mask Value */
  164. rfalAnalogConfigRegVal val; /*!< Register Value */
  165. } rfalAnalogConfigRegAddrMaskVal;
  166. /*! Struct that represents the Analog Configs */
  167. typedef struct {
  168. uint8_t id[sizeof(rfalAnalogConfigId)]; /*!< Configuration ID */
  169. rfalAnalogConfigNum num; /*!< Number of Config Sets to follow */
  170. rfalAnalogConfigRegAddrMaskVal regSet[]; /*!< Register-Mask-Value sets */ /* PRQA S 1060 # MISRA 18.7 - Flexible Array Members are the only meaningful way of denoting a variable length input buffer which follows a fixed header structure. */
  171. } rfalAnalogConfig;
  172. /*
  173. ******************************************************************************
  174. * GLOBAL FUNCTION PROTOTYPES
  175. ******************************************************************************
  176. */
  177. /*!
  178. *****************************************************************************
  179. * \brief Initialize the Analog Configuration
  180. *
  181. * Reset the Analog Configuration LUT pointer to reference to default settings.
  182. *
  183. *****************************************************************************
  184. */
  185. void rfalAnalogConfigInitialize( void );
  186. /*!
  187. *****************************************************************************
  188. * \brief Indicate if the current Analog Configuration Table is complete and ready to be used.
  189. *
  190. * \return true if current Analog Configuration Table is complete and ready to be used.
  191. * \return false if current Analog Configuration Table is incomplete
  192. *
  193. *****************************************************************************
  194. */
  195. bool rfalAnalogConfigIsReady( void );
  196. /*!
  197. *****************************************************************************
  198. * \brief Write the whole Analog Configuration table in raw format
  199. *
  200. * Writes the Analog Configuration and Look Up Table with the given raw table
  201. *
  202. * NOTE: Function does not check the validity of the given Table contents
  203. *
  204. * \param[in] configTbl: location of config Table to be loaded
  205. * \param[in] configTblSize: size of the config Table to be loaded
  206. *
  207. * \return ERR_NONE : if setting is updated
  208. * \return ERR_PARAM : if configTbl is invalid
  209. * \return ERR_NOMEM : if the given Table is bigger exceeds the max size
  210. * \return ERR_REQUEST : if the update Configuration Id is disabled
  211. *
  212. *****************************************************************************
  213. */
  214. ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize );
  215. /*!
  216. *****************************************************************************
  217. * \brief Write the Analog Configuration table with new analog settings.
  218. *
  219. * Writes the Analog Configuration and Look Up Table with the new list of register-mask-value
  220. * and Configuration ID respectively.
  221. *
  222. * NOTE: Function does not check for the validity of the Register Address.
  223. *
  224. * \param[in] more: 0x00 indicates it is last Configuration ID settings;
  225. * 0x01 indicates more Configuration ID setting(s) are coming.
  226. * \param[in] *config: reference to the configuration list of current Configuraiton ID.
  227. *
  228. * \return ERR_PARAM : if Configuration ID or parameter is invalid
  229. * \return ERR_NOMEM : if LUT is full
  230. * \return ERR_REQUEST : if the update Configuration Id is disabled
  231. * \return ERR_NONE : if setting is updated
  232. *
  233. *****************************************************************************
  234. */
  235. ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config );
  236. /*!
  237. *****************************************************************************
  238. * \brief Read the whole Analog Configuration table in raw format
  239. *
  240. * Reads the whole Analog Configuration Table in raw format
  241. *
  242. * \param[out] tblBuf: location to the buffer to place the Config Table
  243. * \param[in] tblBufLen: length of the buffer to place the Config Table
  244. * \param[out] configTblSize: Config Table size
  245. *
  246. * \return ERR_PARAM : if configTbl or configTblSize is invalid
  247. * \return ERR_NOMEM : if configTblSize is not enough for the whole table
  248. * \return ERR_NONE : if read is successful
  249. *
  250. *****************************************************************************
  251. */
  252. ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize );
  253. /*!
  254. *****************************************************************************
  255. * \brief Read the Analog Configuration table.
  256. *
  257. * Read the Analog Configuration Table
  258. *
  259. * \param[in] configOffset: offset to the next Configuration ID in the List Table to be read.
  260. * \param[out] more: 0x00 indicates it is last Configuration ID settings;
  261. * 0x01 indicates more Configuration ID setting(s) are coming.
  262. * \param[out] config: configuration id, number of configuration sets and register-mask-value sets
  263. * \param[in] numConfig: the remaining configuration settings space available;
  264. *
  265. * \return ERR_NOMEM : if number of Configuration for respective Configuration ID is greater the the remaining configuration setting space available
  266. * \return ERR_NONE : if read is successful
  267. *
  268. *****************************************************************************
  269. */
  270. ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig );
  271. /*!
  272. *****************************************************************************
  273. * \brief Set the Analog settings of indicated Configuration ID.
  274. *
  275. * Update the chip with indicated analog settings of indicated Configuration ID.
  276. *
  277. * \param[in] configId: configuration ID
  278. *
  279. * \return ERR_PARAM if Configuration ID is invalid
  280. * \return ERR_INTERNAL if error updating setting to chip
  281. * \return ERR_NONE if new settings is applied to chip
  282. *
  283. *****************************************************************************
  284. */
  285. ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId );
  286. /*!
  287. *****************************************************************************
  288. * \brief Generates Analog Config mode ID
  289. *
  290. * Converts RFAL mode and bitrate into Analog Config Mode ID.
  291. *
  292. * Update the chip with indicated analog settings of indicated Configuration ID.
  293. *
  294. * \param[in] md: RFAL mode format
  295. * \param[in] br: RFAL bit rate format
  296. * \param[in] dir: Analog Config communication direction
  297. *
  298. * \return Analog Config Mode ID
  299. *
  300. *****************************************************************************
  301. */
  302. uint16_t rfalAnalogConfigGenModeID( rfalMode md, rfalBitRate br, uint16_t dir );
  303. #endif /* RFAL_ANALOG_CONFIG_H */
  304. /**
  305. * @}
  306. *
  307. * @}
  308. *
  309. * @}
  310. */