RFAL library for the STMicroelectronics X-NUCLEO-NFC05A1

Dependents:   mbed-os-nfc05a1

Committer:
DiegoOstuni
Date:
Thu Nov 14 14:34:50 2019 +0000
Revision:
0:75fc82583a41
Add files

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:75fc82583a41 1
DiegoOstuni 0:75fc82583a41 2 /******************************************************************************
DiegoOstuni 0:75fc82583a41 3 * @attention
DiegoOstuni 0:75fc82583a41 4 *
DiegoOstuni 0:75fc82583a41 5 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
DiegoOstuni 0:75fc82583a41 6 *
DiegoOstuni 0:75fc82583a41 7 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:75fc82583a41 8 * You may not use this file except in compliance with the License.
DiegoOstuni 0:75fc82583a41 9 * You may obtain a copy of the License at:
DiegoOstuni 0:75fc82583a41 10 *
DiegoOstuni 0:75fc82583a41 11 * http://www.st.com/myliberty
DiegoOstuni 0:75fc82583a41 12 *
DiegoOstuni 0:75fc82583a41 13 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:75fc82583a41 14 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:75fc82583a41 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:75fc82583a41 16 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:75fc82583a41 17 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:75fc82583a41 18 * See the License for the specific language governing permissions and
DiegoOstuni 0:75fc82583a41 19 * limitations under the License.
DiegoOstuni 0:75fc82583a41 20 *
DiegoOstuni 0:75fc82583a41 21 ******************************************************************************/
DiegoOstuni 0:75fc82583a41 22
DiegoOstuni 0:75fc82583a41 23 /*
DiegoOstuni 0:75fc82583a41 24 * PROJECT: ST25R391x firmware
DiegoOstuni 0:75fc82583a41 25 * $Revision: $
DiegoOstuni 0:75fc82583a41 26 * LANGUAGE: ISO C99
DiegoOstuni 0:75fc82583a41 27 */
DiegoOstuni 0:75fc82583a41 28
DiegoOstuni 0:75fc82583a41 29 /*! \file rfal_iso15693.h
DiegoOstuni 0:75fc82583a41 30 *
DiegoOstuni 0:75fc82583a41 31 * \author Ulrich Herrmann
DiegoOstuni 0:75fc82583a41 32 *
DiegoOstuni 0:75fc82583a41 33 * \brief Implementation of ISO-15693-2
DiegoOstuni 0:75fc82583a41 34 *
DiegoOstuni 0:75fc82583a41 35 */
DiegoOstuni 0:75fc82583a41 36 /*!
DiegoOstuni 0:75fc82583a41 37 *
DiegoOstuni 0:75fc82583a41 38 */
DiegoOstuni 0:75fc82583a41 39
DiegoOstuni 0:75fc82583a41 40 #ifndef RFAL_ISO_15693_2_H
DiegoOstuni 0:75fc82583a41 41 #define RFAL_ISO_15693_2_H
DiegoOstuni 0:75fc82583a41 42
DiegoOstuni 0:75fc82583a41 43 /*
DiegoOstuni 0:75fc82583a41 44 ******************************************************************************
DiegoOstuni 0:75fc82583a41 45 * INCLUDES
DiegoOstuni 0:75fc82583a41 46 ******************************************************************************
DiegoOstuni 0:75fc82583a41 47 */
DiegoOstuni 0:75fc82583a41 48 #include "platform1.h"
DiegoOstuni 0:75fc82583a41 49 #include "st_errno.h"
DiegoOstuni 0:75fc82583a41 50 #include <stdbool.h>
DiegoOstuni 0:75fc82583a41 51 /*
DiegoOstuni 0:75fc82583a41 52 ******************************************************************************
DiegoOstuni 0:75fc82583a41 53 * GLOBAL DATATYPES
DiegoOstuni 0:75fc82583a41 54 ******************************************************************************
DiegoOstuni 0:75fc82583a41 55 */
DiegoOstuni 0:75fc82583a41 56 /*!
DiegoOstuni 0:75fc82583a41 57 * enum holding possible VCD codings
DiegoOstuni 0:75fc82583a41 58 */
DiegoOstuni 0:75fc82583a41 59 typedef enum
DiegoOstuni 0:75fc82583a41 60 {
DiegoOstuni 0:75fc82583a41 61 ISO15693_VCD_CODING_1_4,
DiegoOstuni 0:75fc82583a41 62 ISO15693_VCD_CODING_1_256
DiegoOstuni 0:75fc82583a41 63 }iso15693VcdCoding_t;
DiegoOstuni 0:75fc82583a41 64
DiegoOstuni 0:75fc82583a41 65 /*!
DiegoOstuni 0:75fc82583a41 66 * enum holding possible VICC datarates
DiegoOstuni 0:75fc82583a41 67 */
DiegoOstuni 0:75fc82583a41 68
DiegoOstuni 0:75fc82583a41 69 /*!
DiegoOstuni 0:75fc82583a41 70 * Configuration parameter used by #iso15693PhyConfigure
DiegoOstuni 0:75fc82583a41 71 */
DiegoOstuni 0:75fc82583a41 72 typedef struct
DiegoOstuni 0:75fc82583a41 73 {
DiegoOstuni 0:75fc82583a41 74 iso15693VcdCoding_t coding; /*!< desired VCD coding */
DiegoOstuni 0:75fc82583a41 75 bool fastMode; /*!< Fast mode - all pulse numbers and times are divided by 2 */
DiegoOstuni 0:75fc82583a41 76 }iso15693PhyConfig_t;
DiegoOstuni 0:75fc82583a41 77
DiegoOstuni 0:75fc82583a41 78 /*! Parameters how the stream mode should work */
DiegoOstuni 0:75fc82583a41 79 struct iso15693StreamConfig {
DiegoOstuni 0:75fc82583a41 80 uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */
DiegoOstuni 0:75fc82583a41 81 uint8_t din; /*!< the divider for the in subcarrier frequency: fc/2^din */
DiegoOstuni 0:75fc82583a41 82 uint8_t dout; /*!< the divider for the in subcarrier frequency fc/2^dout */
DiegoOstuni 0:75fc82583a41 83 uint8_t report_period_length; /*!< the length of the reporting period 2^report_period_length*/
DiegoOstuni 0:75fc82583a41 84 };
DiegoOstuni 0:75fc82583a41 85 /*
DiegoOstuni 0:75fc82583a41 86 ******************************************************************************
DiegoOstuni 0:75fc82583a41 87 * GLOBAL CONSTANTS
DiegoOstuni 0:75fc82583a41 88 ******************************************************************************
DiegoOstuni 0:75fc82583a41 89 */
DiegoOstuni 0:75fc82583a41 90
DiegoOstuni 0:75fc82583a41 91 /* t1min = 308,2us = 4192/fc = 65.5 * 64/fc */
DiegoOstuni 0:75fc82583a41 92 #define ISO15693_MASK_RECEIVE_TIME (65)
DiegoOstuni 0:75fc82583a41 93
DiegoOstuni 0:75fc82583a41 94 /* t1max = 323,3us = 4384/fc = 68.5 * 64/fc
DiegoOstuni 0:75fc82583a41 95 * 12 = 768/fc unmodulated time of single subcarrior SoF */
DiegoOstuni 0:75fc82583a41 96 #define ISO15693_NO_RESPONSE_TIME (69 + 12)
DiegoOstuni 0:75fc82583a41 97
DiegoOstuni 0:75fc82583a41 98
DiegoOstuni 0:75fc82583a41 99 #define ISO15693_REQ_FLAG_TWO_SUBCARRIERS 0x01
DiegoOstuni 0:75fc82583a41 100 #define ISO15693_REQ_FLAG_HIGH_DATARATE 0x02
DiegoOstuni 0:75fc82583a41 101 /*
DiegoOstuni 0:75fc82583a41 102 ******************************************************************************
DiegoOstuni 0:75fc82583a41 103 * GLOBAL FUNCTION PROTOTYPES
DiegoOstuni 0:75fc82583a41 104 ******************************************************************************
DiegoOstuni 0:75fc82583a41 105 */
DiegoOstuni 0:75fc82583a41 106 /*!
DiegoOstuni 0:75fc82583a41 107 *****************************************************************************
DiegoOstuni 0:75fc82583a41 108 * \brief Initialize the ISO15693 phy.
DiegoOstuni 0:75fc82583a41 109 * \note This function needs to be called every time after switching
DiegoOstuni 0:75fc82583a41 110 * from a different mode and before #iso15693Initialize
DiegoOstuni 0:75fc82583a41 111 *
DiegoOstuni 0:75fc82583a41 112 * \param[in] config : ISO15693 phy related configuration (See #iso15693PhyConfig_t)
DiegoOstuni 0:75fc82583a41 113 * \param[out] needed_stream_config : return a pointer to the stream config
DiegoOstuni 0:75fc82583a41 114 * needed for this iso15693 config. To be used for configure RF chip.
DiegoOstuni 0:75fc82583a41 115 *
DiegoOstuni 0:75fc82583a41 116 * \return ERR_IO : Error during communication.
DiegoOstuni 0:75fc82583a41 117 * \return ERR_NONE : No error.
DiegoOstuni 0:75fc82583a41 118 *
DiegoOstuni 0:75fc82583a41 119 *****************************************************************************
DiegoOstuni 0:75fc82583a41 120 */
DiegoOstuni 0:75fc82583a41 121 extern ReturnCode iso15693PhyConfigure(const iso15693PhyConfig_t* config,
DiegoOstuni 0:75fc82583a41 122 const struct iso15693StreamConfig ** needed_stream_config );
DiegoOstuni 0:75fc82583a41 123
DiegoOstuni 0:75fc82583a41 124 /*!
DiegoOstuni 0:75fc82583a41 125 *****************************************************************************
DiegoOstuni 0:75fc82583a41 126 * \brief Return current phy configuration.
DiegoOstuni 0:75fc82583a41 127 *
DiegoOstuni 0:75fc82583a41 128 * This function returns current Phy configuration previously
DiegoOstuni 0:75fc82583a41 129 * set by #iso15693PhyConfigure
DiegoOstuni 0:75fc82583a41 130 *
DiegoOstuni 0:75fc82583a41 131 * \param[out] config : ISO15693 phy configuration.
DiegoOstuni 0:75fc82583a41 132 *
DiegoOstuni 0:75fc82583a41 133 * \return ERR_NONE : No error.
DiegoOstuni 0:75fc82583a41 134 *
DiegoOstuni 0:75fc82583a41 135 *****************************************************************************
DiegoOstuni 0:75fc82583a41 136 */
DiegoOstuni 0:75fc82583a41 137 extern ReturnCode iso15693PhyGetConfiguration(iso15693PhyConfig_t* config);
DiegoOstuni 0:75fc82583a41 138
DiegoOstuni 0:75fc82583a41 139 /*!
DiegoOstuni 0:75fc82583a41 140 *****************************************************************************
DiegoOstuni 0:75fc82583a41 141 * \brief Code an ISO15693 compatible frame
DiegoOstuni 0:75fc82583a41 142 *
DiegoOstuni 0:75fc82583a41 143 * This function takes \a length bytes from \a buffer, perform proper
DiegoOstuni 0:75fc82583a41 144 * encoding and sends out the frame to the ST25R3911.
DiegoOstuni 0:75fc82583a41 145 *
DiegoOstuni 0:75fc82583a41 146 * \param[in] buffer : data to send, modified to adapt flags.
DiegoOstuni 0:75fc82583a41 147 * \param[in] length : number of bytes to send.
DiegoOstuni 0:75fc82583a41 148 * \param[in] sendCrc : If set to true, CRC is appended to the frame
DiegoOstuni 0:75fc82583a41 149 * \param[in] sendFlags: If set to true, flag field is sent according to
DiegoOstuni 0:75fc82583a41 150 * ISO15693.
DiegoOstuni 0:75fc82583a41 151 * \param[in] picopassMode : If set to true, the coding will be according to Picopass
DiegoOstuni 0:75fc82583a41 152 * \param[out] subbit_total_length : Return the complete bytes which need to
DiegoOstuni 0:75fc82583a41 153 * be send for the current coding
DiegoOstuni 0:75fc82583a41 154 * \param[in,out] offset : Set to 0 for first transfer, function will update it to
DiegoOstuni 0:75fc82583a41 155 point to next byte to be coded
DiegoOstuni 0:75fc82583a41 156 * \param[out] outbuf : buffer where the function will store the coded subbit stream
DiegoOstuni 0:75fc82583a41 157 * \param[out] outBufSize : the size of the output buffer
DiegoOstuni 0:75fc82583a41 158 * \param[out] actOutBufSize : the amount of data stored into the buffer at this call
DiegoOstuni 0:75fc82583a41 159 *
DiegoOstuni 0:75fc82583a41 160 * \return ERR_IO : Error during communication.
DiegoOstuni 0:75fc82583a41 161 * \return ERR_AGAIN : Data was not coded all the way. Call function again with a new/emptied buffer
DiegoOstuni 0:75fc82583a41 162 * \return ERR_NO_MEM : In case outBuf is not big enough. Needs to have at
DiegoOstuni 0:75fc82583a41 163 least 5 bytes for 1of4 coding and 65 bytes for 1of256 coding
DiegoOstuni 0:75fc82583a41 164 * \return ERR_NONE : No error.
DiegoOstuni 0:75fc82583a41 165 *
DiegoOstuni 0:75fc82583a41 166 *****************************************************************************
DiegoOstuni 0:75fc82583a41 167 */
DiegoOstuni 0:75fc82583a41 168 extern ReturnCode iso15693VCDCode(uint8_t* buffer, uint16_t length, bool sendCrc, bool sendFlags, bool picopassMode,
DiegoOstuni 0:75fc82583a41 169 uint16_t *subbit_total_length, uint16_t *offset,
DiegoOstuni 0:75fc82583a41 170 uint8_t* outbuf, uint16_t outBufSize, uint16_t* actOutBufSize);
DiegoOstuni 0:75fc82583a41 171
DiegoOstuni 0:75fc82583a41 172
DiegoOstuni 0:75fc82583a41 173 /*!
DiegoOstuni 0:75fc82583a41 174 *****************************************************************************
DiegoOstuni 0:75fc82583a41 175 * \brief Receive an ISO15693 compatible frame
DiegoOstuni 0:75fc82583a41 176 *
DiegoOstuni 0:75fc82583a41 177 * This function receives an ISO15693 frame from the ST25R3911, decodes the frame
DiegoOstuni 0:75fc82583a41 178 * and writes the raw data to \a buffer.
DiegoOstuni 0:75fc82583a41 179 * \note Buffer needs to be big enough to hold CRC also (+2 bytes)
DiegoOstuni 0:75fc82583a41 180 *
DiegoOstuni 0:75fc82583a41 181 * \param[out] inBuf : buffer with the hamming coded stream to be decoded
DiegoOstuni 0:75fc82583a41 182 * \param[in] inBufLen : number of bytes to decode (=length of buffer).
DiegoOstuni 0:75fc82583a41 183 * \param[out] outBuf : buffer where received data shall be written to.
DiegoOstuni 0:75fc82583a41 184 * \param[in] outBufLen : Length of output buffer, should be approx twice the size of inBuf
DiegoOstuni 0:75fc82583a41 185 * \param[out] outBufPos : The number of decoded bytes. Could be used in
DiegoOstuni 0:75fc82583a41 186 * extended implementation to allow multiple calls
DiegoOstuni 0:75fc82583a41 187 * \param[out] bitsBeforeCol : in case of ERR_COLLISION this value holds the
DiegoOstuni 0:75fc82583a41 188 * number of bits in the current byte where the collision happened.
DiegoOstuni 0:75fc82583a41 189 * \param[in] ignoreBits : number of bits in the beginning where collisions will be ignored
DiegoOstuni 0:75fc82583a41 190 * \param[in] picopassMode : if set to true, the decoding will be according to Picopass
DiegoOstuni 0:75fc82583a41 191 *
DiegoOstuni 0:75fc82583a41 192 * \return ERR_COLLISION : collision occured, data uncorrect
DiegoOstuni 0:75fc82583a41 193 * \return ERR_CRC : CRC error, data uncorrect
DiegoOstuni 0:75fc82583a41 194 * \return ERR_TIMEOUT : timeout waiting for data.
DiegoOstuni 0:75fc82583a41 195 * \return ERR_NONE : No error.
DiegoOstuni 0:75fc82583a41 196 *
DiegoOstuni 0:75fc82583a41 197 *****************************************************************************
DiegoOstuni 0:75fc82583a41 198 */
DiegoOstuni 0:75fc82583a41 199 extern ReturnCode iso15693VICCDecode(uint8_t *inBuf,
DiegoOstuni 0:75fc82583a41 200 uint16_t inBufLen,
DiegoOstuni 0:75fc82583a41 201 uint8_t* outBuf,
DiegoOstuni 0:75fc82583a41 202 uint16_t outBufLen,
DiegoOstuni 0:75fc82583a41 203 uint16_t* outBufPos,
DiegoOstuni 0:75fc82583a41 204 uint16_t* bitsBeforeCol,
DiegoOstuni 0:75fc82583a41 205 uint16_t ignoreBits,
DiegoOstuni 0:75fc82583a41 206 bool picopassMode );
DiegoOstuni 0:75fc82583a41 207
DiegoOstuni 0:75fc82583a41 208 #endif /* RFAL_ISO_15693_2_H */
DiegoOstuni 0:75fc82583a41 209