Diego Ostuni / ST25R3911
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers ST25R3911.h Source File

ST25R3911.h

Go to the documentation of this file.
00001 
00002 /******************************************************************************
00003   * @attention
00004   *
00005   * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
00006   *
00007   * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
00008   * You may not use this file except in compliance with the License.
00009   * You may obtain a copy of the License at:
00010   *
00011   *        http://www.st.com/myliberty
00012   *
00013   * Unless required by applicable law or agreed to in writing, software 
00014   * distributed under the License is distributed on an "AS IS" BASIS, 
00015   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
00016   * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
00017   * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
00018   * See the License for the specific language governing permissions and
00019   * limitations under the License.
00020   *
00021 ******************************************************************************/
00022 
00023 
00024 /*
00025  *      PROJECT:   ST25R3911 firmware
00026  *      $Revision: $
00027  *      LANGUAGE:  ISO C99
00028  */
00029 
00030 /*! \file
00031  *
00032  *  \author Ulrich Herrmann
00033  *
00034  *  \brief ST25R3911 declaration file
00035  *
00036  * API:
00037  * - Initialize ST25R3911 driver: #st25r3911Initialize
00038  * - Deinitialize ST25R3911 driver: #st25r3911Deinitialize
00039  *
00040  *
00041  * @addtogroup RFAL
00042  * @{
00043  *
00044  * @addtogroup RFAL-HAL
00045  * @brief RFAL Hardware Abstraction Layer
00046  * @{
00047  *
00048  * @addtogroup ST25R3911
00049  * @brief RFAL ST25R3911 Driver
00050  * @{
00051  *
00052  * @addtogroup ST25R3911_Driver
00053  * @brief RFAL ST25R3911 Driver
00054  * @{
00055  *
00056  */
00057 
00058 #ifndef ST25R3911_H
00059 #define ST25R3911_H
00060 
00061 /*
00062 ******************************************************************************
00063 * INCLUDES
00064 ******************************************************************************
00065 */
00066 
00067 #include "st_errno.h"
00068 #include "mbed.h"
00069 #include "platform1.h"
00070 #include <stdint.h>
00071 
00072 
00073 
00074 
00075 /*
00076 ******************************************************************************
00077 * LOCAL DEFINES
00078 ******************************************************************************
00079 */
00080 
00081 #define ST25R3911_OSC_STABLE_TIMEOUT           10 /*!< Timeout for Oscillator to get stable, datasheet: 700us, take 5 ms */
00082 #define ST25R3911_CA_TIMEOUT                   10 /*!< Timeout for Collision Avoidance command                           */
00083 
00084 #define ST25R3911_WRITE_MODE  (0)                           /*!< ST25R3911 SPI Operation Mode: Write                            */
00085 #define ST25R3911_READ_MODE   (1 << 6)                      /*!< ST25R3911 SPI Operation Mode: Read                             */
00086 #define ST25R3911_FIFO_LOAD   (2 << 6)                      /*!< ST25R3911 SPI Operation Mode: FIFO Load                        */
00087 #define ST25R3911_FIFO_READ   (0xbf)                        /*!< ST25R3911 SPI Operation Mode: FIFO Read                        */
00088 #define ST25R3911_CMD_MODE    (3 << 6)                      /*!< ST25R3911 SPI Operation Mode: Direct Command                   */
00089 
00090 #define ST25R3911_CMD_LEN     (1)                           /*!< ST25R3911 CMD length                                           */
00091 #define ST25R3911_BUF_LEN     (ST25R3911_CMD_LEN+ST25R3911_FIFO_DEPTH) /*!< ST25R3911 communication buffer: CMD + FIFO length   */
00092 
00093 
00094 class ST25R3911 {
00095     public:
00096 //  ST25R3911();
00097     /* API to comunicate with ST253911 */
00098     void readRegister(uint8_t reg, uint8_t* val, SPI* mspiChannel, DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00099     void writeRegister(uint8_t reg, uint8_t val, SPI* mspiChannel,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00100     void readMultipleRegisters(uint8_t reg, uint8_t* values, uint8_t length, SPI* mspiChannel, ST25R3911* mST25,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00101     void writeMultipleRegisters(uint8_t reg, const uint8_t* values, uint8_t length, SPI* mspiChannel, ST25R3911* mST25,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00102     void executeCommand(uint8_t cmd, SPI* mspiChannel,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00103     void executeCommands(uint8_t* cmds, uint8_t length, ST25R3911* mST25, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00104     void writeFifo(const uint8_t* val, uint8_t length, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00105     void readFifo(uint8_t* buf, uint8_t length, SPI* mspiChannel, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00106 
00107 };
00108 
00109 
00110 
00111 /*
00112 ******************************************************************************
00113 * GLOBAL DATATYPES
00114 ******************************************************************************
00115 */
00116 
00117 
00118 
00119 
00120 
00121 /*! Parameters how the stream mode should work */
00122 struct st25r3911StreamConfig  {
00123     uint8_t useBPSK ; /*!< 0: subcarrier, 1:BPSK */
00124     uint8_t din ; /*!< the divider for the in subcarrier frequency: fc/2^din  */
00125     uint8_t dout ; /*!< the divider for the in subcarrier frequency fc/2^dout */
00126     uint8_t report_period_length ; /*!< the length of the reporting period 2^report_period_length*/
00127 };
00128 
00129 
00130 /*! ST25R3911 Wake-Up Period/Timer */
00131 typedef enum
00132 {
00133     ST25R3911_WUM_PERIDOD_10MS       = 0x00,     /*!< Wake-Up timer 10ms                          */
00134     ST25R3911_WUM_PERIDOD_20MS       = 0x01,     /*!< Wake-Up timer 20ms                          */
00135     ST25R3911_WUM_PERIDOD_30MS       = 0x02,     /*!< Wake-Up timer 30ms                          */
00136     ST25R3911_WUM_PERIDOD_40MS       = 0x03,     /*!< Wake-Up timer 40ms                          */
00137     ST25R3911_WUM_PERIDOD_50MS       = 0x04,     /*!< Wake-Up timer 50ms                          */
00138     ST25R3911_WUM_PERIDOD_60MS       = 0x05,     /*!< Wake-Up timer 60ms                          */
00139     ST25R3911_WUM_PERIDOD_70MS       = 0x06,     /*!< Wake-Up timer 70ms                          */
00140     ST25R3911_WUM_PERIDOD_80MS       = 0x07,     /*!< Wake-Up timer 80ms                          */
00141     ST25R3911_WUM_PERIDOD_100MS      = 0x10,     /*!< Wake-Up timer 100ms                         */
00142     ST25R3911_WUM_PERIDOD_200MS      = 0x11,     /*!< Wake-Up timer 200ms                         */
00143     ST25R3911_WUM_PERIDOD_300MS      = 0x12,     /*!< Wake-Up timer 300ms                         */
00144     ST25R3911_WUM_PERIDOD_400MS      = 0x13,     /*!< Wake-Up timer 400ms                         */
00145     ST25R3911_WUM_PERIDOD_500MS      = 0x14,     /*!< Wake-Up timer 500ms                         */
00146     ST25R3911_WUM_PERIDOD_600MS      = 0x15,     /*!< Wake-Up timer 600ms                         */
00147     ST25R3911_WUM_PERIDOD_700MS      = 0x16,     /*!< Wake-Up timer 700ms                         */
00148     ST25R3911_WUM_PERIDOD_800MS      = 0x17,     /*!< Wake-Up timer 800ms                         */
00149 } st25r3911WumPeriod ;
00150 
00151 
00152 /*! ST25R3911 Wake-Up Period/Timer */
00153 typedef enum
00154 {
00155     ST25R3911_WUM_AA_WEIGHT_4        = 0x00,     /*!< Wake-Up Auto Average Weight 4                */
00156     ST25R3911_WUM_AA_WEIGHT_8        = 0x01,     /*!< Wake-Up Auto Average Weight 8                */
00157     ST25R3911_WUM_AA_WEIGHT_16       = 0x02,     /*!< Wake-Up Auto Average Weight 16               */
00158     ST25R3911_WUM_AA_WEIGHT_32       = 0x03,     /*!< Wake-Up Auto Average Weight 32               */
00159 } st25r3911WumAAWeight ;
00160 
00161 
00162 /*! ST25R3911 Wake-Up Mode configuration */
00163 typedef struct
00164 {
00165     st25r3911WumPeriod         period ;     /*!< Wake-Up Timer period;how often measurement(s) is performed*/
00166     bool                      irqTout ;    /*!< IRQ at every timeout will refresh the measurement(s)      */
00167 
00168     struct{
00169         bool                  enabled ;    /*!< Inductive Amplitude measurement enabled                  */
00170         uint8_t               delta ;      /*!< Delta between the reference and measurement to wake-up   */
00171         uint8_t               reference ;  /*!< Reference to be used; or ST25R3911_WUM_REFRENCE_AUTO     */
00172         bool                  autoAvg ;    /*!< Use the HW Auto Averaging feature                        */
00173         bool                  aaInclMeas ; /*!< When AutoAvg is enables, include IRQ measurement         */
00174         st25r3911WumAAWeight   aaWeight ;   /*!< When AutoAvg is enables, last measure weight             */
00175     }indAmp;
00176     struct{
00177         bool                  enabled;    /*!< Inductive Phase measurement enabled                      */
00178         uint8_t               delta;      /*!< Delta between the reference and measurement to wake-up   */
00179         uint8_t               reference;  /*!< Reference to be used; or ST25R3911_WUM_REFRENCE_AUTO     */
00180         bool                  autoAvg;    /*!< Use the HW Auto Averaging feature                        */
00181         bool                  aaInclMeas; /*!< When AutoAvg is enables, include IRQ measurement         */
00182         st25r3911WumAAWeight   aaWeight;   /*!< When AutoAvg is enables, last measure weight             */
00183     }indPha;
00184     struct{
00185         bool                  enabled;    /*!< Capacitive measurement enabled                           */
00186         uint8_t               delta;      /*!< Delta between the reference and measurement to wake-up   */
00187         uint8_t               reference;  /*!< Reference to be used; or ST25R3911_WUM_REFRENCE_AUTO     */
00188         bool                  autoAvg;    /*!< Use the HW Auto Averaging feature                        */
00189         bool                  aaInclMeas; /*!< When AutoAvg is enables, include IRQ measurement         */
00190         st25r3911WumAAWeight   aaWeight;   /*!< When AutoAvg is enables, last measure weight             */
00191     }cap;
00192 } st25r3911WakeUpConfig ;
00193 
00194 
00195 /*
00196 ******************************************************************************
00197 * GLOBAL DEFINES
00198 ******************************************************************************
00199 */
00200 #define ST25R3911_FDT_NONE                     0x00    /*!< Value indicating not to perform FDT  */
00201 
00202 #define MS_TO_64FCS(A)               ((A) * 212)    /*!< Converts from ms to 64/fc steps      */
00203 #define MS_FROM_64FCS(A)             ((A) / 212)    /*!< Converts from 64/fc steps to ms      */
00204 
00205 /* ST25R3911 direct commands */
00206 #define ST25R3911_CMD_SET_DEFAULT              0xC1    /*!< Puts the chip in default state (same as after power-up) */
00207 #define ST25R3911_CMD_CLEAR_FIFO               0xC2    /*!< Stops all activities and clears FIFO */
00208 #define ST25R3911_CMD_TRANSMIT_WITH_CRC        0xC4    /*!< Transmit with CRC */
00209 #define ST25R3911_CMD_TRANSMIT_WITHOUT_CRC     0xC5    /*!< Transmit without CRC */
00210 #define ST25R3911_CMD_TRANSMIT_REQA            0xC6    /*!< Transmit REQA */
00211 #define ST25R3911_CMD_TRANSMIT_WUPA            0xC7    /*!< Transmit WUPA */
00212 #define ST25R3911_CMD_INITIAL_RF_COLLISION     0xC8    /*!< NFC transmit with Initial RF Collision Avoidance */
00213 #define ST25R3911_CMD_RESPONSE_RF_COLLISION_N  0xC9    /*!< NFC transmit with Response RF Collision Avoidance */
00214 #define ST25R3911_CMD_RESPONSE_RF_COLLISION_0  0xCA    /*!< NFC transmit with Response RF Collision Avoidance with n=0 */
00215 #define ST25R3911_CMD_NORMAL_NFC_MODE          0xCB    /*!< NFC switch to normal NFC mode */
00216 #define ST25R3911_CMD_ANALOG_PRESET            0xCC    /*!< Analog Preset */
00217 #define ST25R3911_CMD_MASK_RECEIVE_DATA        0xD0    /*!< Mask recive data */
00218 #define ST25R3911_CMD_UNMASK_RECEIVE_DATA      0xD1    /*!< Unmask recive data */
00219 #define ST25R3911_CMD_MEASURE_AMPLITUDE        0xD3    /*!< Measure singal amplitude on RFI inputs */
00220 #define ST25R3911_CMD_SQUELCH                  0xD4    /*!< Squelch */
00221 #define ST25R3911_CMD_CLEAR_SQUELCH            0xD5    /*!< Clear Squelch */
00222 #define ST25R3911_CMD_ADJUST_REGULATORS        0xD6    /*!< Adjust regulators */
00223 #define ST25R3911_CMD_CALIBRATE_MODULATION     0xD7    /*!< Calibrate modulation depth */
00224 #define ST25R3911_CMD_CALIBRATE_ANTENNA        0xD8    /*!< Calibrate antenna */
00225 #define ST25R3911_CMD_MEASURE_PHASE            0xD9    /*!< Measure phase between RFO and RFI signal */
00226 #define ST25R3911_CMD_CLEAR_RSSI               0xDA    /*!< clear RSSI bits and restart the measurement */
00227 #define ST25R3911_CMD_TRANSPARENT_MODE         0xDC    /*!< Transparent mode */
00228 #define ST25R3911_CMD_CALIBRATE_C_SENSOR       0xDD    /*!< Calibrate the capacitive sensor */
00229 #define ST25R3911_CMD_MEASURE_CAPACITANCE      0xDE    /*!< Measure capacitance */
00230 #define ST25R3911_CMD_MEASURE_VDD              0xDF    /*!< Measure power supply voltage */
00231 #define ST25R3911_CMD_START_GP_TIMER           0xE0    /*!< Start the general purpose timer */
00232 #define ST25R3911_CMD_START_WUP_TIMER          0xE1    /*!< Start the wake-up timer */
00233 #define ST25R3911_CMD_START_MASK_RECEIVE_TIMER 0xE2    /*!< Start the mask-receive timer */
00234 #define ST25R3911_CMD_START_NO_RESPONSE_TIMER  0xE3    /*!< Start the no-repsonse timer */
00235 #define ST25R3911_CMD_TEST_CLEARA              0xFA    /*!< Clear Test register */
00236 #define ST25R3911_CMD_TEST_CLEARB              0xFB    /*!< Clear Test register */
00237 #define ST25R3911_CMD_TEST_ACCESS              0xFC    /*!< Enable R/W access to the test registers */
00238 #define ST25R3911_CMD_LOAD_PPROM               0xFD    /*!< Load data from the poly fuses to RAM */
00239 #define ST25R3911_CMD_FUSE_PPROM               0xFE    /*!< Fuse poly fuses with data from the RAM */
00240 
00241 
00242 #define ST25R3911_FIFO_DEPTH                   96      /*!< Depth of FIFO                            */
00243 
00244 #define ST25R3911_THRESHOLD_DO_NOT_SET         0xFF    /*!< Indicates not to change this Threshold   */
00245 
00246 #define ST25R3911_BR_DO_NOT_SET                0xFF    /*!< Indicates not to change this Bit Rate    */
00247 #define ST25R3911_BR_106                       0x00    /*!< ST25R3911 Bit Rate 106 kbit/s (fc/128)   */
00248 #define ST25R3911_BR_212                       0x01    /*!< ST25R3911 Bit Rate 212 kbit/s (fc/64)    */
00249 #define ST25R3911_BR_424                       0x02    /*!< ST25R3911 Bit Rate 424 kbit/s (fc/32)    */
00250 #define ST25R3911_BR_848                       0x03    /*!< ST25R3911 Bit Rate 848 kbit/s (fc/16)    */
00251 #define ST25R3911_BR_1695                      0x04    /*!< ST25R3911 Bit Rate 1696 kbit/s (fc/8)    */
00252 #define ST25R3911_BR_3390                      0x05    /*!< ST25R3911 Bit Rate 3390 kbit/s (fc/4)    */
00253 #define ST25R3911_BR_6780                      0x06    /*!< ST25R3911 Bit Rate 6780 kbit/s (fc/2)    */
00254 
00255 
00256 #define ST25R3911_WUM_REFRENCE_AUTO            0xFF    /*!< Indicates new reference is set by the driver   */
00257 #define ST25R3911_WUM_WAKEMASK_INDAMP          0x01    /*!< Wake-Up mode was woken by Inductive Amplitude  */
00258 #define ST25R3911_WUM_WAKEMASK_INDPHA          0x02    /*!< Wake-Up mode was woken by Inductive Phase      */
00259 #define ST25R3911_WUM_WAKEMASK_CAP             0x04    /*!< Wake-Up mode was woken by Capacitive           */
00260 
00261 /*
00262 ******************************************************************************
00263 * GLOBAL MACROS
00264 ******************************************************************************
00265 */
00266 
00267 /*! Checks if General Purpose Timer is still running by reading gpt_on flag */
00268 #define st25r3911IsGPTRunning( )     ( st25r3911CheckReg(ST25R3911_REG_REGULATOR_RESULT, ST25R3911_REG_REGULATOR_RESULT_gpt_on, ST25R3911_REG_REGULATOR_RESULT_gpt_on) )
00269 
00270 /*! Checks if CRC is configured to be in FIFO                               */
00271 #define st25r3911IsCRCinFIFO( )      ( st25r3911CheckReg(ST25R3911_REG_AUX, ST25R3911_REG_AUX_crc_2_fifo, ST25R3911_REG_AUX_crc_2_fifo) )
00272 
00273 /*! Checks if External Filed is detected by reading ST25R3911 External Field
00274  * Detector output                                                          */
00275 #define st25r3911IsExtFieldOn()      ( st25r3911CheckReg(ST25R3911_REG_AUX_DISPLAY, ST25R3911_REG_AUX_DISPLAY_efd_o, ST25R3911_REG_AUX_DISPLAY_efd_o ) )
00276 
00277 /*! Checks if Transmitter is enabled (Field On) */
00278 #define st25r3911IsTxEnabled()       ( st25r3911CheckReg(ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_tx_en, ST25R3911_REG_OP_CONTROL_tx_en ) )
00279 
00280 /*! Turn Off Tx (Field Off) */
00281 #define st25r3911TxOff()              st25r3911ClrRegisterBits(ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_tx_en );
00282 
00283 /*! Checks if last FIFO byte is complete */
00284 #define st25r3911IsLastFIFOComplete() st25r3911CheckReg( ST25R3911_REG_FIFO_RX_STATUS2, ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb, 0 )
00285 
00286 /*! Checks if the Oscillator is enabled  */
00287 #define st25r3911IsOscOn()            st25r3911CheckReg( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_en, ST25R3911_REG_OP_CONTROL_en )
00288 
00289 /*
00290 ******************************************************************************
00291 * GLOBAL FUNCTION PROTOTYPES
00292 ******************************************************************************
00293 */
00294 
00295 /*!
00296  *****************************************************************************
00297  *  \brief  Turn on Oscillator and Regulator
00298  *
00299  *  This function turn on oscillator and regulator and wait for the oscillator to
00300  *  become stable.
00301  *
00302  *****************************************************************************
00303  */
00304 extern void st25r3911OscOn( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00305 
00306 /*!
00307  *****************************************************************************
00308  *  \brief  Turn On Tx and Rx
00309  *
00310  *  This function turns On Tx and Rx (Field On)
00311  *
00312  *****************************************************************************
00313  */
00314 extern void st25r3911TxRxOn( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00315 
00316 /*!
00317  *****************************************************************************
00318  *  \brief  Turn Off Tx and Rx
00319  *
00320  *  This function turns Off Tx and Rx (Field Off)
00321  *
00322  *****************************************************************************
00323  */
00324 extern void st25r3911TxRxOff( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00325 
00326 /*!
00327  *****************************************************************************
00328  *  \brief  Initialise ST25R3911 driver
00329  *
00330  *  This function initialises the ST25R3911 driver.
00331  *
00332  *****************************************************************************
00333  */
00334 extern void st25r3911Initialize( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00335 
00336 /*!
00337  *****************************************************************************
00338  *  \brief  Deinitialize ST25R3911 driver
00339  *
00340  *  Calling this function deinitializes the ST25R3911 driver.
00341  *
00342  *****************************************************************************
00343  */
00344 extern void st25r3911Deinitialize( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00345 
00346 
00347 /*!
00348  *****************************************************************************
00349  *  \brief  Sets the bitrate registers
00350  *
00351  *  This function sets the bitrate register for rx and tx
00352  *
00353  *  \param txRate : speed is 2^txrate * 106 kb/s
00354  *                  0xff : don't set txrate
00355  *  \param rxRate : speed is 2^rxrate * 106 kb/s
00356  *                  0xff : don't set rxrate
00357  *
00358  *  \return ERR_NONE : No error, both bit rates were set
00359  *  \return ERR_PARAM: At least one bit rate was invalid
00360  *
00361  *****************************************************************************
00362  */
00363 extern ReturnCode st25r3911SetBitrate(uint8_t txRate, uint8_t rxRate,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00364 
00365 /*!
00366  *****************************************************************************
00367  *  \brief  Adjusts supply regulators according to the current supply voltage
00368  *
00369  *  This function the power level is measured in maximum load conditions and
00370  *  the regulated voltage reference is set to 250mV below this level.
00371  *  Execution of this function lasts arround 5ms.
00372  *
00373  *  \param [out] result_mV : Result of calibration in milliVolts.
00374  *
00375  *  \return ERR_REQUEST : Adjustment not possible since reg_s bit is set.
00376  *  \return ERR_IO : Error during communication with ST25R3911.
00377  *  \return ERR_NONE : No error.
00378  *
00379  *****************************************************************************
00380  */
00381 extern ReturnCode st25r3911AdjustRegulators(uint16_t* result_mV, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00382 
00383 /*!
00384  *****************************************************************************
00385  *  \brief  Measure RF
00386  *
00387  *  This function measured the amplitude on the RFI inputs and stores the
00388  *  result in parameter \a result.
00389  *
00390  *  \param[out] result: 8 bit long result of RF measurement.
00391  *
00392  *****************************************************************************
00393  */
00394 extern void st25r3911MeasureRF(uint8_t* result,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00395 
00396 /*!
00397  *****************************************************************************
00398  *  \brief  Measure Capacitance
00399  *
00400  *  This function performs the capacitance measurement and stores the
00401  *  result in parameter \a result.
00402  *
00403  *  \param[out] result: 8 bit long result of RF measurement.
00404  *
00405  *****************************************************************************
00406  */
00407 extern void st25r3911MeasureCapacitance(uint8_t* result, SPI *mspiChannel,  DigitalOut * gpio_cs);
00408 
00409 /*!
00410  *****************************************************************************
00411  *  \brief  Measure Voltage
00412  *
00413  *  This function measures the voltage on one of VDD and VSP_*
00414  *  result in parameter \a result.
00415  *
00416  *  \param[in] mpsv : one of ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd
00417  *                           ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf
00418  *                           ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a
00419  *                    or     ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d
00420  *
00421  *  \return the measured voltage in mV
00422  *
00423  *****************************************************************************
00424  */
00425 extern uint16_t st25r3911MeasureVoltage(uint8_t mpsv,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00426 
00427 /*!
00428  *****************************************************************************
00429  *  \brief  Calibrate antenna
00430  *
00431  *  This function is used to calibrate the antenna using a special sequence.
00432  *  The result is stored in the \a result parameter.
00433  *
00434  *  \param[out] result: 8 bit long result of antenna calibration algorithm.
00435  *
00436  *****************************************************************************
00437  */
00438 extern void st25r3911CalibrateAntenna(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00439 
00440 /*!
00441  *****************************************************************************
00442  *  \brief  Check antenna resonance
00443  *
00444  *  This function is used to measure the antenna LC tank resconance to determine
00445  *  whether a calibration is needed.
00446  *  The result is stored in the \a result parameter.
00447  *
00448  *  \param[out] result: 8 bit long result of the measurement.
00449  *
00450  *****************************************************************************
00451  */
00452 extern void st25r3911MeasureAntennaResonance(uint8_t* result, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00453 
00454 /*!
00455  *****************************************************************************
00456  *  \brief  Calibrate modulation depth
00457  *
00458  *  This function is used to calibrate the modulation depth using a special sequence.
00459  *  The result is stored in the \a result parameter.
00460  *
00461  *  \param[out] result: 8 bit long result of antenna calibration algorithm.
00462  *
00463  *****************************************************************************
00464  */
00465 extern void st25r3911CalibrateModulationDepth(uint8_t* result, SPI *mspiChannel,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00466 
00467 
00468 /*!
00469  *****************************************************************************
00470  *  \brief  Calibrate Capacitive Sensor
00471  *
00472  *  This function is used to calibrates the Capacitive Sensor.
00473  *  The result is stored in the \a result parameter.
00474  *
00475  *  \param[out] result: 8 bit long result of antenna calibration algorithm.
00476  *
00477  *****************************************************************************
00478  */
00479 extern void st25r3911CalibrateCapacitiveSensor(uint8_t* result, SPI *mspiChannel,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00480 
00481 /*!
00482  *****************************************************************************
00483  *  \brief  set no response time
00484  *
00485  *  This function executes sets the no response time to the defines value
00486  *
00487  *  \param nrt_64fcs : no response time in 64/fc = 4.72us
00488  *                    completion interrupt
00489  *
00490  *  \return ERR_PARAM : if time is too large
00491  */
00492 extern ReturnCode st25r3911SetNoResponseTime_64fcs(uint32_t nrt_64fcs, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00493 
00494 /*!
00495  *****************************************************************************
00496  *  \brief  set no response time
00497  *
00498  *  This function executes sets and immediately start the no response timer
00499  *   to the defines value
00500  *   This is used when needs to add more time before timeout whitout Tx
00501  *
00502  *  \param nrt_64fcs : no response time in 64/fc = 4.72us
00503  *                    completion interrupt
00504  *
00505  *  \return ERR_PARAM : if time is too large
00506  */
00507 extern ReturnCode st25r3911SetStartNoResponseTime_64fcs(uint32_t nrt_64fcs,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_06);
00508 
00509 /*!
00510  *****************************************************************************
00511  *  \brief  Perform Collision Avoidance
00512  *
00513  *  Performs Collision Avoidance with the given threshold and with the
00514  *  n number of TRFW
00515  *
00516  *  \param[in] FieldONCmd  : Field ON command to be executed ST25R3911_CMD_INITIAL_RF_COLLISION
00517  *                           or ST25R3911_CMD_RESPONSE_RF_COLLISION_0/N
00518  *  \param[in] pdThreshold : Peer Detection Threshold  (ST25R3916_REG_FIELD_THRESHOLD_trg_xx)
00519  *                           0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
00520  *  \param[in] caThreshold : Collision Avoidance Threshold (ST25R3916_REG_FIELD_THRESHOLD_rfe_xx)
00521  *                           0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
00522  *  \param[in] nTRFW       : Number of TRFW
00523  *
00524  *  \return ERR_NONE : no collision detected
00525  *  \return ERR_RF_COLLISION : collision detected
00526  */
00527 extern ReturnCode st25r3911PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00528 
00529 
00530 /*!
00531  *****************************************************************************
00532  *  \brief  Get amount of bits of the last FIFO byte if incomplete
00533  *
00534  *  Gets the number of bits of the last FIFO byte if incomplete
00535  *
00536  *  \return the number of bits of the last FIFO byte if incomplete, 0 if
00537  *          the last byte is complete
00538  *
00539  *****************************************************************************
00540  */
00541 extern uint8_t st25r3911GetNumFIFOLastBits( void );
00542 
00543 /*!
00544  *****************************************************************************
00545  *  \brief  Get NRT time
00546  *
00547  *  This returns the last value set on the NRT
00548  *
00549  *  \warning it does not reads chip register, just the sw var that contains the
00550  *  last value set before
00551  *
00552  *  \return the value of the NRT
00553  */
00554 extern uint32_t st25r3911GetNoResponseTime_64fcs(void);
00555 
00556 /*!
00557  *****************************************************************************
00558  *  \brief  set general purpose timer timeout
00559  *
00560  *  This function sets the proper registers but does not start the timer actually
00561  *
00562  *  \param gpt_8fcs : general purpose timer timeout in 8/fc = 590ns
00563  *
00564  */
00565 extern void st25r3911SetGPTime_8fcs(uint16_t gpt_8fcs,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00566 /*!
00567  *****************************************************************************
00568  *  \brief  Starts GPT with given timeout
00569  *
00570  *  This function starts the general purpose timer with the given timeout
00571  *
00572  *  \param gpt_8fcs : general purpose timer timeout in 8/fc = 590ns
00573  *  \param trigger_source : no trigger, start of Rx, end of Rx, end of Tx in NFC mode
00574  */
00575 extern void st25r3911StartGPTimer_8fcs(uint16_t gpt_8fcs, uint8_t trigger_source, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00576 
00577 /*!
00578  *****************************************************************************
00579  *  \brief  Checks if register contains a expected value
00580  *
00581  *  This function checks if the given reg contains a value that once masked
00582  *  equals the expected value
00583  *
00584  *  \param reg  : the register to check the value
00585  *  \param mask : the mask apply on register value
00586  *  \param val  : expected value to be compared to
00587  *
00588  *  \return  true when reg contains the expected value | false otherwise
00589  */
00590 bool st25r3911CheckReg( uint8_t reg, uint8_t mask, uint8_t val,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00591 
00592 /*!
00593  *****************************************************************************
00594  *  \brief  Sets the number Tx Bits
00595  *
00596  *  Sets ST25R3911 internal registers with correct number of complete bytes and
00597  *  bits to be sent
00598  *
00599  *  \param nBits : the number bits to be transmitted
00600  *****************************************************************************
00601  */
00602 void st25r3911SetNumTxBits( uint32_t nBits,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00603 
00604 /*!
00605  *****************************************************************************
00606  *  \brief  Check Identity
00607  *
00608  *  Checks if the chip ID is as expected.
00609  *
00610  *  5 bit IC type code for ST25R3911: 00001
00611  *  The 3 lsb contain the IC revision code
00612  *
00613  *
00614  *  \param[out] rev  : the IC revision code
00615  *
00616  *  \return  true when IC type is as expected
00617  *
00618  *****************************************************************************
00619  */
00620 bool st25r3911CheckChipID( uint8_t *rev,SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00621 
00622 /*!
00623  *****************************************************************************
00624  *  \brief  Check if command is valid
00625  *
00626  *  Checks if the given command is a valid ST25R3911 command
00627  *
00628  *  \param[in] cmd: Command to check
00629  *
00630  *  \return  true if is a valid command
00631  *  \return  false otherwise
00632  *
00633  *****************************************************************************
00634  */
00635 bool st25r3911IsCmdValid( uint8_t cmd );
00636 
00637 /*!
00638  *****************************************************************************
00639  *  \brief  Configure the stream mode of ST25R3911
00640  *
00641  *  This function initializes the stream with the given parameters
00642  *
00643  *  \param[in] config : all settings for bitrates, type, etc.
00644 
00645  *  \return ERR_NONE : No error, stream mode driver initialized.
00646  *
00647  *****************************************************************************
00648  */
00649 extern ReturnCode st25r3911StreamConfigure(const struct st25r3911StreamConfig  *config, SPI* mspiChannel, ST25R3911* mST25,  DigitalOut * gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00650 
00651 /*!
00652  *****************************************************************************
00653  *  \brief  Retrieves all  internal registers from st25r3911
00654  */
00655 extern ReturnCode st25r3911GetRegsDump(uint8_t* resRegDump, uint8_t* sizeRegDump, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00656 
00657 
00658 /*!
00659  *****************************************************************************
00660  *  \brief  Cheks if a Wakeup IRQ due to Capacitive measument has happen
00661  */
00662 extern bool st25r3911IrqIsWakeUpCap( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00663 
00664 
00665 /*!
00666  *****************************************************************************
00667  *  \brief  Cheks if a Wakeup IRQ due to Phase measument has happen
00668  */
00669 extern bool st25r3911IrqIsWakeUpPhase( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00670 
00671 
00672 /*!
00673  *****************************************************************************
00674  *  \brief  Cheks if a Wakeup IRQ due to Amplitude measument has happen
00675  */
00676 extern bool st25r3911IrqIsWakeUpAmplitude( SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 );
00677 
00678 #endif /* ST25R3911_H */
00679 
00680 /**
00681   * @}
00682   *
00683   * @}
00684   *
00685   * @}
00686   *
00687   * @}
00688   */
00689