Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 /**
vpcola 0:f1d3878b8dd9 2 ******************************************************************************
vpcola 0:f1d3878b8dd9 3 * @file SPIRIT_Calibration.c
vpcola 0:f1d3878b8dd9 4 * @author VMA division - AMS
vpcola 0:f1d3878b8dd9 5 * @version 3.2.2
vpcola 0:f1d3878b8dd9 6 * @date 08-July-2015
vpcola 0:f1d3878b8dd9 7 * @brief Configuration and management of SPIRIT VCO-RCO calibration.
vpcola 0:f1d3878b8dd9 8 *
vpcola 0:f1d3878b8dd9 9 * @attention
vpcola 0:f1d3878b8dd9 10 *
vpcola 0:f1d3878b8dd9 11 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:f1d3878b8dd9 12 *
vpcola 0:f1d3878b8dd9 13 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:f1d3878b8dd9 14 * are permitted provided that the following conditions are met:
vpcola 0:f1d3878b8dd9 15 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:f1d3878b8dd9 16 * this list of conditions and the following disclaimer.
vpcola 0:f1d3878b8dd9 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:f1d3878b8dd9 18 * this list of conditions and the following disclaimer in the documentation
vpcola 0:f1d3878b8dd9 19 * and/or other materials provided with the distribution.
vpcola 0:f1d3878b8dd9 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:f1d3878b8dd9 21 * may be used to endorse or promote products derived from this software
vpcola 0:f1d3878b8dd9 22 * without specific prior written permission.
vpcola 0:f1d3878b8dd9 23 *
vpcola 0:f1d3878b8dd9 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:f1d3878b8dd9 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:f1d3878b8dd9 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:f1d3878b8dd9 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:f1d3878b8dd9 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:f1d3878b8dd9 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:f1d3878b8dd9 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:f1d3878b8dd9 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:f1d3878b8dd9 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:f1d3878b8dd9 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:f1d3878b8dd9 34 *
vpcola 0:f1d3878b8dd9 35 ******************************************************************************
vpcola 0:f1d3878b8dd9 36 */
vpcola 0:f1d3878b8dd9 37
vpcola 0:f1d3878b8dd9 38 /* Includes ------------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 39 #include "SPIRIT_Calibration.h"
vpcola 0:f1d3878b8dd9 40 #include "MCU_Interface.h"
vpcola 0:f1d3878b8dd9 41
vpcola 0:f1d3878b8dd9 42
vpcola 0:f1d3878b8dd9 43
vpcola 0:f1d3878b8dd9 44
vpcola 0:f1d3878b8dd9 45 /**
vpcola 0:f1d3878b8dd9 46 * @addtogroup SPIRIT_Libraries
vpcola 0:f1d3878b8dd9 47 * @{
vpcola 0:f1d3878b8dd9 48 */
vpcola 0:f1d3878b8dd9 49
vpcola 0:f1d3878b8dd9 50
vpcola 0:f1d3878b8dd9 51 /**
vpcola 0:f1d3878b8dd9 52 * @addtogroup SPIRIT_Calibration
vpcola 0:f1d3878b8dd9 53 * @{
vpcola 0:f1d3878b8dd9 54 */
vpcola 0:f1d3878b8dd9 55
vpcola 0:f1d3878b8dd9 56
vpcola 0:f1d3878b8dd9 57 /**
vpcola 0:f1d3878b8dd9 58 * @defgroup Calibration_Private_TypesDefinitions Calibration Private Types Definitions
vpcola 0:f1d3878b8dd9 59 * @{
vpcola 0:f1d3878b8dd9 60 */
vpcola 0:f1d3878b8dd9 61
vpcola 0:f1d3878b8dd9 62 /**
vpcola 0:f1d3878b8dd9 63 *@}
vpcola 0:f1d3878b8dd9 64 */
vpcola 0:f1d3878b8dd9 65
vpcola 0:f1d3878b8dd9 66
vpcola 0:f1d3878b8dd9 67 /**
vpcola 0:f1d3878b8dd9 68 * @defgroup Calibration_Private_Defines Calibration Private Defines
vpcola 0:f1d3878b8dd9 69 * @{
vpcola 0:f1d3878b8dd9 70 */
vpcola 0:f1d3878b8dd9 71
vpcola 0:f1d3878b8dd9 72
vpcola 0:f1d3878b8dd9 73 /**
vpcola 0:f1d3878b8dd9 74 *@}
vpcola 0:f1d3878b8dd9 75 */
vpcola 0:f1d3878b8dd9 76
vpcola 0:f1d3878b8dd9 77
vpcola 0:f1d3878b8dd9 78 /**
vpcola 0:f1d3878b8dd9 79 * @defgroup Calibration_Private_Macros Calibration Private Macros
vpcola 0:f1d3878b8dd9 80 * @{
vpcola 0:f1d3878b8dd9 81 */
vpcola 0:f1d3878b8dd9 82
vpcola 0:f1d3878b8dd9 83 /**
vpcola 0:f1d3878b8dd9 84 *@}
vpcola 0:f1d3878b8dd9 85 */
vpcola 0:f1d3878b8dd9 86
vpcola 0:f1d3878b8dd9 87
vpcola 0:f1d3878b8dd9 88 /**
vpcola 0:f1d3878b8dd9 89 * @defgroup Calibration_Private_Variables Calibration Private Variables
vpcola 0:f1d3878b8dd9 90 * @{
vpcola 0:f1d3878b8dd9 91 */
vpcola 0:f1d3878b8dd9 92
vpcola 0:f1d3878b8dd9 93 /**
vpcola 0:f1d3878b8dd9 94 *@}
vpcola 0:f1d3878b8dd9 95 */
vpcola 0:f1d3878b8dd9 96
vpcola 0:f1d3878b8dd9 97
vpcola 0:f1d3878b8dd9 98
vpcola 0:f1d3878b8dd9 99 /**
vpcola 0:f1d3878b8dd9 100 * @defgroup Calibration_Private_FunctionPrototypes Calibration Private Function Prototypes
vpcola 0:f1d3878b8dd9 101 * @{
vpcola 0:f1d3878b8dd9 102 */
vpcola 0:f1d3878b8dd9 103
vpcola 0:f1d3878b8dd9 104 /**
vpcola 0:f1d3878b8dd9 105 *@}
vpcola 0:f1d3878b8dd9 106 */
vpcola 0:f1d3878b8dd9 107
vpcola 0:f1d3878b8dd9 108
vpcola 0:f1d3878b8dd9 109 /**
vpcola 0:f1d3878b8dd9 110 * @defgroup Calibration_Private_Functions Calibration Private Functions
vpcola 0:f1d3878b8dd9 111 * @{
vpcola 0:f1d3878b8dd9 112 */
vpcola 0:f1d3878b8dd9 113
vpcola 0:f1d3878b8dd9 114 /**
vpcola 0:f1d3878b8dd9 115 * @brief Enables or Disables the RCO calibration.
vpcola 0:f1d3878b8dd9 116 * @param xNewState new state for RCO calibration.
vpcola 0:f1d3878b8dd9 117 This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 118 * @retval None.
vpcola 0:f1d3878b8dd9 119 */
vpcola 0:f1d3878b8dd9 120 void SpiritCalibrationRco(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 121 {
vpcola 0:f1d3878b8dd9 122 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 123
vpcola 0:f1d3878b8dd9 124 /* Check the parameters */
vpcola 0:f1d3878b8dd9 125 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 126
vpcola 0:f1d3878b8dd9 127 /* Reads the register value */
vpcola 0:f1d3878b8dd9 128 g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 129
vpcola 0:f1d3878b8dd9 130 /* Build new value for the register */
vpcola 0:f1d3878b8dd9 131 if(xNewState==S_ENABLE)
vpcola 0:f1d3878b8dd9 132 {
vpcola 0:f1d3878b8dd9 133 tempRegValue |= PROTOCOL2_RCO_CALIBRATION_MASK;
vpcola 0:f1d3878b8dd9 134 }
vpcola 0:f1d3878b8dd9 135 else
vpcola 0:f1d3878b8dd9 136 {
vpcola 0:f1d3878b8dd9 137 tempRegValue &= ~PROTOCOL2_RCO_CALIBRATION_MASK;
vpcola 0:f1d3878b8dd9 138 }
vpcola 0:f1d3878b8dd9 139
vpcola 0:f1d3878b8dd9 140 /* Writes register to enable or disable the RCO calibration */
vpcola 0:f1d3878b8dd9 141 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 142
vpcola 0:f1d3878b8dd9 143 }
vpcola 0:f1d3878b8dd9 144
vpcola 0:f1d3878b8dd9 145
vpcola 0:f1d3878b8dd9 146 /**
vpcola 0:f1d3878b8dd9 147 * @brief Enables or Disables the VCO calibration.
vpcola 0:f1d3878b8dd9 148 * @param xNewState new state for VCO calibration.
vpcola 0:f1d3878b8dd9 149 This parameter can be S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 150 * @retval None.
vpcola 0:f1d3878b8dd9 151 */
vpcola 0:f1d3878b8dd9 152 void SpiritCalibrationVco(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 153 {
vpcola 0:f1d3878b8dd9 154 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 155
vpcola 0:f1d3878b8dd9 156 /* Check the parameters */
vpcola 0:f1d3878b8dd9 157 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 158
vpcola 0:f1d3878b8dd9 159 /* Reads the register value */
vpcola 0:f1d3878b8dd9 160 g_xStatus = SpiritSpiReadRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 161
vpcola 0:f1d3878b8dd9 162 /* Build new value for the register */
vpcola 0:f1d3878b8dd9 163 if(xNewState==S_ENABLE)
vpcola 0:f1d3878b8dd9 164 tempRegValue |= PROTOCOL2_VCO_CALIBRATION_MASK;
vpcola 0:f1d3878b8dd9 165 else
vpcola 0:f1d3878b8dd9 166 tempRegValue &= ~PROTOCOL2_VCO_CALIBRATION_MASK;
vpcola 0:f1d3878b8dd9 167
vpcola 0:f1d3878b8dd9 168 /* Writes register to enable or disable the VCO calibration */
vpcola 0:f1d3878b8dd9 169 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL2_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 170
vpcola 0:f1d3878b8dd9 171 }
vpcola 0:f1d3878b8dd9 172
vpcola 0:f1d3878b8dd9 173
vpcola 0:f1d3878b8dd9 174 /**
vpcola 0:f1d3878b8dd9 175 * @brief Sets the RCO calibration words.
vpcola 0:f1d3878b8dd9 176 * @param cRwt RWT word for RCO calibration.
vpcola 0:f1d3878b8dd9 177 * This parameter can be a value of uint8_t.
vpcola 0:f1d3878b8dd9 178 * @param cRfb RFB word for RCO calibration.
vpcola 0:f1d3878b8dd9 179 * This parameter can be a value of uint8_t.
vpcola 0:f1d3878b8dd9 180 * @retval None.
vpcola 0:f1d3878b8dd9 181 */
vpcola 0:f1d3878b8dd9 182 void SpiritCalibrationSetRcoCalWords(uint8_t cRwt, uint8_t cRfb)
vpcola 0:f1d3878b8dd9 183 {
vpcola 0:f1d3878b8dd9 184 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 185
vpcola 0:f1d3878b8dd9 186 /* Build the value of RWT and the MSbits of the RFB word */
vpcola 0:f1d3878b8dd9 187 tempRegValue[0] = (cRwt << 4) | (cRfb >> 1);
vpcola 0:f1d3878b8dd9 188
vpcola 0:f1d3878b8dd9 189 /* Reads the register value to update the LSbit of RFB */
vpcola 0:f1d3878b8dd9 190 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue[1]);
vpcola 0:f1d3878b8dd9 191
vpcola 0:f1d3878b8dd9 192 /* Build new value for the register */
vpcola 0:f1d3878b8dd9 193 tempRegValue[1] = (tempRegValue[1] & 0x7F) | (cRfb<<7);
vpcola 0:f1d3878b8dd9 194
vpcola 0:f1d3878b8dd9 195 /* Writes the new value for RCO calibration words */
vpcola 0:f1d3878b8dd9 196 g_xStatus = SpiritSpiWriteRegisters(RCO_VCO_CALIBR_IN2_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 197
vpcola 0:f1d3878b8dd9 198 }
vpcola 0:f1d3878b8dd9 199
vpcola 0:f1d3878b8dd9 200
vpcola 0:f1d3878b8dd9 201 /**
vpcola 0:f1d3878b8dd9 202 * @brief Returns the RCO calibration words.
vpcola 0:f1d3878b8dd9 203 * @param pcRwt pointer to the variable in which the RWT word has to be stored.
vpcola 0:f1d3878b8dd9 204 * This parameter is a variable of uint8_t*.
vpcola 0:f1d3878b8dd9 205 * @param pcRfb pointer to the variable in which the RFB word has to be stored.
vpcola 0:f1d3878b8dd9 206 * This parameter is a variable of uint8_t*.
vpcola 0:f1d3878b8dd9 207 * @retval None.
vpcola 0:f1d3878b8dd9 208 */
vpcola 0:f1d3878b8dd9 209 void SpiritCalibrationGetRcoCalWords(uint8_t* pcRwt, uint8_t* pcRfb)
vpcola 0:f1d3878b8dd9 210 {
vpcola 0:f1d3878b8dd9 211 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 212
vpcola 0:f1d3878b8dd9 213 /* Reads the registers values */
vpcola 0:f1d3878b8dd9 214 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_OUT1_BASE, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 215
vpcola 0:f1d3878b8dd9 216 /* Build the RWT value */
vpcola 0:f1d3878b8dd9 217 (*pcRwt) = tempRegValue[0] >> 4;
vpcola 0:f1d3878b8dd9 218 /* Build the RFB value */
vpcola 0:f1d3878b8dd9 219 (*pcRfb) = (tempRegValue[0] & 0x0F)<<1 | (tempRegValue[1]>>7);
vpcola 0:f1d3878b8dd9 220
vpcola 0:f1d3878b8dd9 221 }
vpcola 0:f1d3878b8dd9 222
vpcola 0:f1d3878b8dd9 223
vpcola 0:f1d3878b8dd9 224 /**
vpcola 0:f1d3878b8dd9 225 * @brief Returns the VCO calibration data from internal VCO calibrator.
vpcola 0:f1d3878b8dd9 226 * @param None.
vpcola 0:f1d3878b8dd9 227 * @retval uint8_t VCO calibration data word.
vpcola 0:f1d3878b8dd9 228 */
vpcola 0:f1d3878b8dd9 229 uint8_t SpiritCalibrationGetVcoCalData(void)
vpcola 0:f1d3878b8dd9 230 {
vpcola 0:f1d3878b8dd9 231 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 232
vpcola 0:f1d3878b8dd9 233 /* Reads the register value */
vpcola 0:f1d3878b8dd9 234 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_OUT0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 235
vpcola 0:f1d3878b8dd9 236 /* Build and returns the VCO calibration data value */
vpcola 0:f1d3878b8dd9 237 return (tempRegValue & 0x7F);
vpcola 0:f1d3878b8dd9 238
vpcola 0:f1d3878b8dd9 239 }
vpcola 0:f1d3878b8dd9 240
vpcola 0:f1d3878b8dd9 241
vpcola 0:f1d3878b8dd9 242 /**
vpcola 0:f1d3878b8dd9 243 * @brief Sets the VCO calibration data to be used in TX mode.
vpcola 0:f1d3878b8dd9 244 * @param cVcoCalData calibration data word to be set.
vpcola 0:f1d3878b8dd9 245 * This parameter is a variable of uint8_t.
vpcola 0:f1d3878b8dd9 246 * @retval None.
vpcola 0:f1d3878b8dd9 247 */
vpcola 0:f1d3878b8dd9 248 void SpiritCalibrationSetVcoCalDataTx(uint8_t cVcoCalData)
vpcola 0:f1d3878b8dd9 249 {
vpcola 0:f1d3878b8dd9 250 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 251
vpcola 0:f1d3878b8dd9 252 /* Reads the register value */
vpcola 0:f1d3878b8dd9 253 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 254
vpcola 0:f1d3878b8dd9 255 /* Build the value to be written */
vpcola 0:f1d3878b8dd9 256 tempRegValue &= 0x80;
vpcola 0:f1d3878b8dd9 257 tempRegValue |= cVcoCalData;
vpcola 0:f1d3878b8dd9 258
vpcola 0:f1d3878b8dd9 259 /* Writes the new value of calibration data in TX */
vpcola 0:f1d3878b8dd9 260 g_xStatus = SpiritSpiWriteRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 261
vpcola 0:f1d3878b8dd9 262 }
vpcola 0:f1d3878b8dd9 263
vpcola 0:f1d3878b8dd9 264
vpcola 0:f1d3878b8dd9 265 /**
vpcola 0:f1d3878b8dd9 266 * @brief Returns the actual VCO calibration data used in TX mode.
vpcola 0:f1d3878b8dd9 267 * @param None.
vpcola 0:f1d3878b8dd9 268 * @retval uint8_t Calibration data word used in TX mode.
vpcola 0:f1d3878b8dd9 269 */
vpcola 0:f1d3878b8dd9 270 uint8_t SpiritCalibrationGetVcoCalDataTx(void)
vpcola 0:f1d3878b8dd9 271 {
vpcola 0:f1d3878b8dd9 272 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 273
vpcola 0:f1d3878b8dd9 274 /* Reads the register containing the calibration data word used in TX mode */
vpcola 0:f1d3878b8dd9 275 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 276
vpcola 0:f1d3878b8dd9 277 /* Mask the VCO_CALIBR_TX field and returns the value */
vpcola 0:f1d3878b8dd9 278 return (tempRegValue & 0x7F);
vpcola 0:f1d3878b8dd9 279
vpcola 0:f1d3878b8dd9 280 }
vpcola 0:f1d3878b8dd9 281
vpcola 0:f1d3878b8dd9 282
vpcola 0:f1d3878b8dd9 283 /**
vpcola 0:f1d3878b8dd9 284 * @brief Sets the VCO calibration data to be used in RX mode.
vpcola 0:f1d3878b8dd9 285 * @param cVcoCalData calibration data word to be set.
vpcola 0:f1d3878b8dd9 286 * This parameter is a variable of uint8_t.
vpcola 0:f1d3878b8dd9 287 * @retval None.
vpcola 0:f1d3878b8dd9 288 */
vpcola 0:f1d3878b8dd9 289 void SpiritCalibrationSetVcoCalDataRx(uint8_t cVcoCalData)
vpcola 0:f1d3878b8dd9 290 {
vpcola 0:f1d3878b8dd9 291 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 292
vpcola 0:f1d3878b8dd9 293 /* Reads the register value */
vpcola 0:f1d3878b8dd9 294 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 295
vpcola 0:f1d3878b8dd9 296 /* Build the value to be written */
vpcola 0:f1d3878b8dd9 297 tempRegValue &= 0x80;
vpcola 0:f1d3878b8dd9 298 tempRegValue |= cVcoCalData;
vpcola 0:f1d3878b8dd9 299
vpcola 0:f1d3878b8dd9 300 /* Writes the new value of calibration data in RX */
vpcola 0:f1d3878b8dd9 301 g_xStatus = SpiritSpiWriteRegisters(RCO_VCO_CALIBR_IN0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 302
vpcola 0:f1d3878b8dd9 303 }
vpcola 0:f1d3878b8dd9 304
vpcola 0:f1d3878b8dd9 305
vpcola 0:f1d3878b8dd9 306 /**
vpcola 0:f1d3878b8dd9 307 * @brief Returns the actual VCO calibration data used in RX mode.
vpcola 0:f1d3878b8dd9 308 * @param None.
vpcola 0:f1d3878b8dd9 309 * @retval uint8_t Calibration data word used in RX mode.
vpcola 0:f1d3878b8dd9 310 */
vpcola 0:f1d3878b8dd9 311 uint8_t SpiritCalibrationGetVcoCalDataRx(void)
vpcola 0:f1d3878b8dd9 312 {
vpcola 0:f1d3878b8dd9 313 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 314
vpcola 0:f1d3878b8dd9 315 /* Reads the register containing the calibration data word used in TX mode */
vpcola 0:f1d3878b8dd9 316 g_xStatus = SpiritSpiReadRegisters(RCO_VCO_CALIBR_IN0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 317
vpcola 0:f1d3878b8dd9 318 /* Mask the VCO_CALIBR_RX field and returns the value */
vpcola 0:f1d3878b8dd9 319 return (tempRegValue & 0x7F);
vpcola 0:f1d3878b8dd9 320
vpcola 0:f1d3878b8dd9 321 }
vpcola 0:f1d3878b8dd9 322
vpcola 0:f1d3878b8dd9 323
vpcola 0:f1d3878b8dd9 324 /**
vpcola 0:f1d3878b8dd9 325 * @brief Sets the VCO calibration window.
vpcola 0:f1d3878b8dd9 326 * @param xRefWord value of REFWORD corresponding to the Ref_period according to the formula: CALIBRATION_WIN = 11*Ref_period/fxo.
vpcola 0:f1d3878b8dd9 327 This parameter can be a value of @ref VcoWin.
vpcola 0:f1d3878b8dd9 328 * @retval None.
vpcola 0:f1d3878b8dd9 329 */
vpcola 0:f1d3878b8dd9 330 void SpiritCalibrationSetVcoWindow(VcoWin xRefWord)
vpcola 0:f1d3878b8dd9 331 {
vpcola 0:f1d3878b8dd9 332 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 333
vpcola 0:f1d3878b8dd9 334 /* Check the parameters */
vpcola 0:f1d3878b8dd9 335 s_assert_param(IS_VCO_WIN(xRefWord));
vpcola 0:f1d3878b8dd9 336
vpcola 0:f1d3878b8dd9 337 /* Reads the register value */
vpcola 0:f1d3878b8dd9 338 g_xStatus = SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 339
vpcola 0:f1d3878b8dd9 340 /* Build the values to be written */
vpcola 0:f1d3878b8dd9 341 tempRegValue &= 0xFC;
vpcola 0:f1d3878b8dd9 342 tempRegValue |= xRefWord;
vpcola 0:f1d3878b8dd9 343
vpcola 0:f1d3878b8dd9 344 /* Writes the new value of VCO calibration window */
vpcola 0:f1d3878b8dd9 345 g_xStatus = SpiritSpiWriteRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 346
vpcola 0:f1d3878b8dd9 347 }
vpcola 0:f1d3878b8dd9 348
vpcola 0:f1d3878b8dd9 349
vpcola 0:f1d3878b8dd9 350 /**
vpcola 0:f1d3878b8dd9 351 * @brief Returns the VCO calibration window.
vpcola 0:f1d3878b8dd9 352 * @param None.
vpcola 0:f1d3878b8dd9 353 * @retval VcoWin Value of REFWORD corresponding to the Ref_period according to the formula: CALIBRATION_WIN = 11*Ref_period/fxo.
vpcola 0:f1d3878b8dd9 354 * This parameter can be a value of @ref VcoWin.
vpcola 0:f1d3878b8dd9 355 */
vpcola 0:f1d3878b8dd9 356 VcoWin SpiritCalibrationGetVcoWindow(void)
vpcola 0:f1d3878b8dd9 357 {
vpcola 0:f1d3878b8dd9 358 uint8_t tempRegValue1, tempRegValue2;
vpcola 0:f1d3878b8dd9 359 VcoWin refWord;
vpcola 0:f1d3878b8dd9 360
vpcola 0:f1d3878b8dd9 361 /* Reads the register containing the REFWORD value */
vpcola 0:f1d3878b8dd9 362 g_xStatus = SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue1);
vpcola 0:f1d3878b8dd9 363
vpcola 0:f1d3878b8dd9 364 /* Reads the Xtal configuration */
vpcola 0:f1d3878b8dd9 365 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue2);
vpcola 0:f1d3878b8dd9 366
vpcola 0:f1d3878b8dd9 367 /* Mask the REFWORD field */
vpcola 0:f1d3878b8dd9 368 tempRegValue1 &= 0x03;
vpcola 0:f1d3878b8dd9 369
vpcola 0:f1d3878b8dd9 370 /* Mask the 24_26_MHz_SELECT field */
vpcola 0:f1d3878b8dd9 371 tempRegValue2 = ((tempRegValue2 & 0x40)>>6);
vpcola 0:f1d3878b8dd9 372
vpcola 0:f1d3878b8dd9 373 /* In case of 26 MHz crystal */
vpcola 0:f1d3878b8dd9 374 if(tempRegValue2)
vpcola 0:f1d3878b8dd9 375 {
vpcola 0:f1d3878b8dd9 376 switch(tempRegValue1)
vpcola 0:f1d3878b8dd9 377 {
vpcola 0:f1d3878b8dd9 378 case 0:
vpcola 0:f1d3878b8dd9 379 refWord = CALIB_TIME_6_77_US_26MHZ;
vpcola 0:f1d3878b8dd9 380 break;
vpcola 0:f1d3878b8dd9 381 case 1:
vpcola 0:f1d3878b8dd9 382 refWord = CALIB_TIME_13_54_US_26MHZ;
vpcola 0:f1d3878b8dd9 383 break;
vpcola 0:f1d3878b8dd9 384 case 2:
vpcola 0:f1d3878b8dd9 385 refWord = CALIB_TIME_27_08_US_26MHZ;
vpcola 0:f1d3878b8dd9 386 break;
vpcola 0:f1d3878b8dd9 387 case 3:
vpcola 0:f1d3878b8dd9 388 refWord = CALIB_TIME_54_15_US_26MHZ;
vpcola 0:f1d3878b8dd9 389 break;
vpcola 0:f1d3878b8dd9 390 }
vpcola 0:f1d3878b8dd9 391 }
vpcola 0:f1d3878b8dd9 392
vpcola 0:f1d3878b8dd9 393 /* In case of 24 MHz crystal */
vpcola 0:f1d3878b8dd9 394 else
vpcola 0:f1d3878b8dd9 395 {
vpcola 0:f1d3878b8dd9 396 switch(tempRegValue1)
vpcola 0:f1d3878b8dd9 397 {
vpcola 0:f1d3878b8dd9 398 case 0:
vpcola 0:f1d3878b8dd9 399 refWord = CALIB_TIME_7_33_US_24MHZ;
vpcola 0:f1d3878b8dd9 400 break;
vpcola 0:f1d3878b8dd9 401 case 1:
vpcola 0:f1d3878b8dd9 402 refWord = CALIB_TIME_14_67_US_24MHZ;
vpcola 0:f1d3878b8dd9 403 break;
vpcola 0:f1d3878b8dd9 404 case 2:
vpcola 0:f1d3878b8dd9 405 refWord = CALIB_TIME_29_33_US_24MHZ;
vpcola 0:f1d3878b8dd9 406 break;
vpcola 0:f1d3878b8dd9 407 case 3:
vpcola 0:f1d3878b8dd9 408 refWord = CALIB_TIME_58_67_US_24MHZ;
vpcola 0:f1d3878b8dd9 409 break;
vpcola 0:f1d3878b8dd9 410 }
vpcola 0:f1d3878b8dd9 411 }
vpcola 0:f1d3878b8dd9 412
vpcola 0:f1d3878b8dd9 413 return refWord;
vpcola 0:f1d3878b8dd9 414
vpcola 0:f1d3878b8dd9 415 }
vpcola 0:f1d3878b8dd9 416
vpcola 0:f1d3878b8dd9 417 /**
vpcola 0:f1d3878b8dd9 418 * @brief Selects a VCO.
vpcola 0:f1d3878b8dd9 419 * @param xVco can be VCO_H or VCO_L according to which VCO select.
vpcola 0:f1d3878b8dd9 420 * This parameter can be a value of @ref VcoSel.
vpcola 0:f1d3878b8dd9 421 * @retval None.
vpcola 0:f1d3878b8dd9 422 */
vpcola 0:f1d3878b8dd9 423 void SpiritCalibrationSelectVco(VcoSel xVco)
vpcola 0:f1d3878b8dd9 424 {
vpcola 0:f1d3878b8dd9 425 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 426
vpcola 0:f1d3878b8dd9 427 /* Check the parameter */
vpcola 0:f1d3878b8dd9 428 s_assert_param(IS_VCO_SEL(xVco));
vpcola 0:f1d3878b8dd9 429
vpcola 0:f1d3878b8dd9 430 SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 431
vpcola 0:f1d3878b8dd9 432 tempRegValue &= 0xF9;
vpcola 0:f1d3878b8dd9 433
vpcola 0:f1d3878b8dd9 434 if(xVco == VCO_H)
vpcola 0:f1d3878b8dd9 435 {
vpcola 0:f1d3878b8dd9 436 tempRegValue |= 0x02;
vpcola 0:f1d3878b8dd9 437
vpcola 0:f1d3878b8dd9 438 }
vpcola 0:f1d3878b8dd9 439 else
vpcola 0:f1d3878b8dd9 440 {
vpcola 0:f1d3878b8dd9 441 tempRegValue |= 0x04;
vpcola 0:f1d3878b8dd9 442 }
vpcola 0:f1d3878b8dd9 443 SpiritSpiWriteRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 444
vpcola 0:f1d3878b8dd9 445 }
vpcola 0:f1d3878b8dd9 446
vpcola 0:f1d3878b8dd9 447
vpcola 0:f1d3878b8dd9 448
vpcola 0:f1d3878b8dd9 449 /**
vpcola 0:f1d3878b8dd9 450 * @brief Returns the VCO selected.
vpcola 0:f1d3878b8dd9 451 * @param void.
vpcola 0:f1d3878b8dd9 452 * @retval VCO_H or VCO_L according to which VCO selected.
vpcola 0:f1d3878b8dd9 453 * This parameter can be a value of @ref VcoSel.
vpcola 0:f1d3878b8dd9 454 */
vpcola 0:f1d3878b8dd9 455 VcoSel SpiritCalibrationGetVcoSelecttion(void)
vpcola 0:f1d3878b8dd9 456 {
vpcola 0:f1d3878b8dd9 457 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 458
vpcola 0:f1d3878b8dd9 459 SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 460
vpcola 0:f1d3878b8dd9 461 tempRegValue = (tempRegValue>>1)&0x3;
vpcola 0:f1d3878b8dd9 462
vpcola 0:f1d3878b8dd9 463 if(tempRegValue == 0x01)
vpcola 0:f1d3878b8dd9 464 {
vpcola 0:f1d3878b8dd9 465 return VCO_H;
vpcola 0:f1d3878b8dd9 466
vpcola 0:f1d3878b8dd9 467 }
vpcola 0:f1d3878b8dd9 468 else
vpcola 0:f1d3878b8dd9 469 {
vpcola 0:f1d3878b8dd9 470 return VCO_L;
vpcola 0:f1d3878b8dd9 471 }
vpcola 0:f1d3878b8dd9 472
vpcola 0:f1d3878b8dd9 473 }
vpcola 0:f1d3878b8dd9 474
vpcola 0:f1d3878b8dd9 475
vpcola 0:f1d3878b8dd9 476 /**
vpcola 0:f1d3878b8dd9 477 *@}
vpcola 0:f1d3878b8dd9 478 */
vpcola 0:f1d3878b8dd9 479
vpcola 0:f1d3878b8dd9 480 /**
vpcola 0:f1d3878b8dd9 481 *@}
vpcola 0:f1d3878b8dd9 482 */
vpcola 0:f1d3878b8dd9 483
vpcola 0:f1d3878b8dd9 484
vpcola 0:f1d3878b8dd9 485 /**
vpcola 0:f1d3878b8dd9 486 *@}
vpcola 0:f1d3878b8dd9 487 */
vpcola 0:f1d3878b8dd9 488
vpcola 0:f1d3878b8dd9 489
vpcola 0:f1d3878b8dd9 490
vpcola 0:f1d3878b8dd9 491 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/