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