rfal_iso15693_2.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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_iso15693_2.h
  27. *
  28. * \author Ulrich Herrmann
  29. *
  30. * \brief Implementation of ISO-15693-2
  31. *
  32. */
  33. /*!
  34. *
  35. */
  36. #ifndef RFAL_ISO_15693_2_H
  37. #define RFAL_ISO_15693_2_H
  38. /*
  39. ******************************************************************************
  40. * INCLUDES
  41. ******************************************************************************
  42. */
  43. #include "../platform.h"
  44. #include "../st_errno.h"
  45. /*
  46. ******************************************************************************
  47. * GLOBAL DATATYPES
  48. ******************************************************************************
  49. */
  50. /*! Enum holding possible VCD codings */
  51. typedef enum { ISO15693_VCD_CODING_1_4, ISO15693_VCD_CODING_1_256 } iso15693VcdCoding_t;
  52. /*! Enum holding possible VICC datarates */
  53. /*! Configuration parameter used by #iso15693PhyConfigure */
  54. typedef struct {
  55. iso15693VcdCoding_t coding; /*!< desired VCD coding */
  56. uint32_t
  57. speedMode; /*!< 0: normal mode, 1: 2^1 = x2 Fast mode, 2 : 2^2 = x4 mode, 3 : 2^3 = x8 mode - all rx pulse numbers and times are divided by 1,2,4,8 */
  58. } iso15693PhyConfig_t;
  59. /*! Parameters how the stream mode should work */
  60. struct iso15693StreamConfig {
  61. uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */
  62. uint8_t din; /*!< the divider for the in subcarrier frequency: fc/2^din */
  63. uint8_t dout; /*!< the divider for the in subcarrier frequency fc/2^dout */
  64. uint8_t report_period_length; /*!< the length of the reporting period 2^report_period_length*/
  65. };
  66. /*
  67. ******************************************************************************
  68. * GLOBAL CONSTANTS
  69. ******************************************************************************
  70. */
  71. #define ISO15693_REQ_FLAG_TWO_SUBCARRIERS \
  72. 0x01U /*!< Flag indication that communication uses two subcarriers */
  73. #define ISO15693_REQ_FLAG_HIGH_DATARATE \
  74. 0x02U /*!< Flag indication that communication uses high bitrate */
  75. #define ISO15693_MASK_FDT_LISTEN \
  76. (65) /*!< t1min = 308,2us = 4192/fc = 65.5 * 64/fc */
  77. /*! t1max = 323,3us = 4384/fc = 68.5 * 64/fc
  78. * 12 = 768/fc unmodulated time of single subcarrior SoF */
  79. #define ISO15693_FWT (69 + 12)
  80. /*
  81. ******************************************************************************
  82. * GLOBAL FUNCTION PROTOTYPES
  83. ******************************************************************************
  84. */
  85. /*!
  86. *****************************************************************************
  87. * \brief Initialize the ISO15693 phy
  88. *
  89. * \param[in] config : ISO15693 phy related configuration (See #iso15693PhyConfig_t)
  90. * \param[out] needed_stream_config : return a pointer to the stream config
  91. * needed for this iso15693 config. To be used for configure RF chip.
  92. *
  93. * \return ERR_IO : Error during communication.
  94. * \return ERR_NONE : No error.
  95. *
  96. *****************************************************************************
  97. */
  98. extern ReturnCode iso15693PhyConfigure(
  99. const iso15693PhyConfig_t* config,
  100. const struct iso15693StreamConfig** needed_stream_config);
  101. /*!
  102. *****************************************************************************
  103. * \brief Return current phy configuration
  104. *
  105. * This function returns current Phy configuration previously
  106. * set by #iso15693PhyConfigure
  107. *
  108. * \param[out] config : ISO15693 phy configuration.
  109. *
  110. * \return ERR_NONE : No error.
  111. *
  112. *****************************************************************************
  113. */
  114. extern ReturnCode iso15693PhyGetConfiguration(iso15693PhyConfig_t* config);
  115. /*!
  116. *****************************************************************************
  117. * \brief Code an ISO15693 compatible frame
  118. *
  119. * This function takes \a length bytes from \a buffer, perform proper
  120. * encoding and sends out the frame to the ST25R391x.
  121. *
  122. * \param[in] buffer : data to send, modified to adapt flags.
  123. * \param[in] length : number of bytes to send.
  124. * \param[in] sendCrc : If set to true, CRC is appended to the frame
  125. * \param[in] sendFlags: If set to true, flag field is sent according to
  126. * ISO15693.
  127. * \param[in] picopassMode : If set to true, the coding will be according to Picopass
  128. * \param[out] subbit_total_length : Return the complete bytes which need to
  129. * be send for the current coding
  130. * \param[in,out] offset : Set to 0 for first transfer, function will update it to
  131. point to next byte to be coded
  132. * \param[out] outbuf : buffer where the function will store the coded subbit stream
  133. * \param[out] outBufSize : the size of the output buffer
  134. * \param[out] actOutBufSize : the amount of data stored into the buffer at this call
  135. *
  136. * \return ERR_IO : Error during communication.
  137. * \return ERR_AGAIN : Data was not coded all the way. Call function again with a new/emptied buffer
  138. * \return ERR_NO_MEM : In case outBuf is not big enough. Needs to have at
  139. least 5 bytes for 1of4 coding and 65 bytes for 1of256 coding
  140. * \return ERR_NONE : No error.
  141. *
  142. *****************************************************************************
  143. */
  144. extern ReturnCode iso15693VCDCode(
  145. uint8_t* buffer,
  146. uint16_t length,
  147. bool sendCrc,
  148. bool sendFlags,
  149. bool picopassMode,
  150. uint16_t* subbit_total_length,
  151. uint16_t* offset,
  152. uint8_t* outbuf,
  153. uint16_t outBufSize,
  154. uint16_t* actOutBufSize);
  155. /*!
  156. *****************************************************************************
  157. * \brief Receive an ISO15693 compatible frame
  158. *
  159. * This function receives an ISO15693 frame from the ST25R391x, decodes the frame
  160. * and writes the raw data to \a buffer.
  161. * \note Buffer needs to be big enough to hold CRC also (+2 bytes)
  162. *
  163. * \param[in] inBuf : buffer with the hamming coded stream to be decoded
  164. * \param[in] inBufLen : number of bytes to decode (=length of buffer).
  165. * \param[out] outBuf : buffer where received data shall be written to.
  166. * \param[in] outBufLen : Length of output buffer, should be approx twice the size of inBuf
  167. * \param[out] outBufPos : The number of decoded bytes. Could be used in
  168. * extended implementation to allow multiple calls
  169. * \param[out] bitsBeforeCol : in case of ERR_COLLISION this value holds the
  170. * number of bits in the current byte where the collision happened.
  171. * \param[in] ignoreBits : number of bits in the beginning where collisions will be ignored
  172. * \param[in] picopassMode : if set to true, the decoding will be according to Picopass
  173. *
  174. * \return ERR_COLLISION : collision occurred, data incorrect
  175. * \return ERR_CRC : CRC error, data incorrect
  176. * \return ERR_TIMEOUT : timeout waiting for data.
  177. * \return ERR_NONE : No error.
  178. *
  179. *****************************************************************************
  180. */
  181. extern ReturnCode iso15693VICCDecode(
  182. const uint8_t* inBuf,
  183. uint16_t inBufLen,
  184. uint8_t* outBuf,
  185. uint16_t outBufLen,
  186. uint16_t* outBufPos,
  187. uint16_t* bitsBeforeCol,
  188. uint16_t ignoreBits,
  189. bool picopassMode);
  190. #endif /* RFAL_ISO_15693_2_H */