/******************************************************************************
* @attention
*
* <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.st.com/myliberty
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* $Revision: $
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief RF Abstraction Layer (RFAL)
*
* RFAL implementation for ST25R3911
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_rf.h"
#include "utils.h"
#include "st25r3911.h"
#include "st25r3911_com.h"
#include "st25r3911_interrupt.h"
#include "rfal_analogConfig.h"
#include "rfal_iso15693_2.h"
#include "Type.h"
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! Struct that holds all involved on a Transceive including the context passed by the caller */
typedef struct{
rfalTransceiveState state; /*!< Current transceive state */
rfalTransceiveState lastState; /*!< Last transceive state (debug purposes) */
ReturnCode status; /*!< Current status/error of the transceive */
bool rxse; /*!< Flag indicating if RXE was received with RXS */
rfalTransceiveContext ctx; /*!< The transceive context given by the caller */
} rfalTxRx;
/*! Struct that holds all context for the Listen Mode */
typedef struct{
rfalLmState state; /*!< Current Listen Mode state */
rfalBitRate brDetected; /*!< Last bit rate detected */
uint8_t* rxBuf; /*!< Location to store incoming data in Listen Mode */
uint16_t rxBufLen; /*!< Length of rxBuf */
uint16_t* rxLen; /*!< Pointer to write the data length placed into rxBuf */
bool dataFlag; /*!< Listen Mode current Data Flag */
} rfalLm;
/*! Struct that holds all context for the Wake-Up Mode */
typedef struct{
rfalWumState state; /*!< Current Wake-Up Mode state */
rfalWakeUpConfig cfg; /*!< Current Wake-Up Mode context */
} rfalWum;
/*! Struct that holds the timings GT and FDTs */
typedef struct{
uint32_t GT; /*!< GT in 1/fc */
uint32_t FDTListen; /*!< FDTListen in 1/fc */
uint32_t FDTPoll; /*!< FDTPoll in 1/fc */
} rfalTimings;
/*! Struct that holds the software timers */
typedef struct{
uint32_t GT; /*!< RFAL's GT timer */
uint32_t FWT; /*!< FWT/RWT timer for Active P2P*/
uint32_t RXE; /*!< Timer between RXS and RXE */
} rfalTimers;
/*! Struct that holds the RFAL's callbacks */
typedef struct{
rfalPreTxRxCallback preTxRx; /*!< RFAL's Pre TxRx callback */
rfalPostTxRxCallback postTxRx; /*!< RFAL's Post TxRx callback */
} rfalCallbacks;
/*! Struct that holds counters to control the FIFO on Tx and Rx */
typedef struct{
uint16_t expWL; /*!< The amount of bytes expected to be Tx when a WL interrupt occours */
uint16_t bytesTotal; /*!< Total bytes to be transmitted OR the total bytes received */
uint16_t bytesWritten;/*!< Amount of bytes already written on FIFO (Tx) OR read (RX) from FIFO and written on rxBuffer*/
uint8_t status[ST25R3911_FIFO_STATUS_LEN]; /*!< FIFO Status Registers */
} rfalFIFO;
/*! Struct that holds RFAL's configuration settings */
typedef struct{
uint8_t obsvModeTx; /*!< RFAL's config of the ST25R3911's observation mode while Tx */
uint8_t obsvModeRx; /*!< RFAL's config of the ST25R3911's observation mode while Rx */
rfalEHandling eHandling; /*!< RFAL's error handling config/mode */
} rfalConfigs;
/*! Struct that holds NFC-F data - Used only inside rfalFelicaPoll() (static to avoid adding it into stack) */
typedef struct{
rfalFeliCaPollRes pollResponses[RFAL_FELICA_POLL_MAX_SLOTS]; /* FeliCa Poll response container for 16 slots */
} rfalNfcfWorkingData;
/*! Struct that holds NFC-V current context
*
* 96 bytes is FIFO size of ST25R3911, codingBuffer has to be big enough for coping with maximum response size (Manchester coded)
* - current implementation expects it be written in one bulk into FIFO
* - needs to be above FIFO water level of ST25R3911 (64)
* - 65 is actually 1 byte too much, but ~75us in 1of256 another byte is already gone
*
* - inventory requests responses: 14 bytes
* - Max read single block responses: 32 bytes
* - Read multiple block responses: variable
*
* ISO15693 frame: SOF + Flags + Data + CRC + EOF
*/
typedef struct{
uint8_t codingBuffer[((2 + 255 + 3)*2)];/*!< Coding buffer, length MUST be above 64: [65; ...] */
uint16_t nfcvOffset; /*!< Offset needed for ISO15693 coding function */
rfalTransceiveContext origCtx; /*!< Context provided by user */
uint16_t ignoreBits; /*!< Number of bits at the beginning of a frame to be ignored when decoding */
} rfalNfcvWorkingData;
/*! RFAL instance */
typedef struct{
rfalState state; /*!< RFAL's current state */
rfalMode mode; /*!< RFAL's current mode */
rfalBitRate txBR; /*!< RFAL's current Tx Bit Rate */
rfalBitRate rxBR; /*!< RFAL's current Rx Bit Rate */
bool field; /*!< Current field state (On / Off) */
rfalConfigs conf; /*!< RFAL's configuration settings */
rfalTimings timings; /*!< RFAL's timing setting */
rfalTxRx TxRx; /*!< RFAL's transceive management */
rfalLm Lm; /*!< RFAL's listen mode management */
rfalWum