NFC: application + rfal + driver.

This commit is contained in:
Aleksandr Kutuzov
2020-10-19 01:09:48 +03:00
parent 13608cee9e
commit 4c9eb4928d
72 changed files with 42732 additions and 24 deletions

View File

@@ -0,0 +1,594 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_analogConfig.h
*
* \author bkam
*
* \brief ST25R3916 Analog Configuration Settings
*
*/
#ifndef ST25R3916_ANALOGCONFIG_H
#define ST25R3916_ANALOGCONFIG_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_analogConfig.h"
#include "st25r3916_com.h"
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Macro for Configuration Setting with only one register-mask-value set:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1] */
#define MODE_ENTRY_1_REG(MODE, R0, M0, V0) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 1, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0)
/*! Macro for Configuration Setting with only two register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1] */
#define MODE_ENTRY_2_REG(MODE, R0, M0, V0, R1, M1, V1) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 2, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1)
/*! Macro for Configuration Setting with only three register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_3_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 3, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2)
/*! Macro for Configuration Setting with only four register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_4_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 4, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3)
/*! Macro for Configuration Setting with only five register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_5_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 5, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4)
/*! Macro for Configuration Setting with only six register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_6_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 6, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5)
/*! Macro for Configuration Setting with only seven register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_7_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 7, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6)
/*! Macro for Configuration Setting with only eight register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_8_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 8, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8U), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7)
/*! Macro for Configuration Setting with only nine register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_9_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU), 9, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8U), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8U), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8)
/*! Macro for Configuration Setting with only ten register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_10_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU),10, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8U), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8U), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8U), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9)
/*! Macro for Configuration Setting with eleven register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_11_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU),11, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8U), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8U), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8U), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8U), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10)
/*! Macro for Configuration Setting with twelve register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_12_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU),12, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8U), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8U), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8U), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8U), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((uint16_t)(R11) >> 8U), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11)
/*! Macro for Configuration Setting with thirteen register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_13_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12) \
(uint8_t)((uint16_t)(MODE) >> 8U), (uint8_t)((MODE) & 0xFFU),13, (uint8_t)((uint16_t)(R0) >> 8U), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8U), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8U), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8U), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8U), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8U), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8U), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8U), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8U), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8U), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8U), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((uint16_t)(R11) >> 8U), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
, (uint8_t)((uint16_t)(R12) >> 8U), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12)
/*! Macro for Configuration Setting with fourteen register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_14_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12, R13, M13, V13, R14, M14, V14, R15, M15, V15) \
(uint8_t)((uint16_t)(MODE) >> 8), (uint8_t)((MODE) & 0xFFU),14, (uint8_t)((uint16_t)(R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((uint16_t)(R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
, (uint8_t)((uint16_t)(R12) >> 8), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12) \
, (uint8_t)((uint16_t)(R13) >> 8), (uint8_t)((R13) & 0xFFU), (uint8_t)(M13), (uint8_t)(V13)
/*! Macro for Configuration Setting with fifteen register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_15_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12, R13, M13, V13, R14, M14, V14, R15, M15, V15) \
(uint8_t)((uint16_t)(MODE) >> 8), (uint8_t)((MODE) & 0xFFU),15, (uint8_t)((uint16_t)(R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((uint16_t)(R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
, (uint8_t)((uint16_t)(R12) >> 8), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12) \
, (uint8_t)((uint16_t)(R13) >> 8), (uint8_t)((R13) & 0xFFU), (uint8_t)(M13), (uint8_t)(V13) \
, (uint8_t)((uint16_t)(R14) >> 8), (uint8_t)((R14) & 0xFFU), (uint8_t)(M14), (uint8_t)(V14)
/*! Macro for Configuration Setting with sixteen register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_16_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12, R13, M13, V13, R14, M14, V14, R15, M15, V15) \
(uint8_t)((uint16_t)(MODE) >> 8), (uint8_t)((MODE) & 0xFFU),16, (uint8_t)((uint16_t)(R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((uint16_t)(R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
, (uint8_t)((uint16_t)(R12) >> 8), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12) \
, (uint8_t)((uint16_t)(R13) >> 8), (uint8_t)((R13) & 0xFFU), (uint8_t)(M13), (uint8_t)(V13) \
, (uint8_t)((uint16_t)(R14) >> 8), (uint8_t)((R14) & 0xFFU), (uint8_t)(M14), (uint8_t)(V14) \
, (uint8_t)((uint16_t)(R15) >> 8), (uint8_t)((R15) & 0xFFU), (uint8_t)(M15), (uint8_t)(V15)
/*! Macro for Configuration Setting with seventeen register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_17_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12, R13, M13, V13, R14, M14, V14, R15, M15, V15, R16, M16, V16) \
(uint8_t)((uint16_t)(MODE) >> 8), (uint8_t)((MODE) & 0xFFU),17, (uint8_t)((uint16_t)(R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((uint16_t)(R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((uint16_t)(R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((uint16_t)(R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((uint16_t)(R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((uint16_t)(R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((uint16_t)(R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((uint16_t)(R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((uint16_t)(R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((uint16_t)(R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((uint16_t)(R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((uint16_t)(R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
, (uint8_t)((uint16_t)(R12) >> 8), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12) \
, (uint8_t)((uint16_t)(R13) >> 8), (uint8_t)((R13) & 0xFFU), (uint8_t)(M13), (uint8_t)(V13) \
, (uint8_t)((uint16_t)(R14) >> 8), (uint8_t)((R14) & 0xFFU), (uint8_t)(M14), (uint8_t)(V14) \
, (uint8_t)((uint16_t)(R15) >> 8), (uint8_t)((R15) & 0xFFU), (uint8_t)(M15), (uint8_t)(V15) \
, (uint8_t)((uint16_t)(R16) >> 8), (uint8_t)((R16) & 0xFFU), (uint8_t)(M16), (uint8_t)(V16)
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
/* PRQA S 3406 1 # MISRA 8.6 - Externally generated table included by the library */ /* PRQA S 1514 1 # MISRA 8.9 - Externally generated table included by the library */
const uint8_t rfalAnalogConfigDefaultSettings[] = {
/****** Default Analog Configuration for Chip-Specific Reset ******/
MODE_ENTRY_17_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_INIT)
, ST25R3916_REG_IO_CONF1, (ST25R3916_REG_IO_CONF1_out_cl_mask | ST25R3916_REG_IO_CONF1_lf_clk_off), 0x07 /* Disable MCU_CLK */
, ST25R3916_REG_IO_CONF2, (ST25R3916_REG_IO_CONF2_miso_pd1 | ST25R3916_REG_IO_CONF2_miso_pd2 ), 0x18 /* SPI Pull downs */
, ST25R3916_REG_IO_CONF2, ST25R3916_REG_IO_CONF2_aat_en, ST25R3916_REG_IO_CONF2_aat_en /* Enable AAT */
, ST25R3916_REG_TX_DRIVER, ST25R3916_REG_TX_DRIVER_d_res_mask, 0x00 /* Set RFO resistance Active Tx */
, ST25R3916_REG_RES_AM_MOD, 0xFF, 0x80 /* Use minimum non-overlap */
, ST25R3916_REG_FIELD_THRESHOLD_ACTV, ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_mask, ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_105mV /* Lower activation threshold (higher than deactivation)*/
, ST25R3916_REG_FIELD_THRESHOLD_ACTV, ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_mask, ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_105mV /* Lower activation threshold (higher than deactivation)*/
, ST25R3916_REG_FIELD_THRESHOLD_DEACTV, ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_mask, ST25R3916_REG_FIELD_THRESHOLD_DEACTV_trg_75mV /* Lower deactivation threshold */
, ST25R3916_REG_FIELD_THRESHOLD_DEACTV, ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_mask, ST25R3916_REG_FIELD_THRESHOLD_DEACTV_rfe_75mV /* Lower deactivation threshold */
, ST25R3916_REG_AUX_MOD, ST25R3916_REG_AUX_MOD_lm_ext, 0x00 /* Disable External Load Modulation */
, ST25R3916_REG_AUX_MOD, ST25R3916_REG_AUX_MOD_lm_dri, ST25R3916_REG_AUX_MOD_lm_dri /* Use internal Load Modulation */
, ST25R3916_REG_PASSIVE_TARGET, ST25R3916_REG_PASSIVE_TARGET_fdel_mask, (5U<<ST25R3916_REG_PASSIVE_TARGET_fdel_shift) /* Adjust the FDT to be aligned with the bitgrid */
, ST25R3916_REG_PT_MOD, (ST25R3916_REG_PT_MOD_ptm_res_mask | ST25R3916_REG_PT_MOD_pt_res_mask), 0x5f /* Reduce RFO resistance in Modulated state */
, ST25R3916_REG_EMD_SUP_CONF, ST25R3916_REG_EMD_SUP_CONF_rx_start_emv, ST25R3916_REG_EMD_SUP_CONF_rx_start_emv_on /* Enable start on first 4 bits */
, ST25R3916_REG_ANT_TUNE_A, 0xFF, 0x82 /* Set Antenna Tuning (Poller): ANTL */
, ST25R3916_REG_ANT_TUNE_B, 0xFF, 0x82 /* Set Antenna Tuning (Poller): ANTL */
, 0x84U, 0x10, 0x10 /* Avoid chip internal overheat protection */
)
/****** Default Analog Configuration for Chip-Specific Poll Common ******/
, MODE_ENTRY_9_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
, ST25R3916_REG_TX_DRIVER, ST25R3916_REG_TX_DRIVER_am_mod_mask, ST25R3916_REG_TX_DRIVER_am_mod_12percent /* Set Modulation index */
, ST25R3916_REG_AUX_MOD, (ST25R3916_REG_AUX_MOD_dis_reg_am | ST25R3916_REG_AUX_MOD_res_am), 0x00 /* Use AM via regulator */
, ST25R3916_REG_ANT_TUNE_A, 0xFF, 0x82 /* Set Antenna Tuning (Poller): ANTL */
, ST25R3916_REG_ANT_TUNE_B, 0xFF, 0x82 /* Set Antenna Tuning (Poller): ANTL */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x00 /* Disable Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x00 /* Disable Undershoot Protection */
)
/****** Default Analog Configuration for Poll NFC-A Rx Common ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_correlator /* Use Correlator Receiver */
)
/****** Default Analog Configuration for Poll NFC-A Tx 106 ******/
, MODE_ENTRY_5_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am, ST25R3916_REG_MODE_tr_am_ook /* Use OOK */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x40 /* Set default Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x03 /* Set default Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x40 /* Set default Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x03 /* Set default Undershoot Protection */
)
/****** Default Analog Configuration for Poll NFC-A Rx 106 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x08
, ST25R3916_REG_RX_CONF2, 0xFF, 0x2D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x51
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-A Tx 212 ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
, ST25R3916_REG_AUX_MOD, (ST25R3916_REG_AUX_MOD_dis_reg_am | ST25R3916_REG_AUX_MOD_res_am), 0x88 /* Use Resistive AM */
, ST25R3916_REG_RES_AM_MOD, ST25R3916_REG_RES_AM_MOD_md_res_mask, 0x7F /* Set Resistive modulation */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x40 /* Set default Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x03 /* Set default Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x40 /* Set default Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x03 /* Set default Undershoot Protection */
)
/****** Default Analog Configuration for Poll NFC-A Rx 212 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x02
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x14
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-A Tx 424 ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
, ST25R3916_REG_AUX_MOD, (ST25R3916_REG_AUX_MOD_dis_reg_am | ST25R3916_REG_AUX_MOD_res_am), 0x88 /* Use Resistive AM */
, ST25R3916_REG_RES_AM_MOD, ST25R3916_REG_RES_AM_MOD_md_res_mask, 0x7F /* Set Resistive modulation */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x40 /* Set default Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x03 /* Set default Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x40 /* Set default Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x03 /* Set default Undershoot Protection */
)
/****** Default Analog Configuration for Poll NFC-A Rx 424 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x42
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x54
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-A Tx 848 ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
, ST25R3916_REG_TX_DRIVER, ST25R3916_REG_TX_DRIVER_am_mod_mask, ST25R3916_REG_TX_DRIVER_am_mod_40percent /* Set Modulation index */
, ST25R3916_REG_AUX_MOD, (ST25R3916_REG_AUX_MOD_dis_reg_am | ST25R3916_REG_AUX_MOD_res_am), 0x00 /* Use AM via regulator */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x00 /* Disable Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x00 /* Disable Undershoot Protection */
)
/****** Default Analog Configuration for Poll NFC-A Rx 848 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x42
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x44
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-A Anticolision setting ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_ANTICOL)
, ST25R3916_REG_CORR_CONF1, ST25R3916_REG_CORR_CONF1_corr_s6, 0x00 /* Set collision detection level different from data */
)
#ifdef RFAL_USE_COHE
/****** Default Analog Configuration for Poll NFC-B Rx Common ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_coherent /* Use Coherent Receiver */
)
#else
/****** Default Analog Configuration for Poll NFC-B Rx Common ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_correlator /* Use Correlator Receiver */
)
#endif /*RFAL_USE_COHE*/
/****** Default Analog Configuration for Poll NFC-B Rx 106 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x04
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x1B
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-B Rx 212 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x02
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x14
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-B Rx 424 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x42
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x54
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
/****** Default Analog Configuration for Poll NFC-B Rx 848 ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, 0xFF, 0x42
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x44
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
#ifdef RFAL_USE_COHE
/****** Default Analog Configuration for Poll NFC-F Rx Common ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_coherent /* Use Pulse Receiver */
, ST25R3916_REG_RX_CONF1, 0xFF, 0x13
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x54
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
#else
/****** Default Analog Configuration for Poll NFC-F Rx Common ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_correlator /* Use Correlator Receiver */
, ST25R3916_REG_RX_CONF1, 0xFF, 0x13
, ST25R3916_REG_RX_CONF2, 0xFF, 0x3D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x54
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x00
)
#endif /*RFAL_USE_COHE*/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_1OF4 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am, ST25R3916_REG_MODE_tr_am_ook /* Use OOK */
)
#ifdef RFAL_USE_COHE
/****** Default Analog Configuration for Poll NFC-V Rx Common ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_coherent /* Use Pulse Receiver */
, ST25R3916_REG_RX_CONF1, 0xFF, 0x13
, ST25R3916_REG_RX_CONF2, 0xFF, 0x2D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x13
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x01
)
#else
/****** Default Analog Configuration for Poll NFC-V Rx Common ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_AUX, ST25R3916_REG_AUX_dis_corr, ST25R3916_REG_AUX_dis_corr_correlator /* Use Correlator Receiver */
, ST25R3916_REG_RX_CONF1, 0xFF, 0x13
, ST25R3916_REG_RX_CONF2, 0xFF, 0x2D
, ST25R3916_REG_RX_CONF3, 0xFF, 0x00
, ST25R3916_REG_RX_CONF4, 0xFF, 0x00
, ST25R3916_REG_CORR_CONF1, 0xFF, 0x13
, ST25R3916_REG_CORR_CONF2, 0xFF, 0x01
)
#endif /*RFAL_USE_COHE*/
/****** Default Analog Configuration for Poll AP2P Tx 106 ******/
, MODE_ENTRY_5_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_ook /* Use OOK modulation */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x40 /* Set default Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x03 /* Set default Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x40 /* Set default Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x03 /* Set default Undershoot Protection */
)
/****** Default Analog Configuration for Poll AP2P Tx 212 ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
)
/****** Default Analog Configuration for Poll AP2P Tx 424 ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
)
/****** Default Analog Configuration for Chip-Specific Listen On ******/
, MODE_ENTRY_6_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON)
, ST25R3916_REG_ANT_TUNE_A, 0xFF, 0x00 /* Set Antenna Tuning (Listener): ANTL */
, ST25R3916_REG_ANT_TUNE_B, 0xFF, 0xff /* Set Antenna Tuning (Listener): ANTL */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x00 /* Disable Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x00 /* Disable Undershoot Protection */
)
/****** Default Analog Configuration for Listen AP2P Tx Common ******/
, MODE_ENTRY_7_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_ANT_TUNE_A, 0xFF, 0x82 /* Set Antenna Tuning (Poller): ANTL */
, ST25R3916_REG_ANT_TUNE_B, 0xFF, 0x82 /* Set Antenna Tuning (Poller): ANTL */
, ST25R3916_REG_TX_DRIVER, ST25R3916_REG_TX_DRIVER_am_mod_mask, ST25R3916_REG_TX_DRIVER_am_mod_12percent /* Set Modulation index */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x00 /* Disable Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x00 /* Disable Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x00 /* Disable Undershoot Protection */
)
/****** Default Analog Configuration for Listen AP2P Rx Common ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3916_REG_RX_CONF1, ST25R3916_REG_RX_CONF1_lp_mask, ST25R3916_REG_RX_CONF1_lp_1200khz /* Set Rx filter configuration */
, ST25R3916_REG_RX_CONF1, ST25R3916_REG_RX_CONF1_hz_mask, ST25R3916_REG_RX_CONF1_hz_12_200khz /* Set Rx filter configuration */
, ST25R3916_REG_RX_CONF2, ST25R3916_REG_RX_CONF2_amd_sel, ST25R3916_REG_RX_CONF2_amd_sel_mixer /* AM demodulator: mixer */
)
/****** Default Analog Configuration for Listen AP2P Tx 106 ******/
, MODE_ENTRY_5_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_ook /* Use OOK modulation */
, ST25R3916_REG_OVERSHOOT_CONF1, 0xFF, 0x40 /* Set default Overshoot Protection */
, ST25R3916_REG_OVERSHOOT_CONF2, 0xFF, 0x03 /* Set default Overshoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF1, 0xFF, 0x40 /* Set default Undershoot Protection */
, ST25R3916_REG_UNDERSHOOT_CONF2, 0xFF, 0x03 /* Set default Undershoot Protection */
)
/****** Default Analog Configuration for Listen AP2P Tx 212 ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
)
/****** Default Analog Configuration for Listen AP2P Tx 424 ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3916_REG_MODE, ST25R3916_REG_MODE_tr_am , ST25R3916_REG_MODE_tr_am_am /* Use AM modulation */
)
};
#endif /* ST25R3916_ANALOGCONFIG_H */

View File

@@ -0,0 +1,63 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2020 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: ST25R391x firmware
* $Revision: $
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Martin Zechleitner
*
* \brief RF Dynamic Power Table default values
*/
#ifndef ST25R3916_DPO_H
#define ST25R3916_DPO_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_dpo.h"
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
/*! Default DPO table */
const uint8_t rfalDpoDefaultSettings [] = {
0x00, 255, 200,
0x01, 210, 150,
0x02, 160, 100,
0x03, 110, 50,
};
#endif /* ST25R3916_DPO_H */

View File

@@ -0,0 +1,113 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief RFAL Features/Capabilities Definition for ST25R3916
*/
#ifndef RFAL_FEATURES_H
#define RFAL_FEATURES_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_SUPPORT_MODE_POLL_NFCA true /*!< RFAL Poll NFCA mode support switch */
#define RFAL_SUPPORT_MODE_POLL_NFCB true /*!< RFAL Poll NFCB mode support switch */
#define RFAL_SUPPORT_MODE_POLL_NFCF true /*!< RFAL Poll NFCF mode support switch */
#define RFAL_SUPPORT_MODE_POLL_NFCV true /*!< RFAL Poll NFCV mode support switch */
#define RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P true /*!< RFAL Poll AP2P mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_NFCA true /*!< RFAL Listen NFCA mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_NFCB false /*!< RFAL Listen NFCB mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_NFCF true /*!< RFAL Listen NFCF mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_ACTIVE_P2P true /*!< RFAL Listen AP2P mode support switch */
/*******************************************************************************/
/*! RFAL supported Card Emulation (CE) */
#define RFAL_SUPPORT_CE ( RFAL_SUPPORT_MODE_LISTEN_NFCA || RFAL_SUPPORT_MODE_LISTEN_NFCB || RFAL_SUPPORT_MODE_LISTEN_NFCF )
/*! RFAL supported Reader/Writer (RW) */
#define RFAL_SUPPORT_RW ( RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB || RFAL_SUPPORT_MODE_POLL_NFCF || RFAL_SUPPORT_MODE_POLL_NFCV )
/*! RFAL support for Active P2P (AP2P) */
#define RFAL_SUPPORT_AP2P ( RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P || RFAL_SUPPORT_MODE_LISTEN_ACTIVE_P2P )
/*******************************************************************************/
#define RFAL_SUPPORT_BR_RW_106 true /*!< RFAL RW 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_212 true /*!< RFAL RW 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_424 true /*!< RFAL RW 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_848 true /*!< RFAL RW 848 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_1695 false /*!< RFAL RW 1695 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_3390 false /*!< RFAL RW 3390 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_6780 false /*!< RFAL RW 6780 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_13560 false /*!< RFAL RW 6780 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_AP2P_106 true /*!< RFAL AP2P 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_212 true /*!< RFAL AP2P 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_424 true /*!< RFAL AP2P 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_848 false /*!< RFAL AP2P 848 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_CE_A_106 true /*!< RFAL CE A 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_A_212 false /*!< RFAL CE A 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_A_424 false /*!< RFAL CE A 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_A_848 false /*!< RFAL CE A 848 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_CE_B_106 false /*!< RFAL CE B 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_B_212 false /*!< RFAL CE B 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_B_424 false /*!< RFAL CE B 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_B_848 false /*!< RFAL CE B 848 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_CE_F_212 true /*!< RFAL CE F 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_F_424 true /*!< RFAL CE F 424 Bit Rate support switch */
#endif /* RFAL_FEATURES_H */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,794 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief ST25R3916 high level interface
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3916.h"
#include "st25r3916_com.h"
#include "st25r3916_led.h"
#include "st25r3916_irq.h"
#include "utils.h"
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
#define ST25R3916_SUPPLY_THRESHOLD 3600U /*!< Power supply measure threshold between 3.3V or 5V */
#define ST25R3916_NRT_MAX 0xFFFFU /*!< Max Register value of NRT */
#define ST25R3916_TOUT_MEASURE_VDD 100U /*!< Max duration time of Measure Power Supply command Datasheet: 25us */
#define ST25R3916_TOUT_MEASURE_AMPLITUDE 10U /*!< Max duration time of Measure Amplitude command Datasheet: 25us */
#define ST25R3916_TOUT_MEASURE_PHASE 10U /*!< Max duration time of Measure Phase command Datasheet: 25us */
#define ST25R3916_TOUT_MEASURE_CAPACITANCE 10U /*!< Max duration time of Measure Capacitance command Datasheet: 25us */
#define ST25R3916_TOUT_CALIBRATE_CAP_SENSOR 4U /*!< Max duration Calibrate Capacitive Sensor command Datasheet: 3ms */
#define ST25R3916_TOUT_ADJUST_REGULATORS 6U /*!< Max duration time of Adjust Regulators command Datasheet: 5ms */
#define ST25R3916_TOUT_CA 10U /*!< Max duration time of Collision Avoidance command */
#define ST25R3916_TEST_REG_PATTERN 0x33U /*!< Register Read Write test pattern used during selftest */
#define ST25R3916_TEST_WU_TOUT 12U /*!< Timeout used on WU timer during self test */
#define ST25R3916_TEST_TMR_TOUT 20U /*!< Timeout used during self test */
#define ST25R3916_TEST_TMR_TOUT_DELTA 2U /*!< Timeout used during self test */
#define ST25R3916_TEST_TMR_TOUT_8FC (ST25R3916_TEST_TMR_TOUT * 16950U) /*!< Timeout in 8/fc */
/*
******************************************************************************
* LOCAL CONSTANTS
******************************************************************************
*/
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
static uint32_t gST25R3916NRT_64fcs;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*
******************************************************************************
* LOCAL FUNCTION
******************************************************************************
*/
ReturnCode st25r3916ExecuteCommandAndGetResult( uint8_t cmd, uint8_t resReg, uint8_t tout, uint8_t* result )
{
/* Clear and enable Direct Command interrupt */
st25r3916GetInterrupt( ST25R3916_IRQ_MASK_DCT );
st25r3916EnableInterrupts( ST25R3916_IRQ_MASK_DCT );
st25r3916ExecuteCommand( cmd );
st25r3916WaitForInterruptsTimed( ST25R3916_IRQ_MASK_DCT, tout );
st25r3916DisableInterrupts( ST25R3916_IRQ_MASK_DCT );
/* After execution read out the result if the pointer is not NULL */
if( result != NULL )
{
st25r3916ReadRegister( resReg, result);
}
return ERR_NONE;
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
ReturnCode st25r3916Initialize( void )
{
uint16_t vdd_mV;
ReturnCode ret;
/* Set default state on the ST25R3916 */
st25r3916ExecuteCommand( ST25R3916_CMD_SET_DEFAULT );
#ifndef RFAL_USE_I2C
/* Increase MISO driving level as SPI can go up to 10MHz */
st25r3916WriteRegister(ST25R3916_REG_IO_CONF2, ST25R3916_REG_IO_CONF2_io_drv_lvl);
#endif /* RFAL_USE_I2C */
if( !st25r3916CheckChipID( NULL ) )
{
platformErrorHandle();
return ERR_HW_MISMATCH;
}
st25r3916InitInterrupts();
st25r3916ledInit();
gST25R3916NRT_64fcs = 0;
#ifndef RFAL_USE_I2C
/* Enable pull downs on MISO line */
st25r3916SetRegisterBits(ST25R3916_REG_IO_CONF2, ( ST25R3916_REG_IO_CONF2_miso_pd1 | ST25R3916_REG_IO_CONF2_miso_pd2 ) );
#endif /* RFAL_USE_I2C */
/* Disable internal overheat protection */
st25r3916ChangeTestRegisterBits( 0x04, 0x10, 0x10 );
#ifdef ST25R_SELFTEST
/******************************************************************************
* Check communication interface:
* - write a pattern in a register
* - reads back the register value
* - return ERR_IO in case the read value is different
*/
st25r3916WriteRegister( ST25R3916_REG_BIT_RATE, ST25R3916_TEST_REG_PATTERN );
if( !st25r3916CheckReg( ST25R3916_REG_BIT_RATE, (ST25R3916_REG_BIT_RATE_rxrate_mask | ST25R3916_REG_BIT_RATE_txrate_mask), ST25R3916_TEST_REG_PATTERN ) )
{
platformErrorHandle();
return ERR_IO;
}
/* Restore default value */
st25r3916WriteRegister( ST25R3916_REG_BIT_RATE, 0x00 );
/*
* Check IRQ Handling:
* - use the Wake-up timer to trigger an IRQ
* - wait the Wake-up timer interrupt
* - return ERR_TIMEOUT when the Wake-up timer interrupt is not received
*/
st25r3916WriteRegister( ST25R3916_REG_WUP_TIMER_CONTROL, ST25R3916_REG_WUP_TIMER_CONTROL_wur|ST25R3916_REG_WUP_TIMER_CONTROL_wto);
st25r3916EnableInterrupts( ST25R3916_IRQ_MASK_WT );
st25r3916ExecuteCommand( ST25R3916_CMD_START_WUP_TIMER );
if(st25r3916WaitForInterruptsTimed(ST25R3916_IRQ_MASK_WT, ST25R3916_TEST_WU_TOUT) == 0U )
{
platformErrorHandle();
return ERR_TIMEOUT;
}
st25r3916DisableInterrupts( ST25R3916_IRQ_MASK_WT );
st25r3916WriteRegister( ST25R3916_REG_WUP_TIMER_CONTROL, 0U );
/*******************************************************************************/
#endif /* ST25R_SELFTEST */
/* Enable Oscillator and wait until it gets stable */
ret = st25r3916OscOn();
if( ret != ERR_NONE )
{
platformErrorHandle();
return ret;
}
/* Measure VDD and set sup3V bit according to Power supplied */
vdd_mV = st25r3916MeasureVoltage( ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd );
st25r3916ChangeRegisterBits( ST25R3916_REG_IO_CONF2, ST25R3916_REG_IO_CONF2_sup3V, ((vdd_mV < ST25R3916_SUPPLY_THRESHOLD) ? ST25R3916_REG_IO_CONF2_sup3V_3V : ST25R3916_REG_IO_CONF2_sup3V_5V) );
/* Make sure Transmitter and Receiver are disabled */
st25r3916TxRxOff();
#ifdef ST25R_SELFTEST_TIMER
/******************************************************************************
* Check SW timer operation :
* - use the General Purpose timer to measure an amount of time
* - test whether an interrupt is seen when less time was given
* - test whether an interrupt is seen when sufficient time was given
*/
st25r3916EnableInterrupts( ST25R3916_IRQ_MASK_GPE );
st25r3916SetStartGPTimer( (uint16_t)ST25R3916_TEST_TMR_TOUT_8FC, ST25R3916_REG_TIMER_EMV_CONTROL_gptc_no_trigger);
if( st25r3916WaitForInterruptsTimed( ST25R3916_IRQ_MASK_GPE, (ST25R3916_TEST_TMR_TOUT - ST25R3916_TEST_TMR_TOUT_DELTA)) != 0U )
{
platformErrorHandle();
return ERR_SYSTEM;
}
/* Stop all activities to stop the GP timer */
st25r3916ExecuteCommand( ST25R3916_CMD_STOP );
st25r3916ClearAndEnableInterrupts( ST25R3916_IRQ_MASK_GPE );
st25r3916SetStartGPTimer( (uint16_t)ST25R3916_TEST_TMR_TOUT_8FC, ST25R3916_REG_TIMER_EMV_CONTROL_gptc_no_trigger );
if(st25r3916WaitForInterruptsTimed( ST25R3916_IRQ_MASK_GPE, (ST25R3916_TEST_TMR_TOUT + ST25R3916_TEST_TMR_TOUT_DELTA)) == 0U )
{
platformErrorHandle();
return ERR_SYSTEM;
}
/* Stop all activities to stop the GP timer */
st25r3916ExecuteCommand( ST25R3916_CMD_STOP );
/*******************************************************************************/
#endif /* ST25R_SELFTEST_TIMER */
/* After reset all interrupts are enabled, so disable them at first */
st25r3916DisableInterrupts( ST25R3916_IRQ_MASK_ALL );
/* And clear them, just to be sure */
st25r3916ClearInterrupts();
return ERR_NONE;
}
/*******************************************************************************/
void st25r3916Deinitialize( void )
{
st25r3916DisableInterrupts( ST25R3916_IRQ_MASK_ALL );
/* Disabe Tx and Rx, Keep OSC On */
st25r3916TxRxOff();
return;
}
/*******************************************************************************/
ReturnCode st25r3916OscOn( void )
{
/* Check if oscillator is already turned on and stable */
/* Use ST25R3916_REG_OP_CONTROL_en instead of ST25R3916_REG_AUX_DISPLAY_osc_ok to be on the safe side */
if( !st25r3916CheckReg( ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_en, ST25R3916_REG_OP_CONTROL_en ) )
{
/* Clear any eventual previous oscillator IRQ */
st25r3916GetInterrupt( ST25R3916_IRQ_MASK_OSC );
/* Enable oscillator frequency stable interrupt */
st25r3916EnableInterrupts( ST25R3916_IRQ_MASK_OSC );
/* Enable oscillator and regulator output */
st25r3916SetRegisterBits( ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_en );
/* Wait for the oscillator interrupt */
st25r3916WaitForInterruptsTimed( ST25R3916_IRQ_MASK_OSC, ST25R3916_TOUT_OSC_STABLE );
st25r3916DisableInterrupts( ST25R3916_IRQ_MASK_OSC );
}
if( !st25r3916CheckReg( ST25R3916_REG_AUX_DISPLAY, ST25R3916_REG_AUX_DISPLAY_osc_ok, ST25R3916_REG_AUX_DISPLAY_osc_ok ) )
{
return ERR_SYSTEM;
}
return ERR_NONE;
}
/*******************************************************************************/
uint8_t st25r3916MeasurePowerSupply( uint8_t mpsv )
{
uint8_t result;
/* Set the source of direct command: Measure Power Supply Voltage */
st25r3916ChangeRegisterBits( ST25R3916_REG_REGULATOR_CONTROL, ST25R3916_REG_REGULATOR_CONTROL_mpsv_mask, mpsv );
/* Execute command: Measure Power Supply Voltage */
st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_MEASURE_VDD, ST25R3916_REG_AD_RESULT, ST25R3916_TOUT_MEASURE_VDD, &result);
return result;
}
/*******************************************************************************/
uint16_t st25r3916MeasureVoltage( uint8_t mpsv )
{
uint8_t result;
uint16_t mV;
result = st25r3916MeasurePowerSupply(mpsv);
/* Convert cmd output into mV (each step represents 23.4 mV )*/
mV = ((uint16_t)result) * 23U;
mV += (((((uint16_t)result) * 4U) + 5U) / 10U);
return mV;
}
/*******************************************************************************/
ReturnCode st25r3916AdjustRegulators( uint16_t* result_mV )
{
uint8_t result;
/* Reset logic and set regulated voltages to be defined by result of Adjust Regulators command */
st25r3916SetRegisterBits( ST25R3916_REG_REGULATOR_CONTROL, ST25R3916_REG_REGULATOR_CONTROL_reg_s );
st25r3916ClrRegisterBits( ST25R3916_REG_REGULATOR_CONTROL, ST25R3916_REG_REGULATOR_CONTROL_reg_s );
/* Execute Adjust regulators cmd and retrieve result */
st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_ADJUST_REGULATORS, ST25R3916_REG_REGULATOR_RESULT, ST25R3916_TOUT_ADJUST_REGULATORS, &result );
/* Calculate result in mV */
result >>= ST25R3916_REG_REGULATOR_RESULT_reg_shift;
if( result_mV != NULL )
{
if( st25r3916CheckReg( ST25R3916_REG_IO_CONF2, ST25R3916_REG_IO_CONF2_sup3V, ST25R3916_REG_IO_CONF2_sup3V ) )
{
result = MIN( result, (uint8_t)(result-5U) );/* In 3.3V mode [0,4] are not used */
*result_mV = 2400U; /* Minimum regulated voltage 2.4V in case of 3.3V supply */
}
else
{
*result_mV = 3600U; /* Minimum regulated voltage 3.6V in case of 5V supply */
}
*result_mV += (uint16_t)result * 100U; /* 100mV steps in both 3.3V and 5V supply */
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916MeasureAmplitude( uint8_t* result )
{
return st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_MEASURE_AMPLITUDE, ST25R3916_REG_AD_RESULT, ST25R3916_TOUT_MEASURE_AMPLITUDE, result );
}
/*******************************************************************************/
ReturnCode st25r3916MeasurePhase( uint8_t* result )
{
return st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_MEASURE_PHASE, ST25R3916_REG_AD_RESULT, ST25R3916_TOUT_MEASURE_PHASE, result );
}
/*******************************************************************************/
ReturnCode st25r3916MeasureCapacitance( uint8_t* result )
{
return st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_MEASURE_CAPACITANCE, ST25R3916_REG_AD_RESULT, ST25R3916_TOUT_MEASURE_CAPACITANCE, result );
}
/*******************************************************************************/
ReturnCode st25r3916CalibrateCapacitiveSensor( uint8_t* result )
{
ReturnCode ret;
uint8_t res;
/* Clear Manual calibration values to enable automatic calibration mode */
st25r3916ClrRegisterBits( ST25R3916_REG_CAP_SENSOR_CONTROL, ST25R3916_REG_CAP_SENSOR_CONTROL_cs_mcal_mask );
/* Execute automatic calibration */
ret = st25r3916ExecuteCommandAndGetResult( ST25R3916_CMD_CALIBRATE_C_SENSOR, ST25R3916_REG_CAP_SENSOR_RESULT, ST25R3916_TOUT_CALIBRATE_CAP_SENSOR, &res );
/* Check wether the calibration was successull */
if( ((res & ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_end) != ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_end) ||
((res & ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_err) == ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_err) || (ret != ERR_NONE) )
{
return ERR_IO;
}
if( result != NULL )
{
(*result) = (uint8_t)(res >> ST25R3916_REG_CAP_SENSOR_RESULT_cs_cal_shift);
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916SetBitrate(uint8_t txrate, uint8_t rxrate)
{
uint8_t reg;
st25r3916ReadRegister( ST25R3916_REG_BIT_RATE, &reg );
if( rxrate != ST25R3916_BR_DO_NOT_SET )
{
if(rxrate > ST25R3916_BR_848)
{
return ERR_PARAM;
}
reg = (uint8_t)(reg & ~ST25R3916_REG_BIT_RATE_rxrate_mask); /* MISRA 10.3 */
reg |= rxrate << ST25R3916_REG_BIT_RATE_rxrate_shift;
}
if( txrate != ST25R3916_BR_DO_NOT_SET )
{
if(txrate > ST25R3916_BR_6780)
{
return ERR_PARAM;
}
reg = (uint8_t)(reg & ~ST25R3916_REG_BIT_RATE_txrate_mask); /* MISRA 10.3 */
reg |= txrate<<ST25R3916_REG_BIT_RATE_txrate_shift;
}
return st25r3916WriteRegister( ST25R3916_REG_BIT_RATE, reg );
}
/*******************************************************************************/
ReturnCode st25r3916PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW )
{
uint8_t treMask;
uint32_t irqs;
ReturnCode err;
if( (FieldONCmd != ST25R3916_CMD_INITIAL_RF_COLLISION) && (FieldONCmd != ST25R3916_CMD_RESPONSE_RF_COLLISION_N) )
{
return ERR_PARAM;
}
err = ERR_INTERNAL;
/* Check if new thresholds are to be applied */
if( (pdThreshold != ST25R3916_THRESHOLD_DO_NOT_SET) || (caThreshold != ST25R3916_THRESHOLD_DO_NOT_SET) )
{
treMask = 0;
if(pdThreshold != ST25R3916_THRESHOLD_DO_NOT_SET)
{
treMask |= ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_mask;
}
if(caThreshold != ST25R3916_THRESHOLD_DO_NOT_SET)
{
treMask |= ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_mask;
}
/* Set Detection Threshold and|or Collision Avoidance Threshold */
st25r3916ChangeRegisterBits( ST25R3916_REG_FIELD_THRESHOLD_ACTV, treMask, (pdThreshold & ST25R3916_REG_FIELD_THRESHOLD_ACTV_trg_mask) | (caThreshold & ST25R3916_REG_FIELD_THRESHOLD_ACTV_rfe_mask ) );
}
/* Set n x TRFW */
st25r3916ChangeRegisterBits( ST25R3916_REG_AUX, ST25R3916_REG_AUX_nfc_n_mask, nTRFW );
/*******************************************************************************/
/* Enable and clear CA specific interrupts and execute command */
st25r3916GetInterrupt( (ST25R3916_IRQ_MASK_CAC | ST25R3916_IRQ_MASK_CAT | ST25R3916_IRQ_MASK_APON) );
st25r3916EnableInterrupts( (ST25R3916_IRQ_MASK_CAC | ST25R3916_IRQ_MASK_CAT | ST25R3916_IRQ_MASK_APON) );
st25r3916ExecuteCommand( FieldONCmd );
/*******************************************************************************/
/* Wait for initial APON interrupt, indicating anticollision avoidance done and ST25R3916's
* field is now on, or a CAC indicating a collision */
irqs = st25r3916WaitForInterruptsTimed( ( ST25R3916_IRQ_MASK_CAC | ST25R3916_IRQ_MASK_APON ), ST25R3916_TOUT_CA );
if( (ST25R3916_IRQ_MASK_CAC & irqs) != 0U ) /* Collision occurred */
{
err = ERR_RF_COLLISION;
}
else if( (ST25R3916_IRQ_MASK_APON & irqs) != 0U )
{
/* After APON wait for CAT interrupt, indication field was switched on minimum guard time has been fulfilled */
irqs = st25r3916WaitForInterruptsTimed( ( ST25R3916_IRQ_MASK_CAT ), ST25R3916_TOUT_CA );
if( (ST25R3916_IRQ_MASK_CAT & irqs) != 0U ) /* No Collision detected, Field On */
{
err = ERR_NONE;
}
}
else
{
/* MISRA 15.7 - Empty else */
}
/* Clear any previous External Field events and disable CA specific interrupts */
st25r3916GetInterrupt( (ST25R3916_IRQ_MASK_EOF | ST25R3916_IRQ_MASK_EON) );
st25r3916DisableInterrupts( (ST25R3916_IRQ_MASK_CAC | ST25R3916_IRQ_MASK_CAT | ST25R3916_IRQ_MASK_APON) );
return err;
}
/*******************************************************************************/
void st25r3916SetNumTxBits( uint16_t nBits )
{
st25r3916WriteRegister( ST25R3916_REG_NUM_TX_BYTES2, (uint8_t)((nBits >> 0) & 0xFFU) );
st25r3916WriteRegister( ST25R3916_REG_NUM_TX_BYTES1, (uint8_t)((nBits >> 8) & 0xFFU) );
}
/*******************************************************************************/
uint16_t st25r3916GetNumFIFOBytes( void )
{
uint8_t reg;
uint16_t result;
st25r3916ReadRegister( ST25R3916_REG_FIFO_STATUS2, &reg );
reg = ((reg & ST25R3916_REG_FIFO_STATUS2_fifo_b_mask) >> ST25R3916_REG_FIFO_STATUS2_fifo_b_shift);
result = ((uint16_t)reg << 8);
st25r3916ReadRegister( ST25R3916_REG_FIFO_STATUS1, &reg );
result |= (((uint16_t)reg) & 0x00FFU);
return result;
}
/*******************************************************************************/
uint8_t st25r3916GetNumFIFOLastBits( void )
{
uint8_t reg;
st25r3916ReadRegister( ST25R3916_REG_FIFO_STATUS2, &reg );
return ((reg & ST25R3916_REG_FIFO_STATUS2_fifo_lb_mask) >> ST25R3916_REG_FIFO_STATUS2_fifo_lb_shift);
}
/*******************************************************************************/
uint32_t st25r3916GetNoResponseTime( void )
{
return gST25R3916NRT_64fcs;
}
/*******************************************************************************/
ReturnCode st25r3916SetNoResponseTime( uint32_t nrt_64fcs )
{
ReturnCode err;
uint8_t nrt_step;
uint32_t tmpNRT;
tmpNRT = nrt_64fcs; /* MISRA 17.8 */
err = ERR_NONE;
gST25R3916NRT_64fcs = tmpNRT; /* Store given NRT value in 64/fc into local var */
nrt_step = ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step_64fc; /* Set default NRT in steps of 64/fc */
if( tmpNRT > ST25R3916_NRT_MAX ) /* Check if the given NRT value fits using 64/fc steps */
{
nrt_step = ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step_4096_fc; /* If not, change NRT set to 4096/fc */
tmpNRT = ((tmpNRT + 63U) / 64U); /* Calculate number of steps in 4096/fc */
if( tmpNRT > ST25R3916_NRT_MAX ) /* Check if the NRT value fits using 64/fc steps */
{
tmpNRT = ST25R3916_NRT_MAX; /* Assign the maximum possible */
err = ERR_PARAM; /* Signal parameter error */
}
gST25R3916NRT_64fcs = (64U * tmpNRT);
}
/* Set the ST25R3916 NRT step units and the value */
st25r3916ChangeRegisterBits( ST25R3916_REG_TIMER_EMV_CONTROL, ST25R3916_REG_TIMER_EMV_CONTROL_nrt_step, nrt_step );
st25r3916WriteRegister( ST25R3916_REG_NO_RESPONSE_TIMER1, (uint8_t)(tmpNRT >> 8U) );
st25r3916WriteRegister( ST25R3916_REG_NO_RESPONSE_TIMER2, (uint8_t)(tmpNRT & 0xFFU) );
return err;
}
/*******************************************************************************/
ReturnCode st25r3916SetStartNoResponseTimer( uint32_t nrt_64fcs )
{
ReturnCode err;
err = st25r3916SetNoResponseTime( nrt_64fcs );
if(err == ERR_NONE)
{
st25r3916ExecuteCommand( ST25R3916_CMD_START_NO_RESPONSE_TIMER );
}
return err;
}
/*******************************************************************************/
void st25r3916SetGPTime( uint16_t gpt_8fcs )
{
st25r3916WriteRegister( ST25R3916_REG_GPT1, (uint8_t)(gpt_8fcs >> 8) );
st25r3916WriteRegister( ST25R3916_REG_GPT2, (uint8_t)(gpt_8fcs & 0xFFU) );
}
/*******************************************************************************/
ReturnCode st25r3916SetStartGPTimer( uint16_t gpt_8fcs, uint8_t trigger_source )
{
st25r3916SetGPTime( gpt_8fcs );
st25r3916ChangeRegisterBits( ST25R3916_REG_TIMER_EMV_CONTROL, ST25R3916_REG_TIMER_EMV_CONTROL_gptc_mask, trigger_source );
/* If there's no trigger source, start GPT immediately */
if( trigger_source == ST25R3916_REG_TIMER_EMV_CONTROL_gptc_no_trigger )
{
st25r3916ExecuteCommand( ST25R3916_CMD_START_GP_TIMER );
}
return ERR_NONE;
}
/*******************************************************************************/
bool st25r3916CheckChipID( uint8_t *rev )
{
uint8_t ID;
ID = 0;
st25r3916ReadRegister( ST25R3916_REG_IC_IDENTITY, &ID );
/* Check if IC Identity Register contains ST25R3916's IC type code */
if( (ID & ST25R3916_REG_IC_IDENTITY_ic_type_mask) != ST25R3916_REG_IC_IDENTITY_ic_type_st25r3916 )
{
return false;
}
if(rev != NULL)
{
*rev = (ID & ST25R3916_REG_IC_IDENTITY_ic_rev_mask);
}
return true;
}
/*******************************************************************************/
ReturnCode st25r3916GetRegsDump( t_st25r3916Regs* regDump )
{
uint8_t regIt;
if(regDump == NULL)
{
return ERR_PARAM;
}
/* Dump Registers on space A */
for( regIt = ST25R3916_REG_IO_CONF1; regIt <= ST25R3916_REG_IC_IDENTITY; regIt++ )
{
st25r3916ReadRegister(regIt, &regDump->RsA[regIt] );
}
regIt = 0;
/* Read non-consecutive Registers on space B */
st25r3916ReadRegister( ST25R3916_REG_EMD_SUP_CONF, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_SUBC_START_TIME, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_P2P_RX_CONF, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_CORR_CONF1, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_CORR_CONF2, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_SQUELCH_TIMER, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_FIELD_ON_GT, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_AUX_MOD, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_TX_DRIVER_TIMING, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_RES_AM_MOD, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_TX_DRIVER_STATUS, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_REGULATOR_RESULT, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_OVERSHOOT_CONF1, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_OVERSHOOT_CONF2, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_UNDERSHOOT_CONF1, &regDump->RsB[regIt++] );
st25r3916ReadRegister( ST25R3916_REG_UNDERSHOOT_CONF2, &regDump->RsB[regIt++] );
return ERR_NONE;
}
/*******************************************************************************/
bool st25r3916IsCmdValid( uint8_t cmd )
{
if( !((cmd >= ST25R3916_CMD_SET_DEFAULT) && (cmd <= ST25R3916_CMD_RESPONSE_RF_COLLISION_N)) &&
!((cmd >= ST25R3916_CMD_GOTO_SENSE) && (cmd <= ST25R3916_CMD_GOTO_SLEEP)) &&
!((cmd >= ST25R3916_CMD_MASK_RECEIVE_DATA) && (cmd <= ST25R3916_CMD_MEASURE_AMPLITUDE)) &&
!((cmd >= ST25R3916_CMD_RESET_RXGAIN) && (cmd <= ST25R3916_CMD_ADJUST_REGULATORS)) &&
!((cmd >= ST25R3916_CMD_CALIBRATE_DRIVER_TIMING) && (cmd <= ST25R3916_CMD_START_PPON2_TIMER)) &&
(cmd != ST25R3916_CMD_SPACE_B_ACCESS) && (cmd != ST25R3916_CMD_STOP_NRT) )
{
return false;
}
return true;
}
/*******************************************************************************/
ReturnCode st25r3916StreamConfigure(const struct st25r3916StreamConfig *config)
{
uint8_t smd;
uint8_t mode;
smd = 0;
if( config->useBPSK != 0U )
{
mode = ST25R3916_REG_MODE_om_bpsk_stream;
if( (config->din<2U) || (config->din>4U) ) /* not in fc/4 .. fc/16 */
{
return ERR_PARAM;
}
smd |= ((4U - config->din) << ST25R3916_REG_STREAM_MODE_scf_shift);
}
else
{
mode = ST25R3916_REG_MODE_om_subcarrier_stream;
if( (config->din<3U) || (config->din>6U) ) /* not in fc/8 .. fc/64 */
{
return ERR_PARAM;
}
smd |= ((6U - config->din) << ST25R3916_REG_STREAM_MODE_scf_shift);
if( config->report_period_length == 0U )
{
return ERR_PARAM;
}
}
if( (config->dout<1U) || (config->dout>7U) ) /* not in fc/2 .. fc/128 */
{
return ERR_PARAM;
}
smd |= (7U - config->dout) << ST25R3916_REG_STREAM_MODE_stx_shift;
if( config->report_period_length > 3U )
{
return ERR_PARAM;
}
smd |= (config->report_period_length << ST25R3916_REG_STREAM_MODE_scp_shift);
st25r3916WriteRegister(ST25R3916_REG_STREAM_MODE, smd);
st25r3916ChangeRegisterBits(ST25R3916_REG_MODE, ST25R3916_REG_MODE_om_mask, mode);
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916GetRSSI( uint16_t *amRssi, uint16_t *pmRssi )
{
/*******************************************************************************/
/* MISRA 8.9 An object should be defined at block scope if its identifier only appears in a single function */
/*< ST25R3916 RSSI Display Reg values: 0 1 2 3 4 5 6 7 8 9 a b c d e f */
static const uint16_t st25r3916Rssi2mV[] = { 0 ,20 ,27 ,37 ,52 ,72 ,99 ,136 ,190 ,262 ,357 ,500 ,686 ,950, 1150, 1150 };
/* ST25R3916 2/3 stage gain reduction [dB] 0 0 0 0 0 3 6 9 12 15 18 na na na na na */
static const uint16_t st25r3916Gain2Percent[] = { 100, 100, 100, 100, 100, 141, 200, 281, 398, 562, 794, 1, 1, 1, 1, 1 };
/*******************************************************************************/
uint8_t rssi;
uint8_t gainRed;
st25r3916ReadRegister( ST25R3916_REG_RSSI_RESULT, &rssi );
st25r3916ReadRegister( ST25R3916_REG_GAIN_RED_STATE, &gainRed );
if( amRssi != NULL )
{
*amRssi = (uint16_t) ( ( (uint32_t)st25r3916Rssi2mV[ (rssi >> ST25R3916_REG_RSSI_RESULT_rssi_am_shift) ] * (uint32_t)st25r3916Gain2Percent[ (gainRed >> ST25R3916_REG_GAIN_RED_STATE_gs_am_shift) ] ) / 100U );
}
if( pmRssi != NULL )
{
*pmRssi = (uint16_t) ( ( (uint32_t)st25r3916Rssi2mV[ (rssi & ST25R3916_REG_RSSI_RESULT_rssi_pm_mask) ] * (uint32_t)st25r3916Gain2Percent[ (gainRed & ST25R3916_REG_GAIN_RED_STATE_gs_pm_mask) ] ) / 100U );
}
return ERR_NONE;
}

View File

@@ -0,0 +1,609 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief ST25R3916 high level interface
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup ST25R3916
* \brief RFAL ST25R3916 Driver
* @{
*
* \addtogroup ST25R3916_Driver
* \brief RFAL ST25R3916 Driver
* @{
*
*/
#ifndef ST25R3916_H
#define ST25R3916_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "st25r3916_com.h"
/*
******************************************************************************
* GLOBAL DATATYPES
******************************************************************************
*/
/*! Struct to represent all regs on ST25R3916 */
typedef struct{
uint8_t RsA[(ST25R3916_REG_IC_IDENTITY+1U)]; /*!< Registers contained on ST25R3916 space A (Rs-A) */
uint8_t RsB[ST25R3916_SPACE_B_REG_LEN]; /*!< Registers contained on ST25R3916 space B (Rs-B) */
}t_st25r3916Regs;
/*! Parameters how the stream mode should work */
struct st25r3916StreamConfig {
uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */
uint8_t din; /*!< Divider for the in subcarrier frequency: fc/2^din */
uint8_t dout; /*!< Divider for the in subcarrier frequency fc/2^dout */
uint8_t report_period_length; /*!< Length of the reporting period 2^report_period_length*/
};
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
/* ST25R3916 direct commands */
#define ST25R3916_CMD_SET_DEFAULT 0xC1U /*!< Puts the chip in default state (same as after power-up) */
#define ST25R3916_CMD_STOP 0xC2U /*!< Stops all activities and clears FIFO */
#define ST25R3916_CMD_TRANSMIT_WITH_CRC 0xC4U /*!< Transmit with CRC */
#define ST25R3916_CMD_TRANSMIT_WITHOUT_CRC 0xC5U /*!< Transmit without CRC */
#define ST25R3916_CMD_TRANSMIT_REQA 0xC6U /*!< Transmit REQA */
#define ST25R3916_CMD_TRANSMIT_WUPA 0xC7U /*!< Transmit WUPA */
#define ST25R3916_CMD_INITIAL_RF_COLLISION 0xC8U /*!< NFC transmit with Initial RF Collision Avoidance */
#define ST25R3916_CMD_RESPONSE_RF_COLLISION_N 0xC9U /*!< NFC transmit with Response RF Collision Avoidance */
#define ST25R3916_CMD_GOTO_SENSE 0xCDU /*!< Passive target logic to Sense/Idle state */
#define ST25R3916_CMD_GOTO_SLEEP 0xCEU /*!< Passive target logic to Sleep/Halt state */
#define ST25R3916_CMD_MASK_RECEIVE_DATA 0xD0U /*!< Mask receive data */
#define ST25R3916_CMD_UNMASK_RECEIVE_DATA 0xD1U /*!< Unmask receive data */
#define ST25R3916_CMD_AM_MOD_STATE_CHANGE 0xD2U /*!< AM Modulation state change */
#define ST25R3916_CMD_MEASURE_AMPLITUDE 0xD3U /*!< Measure singal amplitude on RFI inputs */
#define ST25R3916_CMD_RESET_RXGAIN 0xD5U /*!< Reset RX Gain */
#define ST25R3916_CMD_ADJUST_REGULATORS 0xD6U /*!< Adjust regulators */
#define ST25R3916_CMD_CALIBRATE_DRIVER_TIMING 0xD8U /*!< Starts the sequence to adjust the driver timing */
#define ST25R3916_CMD_MEASURE_PHASE 0xD9U /*!< Measure phase between RFO and RFI signal */
#define ST25R3916_CMD_CLEAR_RSSI 0xDAU /*!< Clear RSSI bits and restart the measurement */
#define ST25R3916_CMD_CLEAR_FIFO 0xDBU /*!< Clears FIFO, Collision and IRQ status */
#define ST25R3916_CMD_TRANSPARENT_MODE 0xDCU /*!< Transparent mode */
#define ST25R3916_CMD_CALIBRATE_C_SENSOR 0xDDU /*!< Calibrate the capacitive sensor */
#define ST25R3916_CMD_MEASURE_CAPACITANCE 0xDEU /*!< Measure capacitance */
#define ST25R3916_CMD_MEASURE_VDD 0xDFU /*!< Measure power supply voltage */
#define ST25R3916_CMD_START_GP_TIMER 0xE0U /*!< Start the general purpose timer */
#define ST25R3916_CMD_START_WUP_TIMER 0xE1U /*!< Start the wake-up timer */
#define ST25R3916_CMD_START_MASK_RECEIVE_TIMER 0xE2U /*!< Start the mask-receive timer */
#define ST25R3916_CMD_START_NO_RESPONSE_TIMER 0xE3U /*!< Start the no-response timer */
#define ST25R3916_CMD_START_PPON2_TIMER 0xE4U /*!< Start PPon2 timer */
#define ST25R3916_CMD_STOP_NRT 0xE8U /*!< Stop No Response Timer */
#define ST25R3916_CMD_SPACE_B_ACCESS 0xFBU /*!< Enable R/W access to the test registers */
#define ST25R3916_CMD_TEST_ACCESS 0xFCU /*!< Enable R/W access to the test registers */
#define ST25R3916_THRESHOLD_DO_NOT_SET 0xFFU /*!< Indicates not to change this Threshold */
#define ST25R3916_BR_DO_NOT_SET 0xFFU /*!< Indicates not to change this Bit Rate */
#define ST25R3916_BR_106 0x00U /*!< ST25R3916 Bit Rate 106 kbit/s (fc/128) */
#define ST25R3916_BR_212 0x01U /*!< ST25R3916 Bit Rate 212 kbit/s (fc/64) */
#define ST25R3916_BR_424 0x02U /*!< ST25R3916 Bit Rate 424 kbit/s (fc/32) */
#define ST25R3916_BR_848 0x03U /*!< ST25R3916 Bit Rate 848 kbit/s (fc/16) */
#define ST25R3916_BR_1695 0x04U /*!< ST25R3916 Bit Rate 1696 kbit/s (fc/8) */
#define ST25R3916_BR_3390 0x05U /*!< ST25R3916 Bit Rate 3390 kbit/s (fc/4) */
#define ST25R3916_BR_6780 0x07U /*!< ST25R3916 Bit Rate 6780 kbit/s (fc/2) */
#define ST25R3916_FIFO_DEPTH 512U /*!< Depth of FIFO */
#define ST25R3916_TOUT_OSC_STABLE 10U /*!< Max timeout for Oscillator to get stable DS: 700us */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Enables the Transmitter (Field On) and Receiver */
#define st25r3916TxRxOn() st25r3916SetRegisterBits( ST25R3916_REG_OP_CONTROL, (ST25R3916_REG_OP_CONTROL_rx_en | ST25R3916_REG_OP_CONTROL_tx_en ) )
/*! Disables the Transmitter (Field Off) and Receiver */
#define st25r3916TxRxOff() st25r3916ClrRegisterBits( ST25R3916_REG_OP_CONTROL, (ST25R3916_REG_OP_CONTROL_rx_en | ST25R3916_REG_OP_CONTROL_tx_en ) )
/*! Disables the Transmitter (Field Off) */
#define st25r3916TxOff() st25r3916ClrRegisterBits( ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_tx_en )
/*! Checks if General Purpose Timer is still running by reading gpt_on flag */
#define st25r3916IsGPTRunning( ) st25r3916CheckReg( ST25R3916_REG_NFCIP1_BIT_RATE, ST25R3916_REG_NFCIP1_BIT_RATE_gpt_on, ST25R3916_REG_NFCIP1_BIT_RATE_gpt_on )
/*! Checks if External Filed is detected by reading ST25R3916 External Field Detector output */
#define st25r3916IsExtFieldOn() st25r3916CheckReg( ST25R3916_REG_AUX_DISPLAY, ST25R3916_REG_AUX_DISPLAY_efd_o, ST25R3916_REG_AUX_DISPLAY_efd_o )
/*! Checks if Transmitter is enabled (Field On) */
#define st25r3916IsTxEnabled() st25r3916CheckReg( ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_tx_en, ST25R3916_REG_OP_CONTROL_tx_en )
/*! Checks if NRT is in EMV mode */
#define st25r3916IsNRTinEMV() st25r3916CheckReg( ST25R3916_REG_TIMER_EMV_CONTROL, ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv, ST25R3916_REG_TIMER_EMV_CONTROL_nrt_emv_on )
/*! Checks if last FIFO byte is complete */
#define st25r3916IsLastFIFOComplete() st25r3916CheckReg( ST25R3916_REG_FIFO_STATUS2, ST25R3916_REG_FIFO_STATUS2_fifo_lb_mask, 0 )
/*! Checks if the Oscillator is enabled */
#define st25r3916IsOscOn() st25r3916CheckReg( ST25R3916_REG_OP_CONTROL, ST25R3916_REG_OP_CONTROL_en, ST25R3916_REG_OP_CONTROL_en )
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialise ST25R3916 driver
*
* This function initialises the ST25R3916 driver.
*
* \return ERR_NONE : Operation successful
* \return ERR_HW_MISMATCH : Expected HW do not match or communication error
* \return ERR_IO : Error during communication selftest. Check communication interface
* \return ERR_TIMEOUT : Timeout during IRQ selftest. Check IRQ handling
* \return ERR_SYSTEM : Failure during oscillator activation or timer error
*
*****************************************************************************
*/
ReturnCode st25r3916Initialize( void );
/*!
*****************************************************************************
* \brief Deinitialize ST25R3916 driver
*
* Calling this function deinitializes the ST25R3916 driver.
*
*****************************************************************************
*/
void st25r3916Deinitialize( void );
/*!
*****************************************************************************
* \brief Turn on Oscillator and Regulator
*
* This function turn on oscillator and regulator and waits for the
* oscillator to become stable
*
* \return ERR_SYSTEM : Failure dusring Oscillator activation
* \return ERR_NONE : No error, Oscillator is active and stable, Regulator is on
*
*****************************************************************************
*/
ReturnCode st25r3916OscOn( void );
/*!
*****************************************************************************
* \brief Sets the bitrate
*
* This function sets the bitrates for rx and tx
*
* \param txrate : speed is 2^txrate * 106 kb/s
* 0xff : don't set txrate (ST25R3916_BR_DO_NOT_SET)
* \param rxrate : speed is 2^rxrate * 106 kb/s
* 0xff : don't set rxrate (ST25R3916_BR_DO_NOT_SET)
*
* \return ERR_PARAM: At least one bit rate was invalid
* \return ERR_NONE : No error, both bit rates were set
*
*****************************************************************************
*/
ReturnCode st25r3916SetBitrate( uint8_t txrate, uint8_t rxrate );
/*!
*****************************************************************************
* \brief Adjusts supply regulators according to the current supply voltage
*
* This function the power level is measured in maximum load conditions and
* the regulated voltage reference is set to 250mV below this level.
* Execution of this function lasts arround 5ms.
*
* The regulated voltages will be set to the result of Adjust Regulators
*
* \param [out] result_mV : Result of calibration in milliVolts
*
* \return ERR_IO : Error during communication with ST25R3916
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916AdjustRegulators( uint16_t* result_mV );
/*!
*****************************************************************************
* \brief Measure Amplitude
*
* This function measured the amplitude on the RFI inputs and stores the
* result in parameter \a result.
*
* \param[out] result: result of RF measurement.
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916MeasureAmplitude( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Power Supply
*
* This function executes Measure Power Supply and returns the raw value
*
* \param[in] mpsv : one of ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_rf
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_a
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_d
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_am
*
* \return the measured voltage in raw format.
*
*****************************************************************************
*/
uint8_t st25r3916MeasurePowerSupply( uint8_t mpsv );
/*!
*****************************************************************************
* \brief Measure Voltage
*
* This function measures the voltage on one of VDD and VDD_* and returns
* the result in mV
*
* \param[in] mpsv : one of ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_rf
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_a
* ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_d
* or ST25R3916_REG_REGULATOR_CONTROL_mpsv_vdd_am
*
* \return the measured voltage in mV
*
*****************************************************************************
*/
uint16_t st25r3916MeasureVoltage( uint8_t mpsv );
/*!
*****************************************************************************
* \brief Measure Phase
*
* This function performs a Phase measurement.
* The result is stored in the \a result parameter.
*
* \param[out] result: 8 bit long result of the measurement.
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916MeasurePhase( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Capacitance
*
* This function performs the capacitance measurement and stores the
* result in parameter \a result.
*
* \param[out] result: 8 bit long result of RF measurement.
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916MeasureCapacitance( uint8_t* result );
/*!
*****************************************************************************
* \brief Calibrates Capacitive Sensor
*
* This function performs automatic calibration of the capacitive sensor
* and stores the result in parameter \a result.
*
* \warning To avoid interference with Xtal oscillator and reader magnetic
* field, it is strongly recommended to perform calibration
* in Power-down mode only.
* This method does not modify the Oscillator nor transmitter state,
* these should be configured before by user.
*
* \param[out] result: 5 bit long result of the calibration.
* Binary weighted, step 0.1 pF, max 3.1 pF
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_IO : The calibration was not successful
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916CalibrateCapacitiveSensor( uint8_t* result );
/*!
*****************************************************************************
* \brief Get NRT time
*
* This returns the last value set on the NRT
*
* \warning it does not read chip register, just the sw var that contains the
* last value set before
*
* \return the value of the NRT in 64/fc
*/
uint32_t st25r3916GetNoResponseTime( void );
/*!
*****************************************************************************
* \brief Set NRT time
*
* This function sets the No Response Time with the given value
*
* \param [in] nrt_64fcs : no response time in steps of 64/fc (4.72us)
*
* \return ERR_PARAM : Invalid parameter (time is too large)
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916SetNoResponseTime( uint32_t nrt_64fcs );
/*!
*****************************************************************************
* \brief Set and Start NRT
*
* This function sets the No Response Time with the given value and
* immediately starts it
* Used when needs to add more time before timeout without performing Tx
*
* \param [in] nrt_64fcs : no response time in steps of 64/fc (4.72us)
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916SetStartNoResponseTimer( uint32_t nrt_64fcs );
/*!
*****************************************************************************
* \brief Set GPT time
*
* This function sets the General Purpose Timer time registers
*
* \param [in] gpt_8fcs : general purpose timer timeout in steps of 8/fc (590ns)
*
*****************************************************************************
*/
void st25r3916SetGPTime( uint16_t gpt_8fcs );
/*!
*****************************************************************************
* \brief Set and Start GPT
*
* This function sets the General Purpose Timer with the given timeout and
* immediately starts it ONLY if the trigger source is not set to none.
*
* \param [in] gpt_8fcs : general purpose timer timeout in steps of8/fc (590ns)
* \param [in] trigger_source : no trigger, start of Rx, end of Rx, end of Tx in NFC mode
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916SetStartGPTimer( uint16_t gpt_8fcs, uint8_t trigger_source );
/*!
*****************************************************************************
* \brief Sets the number Tx Bits
*
* Sets ST25R3916 internal registers with correct number of complete bytes and
* bits to be sent
*
* \param [in] nBits : number of bits to be set/transmitted
*
*****************************************************************************
*/
void st25r3916SetNumTxBits( uint16_t nBits );
/*!
*****************************************************************************
* \brief Get amount of bytes in FIFO
*
* Gets the number of bytes currently in the FIFO
*
* \return the number of bytes currently in the FIFO
*
*****************************************************************************
*/
uint16_t st25r3916GetNumFIFOBytes( void );
/*!
*****************************************************************************
* \brief Get amount of bits of the last FIFO byte if incomplete
*
* Gets the number of bits of the last FIFO byte if incomplete
*
* \return the number of bits of the last FIFO byte if incomplete, 0 if
* the last byte is complete
*
*****************************************************************************
*/
uint8_t st25r3916GetNumFIFOLastBits( void );
/*!
*****************************************************************************
* \brief Perform Collision Avoidance
*
* Performs Collision Avoidance with the given threshold and with the
* n number of TRFW
*
* \param[in] FieldONCmd : Field ON command to be executed ST25R3916_CMD_INITIAL_RF_COLLISION
* or ST25R3916_CMD_RESPONSE_RF_COLLISION_N
* \param[in] pdThreshold : Peer Detection Threshold (ST25R3916_REG_FIELD_THRESHOLD_trg_xx)
* 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
* \param[in] caThreshold : Collision Avoidance Threshold (ST25R3916_REG_FIELD_THRESHOLD_rfe_xx)
* 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
* \param[in] nTRFW : Number of TRFW
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_RF_COLLISION : Collision detected
* \return ERR_NONE : No collision detected
*
*****************************************************************************
*/
ReturnCode st25r3916PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW );
/*!
*****************************************************************************
* \brief Check Identity
*
* Checks if the chip ID is as expected.
*
* 5 bit IC type code for ST25R3916: 00101
* The 3 lsb contain the IC revision code
*
* \param[out] rev : the IC revision code
*
* \return true when IC type is as expected
* \return false otherwise
*/
bool st25r3916CheckChipID( uint8_t *rev );
/*!
*****************************************************************************
* \brief Retrieves all internal registers from ST25R3916
*
* \param[out] regDump : pointer to the struct/buffer where the reg dump
* will be written
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode st25r3916GetRegsDump( t_st25r3916Regs* regDump );
/*!
*****************************************************************************
* \brief Check if command is valid
*
* Checks if the given command is a valid ST25R3916 command
*
* \param[in] cmd: Command to check
*
* \return true if is a valid command
* \return false otherwise
*
*****************************************************************************
*/
bool st25r3916IsCmdValid( uint8_t cmd );
/*!
*****************************************************************************
* \brief Configure the stream mode of ST25R3916
*
* This function initializes the stream with the given parameters
*
* \param[in] config : all settings for bitrates, type, etc.
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error, stream mode driver initialized
*
*****************************************************************************
*/
ReturnCode st25r3916StreamConfigure( const struct st25r3916StreamConfig *config );
/*!
*****************************************************************************
* \brief Executes a direct command and returns the result
*
* This function executes the direct command given by \a cmd waits for
* \a sleeptime for I_dct and returns the result read from register \a resreg.
* The value of cmd is not checked.
*
* \param[in] cmd : direct command to execute
* \param[in] resReg: address of the register containing the result
* \param[in] tout : time in milliseconds to wait before reading the result
* \param[out] result: result
*
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916ExecuteCommandAndGetResult( uint8_t cmd, uint8_t resReg, uint8_t tout, uint8_t* result );
/*!
*****************************************************************************
* \brief Gets the RSSI values
*
* This function gets the RSSI value of the previous reception taking into
* account the gain reductions that were used.
* RSSI value for both AM and PM channel can be retrieved.
*
* \param[out] amRssi: the RSSI on the AM channel expressed in mV
* \param[out] pmRssi: the RSSI on the PM channel expressed in mV
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3916GetRSSI( uint16_t *amRssi, uint16_t *pmRssi );
#endif /* ST25R3916_H */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@@ -0,0 +1,329 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file st25r3916_aat.c
*
* \author
*
* \brief ST25R3916 Antenna Tuning
*
* The antenna tuning algorithm tries to find the optimal settings for
* the AAT_A and AAT_B registers, which are connected to variable capacitors
* to tune the antenna matching.
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3916_aat.h"
#include "utils.h"
#include "st_errno.h"
#include "st25r3916.h"
#include "st25r3916_com.h"
#include "platform.h"
#include "rfal_chip.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define ST25R3916_AAT_CAP_DELAY_MAX 10 /*!< Max Variable Capacitor settle delay */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define st25r3916AatLog(...) /* platformLog(__VA_ARGS__) */ /*!< Logging macro */
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static ReturnCode aatHillClimb(const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus);
static int32_t aatGreedyDescent(uint32_t *f_min, const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus, int32_t previousDir);
static int32_t aatSteepestDescent(uint32_t *f_min, const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus, int32_t previousDir, int32_t previousDir2);
static ReturnCode aatMeasure(uint8_t serCap, uint8_t parCap, uint8_t *amplitude, uint8_t *phase, uint16_t *measureCnt);
static uint32_t aatCalcF(const struct st25r3916AatTuneParams *tuningParams, uint8_t amplitude, uint8_t phase);
static ReturnCode aatStepDacVals(const struct st25r3916AatTuneParams *tuningParams,uint8_t *a, uint8_t *b, int32_t dir);
/*******************************************************************************/
ReturnCode st25r3916AatTune(const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus)
{
ReturnCode err;
const struct st25r3916AatTuneParams *tp = tuningParams;
struct st25r3916AatTuneResult *ts = tuningStatus;
struct st25r3916AatTuneParams defaultTuningParams =
{
.aat_a_min=0,
.aat_a_max=255,
.aat_a_start=127,
.aat_a_stepWidth=32,
.aat_b_min=0,
.aat_b_max=255,
.aat_b_start=127,
.aat_b_stepWidth=32,
.phaTarget=128,
.phaWeight=2,
.ampTarget=196,
.ampWeight=1,
.doDynamicSteps=true,
.measureLimit=50,
};
struct st25r3916AatTuneResult defaultTuneResult;
if ((NULL != tp) && (
(tp->aat_a_min > tp->aat_a_max )
|| (tp->aat_a_start < tp->aat_a_min )
|| (tp->aat_a_start > tp->aat_a_max )
|| (tp->aat_b_min > tp->aat_b_max )
|| (tp->aat_b_start < tp->aat_b_min )
|| (tp->aat_b_start > tp->aat_b_max )
))
{
return ERR_PARAM;
}
if (NULL == tp)
{ /* Start from current caps with default params */
st25r3916ReadRegister(ST25R3916_REG_ANT_TUNE_A, &defaultTuningParams.aat_a_start);
st25r3916ReadRegister(ST25R3916_REG_ANT_TUNE_B, &defaultTuningParams.aat_b_start);
tp = &defaultTuningParams;
}
if (NULL == ts){ts = &defaultTuneResult;}
ts->measureCnt = 0; /* Clear current measure count */
err = aatHillClimb(tp, ts);
return err;
}
/*******************************************************************************/
static ReturnCode aatHillClimb(const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus)
{
ReturnCode err = ERR_NONE;
uint32_t f_min;
int32_t direction, gdirection;
uint8_t amp,phs;
struct st25r3916AatTuneParams tp = *tuningParams; // local copy to obey const
tuningStatus->aat_a = tuningParams->aat_a_start;
tuningStatus->aat_b = tuningParams->aat_b_start;
/* Get a proper start value */
aatMeasure(tuningStatus->aat_a,tuningStatus->aat_b,&amp,&phs,&tuningStatus->measureCnt);
f_min = aatCalcF(&tp, amp, phs);
direction = 0;
st25r3916AatLog("%d %d: %d***\n",tuningStatus->aat_a,tuningStatus->aat_b,f_min);
do {
direction = 0; /* Initially and after reducing step sizes we don't have a previous direction */
do {
/* With the greedy step below always executed aftwards the -direction does never need to be investigated */
direction = aatSteepestDescent(&f_min, &tp, tuningStatus, direction, -direction);
if (tuningStatus->measureCnt > tp.measureLimit)
{
err = ERR_OVERRUN;
break;
}
do
{
gdirection = aatGreedyDescent(&f_min, &tp, tuningStatus, direction);
if (tuningStatus->measureCnt > tp.measureLimit) {
err = ERR_OVERRUN;
break;
}
} while (0 != gdirection);
} while (0 != direction);
tp.aat_a_stepWidth /= 2U; /* Reduce step sizes */
tp.aat_b_stepWidth /= 2U;
} while (tp.doDynamicSteps && ((tp.aat_a_stepWidth>0U) || (tp.aat_b_stepWidth>0U)));
return err;
}
/*******************************************************************************/
static int32_t aatSteepestDescent(uint32_t *f_min, const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus, int32_t previousDir, int32_t previousDir2)
{
int32_t i;
uint8_t amp,phs;
uint32_t f;
int32_t bestdir = 0; /* Negative direction: decrease, Positive: increase. (-)1: aat_a, (-)2: aat_b */
for (i = -2; i <= 2; i++)
{
uint8_t a = tuningStatus->aat_a , b = tuningStatus->aat_b;
if ((0==i) || (i==-previousDir) || (i==-previousDir2))
{ /* Skip no direction and avoid going backwards */
continue;
}
if (0U!=aatStepDacVals(tuningParams, &a, &b, i))
{ /* If stepping did not change the value, omit this direction */
continue;
}
aatMeasure(a,b,&amp,&phs,&tuningStatus->measureCnt);
f = aatCalcF(tuningParams, amp, phs);
st25r3916AatLog("%d : %d %d: %d",i,a, b, f);
if (f < *f_min)
{ /* Value is better than all previous ones */
st25r3916AatLog("*");
*f_min = f;
bestdir = i;
}
st25r3916AatLog("\n");
}
if (0!=bestdir)
{ /* Walk into the best direction */
aatStepDacVals(tuningParams, &tuningStatus->aat_a, &tuningStatus->aat_b, bestdir);
}
return bestdir;
}
/*******************************************************************************/
static int32_t aatGreedyDescent(uint32_t *f_min, const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus, int32_t previousDir)
{
uint8_t amp,phs;
uint32_t f;
uint8_t a = tuningStatus->aat_a , b = tuningStatus->aat_b;
if (0U != aatStepDacVals(tuningParams, &a, &b, previousDir))
{ /* If stepping did not change the value, omit this direction */
return 0;
}
aatMeasure(a,b,&amp,&phs,&tuningStatus->measureCnt);
f = aatCalcF(tuningParams, amp, phs);
st25r3916AatLog("g : %d %d: %d",a, b, f);
if (f < *f_min)
{ /* Value is better than previous one */
st25r3916AatLog("*\n");
tuningStatus->aat_a = a;
tuningStatus->aat_b = b;
*f_min = f;
return previousDir;
}
st25r3916AatLog("\n");
return 0;
}
/*******************************************************************************/
static uint32_t aatCalcF(const struct st25r3916AatTuneParams *tuningParams, uint8_t amplitude, uint8_t phase)
{
/* f(amp, pha) = (ampWeight * |amp - ampTarget|) + (phaWeight * |pha - phaTarget|) */
uint8_t ampTarget = tuningParams->ampTarget;
uint8_t phaTarget = tuningParams->phaTarget;
uint32_t ampWeight = tuningParams->ampWeight;
uint32_t phaWeight = tuningParams->phaWeight;
/* Temp variables to avoid MISRA R10.8 (cast on composite expression) */
uint8_t ad = ((amplitude > ampTarget) ? (amplitude - ampTarget) : (ampTarget - amplitude));
uint8_t pd = ((phase > phaTarget) ? (phase - phaTarget) : (phaTarget - phase));
uint32_t ampDelta = (uint32_t)ad;
uint32_t phaDelta = (uint32_t)pd;
return ((ampWeight * ampDelta) + (phaWeight * phaDelta));
}
/*******************************************************************************/
static ReturnCode aatStepDacVals(const struct st25r3916AatTuneParams *tuningParams,uint8_t *a, uint8_t *b, int32_t dir)
{
int16_t aat_a = (int16_t)*a, aat_b = (int16_t)*b;
switch (abs(dir))
{ /* Advance by steps size in requested direction */
case 1:
aat_a = (dir<0)?(aat_a - (int16_t)tuningParams->aat_a_stepWidth):(aat_a + (int16_t)tuningParams->aat_a_stepWidth);
if(aat_a < (int16_t)tuningParams->aat_a_min){ aat_a = (int16_t)tuningParams->aat_a_min; }
if(aat_a > (int16_t)tuningParams->aat_a_max){ aat_a = (int16_t)tuningParams->aat_a_max; }
if ((int16_t)*a == aat_a) {return ERR_PARAM;}
break;
case 2:
aat_b = (dir<0)?(aat_b - (int16_t)tuningParams->aat_b_stepWidth):(aat_b + (int16_t)tuningParams->aat_b_stepWidth);
if(aat_b < (int16_t)tuningParams->aat_b_min){ aat_b = (int16_t)tuningParams->aat_b_min; }
if(aat_b > (int16_t)tuningParams->aat_b_max){ aat_b = (int16_t)tuningParams->aat_b_max; }
if ((int16_t)*b == aat_b) {return ERR_PARAM;}
break;
default:
return ERR_REQUEST;
}
/* We only get here if actual values have changed. In all other cases an error is returned */
*a = (uint8_t)aat_a;
*b = (uint8_t)aat_b;
return ERR_NONE;
}
/*******************************************************************************/
static ReturnCode aatMeasure(uint8_t serCap, uint8_t parCap, uint8_t *amplitude, uint8_t *phase, uint16_t *measureCnt)
{
ReturnCode err;
*amplitude = 0;
*phase = 0;
st25r3916WriteRegister(ST25R3916_REG_ANT_TUNE_A, serCap);
st25r3916WriteRegister(ST25R3916_REG_ANT_TUNE_B, parCap);
/* Wait till caps have settled.. */
platformDelay( ST25R3916_AAT_CAP_DELAY_MAX );
/* Get amplitude and phase .. */
err = rfalChipMeasureAmplitude(amplitude);
if (ERR_NONE == err)
{
err = rfalChipMeasurePhase(phase);
}
if( measureCnt != NULL )
{
(*measureCnt)++;
}
return err;
}

View File

@@ -0,0 +1,113 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file st25r3916_aat.h
*
* \author
*
* \brief ST25R3916 Antenna Tuning
*
* The antenna tuning algorithm tries to find the optimal settings for
* the AAT_A and AAT_B registers, which are connected to variable capacitors
* to tune the antenna matching.
*
*/
#ifndef ST25R3916_AAT_H
#define ST25R3916_AAT_H
#include "platform.h"
#include "st_errno.h"
/*
******************************************************************************
* GLOBAL DATATYPES
******************************************************************************
*/
/*!
* struct representing input parameters for the antenna tuning
*/
struct st25r3916AatTuneParams{
uint8_t aat_a_min; /*!< min value of A cap */
uint8_t aat_a_max; /*!< max value of A cap */
uint8_t aat_a_start; /*!< start value of A cap */
uint8_t aat_a_stepWidth; /*!< increment stepWidth for A cap */
uint8_t aat_b_min; /*!< min value of B cap */
uint8_t aat_b_max; /*!< max value of B cap */
uint8_t aat_b_start; /*!< start value of B cap */
uint8_t aat_b_stepWidth; /*!< increment stepWidth for B cap */
uint8_t phaTarget; /*!< target phase */
uint8_t phaWeight; /*!< weight of target phase */
uint8_t ampTarget; /*!< target amplitude */
uint8_t ampWeight; /*!< weight of target amplitude */
bool doDynamicSteps; /*!< dynamically reduce step size in algo */
uint8_t measureLimit; /*!< max number of allowed steps/measurements */
};
/*!
* struct representing out parameters for the antenna tuning
*/
struct st25r3916AatTuneResult{
uint8_t aat_a; /*!< serial cap after tuning */
uint8_t aat_b; /*!< parallel cap after tuning */
uint8_t pha; /*!< phase after tuning */
uint8_t amp; /*!< amplitude after tuning */
uint16_t measureCnt; /*!< number of measures performed */
};
/*!
*****************************************************************************
* \brief Perform antenna tuning
*
* This function starts an antenna tuning procedure by modifying the serial
* and parallel capacitors of the antenna matching circuit via the AAT_A
* and AAT_B registers.
*
* \param[in] tuningParams : Input parameters for the tuning algorithm. If NULL
* default values will be used.
* \param[out] tuningStatus : Result information of performed tuning. If NULL
* no further information is returned, only registers
* ST25R3916 (AAT_A,B) will be adapted.
*
* \return ERR_IO : Error during communication.
* \return ERR_PARAM : Invalid input parameters
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
extern ReturnCode st25r3916AatTune(const struct st25r3916AatTuneParams *tuningParams, struct st25r3916AatTuneResult *tuningStatus);
#endif /* ST25R3916_AAT_H */

View File

@@ -0,0 +1,649 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief Implementation of ST25R3916 communication
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3916.h"
#include "st25r3916_com.h"
#include "st25r3916_led.h"
#include "st_errno.h"
#include "platform.h"
#include "utils.h"
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
#define ST25R3916_OPTIMIZE true /*!< Optimization switch: false always write value to register */
#define ST25R3916_I2C_ADDR (0xA0U >> 1) /*!< ST25R3916's default I2C address */
#define ST25R3916_REG_LEN 1U /*!< Byte length of a ST25R3916 register */
#define ST25R3916_WRITE_MODE (0U << 6) /*!< ST25R3916 Operation Mode: Write */
#define ST25R3916_READ_MODE (1U << 6) /*!< ST25R3916 Operation Mode: Read */
#define ST25R3916_CMD_MODE (3U << 6) /*!< ST25R3916 Operation Mode: Direct Command */
#define ST25R3916_FIFO_LOAD (0x80U) /*!< ST25R3916 Operation Mode: FIFO Load */
#define ST25R3916_FIFO_READ (0x9FU) /*!< ST25R3916 Operation Mode: FIFO Read */
#define ST25R3916_PT_A_CONFIG_LOAD (0xA0U) /*!< ST25R3916 Operation Mode: Passive Target Memory A-Config Load */
#define ST25R3916_PT_F_CONFIG_LOAD (0xA8U) /*!< ST25R3916 Operation Mode: Passive Target Memory F-Config Load */
#define ST25R3916_PT_TSN_DATA_LOAD (0xACU) /*!< ST25R3916 Operation Mode: Passive Target Memory TSN Load */
#define ST25R3916_PT_MEM_READ (0xBFU) /*!< ST25R3916 Operation Mode: Passive Target Memory Read */
#define ST25R3916_CMD_LEN (1U) /*!< ST25R3916 CMD length */
#define ST25R3916_BUF_LEN (ST25R3916_CMD_LEN+ST25R3916_FIFO_DEPTH) /*!< ST25R3916 communication buffer: CMD + FIFO length */
/*
******************************************************************************
* MACROS
******************************************************************************
*/
#ifdef RFAL_USE_I2C
#define st25r3916I2CStart() platformI2CStart() /*!< ST25R3916 HAL I2C driver macro to start a I2C transfer */
#define st25r3916I2CStop() platformI2CStop() /*!< ST25R3916 HAL I2C driver macro to stop a I2C transfer */
#define st25r3916I2CRepeatStart() platformI2CRepeatStart() /*!< ST25R3916 HAL I2C driver macro to repeat Start */
#define st25r3916I2CSlaveAddrWR( sA ) platformI2CSlaveAddrWR( sA ) /*!< ST25R3916 HAL I2C driver macro to repeat Start */
#define st25r3916I2CSlaveAddrRD( sA ) platformI2CSlaveAddrRD( sA ) /*!< ST25R3916 HAL I2C driver macro to repeat Start */
#endif /* RFAL_USE_I2C */
#if defined(ST25R_COM_SINGLETXRX) && !defined(RFAL_USE_I2C)
static uint8_t comBuf[ST25R3916_BUF_LEN]; /*!< ST25R3916 communication buffer */
static uint16_t comBufIt; /*!< ST25R3916 communication buffer iterator */
#endif /* ST25R_COM_SINGLETXRX */
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
******************************************************************************
* \brief ST25R3916 communication Start
*
* This method performs the required actions to start communications with
* ST25R3916, either by SPI or I2C
******************************************************************************
*/
static void st25r3916comStart( void );
/*!
******************************************************************************
* \brief ST25R3916 communication Stop
*
* This method performs the required actions to terminate communications with
* ST25R3916, either by SPI or I2C
******************************************************************************
*/
static void st25r3916comStop( void );
/*!
******************************************************************************
* \brief ST25R3916 communication Repeat Start
*
* This method performs the required actions to repeat start a transmission
* with ST25R3916, either by SPI or I2C
******************************************************************************
*/
#ifdef RFAL_USE_I2C
static void st25r3916comRepeatStart( void );
#else
#define st25r3916comRepeatStart()
#endif /* RFAL_USE_I2C */
/*!
******************************************************************************
* \brief ST25R3916 communication Tx
*
* This method performs the required actions to transmit the given buffer
* to ST25R3916, either by SPI or I2C
*
* \param[in] txBuf : the buffer to transmit
* \param[in] txLen : the length of the buffer to transmit
* \param[in] last : true if last data to be transmitted
* \param[in] txOnly : true no reception is to be performed
*
******************************************************************************
*/
static void st25r3916comTx( const uint8_t* txBuf, uint16_t txLen, bool last, bool txOnly );
/*!
******************************************************************************
* \brief ST25R3916 communication Rx
*
* This method performs the required actions to receive from ST25R3916 the given
* amount of bytes, either by SPI or I2C
*
* \param[out] rxBuf : the buffer place the received bytes
* \param[in] rxLen : the length to receive
*
******************************************************************************
*/
static void st25r3916comRx( uint8_t* rxBuf, uint16_t rxLen );
/*!
******************************************************************************
* \brief ST25R3916 communication Tx Byte
*
* This helper method transmits a byte passed by value and not by reference
*
* \param[in] txByte : the value of the byte to be transmitted
* \param[in] last : true if last byte to be transmitted
* \param[in] txOnly : true no reception is to be performed
*
******************************************************************************
*/
static void st25r3916comTxByte( uint8_t txByte, bool last, bool txOnly );
/*
******************************************************************************
* LOCAL FUNCTION
******************************************************************************
*/
static void st25r3916comStart( void )
{
/* Make this operation atomic, disabling ST25R3916 interrupt during communications*/
platformProtectST25RComm();
#ifdef RFAL_USE_I2C
/* I2C Start and send Slave Address */
st25r3916I2CStart();
st25r3916I2CSlaveAddrWR( ST25R3916_I2C_ADDR );
#else
/* Perform the chip select */
platformSpiSelect();
#if defined(ST25R_COM_SINGLETXRX)
comBufIt = 0; /* reset local buffer position */
#endif /* ST25R_COM_SINGLETXRX */
#endif /* RFAL_USE_I2C */
}
/*******************************************************************************/
static void st25r3916comStop( void )
{
#ifdef RFAL_USE_I2C
/* Generate Stop signal */
st25r3916I2CStop();
#else
/* Release the chip select */
platformSpiDeselect();
#endif /* RFAL_USE_I2C */
/* reEnable the ST25R3916 interrupt */
platformUnprotectST25RComm();
}
/*******************************************************************************/
#ifdef RFAL_USE_I2C
static void st25r3916comRepeatStart( void )
{
st25r3916I2CRepeatStart();
st25r3916I2CSlaveAddrRD( ST25R3916_I2C_ADDR );
}
#endif /* RFAL_USE_I2C */
/*******************************************************************************/
static void st25r3916comTx( const uint8_t* txBuf, uint16_t txLen, bool last, bool txOnly )
{
NO_WARNING(last);
NO_WARNING(txOnly);
if( txLen > 0U )
{
#ifdef RFAL_USE_I2C
platformI2CTx( txBuf, txLen, last, txOnly );
#else /* RFAL_USE_I2C */
#ifdef ST25R_COM_SINGLETXRX
ST_MEMCPY( &comBuf[comBufIt], txBuf, MIN( txLen, (ST25R3916_BUF_LEN - comBufIt) ) ); /* copy tx data to local buffer */
comBufIt += MIN( txLen, (ST25R3916_BUF_LEN - comBufIt) ); /* store position on local buffer */
if( last && txOnly ) /* only perform SPI transaction if no Rx will follow */
{
platformSpiTxRx( comBuf, NULL, comBufIt );
}
#else
platformSpiTxRx( txBuf, NULL, txLen );
#endif /* ST25R_COM_SINGLETXRX */
#endif /* RFAL_USE_I2C */
}
}
/*******************************************************************************/
static void st25r3916comRx( uint8_t* rxBuf, uint16_t rxLen )
{
if( rxLen > 0U )
{
#ifdef RFAL_USE_I2C
platformI2CRx( rxBuf, rxLen );
#else /* RFAL_USE_I2C */
#ifdef ST25R_COM_SINGLETXRX
ST_MEMSET( &comBuf[comBufIt], 0x00, MIN( rxLen, (ST25R3916_BUF_LEN - comBufIt) ) ); /* clear outgoing buffer */
platformSpiTxRx( comBuf, comBuf, MIN( (comBufIt + rxLen), ST25R3916_BUF_LEN ) ); /* transceive as a single SPI call */
ST_MEMCPY( rxBuf, &comBuf[comBufIt], MIN( rxLen, (ST25R3916_BUF_LEN - comBufIt) ) ); /* copy from local buf to output buffer and skip cmd byte */
#else
if( rxBuf != NULL)
{
ST_MEMSET( rxBuf, 0x00, rxLen ); /* clear outgoing buffer */
}
platformSpiTxRx( NULL, rxBuf, rxLen );
#endif /* ST25R_COM_SINGLETXRX */
#endif /* RFAL_USE_I2C */
}
}
/*******************************************************************************/
static void st25r3916comTxByte( uint8_t txByte, bool last, bool txOnly )
{
uint8_t val = txByte; /* MISRA 17.8: use intermediate variable */
st25r3916comTx( &val, ST25R3916_REG_LEN, last, txOnly );
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode st25r3916ReadRegister( uint8_t reg, uint8_t* val )
{
return st25r3916ReadMultipleRegisters( reg, val, ST25R3916_REG_LEN );
}
/*******************************************************************************/
ReturnCode st25r3916ReadMultipleRegisters( uint8_t reg, uint8_t* values, uint8_t length )
{
if( length > 0U )
{
st25r3916comStart();
/* If is a space-B register send a direct command first */
if( (reg & ST25R3916_SPACE_B) != 0U )
{
st25r3916comTxByte( ST25R3916_CMD_SPACE_B_ACCESS, false, false );
}
st25r3916comTxByte( ((reg & ~ST25R3916_SPACE_B) | ST25R3916_READ_MODE), true, false );
st25r3916comRepeatStart();
st25r3916comRx( values, length );
st25r3916comStop();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916WriteRegister( uint8_t reg, uint8_t val )
{
uint8_t value = val; /* MISRA 17.8: use intermediate variable */
return st25r3916WriteMultipleRegisters( reg, &value, ST25R3916_REG_LEN );
}
/*******************************************************************************/
ReturnCode st25r3916WriteMultipleRegisters( uint8_t reg, const uint8_t* values, uint8_t length )
{
if( length > 0U )
{
st25r3916comStart();
if( (reg & ST25R3916_SPACE_B) != 0U )
{
st25r3916comTxByte( ST25R3916_CMD_SPACE_B_ACCESS, false, true );
}
st25r3916comTxByte( ((reg & ~ST25R3916_SPACE_B) | ST25R3916_WRITE_MODE), false, true );
st25r3916comTx( values, length, true, true );
st25r3916comStop();
/* Send a WriteMultiReg event to LED handling */
st25r3916ledEvtWrMultiReg( reg, values, length);
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916WriteFifo( const uint8_t* values, uint16_t length )
{
if( length > ST25R3916_FIFO_DEPTH )
{
return ERR_PARAM;
}
if( length > 0U )
{
st25r3916comStart();
st25r3916comTxByte( ST25R3916_FIFO_LOAD, false, true );
st25r3916comTx( values, length, true, true );
st25r3916comStop();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916ReadFifo( uint8_t* buf, uint16_t length )
{
if( length > 0U )
{
st25r3916comStart();
st25r3916comTxByte( ST25R3916_FIFO_READ, true, false );
st25r3916comRepeatStart();
st25r3916comRx( buf, length );
st25r3916comStop();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916WritePTMem( const uint8_t* values, uint16_t length )
{
if( length > ST25R3916_PTM_LEN )
{
return ERR_PARAM;
}
if( length > 0U )
{
st25r3916comStart();
st25r3916comTxByte( ST25R3916_PT_A_CONFIG_LOAD, false, true );
st25r3916comTx( values, length, true, true );
st25r3916comStop();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916ReadPTMem( uint8_t* values, uint16_t length )
{
uint8_t tmp[ST25R3916_REG_LEN + ST25R3916_PTM_LEN]; /* local buffer to handle prepended byte on I2C and SPI */
if( length > 0U )
{
if( length > ST25R3916_PTM_LEN )
{
return ERR_PARAM;
}
st25r3916comStart();
st25r3916comTxByte( ST25R3916_PT_MEM_READ, true, false );
st25r3916comRepeatStart();
st25r3916comRx( tmp, (ST25R3916_REG_LEN + length) ); /* skip prepended byte */
st25r3916comStop();
/* Copy PTMem content without prepended byte */
ST_MEMCPY( values, (tmp+ST25R3916_REG_LEN), length );
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916WritePTMemF( const uint8_t* values, uint16_t length )
{
if( length > (ST25R3916_PTM_F_LEN + ST25R3916_PTM_TSN_LEN) )
{
return ERR_PARAM;
}
if( length > 0U )
{
st25r3916comStart();
st25r3916comTxByte( ST25R3916_PT_F_CONFIG_LOAD, false, true );
st25r3916comTx( values, length, true, true );
st25r3916comStop();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916WritePTMemTSN( const uint8_t* values, uint16_t length )
{
if( length > ST25R3916_PTM_TSN_LEN )
{
return ERR_PARAM;
}
if(length > 0U)
{
st25r3916comStart();
st25r3916comTxByte( ST25R3916_PT_TSN_DATA_LOAD, false, true );
st25r3916comTx( values, length, true, true );
st25r3916comStop();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916ExecuteCommand( uint8_t cmd )
{
st25r3916comStart();
st25r3916comTxByte( (cmd | ST25R3916_CMD_MODE ), true, true );
st25r3916comStop();
/* Send a cmd event to LED handling */
st25r3916ledEvtCmd(cmd);
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916ReadTestRegister( uint8_t reg, uint8_t* val )
{
st25r3916comStart();
st25r3916comTxByte( ST25R3916_CMD_TEST_ACCESS, false, false );
st25r3916comTxByte( (reg | ST25R3916_READ_MODE), true, false );
st25r3916comRepeatStart();
st25r3916comRx( val, ST25R3916_REG_LEN );
st25r3916comStop();
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916WriteTestRegister( uint8_t reg, uint8_t val )
{
uint8_t value = val; /* MISRA 17.8: use intermediate variable */
st25r3916comStart();
st25r3916comTxByte( ST25R3916_CMD_TEST_ACCESS, false, true );
st25r3916comTxByte( (reg | ST25R3916_WRITE_MODE), false, true );
st25r3916comTx( &value, ST25R3916_REG_LEN, true, true );
st25r3916comStop();
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3916ClrRegisterBits( uint8_t reg, uint8_t clr_mask )
{
ReturnCode ret;
uint8_t rdVal;
/* Read current reg value */
EXIT_ON_ERR( ret, st25r3916ReadRegister(reg, &rdVal) );
/* Only perform a Write if value to be written is different */
if( ST25R3916_OPTIMIZE && (rdVal == (uint8_t)(rdVal & ~clr_mask)) )
{
return ERR_NONE;
}
/* Write new reg value */
return st25r3916WriteRegister(reg, (uint8_t)(rdVal & ~clr_mask) );
}
/*******************************************************************************/
ReturnCode st25r3916SetRegisterBits( uint8_t reg, uint8_t set_mask )
{
ReturnCode ret;
uint8_t rdVal;
/* Read current reg value */
EXIT_ON_ERR( ret, st25r3916ReadRegister(reg, &rdVal) );
/* Only perform a Write if the value to be written is different */
if( ST25R3916_OPTIMIZE && (rdVal == (rdVal | set_mask)) )
{
return ERR_NONE;
}
/* Write new reg value */
return st25r3916WriteRegister(reg, (rdVal | set_mask) );
}
/*******************************************************************************/
ReturnCode st25r3916ChangeRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value )
{
return st25r3916ModifyRegister(reg, valueMask, (valueMask & value) );
}
/*******************************************************************************/
ReturnCode st25r3916ModifyRegister( uint8_t reg, uint8_t clr_mask, uint8_t set_mask )
{
ReturnCode ret;
uint8_t rdVal;
uint8_t wrVal;
/* Read current reg value */
EXIT_ON_ERR( ret, st25r3916ReadRegister(reg, &rdVal) );
/* Compute new value */
wrVal = (uint8_t)(rdVal & ~clr_mask);
wrVal |= set_mask;
/* Only perform a Write if the value to be written is different */
if( ST25R3916_OPTIMIZE && (rdVal == wrVal) )
{
return ERR_NONE;
}
/* Write new reg value */
return st25r3916WriteRegister(reg, wrVal );
}
/*******************************************************************************/
ReturnCode st25r3916ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value )
{
ReturnCode ret;
uint8_t rdVal;
uint8_t wrVal;
/* Read current reg value */
EXIT_ON_ERR( ret, st25r3916ReadTestRegister(reg, &rdVal) );
/* Compute new value */
wrVal = (uint8_t)(rdVal & ~valueMask);
wrVal |= (uint8_t)(value & valueMask);
/* Only perform a Write if the value to be written is different */
if( ST25R3916_OPTIMIZE && (rdVal == wrVal) )
{
return ERR_NONE;
}
/* Write new reg value */
return st25r3916WriteTestRegister(reg, wrVal );
}
/*******************************************************************************/
bool st25r3916CheckReg( uint8_t reg, uint8_t mask, uint8_t val )
{
uint8_t regVal;
regVal = 0;
st25r3916ReadRegister( reg, &regVal );
return ( (regVal & mask) == val );
}
/*******************************************************************************/
bool st25r3916IsRegValid( uint8_t reg )
{
if( !(( (int16_t)reg >= (int16_t)ST25R3916_REG_IO_CONF1) && (reg <= (ST25R3916_SPACE_B | ST25R3916_REG_IC_IDENTITY)) ))
{
return false;
}
return true;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,262 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief ST25R3916 Interrupt handling
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3916_irq.h"
#include "st25r3916_com.h"
#include "st25r3916_led.h"
#include "st25r3916.h"
#include "utils.h"
/*
******************************************************************************
* LOCAL DATA TYPES
******************************************************************************
*/
/*! Holds current and previous interrupt callback pointer as well as current Interrupt status and mask */
typedef struct
{
void (*prevCallback)(void); /*!< call back function for ST25R3916 interrupt */
void (*callback)(void); /*!< call back function for ST25R3916 interrupt */
uint32_t status; /*!< latest interrupt status */
uint32_t mask; /*!< Interrupt mask. Negative mask = ST25R3916 mask regs */
} st25r3916Interrupt;
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
/*! Length of the interrupt registers */
#define ST25R3916_INT_REGS_LEN ( (ST25R3916_REG_IRQ_TARGET - ST25R3916_REG_IRQ_MAIN) + 1U )
/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/
static volatile st25r3916Interrupt st25r3916interrupt; /*!< Instance of ST25R3916 interrupt */
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void st25r3916InitInterrupts( void )
{
platformIrqST25RPinInitialize();
platformIrqST25RSetCallback( st25r3916Isr );
st25r3916interrupt.callback = NULL;
st25r3916interrupt.prevCallback = NULL;
st25r3916interrupt.status = ST25R3916_IRQ_MASK_NONE;
st25r3916interrupt.mask = ST25R3916_IRQ_MASK_NONE;
}
/*******************************************************************************/
void st25r3916Isr( void )
{
st25r3916CheckForReceivedInterrupts();
// Check if callback is set and run it
if( NULL != st25r3916interrupt.callback )
{
st25r3916interrupt.callback();
}
}
/*******************************************************************************/
void st25r3916CheckForReceivedInterrupts( void )
{
uint8_t iregs[ST25R3916_INT_REGS_LEN];
uint32_t irqStatus;
/* Initialize iregs */
irqStatus = ST25R3916_IRQ_MASK_NONE;
ST_MEMSET( iregs, (int32_t)(ST25R3916_IRQ_MASK_ALL & 0xFFU), ST25R3916_INT_REGS_LEN );
/* In case the IRQ is Edge (not Level) triggered read IRQs until done */
while( platformGpioIsHigh( ST25R_INT_PORT, ST25R_INT_PIN ) )
{
st25r3916ReadMultipleRegisters( ST25R3916_REG_IRQ_MAIN, iregs, ST25R3916_INT_REGS_LEN );
irqStatus |= (uint32_t)iregs[0];
irqStatus |= (uint32_t)iregs[1]<<8;
irqStatus |= (uint32_t)iregs[2]<<16;
irqStatus |= (uint32_t)iregs[3]<<24;
}
/* Forward all interrupts, even masked ones to application */
platformProtectST25RIrqStatus();
st25r3916interrupt.status |= irqStatus;
platformUnprotectST25RIrqStatus();
/* Send an IRQ event to LED handling */
st25r3916ledEvtIrq( st25r3916interrupt.status );
}
/*******************************************************************************/
void st25r3916ModifyInterrupts(uint32_t clr_mask, uint32_t set_mask)
{
uint8_t i;
uint32_t old_mask;
uint32_t new_mask;
old_mask = st25r3916interrupt.mask;
new_mask = ((~old_mask & set_mask) | (old_mask & clr_mask));
st25r3916interrupt.mask &= ~clr_mask;
st25r3916interrupt.mask |= set_mask;
for(i=0; i<ST25R3916_INT_REGS_LEN; i++)
{
if( ((new_mask >> (8U*i)) & 0xFFU) == 0U )
{
continue;
}
st25r3916WriteRegister(ST25R3916_REG_IRQ_MASK_MAIN + i, (uint8_t)((st25r3916interrupt.mask>>(8U*i)) & 0xFFU) );
}
return;
}
/*******************************************************************************/
uint32_t st25r3916WaitForInterruptsTimed( uint32_t mask, uint16_t tmo )
{
uint32_t tmrDelay;
uint32_t status;
tmrDelay = platformTimerCreate( tmo );
/* Run until specific interrupt has happen or the timer has expired */
do
{
status = (st25r3916interrupt.status & mask);
} while( ( !platformTimerIsExpired( tmrDelay ) || (tmo == 0U)) && (status == 0U) );
platformTimerDestroy( tmrDelay );
status = st25r3916interrupt.status & mask;
platformProtectST25RIrqStatus();
st25r3916interrupt.status &= ~status;
platformUnprotectST25RIrqStatus();
return status;
}
/*******************************************************************************/
uint32_t st25r3916GetInterrupt( uint32_t mask )
{
uint32_t irqs;
irqs = (st25r3916interrupt.status & mask);
if(irqs != ST25R3916_IRQ_MASK_NONE)
{
platformProtectST25RIrqStatus();
st25r3916interrupt.status &= ~irqs;
platformUnprotectST25RIrqStatus();
}
return irqs;
}
/*******************************************************************************/
void st25r3916ClearAndEnableInterrupts( uint32_t mask )
{
st25r3916GetInterrupt( mask );
st25r3916EnableInterrupts( mask );
}
/*******************************************************************************/
void st25r3916EnableInterrupts(uint32_t mask)
{
st25r3916ModifyInterrupts(mask, 0);
}
/*******************************************************************************/
void st25r3916DisableInterrupts(uint32_t mask)
{
st25r3916ModifyInterrupts(0, mask);
}
/*******************************************************************************/
void st25r3916ClearInterrupts( void )
{
uint8_t iregs[ST25R3916_INT_REGS_LEN];
st25r3916ReadMultipleRegisters(ST25R3916_REG_IRQ_MAIN, iregs, ST25R3916_INT_REGS_LEN);
platformProtectST25RIrqStatus();
st25r3916interrupt.status = ST25R3916_IRQ_MASK_NONE;
platformUnprotectST25RIrqStatus();
return;
}
/*******************************************************************************/
void st25r3916IRQCallbackSet( void (*cb)(void) )
{
st25r3916interrupt.prevCallback = st25r3916interrupt.callback;
st25r3916interrupt.callback = cb;
}
/*******************************************************************************/
void st25r3916IRQCallbackRestore( void )
{
st25r3916interrupt.callback = st25r3916interrupt.prevCallback;
st25r3916interrupt.prevCallback = NULL;
}

View File

@@ -0,0 +1,264 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief ST25R3916 Interrupt handling
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup ST25R3916
* \brief RFAL ST25R3916 Driver
* @{
*
* \addtogroup ST25R3916_IRQ
* \brief RFAL ST25R3916 IRQ
* @{
*
*/
#ifndef ST25R3916_IRQ_H
#define ST25R3916_IRQ_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define ST25R3916_IRQ_MASK_ALL (uint32_t)(0xFFFFFFFFUL) /*!< All ST25R3916 interrupt sources */
#define ST25R3916_IRQ_MASK_NONE (uint32_t)(0x00000000UL) /*!< No ST25R3916 interrupt source */
/* Main interrupt register */
#define ST25R3916_IRQ_MASK_OSC (uint32_t)(0x00000080U) /*!< ST25R3916 oscillator stable interrupt */
#define ST25R3916_IRQ_MASK_FWL (uint32_t)(0x00000040U) /*!< ST25R3916 FIFO water level interrupt */
#define ST25R3916_IRQ_MASK_RXS (uint32_t)(0x00000020U) /*!< ST25R3916 start of receive interrupt */
#define ST25R3916_IRQ_MASK_RXE (uint32_t)(0x00000010U) /*!< ST25R3916 end of receive interrupt */
#define ST25R3916_IRQ_MASK_TXE (uint32_t)(0x00000008U) /*!< ST25R3916 end of transmission interrupt */
#define ST25R3916_IRQ_MASK_COL (uint32_t)(0x00000004U) /*!< ST25R3916 bit collision interrupt */
#define ST25R3916_IRQ_MASK_RX_REST (uint32_t)(0x00000002U) /*!< ST25R3916 automatic reception restart interrupt */
#define ST25R3916_IRQ_MASK_RFU (uint32_t)(0x00000001U) /*!< ST25R3916 RFU interrupt */
/* Timer and NFC interrupt register */
#define ST25R3916_IRQ_MASK_DCT (uint32_t)(0x00008000U) /*!< ST25R3916 termination of direct command interrupt. */
#define ST25R3916_IRQ_MASK_NRE (uint32_t)(0x00004000U) /*!< ST25R3916 no-response timer expired interrupt */
#define ST25R3916_IRQ_MASK_GPE (uint32_t)(0x00002000U) /*!< ST25R3916 general purpose timer expired interrupt */
#define ST25R3916_IRQ_MASK_EON (uint32_t)(0x00001000U) /*!< ST25R3916 external field on interrupt */
#define ST25R3916_IRQ_MASK_EOF (uint32_t)(0x00000800U) /*!< ST25R3916 external field off interrupt */
#define ST25R3916_IRQ_MASK_CAC (uint32_t)(0x00000400U) /*!< ST25R3916 collision during RF collision avoidance interrupt */
#define ST25R3916_IRQ_MASK_CAT (uint32_t)(0x00000200U) /*!< ST25R3916 minimum guard time expired interrupt */
#define ST25R3916_IRQ_MASK_NFCT (uint32_t)(0x00000100U) /*!< ST25R3916 initiator bit rate recognised interrupt */
/* Error and wake-up interrupt register */
#define ST25R3916_IRQ_MASK_CRC (uint32_t)(0x00800000U) /*!< ST25R3916 CRC error interrupt */
#define ST25R3916_IRQ_MASK_PAR (uint32_t)(0x00400000U) /*!< ST25R3916 parity error interrupt */
#define ST25R3916_IRQ_MASK_ERR2 (uint32_t)(0x00200000U) /*!< ST25R3916 soft framing error interrupt */
#define ST25R3916_IRQ_MASK_ERR1 (uint32_t)(0x00100000U) /*!< ST25R3916 hard framing error interrupt */
#define ST25R3916_IRQ_MASK_WT (uint32_t)(0x00080000U) /*!< ST25R3916 wake-up interrupt */
#define ST25R3916_IRQ_MASK_WAM (uint32_t)(0x00040000U) /*!< ST25R3916 wake-up due to amplitude interrupt */
#define ST25R3916_IRQ_MASK_WPH (uint32_t)(0x00020000U) /*!< ST25R3916 wake-up due to phase interrupt */
#define ST25R3916_IRQ_MASK_WCAP (uint32_t)(0x00010000U) /*!< ST25R3916 wake-up due to capacitance measurement */
/* Passive Target Interrupt Register */
#define ST25R3916_IRQ_MASK_PPON2 (uint32_t)(0x80000000U) /*!< ST25R3916 PPON2 Field on waiting Timer interrupt */
#define ST25R3916_IRQ_MASK_SL_WL (uint32_t)(0x40000000U) /*!< ST25R3916 Passive target slot number water level interrupt */
#define ST25R3916_IRQ_MASK_APON (uint32_t)(0x20000000U) /*!< ST25R3916 Anticollision done and Field On interrupt */
#define ST25R3916_IRQ_MASK_RXE_PTA (uint32_t)(0x10000000U) /*!< ST25R3916 RXE with an automatic response interrupt */
#define ST25R3916_IRQ_MASK_WU_F (uint32_t)(0x08000000U) /*!< ST25R3916 212/424b/s Passive target interrupt: Active */
#define ST25R3916_IRQ_MASK_RFU2 (uint32_t)(0x04000000U) /*!< ST25R3916 RFU2 interrupt */
#define ST25R3916_IRQ_MASK_WU_A_X (uint32_t)(0x02000000U) /*!< ST25R3916 106kb/s Passive target state interrupt: Active* */
#define ST25R3916_IRQ_MASK_WU_A (uint32_t)(0x01000000U) /*!< ST25R3916 106kb/s Passive target state interrupt: Active */
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Wait until an ST25R3916 interrupt occurs
*
* This function is used to access the ST25R3916 interrupt flags. Use this
* to wait for max. \a tmo milliseconds for the \b first interrupt indicated
* with mask \a mask to occur.
*
* \param[in] mask : mask indicating the interrupts to wait for.
* \param[in] tmo : time in milliseconds until timeout occurs. If set to 0
* the functions waits forever.
*
* \return : 0 if timeout occured otherwise a mask indicating the cleared
* interrupts.
*
*****************************************************************************
*/
uint32_t st25r3916WaitForInterruptsTimed( uint32_t mask, uint16_t tmo );
/*!
*****************************************************************************
* \brief Get status for the given interrupt
*
* This function is used to check whether the interrupt given by \a mask
* has occured. If yes the interrupt gets cleared. This function returns
* only status bits which are inside \a mask.
*
* \param[in] mask : mask indicating the interrupt to check for.
*
* \return the mask of the interrupts occurred
*
*****************************************************************************
*/
uint32_t st25r3916GetInterrupt( uint32_t mask );
/*!
*****************************************************************************
* \brief Init the 3916 interrupt
*
* This function is used to check whether the interrupt given by \a mask
* has occured.
*
*****************************************************************************
*/
void st25r3916InitInterrupts( void );
/*!
*****************************************************************************
* \brief Modifies the Interrupt
*
* This function modifies the interrupt
*
* \param[in] clr_mask : bit mask to be cleared on the interrupt mask
* \param[in] set_mask : bit mask to be set on the interrupt mask
*****************************************************************************
*/
void st25r3916ModifyInterrupts( uint32_t clr_mask, uint32_t set_mask );
/*!
*****************************************************************************
* \brief Checks received interrupts
*
* Checks received interrupts and saves the result into global params
*****************************************************************************
*/
void st25r3916CheckForReceivedInterrupts( void );
/*!
*****************************************************************************
* \brief ISR Service routine
*
* This function modiefies the interupt
*****************************************************************************
*/
void st25r3916Isr( void );
/*!
*****************************************************************************
* \brief Enable a given ST25R3916 Interrupt source
*
* This function enables all interrupts given by \a mask,
* ST25R3916_IRQ_MASK_ALL enables all interrupts.
*
* \param[in] mask: mask indicating the interrupts to be enabled
*
*****************************************************************************
*/
void st25r3916EnableInterrupts( uint32_t mask );
/*!
*****************************************************************************
* \brief Disable one or more a given ST25R3916 Interrupt sources
*
* This function disables all interrupts given by \a mask. 0xff disables all.
*
* \param[in] mask: mask indicating the interrupts to be disabled.
*
*****************************************************************************
*/
void st25r3916DisableInterrupts( uint32_t mask );
/*!
*****************************************************************************
* \brief Clear all ST25R3916 irq flags
*
*****************************************************************************
*/
void st25r3916ClearInterrupts( void );
/*!
*****************************************************************************
* \brief Clears and then enables the given ST25R3916 Interrupt sources
*
* \param[in] mask: mask indicating the interrupts to be cleared and enabled
*****************************************************************************
*/
void st25r3916ClearAndEnableInterrupts( uint32_t mask );
/*!
*****************************************************************************
* \brief Sets IRQ callback for the ST25R3916 interrupt
*
*****************************************************************************
*/
void st25r3916IRQCallbackSet( void (*cb)( void ) );
/*!
*****************************************************************************
* \brief Sets IRQ callback for the ST25R3916 interrupt
*
*****************************************************************************
*/
void st25r3916IRQCallbackRestore( void );
#endif /* ST25R3916_IRQ_H */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@@ -0,0 +1,157 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief ST25R3916 LEDs handling
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3916_led.h"
#include "st25r3916_irq.h"
#include "st25r3916_com.h"
#include "st25r3916.h"
/*
******************************************************************************
* MACROS
******************************************************************************
*/
#ifdef PLATFORM_LED_RX_PIN
#define st25r3916ledRxOn() platformLedOn( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN ); /*!< LED Rx Pin On from system HAL */
#define st25r3916ledRxOff() platformLedOff( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN ); /*!< LED Rx Pin Off from system HAL */
#else /* PLATFORM_LED_RX_PIN */
#define st25r3916ledRxOn()
#define st25r3916ledRxOff()
#endif /* PLATFORM_LED_RX_PIN */
#ifdef PLATFORM_LED_FIELD_PIN
#define st25r3916ledFieldOn() platformLedOn( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN ); /*!< LED Field Pin On from system HAL */
#define st25r3916ledFieldOff() platformLedOff( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN ); /*!< LED Field Pin Off from system HAL */
#else /* PLATFORM_LED_FIELD_PIN */
#define st25r3916ledFieldOn()
#define st25r3916ledFieldOff()
#endif /* PLATFORM_LED_FIELD_PIN */
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void st25r3916ledInit( void )
{
/* Initialize LEDs if existing and defined */
platformLedsInitialize();
st25r3916ledRxOff();
st25r3916ledFieldOff();
}
/*******************************************************************************/
void st25r3916ledEvtIrq( uint32_t irqs )
{
if( (irqs & (ST25R3916_IRQ_MASK_TXE | ST25R3916_IRQ_MASK_CAT) ) != 0U )
{
st25r3916ledFieldOn();
}
if( (irqs & (ST25R3916_IRQ_MASK_RXS | ST25R3916_IRQ_MASK_NFCT) ) != 0U )
{
st25r3916ledRxOn();
}
if( (irqs & (ST25R3916_IRQ_MASK_RXE | ST25R3916_IRQ_MASK_NRE | ST25R3916_IRQ_MASK_RX_REST | ST25R3916_IRQ_MASK_RXE_PTA |
ST25R3916_IRQ_MASK_WU_A | ST25R3916_IRQ_MASK_WU_A_X | ST25R3916_IRQ_MASK_WU_F | ST25R3916_IRQ_MASK_RFU2) ) != 0U )
{
st25r3916ledRxOff();
}
}
/*******************************************************************************/
void st25r3916ledEvtWrReg( uint8_t reg, uint8_t val )
{
if( reg == ST25R3916_REG_OP_CONTROL )
{
if( (ST25R3916_REG_OP_CONTROL_tx_en & val) != 0U )
{
st25r3916ledFieldOn();
}
else
{
st25r3916ledFieldOff();
}
}
}
/*******************************************************************************/
void st25r3916ledEvtWrMultiReg( uint8_t reg, const uint8_t* vals, uint8_t len )
{
uint8_t i;
for(i=0; i<(len); i++)
{
st25r3916ledEvtWrReg( (reg+i), vals[i] );
}
}
/*******************************************************************************/
void st25r3916ledEvtCmd( uint8_t cmd )
{
if( (cmd >= ST25R3916_CMD_TRANSMIT_WITH_CRC) && (cmd <= ST25R3916_CMD_RESPONSE_RF_COLLISION_N) )
{
st25r3916ledFieldOff();
}
if( cmd == ST25R3916_CMD_UNMASK_RECEIVE_DATA )
{
st25r3916ledRxOff();
}
if( cmd == ST25R3916_CMD_SET_DEFAULT )
{
st25r3916ledFieldOff();
st25r3916ledRxOff();
}
}

View File

@@ -0,0 +1,153 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2020 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:
*
* 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: ST25R3916 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief ST25R3916 LEDs handling
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup ST25R3916
* \brief RFAL ST25R3916 Driver
* @{
*
* \addtogroup ST25R3916_LED
* \brief RFAL ST25R3916 LED
* @{
*
*/
#ifndef ST25R3916_LED_H
#define ST25R3916_LED_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief ST25R3916 LED Initialize
*
* This function initializes the LEDs that represent ST25R3916 activity
*
*****************************************************************************
*/
void st25r3916ledInit( void );
/*!
*****************************************************************************
* \brief ST25R3916 LED Event Interrupt
*
* This function should be called upon a ST25R3916 Interrupt, providing
* the interrupt event with ST25R3916 irq flags to update LEDs
*
* \param[in] irqs: ST25R3916 irqs mask
*
*****************************************************************************
*/
void st25r3916ledEvtIrq( uint32_t irqs );
/*!
*****************************************************************************
* \brief ST25R3916 LED Event Write Register
*
* This function should be called on a ST25R3916 Write Register operation
* providing the event with the register and value to update LEDs
*
* \param[in] reg: ST25R3916 register to be written
* \param[in] val: value to be written on the register
*
*****************************************************************************
*/
void st25r3916ledEvtWrReg( uint8_t reg, uint8_t val );
/*!
*****************************************************************************
* \brief ST25R3916 LED Event Write Multiple Register
*
* This function should be called upon a ST25R3916 Write Multiple Registers,
* providing the event with the registers and values to update LEDs
*
* \param[in] reg : ST25R3916 first register written
* \param[in] vals: pointer to the values written
* \param[in] len : number of registers written
*
*****************************************************************************
*/
void st25r3916ledEvtWrMultiReg( uint8_t reg, const uint8_t* vals, uint8_t len );
/*!
*****************************************************************************
* \brief ST25R3916 LED Event Direct Command
*
* This function should be called upon a ST25R3916 direct command, providing
* the event with the command executed
*
* \param[in] cmd: ST25R3916 cmd executed
*
*****************************************************************************
*/
void st25r3916ledEvtCmd( uint8_t cmd );
#endif /* ST25R3916_LED_H */
/**
* @}
*
* @}
*
* @}
*
* @}
*/