Fork of the GitHub

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DiegoOstuni 0:75fc82583a41 1
DiegoOstuni 0:75fc82583a41 2 /******************************************************************************
DiegoOstuni 0:75fc82583a41 3 * @attention
DiegoOstuni 0:75fc82583a41 4 *
DiegoOstuni 0:75fc82583a41 5 * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
DiegoOstuni 0:75fc82583a41 6 *
DiegoOstuni 0:75fc82583a41 7 * Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
DiegoOstuni 0:75fc82583a41 8 * You may not use this file except in compliance with the License.
DiegoOstuni 0:75fc82583a41 9 * You may obtain a copy of the License at:
DiegoOstuni 0:75fc82583a41 10 *
DiegoOstuni 0:75fc82583a41 11 * http://www.st.com/myliberty
DiegoOstuni 0:75fc82583a41 12 *
DiegoOstuni 0:75fc82583a41 13 * Unless required by applicable law or agreed to in writing, software
DiegoOstuni 0:75fc82583a41 14 * distributed under the License is distributed on an "AS IS" BASIS,
DiegoOstuni 0:75fc82583a41 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
DiegoOstuni 0:75fc82583a41 16 * AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
DiegoOstuni 0:75fc82583a41 17 * FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
DiegoOstuni 0:75fc82583a41 18 * See the License for the specific language governing permissions and
DiegoOstuni 0:75fc82583a41 19 * limitations under the License.
DiegoOstuni 0:75fc82583a41 20 *
DiegoOstuni 0:75fc82583a41 21 ******************************************************************************/
DiegoOstuni 0:75fc82583a41 22
DiegoOstuni 0:75fc82583a41 23 /*
DiegoOstuni 0:75fc82583a41 24 * PROJECT: ST25R391x firmware
DiegoOstuni 0:75fc82583a41 25 * $Revision: $
DiegoOstuni 0:75fc82583a41 26 * LANGUAGE: ISO C99
DiegoOstuni 0:75fc82583a41 27 */
DiegoOstuni 0:75fc82583a41 28
DiegoOstuni 0:75fc82583a41 29 /*! \file rfal_analogConfig.c
DiegoOstuni 0:75fc82583a41 30 *
DiegoOstuni 0:75fc82583a41 31 * \author bkam
DiegoOstuni 0:75fc82583a41 32 *
DiegoOstuni 0:75fc82583a41 33 * \brief Funcitons to manage and set analog settings.
DiegoOstuni 0:75fc82583a41 34 *
DiegoOstuni 0:75fc82583a41 35 */
DiegoOstuni 0:75fc82583a41 36
DiegoOstuni 0:75fc82583a41 37 /*
DiegoOstuni 0:75fc82583a41 38 ******************************************************************************
DiegoOstuni 0:75fc82583a41 39 * INCLUDES
DiegoOstuni 0:75fc82583a41 40 ******************************************************************************
DiegoOstuni 0:75fc82583a41 41 */
DiegoOstuni 0:75fc82583a41 42 #include "rfal_analogConfigTbl.h"
DiegoOstuni 0:75fc82583a41 43 #include "rfal_AnalogConfig.h"
DiegoOstuni 0:75fc82583a41 44 #include "rfal_chip.h"
DiegoOstuni 0:75fc82583a41 45 #include "st_errno.h"
DiegoOstuni 0:75fc82583a41 46 #include "platform1.h"
DiegoOstuni 0:75fc82583a41 47 #include "utils.h"
DiegoOstuni 0:75fc82583a41 48
DiegoOstuni 0:75fc82583a41 49 /*
DiegoOstuni 0:75fc82583a41 50 ******************************************************************************
DiegoOstuni 0:75fc82583a41 51 * DEFINES
DiegoOstuni 0:75fc82583a41 52 ******************************************************************************
DiegoOstuni 0:75fc82583a41 53 */
DiegoOstuni 0:75fc82583a41 54
DiegoOstuni 0:75fc82583a41 55 #define RFAL_TEST_REG 0x0080 /*!< Test Register indicator */
DiegoOstuni 0:75fc82583a41 56
DiegoOstuni 0:75fc82583a41 57 /*
DiegoOstuni 0:75fc82583a41 58 ******************************************************************************
DiegoOstuni 0:75fc82583a41 59 * MACROS
DiegoOstuni 0:75fc82583a41 60 ******************************************************************************
DiegoOstuni 0:75fc82583a41 61 */
DiegoOstuni 0:75fc82583a41 62
DiegoOstuni 0:75fc82583a41 63 /*
DiegoOstuni 0:75fc82583a41 64 ******************************************************************************
DiegoOstuni 0:75fc82583a41 65 * LOCAL DATA TYPES
DiegoOstuni 0:75fc82583a41 66 ******************************************************************************
DiegoOstuni 0:75fc82583a41 67 */
DiegoOstuni 0:75fc82583a41 68
DiegoOstuni 0:75fc82583a41 69 #if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
DiegoOstuni 0:75fc82583a41 70 static uint8_t gRfalAnalogConfig[RFAL_ANALOG_CONFIG_TBL_SIZE]; /*!< Analog Configuration Settings List */
DiegoOstuni 0:75fc82583a41 71 #endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
DiegoOstuni 0:75fc82583a41 72
DiegoOstuni 0:75fc82583a41 73
DiegoOstuni 0:75fc82583a41 74 /*! Struct for Analog Config Look Up Table Update */
DiegoOstuni 0:75fc82583a41 75 typedef struct {
DiegoOstuni 0:75fc82583a41 76 uint8_t *currentAnalogConfigTbl; /*!< Reference to start of current Analog Configuration */
DiegoOstuni 0:75fc82583a41 77 uint16_t configTblSize; /*!< Total size of Analog Configuration */
DiegoOstuni 0:75fc82583a41 78 uint8_t ready; /*!< Indicate if Look Up Table is complete and ready for use */
DiegoOstuni 0:75fc82583a41 79 } rfalAnalogConfigMgmt;
DiegoOstuni 0:75fc82583a41 80
DiegoOstuni 0:75fc82583a41 81 static rfalAnalogConfigMgmt gRfalAnalogConfigMgmt; /*!< Analog Configuration LUT management */
DiegoOstuni 0:75fc82583a41 82
DiegoOstuni 0:75fc82583a41 83 /*
DiegoOstuni 0:75fc82583a41 84 ******************************************************************************
DiegoOstuni 0:75fc82583a41 85 * LOCAL TABLES
DiegoOstuni 0:75fc82583a41 86 ******************************************************************************
DiegoOstuni 0:75fc82583a41 87 */
DiegoOstuni 0:75fc82583a41 88
DiegoOstuni 0:75fc82583a41 89 /*
DiegoOstuni 0:75fc82583a41 90 ******************************************************************************
DiegoOstuni 0:75fc82583a41 91 * LOCAL FUNCTION PROTOTYPES
DiegoOstuni 0:75fc82583a41 92 ******************************************************************************
DiegoOstuni 0:75fc82583a41 93 */
DiegoOstuni 0:75fc82583a41 94 static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset );
DiegoOstuni 0:75fc82583a41 95
DiegoOstuni 0:75fc82583a41 96 #if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
DiegoOstuni 0:75fc82583a41 97 static void rfalAnalogConfigPtrUpdate( uint8_t* analogConfigTbl );
DiegoOstuni 0:75fc82583a41 98 #endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
DiegoOstuni 0:75fc82583a41 99
DiegoOstuni 0:75fc82583a41 100 /*
DiegoOstuni 0:75fc82583a41 101 ******************************************************************************
DiegoOstuni 0:75fc82583a41 102 * GLOBAL VARIABLE DEFINITIONS
DiegoOstuni 0:75fc82583a41 103 ******************************************************************************
DiegoOstuni 0:75fc82583a41 104 */
DiegoOstuni 0:75fc82583a41 105
DiegoOstuni 0:75fc82583a41 106 /*
DiegoOstuni 0:75fc82583a41 107 ******************************************************************************
DiegoOstuni 0:75fc82583a41 108 * GLOBAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 109 ******************************************************************************
DiegoOstuni 0:75fc82583a41 110 */
DiegoOstuni 0:75fc82583a41 111
DiegoOstuni 0:75fc82583a41 112 void rfalAnalogConfigInitialize( void )
DiegoOstuni 0:75fc82583a41 113 {
DiegoOstuni 0:75fc82583a41 114 /* Use default Analog configuration settings in Flash by default. */
DiegoOstuni 0:75fc82583a41 115 gRfalAnalogConfigMgmt.currentAnalogConfigTbl = (uint8_t *)rfalAnalogConfigDefaultSettings;
DiegoOstuni 0:75fc82583a41 116 gRfalAnalogConfigMgmt.configTblSize = sizeof(rfalAnalogConfigDefaultSettings);
DiegoOstuni 0:75fc82583a41 117 gRfalAnalogConfigMgmt.ready = true;
DiegoOstuni 0:75fc82583a41 118
DiegoOstuni 0:75fc82583a41 119 } /* rfalAnalogConfigInitialize() */
DiegoOstuni 0:75fc82583a41 120
DiegoOstuni 0:75fc82583a41 121
DiegoOstuni 0:75fc82583a41 122 bool rfalAnalogConfigIsReady( void )
DiegoOstuni 0:75fc82583a41 123 {
DiegoOstuni 0:75fc82583a41 124 return gRfalAnalogConfigMgmt.ready;
DiegoOstuni 0:75fc82583a41 125 }
DiegoOstuni 0:75fc82583a41 126
DiegoOstuni 0:75fc82583a41 127 ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize )
DiegoOstuni 0:75fc82583a41 128 {
DiegoOstuni 0:75fc82583a41 129 #if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
DiegoOstuni 0:75fc82583a41 130
DiegoOstuni 0:75fc82583a41 131 /* Check if the Configuration Table exceed the Table size */
DiegoOstuni 0:75fc82583a41 132 if ( configTblSize >= RFAL_ANALOG_CONFIG_TBL_SIZE )
DiegoOstuni 0:75fc82583a41 133 {
DiegoOstuni 0:75fc82583a41 134 rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
DiegoOstuni 0:75fc82583a41 135 return ERR_NOMEM;
DiegoOstuni 0:75fc82583a41 136 }
DiegoOstuni 0:75fc82583a41 137
DiegoOstuni 0:75fc82583a41 138 /* Check for invalid parameters */
DiegoOstuni 0:75fc82583a41 139 if( configTbl == NULL )
DiegoOstuni 0:75fc82583a41 140 {
DiegoOstuni 0:75fc82583a41 141 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 142 }
DiegoOstuni 0:75fc82583a41 143
DiegoOstuni 0:75fc82583a41 144 /* NOTE: Function does not check for the validity of the Table contents (conf IDs, conf sets, register address) */
DiegoOstuni 0:75fc82583a41 145 ST_MEMCPY( gRfalAnalogConfig, configTbl, configTblSize );
DiegoOstuni 0:75fc82583a41 146
DiegoOstuni 0:75fc82583a41 147 /* Update the total size of configuration settings */
DiegoOstuni 0:75fc82583a41 148 gRfalAnalogConfigMgmt.configTblSize = configTblSize;
DiegoOstuni 0:75fc82583a41 149
DiegoOstuni 0:75fc82583a41 150 rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
DiegoOstuni 0:75fc82583a41 151 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 152
DiegoOstuni 0:75fc82583a41 153 #else
DiegoOstuni 0:75fc82583a41 154
DiegoOstuni 0:75fc82583a41 155 /* If Analog Configuration Update is to be disabled */
DiegoOstuni 0:75fc82583a41 156 NO_WARNING(configTbl);
DiegoOstuni 0:75fc82583a41 157 NO_WARNING(configTblSize);
DiegoOstuni 0:75fc82583a41 158 return ERR_REQUEST;
DiegoOstuni 0:75fc82583a41 159
DiegoOstuni 0:75fc82583a41 160 #endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
DiegoOstuni 0:75fc82583a41 161 }
DiegoOstuni 0:75fc82583a41 162
DiegoOstuni 0:75fc82583a41 163 ReturnCode rfalAnalogConfigListWrite( uint8_t more, rfalAnalogConfig *config )
DiegoOstuni 0:75fc82583a41 164 {
DiegoOstuni 0:75fc82583a41 165 #if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
DiegoOstuni 0:75fc82583a41 166
DiegoOstuni 0:75fc82583a41 167 rfalAnalogConfigId configId;
DiegoOstuni 0:75fc82583a41 168 rfalAnalogConfigNum numConfig;
DiegoOstuni 0:75fc82583a41 169 uint8_t configSize;
DiegoOstuni 0:75fc82583a41 170
DiegoOstuni 0:75fc82583a41 171 if (true == gRfalAnalogConfigMgmt.ready)
DiegoOstuni 0:75fc82583a41 172 { /* First Update to the Configuration list. */
DiegoOstuni 0:75fc82583a41 173 gRfalAnalogConfigMgmt.ready = false; /* invalidate the config List */
DiegoOstuni 0:75fc82583a41 174 gRfalAnalogConfigMgmt.configTblSize = 0; /* Clear the config List */
DiegoOstuni 0:75fc82583a41 175 }
DiegoOstuni 0:75fc82583a41 176
DiegoOstuni 0:75fc82583a41 177 configId = GETU16(config->id);
DiegoOstuni 0:75fc82583a41 178
DiegoOstuni 0:75fc82583a41 179 /* Check validity of the Configuration ID. */
DiegoOstuni 0:75fc82583a41 180 if ( (RFAL_ANALOG_CONFIG_TECH_RFU <= RFAL_ANALOG_CONFIG_ID_GET_TECH(configId))
DiegoOstuni 0:75fc82583a41 181 ||((RFAL_ANALOG_CONFIG_BITRATE_6780 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) && (RFAL_ANALOG_CONFIG_BITRATE_1OF4 > RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)))
DiegoOstuni 0:75fc82583a41 182 ||(RFAL_ANALOG_CONFIG_BITRATE_1OF256 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))
DiegoOstuni 0:75fc82583a41 183 )
DiegoOstuni 0:75fc82583a41 184 {
DiegoOstuni 0:75fc82583a41 185 rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
DiegoOstuni 0:75fc82583a41 186 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 187 }
DiegoOstuni 0:75fc82583a41 188
DiegoOstuni 0:75fc82583a41 189 numConfig = config->num;
DiegoOstuni 0:75fc82583a41 190 configSize = (sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal)));
DiegoOstuni 0:75fc82583a41 191
DiegoOstuni 0:75fc82583a41 192 /* Check if the Configuration Set exceed the Table size. */
DiegoOstuni 0:75fc82583a41 193 if ( RFAL_ANALOG_CONFIG_TBL_SIZE <= (gRfalAnalogConfigMgmt.configTblSize + configSize) )
DiegoOstuni 0:75fc82583a41 194 {
DiegoOstuni 0:75fc82583a41 195 rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
DiegoOstuni 0:75fc82583a41 196 return ERR_NOMEM;
DiegoOstuni 0:75fc82583a41 197 }
DiegoOstuni 0:75fc82583a41 198
DiegoOstuni 0:75fc82583a41 199 /* NOTE: Function does not check for the validity of the Register Address. */
DiegoOstuni 0:75fc82583a41 200 ST_MEMCPY(&gRfalAnalogConfig[gRfalAnalogConfigMgmt.configTblSize], config, configSize);
DiegoOstuni 0:75fc82583a41 201
DiegoOstuni 0:75fc82583a41 202 /* Increment the total size of configuration settings. */
DiegoOstuni 0:75fc82583a41 203 gRfalAnalogConfigMgmt.configTblSize += configSize;
DiegoOstuni 0:75fc82583a41 204
DiegoOstuni 0:75fc82583a41 205 /* Check if it is the last Analog Configuration to load. */
DiegoOstuni 0:75fc82583a41 206 if (RFAL_ANALOG_CONFIG_UPDATE_LAST == more)
DiegoOstuni 0:75fc82583a41 207 { /* Update the Analog Configuration to the new settings. */
DiegoOstuni 0:75fc82583a41 208 rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
DiegoOstuni 0:75fc82583a41 209 }
DiegoOstuni 0:75fc82583a41 210
DiegoOstuni 0:75fc82583a41 211 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 212
DiegoOstuni 0:75fc82583a41 213 #else
DiegoOstuni 0:75fc82583a41 214
DiegoOstuni 0:75fc82583a41 215 /* If Analog Configuration Update is to be disabled */
DiegoOstuni 0:75fc82583a41 216 NO_WARNING(config);
DiegoOstuni 0:75fc82583a41 217 NO_WARNING(more);
DiegoOstuni 0:75fc82583a41 218 return ERR_DISABLED;
DiegoOstuni 0:75fc82583a41 219
DiegoOstuni 0:75fc82583a41 220 #endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
DiegoOstuni 0:75fc82583a41 221
DiegoOstuni 0:75fc82583a41 222 } /* rfalAnalogConfigListUpdate() */
DiegoOstuni 0:75fc82583a41 223
DiegoOstuni 0:75fc82583a41 224 ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize )
DiegoOstuni 0:75fc82583a41 225 {
DiegoOstuni 0:75fc82583a41 226 /* Check if the the current table will fit into the given buffer */
DiegoOstuni 0:75fc82583a41 227 if( tblBufLen < gRfalAnalogConfigMgmt.configTblSize )
DiegoOstuni 0:75fc82583a41 228 {
DiegoOstuni 0:75fc82583a41 229 return ERR_NOMEM;
DiegoOstuni 0:75fc82583a41 230 }
DiegoOstuni 0:75fc82583a41 231
DiegoOstuni 0:75fc82583a41 232 /* Check for invalid parameters */
DiegoOstuni 0:75fc82583a41 233 if( configTblSize == NULL )
DiegoOstuni 0:75fc82583a41 234 {
DiegoOstuni 0:75fc82583a41 235 return ERR_PARAM;
DiegoOstuni 0:75fc82583a41 236 }
DiegoOstuni 0:75fc82583a41 237
DiegoOstuni 0:75fc82583a41 238 /* Copy the whole Table to the given buffer */
DiegoOstuni 0:75fc82583a41 239 ST_MEMCPY( tblBuf, gRfalAnalogConfigMgmt.currentAnalogConfigTbl, gRfalAnalogConfigMgmt.configTblSize );
DiegoOstuni 0:75fc82583a41 240 *configTblSize = gRfalAnalogConfigMgmt.configTblSize;
DiegoOstuni 0:75fc82583a41 241
DiegoOstuni 0:75fc82583a41 242 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 243 }
DiegoOstuni 0:75fc82583a41 244
DiegoOstuni 0:75fc82583a41 245 ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig )
DiegoOstuni 0:75fc82583a41 246 {
DiegoOstuni 0:75fc82583a41 247 uint8_t configSize;
DiegoOstuni 0:75fc82583a41 248 rfalAnalogConfigOffset offset = *configOffset;
DiegoOstuni 0:75fc82583a41 249
DiegoOstuni 0:75fc82583a41 250 /* Check if the number of register-mask-value settings for the respective Configuration ID will fit into the buffer passed in. */
DiegoOstuni 0:75fc82583a41 251 if (gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)] > numConfig)
DiegoOstuni 0:75fc82583a41 252 {
DiegoOstuni 0:75fc82583a41 253 return ERR_NOMEM;
DiegoOstuni 0:75fc82583a41 254 }
DiegoOstuni 0:75fc82583a41 255
DiegoOstuni 0:75fc82583a41 256 /* Get the number of Configuration set */
DiegoOstuni 0:75fc82583a41 257 numConfig = gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)];
DiegoOstuni 0:75fc82583a41 258
DiegoOstuni 0:75fc82583a41 259 /* Pass Configuration Register-Mask-Value sets */
DiegoOstuni 0:75fc82583a41 260 configSize = (sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal)));
DiegoOstuni 0:75fc82583a41 261 ST_MEMCPY( config
DiegoOstuni 0:75fc82583a41 262 , &gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset]
DiegoOstuni 0:75fc82583a41 263 , configSize
DiegoOstuni 0:75fc82583a41 264 );
DiegoOstuni 0:75fc82583a41 265 *configOffset = offset + configSize;
DiegoOstuni 0:75fc82583a41 266
DiegoOstuni 0:75fc82583a41 267 /* Check if it is the last Analog Configuration in the Table.*/
DiegoOstuni 0:75fc82583a41 268 *more = (*configOffset >= gRfalAnalogConfigMgmt.configTblSize) ? RFAL_ANALOG_CONFIG_UPDATE_LAST
DiegoOstuni 0:75fc82583a41 269 : RFAL_ANALOG_CONFIG_UPDATE_MORE;
DiegoOstuni 0:75fc82583a41 270
DiegoOstuni 0:75fc82583a41 271 return ERR_NONE;
DiegoOstuni 0:75fc82583a41 272 } /* rfalAnalogConfigListRead() */
DiegoOstuni 0:75fc82583a41 273
DiegoOstuni 0:75fc82583a41 274
DiegoOstuni 0:75fc82583a41 275 ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId, SPI* mspiChannel, ST25R3911* mST25, DigitalOut* gpio_cs, InterruptIn* IRQ, DigitalOut* fieldLED_01, DigitalOut* fieldLED_02, DigitalOut* fieldLED_03, DigitalOut* fieldLED_04, DigitalOut* fieldLED_05, DigitalOut* fieldLED_06 )
DiegoOstuni 0:75fc82583a41 276 {
DiegoOstuni 0:75fc82583a41 277 rfalAnalogConfigOffset configOffset = 0;
DiegoOstuni 0:75fc82583a41 278 rfalAnalogConfigNum numConfigSet;
DiegoOstuni 0:75fc82583a41 279 rfalAnalogConfigRegAddrMaskVal *configTbl;
DiegoOstuni 0:75fc82583a41 280 ReturnCode retCode = ERR_NONE;
DiegoOstuni 0:75fc82583a41 281 rfalAnalogConfigNum i;
DiegoOstuni 0:75fc82583a41 282
DiegoOstuni 0:75fc82583a41 283 if (true != gRfalAnalogConfigMgmt.ready)
DiegoOstuni 0:75fc82583a41 284 {
DiegoOstuni 0:75fc82583a41 285 return ERR_REQUEST;
DiegoOstuni 0:75fc82583a41 286 }
DiegoOstuni 0:75fc82583a41 287
DiegoOstuni 0:75fc82583a41 288 /* Search LUT for the specific Configuration ID. */
DiegoOstuni 0:75fc82583a41 289 while (RFAL_ANALOG_CONFIG_LUT_NOT_FOUND != (numConfigSet = rfalAnalogConfigSearch(configId, &configOffset)))
DiegoOstuni 0:75fc82583a41 290 {
DiegoOstuni 0:75fc82583a41 291 configTbl = (rfalAnalogConfigRegAddrMaskVal *)( (uint32_t)gRfalAnalogConfigMgmt.currentAnalogConfigTbl + (uint32_t)configOffset);
DiegoOstuni 0:75fc82583a41 292 /* Increment the offset to the next index to search from. */
DiegoOstuni 0:75fc82583a41 293 configOffset += (numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal));
DiegoOstuni 0:75fc82583a41 294
DiegoOstuni 0:75fc82583a41 295 if ((gRfalAnalogConfigMgmt.configTblSize + 1) < configOffset)
DiegoOstuni 0:75fc82583a41 296 { /* Error check make sure that the we do not access outside the configuration Table Size */
DiegoOstuni 0:75fc82583a41 297 return ERR_NOMEM;
DiegoOstuni 0:75fc82583a41 298 }
DiegoOstuni 0:75fc82583a41 299
DiegoOstuni 0:75fc82583a41 300 for ( i = 0; i < numConfigSet; i++)
DiegoOstuni 0:75fc82583a41 301 {
DiegoOstuni 0:75fc82583a41 302 if( GETU16(configTbl[i].addr) & RFAL_TEST_REG )
DiegoOstuni 0:75fc82583a41 303 {
DiegoOstuni 0:75fc82583a41 304 EXIT_ON_ERR(retCode, rfalChipChangeTestRegBits( (GETU16(configTbl[i].addr) & ~RFAL_TEST_REG), configTbl[i].mask, configTbl[i].val, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 305 }
DiegoOstuni 0:75fc82583a41 306 else
DiegoOstuni 0:75fc82583a41 307 {
DiegoOstuni 0:75fc82583a41 308 EXIT_ON_ERR(retCode, rfalChipChangeRegBits( GETU16(configTbl[i].addr), configTbl[i].mask, configTbl[i].val, mspiChannel, mST25, gpio_cs, IRQ, fieldLED_01, fieldLED_02, fieldLED_03, fieldLED_04, fieldLED_05, fieldLED_06 ) );
DiegoOstuni 0:75fc82583a41 309 }
DiegoOstuni 0:75fc82583a41 310 }
DiegoOstuni 0:75fc82583a41 311
DiegoOstuni 0:75fc82583a41 312 } /* while(found Analog Config Id) */
DiegoOstuni 0:75fc82583a41 313
DiegoOstuni 0:75fc82583a41 314 return retCode;
DiegoOstuni 0:75fc82583a41 315
DiegoOstuni 0:75fc82583a41 316 } /* rfalSetAnalogConfig() */
DiegoOstuni 0:75fc82583a41 317
DiegoOstuni 0:75fc82583a41 318 /*
DiegoOstuni 0:75fc82583a41 319 ******************************************************************************
DiegoOstuni 0:75fc82583a41 320 * LOCAL FUNCTIONS
DiegoOstuni 0:75fc82583a41 321 ******************************************************************************
DiegoOstuni 0:75fc82583a41 322 */
DiegoOstuni 0:75fc82583a41 323
DiegoOstuni 0:75fc82583a41 324 /*!
DiegoOstuni 0:75fc82583a41 325 *****************************************************************************
DiegoOstuni 0:75fc82583a41 326 * \brief Update the link to Analog Configuration LUT
DiegoOstuni 0:75fc82583a41 327 *
DiegoOstuni 0:75fc82583a41 328 * Update the link to the Analog Configuration LUT for the subsequent search
DiegoOstuni 0:75fc82583a41 329 * of Analog Settings.
DiegoOstuni 0:75fc82583a41 330 *
DiegoOstuni 0:75fc82583a41 331 * \param[in] analogConfigTbl: reference to the start of the new Analog Configuration Table
DiegoOstuni 0:75fc82583a41 332 *
DiegoOstuni 0:75fc82583a41 333 *****************************************************************************
DiegoOstuni 0:75fc82583a41 334 */
DiegoOstuni 0:75fc82583a41 335 #if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
DiegoOstuni 0:75fc82583a41 336 static void rfalAnalogConfigPtrUpdate( uint8_t* analogConfigTbl )
DiegoOstuni 0:75fc82583a41 337 {
DiegoOstuni 0:75fc82583a41 338
DiegoOstuni 0:75fc82583a41 339 gRfalAnalogConfigMgmt.currentAnalogConfigTbl = analogConfigTbl;
DiegoOstuni 0:75fc82583a41 340 gRfalAnalogConfigMgmt.ready = true;
DiegoOstuni 0:75fc82583a41 341
DiegoOstuni 0:75fc82583a41 342 } /* rfalAnalogConfigPtrUpdate() */
DiegoOstuni 0:75fc82583a41 343 #endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
DiegoOstuni 0:75fc82583a41 344
DiegoOstuni 0:75fc82583a41 345
DiegoOstuni 0:75fc82583a41 346 /*!
DiegoOstuni 0:75fc82583a41 347 *****************************************************************************
DiegoOstuni 0:75fc82583a41 348 * \brief Search the Analog Configuration LUT for a specific Configuration ID.
DiegoOstuni 0:75fc82583a41 349 *
DiegoOstuni 0:75fc82583a41 350 * Search the Analog Configuration LUT for the Configuration ID.
DiegoOstuni 0:75fc82583a41 351 *
DiegoOstuni 0:75fc82583a41 352 * \param[in] configId: Configuration ID to search for.
DiegoOstuni 0:75fc82583a41 353 * \param[in] configOffset: Configuration Offset in Table
DiegoOstuni 0:75fc82583a41 354 *
DiegoOstuni 0:75fc82583a41 355 * \return number of Configuration Sets
DiegoOstuni 0:75fc82583a41 356 * \return #RFAL_ANALOG_CONFIG_LUT_NOT_FOUND in case Configuration ID is not found.
DiegoOstuni 0:75fc82583a41 357 *****************************************************************************
DiegoOstuni 0:75fc82583a41 358 */
DiegoOstuni 0:75fc82583a41 359 static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset )
DiegoOstuni 0:75fc82583a41 360 {
DiegoOstuni 0:75fc82583a41 361 rfalAnalogConfigId foundConfigId;
DiegoOstuni 0:75fc82583a41 362 rfalAnalogConfigId configIdMaskVal;
DiegoOstuni 0:75fc82583a41 363 uint8_t *configTbl;
DiegoOstuni 0:75fc82583a41 364 uint8_t *currentConfigTbl;
DiegoOstuni 0:75fc82583a41 365 uint16_t i;
DiegoOstuni 0:75fc82583a41 366
DiegoOstuni 0:75fc82583a41 367 currentConfigTbl = gRfalAnalogConfigMgmt.currentAnalogConfigTbl;
DiegoOstuni 0:75fc82583a41 368 configIdMaskVal = ((RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK)
DiegoOstuni 0:75fc82583a41 369 |(RFAL_ANALOG_CONFIG_TECH_CHIP == (RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ? RFAL_ANALOG_CONFIG_TECH_MASK : configId)
DiegoOstuni 0:75fc82583a41 370 |(RFAL_ANALOG_CONFIG_NO_DIRECTION == (RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId)) ? RFAL_ANALOG_CONFIG_DIRECTION_MASK : configId)
DiegoOstuni 0:75fc82583a41 371 );
DiegoOstuni 0:75fc82583a41 372
DiegoOstuni 0:75fc82583a41 373 for ( i = *configOffset; i < gRfalAnalogConfigMgmt.configTblSize; )
DiegoOstuni 0:75fc82583a41 374 {
DiegoOstuni 0:75fc82583a41 375 configTbl = &currentConfigTbl[i];
DiegoOstuni 0:75fc82583a41 376 foundConfigId = GETU16(configTbl);
DiegoOstuni 0:75fc82583a41 377 if (configId == (foundConfigId & configIdMaskVal))
DiegoOstuni 0:75fc82583a41 378 {
DiegoOstuni 0:75fc82583a41 379 *configOffset = (i + sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum));
DiegoOstuni 0:75fc82583a41 380 return configTbl[sizeof(rfalAnalogConfigId)];
DiegoOstuni 0:75fc82583a41 381 }
DiegoOstuni 0:75fc82583a41 382
DiegoOstuni 0:75fc82583a41 383 /* If Config Id does not match, increment to next Configuration Id */
DiegoOstuni 0:75fc82583a41 384 i += ( sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum)
DiegoOstuni 0:75fc82583a41 385 + (configTbl[sizeof(rfalAnalogConfigId)] * sizeof(rfalAnalogConfigRegAddrMaskVal) )
DiegoOstuni 0:75fc82583a41 386 );
DiegoOstuni 0:75fc82583a41 387 }
DiegoOstuni 0:75fc82583a41 388
DiegoOstuni 0:75fc82583a41 389 return RFAL_ANALOG_CONFIG_LUT_NOT_FOUND;
DiegoOstuni 0:75fc82583a41 390 } /* rfalAnalogConfigSearch() */