2020-10-18 22:09:48 +00:00
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* \attention
|
|
|
|
*
|
|
|
|
* <h2><center>© 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
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/*! \file rfal_analogConfig.c
|
|
|
|
*
|
|
|
|
* \author bkam
|
|
|
|
*
|
|
|
|
* \brief Funcitons to manage and set analog settings.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* INCLUDES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
#include "rfal_analogConfig.h"
|
|
|
|
#include "rfal_chip.h"
|
|
|
|
#include "st_errno.h"
|
|
|
|
#include "platform.h"
|
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/* Check whether the Default Analog settings are to be used or custom ones */
|
|
|
|
#ifdef RFAL_ANALOG_CONFIG_CUSTOM
|
2022-01-05 16:10:18 +00:00
|
|
|
extern const uint8_t* rfalAnalogConfigCustomSettings;
|
|
|
|
extern const uint16_t rfalAnalogConfigCustomSettingsLength;
|
2020-10-18 22:09:48 +00:00
|
|
|
#else
|
2022-01-05 16:10:18 +00:00
|
|
|
#include "rfal_analogConfigTbl.h"
|
2020-10-18 22:09:48 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* DEFINES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
#define RFAL_TEST_REG 0x0080U /*!< Test Register indicator */
|
2020-10-18 22:09:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* MACROS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL DATA TYPES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
|
2022-01-05 16:10:18 +00:00
|
|
|
static uint8_t
|
|
|
|
gRfalAnalogConfig[RFAL_ANALOG_CONFIG_TBL_SIZE]; /*!< Analog Configuration Settings List */
|
2020-10-18 22:09:48 +00:00
|
|
|
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
|
|
|
|
|
|
|
|
/*! Struct for Analog Config Look Up Table Update */
|
|
|
|
typedef struct {
|
2022-01-05 16:10:18 +00:00
|
|
|
const uint8_t*
|
|
|
|
currentAnalogConfigTbl; /*!< Reference to start of current Analog Configuration */
|
|
|
|
uint16_t configTblSize; /*!< Total size of Analog Configuration */
|
|
|
|
bool ready; /*!< Indicate if Look Up Table is complete and ready for use */
|
2020-10-18 22:09:48 +00:00
|
|
|
} rfalAnalogConfigMgmt;
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
static rfalAnalogConfigMgmt gRfalAnalogConfigMgmt; /*!< Analog Configuration LUT management */
|
2020-10-18 22:09:48 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL TABLES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL FUNCTION PROTOTYPES
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
static rfalAnalogConfigNum
|
|
|
|
rfalAnalogConfigSearch(rfalAnalogConfigId configId, uint16_t* configOffset);
|
2020-10-18 22:09:48 +00:00
|
|
|
|
|
|
|
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
|
2022-01-05 16:10:18 +00:00
|
|
|
static void rfalAnalogConfigPtrUpdate(const uint8_t* analogConfigTbl);
|
2020-10-18 22:09:48 +00:00
|
|
|
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL VARIABLE DEFINITIONS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
void rfalAnalogConfigInitialize(void) {
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Use default Analog configuration settings in Flash by default. */
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
/* Check whether the Default Analog settings are to be used or custom ones */
|
2020-10-18 22:09:48 +00:00
|
|
|
#ifdef RFAL_ANALOG_CONFIG_CUSTOM
|
2022-01-05 16:10:18 +00:00
|
|
|
gRfalAnalogConfigMgmt.currentAnalogConfigTbl = (const uint8_t*)&rfalAnalogConfigCustomSettings;
|
|
|
|
gRfalAnalogConfigMgmt.configTblSize = rfalAnalogConfigCustomSettingsLength;
|
|
|
|
#else
|
|
|
|
gRfalAnalogConfigMgmt.currentAnalogConfigTbl =
|
|
|
|
(const uint8_t*)&rfalAnalogConfigDefaultSettings;
|
|
|
|
gRfalAnalogConfigMgmt.configTblSize = sizeof(rfalAnalogConfigDefaultSettings);
|
2020-10-18 22:09:48 +00:00
|
|
|
#endif
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
gRfalAnalogConfigMgmt.ready = true;
|
|
|
|
} /* rfalAnalogConfigInitialize() */
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
bool rfalAnalogConfigIsReady(void) {
|
2020-10-18 22:09:48 +00:00
|
|
|
return gRfalAnalogConfigMgmt.ready;
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalAnalogConfigListWriteRaw(const uint8_t* configTbl, uint16_t configTblSize) {
|
2020-10-18 22:09:48 +00:00
|
|
|
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check if the Configuration Table exceed the Table size */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(configTblSize >= RFAL_ANALOG_CONFIG_TBL_SIZE) {
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
|
|
|
|
return ERR_NOMEM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check for invalid parameters */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((configTbl == NULL) || (configTblSize == 0U)) {
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* NOTE: Function does not check for the validity of the Table contents (conf IDs, conf sets, register address) */
|
2022-01-05 16:10:18 +00:00
|
|
|
ST_MEMCPY(gRfalAnalogConfig, configTbl, configTblSize);
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Update the total size of configuration settings */
|
|
|
|
gRfalAnalogConfigMgmt.configTblSize = configTblSize;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
|
|
|
|
return ERR_NONE;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
#else
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
// If Analog Configuration Update is to be disabled
|
|
|
|
NO_WARNING(configTbl);
|
|
|
|
NO_WARNING(configTblSize);
|
|
|
|
return ERR_REQUEST;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalAnalogConfigListWrite(uint8_t more, const rfalAnalogConfig* config) {
|
2020-10-18 22:09:48 +00:00
|
|
|
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigId configId;
|
|
|
|
rfalAnalogConfigNum numConfig;
|
|
|
|
uint8_t configSize;
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
if(true == gRfalAnalogConfigMgmt.ready) { /* First Update to the Configuration list. */
|
|
|
|
gRfalAnalogConfigMgmt.ready = false; // invalidate the config List
|
2020-10-18 22:09:48 +00:00
|
|
|
gRfalAnalogConfigMgmt.configTblSize = 0; // Clear the config List
|
|
|
|
}
|
|
|
|
|
|
|
|
configId = GETU16(config->id);
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check validity of the Configuration ID. */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((RFAL_ANALOG_CONFIG_TECH_RFU <= RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ||
|
|
|
|
((RFAL_ANALOG_CONFIG_BITRATE_6780 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) &&
|
|
|
|
(RFAL_ANALOG_CONFIG_BITRATE_1OF4 > RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))) ||
|
|
|
|
(RFAL_ANALOG_CONFIG_BITRATE_1OF256 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))) {
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
|
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
numConfig = config->num;
|
2022-01-05 16:10:18 +00:00
|
|
|
configSize =
|
|
|
|
(uint8_t)(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal)));
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check if the Configuration Set exceed the Table size. */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(RFAL_ANALOG_CONFIG_TBL_SIZE <= (gRfalAnalogConfigMgmt.configTblSize + configSize)) {
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
|
|
|
|
return ERR_NOMEM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* NOTE: Function does not check for the validity of the Register Address. */
|
2022-01-05 16:10:18 +00:00
|
|
|
ST_MEMCPY(
|
|
|
|
&gRfalAnalogConfig[gRfalAnalogConfigMgmt.configTblSize],
|
|
|
|
(const uint8_t*)config,
|
|
|
|
configSize);
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Increment the total size of configuration settings. */
|
|
|
|
gRfalAnalogConfigMgmt.configTblSize += configSize;
|
|
|
|
|
|
|
|
/* Check if it is the last Analog Configuration to load. */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(RFAL_ANALOG_CONFIG_UPDATE_LAST ==
|
|
|
|
more) { /* Update the Analog Configuration to the new settings. */
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_NONE;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
#else
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
// If Analog Configuration Update is to be disabled
|
|
|
|
NO_WARNING(config);
|
|
|
|
NO_WARNING(more);
|
|
|
|
return ERR_DISABLED;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
} /* rfalAnalogConfigListUpdate() */
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode
|
|
|
|
rfalAnalogConfigListReadRaw(uint8_t* tblBuf, uint16_t tblBufLen, uint16_t* configTblSize) {
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check if the the current table will fit into the given buffer */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(tblBufLen < gRfalAnalogConfigMgmt.configTblSize) {
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_NOMEM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check for invalid parameters */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(configTblSize == NULL) {
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_PARAM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Copy the whole Table to the given buffer */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(gRfalAnalogConfigMgmt.configTblSize > 0U) /* MISRA 21.18 */
|
2020-10-18 22:09:48 +00:00
|
|
|
{
|
2022-01-05 16:10:18 +00:00
|
|
|
ST_MEMCPY(
|
|
|
|
tblBuf,
|
|
|
|
gRfalAnalogConfigMgmt.currentAnalogConfigTbl,
|
|
|
|
gRfalAnalogConfigMgmt.configTblSize);
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
|
|
|
*configTblSize = gRfalAnalogConfigMgmt.configTblSize;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_NONE;
|
|
|
|
}
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalAnalogConfigListRead(
|
|
|
|
rfalAnalogConfigOffset* configOffset,
|
|
|
|
uint8_t* more,
|
|
|
|
rfalAnalogConfig* config,
|
|
|
|
rfalAnalogConfigNum numConfig) {
|
2020-10-18 22:09:48 +00:00
|
|
|
uint16_t configSize;
|
|
|
|
rfalAnalogConfigOffset offset = *configOffset;
|
|
|
|
rfalAnalogConfigNum numConfigSet;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check if the number of register-mask-value settings for the respective Configuration ID will fit into the buffer passed in. */
|
2022-01-05 16:10:18 +00:00
|
|
|
if(gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)] >
|
|
|
|
numConfig) {
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the number of Configuration set */
|
2022-01-05 16:10:18 +00:00
|
|
|
numConfigSet =
|
|
|
|
gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)];
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Pass Configuration Register-Mask-Value sets */
|
2022-01-05 16:10:18 +00:00
|
|
|
configSize =
|
|
|
|
(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) +
|
|
|
|
(uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal)));
|
|
|
|
ST_MEMCPY((uint8_t*)config, &gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset], configSize);
|
2020-10-18 22:09:48 +00:00
|
|
|
*configOffset = offset + configSize;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Check if it is the last Analog Configuration in the Table.*/
|
2022-01-05 16:10:18 +00:00
|
|
|
*more =
|
|
|
|
(uint8_t)((*configOffset >= gRfalAnalogConfigMgmt.configTblSize) ? RFAL_ANALOG_CONFIG_UPDATE_LAST : RFAL_ANALOG_CONFIG_UPDATE_MORE);
|
2020-10-18 22:09:48 +00:00
|
|
|
|
|
|
|
return ERR_NONE;
|
|
|
|
} /* rfalAnalogConfigListRead() */
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
ReturnCode rfalSetAnalogConfig(rfalAnalogConfigId configId) {
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigOffset configOffset = 0;
|
|
|
|
rfalAnalogConfigNum numConfigSet;
|
2022-01-05 16:10:18 +00:00
|
|
|
const rfalAnalogConfigRegAddrMaskVal* configTbl;
|
2020-10-18 22:09:48 +00:00
|
|
|
ReturnCode retCode = ERR_NONE;
|
|
|
|
rfalAnalogConfigNum i;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
if(true != gRfalAnalogConfigMgmt.ready) {
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_REQUEST;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Search LUT for the specific Configuration ID. */
|
2022-01-05 16:10:18 +00:00
|
|
|
while(true) {
|
2020-10-18 22:09:48 +00:00
|
|
|
numConfigSet = rfalAnalogConfigSearch(configId, &configOffset);
|
2022-01-05 16:10:18 +00:00
|
|
|
if(RFAL_ANALOG_CONFIG_LUT_NOT_FOUND == numConfigSet) {
|
2020-10-18 22:09:48 +00:00
|
|
|
break;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
configTbl =
|
|
|
|
(rfalAnalogConfigRegAddrMaskVal*)((uint32_t)gRfalAnalogConfigMgmt.currentAnalogConfigTbl + (uint32_t)configOffset);
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Increment the offset to the next index to search from. */
|
2022-01-05 16:10:18 +00:00
|
|
|
configOffset += (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal));
|
|
|
|
|
|
|
|
if((gRfalAnalogConfigMgmt.configTblSize + 1U) <
|
|
|
|
configOffset) { /* Error check make sure that the we do not access outside the configuration Table Size */
|
2020-10-18 22:09:48 +00:00
|
|
|
return ERR_NOMEM;
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
|
|
|
for(i = 0; i < numConfigSet; i++) {
|
|
|
|
if((GETU16(configTbl[i].addr) & RFAL_TEST_REG) != 0U) {
|
|
|
|
EXIT_ON_ERR(
|
|
|
|
retCode,
|
|
|
|
rfalChipChangeTestRegBits(
|
|
|
|
(GETU16(configTbl[i].addr) & ~RFAL_TEST_REG),
|
|
|
|
configTbl[i].mask,
|
|
|
|
configTbl[i].val));
|
|
|
|
} else {
|
|
|
|
EXIT_ON_ERR(
|
|
|
|
retCode,
|
|
|
|
rfalChipChangeRegBits(
|
|
|
|
GETU16(configTbl[i].addr), configTbl[i].mask, configTbl[i].val));
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
} /* while(found Analog Config Id) */
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
return retCode;
|
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
} /* rfalSetAnalogConfig() */
|
2020-10-18 22:09:48 +00:00
|
|
|
|
2022-01-05 16:10:18 +00:00
|
|
|
uint16_t rfalAnalogConfigGenModeID(rfalMode md, rfalBitRate br, uint16_t dir) {
|
2020-10-18 22:09:48 +00:00
|
|
|
uint16_t id;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Assign Poll/Listen Mode */
|
|
|
|
id = ((md >= RFAL_MODE_LISTEN_NFCA) ? RFAL_ANALOG_CONFIG_LISTEN : RFAL_ANALOG_CONFIG_POLL);
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Assign Technology */
|
2022-01-05 16:10:18 +00:00
|
|
|
switch(md) {
|
|
|
|
case RFAL_MODE_POLL_NFCA:
|
|
|
|
case RFAL_MODE_POLL_NFCA_T1T:
|
|
|
|
case RFAL_MODE_LISTEN_NFCA:
|
|
|
|
id |= RFAL_ANALOG_CONFIG_TECH_NFCA;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RFAL_MODE_POLL_NFCB:
|
|
|
|
case RFAL_MODE_POLL_B_PRIME:
|
|
|
|
case RFAL_MODE_POLL_B_CTS:
|
|
|
|
case RFAL_MODE_LISTEN_NFCB:
|
|
|
|
id |= RFAL_ANALOG_CONFIG_TECH_NFCB;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RFAL_MODE_POLL_NFCF:
|
|
|
|
case RFAL_MODE_LISTEN_NFCF:
|
|
|
|
id |= RFAL_ANALOG_CONFIG_TECH_NFCF;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RFAL_MODE_POLL_NFCV:
|
|
|
|
case RFAL_MODE_POLL_PICOPASS:
|
|
|
|
id |= RFAL_ANALOG_CONFIG_TECH_NFCV;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RFAL_MODE_POLL_ACTIVE_P2P:
|
|
|
|
case RFAL_MODE_LISTEN_ACTIVE_P2P:
|
|
|
|
id |= RFAL_ANALOG_CONFIG_TECH_AP2P;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
id = RFAL_ANALOG_CONFIG_TECH_CHIP;
|
|
|
|
break;
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Assign Bitrate */
|
2022-01-05 16:10:18 +00:00
|
|
|
id |=
|
|
|
|
(((((uint16_t)(br) >= (uint16_t)RFAL_BR_52p97) ? (uint16_t)(br) : ((uint16_t)(br) + 1U))
|
|
|
|
<< RFAL_ANALOG_CONFIG_BITRATE_SHIFT) &
|
|
|
|
RFAL_ANALOG_CONFIG_BITRATE_MASK);
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* Assign Direction */
|
2022-01-05 16:10:18 +00:00
|
|
|
id |= ((dir << RFAL_ANALOG_CONFIG_DIRECTION_SHIFT) & RFAL_ANALOG_CONFIG_DIRECTION_MASK);
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
return id;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
} /* rfalAnalogConfigGenModeID() */
|
|
|
|
|
|
|
|
/*
|
|
|
|
******************************************************************************
|
|
|
|
* LOCAL FUNCTIONS
|
|
|
|
******************************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*****************************************************************************
|
|
|
|
* \brief Update the link to Analog Configuration LUT
|
|
|
|
*
|
|
|
|
* Update the link to the Analog Configuration LUT for the subsequent search
|
|
|
|
* of Analog Settings.
|
|
|
|
*
|
|
|
|
* \param[in] analogConfigTbl: reference to the start of the new Analog Configuration Table
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
|
|
|
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
|
2022-01-05 16:10:18 +00:00
|
|
|
static void rfalAnalogConfigPtrUpdate(const uint8_t* analogConfigTbl) {
|
2020-10-18 22:09:48 +00:00
|
|
|
gRfalAnalogConfigMgmt.currentAnalogConfigTbl = analogConfigTbl;
|
|
|
|
gRfalAnalogConfigMgmt.ready = true;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
} /* rfalAnalogConfigPtrUpdate() */
|
|
|
|
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
|
|
|
|
|
|
|
|
/*!
|
|
|
|
*****************************************************************************
|
|
|
|
* \brief Search the Analog Configuration LUT for a specific Configuration ID.
|
|
|
|
*
|
|
|
|
* Search the Analog Configuration LUT for the Configuration ID.
|
|
|
|
*
|
|
|
|
* \param[in] configId: Configuration ID to search for.
|
|
|
|
* \param[in] configOffset: Configuration Offset in Table
|
|
|
|
*
|
|
|
|
* \return number of Configuration Sets
|
|
|
|
* \return #RFAL_ANALOG_CONFIG_LUT_NOT_FOUND in case Configuration ID is not found.
|
|
|
|
*****************************************************************************
|
|
|
|
*/
|
2022-01-05 16:10:18 +00:00
|
|
|
static rfalAnalogConfigNum
|
|
|
|
rfalAnalogConfigSearch(rfalAnalogConfigId configId, uint16_t* configOffset) {
|
2020-10-18 22:09:48 +00:00
|
|
|
rfalAnalogConfigId foundConfigId;
|
|
|
|
rfalAnalogConfigId configIdMaskVal;
|
2022-01-05 16:10:18 +00:00
|
|
|
const uint8_t* configTbl;
|
|
|
|
const uint8_t* currentConfigTbl;
|
2020-10-18 22:09:48 +00:00
|
|
|
uint16_t i;
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
currentConfigTbl = gRfalAnalogConfigMgmt.currentAnalogConfigTbl;
|
2022-01-05 16:10:18 +00:00
|
|
|
configIdMaskVal =
|
|
|
|
((RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK) |
|
|
|
|
((RFAL_ANALOG_CONFIG_TECH_CHIP == RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ?
|
|
|
|
(RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK) :
|
|
|
|
configId) |
|
|
|
|
((RFAL_ANALOG_CONFIG_NO_DIRECTION == RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId)) ?
|
|
|
|
RFAL_ANALOG_CONFIG_DIRECTION_MASK :
|
|
|
|
configId));
|
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* When specific ConfigIDs are to be used, override search mask */
|
2022-01-05 16:10:18 +00:00
|
|
|
if((RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId) == RFAL_ANALOG_CONFIG_DPO)) {
|
|
|
|
configIdMaskVal =
|
|
|
|
(RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_TECH_MASK |
|
|
|
|
RFAL_ANALOG_CONFIG_BITRATE_MASK | RFAL_ANALOG_CONFIG_DIRECTION_MASK);
|
2020-10-18 22:09:48 +00:00
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
i = *configOffset;
|
2022-01-05 16:10:18 +00:00
|
|
|
while(i < gRfalAnalogConfigMgmt.configTblSize) {
|
2020-10-18 22:09:48 +00:00
|
|
|
configTbl = ¤tConfigTbl[i];
|
|
|
|
foundConfigId = GETU16(configTbl);
|
2022-01-05 16:10:18 +00:00
|
|
|
if(configId == (foundConfigId & configIdMaskVal)) {
|
|
|
|
*configOffset =
|
|
|
|
(uint16_t)(i + sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum));
|
2020-10-18 22:09:48 +00:00
|
|
|
return configTbl[sizeof(rfalAnalogConfigId)];
|
|
|
|
}
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
/* If Config Id does not match, increment to next Configuration Id */
|
2022-01-05 16:10:18 +00:00
|
|
|
i +=
|
|
|
|
(uint16_t)(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (configTbl[sizeof(rfalAnalogConfigId)] * sizeof(rfalAnalogConfigRegAddrMaskVal)));
|
2020-10-18 22:09:48 +00:00
|
|
|
} /* for */
|
2022-01-05 16:10:18 +00:00
|
|
|
|
2020-10-18 22:09:48 +00:00
|
|
|
return RFAL_ANALOG_CONFIG_LUT_NOT_FOUND;
|
|
|
|
} /* rfalAnalogConfigSearch() */
|