Added support for the WNC M14A2A Cellular LTE Data Module.
Dependencies: WNC14A2AInterface
SPIRIT_Calibration.c
00001 /** 00002 ****************************************************************************** 00003 * @file SPIRIT_Calibration.c 00004 * @author VMA division - AMS 00005 * @version 3.2.2 00006 * @date 08-July-2015 00007 * @brief Configuration and management of SPIRIT VCO-RCO calibration. 00008 * 00009 * @attention 00010 * 00011 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00012 * 00013 * Redistribution and use in source and binary forms, with or without modification, 00014 * are permitted provided that the following conditions are met: 00015 * 1. Redistributions of source code must retain the above copyright notice, 00016 * this list of conditions and the following disclaimer. 00017 * 2. Redistributions in binary form must reproduce the above copyright notice, 00018 * this list of conditions and the following disclaimer in the documentation 00019 * and/or other materials provided with the distribution. 00020 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00021 * may be used to endorse or promote products derived from this software 00022 * without specific prior written permission. 00023 * 00024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00028 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00029 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00030 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00031 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00032 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00033 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00034 * 00035 ****************************************************************************** 00036 */ 00037 00038 /* Includes ------------------------------------------------------------------*/ 00039 #include "SPIRIT_Calibration.h" 00040 #include "MCU_Interface.h" 00041 00042 00043 00044 00045 /** 00046 * @addtogroup SPIRIT_Libraries 00047 * @{ 00048 */ 00049 00050 00051 /** 00052 * @addtogroup SPIRIT_Calibration 00053 * @{ 00054 */ 00055 00056 00057 /** 00058 * @defgroup Calibration_Private_TypesDefinitions Calibration Private Types Definitions 00059 * @{ 00060 */ 00061 00062 /** 00063 *@} 00064 */ 00065 00066 00067 /** 00068 * @defgroup Calibration_Private_Defines Calibration Private Defines 00069 * @{ 00070 */ 00071 00072 00073 /** 00074 *@} 00075 */ 00076 00077 00078 /** 00079 * @defgroup Calibration_Private_Macros Calibration Private Macros 00080 * @{ 00081 */ 00082 00083 /** 00084 *@} 00085 */ 00086 00087 00088 /** 00089 * @defgroup Calibration_Private_Variables Calibration Private Variables 00090 * @{ 00091 */ 00092 00093 /** 00094 *@} 00095 */ 00096 00097 00098 00099 /** 00100 * @defgroup Calibration_Private_FunctionPrototypes Calibration Private Function Prototypes 00101 * @{ 00102 */ 00103 00104 /** 00105 *@} 00106 */ 00107 00108 00109 /** 00110 * @defgroup Calibration_Private_Functions Calibration Private Functions 00111 * @{ 00112 */ 00113 00114 /** 00115 * @brief Enables or Disables the RCO calibration. 00116 * @param xNewState new state for RCO calibration. 00117 This parameter can be S_ENABLE or S_DISABLE. 00118 * @retval None. 00119 */ 00120 void SpiritCalibrationRco(SpiritFunctionalState xNewState) 00121 { 00122 uint8_t tempRegValue; 00123 00124 /* Check the parameters */ 00125 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00126 00127 /* Reads the register value */ 00128 g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue); 00129 00130 /* Build new value for the register */ 00131 if(xNewState==S_ENABLE) 00132 { 00133 tempRegValue |= PROTOCOL2_RCO_CALIBRATION_MASK; 00134 } 00135 else 00136 { 00137 tempRegValue &= ~PROTOCOL2_RCO_CALIBRATION_MASK; 00138 } 00139 00140 /* Writes register to enable or disable the RCO calibration */ 00141 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue); 00142 00143 } 00144 00145 00146 /** 00147 * @brief Enables or Disables the VCO calibration. 00148 * @param xNewState new state for VCO calibration. 00149 This parameter can be S_ENABLE or S_DISABLE. 00150 * @retval None. 00151 */ 00152 void SpiritCalibrationVco(SpiritFunctionalState xNewState) 00153 { 00154 uint8_t tempRegValue; 00155 00156 /* Check the parameters */ 00157 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00158 00159 /* Reads the register value */ 00160 g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue); 00161 00162 /* Build new value for the register */ 00163 if(xNewState==S_ENABLE) 00164 tempRegValue |= PROTOCOL2_VCO_CALIBRATION_MASK; 00165 else 00166 tempRegValue &= ~PROTOCOL2_VCO_CALIBRATION_MASK; 00167 00168 /* Writes register to enable or disable the VCO calibration */ 00169 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue); 00170 00171 } 00172 00173 00174 /** 00175 * @brief Sets the RCO calibration words. 00176 * @param cRwt RWT word for RCO calibration. 00177 * This parameter can be a value of uint8_t. 00178 * @param cRfb RFB word for RCO calibration. 00179 * This parameter can be a value of uint8_t. 00180 * @retval None. 00181 */ 00182 void SpiritCalibrationSetRcoCalWords(uint8_t cRwt, uint8_t cRfb) 00183 { 00184 uint8_t tempRegValue[2]; 00185 00186 /* Build the value of RWT and the MSbits of the RFB word */ 00187 tempRegValue[0] = (cRwt << 4) | (cRfb >> 1); 00188 00189 /* Reads the register value to update the LSbit of RFB */ 00190 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue[1]); 00191 00192 /* Build new value for the register */ 00193 tempRegValue[1] = (tempRegValue[1] & 0x7F) | (cRfb<<7); 00194 00195 /* Writes the new value for RCO calibration words */ 00196 g_xStatus = SpiritSpiWriteRegisters(RCO_VCO_CALIBR_IN2_BASE, 2, tempRegValue); 00197 00198 } 00199 00200 00201 /** 00202 * @brief Returns the RCO calibration words. 00203 * @param pcRwt pointer to the variable in which the RWT word has to be stored. 00204 * This parameter is a variable of uint8_t*. 00205 * @param pcRfb pointer to the variable in which the RFB word has to be stored. 00206 * This parameter is a variable of uint8_t*. 00207 * @retval None. 00208 */ 00209 void SpiritCalibrationGetRcoCalWords(uint8_t* pcRwt, uint8_t* pcRfb) 00210 { 00211 uint8_t tempRegValue[2]; 00212 00213 /* Reads the registers values */ 00214 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_OUT1_BASE, 2, tempRegValue); 00215 00216 /* Build the RWT value */ 00217 (*pcRwt) = tempRegValue[0] >> 4; 00218 /* Build the RFB value */ 00219 (*pcRfb) = (tempRegValue[0] & 0x0F)<<1 | (tempRegValue[1]>>7); 00220 00221 } 00222 00223 00224 /** 00225 * @brief Returns the VCO calibration data from internal VCO calibrator. 00226 * @param None. 00227 * @retval uint8_t VCO calibration data word. 00228 */ 00229 uint8_t SpiritCalibrationGetVcoCalData(void) 00230 { 00231 uint8_t tempRegValue; 00232 00233 /* Reads the register value */ 00234 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_OUT0_BASE, 1, &tempRegValue); 00235 00236 /* Build and returns the VCO calibration data value */ 00237 return (tempRegValue & 0x7F); 00238 00239 } 00240 00241 00242 /** 00243 * @brief Sets the VCO calibration data to be used in TX mode. 00244 * @param cVcoCalData calibration data word to be set. 00245 * This parameter is a variable of uint8_t. 00246 * @retval None. 00247 */ 00248 void SpiritCalibrationSetVcoCalDataTx(uint8_t cVcoCalData) 00249 { 00250 uint8_t tempRegValue; 00251 00252 /* Reads the register value */ 00253 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue); 00254 00255 /* Build the value to be written */ 00256 tempRegValue &= 0x80; 00257 tempRegValue |= cVcoCalData; 00258 00259 /* Writes the new value of calibration data in TX */ 00260 g_xStatus = SpiritSpiWriteRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue); 00261 00262 } 00263 00264 00265 /** 00266 * @brief Returns the actual VCO calibration data used in TX mode. 00267 * @param None. 00268 * @retval uint8_t Calibration data word used in TX mode. 00269 */ 00270 uint8_t SpiritCalibrationGetVcoCalDataTx(void) 00271 { 00272 uint8_t tempRegValue; 00273 00274 /* Reads the register containing the calibration data word used in TX mode */ 00275 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue); 00276 00277 /* Mask the VCO_CALIBR_TX field and returns the value */ 00278 return (tempRegValue & 0x7F); 00279 00280 } 00281 00282 00283 /** 00284 * @brief Sets the VCO calibration data to be used in RX mode. 00285 * @param cVcoCalData calibration data word to be set. 00286 * This parameter is a variable of uint8_t. 00287 * @retval None. 00288 */ 00289 void SpiritCalibrationSetVcoCalDataRx(uint8_t cVcoCalData) 00290 { 00291 uint8_t tempRegValue; 00292 00293 /* Reads the register value */ 00294 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN0_BASE, 1, &tempRegValue); 00295 00296 /* Build the value to be written */ 00297 tempRegValue &= 0x80; 00298 tempRegValue |= cVcoCalData; 00299 00300 /* Writes the new value of calibration data in RX */ 00301 g_xStatus = SpiritSpiWriteRegisters(RCO_VCO_CALIBR_IN0_BASE, 1, &tempRegValue); 00302 00303 } 00304 00305 00306 /** 00307 * @brief Returns the actual VCO calibration data used in RX mode. 00308 * @param None. 00309 * @retval uint8_t Calibration data word used in RX mode. 00310 */ 00311 uint8_t SpiritCalibrationGetVcoCalDataRx(void) 00312 { 00313 uint8_t tempRegValue; 00314 00315 /* Reads the register containing the calibration data word used in TX mode */ 00316 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN0_BASE, 1, &tempRegValue); 00317 00318 /* Mask the VCO_CALIBR_RX field and returns the value */ 00319 return (tempRegValue & 0x7F); 00320 00321 } 00322 00323 00324 /** 00325 * @brief Sets the VCO calibration window. 00326 * @param xRefWord value of REFWORD corresponding to the Ref_period according to the formula: CALIBRATION_WIN = 11*Ref_period/fxo. 00327 This parameter can be a value of @ref VcoWin. 00328 * @retval None. 00329 */ 00330 void SpiritCalibrationSetVcoWindow(VcoWin xRefWord) 00331 { 00332 uint8_t tempRegValue; 00333 00334 /* Check the parameters */ 00335 s_assert_param(IS_VCO_WIN(xRefWord)); 00336 00337 /* Reads the register value */ 00338 g_xStatus = SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue); 00339 00340 /* Build the values to be written */ 00341 tempRegValue &= 0xFC; 00342 tempRegValue |= xRefWord; 00343 00344 /* Writes the new value of VCO calibration window */ 00345 g_xStatus = SpiritSpiWriteRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue); 00346 00347 } 00348 00349 00350 /** 00351 * @brief Returns the VCO calibration window. 00352 * @param None. 00353 * @retval VcoWin Value of REFWORD corresponding to the Ref_period according to the formula: CALIBRATION_WIN = 11*Ref_period/fxo. 00354 * This parameter can be a value of @ref VcoWin. 00355 */ 00356 VcoWin SpiritCalibrationGetVcoWindow(void) 00357 { 00358 uint8_t tempRegValue1, tempRegValue2; 00359 VcoWin refWord; 00360 00361 /* Reads the register containing the REFWORD value */ 00362 g_xStatus = SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue1); 00363 00364 /* Reads the Xtal configuration */ 00365 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue2); 00366 00367 /* Mask the REFWORD field */ 00368 tempRegValue1 &= 0x03; 00369 00370 /* Mask the 24_26_MHz_SELECT field */ 00371 tempRegValue2 = ((tempRegValue2 & 0x40)>>6); 00372 00373 /* In case of 26 MHz crystal */ 00374 if(tempRegValue2) 00375 { 00376 switch(tempRegValue1) 00377 { 00378 case 0: 00379 refWord = CALIB_TIME_6_77_US_26MHZ; 00380 break; 00381 case 1: 00382 refWord = CALIB_TIME_13_54_US_26MHZ; 00383 break; 00384 case 2: 00385 refWord = CALIB_TIME_27_08_US_26MHZ; 00386 break; 00387 case 3: 00388 refWord = CALIB_TIME_54_15_US_26MHZ; 00389 break; 00390 } 00391 } 00392 00393 /* In case of 24 MHz crystal */ 00394 else 00395 { 00396 switch(tempRegValue1) 00397 { 00398 case 0: 00399 refWord = CALIB_TIME_7_33_US_24MHZ; 00400 break; 00401 case 1: 00402 refWord = CALIB_TIME_14_67_US_24MHZ; 00403 break; 00404 case 2: 00405 refWord = CALIB_TIME_29_33_US_24MHZ; 00406 break; 00407 case 3: 00408 refWord = CALIB_TIME_58_67_US_24MHZ; 00409 break; 00410 } 00411 } 00412 00413 return refWord; 00414 00415 } 00416 00417 /** 00418 * @brief Selects a VCO. 00419 * @param xVco can be VCO_H or VCO_L according to which VCO select. 00420 * This parameter can be a value of @ref VcoSel. 00421 * @retval None. 00422 */ 00423 void SpiritCalibrationSelectVco(VcoSel xVco) 00424 { 00425 uint8_t tempRegValue; 00426 00427 /* Check the parameter */ 00428 s_assert_param(IS_VCO_SEL(xVco)); 00429 00430 SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue); 00431 00432 tempRegValue &= 0xF9; 00433 00434 if(xVco == VCO_H) 00435 { 00436 tempRegValue |= 0x02; 00437 00438 } 00439 else 00440 { 00441 tempRegValue |= 0x04; 00442 } 00443 SpiritSpiWriteRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue); 00444 00445 } 00446 00447 00448 00449 /** 00450 * @brief Returns the VCO selected. 00451 * @param void. 00452 * @retval VCO_H or VCO_L according to which VCO selected. 00453 * This parameter can be a value of @ref VcoSel. 00454 */ 00455 VcoSel SpiritCalibrationGetVcoSelecttion(void) 00456 { 00457 uint8_t tempRegValue; 00458 00459 SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue); 00460 00461 tempRegValue = (tempRegValue>>1)&0x3; 00462 00463 if(tempRegValue == 0x01) 00464 { 00465 return VCO_H; 00466 00467 } 00468 else 00469 { 00470 return VCO_L; 00471 } 00472 00473 } 00474 00475 00476 /** 00477 *@} 00478 */ 00479 00480 /** 00481 *@} 00482 */ 00483 00484 00485 /** 00486 *@} 00487 */ 00488 00489 00490 00491 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 19:09:04 by 1.7.2