Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:a1734fe1ec4b 1 /**
vpcola 0:a1734fe1ec4b 2 ******************************************************************************
vpcola 0:a1734fe1ec4b 3 * @file SPIRIT_Radio.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 This file provides all the low level API to manage Analog and Digital
vpcola 0:a1734fe1ec4b 8 * radio part of SPIRIT.
vpcola 0:a1734fe1ec4b 9 * @details
vpcola 0:a1734fe1ec4b 10 *
vpcola 0:a1734fe1ec4b 11 * @attention
vpcola 0:a1734fe1ec4b 12 *
vpcola 0:a1734fe1ec4b 13 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:a1734fe1ec4b 14 *
vpcola 0:a1734fe1ec4b 15 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:a1734fe1ec4b 16 * are permitted provided that the following conditions are met:
vpcola 0:a1734fe1ec4b 17 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:a1734fe1ec4b 18 * this list of conditions and the following disclaimer.
vpcola 0:a1734fe1ec4b 19 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:a1734fe1ec4b 20 * this list of conditions and the following disclaimer in the documentation
vpcola 0:a1734fe1ec4b 21 * and/or other materials provided with the distribution.
vpcola 0:a1734fe1ec4b 22 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:a1734fe1ec4b 23 * may be used to endorse or promote products derived from this software
vpcola 0:a1734fe1ec4b 24 * without specific prior written permission.
vpcola 0:a1734fe1ec4b 25 *
vpcola 0:a1734fe1ec4b 26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:a1734fe1ec4b 27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:a1734fe1ec4b 28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:a1734fe1ec4b 29 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:a1734fe1ec4b 30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:a1734fe1ec4b 31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:a1734fe1ec4b 32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:a1734fe1ec4b 33 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:a1734fe1ec4b 34 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:a1734fe1ec4b 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:a1734fe1ec4b 36 *
vpcola 0:a1734fe1ec4b 37 ******************************************************************************
vpcola 0:a1734fe1ec4b 38 */
vpcola 0:a1734fe1ec4b 39
vpcola 0:a1734fe1ec4b 40 /* Includes ------------------------------------------------------------------*/
vpcola 0:a1734fe1ec4b 41 #include "SPIRIT_Radio.h"
vpcola 0:a1734fe1ec4b 42 #include "MCU_Interface.h"
vpcola 0:a1734fe1ec4b 43 #include <math.h>
vpcola 0:a1734fe1ec4b 44
vpcola 0:a1734fe1ec4b 45 /** @addtogroup SPIRIT_Libraries
vpcola 0:a1734fe1ec4b 46 * @{
vpcola 0:a1734fe1ec4b 47 */
vpcola 0:a1734fe1ec4b 48
vpcola 0:a1734fe1ec4b 49
vpcola 0:a1734fe1ec4b 50 /** @addtogroup SPIRIT_Radio
vpcola 0:a1734fe1ec4b 51 * @{
vpcola 0:a1734fe1ec4b 52 */
vpcola 0:a1734fe1ec4b 53
vpcola 0:a1734fe1ec4b 54
vpcola 0:a1734fe1ec4b 55 /** @defgroup Radio_Private_TypesDefinitions Radio Private Types Definitions
vpcola 0:a1734fe1ec4b 56 * @{
vpcola 0:a1734fe1ec4b 57 */
vpcola 0:a1734fe1ec4b 58
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 /** @defgroup Radio_Private_Defines Radio Private Defines
vpcola 0:a1734fe1ec4b 66 * @{
vpcola 0:a1734fe1ec4b 67 */
vpcola 0:a1734fe1ec4b 68
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 /** @defgroup Radio_Private_Macros Radio Private Macros
vpcola 0:a1734fe1ec4b 78 * @{
vpcola 0:a1734fe1ec4b 79 */
vpcola 0:a1734fe1ec4b 80 #define XTAL_FLAG(xtalFrequency) (xtalFrequency>=25e6) ? XTAL_FLAG_26_MHz:XTAL_FLAG_24_MHz
vpcola 0:a1734fe1ec4b 81
vpcola 0:a1734fe1ec4b 82 #define ROUND(A) (((A-(uint32_t)A)> 0.5)? (uint32_t)A+1:(uint32_t)A)
vpcola 0:a1734fe1ec4b 83 /**
vpcola 0:a1734fe1ec4b 84 * @}
vpcola 0:a1734fe1ec4b 85 */
vpcola 0:a1734fe1ec4b 86
vpcola 0:a1734fe1ec4b 87
vpcola 0:a1734fe1ec4b 88 /** @defgroup Radio_Private_Variables Radio Private Variables
vpcola 0:a1734fe1ec4b 89 * @{
vpcola 0:a1734fe1ec4b 90 */
vpcola 0:a1734fe1ec4b 91 /**
vpcola 0:a1734fe1ec4b 92 * @brief The Xtal frequency. To be set by the user (see SetXtalFreq() function)
vpcola 0:a1734fe1ec4b 93 */
vpcola 0:a1734fe1ec4b 94 static uint32_t s_lXtalFrequency;
vpcola 0:a1734fe1ec4b 95
vpcola 0:a1734fe1ec4b 96 /**
vpcola 0:a1734fe1ec4b 97 * @brief Factor is: B/2 used in the formula for SYNTH word calculation
vpcola 0:a1734fe1ec4b 98 */
vpcola 0:a1734fe1ec4b 99 static const uint8_t s_vectcBHalfFactor[4]={(HIGH_BAND_FACTOR/2), (MIDDLE_BAND_FACTOR/2), (LOW_BAND_FACTOR/2), (VERY_LOW_BAND_FACTOR/2)};
vpcola 0:a1734fe1ec4b 100
vpcola 0:a1734fe1ec4b 101 /**
vpcola 0:a1734fe1ec4b 102 * @brief BS value to write in the SYNT0 register according to the selected band
vpcola 0:a1734fe1ec4b 103 */
vpcola 0:a1734fe1ec4b 104 static const uint8_t s_vectcBandRegValue[4]={SYNT0_BS_6, SYNT0_BS_12, SYNT0_BS_16, SYNT0_BS_32};
vpcola 0:a1734fe1ec4b 105
vpcola 0:a1734fe1ec4b 106
vpcola 0:a1734fe1ec4b 107 /**
vpcola 0:a1734fe1ec4b 108 * @brief It represents the available channel bandwidth times 10 for 26 Mhz xtal.
vpcola 0:a1734fe1ec4b 109 * @note The channel bandwidth for others xtal frequencies can be computed since this table
vpcola 0:a1734fe1ec4b 110 * multiplying the current table by a factor xtal_frequency/26e6.
vpcola 0:a1734fe1ec4b 111 */
vpcola 0:a1734fe1ec4b 112 static const uint16_t s_vectnBandwidth26M[90]=
vpcola 0:a1734fe1ec4b 113 {
vpcola 0:a1734fe1ec4b 114 8001, 7951, 7684, 7368, 7051, 6709, 6423, 5867, 5414, \
vpcola 0:a1734fe1ec4b 115 4509, 4259, 4032, 3808, 3621, 3417, 3254, 2945, 2703, \
vpcola 0:a1734fe1ec4b 116 2247, 2124, 2015, 1900, 1807, 1706, 1624, 1471, 1350, \
vpcola 0:a1734fe1ec4b 117 1123, 1062, 1005, 950, 903, 853, 812, 735, 675, \
vpcola 0:a1734fe1ec4b 118 561, 530, 502, 474, 451, 426, 406, 367, 337, \
vpcola 0:a1734fe1ec4b 119 280, 265, 251, 237, 226, 213, 203, 184, 169, \
vpcola 0:a1734fe1ec4b 120 140, 133, 126, 119, 113, 106, 101, 92, 84, \
vpcola 0:a1734fe1ec4b 121 70, 66, 63, 59, 56, 53, 51, 46, 42, \
vpcola 0:a1734fe1ec4b 122 35, 33, 31, 30, 28, 27, 25, 23, 21, \
vpcola 0:a1734fe1ec4b 123 18, 17, 16, 15, 14, 13, 13, 12, 11
vpcola 0:a1734fe1ec4b 124 };
vpcola 0:a1734fe1ec4b 125
vpcola 0:a1734fe1ec4b 126 /**
vpcola 0:a1734fe1ec4b 127 * @brief It represents the available VCO frequencies
vpcola 0:a1734fe1ec4b 128 */
vpcola 0:a1734fe1ec4b 129 static const uint16_t s_vectnVCOFreq[16]=
vpcola 0:a1734fe1ec4b 130 {
vpcola 0:a1734fe1ec4b 131 4644, 4708, 4772, 4836, 4902, 4966, 5030, 5095, \
vpcola 0:a1734fe1ec4b 132 5161, 5232, 5303, 5375, 5448, 5519, 5592, 5663
vpcola 0:a1734fe1ec4b 133 };
vpcola 0:a1734fe1ec4b 134
vpcola 0:a1734fe1ec4b 135 /**
vpcola 0:a1734fe1ec4b 136 * @brief This variable is used to enable or disable
vpcola 0:a1734fe1ec4b 137 * the VCO calibration WA called at the end of the SpiritRadioSetFrequencyBase fcn.
vpcola 0:a1734fe1ec4b 138 * Default is enabled.
vpcola 0:a1734fe1ec4b 139 */
vpcola 0:a1734fe1ec4b 140 static SpiritFunctionalState xDoVcoCalibrationWA=S_ENABLE;
vpcola 0:a1734fe1ec4b 141
vpcola 0:a1734fe1ec4b 142
vpcola 0:a1734fe1ec4b 143 /**
vpcola 0:a1734fe1ec4b 144 * @brief These values are used to interpolate the power curves.
vpcola 0:a1734fe1ec4b 145 * Interpolation curves are linear in the following 3 regions:
vpcola 0:a1734fe1ec4b 146 * - reg value: 1 to 13 (up region)
vpcola 0:a1734fe1ec4b 147 * - reg value: 13 to 40 (mid region)
vpcola 0:a1734fe1ec4b 148 * - reg value: 41 to 90 (low region)
vpcola 0:a1734fe1ec4b 149 * power_reg = m*power_dBm + q
vpcola 0:a1734fe1ec4b 150 * For each band the order is: {m-up, q-up, m-mid, q-mid, m-low, q-low}.
vpcola 0:a1734fe1ec4b 151 * @note The power interpolation curves have been extracted
vpcola 0:a1734fe1ec4b 152 * by measurements done on the divisional evaluation boards.
vpcola 0:a1734fe1ec4b 153 */
vpcola 0:a1734fe1ec4b 154 static const float fPowerFactors[5][6]={
vpcola 0:a1734fe1ec4b 155 {-2.11,25.66,-2.11,25.66,-2.00,31.28}, /* 915 */
vpcola 0:a1734fe1ec4b 156 {-2.04,23.45,-2.04,23.45,-1.95,27.66}, /* 868 */
vpcola 0:a1734fe1ec4b 157 {-3.48,38.45,-1.89,27.66,-1.92,30.23}, /* 433 */
vpcola 0:a1734fe1ec4b 158 {-3.27,35.43,-1.80,26.31,-1.89,29.61}, /* 315 */
vpcola 0:a1734fe1ec4b 159 {-4.18,50.66,-1.80,30.04,-1.86,32.22}, /* 169 */
vpcola 0:a1734fe1ec4b 160 };
vpcola 0:a1734fe1ec4b 161
vpcola 0:a1734fe1ec4b 162 /**
vpcola 0:a1734fe1ec4b 163 * @}
vpcola 0:a1734fe1ec4b 164 */
vpcola 0:a1734fe1ec4b 165
vpcola 0:a1734fe1ec4b 166
vpcola 0:a1734fe1ec4b 167 /** @defgroup Radio_Private_FunctionPrototypes Radio Private Function Prototypes
vpcola 0:a1734fe1ec4b 168 * @{
vpcola 0:a1734fe1ec4b 169 */
vpcola 0:a1734fe1ec4b 170
vpcola 0:a1734fe1ec4b 171
vpcola 0:a1734fe1ec4b 172 /**
vpcola 0:a1734fe1ec4b 173 * @}
vpcola 0:a1734fe1ec4b 174 */
vpcola 0:a1734fe1ec4b 175
vpcola 0:a1734fe1ec4b 176
vpcola 0:a1734fe1ec4b 177 /** @defgroup Radio_Private_Functions Radio Private Functions
vpcola 0:a1734fe1ec4b 178 * @{
vpcola 0:a1734fe1ec4b 179 */
vpcola 0:a1734fe1ec4b 180
vpcola 0:a1734fe1ec4b 181 /**
vpcola 0:a1734fe1ec4b 182 * @brief Initializes the SPIRIT analog and digital radio part according to the specified
vpcola 0:a1734fe1ec4b 183 * parameters in the pxSRadioInitStruct.
vpcola 0:a1734fe1ec4b 184 * @param pxSRadioInitStruct pointer to a SRadioInit structure that
vpcola 0:a1734fe1ec4b 185 * contains the configuration information for the analog radio part of SPIRIT.
vpcola 0:a1734fe1ec4b 186 * @retval Error code: 0=no error, 1=error during calibration of VCO.
vpcola 0:a1734fe1ec4b 187 */
vpcola 0:a1734fe1ec4b 188 uint8_t SpiritRadioInit(SRadioInit* pxSRadioInitStruct)
vpcola 0:a1734fe1ec4b 189 {
vpcola 0:a1734fe1ec4b 190 int32_t FOffsetTmp;
vpcola 0:a1734fe1ec4b 191 uint8_t anaRadioRegArray[8], digRadioRegArray[4];
vpcola 0:a1734fe1ec4b 192 int16_t xtalOffsetFactor;
vpcola 0:a1734fe1ec4b 193 uint8_t drM, drE, FdevM, FdevE, bwM, bwE;
vpcola 0:a1734fe1ec4b 194
vpcola 0:a1734fe1ec4b 195 /* Workaround for Vtune */
vpcola 0:a1734fe1ec4b 196 uint8_t value = 0xA0; SpiritSpiWriteRegisters(0x9F, 1, &value);
vpcola 0:a1734fe1ec4b 197
vpcola 0:a1734fe1ec4b 198 /* Calculates the offset respect to RF frequency and according to xtal_ppm parameter: (xtal_ppm*FBase)/10^6 */
vpcola 0:a1734fe1ec4b 199 FOffsetTmp = (int32_t)(((float)pxSRadioInitStruct->nXtalOffsetPpm*pxSRadioInitStruct->lFrequencyBase)/PPM_FACTOR);
vpcola 0:a1734fe1ec4b 200
vpcola 0:a1734fe1ec4b 201 /* Check the parameters */
vpcola 0:a1734fe1ec4b 202 s_assert_param(IS_FREQUENCY_BAND(pxSRadioInitStruct->lFrequencyBase));
vpcola 0:a1734fe1ec4b 203 s_assert_param(IS_MODULATION_SELECTED(pxSRadioInitStruct->xModulationSelect));
vpcola 0:a1734fe1ec4b 204 s_assert_param(IS_DATARATE(pxSRadioInitStruct->lDatarate));
vpcola 0:a1734fe1ec4b 205 s_assert_param(IS_FREQUENCY_OFFSET(FOffsetTmp,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 206 s_assert_param(IS_CHANNEL_SPACE(pxSRadioInitStruct->nChannelSpace,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 207 s_assert_param(IS_F_DEV(pxSRadioInitStruct->lFreqDev,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 208
vpcola 0:a1734fe1ec4b 209 /* Disable the digital, ADC, SMPS reference clock divider if fXO>24MHz or fXO<26MHz */
vpcola 0:a1734fe1ec4b 210 SpiritSpiCommandStrobes(COMMAND_STANDBY);
vpcola 0:a1734fe1ec4b 211 do{
vpcola 0:a1734fe1ec4b 212 /* Delay for state transition */
vpcola 0:a1734fe1ec4b 213 for(volatile uint8_t i=0; i!=0xFF; i++);
vpcola 0:a1734fe1ec4b 214
vpcola 0:a1734fe1ec4b 215 /* Reads the MC_STATUS register */
vpcola 0:a1734fe1ec4b 216 SpiritRefreshStatus();
vpcola 0:a1734fe1ec4b 217 }while(g_xStatus.MC_STATE!=MC_STATE_STANDBY);
vpcola 0:a1734fe1ec4b 218
vpcola 0:a1734fe1ec4b 219 if(s_lXtalFrequency<DOUBLE_XTAL_THR)
vpcola 0:a1734fe1ec4b 220 {
vpcola 0:a1734fe1ec4b 221 SpiritRadioSetDigDiv(S_DISABLE);
vpcola 0:a1734fe1ec4b 222 s_assert_param(IS_CH_BW(pxSRadioInitStruct->lBandwidth,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 223 }
vpcola 0:a1734fe1ec4b 224 else
vpcola 0:a1734fe1ec4b 225 {
vpcola 0:a1734fe1ec4b 226 SpiritRadioSetDigDiv(S_ENABLE);
vpcola 0:a1734fe1ec4b 227 s_assert_param(IS_CH_BW(pxSRadioInitStruct->lBandwidth,(s_lXtalFrequency>>1)));
vpcola 0:a1734fe1ec4b 228 }
vpcola 0:a1734fe1ec4b 229
vpcola 0:a1734fe1ec4b 230 /* Goes in READY state */
vpcola 0:a1734fe1ec4b 231 SpiritSpiCommandStrobes(COMMAND_READY);
vpcola 0:a1734fe1ec4b 232 do{
vpcola 0:a1734fe1ec4b 233 /* Delay for state transition */
vpcola 0:a1734fe1ec4b 234 for(volatile uint8_t i=0; i!=0xFF; i++);
vpcola 0:a1734fe1ec4b 235
vpcola 0:a1734fe1ec4b 236 /* Reads the MC_STATUS register */
vpcola 0:a1734fe1ec4b 237 SpiritRefreshStatus();
vpcola 0:a1734fe1ec4b 238 }while(g_xStatus.MC_STATE!=MC_STATE_READY);
vpcola 0:a1734fe1ec4b 239
vpcola 0:a1734fe1ec4b 240 /* Calculates the FC_OFFSET parameter and cast as signed int: FOffsetTmp = (Fxtal/2^18)*FC_OFFSET */
vpcola 0:a1734fe1ec4b 241 xtalOffsetFactor = (int16_t)(((float)FOffsetTmp*FBASE_DIVIDER)/s_lXtalFrequency);
vpcola 0:a1734fe1ec4b 242 anaRadioRegArray[2] = (uint8_t)((((uint16_t)xtalOffsetFactor)>>8)&0x0F);
vpcola 0:a1734fe1ec4b 243 anaRadioRegArray[3] = (uint8_t)(xtalOffsetFactor);
vpcola 0:a1734fe1ec4b 244
vpcola 0:a1734fe1ec4b 245 /* Calculates the channel space factor */
vpcola 0:a1734fe1ec4b 246 anaRadioRegArray[0] =((uint32_t)pxSRadioInitStruct->nChannelSpace<<9)/(s_lXtalFrequency>>6)+1;
vpcola 0:a1734fe1ec4b 247
vpcola 0:a1734fe1ec4b 248 SpiritManagementWaTRxFcMem(pxSRadioInitStruct->lFrequencyBase);
vpcola 0:a1734fe1ec4b 249
vpcola 0:a1734fe1ec4b 250 /* 2nd order DEM algorithm enabling */
vpcola 0:a1734fe1ec4b 251 uint8_t tmpreg; SpiritSpiReadRegisters(0xA3, 1, &tmpreg);
vpcola 0:a1734fe1ec4b 252 tmpreg &= ~0x02; SpiritSpiWriteRegisters(0xA3, 1, &tmpreg);
vpcola 0:a1734fe1ec4b 253
vpcola 0:a1734fe1ec4b 254 /* Check the channel center frequency is in one of the possible range */
vpcola 0:a1734fe1ec4b 255 s_assert_param(IS_FREQUENCY_BAND((pxSRadioInitStruct->lFrequencyBase + ((xtalOffsetFactor*s_lXtalFrequency)/FBASE_DIVIDER) + pxSRadioInitStruct->nChannelSpace * pxSRadioInitStruct->cChannelNumber)));
vpcola 0:a1734fe1ec4b 256
vpcola 0:a1734fe1ec4b 257 /* Calculates the datarate mantissa and exponent */
vpcola 0:a1734fe1ec4b 258 SpiritRadioSearchDatarateME(pxSRadioInitStruct->lDatarate, &drM, &drE);
vpcola 0:a1734fe1ec4b 259 digRadioRegArray[0] = (uint8_t)(drM);
vpcola 0:a1734fe1ec4b 260 digRadioRegArray[1] = (uint8_t)(0x00 | pxSRadioInitStruct->xModulationSelect |drE);
vpcola 0:a1734fe1ec4b 261
vpcola 0:a1734fe1ec4b 262 /* Read the fdev register to preserve the clock recovery algo bit */
vpcola 0:a1734fe1ec4b 263 SpiritSpiReadRegisters(0x1C, 1, &tmpreg);
vpcola 0:a1734fe1ec4b 264
vpcola 0:a1734fe1ec4b 265 /* Calculates the frequency deviation mantissa and exponent */
vpcola 0:a1734fe1ec4b 266 SpiritRadioSearchFreqDevME(pxSRadioInitStruct->lFreqDev, &FdevM, &FdevE);
vpcola 0:a1734fe1ec4b 267 digRadioRegArray[2] = (uint8_t)((FdevE<<4) | (tmpreg&0x08) | FdevM);
vpcola 0:a1734fe1ec4b 268
vpcola 0:a1734fe1ec4b 269 /* Calculates the channel filter mantissa and exponent */
vpcola 0:a1734fe1ec4b 270 SpiritRadioSearchChannelBwME(pxSRadioInitStruct->lBandwidth, &bwM, &bwE);
vpcola 0:a1734fe1ec4b 271
vpcola 0:a1734fe1ec4b 272 digRadioRegArray[3] = (uint8_t)((bwM<<4) | bwE);
vpcola 0:a1734fe1ec4b 273
vpcola 0:a1734fe1ec4b 274 float if_off=(3.0*480140)/(s_lXtalFrequency>>12)-64;
vpcola 0:a1734fe1ec4b 275
vpcola 0:a1734fe1ec4b 276 uint8_t ifOffsetAna = ROUND(if_off);
vpcola 0:a1734fe1ec4b 277
vpcola 0:a1734fe1ec4b 278 if(s_lXtalFrequency<DOUBLE_XTAL_THR)
vpcola 0:a1734fe1ec4b 279 {
vpcola 0:a1734fe1ec4b 280 /* if offset digital is the same in case of single xtal */
vpcola 0:a1734fe1ec4b 281 anaRadioRegArray[1] = ifOffsetAna;
vpcola 0:a1734fe1ec4b 282 }
vpcola 0:a1734fe1ec4b 283 else
vpcola 0:a1734fe1ec4b 284 {
vpcola 0:a1734fe1ec4b 285 if_off=(3.0*480140)/(s_lXtalFrequency>>13)-64;
vpcola 0:a1734fe1ec4b 286
vpcola 0:a1734fe1ec4b 287 /* ... otherwise recompute it */
vpcola 0:a1734fe1ec4b 288 anaRadioRegArray[1] = ROUND(if_off);
vpcola 0:a1734fe1ec4b 289 }
vpcola 0:a1734fe1ec4b 290 // if(s_lXtalFrequency==24000000) {
vpcola 0:a1734fe1ec4b 291 // ifOffsetAna = 0xB6;
vpcola 0:a1734fe1ec4b 292 // anaRadioRegArray[1] = 0xB6;
vpcola 0:a1734fe1ec4b 293 // }
vpcola 0:a1734fe1ec4b 294 // if(s_lXtalFrequency==25000000) {
vpcola 0:a1734fe1ec4b 295 // ifOffsetAna = 0xAC;
vpcola 0:a1734fe1ec4b 296 // anaRadioRegArray[1] = 0xAC;
vpcola 0:a1734fe1ec4b 297 // }
vpcola 0:a1734fe1ec4b 298 // if(s_lXtalFrequency==26000000) {
vpcola 0:a1734fe1ec4b 299 // ifOffsetAna = 0xA3;
vpcola 0:a1734fe1ec4b 300 // anaRadioRegArray[1] = 0xA3;
vpcola 0:a1734fe1ec4b 301 // }
vpcola 0:a1734fe1ec4b 302 // if(s_lXtalFrequency==48000000) {
vpcola 0:a1734fe1ec4b 303 // ifOffsetAna = 0x3B;
vpcola 0:a1734fe1ec4b 304 // anaRadioRegArray[1] = 0xB6;
vpcola 0:a1734fe1ec4b 305 // }
vpcola 0:a1734fe1ec4b 306 // if(s_lXtalFrequency==50000000) {
vpcola 0:a1734fe1ec4b 307 // ifOffsetAna = 0x36;
vpcola 0:a1734fe1ec4b 308 // anaRadioRegArray[1] = 0xAC;
vpcola 0:a1734fe1ec4b 309 // }
vpcola 0:a1734fe1ec4b 310 // if(s_lXtalFrequency==52000000) {
vpcola 0:a1734fe1ec4b 311 // ifOffsetAna = 0x31;
vpcola 0:a1734fe1ec4b 312 // anaRadioRegArray[1] = 0xA3;
vpcola 0:a1734fe1ec4b 313 // }
vpcola 0:a1734fe1ec4b 314
vpcola 0:a1734fe1ec4b 315 g_xStatus = SpiritSpiWriteRegisters(IF_OFFSET_ANA_BASE, 1, &ifOffsetAna);
vpcola 0:a1734fe1ec4b 316
vpcola 0:a1734fe1ec4b 317
vpcola 0:a1734fe1ec4b 318 /* Sets Xtal configuration */
vpcola 0:a1734fe1ec4b 319 if(s_lXtalFrequency>DOUBLE_XTAL_THR)
vpcola 0:a1734fe1ec4b 320 {
vpcola 0:a1734fe1ec4b 321 SpiritRadioSetXtalFlag(XTAL_FLAG((s_lXtalFrequency/2)));
vpcola 0:a1734fe1ec4b 322 }
vpcola 0:a1734fe1ec4b 323 else
vpcola 0:a1734fe1ec4b 324 {
vpcola 0:a1734fe1ec4b 325 SpiritRadioSetXtalFlag(XTAL_FLAG(s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 326 }
vpcola 0:a1734fe1ec4b 327
vpcola 0:a1734fe1ec4b 328 /* Sets the channel number in the corresponding register */
vpcola 0:a1734fe1ec4b 329 SpiritSpiWriteRegisters(CHNUM_BASE, 1, &pxSRadioInitStruct->cChannelNumber);
vpcola 0:a1734fe1ec4b 330
vpcola 0:a1734fe1ec4b 331 /* Configures the Analog Radio registers */
vpcola 0:a1734fe1ec4b 332 SpiritSpiWriteRegisters(CHSPACE_BASE, 4, anaRadioRegArray);
vpcola 0:a1734fe1ec4b 333
vpcola 0:a1734fe1ec4b 334 /* Configures the Digital Radio registers */
vpcola 0:a1734fe1ec4b 335 g_xStatus = SpiritSpiWriteRegisters(MOD1_BASE, 4, digRadioRegArray);
vpcola 0:a1734fe1ec4b 336
vpcola 0:a1734fe1ec4b 337 /* Enable the freeze option of the AFC on the SYNC word */
vpcola 0:a1734fe1ec4b 338 SpiritRadioAFCFreezeOnSync(S_ENABLE);
vpcola 0:a1734fe1ec4b 339
vpcola 0:a1734fe1ec4b 340 /* Set the IQC correction optimal value */
vpcola 0:a1734fe1ec4b 341 anaRadioRegArray[0]=0x80;
vpcola 0:a1734fe1ec4b 342 anaRadioRegArray[1]=0xE3;
vpcola 0:a1734fe1ec4b 343 g_xStatus = SpiritSpiWriteRegisters(0x99, 2, anaRadioRegArray);
vpcola 0:a1734fe1ec4b 344
vpcola 0:a1734fe1ec4b 345 return SpiritRadioSetFrequencyBase(pxSRadioInitStruct->lFrequencyBase);
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 SPIRIT analog and digital radio structure according to the registers value.
vpcola 0:a1734fe1ec4b 352 * @param pxSRadioInitStruct pointer to a SRadioInit structure that
vpcola 0:a1734fe1ec4b 353 * contains the configuration information for the analog radio part of SPIRIT.
vpcola 0:a1734fe1ec4b 354 * @retval None.
vpcola 0:a1734fe1ec4b 355 */
vpcola 0:a1734fe1ec4b 356 void SpiritRadioGetInfo(SRadioInit* pxSRadioInitStruct)
vpcola 0:a1734fe1ec4b 357 {
vpcola 0:a1734fe1ec4b 358 uint8_t anaRadioRegArray[8], digRadioRegArray[4];
vpcola 0:a1734fe1ec4b 359 BandSelect band;
vpcola 0:a1734fe1ec4b 360 int16_t xtalOffsetFactor;
vpcola 0:a1734fe1ec4b 361
vpcola 0:a1734fe1ec4b 362 /* Get the RF board version */
vpcola 0:a1734fe1ec4b 363 //SpiritVersion xSpiritVersion = SpiritGeneralGetSpiritVersion();
vpcola 0:a1734fe1ec4b 364
vpcola 0:a1734fe1ec4b 365 /* Reads the Analog Radio registers */
vpcola 0:a1734fe1ec4b 366 SpiritSpiReadRegisters(SYNT3_BASE, 8, anaRadioRegArray);
vpcola 0:a1734fe1ec4b 367
vpcola 0:a1734fe1ec4b 368 /* Reads the Digital Radio registers */
vpcola 0:a1734fe1ec4b 369 g_xStatus = SpiritSpiReadRegisters(MOD1_BASE, 4, digRadioRegArray);
vpcola 0:a1734fe1ec4b 370
vpcola 0:a1734fe1ec4b 371 /* Reads the operating band masking the Band selected field */
vpcola 0:a1734fe1ec4b 372 if((anaRadioRegArray[3] & 0x07) == SYNT0_BS_6)
vpcola 0:a1734fe1ec4b 373 {
vpcola 0:a1734fe1ec4b 374 band = HIGH_BAND;
vpcola 0:a1734fe1ec4b 375 }
vpcola 0:a1734fe1ec4b 376 else if ((anaRadioRegArray[3] & 0x07) == SYNT0_BS_12)
vpcola 0:a1734fe1ec4b 377 {
vpcola 0:a1734fe1ec4b 378 band = MIDDLE_BAND;
vpcola 0:a1734fe1ec4b 379 }
vpcola 0:a1734fe1ec4b 380 else if ((anaRadioRegArray[3] & 0x07) == SYNT0_BS_16)
vpcola 0:a1734fe1ec4b 381 {
vpcola 0:a1734fe1ec4b 382 band = LOW_BAND;
vpcola 0:a1734fe1ec4b 383 }
vpcola 0:a1734fe1ec4b 384 else if ((anaRadioRegArray[3] & 0x07) == SYNT0_BS_32)
vpcola 0:a1734fe1ec4b 385 {
vpcola 0:a1734fe1ec4b 386 band = VERY_LOW_BAND;
vpcola 0:a1734fe1ec4b 387 }
vpcola 0:a1734fe1ec4b 388 else
vpcola 0:a1734fe1ec4b 389 {
vpcola 0:a1734fe1ec4b 390 /* if it is another value, set it to a valid one in order to avoid access violation */
vpcola 0:a1734fe1ec4b 391 uint8_t tmp=(anaRadioRegArray[3]&0xF8)|SYNT0_BS_6;
vpcola 0:a1734fe1ec4b 392 SpiritSpiWriteRegisters(SYNT0_BASE,1,&tmp);
vpcola 0:a1734fe1ec4b 393 band = HIGH_BAND;
vpcola 0:a1734fe1ec4b 394 }
vpcola 0:a1734fe1ec4b 395
vpcola 0:a1734fe1ec4b 396 /* Computes the synth word */
vpcola 0:a1734fe1ec4b 397 uint32_t synthWord = (uint32_t)((((uint32_t)(anaRadioRegArray[0]&0x1F))<<21)+(((uint32_t)(anaRadioRegArray[1]))<<13)+\
vpcola 0:a1734fe1ec4b 398 (((uint32_t)(anaRadioRegArray[2]))<<5)+(((uint32_t)(anaRadioRegArray[3]))>>3));
vpcola 0:a1734fe1ec4b 399
vpcola 0:a1734fe1ec4b 400 /* Calculates the frequency base */
vpcola 0:a1734fe1ec4b 401 uint8_t cRefDiv = (uint8_t)SpiritRadioGetRefDiv()+1;
vpcola 0:a1734fe1ec4b 402 pxSRadioInitStruct->lFrequencyBase = (uint32_t)round(synthWord*(((double)s_lXtalFrequency)/(FBASE_DIVIDER*cRefDiv*s_vectcBHalfFactor[band])));
vpcola 0:a1734fe1ec4b 403
vpcola 0:a1734fe1ec4b 404 /* Calculates the Offset Factor */
vpcola 0:a1734fe1ec4b 405 uint16_t xtalOffTemp = ((((uint16_t)anaRadioRegArray[6])<<8)+((uint16_t)anaRadioRegArray[7]));
vpcola 0:a1734fe1ec4b 406
vpcola 0:a1734fe1ec4b 407 /* If a negative number then convert the 12 bit 2-complement in a 16 bit number */
vpcola 0:a1734fe1ec4b 408 if(xtalOffTemp & 0x0800)
vpcola 0:a1734fe1ec4b 409 {
vpcola 0:a1734fe1ec4b 410 xtalOffTemp = xtalOffTemp | 0xF000;
vpcola 0:a1734fe1ec4b 411 }
vpcola 0:a1734fe1ec4b 412 else
vpcola 0:a1734fe1ec4b 413 {
vpcola 0:a1734fe1ec4b 414 xtalOffTemp = xtalOffTemp & 0x0FFF;
vpcola 0:a1734fe1ec4b 415 }
vpcola 0:a1734fe1ec4b 416
vpcola 0:a1734fe1ec4b 417 xtalOffsetFactor = *((int16_t*)(&xtalOffTemp));
vpcola 0:a1734fe1ec4b 418
vpcola 0:a1734fe1ec4b 419 /* Calculates the frequency offset in ppm */
vpcola 0:a1734fe1ec4b 420 pxSRadioInitStruct->nXtalOffsetPpm =(int16_t)((uint32_t)xtalOffsetFactor*s_lXtalFrequency*PPM_FACTOR)/((uint32_t)FBASE_DIVIDER*pxSRadioInitStruct->lFrequencyBase);
vpcola 0:a1734fe1ec4b 421
vpcola 0:a1734fe1ec4b 422 /* Channel space */
vpcola 0:a1734fe1ec4b 423 pxSRadioInitStruct->nChannelSpace = anaRadioRegArray[4]*(s_lXtalFrequency>>15);
vpcola 0:a1734fe1ec4b 424
vpcola 0:a1734fe1ec4b 425 /* Channel number */
vpcola 0:a1734fe1ec4b 426 pxSRadioInitStruct->cChannelNumber = SpiritRadioGetChannel();
vpcola 0:a1734fe1ec4b 427
vpcola 0:a1734fe1ec4b 428 /* Modulation select */
vpcola 0:a1734fe1ec4b 429 pxSRadioInitStruct->xModulationSelect = (ModulationSelect)(digRadioRegArray[1] & 0x70);
vpcola 0:a1734fe1ec4b 430
vpcola 0:a1734fe1ec4b 431 /* Reads the frequency deviation for mantissa and exponent */
vpcola 0:a1734fe1ec4b 432 uint8_t FDevM = digRadioRegArray[2]&0x07;
vpcola 0:a1734fe1ec4b 433 uint8_t FDevE = (digRadioRegArray[2]&0xF0)>>4;
vpcola 0:a1734fe1ec4b 434
vpcola 0:a1734fe1ec4b 435 /* Reads the channel filter register for mantissa and exponent */
vpcola 0:a1734fe1ec4b 436 uint8_t bwM = (digRadioRegArray[3]&0xF0)>>4;
vpcola 0:a1734fe1ec4b 437 uint8_t bwE = digRadioRegArray[3]&0x0F;
vpcola 0:a1734fe1ec4b 438
vpcola 0:a1734fe1ec4b 439 uint8_t cDivider = 0;
vpcola 0:a1734fe1ec4b 440 cDivider = SpiritRadioGetDigDiv();
vpcola 0:a1734fe1ec4b 441
vpcola 0:a1734fe1ec4b 442 /* Calculates the datarate */
vpcola 0:a1734fe1ec4b 443 pxSRadioInitStruct->lDatarate = ((s_lXtalFrequency>>(5+cDivider))*(256+digRadioRegArray[0]))>>(23-(digRadioRegArray[1]&0x0F));
vpcola 0:a1734fe1ec4b 444
vpcola 0:a1734fe1ec4b 445 /* Calculates the frequency deviation */
vpcola 0:a1734fe1ec4b 446 // (((s_lXtalFrequency>>6)*(8+FDevM))>>(12-FDevE+cCorrection));
vpcola 0:a1734fe1ec4b 447 pxSRadioInitStruct->lFreqDev =(uint32_t)((float)s_lXtalFrequency/(((uint32_t)1)<<18)*(uint32_t)((8.0+FDevM)/2*(1<<FDevE)));
vpcola 0:a1734fe1ec4b 448
vpcola 0:a1734fe1ec4b 449 /* Reads the channel filter bandwidth from the look-up table and return it */
vpcola 0:a1734fe1ec4b 450 pxSRadioInitStruct->lBandwidth = (uint32_t)(100.0*s_vectnBandwidth26M[bwM+(bwE*9)]*((s_lXtalFrequency>>cDivider)/26e6));
vpcola 0:a1734fe1ec4b 451
vpcola 0:a1734fe1ec4b 452 }
vpcola 0:a1734fe1ec4b 453
vpcola 0:a1734fe1ec4b 454
vpcola 0:a1734fe1ec4b 455 /**
vpcola 0:a1734fe1ec4b 456 * @brief Sets the Xtal configuration in the ANA_FUNC_CONF0 register.
vpcola 0:a1734fe1ec4b 457 * @param xXtal one of the possible value of the enum type XtalFrequency.
vpcola 0:a1734fe1ec4b 458 * @arg XTAL_FLAG_24_MHz: in case of 24 MHz crystal
vpcola 0:a1734fe1ec4b 459 * @arg XTAL_FLAG_26_MHz: in case of 26 MHz crystal
vpcola 0:a1734fe1ec4b 460 * @retval None.
vpcola 0:a1734fe1ec4b 461 */
vpcola 0:a1734fe1ec4b 462 void SpiritRadioSetXtalFlag(XtalFlag xXtal)
vpcola 0:a1734fe1ec4b 463 {
vpcola 0:a1734fe1ec4b 464 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 465
vpcola 0:a1734fe1ec4b 466 /* Check the parameters */
vpcola 0:a1734fe1ec4b 467 s_assert_param(IS_XTAL_FLAG(xXtal));
vpcola 0:a1734fe1ec4b 468
vpcola 0:a1734fe1ec4b 469 /* Reads the ANA_FUNC_CONF_0 register */
vpcola 0:a1734fe1ec4b 470 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 471 if(xXtal == XTAL_FLAG_26_MHz)
vpcola 0:a1734fe1ec4b 472 {
vpcola 0:a1734fe1ec4b 473 tempRegValue|=SELECT_24_26_MHZ_MASK;
vpcola 0:a1734fe1ec4b 474 }
vpcola 0:a1734fe1ec4b 475 else
vpcola 0:a1734fe1ec4b 476 {
vpcola 0:a1734fe1ec4b 477 tempRegValue &= (~SELECT_24_26_MHZ_MASK);
vpcola 0:a1734fe1ec4b 478 }
vpcola 0:a1734fe1ec4b 479
vpcola 0:a1734fe1ec4b 480 /* Sets the 24_26MHz_SELECT field in the ANA_FUNC_CONF_0 register */
vpcola 0:a1734fe1ec4b 481 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 482
vpcola 0:a1734fe1ec4b 483 }
vpcola 0:a1734fe1ec4b 484
vpcola 0:a1734fe1ec4b 485
vpcola 0:a1734fe1ec4b 486 /**
vpcola 0:a1734fe1ec4b 487 * @brief Returns the Xtal configuration in the ANA_FUNC_CONF0 register.
vpcola 0:a1734fe1ec4b 488 * @param None.
vpcola 0:a1734fe1ec4b 489 * @retval XtalFrequency Settled Xtal configuration.
vpcola 0:a1734fe1ec4b 490 */
vpcola 0:a1734fe1ec4b 491 XtalFlag SpiritRadioGetXtalFlag(void)
vpcola 0:a1734fe1ec4b 492 {
vpcola 0:a1734fe1ec4b 493 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 494
vpcola 0:a1734fe1ec4b 495 /* Reads the Xtal configuration in the ANA_FUNC_CONF_0 register and return the value */
vpcola 0:a1734fe1ec4b 496 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 497
vpcola 0:a1734fe1ec4b 498 return (XtalFlag)((tempRegValue & 0x40)>>6);
vpcola 0:a1734fe1ec4b 499
vpcola 0:a1734fe1ec4b 500 }
vpcola 0:a1734fe1ec4b 501
vpcola 0:a1734fe1ec4b 502
vpcola 0:a1734fe1ec4b 503 /**
vpcola 0:a1734fe1ec4b 504 * @brief Returns the charge pump word for a given VCO frequency.
vpcola 0:a1734fe1ec4b 505 * @param lFc channel center frequency expressed in Hz.
vpcola 0:a1734fe1ec4b 506 * This parameter can be a value in one of the following ranges:<ul>
vpcola 0:a1734fe1ec4b 507 * <li> High_Band: from 779 MHz to 915 MHz </li>
vpcola 0:a1734fe1ec4b 508 * <li> Middle Band: from 387 MHz to 470 MHz </li>
vpcola 0:a1734fe1ec4b 509 * <li> Low Band: from 300 MHz to 348 MHz </li>
vpcola 0:a1734fe1ec4b 510 * <li> Very low Band: from 150 MHz to 174 MHz </li> </ul>
vpcola 0:a1734fe1ec4b 511 * @retval uint8_t Charge pump word.
vpcola 0:a1734fe1ec4b 512 */
vpcola 0:a1734fe1ec4b 513 uint8_t SpiritRadioSearchWCP(uint32_t lFc)
vpcola 0:a1734fe1ec4b 514 {
vpcola 0:a1734fe1ec4b 515 int8_t i;
vpcola 0:a1734fe1ec4b 516 uint32_t vcofreq;
vpcola 0:a1734fe1ec4b 517 uint8_t BFactor;
vpcola 0:a1734fe1ec4b 518
vpcola 0:a1734fe1ec4b 519 /* Check the channel center frequency is in one of the possible range */
vpcola 0:a1734fe1ec4b 520 s_assert_param(IS_FREQUENCY_BAND(lFc));
vpcola 0:a1734fe1ec4b 521
vpcola 0:a1734fe1ec4b 522 /* Search the operating band */
vpcola 0:a1734fe1ec4b 523 if(IS_FREQUENCY_BAND_HIGH(lFc))
vpcola 0:a1734fe1ec4b 524 {
vpcola 0:a1734fe1ec4b 525 BFactor = HIGH_BAND_FACTOR;
vpcola 0:a1734fe1ec4b 526 }
vpcola 0:a1734fe1ec4b 527 else if(IS_FREQUENCY_BAND_MIDDLE(lFc))
vpcola 0:a1734fe1ec4b 528 {
vpcola 0:a1734fe1ec4b 529 BFactor = MIDDLE_BAND_FACTOR;
vpcola 0:a1734fe1ec4b 530 }
vpcola 0:a1734fe1ec4b 531 else if(IS_FREQUENCY_BAND_LOW(lFc))
vpcola 0:a1734fe1ec4b 532 {
vpcola 0:a1734fe1ec4b 533 BFactor = LOW_BAND_FACTOR;
vpcola 0:a1734fe1ec4b 534 }
vpcola 0:a1734fe1ec4b 535 else
vpcola 0:a1734fe1ec4b 536 {
vpcola 0:a1734fe1ec4b 537 BFactor = VERY_LOW_BAND_FACTOR;
vpcola 0:a1734fe1ec4b 538 }
vpcola 0:a1734fe1ec4b 539
vpcola 0:a1734fe1ec4b 540 /* Calculates the VCO frequency VCOFreq = lFc*B */
vpcola 0:a1734fe1ec4b 541 vcofreq = (lFc/1000000)*BFactor;
vpcola 0:a1734fe1ec4b 542
vpcola 0:a1734fe1ec4b 543 /* Search in the vco frequency array the charge pump word */
vpcola 0:a1734fe1ec4b 544 if(vcofreq>=s_vectnVCOFreq[15])
vpcola 0:a1734fe1ec4b 545 {
vpcola 0:a1734fe1ec4b 546 i=15;
vpcola 0:a1734fe1ec4b 547 }
vpcola 0:a1734fe1ec4b 548 else
vpcola 0:a1734fe1ec4b 549 {
vpcola 0:a1734fe1ec4b 550 /* Search the value */
vpcola 0:a1734fe1ec4b 551 for(i=0 ; i<15 && vcofreq>s_vectnVCOFreq[i] ; i++);
vpcola 0:a1734fe1ec4b 552
vpcola 0:a1734fe1ec4b 553 /* Be sure that it is the best approssimation */
vpcola 0:a1734fe1ec4b 554 if (i!=0 && s_vectnVCOFreq[i]-vcofreq>vcofreq-s_vectnVCOFreq[i-1])
vpcola 0:a1734fe1ec4b 555 i--;
vpcola 0:a1734fe1ec4b 556 }
vpcola 0:a1734fe1ec4b 557
vpcola 0:a1734fe1ec4b 558 /* Return index */
vpcola 0:a1734fe1ec4b 559 return (i%8);
vpcola 0:a1734fe1ec4b 560
vpcola 0:a1734fe1ec4b 561 }
vpcola 0:a1734fe1ec4b 562
vpcola 0:a1734fe1ec4b 563 /**
vpcola 0:a1734fe1ec4b 564 * @brief Returns the synth word.
vpcola 0:a1734fe1ec4b 565 * @param None.
vpcola 0:a1734fe1ec4b 566 * @retval uint32_t Synth word.
vpcola 0:a1734fe1ec4b 567 */
vpcola 0:a1734fe1ec4b 568 uint32_t SpiritRadioGetSynthWord(void)
vpcola 0:a1734fe1ec4b 569 {
vpcola 0:a1734fe1ec4b 570 uint8_t regArray[4];
vpcola 0:a1734fe1ec4b 571
vpcola 0:a1734fe1ec4b 572 /* Reads the SYNTH registers, build the synth word and return it */
vpcola 0:a1734fe1ec4b 573 g_xStatus = SpiritSpiReadRegisters(SYNT3_BASE, 4, regArray);
vpcola 0:a1734fe1ec4b 574 return ((((uint32_t)(regArray[0]&0x1F))<<21)+(((uint32_t)(regArray[1]))<<13)+\
vpcola 0:a1734fe1ec4b 575 (((uint32_t)(regArray[2]))<<5)+(((uint32_t)(regArray[3]))>>3));
vpcola 0:a1734fe1ec4b 576
vpcola 0:a1734fe1ec4b 577 }
vpcola 0:a1734fe1ec4b 578
vpcola 0:a1734fe1ec4b 579
vpcola 0:a1734fe1ec4b 580 /**
vpcola 0:a1734fe1ec4b 581 * @brief Sets the SYNTH registers.
vpcola 0:a1734fe1ec4b 582 * @param lSynthWord the synth word to write in the SYNTH[3:0] registers.
vpcola 0:a1734fe1ec4b 583 * @retval None.
vpcola 0:a1734fe1ec4b 584 */
vpcola 0:a1734fe1ec4b 585 void SpiritRadioSetSynthWord(uint32_t lSynthWord)
vpcola 0:a1734fe1ec4b 586 {
vpcola 0:a1734fe1ec4b 587 uint8_t tempArray[4];
vpcola 0:a1734fe1ec4b 588 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 589
vpcola 0:a1734fe1ec4b 590 /* Reads the SYNT0 register */
vpcola 0:a1734fe1ec4b 591 g_xStatus = SpiritSpiReadRegisters(SYNT0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 592
vpcola 0:a1734fe1ec4b 593 /* Mask the Band selected field */
vpcola 0:a1734fe1ec4b 594 tempRegValue &= 0x07;
vpcola 0:a1734fe1ec4b 595
vpcola 0:a1734fe1ec4b 596 /* Build the array for SYNTH registers */
vpcola 0:a1734fe1ec4b 597 tempArray[0] = (uint8_t)((lSynthWord>>21)&(0x0000001F));
vpcola 0:a1734fe1ec4b 598 tempArray[1] = (uint8_t)((lSynthWord>>13)&(0x000000FF));
vpcola 0:a1734fe1ec4b 599 tempArray[2] = (uint8_t)((lSynthWord>>5)&(0x000000FF));
vpcola 0:a1734fe1ec4b 600 tempArray[3] = (uint8_t)(((lSynthWord&0x0000001F)<<3)| tempRegValue);
vpcola 0:a1734fe1ec4b 601
vpcola 0:a1734fe1ec4b 602 /* Writes the synth word in the SYNTH registers */
vpcola 0:a1734fe1ec4b 603 g_xStatus = SpiritSpiWriteRegisters(SYNT3_BASE, 4, tempArray);
vpcola 0:a1734fe1ec4b 604
vpcola 0:a1734fe1ec4b 605 }
vpcola 0:a1734fe1ec4b 606
vpcola 0:a1734fe1ec4b 607
vpcola 0:a1734fe1ec4b 608 /**
vpcola 0:a1734fe1ec4b 609 * @brief Sets the operating band.
vpcola 0:a1734fe1ec4b 610 * @param xBand the band to set.
vpcola 0:a1734fe1ec4b 611 * This parameter can be one of following parameters:
vpcola 0:a1734fe1ec4b 612 * @arg HIGH_BAND High_Band selected: from 779 MHz to 915 MHz
vpcola 0:a1734fe1ec4b 613 * @arg MIDDLE_BAND: Middle Band selected: from 387 MHz to 470 MHz
vpcola 0:a1734fe1ec4b 614 * @arg LOW_BAND: Low Band selected: from 300 MHz to 348 MHz
vpcola 0:a1734fe1ec4b 615 * @arg VERY_LOW_BAND: Very low Band selected: from 150 MHz to 174 MHz
vpcola 0:a1734fe1ec4b 616 * @retval None.
vpcola 0:a1734fe1ec4b 617 */
vpcola 0:a1734fe1ec4b 618 void SpiritRadioSetBand(BandSelect xBand)
vpcola 0:a1734fe1ec4b 619 {
vpcola 0:a1734fe1ec4b 620 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 621
vpcola 0:a1734fe1ec4b 622 /* Check the parameters */
vpcola 0:a1734fe1ec4b 623 s_assert_param(IS_BAND_SELECTED(xBand));
vpcola 0:a1734fe1ec4b 624
vpcola 0:a1734fe1ec4b 625 /* Reads the SYNT0 register*/
vpcola 0:a1734fe1ec4b 626 g_xStatus = SpiritSpiReadRegisters(SYNT0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 627
vpcola 0:a1734fe1ec4b 628 /* Mask the SYNTH[4;0] field and write the BS value */
vpcola 0:a1734fe1ec4b 629 tempRegValue &= 0xF8;
vpcola 0:a1734fe1ec4b 630 tempRegValue |= s_vectcBandRegValue[xBand];
vpcola 0:a1734fe1ec4b 631
vpcola 0:a1734fe1ec4b 632 /* Configures the SYNT0 register setting the operating band */
vpcola 0:a1734fe1ec4b 633 g_xStatus = SpiritSpiWriteRegisters(SYNT0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 634
vpcola 0:a1734fe1ec4b 635 }
vpcola 0:a1734fe1ec4b 636
vpcola 0:a1734fe1ec4b 637
vpcola 0:a1734fe1ec4b 638 /**
vpcola 0:a1734fe1ec4b 639 * @brief Returns the operating band.
vpcola 0:a1734fe1ec4b 640 * @param None.
vpcola 0:a1734fe1ec4b 641 * @retval BandSelect Settled band.
vpcola 0:a1734fe1ec4b 642 * This returned value can be one of the following parameters:
vpcola 0:a1734fe1ec4b 643 * @arg HIGH_BAND High_Band selected: from 779 MHz to 915 MHz
vpcola 0:a1734fe1ec4b 644 * @arg MIDDLE_BAND: Middle Band selected: from 387 MHz to 470 MHz
vpcola 0:a1734fe1ec4b 645 * @arg LOW_BAND: Low Band selected: from 300 MHz to 348 MHz
vpcola 0:a1734fe1ec4b 646 * @arg VERY_LOW_BAND: Very low Band selected: from 150 MHz to 174 MHz
vpcola 0:a1734fe1ec4b 647 */
vpcola 0:a1734fe1ec4b 648 BandSelect SpiritRadioGetBand(void)
vpcola 0:a1734fe1ec4b 649 {
vpcola 0:a1734fe1ec4b 650 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 651
vpcola 0:a1734fe1ec4b 652 /* Reads the SYNT0 register */
vpcola 0:a1734fe1ec4b 653 g_xStatus = SpiritSpiReadRegisters(SYNT0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 654
vpcola 0:a1734fe1ec4b 655 /* Mask the Band selected field */
vpcola 0:a1734fe1ec4b 656 if((tempRegValue & 0x07) == SYNT0_BS_6)
vpcola 0:a1734fe1ec4b 657 {
vpcola 0:a1734fe1ec4b 658 return HIGH_BAND;
vpcola 0:a1734fe1ec4b 659 }
vpcola 0:a1734fe1ec4b 660 else if ((tempRegValue & 0x07) == SYNT0_BS_12)
vpcola 0:a1734fe1ec4b 661 {
vpcola 0:a1734fe1ec4b 662 return MIDDLE_BAND;
vpcola 0:a1734fe1ec4b 663 }
vpcola 0:a1734fe1ec4b 664 else if ((tempRegValue & 0x07) == SYNT0_BS_16)
vpcola 0:a1734fe1ec4b 665 {
vpcola 0:a1734fe1ec4b 666 return LOW_BAND;
vpcola 0:a1734fe1ec4b 667 }
vpcola 0:a1734fe1ec4b 668 else
vpcola 0:a1734fe1ec4b 669 {
vpcola 0:a1734fe1ec4b 670 return VERY_LOW_BAND;
vpcola 0:a1734fe1ec4b 671 }
vpcola 0:a1734fe1ec4b 672
vpcola 0:a1734fe1ec4b 673 }
vpcola 0:a1734fe1ec4b 674
vpcola 0:a1734fe1ec4b 675
vpcola 0:a1734fe1ec4b 676 /**
vpcola 0:a1734fe1ec4b 677 * @brief Sets the channel number.
vpcola 0:a1734fe1ec4b 678 * @param cChannel the channel number.
vpcola 0:a1734fe1ec4b 679 * @retval None.
vpcola 0:a1734fe1ec4b 680 */
vpcola 0:a1734fe1ec4b 681 void SpiritRadioSetChannel(uint8_t cChannel)
vpcola 0:a1734fe1ec4b 682 {
vpcola 0:a1734fe1ec4b 683 /* Writes the CHNUM register */
vpcola 0:a1734fe1ec4b 684 g_xStatus = SpiritSpiWriteRegisters(CHNUM_BASE, 1, &cChannel);
vpcola 0:a1734fe1ec4b 685
vpcola 0:a1734fe1ec4b 686 }
vpcola 0:a1734fe1ec4b 687
vpcola 0:a1734fe1ec4b 688
vpcola 0:a1734fe1ec4b 689 /**
vpcola 0:a1734fe1ec4b 690 * @brief Returns the actual channel number.
vpcola 0:a1734fe1ec4b 691 * @param None.
vpcola 0:a1734fe1ec4b 692 * @retval uint8_t Actual channel number.
vpcola 0:a1734fe1ec4b 693 */
vpcola 0:a1734fe1ec4b 694 uint8_t SpiritRadioGetChannel(void)
vpcola 0:a1734fe1ec4b 695 {
vpcola 0:a1734fe1ec4b 696 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 697
vpcola 0:a1734fe1ec4b 698 /* Reads the CHNUM register and return the value */
vpcola 0:a1734fe1ec4b 699 g_xStatus = SpiritSpiReadRegisters(CHNUM_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 700
vpcola 0:a1734fe1ec4b 701 return tempRegValue;
vpcola 0:a1734fe1ec4b 702
vpcola 0:a1734fe1ec4b 703 }
vpcola 0:a1734fe1ec4b 704
vpcola 0:a1734fe1ec4b 705
vpcola 0:a1734fe1ec4b 706 /**
vpcola 0:a1734fe1ec4b 707 * @brief Sets the channel space factor in channel space register.
vpcola 0:a1734fe1ec4b 708 * The channel spacing step is computed as F_Xo/32768.
vpcola 0:a1734fe1ec4b 709 * @param fChannelSpace the channel space expressed in Hz.
vpcola 0:a1734fe1ec4b 710 * @retval None.
vpcola 0:a1734fe1ec4b 711 */
vpcola 0:a1734fe1ec4b 712 void SpiritRadioSetChannelSpace(uint32_t fChannelSpace)
vpcola 0:a1734fe1ec4b 713 {
vpcola 0:a1734fe1ec4b 714 uint8_t cChannelSpaceFactor;
vpcola 0:a1734fe1ec4b 715
vpcola 0:a1734fe1ec4b 716 /* Round to the nearest integer */
vpcola 0:a1734fe1ec4b 717 cChannelSpaceFactor = ((uint32_t)fChannelSpace*CHSPACE_DIVIDER)/s_lXtalFrequency;
vpcola 0:a1734fe1ec4b 718
vpcola 0:a1734fe1ec4b 719 /* Write value into the register */
vpcola 0:a1734fe1ec4b 720 g_xStatus = SpiritSpiWriteRegisters(CHSPACE_BASE, 1, &cChannelSpaceFactor);
vpcola 0:a1734fe1ec4b 721
vpcola 0:a1734fe1ec4b 722 }
vpcola 0:a1734fe1ec4b 723
vpcola 0:a1734fe1ec4b 724
vpcola 0:a1734fe1ec4b 725 /**
vpcola 0:a1734fe1ec4b 726 * @brief Returns the channel space register.
vpcola 0:a1734fe1ec4b 727 * @param None.
vpcola 0:a1734fe1ec4b 728 * @retval uint32_t Channel space. The channel space is: CS = channel_space_factor x XtalFrequency/2^15
vpcola 0:a1734fe1ec4b 729 * where channel_space_factor is the CHSPACE register value.
vpcola 0:a1734fe1ec4b 730 */
vpcola 0:a1734fe1ec4b 731 uint32_t SpiritRadioGetChannelSpace(void)
vpcola 0:a1734fe1ec4b 732 {
vpcola 0:a1734fe1ec4b 733 uint8_t channelSpaceFactor;
vpcola 0:a1734fe1ec4b 734
vpcola 0:a1734fe1ec4b 735 /* Reads the CHSPACE register, calculate the channel space and return it */
vpcola 0:a1734fe1ec4b 736 g_xStatus = SpiritSpiReadRegisters(CHSPACE_BASE, 1, &channelSpaceFactor);
vpcola 0:a1734fe1ec4b 737
vpcola 0:a1734fe1ec4b 738 /* Compute the Hertz value and return it */
vpcola 0:a1734fe1ec4b 739 return ((channelSpaceFactor*s_lXtalFrequency)/CHSPACE_DIVIDER);
vpcola 0:a1734fe1ec4b 740
vpcola 0:a1734fe1ec4b 741 }
vpcola 0:a1734fe1ec4b 742
vpcola 0:a1734fe1ec4b 743
vpcola 0:a1734fe1ec4b 744 /**
vpcola 0:a1734fe1ec4b 745 * @brief Sets the FC OFFSET register starting from xtal ppm value.
vpcola 0:a1734fe1ec4b 746 * @param nXtalPpm the xtal offset expressed in ppm.
vpcola 0:a1734fe1ec4b 747 * @retval None.
vpcola 0:a1734fe1ec4b 748 */
vpcola 0:a1734fe1ec4b 749 void SpiritRadioSetFrequencyOffsetPpm(int16_t nXtalPpm)
vpcola 0:a1734fe1ec4b 750 {
vpcola 0:a1734fe1ec4b 751 uint8_t tempArray[2];
vpcola 0:a1734fe1ec4b 752 int16_t xtalOffsetFactor;
vpcola 0:a1734fe1ec4b 753 uint32_t synthWord, fBase;
vpcola 0:a1734fe1ec4b 754 int32_t FOffsetTmp;
vpcola 0:a1734fe1ec4b 755 BandSelect band;
vpcola 0:a1734fe1ec4b 756
vpcola 0:a1734fe1ec4b 757 /* Reads the synth word */
vpcola 0:a1734fe1ec4b 758 synthWord = SpiritRadioGetSynthWord();
vpcola 0:a1734fe1ec4b 759
vpcola 0:a1734fe1ec4b 760 /* Reads the operating band */
vpcola 0:a1734fe1ec4b 761 band = SpiritRadioGetBand();
vpcola 0:a1734fe1ec4b 762
vpcola 0:a1734fe1ec4b 763 /* Calculates the frequency base */
vpcola 0:a1734fe1ec4b 764 uint8_t cRefDiv = (uint8_t)SpiritRadioGetRefDiv()+1;
vpcola 0:a1734fe1ec4b 765 fBase = synthWord*(s_lXtalFrequency/(s_vectcBHalfFactor[band]*cRefDiv)/FBASE_DIVIDER);
vpcola 0:a1734fe1ec4b 766
vpcola 0:a1734fe1ec4b 767 /* Calculates the offset respect to RF frequency and according to xtal_ppm parameter */
vpcola 0:a1734fe1ec4b 768 FOffsetTmp = (int32_t)(((float)nXtalPpm*fBase)/PPM_FACTOR);
vpcola 0:a1734fe1ec4b 769
vpcola 0:a1734fe1ec4b 770 /* Check the Offset is in the correct range */
vpcola 0:a1734fe1ec4b 771 s_assert_param(IS_FREQUENCY_OFFSET(FOffsetTmp,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 772
vpcola 0:a1734fe1ec4b 773 /* Calculates the FC_OFFSET value to write in the corresponding register */
vpcola 0:a1734fe1ec4b 774 xtalOffsetFactor = (int16_t)(((float)FOffsetTmp*FBASE_DIVIDER)/s_lXtalFrequency);
vpcola 0:a1734fe1ec4b 775
vpcola 0:a1734fe1ec4b 776 /* Build the array related to the FC_OFFSET_1 and FC_OFFSET_0 register */
vpcola 0:a1734fe1ec4b 777 tempArray[0]=(uint8_t)((((uint16_t)xtalOffsetFactor)>>8)&0x0F);
vpcola 0:a1734fe1ec4b 778 tempArray[1]=(uint8_t)(xtalOffsetFactor);
vpcola 0:a1734fe1ec4b 779
vpcola 0:a1734fe1ec4b 780 /* Writes the FC_OFFSET registers */
vpcola 0:a1734fe1ec4b 781 g_xStatus = SpiritSpiWriteRegisters(FC_OFFSET1_BASE, 2, tempArray);
vpcola 0:a1734fe1ec4b 782
vpcola 0:a1734fe1ec4b 783 }
vpcola 0:a1734fe1ec4b 784
vpcola 0:a1734fe1ec4b 785
vpcola 0:a1734fe1ec4b 786 /**
vpcola 0:a1734fe1ec4b 787 * @brief Sets the FC OFFSET register starting from frequency offset expressed in Hz.
vpcola 0:a1734fe1ec4b 788 * @param lFOffset frequency offset expressed in Hz as signed word.
vpcola 0:a1734fe1ec4b 789 * @retval None.
vpcola 0:a1734fe1ec4b 790 */
vpcola 0:a1734fe1ec4b 791 void SpiritRadioSetFrequencyOffset(int32_t lFOffset)
vpcola 0:a1734fe1ec4b 792 {
vpcola 0:a1734fe1ec4b 793 uint8_t tempArray[2];
vpcola 0:a1734fe1ec4b 794 int16_t offset;
vpcola 0:a1734fe1ec4b 795
vpcola 0:a1734fe1ec4b 796 /* Check that the Offset is in the correct range */
vpcola 0:a1734fe1ec4b 797 s_assert_param(IS_FREQUENCY_OFFSET(lFOffset,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 798
vpcola 0:a1734fe1ec4b 799 /* Calculates the offset value to write in the FC_OFFSET register */
vpcola 0:a1734fe1ec4b 800 offset = (int16_t)(((float)lFOffset*FBASE_DIVIDER)/s_lXtalFrequency);
vpcola 0:a1734fe1ec4b 801
vpcola 0:a1734fe1ec4b 802 /* Build the array related to the FC_OFFSET_1 and FC_OFFSET_0 register */
vpcola 0:a1734fe1ec4b 803 tempArray[0]=(uint8_t)((((uint16_t)offset)>>8)&0x0F);
vpcola 0:a1734fe1ec4b 804 tempArray[1]=(uint8_t)(offset);
vpcola 0:a1734fe1ec4b 805
vpcola 0:a1734fe1ec4b 806 /* Writes the FC_OFFSET registers */
vpcola 0:a1734fe1ec4b 807 g_xStatus = SpiritSpiWriteRegisters(FC_OFFSET1_BASE, 2, tempArray);
vpcola 0:a1734fe1ec4b 808
vpcola 0:a1734fe1ec4b 809 }
vpcola 0:a1734fe1ec4b 810
vpcola 0:a1734fe1ec4b 811
vpcola 0:a1734fe1ec4b 812 /**
vpcola 0:a1734fe1ec4b 813 * @brief Returns the actual frequency offset.
vpcola 0:a1734fe1ec4b 814 * @param None.
vpcola 0:a1734fe1ec4b 815 * @retval int32_t Frequency offset expressed in Hz as signed word.
vpcola 0:a1734fe1ec4b 816 */
vpcola 0:a1734fe1ec4b 817 int32_t SpiritRadioGetFrequencyOffset(void)
vpcola 0:a1734fe1ec4b 818 {
vpcola 0:a1734fe1ec4b 819 uint8_t tempArray[2];
vpcola 0:a1734fe1ec4b 820 int16_t xtalOffsetFactor;
vpcola 0:a1734fe1ec4b 821
vpcola 0:a1734fe1ec4b 822 /* Reads the FC_OFFSET registers */
vpcola 0:a1734fe1ec4b 823 g_xStatus = SpiritSpiReadRegisters(FC_OFFSET1_BASE, 2, tempArray);
vpcola 0:a1734fe1ec4b 824
vpcola 0:a1734fe1ec4b 825 /* Calculates the Offset Factor */
vpcola 0:a1734fe1ec4b 826 uint16_t xtalOffTemp = ((((uint16_t)tempArray[0])<<8)+((uint16_t)tempArray[1]));
vpcola 0:a1734fe1ec4b 827
vpcola 0:a1734fe1ec4b 828 if(xtalOffTemp & 0x0800)
vpcola 0:a1734fe1ec4b 829 {
vpcola 0:a1734fe1ec4b 830 xtalOffTemp = xtalOffTemp | 0xF000;
vpcola 0:a1734fe1ec4b 831 }
vpcola 0:a1734fe1ec4b 832 else
vpcola 0:a1734fe1ec4b 833 {
vpcola 0:a1734fe1ec4b 834 xtalOffTemp = xtalOffTemp & 0x0FFF;
vpcola 0:a1734fe1ec4b 835 }
vpcola 0:a1734fe1ec4b 836
vpcola 0:a1734fe1ec4b 837 xtalOffsetFactor = *((int16_t*)(&xtalOffTemp));
vpcola 0:a1734fe1ec4b 838
vpcola 0:a1734fe1ec4b 839 /* Calculates the frequency offset and return it */
vpcola 0:a1734fe1ec4b 840 return ((int32_t)(xtalOffsetFactor*s_lXtalFrequency)/FBASE_DIVIDER);
vpcola 0:a1734fe1ec4b 841
vpcola 0:a1734fe1ec4b 842 }
vpcola 0:a1734fe1ec4b 843
vpcola 0:a1734fe1ec4b 844
vpcola 0:a1734fe1ec4b 845
vpcola 0:a1734fe1ec4b 846 /**
vpcola 0:a1734fe1ec4b 847 * @brief Sets the Synth word and the Band Select register according to desired base carrier frequency.
vpcola 0:a1734fe1ec4b 848 * In this API the Xtal configuration is read out from
vpcola 0:a1734fe1ec4b 849 * the corresponding register. The user shall fix it before call this API.
vpcola 0:a1734fe1ec4b 850 * @param lFBase the base carrier frequency expressed in Hz as unsigned word.
vpcola 0:a1734fe1ec4b 851 * @retval Error code: 0=no error, 1=error during calibration of VCO.
vpcola 0:a1734fe1ec4b 852 */
vpcola 0:a1734fe1ec4b 853 uint8_t SpiritRadioSetFrequencyBase(uint32_t lFBase)
vpcola 0:a1734fe1ec4b 854 {
vpcola 0:a1734fe1ec4b 855 uint32_t synthWord, Fc;
vpcola 0:a1734fe1ec4b 856 uint8_t band, anaRadioRegArray[4], wcp;
vpcola 0:a1734fe1ec4b 857
vpcola 0:a1734fe1ec4b 858 /* Check the parameter */
vpcola 0:a1734fe1ec4b 859 s_assert_param(IS_FREQUENCY_BAND(lFBase));
vpcola 0:a1734fe1ec4b 860
vpcola 0:a1734fe1ec4b 861 /* Search the operating band */
vpcola 0:a1734fe1ec4b 862 if(IS_FREQUENCY_BAND_HIGH(lFBase))
vpcola 0:a1734fe1ec4b 863 {
vpcola 0:a1734fe1ec4b 864 band = HIGH_BAND;
vpcola 0:a1734fe1ec4b 865 }
vpcola 0:a1734fe1ec4b 866 else if(IS_FREQUENCY_BAND_MIDDLE(lFBase))
vpcola 0:a1734fe1ec4b 867 {
vpcola 0:a1734fe1ec4b 868 band = MIDDLE_BAND;
vpcola 0:a1734fe1ec4b 869 }
vpcola 0:a1734fe1ec4b 870 else if(IS_FREQUENCY_BAND_LOW(lFBase))
vpcola 0:a1734fe1ec4b 871 {
vpcola 0:a1734fe1ec4b 872 band = LOW_BAND;
vpcola 0:a1734fe1ec4b 873 }
vpcola 0:a1734fe1ec4b 874 else
vpcola 0:a1734fe1ec4b 875 {
vpcola 0:a1734fe1ec4b 876 band = VERY_LOW_BAND;
vpcola 0:a1734fe1ec4b 877 }
vpcola 0:a1734fe1ec4b 878
vpcola 0:a1734fe1ec4b 879 int32_t FOffset = SpiritRadioGetFrequencyOffset();
vpcola 0:a1734fe1ec4b 880 uint32_t lChannelSpace = SpiritRadioGetChannelSpace();
vpcola 0:a1734fe1ec4b 881 uint8_t cChannelNum = SpiritRadioGetChannel();
vpcola 0:a1734fe1ec4b 882
vpcola 0:a1734fe1ec4b 883 /* Calculates the channel center frequency */
vpcola 0:a1734fe1ec4b 884 Fc = lFBase + FOffset + lChannelSpace*cChannelNum;
vpcola 0:a1734fe1ec4b 885
vpcola 0:a1734fe1ec4b 886 /* Reads the reference divider */
vpcola 0:a1734fe1ec4b 887 uint8_t cRefDiv = (uint8_t)SpiritRadioGetRefDiv()+1;
vpcola 0:a1734fe1ec4b 888
vpcola 0:a1734fe1ec4b 889 /* Selects the VCO */
vpcola 0:a1734fe1ec4b 890 switch(band)
vpcola 0:a1734fe1ec4b 891 {
vpcola 0:a1734fe1ec4b 892 case VERY_LOW_BAND:
vpcola 0:a1734fe1ec4b 893 if(Fc<161281250)
vpcola 0:a1734fe1ec4b 894 {
vpcola 0:a1734fe1ec4b 895 SpiritCalibrationSelectVco(VCO_L);
vpcola 0:a1734fe1ec4b 896 }
vpcola 0:a1734fe1ec4b 897 else
vpcola 0:a1734fe1ec4b 898 {
vpcola 0:a1734fe1ec4b 899 SpiritCalibrationSelectVco(VCO_H);
vpcola 0:a1734fe1ec4b 900 }
vpcola 0:a1734fe1ec4b 901 break;
vpcola 0:a1734fe1ec4b 902
vpcola 0:a1734fe1ec4b 903 case LOW_BAND:
vpcola 0:a1734fe1ec4b 904 if(Fc<322562500)
vpcola 0:a1734fe1ec4b 905 {
vpcola 0:a1734fe1ec4b 906 SpiritCalibrationSelectVco(VCO_L);
vpcola 0:a1734fe1ec4b 907 }
vpcola 0:a1734fe1ec4b 908 else
vpcola 0:a1734fe1ec4b 909 {
vpcola 0:a1734fe1ec4b 910 SpiritCalibrationSelectVco(VCO_H);
vpcola 0:a1734fe1ec4b 911 }
vpcola 0:a1734fe1ec4b 912 break;
vpcola 0:a1734fe1ec4b 913
vpcola 0:a1734fe1ec4b 914 case MIDDLE_BAND:
vpcola 0:a1734fe1ec4b 915 if(Fc<430083334)
vpcola 0:a1734fe1ec4b 916 {
vpcola 0:a1734fe1ec4b 917 SpiritCalibrationSelectVco(VCO_L);
vpcola 0:a1734fe1ec4b 918 }
vpcola 0:a1734fe1ec4b 919 else
vpcola 0:a1734fe1ec4b 920 {
vpcola 0:a1734fe1ec4b 921 SpiritCalibrationSelectVco(VCO_H);
vpcola 0:a1734fe1ec4b 922 }
vpcola 0:a1734fe1ec4b 923 break;
vpcola 0:a1734fe1ec4b 924
vpcola 0:a1734fe1ec4b 925 case HIGH_BAND:
vpcola 0:a1734fe1ec4b 926 if(Fc<860166667)
vpcola 0:a1734fe1ec4b 927 {
vpcola 0:a1734fe1ec4b 928 SpiritCalibrationSelectVco(VCO_L);
vpcola 0:a1734fe1ec4b 929 }
vpcola 0:a1734fe1ec4b 930 else
vpcola 0:a1734fe1ec4b 931 {
vpcola 0:a1734fe1ec4b 932 SpiritCalibrationSelectVco(VCO_H);
vpcola 0:a1734fe1ec4b 933 }
vpcola 0:a1734fe1ec4b 934 }
vpcola 0:a1734fe1ec4b 935
vpcola 0:a1734fe1ec4b 936 /* Search the VCO charge pump word and set the corresponding register */
vpcola 0:a1734fe1ec4b 937 wcp = SpiritRadioSearchWCP(Fc);
vpcola 0:a1734fe1ec4b 938
vpcola 0:a1734fe1ec4b 939 synthWord = (uint32_t)(lFBase*s_vectcBHalfFactor[band]*(((double)(FBASE_DIVIDER*cRefDiv))/s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 940
vpcola 0:a1734fe1ec4b 941 /* Build the array of registers values for the analog part */
vpcola 0:a1734fe1ec4b 942 anaRadioRegArray[0] = (uint8_t)(((synthWord>>21)&(0x0000001F))|(wcp<<5));
vpcola 0:a1734fe1ec4b 943 anaRadioRegArray[1] = (uint8_t)((synthWord>>13)&(0x000000FF));
vpcola 0:a1734fe1ec4b 944 anaRadioRegArray[2] = (uint8_t)((synthWord>>5)&(0x000000FF));
vpcola 0:a1734fe1ec4b 945 anaRadioRegArray[3] = (uint8_t)(((synthWord&0x0000001F)<<3)| s_vectcBandRegValue[band]);
vpcola 0:a1734fe1ec4b 946
vpcola 0:a1734fe1ec4b 947 /* Configures the needed Analog Radio registers */
vpcola 0:a1734fe1ec4b 948 g_xStatus = SpiritSpiWriteRegisters(SYNT3_BASE, 4, anaRadioRegArray);
vpcola 0:a1734fe1ec4b 949
vpcola 0:a1734fe1ec4b 950 if(xDoVcoCalibrationWA==S_ENABLE)
vpcola 0:a1734fe1ec4b 951 return SpiritManagementWaVcoCalibration();
vpcola 0:a1734fe1ec4b 952
vpcola 0:a1734fe1ec4b 953 return 0;
vpcola 0:a1734fe1ec4b 954 }
vpcola 0:a1734fe1ec4b 955
vpcola 0:a1734fe1ec4b 956 /**
vpcola 0:a1734fe1ec4b 957 * @brief To say to the set frequency base if do or not the VCO calibration WA.
vpcola 0:a1734fe1ec4b 958 * @param S_ENABLE or S_DISABLE the WA procedure.
vpcola 0:a1734fe1ec4b 959 * @retval None.
vpcola 0:a1734fe1ec4b 960 */
vpcola 0:a1734fe1ec4b 961 void SpiritRadioVcoCalibrationWAFB(SpiritFunctionalState xNewstate)
vpcola 0:a1734fe1ec4b 962 {
vpcola 0:a1734fe1ec4b 963 xDoVcoCalibrationWA=xNewstate;
vpcola 0:a1734fe1ec4b 964 }
vpcola 0:a1734fe1ec4b 965
vpcola 0:a1734fe1ec4b 966 /**
vpcola 0:a1734fe1ec4b 967 * @brief Returns the base carrier frequency.
vpcola 0:a1734fe1ec4b 968 * @param None.
vpcola 0:a1734fe1ec4b 969 * @retval uint32_t Base carrier frequency expressed in Hz as unsigned word.
vpcola 0:a1734fe1ec4b 970 */
vpcola 0:a1734fe1ec4b 971 uint32_t SpiritRadioGetFrequencyBase(void)
vpcola 0:a1734fe1ec4b 972 {
vpcola 0:a1734fe1ec4b 973 uint32_t synthWord;
vpcola 0:a1734fe1ec4b 974 BandSelect band;
vpcola 0:a1734fe1ec4b 975
vpcola 0:a1734fe1ec4b 976 /* Reads the synth word */
vpcola 0:a1734fe1ec4b 977 synthWord = SpiritRadioGetSynthWord();
vpcola 0:a1734fe1ec4b 978
vpcola 0:a1734fe1ec4b 979 /* Reads the operating band */
vpcola 0:a1734fe1ec4b 980 band = SpiritRadioGetBand();
vpcola 0:a1734fe1ec4b 981
vpcola 0:a1734fe1ec4b 982 uint8_t cRefDiv = (uint8_t)SpiritRadioGetRefDiv() + 1;
vpcola 0:a1734fe1ec4b 983
vpcola 0:a1734fe1ec4b 984 /* Calculates the frequency base and return it */
vpcola 0:a1734fe1ec4b 985 return (uint32_t)round(synthWord*(((double)s_lXtalFrequency)/(FBASE_DIVIDER*cRefDiv*s_vectcBHalfFactor[band])));
vpcola 0:a1734fe1ec4b 986 }
vpcola 0:a1734fe1ec4b 987
vpcola 0:a1734fe1ec4b 988
vpcola 0:a1734fe1ec4b 989 /**
vpcola 0:a1734fe1ec4b 990 * @brief Returns the actual channel center frequency.
vpcola 0:a1734fe1ec4b 991 * @param None.
vpcola 0:a1734fe1ec4b 992 * @retval uint32_t Actual channel center frequency expressed in Hz.
vpcola 0:a1734fe1ec4b 993 */
vpcola 0:a1734fe1ec4b 994 uint32_t SpiritRadioGetCenterFrequency(void)
vpcola 0:a1734fe1ec4b 995 {
vpcola 0:a1734fe1ec4b 996 int32_t offset;
vpcola 0:a1734fe1ec4b 997 uint8_t channel;
vpcola 0:a1734fe1ec4b 998 uint32_t fBase;
vpcola 0:a1734fe1ec4b 999 uint32_t channelSpace;
vpcola 0:a1734fe1ec4b 1000
vpcola 0:a1734fe1ec4b 1001 /* Reads the frequency base */
vpcola 0:a1734fe1ec4b 1002 fBase = SpiritRadioGetFrequencyBase();
vpcola 0:a1734fe1ec4b 1003
vpcola 0:a1734fe1ec4b 1004 /* Reads the frequency offset */
vpcola 0:a1734fe1ec4b 1005 offset = SpiritRadioGetFrequencyOffset();
vpcola 0:a1734fe1ec4b 1006
vpcola 0:a1734fe1ec4b 1007 /* Reads the channel space */
vpcola 0:a1734fe1ec4b 1008 channelSpace = SpiritRadioGetChannelSpace();
vpcola 0:a1734fe1ec4b 1009
vpcola 0:a1734fe1ec4b 1010 /* Reads the channel number */
vpcola 0:a1734fe1ec4b 1011 channel = SpiritRadioGetChannel();
vpcola 0:a1734fe1ec4b 1012
vpcola 0:a1734fe1ec4b 1013 /* Calculates the channel center frequency and return it */
vpcola 0:a1734fe1ec4b 1014 return (uint32_t)(fBase + offset + (uint32_t)(channelSpace*channel));
vpcola 0:a1734fe1ec4b 1015
vpcola 0:a1734fe1ec4b 1016 }
vpcola 0:a1734fe1ec4b 1017
vpcola 0:a1734fe1ec4b 1018
vpcola 0:a1734fe1ec4b 1019 /**
vpcola 0:a1734fe1ec4b 1020 * @brief Returns the mantissa and exponent, whose value used in the datarate formula
vpcola 0:a1734fe1ec4b 1021 * will give the datarate value closer to the given datarate.
vpcola 0:a1734fe1ec4b 1022 * @param fDatarate datarate expressed in bps. This parameter ranging between 100 and 500000.
vpcola 0:a1734fe1ec4b 1023 * @param pcM pointer to the returned mantissa value.
vpcola 0:a1734fe1ec4b 1024 * @param pcE pointer to the returned exponent value.
vpcola 0:a1734fe1ec4b 1025 * @retval None.
vpcola 0:a1734fe1ec4b 1026 */
vpcola 0:a1734fe1ec4b 1027 void SpiritRadioSearchDatarateME(uint32_t lDatarate, uint8_t* pcM, uint8_t* pcE)
vpcola 0:a1734fe1ec4b 1028 {
vpcola 0:a1734fe1ec4b 1029 volatile SpiritBool find = S_FALSE;
vpcola 0:a1734fe1ec4b 1030 int8_t i=15;
vpcola 0:a1734fe1ec4b 1031 uint8_t cMantissaTmp;
vpcola 0:a1734fe1ec4b 1032 uint8_t cDivider = 0;
vpcola 0:a1734fe1ec4b 1033
vpcola 0:a1734fe1ec4b 1034 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1035 s_assert_param(IS_DATARATE(lDatarate));
vpcola 0:a1734fe1ec4b 1036
vpcola 0:a1734fe1ec4b 1037 cDivider = (uint8_t)SpiritRadioGetDigDiv();
vpcola 0:a1734fe1ec4b 1038
vpcola 0:a1734fe1ec4b 1039 /* Search in the datarate array the exponent value */
vpcola 0:a1734fe1ec4b 1040 while(!find && i>=0)
vpcola 0:a1734fe1ec4b 1041 {
vpcola 0:a1734fe1ec4b 1042 if(lDatarate>=(s_lXtalFrequency>>(20-i+cDivider)))
vpcola 0:a1734fe1ec4b 1043 {
vpcola 0:a1734fe1ec4b 1044 find = S_TRUE;
vpcola 0:a1734fe1ec4b 1045 }
vpcola 0:a1734fe1ec4b 1046 else
vpcola 0:a1734fe1ec4b 1047 {
vpcola 0:a1734fe1ec4b 1048 i--;
vpcola 0:a1734fe1ec4b 1049 }
vpcola 0:a1734fe1ec4b 1050 }
vpcola 0:a1734fe1ec4b 1051 i<0 ? i=0 : i;
vpcola 0:a1734fe1ec4b 1052 *pcE = i;
vpcola 0:a1734fe1ec4b 1053
vpcola 0:a1734fe1ec4b 1054 /* Calculates the mantissa value according to the datarate formula */
vpcola 0:a1734fe1ec4b 1055 cMantissaTmp = (lDatarate*((uint32_t)1<<(23-i)))/(s_lXtalFrequency>>(5+cDivider))-256;
vpcola 0:a1734fe1ec4b 1056
vpcola 0:a1734fe1ec4b 1057 /* Finds the mantissa value with less approximation */
vpcola 0:a1734fe1ec4b 1058 int16_t mantissaCalculation[3];
vpcola 0:a1734fe1ec4b 1059 for(uint8_t j=0;j<3;j++)
vpcola 0:a1734fe1ec4b 1060 {
vpcola 0:a1734fe1ec4b 1061 if((cMantissaTmp+j-1))
vpcola 0:a1734fe1ec4b 1062 {
vpcola 0:a1734fe1ec4b 1063 mantissaCalculation[j]=lDatarate-(((256+cMantissaTmp+j-1)*(s_lXtalFrequency>>(5+cDivider)))>>(23-i));
vpcola 0:a1734fe1ec4b 1064 }
vpcola 0:a1734fe1ec4b 1065 else
vpcola 0:a1734fe1ec4b 1066 {
vpcola 0:a1734fe1ec4b 1067 mantissaCalculation[j]=0x7FFF;
vpcola 0:a1734fe1ec4b 1068 }
vpcola 0:a1734fe1ec4b 1069 }
vpcola 0:a1734fe1ec4b 1070 uint16_t mantissaCalculationDelta = 0xFFFF;
vpcola 0:a1734fe1ec4b 1071 for(uint8_t j=0;j<3;j++)
vpcola 0:a1734fe1ec4b 1072 {
vpcola 0:a1734fe1ec4b 1073 if(S_ABS(mantissaCalculation[j])<mantissaCalculationDelta)
vpcola 0:a1734fe1ec4b 1074 {
vpcola 0:a1734fe1ec4b 1075 mantissaCalculationDelta = S_ABS(mantissaCalculation[j]);
vpcola 0:a1734fe1ec4b 1076 *pcM = cMantissaTmp+j-1;
vpcola 0:a1734fe1ec4b 1077 }
vpcola 0:a1734fe1ec4b 1078 }
vpcola 0:a1734fe1ec4b 1079
vpcola 0:a1734fe1ec4b 1080 }
vpcola 0:a1734fe1ec4b 1081
vpcola 0:a1734fe1ec4b 1082
vpcola 0:a1734fe1ec4b 1083 /**
vpcola 0:a1734fe1ec4b 1084 * @brief Returns the mantissa and exponent for a given bandwidth.
vpcola 0:a1734fe1ec4b 1085 * Even if it is possible to pass as parameter any value in the below mentioned range,
vpcola 0:a1734fe1ec4b 1086 * the API will search the closer value according to a fixed table of channel
vpcola 0:a1734fe1ec4b 1087 * bandwidth values (@ref s_vectnBandwidth), as defined in the datasheet, returning the corresponding mantissa
vpcola 0:a1734fe1ec4b 1088 * and exponent value.
vpcola 0:a1734fe1ec4b 1089 * @param lBandwidth bandwidth expressed in Hz. This parameter ranging between 1100 and 800100.
vpcola 0:a1734fe1ec4b 1090 * @param pcM pointer to the returned mantissa value.
vpcola 0:a1734fe1ec4b 1091 * @param pcE pointer to the returned exponent value.
vpcola 0:a1734fe1ec4b 1092 * @retval None.
vpcola 0:a1734fe1ec4b 1093 */
vpcola 0:a1734fe1ec4b 1094 void SpiritRadioSearchChannelBwME(uint32_t lBandwidth, uint8_t* pcM, uint8_t* pcE)
vpcola 0:a1734fe1ec4b 1095 {
vpcola 0:a1734fe1ec4b 1096 int8_t i, i_tmp;
vpcola 0:a1734fe1ec4b 1097 uint8_t cDivider = 1;
vpcola 0:a1734fe1ec4b 1098
vpcola 0:a1734fe1ec4b 1099 /* Search in the channel filter bandwidth table the exponent value */
vpcola 0:a1734fe1ec4b 1100 if(SpiritRadioGetDigDiv())
vpcola 0:a1734fe1ec4b 1101 {
vpcola 0:a1734fe1ec4b 1102 cDivider = 2;
vpcola 0:a1734fe1ec4b 1103 }
vpcola 0:a1734fe1ec4b 1104 else
vpcola 0:a1734fe1ec4b 1105 {
vpcola 0:a1734fe1ec4b 1106 cDivider = 1;
vpcola 0:a1734fe1ec4b 1107 }
vpcola 0:a1734fe1ec4b 1108
vpcola 0:a1734fe1ec4b 1109 s_assert_param(IS_CH_BW(lBandwidth,s_lXtalFrequency/cDivider));
vpcola 0:a1734fe1ec4b 1110
vpcola 0:a1734fe1ec4b 1111 uint32_t lChfltFactor = (s_lXtalFrequency/cDivider)/100;
vpcola 0:a1734fe1ec4b 1112
vpcola 0:a1734fe1ec4b 1113 for(i=0;i<90 && (lBandwidth<(uint32_t)((s_vectnBandwidth26M[i]*lChfltFactor)/2600));i++);
vpcola 0:a1734fe1ec4b 1114
vpcola 0:a1734fe1ec4b 1115 if(i!=0)
vpcola 0:a1734fe1ec4b 1116 {
vpcola 0:a1734fe1ec4b 1117 /* Finds the mantissa value with less approximation */
vpcola 0:a1734fe1ec4b 1118 i_tmp=i;
vpcola 0:a1734fe1ec4b 1119 int16_t chfltCalculation[3];
vpcola 0:a1734fe1ec4b 1120 for(uint8_t j=0;j<3;j++)
vpcola 0:a1734fe1ec4b 1121 {
vpcola 0:a1734fe1ec4b 1122 if(((i_tmp+j-1)>=0) || ((i_tmp+j-1)<=89))
vpcola 0:a1734fe1ec4b 1123 {
vpcola 0:a1734fe1ec4b 1124 chfltCalculation[j] = lBandwidth - (uint32_t)((s_vectnBandwidth26M[i_tmp+j-1]*lChfltFactor)/2600);
vpcola 0:a1734fe1ec4b 1125 }
vpcola 0:a1734fe1ec4b 1126 else
vpcola 0:a1734fe1ec4b 1127 {
vpcola 0:a1734fe1ec4b 1128 chfltCalculation[j] = 0x7FFF;
vpcola 0:a1734fe1ec4b 1129 }
vpcola 0:a1734fe1ec4b 1130 }
vpcola 0:a1734fe1ec4b 1131 uint16_t chfltDelta = 0xFFFF;
vpcola 0:a1734fe1ec4b 1132
vpcola 0:a1734fe1ec4b 1133 for(uint8_t j=0;j<3;j++)
vpcola 0:a1734fe1ec4b 1134 {
vpcola 0:a1734fe1ec4b 1135 if(S_ABS(chfltCalculation[j])<chfltDelta)
vpcola 0:a1734fe1ec4b 1136 {
vpcola 0:a1734fe1ec4b 1137 chfltDelta = S_ABS(chfltCalculation[j]);
vpcola 0:a1734fe1ec4b 1138 i=i_tmp+j-1;
vpcola 0:a1734fe1ec4b 1139 }
vpcola 0:a1734fe1ec4b 1140 }
vpcola 0:a1734fe1ec4b 1141 }
vpcola 0:a1734fe1ec4b 1142 (*pcE) = (uint8_t)(i/9);
vpcola 0:a1734fe1ec4b 1143 (*pcM) = (uint8_t)(i%9);
vpcola 0:a1734fe1ec4b 1144
vpcola 0:a1734fe1ec4b 1145 }
vpcola 0:a1734fe1ec4b 1146
vpcola 0:a1734fe1ec4b 1147 /**
vpcola 0:a1734fe1ec4b 1148 * @brief Returns the mantissa and exponent, whose value used in the frequency deviation formula
vpcola 0:a1734fe1ec4b 1149 * will give a frequency deviation value most closer to the given frequency deviation.
vpcola 0:a1734fe1ec4b 1150 * @param fFDev frequency deviation expressed in Hz. This parameter can be a value in the range [F_Xo*8/2^18, F_Xo*7680/2^18].
vpcola 0:a1734fe1ec4b 1151 * @param pcM pointer to the returned mantissa value.
vpcola 0:a1734fe1ec4b 1152 * @param pcE pointer to the returned exponent value.
vpcola 0:a1734fe1ec4b 1153 * @retval None.
vpcola 0:a1734fe1ec4b 1154 */
vpcola 0:a1734fe1ec4b 1155 void SpiritRadioSearchFreqDevME(uint32_t lFDev, uint8_t* pcM, uint8_t* pcE)
vpcola 0:a1734fe1ec4b 1156 {
vpcola 0:a1734fe1ec4b 1157 uint8_t i;
vpcola 0:a1734fe1ec4b 1158 uint32_t a,bp,b=0;
vpcola 0:a1734fe1ec4b 1159 float xtalDivtmp=(float)s_lXtalFrequency/(((uint32_t)1)<<18);
vpcola 0:a1734fe1ec4b 1160
vpcola 0:a1734fe1ec4b 1161 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1162 s_assert_param(IS_F_DEV(lFDev,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 1163
vpcola 0:a1734fe1ec4b 1164 for(i=0;i<10;i++)
vpcola 0:a1734fe1ec4b 1165 {
vpcola 0:a1734fe1ec4b 1166 a=(uint32_t)(xtalDivtmp*(uint32_t)(7.5*(1<<i)));
vpcola 0:a1734fe1ec4b 1167 if(lFDev<a)
vpcola 0:a1734fe1ec4b 1168 break;
vpcola 0:a1734fe1ec4b 1169 }
vpcola 0:a1734fe1ec4b 1170 (*pcE) = i;
vpcola 0:a1734fe1ec4b 1171
vpcola 0:a1734fe1ec4b 1172 for(i=0;i<8;i++)
vpcola 0:a1734fe1ec4b 1173 {
vpcola 0:a1734fe1ec4b 1174 bp=b;
vpcola 0:a1734fe1ec4b 1175 b=(uint32_t)(xtalDivtmp*(uint32_t)((8.0+i)/2*(1<<(*pcE))));
vpcola 0:a1734fe1ec4b 1176 if(lFDev<b)
vpcola 0:a1734fe1ec4b 1177 break;
vpcola 0:a1734fe1ec4b 1178 }
vpcola 0:a1734fe1ec4b 1179
vpcola 0:a1734fe1ec4b 1180 (*pcM)=i;
vpcola 0:a1734fe1ec4b 1181 if((lFDev-bp)<(b-lFDev))
vpcola 0:a1734fe1ec4b 1182 (*pcM)--;
vpcola 0:a1734fe1ec4b 1183
vpcola 0:a1734fe1ec4b 1184 }
vpcola 0:a1734fe1ec4b 1185
vpcola 0:a1734fe1ec4b 1186
vpcola 0:a1734fe1ec4b 1187 /**
vpcola 0:a1734fe1ec4b 1188 * @brief Sets the datarate.
vpcola 0:a1734fe1ec4b 1189 * @param fDatarate datarate expressed in bps. This value shall be in the range
vpcola 0:a1734fe1ec4b 1190 * [100 500000].
vpcola 0:a1734fe1ec4b 1191 * @retval None.
vpcola 0:a1734fe1ec4b 1192 */
vpcola 0:a1734fe1ec4b 1193 void SpiritRadioSetDatarate(uint32_t lDatarate)
vpcola 0:a1734fe1ec4b 1194 {
vpcola 0:a1734fe1ec4b 1195 uint8_t drE, tempRegValue[2];
vpcola 0:a1734fe1ec4b 1196
vpcola 0:a1734fe1ec4b 1197 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1198 s_assert_param(IS_DATARATE(lDatarate));
vpcola 0:a1734fe1ec4b 1199
vpcola 0:a1734fe1ec4b 1200 /* Calculates the datarate mantissa and exponent */
vpcola 0:a1734fe1ec4b 1201 SpiritRadioSearchDatarateME(lDatarate, &tempRegValue[0], &drE);
vpcola 0:a1734fe1ec4b 1202
vpcola 0:a1734fe1ec4b 1203 /* Reads the MOD_O register*/
vpcola 0:a1734fe1ec4b 1204 SpiritSpiReadRegisters(MOD0_BASE, 1, &tempRegValue[1]);
vpcola 0:a1734fe1ec4b 1205
vpcola 0:a1734fe1ec4b 1206 /* Mask the other fields and set the datarate exponent */
vpcola 0:a1734fe1ec4b 1207 tempRegValue[1] &= 0xF0;
vpcola 0:a1734fe1ec4b 1208 tempRegValue[1] |= drE;
vpcola 0:a1734fe1ec4b 1209
vpcola 0:a1734fe1ec4b 1210 /* Writes the Datarate registers */
vpcola 0:a1734fe1ec4b 1211 g_xStatus = SpiritSpiWriteRegisters(MOD1_BASE, 2, tempRegValue);
vpcola 0:a1734fe1ec4b 1212
vpcola 0:a1734fe1ec4b 1213 }
vpcola 0:a1734fe1ec4b 1214
vpcola 0:a1734fe1ec4b 1215
vpcola 0:a1734fe1ec4b 1216 /**
vpcola 0:a1734fe1ec4b 1217 * @brief Returns the datarate.
vpcola 0:a1734fe1ec4b 1218 * @param None.
vpcola 0:a1734fe1ec4b 1219 * @retval uint32_t Settled datarate expressed in bps.
vpcola 0:a1734fe1ec4b 1220 */
vpcola 0:a1734fe1ec4b 1221 uint32_t SpiritRadioGetDatarate(void)
vpcola 0:a1734fe1ec4b 1222 {
vpcola 0:a1734fe1ec4b 1223 uint8_t tempRegValue[2];
vpcola 0:a1734fe1ec4b 1224 uint8_t cDivider=0;
vpcola 0:a1734fe1ec4b 1225
vpcola 0:a1734fe1ec4b 1226 /* Reads the datarate registers for mantissa and exponent */
vpcola 0:a1734fe1ec4b 1227 g_xStatus = SpiritSpiReadRegisters(MOD1_BASE, 2, tempRegValue);
vpcola 0:a1734fe1ec4b 1228
vpcola 0:a1734fe1ec4b 1229 /* Calculates the datarate */
vpcola 0:a1734fe1ec4b 1230 cDivider = (uint8_t)SpiritRadioGetDigDiv();
vpcola 0:a1734fe1ec4b 1231
vpcola 0:a1734fe1ec4b 1232 return (((s_lXtalFrequency>>(5+cDivider))*(256+tempRegValue[0]))>>(23-(tempRegValue[1]&0x0F)));
vpcola 0:a1734fe1ec4b 1233 }
vpcola 0:a1734fe1ec4b 1234
vpcola 0:a1734fe1ec4b 1235
vpcola 0:a1734fe1ec4b 1236 /**
vpcola 0:a1734fe1ec4b 1237 * @brief Sets the frequency deviation.
vpcola 0:a1734fe1ec4b 1238 * @param fFDev frequency deviation expressed in Hz. Be sure that this value
vpcola 0:a1734fe1ec4b 1239 * is in the correct range [F_Xo*8/2^18, F_Xo*7680/2^18] Hz.
vpcola 0:a1734fe1ec4b 1240 * @retval None.
vpcola 0:a1734fe1ec4b 1241 */
vpcola 0:a1734fe1ec4b 1242 void SpiritRadioSetFrequencyDev(uint32_t lFDev)
vpcola 0:a1734fe1ec4b 1243 {
vpcola 0:a1734fe1ec4b 1244 uint8_t FDevM, FDevE, tempRegValue;
vpcola 0:a1734fe1ec4b 1245
vpcola 0:a1734fe1ec4b 1246 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1247 s_assert_param(IS_F_DEV(lFDev, s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 1248
vpcola 0:a1734fe1ec4b 1249 /* Calculates the frequency deviation mantissa and exponent */
vpcola 0:a1734fe1ec4b 1250 SpiritRadioSearchFreqDevME(lFDev, &FDevM, &FDevE);
vpcola 0:a1734fe1ec4b 1251
vpcola 0:a1734fe1ec4b 1252 /* Reads the FDEV0 register */
vpcola 0:a1734fe1ec4b 1253 SpiritSpiReadRegisters(FDEV0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1254
vpcola 0:a1734fe1ec4b 1255 /* Mask the other fields and set the frequency deviation mantissa and exponent */
vpcola 0:a1734fe1ec4b 1256 tempRegValue &= 0x08;
vpcola 0:a1734fe1ec4b 1257 tempRegValue |= ((FDevE<<4)|(FDevM));
vpcola 0:a1734fe1ec4b 1258
vpcola 0:a1734fe1ec4b 1259 /* Writes the Frequency deviation register */
vpcola 0:a1734fe1ec4b 1260 g_xStatus = SpiritSpiWriteRegisters(FDEV0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1261
vpcola 0:a1734fe1ec4b 1262 }
vpcola 0:a1734fe1ec4b 1263
vpcola 0:a1734fe1ec4b 1264
vpcola 0:a1734fe1ec4b 1265 /**
vpcola 0:a1734fe1ec4b 1266 * @brief Returns the frequency deviation.
vpcola 0:a1734fe1ec4b 1267 * @param None.
vpcola 0:a1734fe1ec4b 1268 * @retval uint32_t Frequency deviation value expressed in Hz.
vpcola 0:a1734fe1ec4b 1269 * This value will be in the range [F_Xo*8/2^18, F_Xo*7680/2^18] Hz.
vpcola 0:a1734fe1ec4b 1270 */
vpcola 0:a1734fe1ec4b 1271 uint32_t SpiritRadioGetFrequencyDev(void)
vpcola 0:a1734fe1ec4b 1272 {
vpcola 0:a1734fe1ec4b 1273 uint8_t tempRegValue, FDevM, FDevE;
vpcola 0:a1734fe1ec4b 1274
vpcola 0:a1734fe1ec4b 1275
vpcola 0:a1734fe1ec4b 1276 /* Reads the frequency deviation register for mantissa and exponent */
vpcola 0:a1734fe1ec4b 1277 g_xStatus = SpiritSpiReadRegisters(FDEV0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1278 FDevM = tempRegValue&0x07;
vpcola 0:a1734fe1ec4b 1279 FDevE = (tempRegValue&0xF0)>>4;
vpcola 0:a1734fe1ec4b 1280
vpcola 0:a1734fe1ec4b 1281 /* Calculates the frequency deviation and return it */
vpcola 0:a1734fe1ec4b 1282 //return (((s_lXtalFrequency>>6)*(8+FDevM))>>(13-FDevE));
vpcola 0:a1734fe1ec4b 1283
vpcola 0:a1734fe1ec4b 1284 return (uint32_t)((float)s_lXtalFrequency/(((uint32_t)1)<<18)*(uint32_t)((8.0+FDevM)/2*(1<<FDevE)));
vpcola 0:a1734fe1ec4b 1285
vpcola 0:a1734fe1ec4b 1286 }
vpcola 0:a1734fe1ec4b 1287
vpcola 0:a1734fe1ec4b 1288
vpcola 0:a1734fe1ec4b 1289 /**
vpcola 0:a1734fe1ec4b 1290 * @brief Sets the channel filter bandwidth.
vpcola 0:a1734fe1ec4b 1291 * @param lBandwidth channel filter bandwidth expressed in Hz. This parameter shall be in the range [1100 800100]
vpcola 0:a1734fe1ec4b 1292 * Even if it is possible to pass as parameter any value in the above mentioned range,
vpcola 0:a1734fe1ec4b 1293 * the API will search the most closer value according to a fixed table of channel
vpcola 0:a1734fe1ec4b 1294 * bandwidth values (@ref s_vectnBandwidth), as defined in the datasheet. To verify the settled channel bandwidth
vpcola 0:a1734fe1ec4b 1295 * it is possible to use the SpiritRadioGetChannelBW() API.
vpcola 0:a1734fe1ec4b 1296 * @retval None.
vpcola 0:a1734fe1ec4b 1297 */
vpcola 0:a1734fe1ec4b 1298 void SpiritRadioSetChannelBW(uint32_t lBandwidth)
vpcola 0:a1734fe1ec4b 1299 {
vpcola 0:a1734fe1ec4b 1300 uint8_t bwM, bwE, tempRegValue;
vpcola 0:a1734fe1ec4b 1301
vpcola 0:a1734fe1ec4b 1302 /* Search in the channel filter bandwidth table the exponent value */
vpcola 0:a1734fe1ec4b 1303 if(SpiritRadioGetDigDiv())
vpcola 0:a1734fe1ec4b 1304 {
vpcola 0:a1734fe1ec4b 1305 s_assert_param(IS_CH_BW(lBandwidth,(s_lXtalFrequency/2)));
vpcola 0:a1734fe1ec4b 1306 }
vpcola 0:a1734fe1ec4b 1307 else
vpcola 0:a1734fe1ec4b 1308 {
vpcola 0:a1734fe1ec4b 1309 s_assert_param(IS_CH_BW(lBandwidth,(s_lXtalFrequency)));
vpcola 0:a1734fe1ec4b 1310 }
vpcola 0:a1734fe1ec4b 1311
vpcola 0:a1734fe1ec4b 1312 /* Calculates the channel bandwidth mantissa and exponent */
vpcola 0:a1734fe1ec4b 1313 SpiritRadioSearchChannelBwME(lBandwidth, &bwM, &bwE);
vpcola 0:a1734fe1ec4b 1314 tempRegValue = (bwM<<4)|(bwE);
vpcola 0:a1734fe1ec4b 1315
vpcola 0:a1734fe1ec4b 1316 /* Writes the Channel filter register */
vpcola 0:a1734fe1ec4b 1317 g_xStatus = SpiritSpiWriteRegisters(CHFLT_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1318
vpcola 0:a1734fe1ec4b 1319 }
vpcola 0:a1734fe1ec4b 1320
vpcola 0:a1734fe1ec4b 1321 /**
vpcola 0:a1734fe1ec4b 1322 * @brief Returns the channel filter bandwidth.
vpcola 0:a1734fe1ec4b 1323 * @param None.
vpcola 0:a1734fe1ec4b 1324 * @retval uint32_t Channel filter bandwidth expressed in Hz.
vpcola 0:a1734fe1ec4b 1325 */
vpcola 0:a1734fe1ec4b 1326 uint32_t SpiritRadioGetChannelBW(void)
vpcola 0:a1734fe1ec4b 1327 {
vpcola 0:a1734fe1ec4b 1328 uint8_t tempRegValue, bwM, bwE;
vpcola 0:a1734fe1ec4b 1329
vpcola 0:a1734fe1ec4b 1330 /* Reads the channel filter register for mantissa and exponent */
vpcola 0:a1734fe1ec4b 1331 g_xStatus = SpiritSpiReadRegisters(CHFLT_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1332 bwM = (tempRegValue&0xF0)>>4;
vpcola 0:a1734fe1ec4b 1333 bwE = tempRegValue&0x0F;
vpcola 0:a1734fe1ec4b 1334
vpcola 0:a1734fe1ec4b 1335 /* Reads the channel filter bandwidth from the look-up table and return it */
vpcola 0:a1734fe1ec4b 1336 return (uint32_t)(100.0*s_vectnBandwidth26M[bwM+(bwE*9)]*s_lXtalFrequency/26e6);
vpcola 0:a1734fe1ec4b 1337
vpcola 0:a1734fe1ec4b 1338 }
vpcola 0:a1734fe1ec4b 1339
vpcola 0:a1734fe1ec4b 1340
vpcola 0:a1734fe1ec4b 1341 /**
vpcola 0:a1734fe1ec4b 1342 * @brief Sets the modulation type.
vpcola 0:a1734fe1ec4b 1343 * @param xModulation modulation to set.
vpcola 0:a1734fe1ec4b 1344 * This parameter shall be of type @ref ModulationSelect .
vpcola 0:a1734fe1ec4b 1345 * @retval None.
vpcola 0:a1734fe1ec4b 1346 */
vpcola 0:a1734fe1ec4b 1347 void SpiritRadioSetModulation(ModulationSelect xModulation)
vpcola 0:a1734fe1ec4b 1348 {
vpcola 0:a1734fe1ec4b 1349 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1350
vpcola 0:a1734fe1ec4b 1351 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1352 s_assert_param(IS_MODULATION_SELECTED(xModulation));
vpcola 0:a1734fe1ec4b 1353
vpcola 0:a1734fe1ec4b 1354 /* Reads the modulation register */
vpcola 0:a1734fe1ec4b 1355 SpiritSpiReadRegisters(MOD0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1356
vpcola 0:a1734fe1ec4b 1357 /* Mask the other fields and set the modulation type */
vpcola 0:a1734fe1ec4b 1358 tempRegValue &=0x8F;
vpcola 0:a1734fe1ec4b 1359 tempRegValue |= xModulation;
vpcola 0:a1734fe1ec4b 1360
vpcola 0:a1734fe1ec4b 1361 /* Writes the modulation register */
vpcola 0:a1734fe1ec4b 1362 g_xStatus = SpiritSpiWriteRegisters(MOD0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1363
vpcola 0:a1734fe1ec4b 1364 }
vpcola 0:a1734fe1ec4b 1365
vpcola 0:a1734fe1ec4b 1366
vpcola 0:a1734fe1ec4b 1367 /**
vpcola 0:a1734fe1ec4b 1368 * @brief Returns the modulation type used.
vpcola 0:a1734fe1ec4b 1369 * @param None.
vpcola 0:a1734fe1ec4b 1370 * @retval ModulationSelect Settled modulation type.
vpcola 0:a1734fe1ec4b 1371 */
vpcola 0:a1734fe1ec4b 1372 ModulationSelect SpiritRadioGetModulation(void)
vpcola 0:a1734fe1ec4b 1373 {
vpcola 0:a1734fe1ec4b 1374 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1375
vpcola 0:a1734fe1ec4b 1376 /* Reads the modulation register MOD0*/
vpcola 0:a1734fe1ec4b 1377 g_xStatus = SpiritSpiReadRegisters(MOD0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1378
vpcola 0:a1734fe1ec4b 1379 /* Return the modulation type */
vpcola 0:a1734fe1ec4b 1380 return (ModulationSelect)(tempRegValue&0x70);
vpcola 0:a1734fe1ec4b 1381
vpcola 0:a1734fe1ec4b 1382 }
vpcola 0:a1734fe1ec4b 1383
vpcola 0:a1734fe1ec4b 1384
vpcola 0:a1734fe1ec4b 1385 /**
vpcola 0:a1734fe1ec4b 1386 * @brief Enables or Disables the Continuous Wave transmit mode.
vpcola 0:a1734fe1ec4b 1387 * @param xNewState new state for power ramping.
vpcola 0:a1734fe1ec4b 1388 * This parameter can be: S_ENABLE or S_DISABLE .
vpcola 0:a1734fe1ec4b 1389 * @retval None.
vpcola 0:a1734fe1ec4b 1390 */
vpcola 0:a1734fe1ec4b 1391 void SpiritRadioCWTransmitMode(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 1392 {
vpcola 0:a1734fe1ec4b 1393 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1394
vpcola 0:a1734fe1ec4b 1395 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1396 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 1397
vpcola 0:a1734fe1ec4b 1398 /* Reads the modulation register MOD0 and mask the CW field */
vpcola 0:a1734fe1ec4b 1399 SpiritSpiReadRegisters(MOD0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1400 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 1401 {
vpcola 0:a1734fe1ec4b 1402 tempRegValue |=MOD0_CW;
vpcola 0:a1734fe1ec4b 1403 }
vpcola 0:a1734fe1ec4b 1404 else
vpcola 0:a1734fe1ec4b 1405 {
vpcola 0:a1734fe1ec4b 1406 tempRegValue &= (~MOD0_CW);
vpcola 0:a1734fe1ec4b 1407 }
vpcola 0:a1734fe1ec4b 1408
vpcola 0:a1734fe1ec4b 1409 /* Writes the new value in the MOD0 register */
vpcola 0:a1734fe1ec4b 1410 g_xStatus = SpiritSpiWriteRegisters(MOD0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1411
vpcola 0:a1734fe1ec4b 1412 }
vpcola 0:a1734fe1ec4b 1413
vpcola 0:a1734fe1ec4b 1414
vpcola 0:a1734fe1ec4b 1415 /**
vpcola 0:a1734fe1ec4b 1416 * @brief Sets the OOK Peak Decay.
vpcola 0:a1734fe1ec4b 1417 * @param xOokDecay Peak decay control for OOK.
vpcola 0:a1734fe1ec4b 1418 * This parameter shall be of type @ref OokPeakDecay .
vpcola 0:a1734fe1ec4b 1419 * @retval None.
vpcola 0:a1734fe1ec4b 1420 */
vpcola 0:a1734fe1ec4b 1421 void SpiritRadioSetOokPeakDecay(OokPeakDecay xOokDecay)
vpcola 0:a1734fe1ec4b 1422 {
vpcola 0:a1734fe1ec4b 1423 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1424
vpcola 0:a1734fe1ec4b 1425 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1426 s_assert_param(IS_OOK_PEAK_DECAY(xOokDecay));
vpcola 0:a1734fe1ec4b 1427
vpcola 0:a1734fe1ec4b 1428 /* Reads the RSSI_FLT register */
vpcola 0:a1734fe1ec4b 1429 SpiritSpiReadRegisters(RSSI_FLT_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1430
vpcola 0:a1734fe1ec4b 1431 /* Mask the other fields and set OOK Peak Decay */
vpcola 0:a1734fe1ec4b 1432 tempRegValue &= 0xFC;
vpcola 0:a1734fe1ec4b 1433 tempRegValue |= xOokDecay;
vpcola 0:a1734fe1ec4b 1434
vpcola 0:a1734fe1ec4b 1435 /* Writes the RSSI_FLT register to set the new OOK peak dacay value */
vpcola 0:a1734fe1ec4b 1436 g_xStatus = SpiritSpiWriteRegisters(RSSI_FLT_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1437
vpcola 0:a1734fe1ec4b 1438 }
vpcola 0:a1734fe1ec4b 1439
vpcola 0:a1734fe1ec4b 1440
vpcola 0:a1734fe1ec4b 1441 /**
vpcola 0:a1734fe1ec4b 1442 * @brief Returns the OOK Peak Decay.
vpcola 0:a1734fe1ec4b 1443 * @param None
vpcola 0:a1734fe1ec4b 1444 * @retval OokPeakDecay Ook peak decay value.
vpcola 0:a1734fe1ec4b 1445 */
vpcola 0:a1734fe1ec4b 1446 OokPeakDecay SpiritRadioGetOokPeakDecay(void)
vpcola 0:a1734fe1ec4b 1447 {
vpcola 0:a1734fe1ec4b 1448 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1449
vpcola 0:a1734fe1ec4b 1450 /* Reads the OOK peak decay register RSSI_FLT_BASE*/
vpcola 0:a1734fe1ec4b 1451 g_xStatus = SpiritSpiReadRegisters(RSSI_FLT_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1452
vpcola 0:a1734fe1ec4b 1453 /* Returns the OOK peak decay */
vpcola 0:a1734fe1ec4b 1454 return (OokPeakDecay) (tempRegValue & 0x03);
vpcola 0:a1734fe1ec4b 1455
vpcola 0:a1734fe1ec4b 1456 }
vpcola 0:a1734fe1ec4b 1457
vpcola 0:a1734fe1ec4b 1458 /**
vpcola 0:a1734fe1ec4b 1459 * @brief Returns the PA register value that corresponds to the passed dBm power.
vpcola 0:a1734fe1ec4b 1460 * @param lFbase Frequency base expressed in Hz.
vpcola 0:a1734fe1ec4b 1461 * @param fPowerdBm Desired power in dBm.
vpcola 0:a1734fe1ec4b 1462 * @retval Register value as byte.
vpcola 0:a1734fe1ec4b 1463 * @note The power interpolation curves used by this function have been extracted
vpcola 0:a1734fe1ec4b 1464 * by measurements done on the divisional evaluation boards.
vpcola 0:a1734fe1ec4b 1465 */
vpcola 0:a1734fe1ec4b 1466 uint8_t SpiritRadioGetdBm2Reg(uint32_t lFBase, float fPowerdBm)
vpcola 0:a1734fe1ec4b 1467 {
vpcola 0:a1734fe1ec4b 1468 uint8_t i=0;
vpcola 0:a1734fe1ec4b 1469 uint8_t j=0;
vpcola 0:a1734fe1ec4b 1470 float fReg;
vpcola 0:a1734fe1ec4b 1471
vpcola 0:a1734fe1ec4b 1472 if(IS_FREQUENCY_BAND_HIGH(lFBase))
vpcola 0:a1734fe1ec4b 1473 {
vpcola 0:a1734fe1ec4b 1474 i=0;
vpcola 0:a1734fe1ec4b 1475 if(lFBase<900000000) i=1;// 868
vpcola 0:a1734fe1ec4b 1476 }
vpcola 0:a1734fe1ec4b 1477 else if(IS_FREQUENCY_BAND_MIDDLE(lFBase))
vpcola 0:a1734fe1ec4b 1478 {
vpcola 0:a1734fe1ec4b 1479 i=2;
vpcola 0:a1734fe1ec4b 1480 }
vpcola 0:a1734fe1ec4b 1481 else if(IS_FREQUENCY_BAND_LOW(lFBase))
vpcola 0:a1734fe1ec4b 1482 {
vpcola 0:a1734fe1ec4b 1483 i=3;
vpcola 0:a1734fe1ec4b 1484 }
vpcola 0:a1734fe1ec4b 1485 else if(IS_FREQUENCY_BAND_VERY_LOW(lFBase))
vpcola 0:a1734fe1ec4b 1486 {
vpcola 0:a1734fe1ec4b 1487 i=4;
vpcola 0:a1734fe1ec4b 1488 }
vpcola 0:a1734fe1ec4b 1489
vpcola 0:a1734fe1ec4b 1490 j=1;
vpcola 0:a1734fe1ec4b 1491 if(fPowerdBm>0 && 13.0/fPowerFactors[i][2]-fPowerFactors[i][3]/fPowerFactors[i][2]<fPowerdBm)
vpcola 0:a1734fe1ec4b 1492 j=0;
vpcola 0:a1734fe1ec4b 1493 else if(fPowerdBm<=0 && 40.0/fPowerFactors[i][2]-fPowerFactors[i][3]/fPowerFactors[i][2]>fPowerdBm)
vpcola 0:a1734fe1ec4b 1494 j=2;
vpcola 0:a1734fe1ec4b 1495
vpcola 0:a1734fe1ec4b 1496 fReg=fPowerFactors[i][2*j]*fPowerdBm+fPowerFactors[i][2*j+1];
vpcola 0:a1734fe1ec4b 1497
vpcola 0:a1734fe1ec4b 1498 if(fReg<1)
vpcola 0:a1734fe1ec4b 1499 fReg=1;
vpcola 0:a1734fe1ec4b 1500 else if(fReg>90)
vpcola 0:a1734fe1ec4b 1501 fReg=90;
vpcola 0:a1734fe1ec4b 1502
vpcola 0:a1734fe1ec4b 1503 return ((uint8_t)fReg);
vpcola 0:a1734fe1ec4b 1504 }
vpcola 0:a1734fe1ec4b 1505
vpcola 0:a1734fe1ec4b 1506
vpcola 0:a1734fe1ec4b 1507 /**
vpcola 0:a1734fe1ec4b 1508 * @brief Returns the dBm power that corresponds to the value of PA register.
vpcola 0:a1734fe1ec4b 1509 * @param lFbase Frequency base expressed in Hz.
vpcola 0:a1734fe1ec4b 1510 * @param cPowerReg Register value of the PA.
vpcola 0:a1734fe1ec4b 1511 * @retval Power in dBm as float.
vpcola 0:a1734fe1ec4b 1512 * @note The power interpolation curves used by this function have been extracted
vpcola 0:a1734fe1ec4b 1513 * by measurements done on the divisional evaluation boards.
vpcola 0:a1734fe1ec4b 1514 */
vpcola 0:a1734fe1ec4b 1515 float SpiritRadioGetReg2dBm(uint32_t lFBase, uint8_t cPowerReg)
vpcola 0:a1734fe1ec4b 1516 {
vpcola 0:a1734fe1ec4b 1517 uint8_t i=0;
vpcola 0:a1734fe1ec4b 1518 uint8_t j=0;
vpcola 0:a1734fe1ec4b 1519 float fPower;
vpcola 0:a1734fe1ec4b 1520
vpcola 0:a1734fe1ec4b 1521 if(cPowerReg==0 || cPowerReg>90)
vpcola 0:a1734fe1ec4b 1522 return (-130.0);
vpcola 0:a1734fe1ec4b 1523
vpcola 0:a1734fe1ec4b 1524 if(IS_FREQUENCY_BAND_HIGH(lFBase))
vpcola 0:a1734fe1ec4b 1525 {
vpcola 0:a1734fe1ec4b 1526 i=0;
vpcola 0:a1734fe1ec4b 1527 if(lFBase<900000000) i=1;// 868
vpcola 0:a1734fe1ec4b 1528 }
vpcola 0:a1734fe1ec4b 1529 else if(IS_FREQUENCY_BAND_MIDDLE(lFBase))
vpcola 0:a1734fe1ec4b 1530 {
vpcola 0:a1734fe1ec4b 1531 i=2;
vpcola 0:a1734fe1ec4b 1532 }
vpcola 0:a1734fe1ec4b 1533 else if(IS_FREQUENCY_BAND_LOW(lFBase))
vpcola 0:a1734fe1ec4b 1534 {
vpcola 0:a1734fe1ec4b 1535 i=3;
vpcola 0:a1734fe1ec4b 1536 }
vpcola 0:a1734fe1ec4b 1537 else if(IS_FREQUENCY_BAND_VERY_LOW(lFBase))
vpcola 0:a1734fe1ec4b 1538 {
vpcola 0:a1734fe1ec4b 1539 i=4;
vpcola 0:a1734fe1ec4b 1540 }
vpcola 0:a1734fe1ec4b 1541
vpcola 0:a1734fe1ec4b 1542 j=1;
vpcola 0:a1734fe1ec4b 1543 if(cPowerReg<13) j=0;
vpcola 0:a1734fe1ec4b 1544 else if(cPowerReg>40) j=2;
vpcola 0:a1734fe1ec4b 1545
vpcola 0:a1734fe1ec4b 1546 fPower=(((float)cPowerReg)/fPowerFactors[i][2*j]-fPowerFactors[i][2*j+1]/fPowerFactors[i][2*j]);
vpcola 0:a1734fe1ec4b 1547
vpcola 0:a1734fe1ec4b 1548 return fPower;
vpcola 0:a1734fe1ec4b 1549 }
vpcola 0:a1734fe1ec4b 1550
vpcola 0:a1734fe1ec4b 1551 /**
vpcola 0:a1734fe1ec4b 1552 * @brief Configures the Power Amplifier Table and registers with value expressed in dBm.
vpcola 0:a1734fe1ec4b 1553 * @param cPALevelMaxIndex number of levels to set. This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1554 * @param cWidth step width expressed in terms of bit period units Tb/8.
vpcola 0:a1734fe1ec4b 1555 * This parameter shall be in the range [1:4].
vpcola 0:a1734fe1ec4b 1556 * @param xCLoad one of the possible value of the enum type PALoadCapacitor.
vpcola 0:a1734fe1ec4b 1557 * @arg LOAD_0_PF No additional PA load capacitor
vpcola 0:a1734fe1ec4b 1558 * @arg LOAD_1_2_PF 1.2pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1559 * @arg LOAD_2_4_PF 2.4pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1560 * @arg LOAD_3_6_PF 3.6pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1561 * @param pfPAtabledBm pointer to an array of PA values in dbm between [-PA_LOWER_LIMIT: PA_UPPER_LIMIT] dbm.
vpcola 0:a1734fe1ec4b 1562 * The first element shall be the lower level (PA_LEVEL[0]) value and the last element
vpcola 0:a1734fe1ec4b 1563 * the higher level one (PA_LEVEL[paLevelMaxIndex]).
vpcola 0:a1734fe1ec4b 1564 * @retval None.
vpcola 0:a1734fe1ec4b 1565 */
vpcola 0:a1734fe1ec4b 1566 void SpiritRadioSetPATabledBm(uint8_t cPALevelMaxIndex, uint8_t cWidth, PALoadCapacitor xCLoad, float* pfPAtabledBm)
vpcola 0:a1734fe1ec4b 1567 {
vpcola 0:a1734fe1ec4b 1568 uint8_t palevel[9], address, paLevelValue;
vpcola 0:a1734fe1ec4b 1569 uint32_t lFBase=SpiritRadioGetFrequencyBase();
vpcola 0:a1734fe1ec4b 1570
vpcola 0:a1734fe1ec4b 1571 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1572 s_assert_param(IS_PA_MAX_INDEX(cPALevelMaxIndex));
vpcola 0:a1734fe1ec4b 1573 s_assert_param(IS_PA_STEP_WIDTH(cWidth));
vpcola 0:a1734fe1ec4b 1574 s_assert_param(IS_PA_LOAD_CAP(xCLoad));
vpcola 0:a1734fe1ec4b 1575
vpcola 0:a1734fe1ec4b 1576 /* Check the PA level in dBm is in the range and calculate the PA_LEVEL value
vpcola 0:a1734fe1ec4b 1577 to write in the corresponding register using the linearization formula */
vpcola 0:a1734fe1ec4b 1578 for(int i=0; i<=cPALevelMaxIndex; i++)
vpcola 0:a1734fe1ec4b 1579 {
vpcola 0:a1734fe1ec4b 1580 s_assert_param(IS_PAPOWER_DBM(*pfPAtabledBm));
vpcola 0:a1734fe1ec4b 1581 paLevelValue=SpiritRadioGetdBm2Reg(lFBase,(*pfPAtabledBm));
vpcola 0:a1734fe1ec4b 1582 palevel[cPALevelMaxIndex-i]=paLevelValue;
vpcola 0:a1734fe1ec4b 1583 pfPAtabledBm++;
vpcola 0:a1734fe1ec4b 1584 }
vpcola 0:a1734fe1ec4b 1585
vpcola 0:a1734fe1ec4b 1586 /* Sets the PA_POWER[0] register */
vpcola 0:a1734fe1ec4b 1587 palevel[cPALevelMaxIndex+1]=xCLoad|(cWidth-1)<<3|cPALevelMaxIndex;
vpcola 0:a1734fe1ec4b 1588
vpcola 0:a1734fe1ec4b 1589 /* Sets the base address */
vpcola 0:a1734fe1ec4b 1590 address=PA_POWER8_BASE+7-cPALevelMaxIndex;
vpcola 0:a1734fe1ec4b 1591
vpcola 0:a1734fe1ec4b 1592 /* Configures the PA_POWER registers */
vpcola 0:a1734fe1ec4b 1593 g_xStatus = SpiritSpiWriteRegisters(address, cPALevelMaxIndex+2, palevel);
vpcola 0:a1734fe1ec4b 1594
vpcola 0:a1734fe1ec4b 1595 }
vpcola 0:a1734fe1ec4b 1596
vpcola 0:a1734fe1ec4b 1597
vpcola 0:a1734fe1ec4b 1598 /**
vpcola 0:a1734fe1ec4b 1599 * @brief Returns the Power Amplifier Table and registers, returning values in dBm.
vpcola 0:a1734fe1ec4b 1600 * @param pcPALevelMaxIndex pointer to the number of levels settled.
vpcola 0:a1734fe1ec4b 1601 * This parameter will be in the range [0:7].
vpcola 0:a1734fe1ec4b 1602 * @param pfPAtabledBm pointer to an array of 8 elements containing the PA value in dbm.
vpcola 0:a1734fe1ec4b 1603 * The first element will be the PA_LEVEL_0 and the last element
vpcola 0:a1734fe1ec4b 1604 * will be PA_LEVEL_7. Any value higher than PA_UPPER_LIMIT implies no output
vpcola 0:a1734fe1ec4b 1605 * power (output stage is in high impedance).
vpcola 0:a1734fe1ec4b 1606 * @retval None.
vpcola 0:a1734fe1ec4b 1607 */
vpcola 0:a1734fe1ec4b 1608 void SpiritRadioGetPATabledBm(uint8_t* pcPALevelMaxIndex, float* pfPAtabledBm)
vpcola 0:a1734fe1ec4b 1609 {
vpcola 0:a1734fe1ec4b 1610 uint8_t palevelvect[9];
vpcola 0:a1734fe1ec4b 1611 uint32_t lFBase=SpiritRadioGetFrequencyBase();
vpcola 0:a1734fe1ec4b 1612
vpcola 0:a1734fe1ec4b 1613 /* Reads the PA_LEVEL_x registers and the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1614 g_xStatus = SpiritSpiReadRegisters(PA_POWER8_BASE, 9, palevelvect);
vpcola 0:a1734fe1ec4b 1615
vpcola 0:a1734fe1ec4b 1616 /* Fill the PAtable */
vpcola 0:a1734fe1ec4b 1617 for(int i=7; i>=0; i--)
vpcola 0:a1734fe1ec4b 1618 {
vpcola 0:a1734fe1ec4b 1619 (*pfPAtabledBm)=SpiritRadioGetReg2dBm(lFBase,palevelvect[i]);
vpcola 0:a1734fe1ec4b 1620 pfPAtabledBm++;
vpcola 0:a1734fe1ec4b 1621 }
vpcola 0:a1734fe1ec4b 1622
vpcola 0:a1734fe1ec4b 1623 /* Return the settled index */
vpcola 0:a1734fe1ec4b 1624 *pcPALevelMaxIndex = palevelvect[8]&0x07;
vpcola 0:a1734fe1ec4b 1625
vpcola 0:a1734fe1ec4b 1626 }
vpcola 0:a1734fe1ec4b 1627
vpcola 0:a1734fe1ec4b 1628
vpcola 0:a1734fe1ec4b 1629
vpcola 0:a1734fe1ec4b 1630
vpcola 0:a1734fe1ec4b 1631
vpcola 0:a1734fe1ec4b 1632
vpcola 0:a1734fe1ec4b 1633 /**
vpcola 0:a1734fe1ec4b 1634 * @brief Sets a specific PA_LEVEL register, with a value given in dBm.
vpcola 0:a1734fe1ec4b 1635 * @param cIndex PA_LEVEL to set. This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1636 * @param fPowerdBm PA value to write expressed in dBm . Be sure that this values is in the
vpcola 0:a1734fe1ec4b 1637 * correct range [-PA_LOWER_LIMIT: PA_UPPER_LIMIT] dBm.
vpcola 0:a1734fe1ec4b 1638 * @retval None.
vpcola 0:a1734fe1ec4b 1639 * @note This function makes use of the @ref SpiritRadioGetdBm2Reg fcn to interpolate the
vpcola 0:a1734fe1ec4b 1640 * power value.
vpcola 0:a1734fe1ec4b 1641 */
vpcola 0:a1734fe1ec4b 1642 void SpiritRadioSetPALeveldBm(uint8_t cIndex, float fPowerdBm)
vpcola 0:a1734fe1ec4b 1643 {
vpcola 0:a1734fe1ec4b 1644 uint8_t address, paLevelValue;
vpcola 0:a1734fe1ec4b 1645
vpcola 0:a1734fe1ec4b 1646 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1647 s_assert_param(IS_PA_MAX_INDEX(cIndex));
vpcola 0:a1734fe1ec4b 1648 s_assert_param(IS_PAPOWER_DBM(fPowerdBm));
vpcola 0:a1734fe1ec4b 1649
vpcola 0:a1734fe1ec4b 1650 /* interpolate the power level */
vpcola 0:a1734fe1ec4b 1651 paLevelValue=SpiritRadioGetdBm2Reg(SpiritRadioGetFrequencyBase(),fPowerdBm);
vpcola 0:a1734fe1ec4b 1652
vpcola 0:a1734fe1ec4b 1653 /* Sets the base address */
vpcola 0:a1734fe1ec4b 1654 address=PA_POWER8_BASE+7-cIndex;
vpcola 0:a1734fe1ec4b 1655
vpcola 0:a1734fe1ec4b 1656 /* Configures the PA_LEVEL register */
vpcola 0:a1734fe1ec4b 1657 g_xStatus = SpiritSpiWriteRegisters(address, 1, &paLevelValue);
vpcola 0:a1734fe1ec4b 1658
vpcola 0:a1734fe1ec4b 1659 }
vpcola 0:a1734fe1ec4b 1660
vpcola 0:a1734fe1ec4b 1661
vpcola 0:a1734fe1ec4b 1662 /**
vpcola 0:a1734fe1ec4b 1663 * @brief Returns a specific PA_LEVEL register, returning a value in dBm.
vpcola 0:a1734fe1ec4b 1664 * @param cIndex PA_LEVEL to read. This parameter shall be in the range [0:7]
vpcola 0:a1734fe1ec4b 1665 * @retval float Settled power level expressed in dBm. A value
vpcola 0:a1734fe1ec4b 1666 * higher than PA_UPPER_LIMIT dBm implies no output power
vpcola 0:a1734fe1ec4b 1667 * (output stage is in high impedance).
vpcola 0:a1734fe1ec4b 1668 * @note This function makes use of the @ref SpiritRadioGetReg2dBm fcn to interpolate the
vpcola 0:a1734fe1ec4b 1669 * power value.
vpcola 0:a1734fe1ec4b 1670 */
vpcola 0:a1734fe1ec4b 1671 float SpiritRadioGetPALeveldBm(uint8_t cIndex)
vpcola 0:a1734fe1ec4b 1672 {
vpcola 0:a1734fe1ec4b 1673 uint8_t address, paLevelValue;
vpcola 0:a1734fe1ec4b 1674
vpcola 0:a1734fe1ec4b 1675 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1676 s_assert_param(IS_PA_MAX_INDEX(cIndex));
vpcola 0:a1734fe1ec4b 1677
vpcola 0:a1734fe1ec4b 1678 /* Sets the base address */
vpcola 0:a1734fe1ec4b 1679 address=PA_POWER8_BASE+7-cIndex;
vpcola 0:a1734fe1ec4b 1680
vpcola 0:a1734fe1ec4b 1681 /* Reads the PA_LEVEL[cIndex] register */
vpcola 0:a1734fe1ec4b 1682 g_xStatus = SpiritSpiReadRegisters(address, 1, &paLevelValue);
vpcola 0:a1734fe1ec4b 1683
vpcola 0:a1734fe1ec4b 1684 return SpiritRadioGetReg2dBm(SpiritRadioGetFrequencyBase(),paLevelValue);
vpcola 0:a1734fe1ec4b 1685 }
vpcola 0:a1734fe1ec4b 1686
vpcola 0:a1734fe1ec4b 1687
vpcola 0:a1734fe1ec4b 1688 /**
vpcola 0:a1734fe1ec4b 1689 * @brief Configures the Power Amplifier Table and registers.
vpcola 0:a1734fe1ec4b 1690 * @param cPALevelMaxIndex number of levels to set. This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1691 * @param cWidth step width expressed in terms of bit period units Tb/8.
vpcola 0:a1734fe1ec4b 1692 * This parameter shall be in the range [1:4].
vpcola 0:a1734fe1ec4b 1693 * @param xCLoad one of the possible value of the enum type PALoadCapacitor.
vpcola 0:a1734fe1ec4b 1694 * @arg LOAD_0_PF No additional PA load capacitor
vpcola 0:a1734fe1ec4b 1695 * @arg LOAD_1_2_PF 1.2pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1696 * @arg LOAD_2_4_PF 2.4pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1697 * @arg LOAD_3_6_PF 3.6pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1698 * @param pcPAtable pointer to an array of PA values in the range [0: 90], where 0 implies no
vpcola 0:a1734fe1ec4b 1699 * output power, 1 will be the maximum level and 90 the minimum one
vpcola 0:a1734fe1ec4b 1700 * The first element shall be the lower level (PA_LEVEL[0]) value and the last element
vpcola 0:a1734fe1ec4b 1701 * the higher level one (PA_LEVEL[paLevelMaxIndex]).
vpcola 0:a1734fe1ec4b 1702 * @retval None.
vpcola 0:a1734fe1ec4b 1703 */
vpcola 0:a1734fe1ec4b 1704 void SpiritRadioSetPATable(uint8_t cPALevelMaxIndex, uint8_t cWidth, PALoadCapacitor xCLoad, uint8_t* pcPAtable)
vpcola 0:a1734fe1ec4b 1705 {
vpcola 0:a1734fe1ec4b 1706 uint8_t palevel[9], address;
vpcola 0:a1734fe1ec4b 1707
vpcola 0:a1734fe1ec4b 1708 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1709 s_assert_param(IS_PA_MAX_INDEX(cPALevelMaxIndex));
vpcola 0:a1734fe1ec4b 1710 s_assert_param(IS_PA_STEP_WIDTH(cWidth));
vpcola 0:a1734fe1ec4b 1711 s_assert_param(IS_PA_LOAD_CAP(xCLoad));
vpcola 0:a1734fe1ec4b 1712
vpcola 0:a1734fe1ec4b 1713 /* Check the PA levels are in the range */
vpcola 0:a1734fe1ec4b 1714 for(int i=0; i<=cPALevelMaxIndex; i++)
vpcola 0:a1734fe1ec4b 1715 {
vpcola 0:a1734fe1ec4b 1716 s_assert_param(IS_PAPOWER(*pcPAtable));
vpcola 0:a1734fe1ec4b 1717 palevel[cPALevelMaxIndex-i]=*pcPAtable;
vpcola 0:a1734fe1ec4b 1718 pcPAtable++;
vpcola 0:a1734fe1ec4b 1719 }
vpcola 0:a1734fe1ec4b 1720
vpcola 0:a1734fe1ec4b 1721 /* Sets the PA_POWER[0] register */
vpcola 0:a1734fe1ec4b 1722 palevel[cPALevelMaxIndex+1]=xCLoad|((cWidth-1)<<3)|cPALevelMaxIndex;
vpcola 0:a1734fe1ec4b 1723
vpcola 0:a1734fe1ec4b 1724 /* Sets the base address */
vpcola 0:a1734fe1ec4b 1725 address=PA_POWER8_BASE+7-cPALevelMaxIndex;
vpcola 0:a1734fe1ec4b 1726
vpcola 0:a1734fe1ec4b 1727 /* Configures the PA_POWER registers */
vpcola 0:a1734fe1ec4b 1728 g_xStatus = SpiritSpiWriteRegisters(address, cPALevelMaxIndex+2, palevel);
vpcola 0:a1734fe1ec4b 1729
vpcola 0:a1734fe1ec4b 1730 }
vpcola 0:a1734fe1ec4b 1731
vpcola 0:a1734fe1ec4b 1732
vpcola 0:a1734fe1ec4b 1733 /**
vpcola 0:a1734fe1ec4b 1734 * @brief Returns the Power Amplifier Table and registers.
vpcola 0:a1734fe1ec4b 1735 * @param pcPALevelMaxIndex pointer to the number of levels settled.
vpcola 0:a1734fe1ec4b 1736 * This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1737 * @param pcPAtable pointer to an array of 8 elements containing the PA value.
vpcola 0:a1734fe1ec4b 1738 * The first element will be the PA_LEVEL_0 and the last element
vpcola 0:a1734fe1ec4b 1739 * will be PA_LEVEL_7. Any value equals to 0 implies that level has
vpcola 0:a1734fe1ec4b 1740 * no output power (output stage is in high impedance).
vpcola 0:a1734fe1ec4b 1741 * @retval None
vpcola 0:a1734fe1ec4b 1742 */
vpcola 0:a1734fe1ec4b 1743 void SpiritRadioGetPATable(uint8_t* pcPALevelMaxIndex, uint8_t* pcPAtable)
vpcola 0:a1734fe1ec4b 1744 {
vpcola 0:a1734fe1ec4b 1745 uint8_t palevelvect[9];
vpcola 0:a1734fe1ec4b 1746
vpcola 0:a1734fe1ec4b 1747 /* Reads the PA_LEVEL_x registers and the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1748 g_xStatus = SpiritSpiReadRegisters(PA_POWER8_BASE, 9, palevelvect);
vpcola 0:a1734fe1ec4b 1749
vpcola 0:a1734fe1ec4b 1750 /* Fill the PAtable */
vpcola 0:a1734fe1ec4b 1751 for(int i=7; i>=0; i--)
vpcola 0:a1734fe1ec4b 1752 {
vpcola 0:a1734fe1ec4b 1753 *pcPAtable = palevelvect[i];
vpcola 0:a1734fe1ec4b 1754 pcPAtable++;
vpcola 0:a1734fe1ec4b 1755 }
vpcola 0:a1734fe1ec4b 1756
vpcola 0:a1734fe1ec4b 1757 /* Return the settled index */
vpcola 0:a1734fe1ec4b 1758 *pcPALevelMaxIndex = palevelvect[8]&0x07;
vpcola 0:a1734fe1ec4b 1759
vpcola 0:a1734fe1ec4b 1760 }
vpcola 0:a1734fe1ec4b 1761
vpcola 0:a1734fe1ec4b 1762
vpcola 0:a1734fe1ec4b 1763 /**
vpcola 0:a1734fe1ec4b 1764 * @brief Sets a specific PA_LEVEL register.
vpcola 0:a1734fe1ec4b 1765 * @param cIndex PA_LEVEL to set. This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1766 * @param cPower PA value to write in the register. Be sure that this values is in the
vpcola 0:a1734fe1ec4b 1767 * correct range [0 : 90].
vpcola 0:a1734fe1ec4b 1768 * @retval None.
vpcola 0:a1734fe1ec4b 1769 */
vpcola 0:a1734fe1ec4b 1770 void SpiritRadioSetPALevel(uint8_t cIndex, uint8_t cPower)
vpcola 0:a1734fe1ec4b 1771 {
vpcola 0:a1734fe1ec4b 1772 uint8_t address;
vpcola 0:a1734fe1ec4b 1773
vpcola 0:a1734fe1ec4b 1774 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1775 s_assert_param(IS_PA_MAX_INDEX(cIndex));
vpcola 0:a1734fe1ec4b 1776 s_assert_param(IS_PAPOWER(cPower));
vpcola 0:a1734fe1ec4b 1777
vpcola 0:a1734fe1ec4b 1778 /* Sets the base address */
vpcola 0:a1734fe1ec4b 1779 address=PA_POWER8_BASE+7-cIndex;
vpcola 0:a1734fe1ec4b 1780
vpcola 0:a1734fe1ec4b 1781 /* Configures the PA_LEVEL register */
vpcola 0:a1734fe1ec4b 1782 g_xStatus = SpiritSpiWriteRegisters(address, 1, &cPower);
vpcola 0:a1734fe1ec4b 1783
vpcola 0:a1734fe1ec4b 1784 }
vpcola 0:a1734fe1ec4b 1785
vpcola 0:a1734fe1ec4b 1786
vpcola 0:a1734fe1ec4b 1787 /**
vpcola 0:a1734fe1ec4b 1788 * @brief Returns a specific PA_LEVEL register.
vpcola 0:a1734fe1ec4b 1789 * @param cIndex PA_LEVEL to read. This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1790 * @retval uint8_t PA_LEVEL value. A value equal to zero
vpcola 0:a1734fe1ec4b 1791 * implies no output power (output stage is in high impedance).
vpcola 0:a1734fe1ec4b 1792 */
vpcola 0:a1734fe1ec4b 1793 uint8_t SpiritRadioGetPALevel(uint8_t cIndex)
vpcola 0:a1734fe1ec4b 1794 {
vpcola 0:a1734fe1ec4b 1795 uint8_t address, tempRegValue;
vpcola 0:a1734fe1ec4b 1796
vpcola 0:a1734fe1ec4b 1797 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1798 s_assert_param(IS_PA_MAX_INDEX(cIndex));
vpcola 0:a1734fe1ec4b 1799
vpcola 0:a1734fe1ec4b 1800 /* Sets the base address */
vpcola 0:a1734fe1ec4b 1801 address=PA_POWER8_BASE+7-cIndex;
vpcola 0:a1734fe1ec4b 1802
vpcola 0:a1734fe1ec4b 1803 /* Reads the PA_LEVEL[cIndex] register and return the value */
vpcola 0:a1734fe1ec4b 1804 g_xStatus = SpiritSpiReadRegisters(address, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1805 return tempRegValue;
vpcola 0:a1734fe1ec4b 1806
vpcola 0:a1734fe1ec4b 1807 }
vpcola 0:a1734fe1ec4b 1808
vpcola 0:a1734fe1ec4b 1809
vpcola 0:a1734fe1ec4b 1810 /**
vpcola 0:a1734fe1ec4b 1811 * @brief Sets the output stage additional load capacitor bank.
vpcola 0:a1734fe1ec4b 1812 * @param xCLoad one of the possible value of the enum type PALoadCapacitor.
vpcola 0:a1734fe1ec4b 1813 * @arg LOAD_0_PF No additional PA load capacitor
vpcola 0:a1734fe1ec4b 1814 * @arg LOAD_1_2_PF 1.2pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1815 * @arg LOAD_2_4_PF 2.4pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1816 * @arg LOAD_3_6_PF 3.6pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1817 * @retval None.
vpcola 0:a1734fe1ec4b 1818 */
vpcola 0:a1734fe1ec4b 1819 void SpiritRadioSetPACwc(PALoadCapacitor xCLoad)
vpcola 0:a1734fe1ec4b 1820 {
vpcola 0:a1734fe1ec4b 1821 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1822
vpcola 0:a1734fe1ec4b 1823 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1824 s_assert_param(IS_PA_LOAD_CAP(xCLoad));
vpcola 0:a1734fe1ec4b 1825
vpcola 0:a1734fe1ec4b 1826 /* Reads the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1827 SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1828
vpcola 0:a1734fe1ec4b 1829 /* Mask the CWC[1:0] field and write the new value */
vpcola 0:a1734fe1ec4b 1830 tempRegValue &= 0x3F;
vpcola 0:a1734fe1ec4b 1831 tempRegValue |= xCLoad;
vpcola 0:a1734fe1ec4b 1832
vpcola 0:a1734fe1ec4b 1833 /* Configures the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1834 g_xStatus = SpiritSpiWriteRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1835
vpcola 0:a1734fe1ec4b 1836 }
vpcola 0:a1734fe1ec4b 1837
vpcola 0:a1734fe1ec4b 1838
vpcola 0:a1734fe1ec4b 1839 /**
vpcola 0:a1734fe1ec4b 1840 * @brief Returns the output stage additional load capacitor bank.
vpcola 0:a1734fe1ec4b 1841 * @param None.
vpcola 0:a1734fe1ec4b 1842 * @retval PALoadCapacitor Output stage additional load capacitor bank.
vpcola 0:a1734fe1ec4b 1843 * This parameter can be:
vpcola 0:a1734fe1ec4b 1844 * @arg LOAD_0_PF No additional PA load capacitor
vpcola 0:a1734fe1ec4b 1845 * @arg LOAD_1_2_PF 1.2pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1846 * @arg LOAD_2_4_PF 2.4pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1847 * @arg LOAD_3_6_PF 3.6pF additional PA load capacitor
vpcola 0:a1734fe1ec4b 1848 */
vpcola 0:a1734fe1ec4b 1849 PALoadCapacitor SpiritRadioGetPACwc(void)
vpcola 0:a1734fe1ec4b 1850 {
vpcola 0:a1734fe1ec4b 1851 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1852
vpcola 0:a1734fe1ec4b 1853 /* Reads the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1854 g_xStatus = SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1855
vpcola 0:a1734fe1ec4b 1856 /* Mask the CWC[1:0] field and return the value*/
vpcola 0:a1734fe1ec4b 1857 return (PALoadCapacitor)(tempRegValue & 0xC0);
vpcola 0:a1734fe1ec4b 1858
vpcola 0:a1734fe1ec4b 1859 }
vpcola 0:a1734fe1ec4b 1860
vpcola 0:a1734fe1ec4b 1861
vpcola 0:a1734fe1ec4b 1862 /**
vpcola 0:a1734fe1ec4b 1863 * @brief Sets a specific PA_LEVEL_MAX_INDEX.
vpcola 0:a1734fe1ec4b 1864 * @param cIndex PA_LEVEL_MAX_INDEX to set. This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 1865 * @retval None
vpcola 0:a1734fe1ec4b 1866 */
vpcola 0:a1734fe1ec4b 1867 void SpiritRadioSetPALevelMaxIndex(uint8_t cIndex)
vpcola 0:a1734fe1ec4b 1868 {
vpcola 0:a1734fe1ec4b 1869 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1870
vpcola 0:a1734fe1ec4b 1871 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1872 s_assert_param(IS_PA_MAX_INDEX(cIndex));
vpcola 0:a1734fe1ec4b 1873
vpcola 0:a1734fe1ec4b 1874 /* Reads the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1875 SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1876
vpcola 0:a1734fe1ec4b 1877 /* Mask the PA_LEVEL_MAX_INDEX[1:0] field and write the new value */
vpcola 0:a1734fe1ec4b 1878 tempRegValue &= 0xF8;
vpcola 0:a1734fe1ec4b 1879 tempRegValue |= cIndex;
vpcola 0:a1734fe1ec4b 1880
vpcola 0:a1734fe1ec4b 1881 /* Configures the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1882 g_xStatus = SpiritSpiWriteRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1883
vpcola 0:a1734fe1ec4b 1884 }
vpcola 0:a1734fe1ec4b 1885
vpcola 0:a1734fe1ec4b 1886
vpcola 0:a1734fe1ec4b 1887 /**
vpcola 0:a1734fe1ec4b 1888 * @brief Returns the actual PA_LEVEL_MAX_INDEX.
vpcola 0:a1734fe1ec4b 1889 * @param None.
vpcola 0:a1734fe1ec4b 1890 * @retval uint8_t Actual PA_LEVEL_MAX_INDEX. This parameter will be in the range [0:7].
vpcola 0:a1734fe1ec4b 1891 */
vpcola 0:a1734fe1ec4b 1892 uint8_t SpiritRadioGetPALevelMaxIndex(void)
vpcola 0:a1734fe1ec4b 1893 {
vpcola 0:a1734fe1ec4b 1894 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1895
vpcola 0:a1734fe1ec4b 1896 /* Reads the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1897 g_xStatus = SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1898
vpcola 0:a1734fe1ec4b 1899 /* Mask the PA_LEVEL_MAX_INDEX[1:0] field and return the value */
vpcola 0:a1734fe1ec4b 1900 return (tempRegValue & 0x07);
vpcola 0:a1734fe1ec4b 1901
vpcola 0:a1734fe1ec4b 1902 }
vpcola 0:a1734fe1ec4b 1903
vpcola 0:a1734fe1ec4b 1904
vpcola 0:a1734fe1ec4b 1905 /**
vpcola 0:a1734fe1ec4b 1906 * @brief Sets a specific PA_RAMP_STEP_WIDTH.
vpcola 0:a1734fe1ec4b 1907 * @param cWidth step width expressed in terms of bit period units Tb/8.
vpcola 0:a1734fe1ec4b 1908 * This parameter shall be in the range [1:4].
vpcola 0:a1734fe1ec4b 1909 * @retval None.
vpcola 0:a1734fe1ec4b 1910 */
vpcola 0:a1734fe1ec4b 1911 void SpiritRadioSetPAStepWidth(uint8_t cWidth)
vpcola 0:a1734fe1ec4b 1912 {
vpcola 0:a1734fe1ec4b 1913 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1914
vpcola 0:a1734fe1ec4b 1915 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1916 s_assert_param(IS_PA_STEP_WIDTH(cWidth));
vpcola 0:a1734fe1ec4b 1917
vpcola 0:a1734fe1ec4b 1918 /* Reads the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1919 SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1920
vpcola 0:a1734fe1ec4b 1921 /* Mask the PA_RAMP_STEP_WIDTH[1:0] field and write the new value */
vpcola 0:a1734fe1ec4b 1922 tempRegValue &= 0xE7;
vpcola 0:a1734fe1ec4b 1923 tempRegValue |= (cWidth-1)<<3;
vpcola 0:a1734fe1ec4b 1924
vpcola 0:a1734fe1ec4b 1925 /* Configures the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1926 g_xStatus = SpiritSpiWriteRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1927
vpcola 0:a1734fe1ec4b 1928 }
vpcola 0:a1734fe1ec4b 1929
vpcola 0:a1734fe1ec4b 1930
vpcola 0:a1734fe1ec4b 1931 /**
vpcola 0:a1734fe1ec4b 1932 * @brief Returns the actual PA_RAMP_STEP_WIDTH.
vpcola 0:a1734fe1ec4b 1933 * @param None.
vpcola 0:a1734fe1ec4b 1934 * @retval uint8_t Step width value expressed in terms of bit period units Tb/8.
vpcola 0:a1734fe1ec4b 1935 * This parameter will be in the range [1:4].
vpcola 0:a1734fe1ec4b 1936 */
vpcola 0:a1734fe1ec4b 1937 uint8_t SpiritRadioGetPAStepWidth(void)
vpcola 0:a1734fe1ec4b 1938 {
vpcola 0:a1734fe1ec4b 1939 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1940
vpcola 0:a1734fe1ec4b 1941 /* Reads the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1942 g_xStatus = SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1943
vpcola 0:a1734fe1ec4b 1944 /* Mask the PA_RAMP_STEP_WIDTH[1:0] field and return the value */
vpcola 0:a1734fe1ec4b 1945 tempRegValue &= 0x18;
vpcola 0:a1734fe1ec4b 1946 return ((tempRegValue>>3)+1);
vpcola 0:a1734fe1ec4b 1947
vpcola 0:a1734fe1ec4b 1948 }
vpcola 0:a1734fe1ec4b 1949
vpcola 0:a1734fe1ec4b 1950
vpcola 0:a1734fe1ec4b 1951 /**
vpcola 0:a1734fe1ec4b 1952 * @brief Enables or Disables the Power Ramping.
vpcola 0:a1734fe1ec4b 1953 * @param xNewState new state for power ramping.
vpcola 0:a1734fe1ec4b 1954 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 1955 * @retval None.
vpcola 0:a1734fe1ec4b 1956 */
vpcola 0:a1734fe1ec4b 1957 void SpiritRadioPARamping(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 1958 {
vpcola 0:a1734fe1ec4b 1959 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 1960
vpcola 0:a1734fe1ec4b 1961 /* Check the parameters */
vpcola 0:a1734fe1ec4b 1962 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 1963
vpcola 0:a1734fe1ec4b 1964 /* Reads the PA_POWER_0 register and configure the PA_RAMP_ENABLE field */
vpcola 0:a1734fe1ec4b 1965 SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1966 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 1967 {
vpcola 0:a1734fe1ec4b 1968 tempRegValue |= PA_POWER0_PA_RAMP_MASK;
vpcola 0:a1734fe1ec4b 1969 }
vpcola 0:a1734fe1ec4b 1970 else
vpcola 0:a1734fe1ec4b 1971 {
vpcola 0:a1734fe1ec4b 1972 tempRegValue &= (~PA_POWER0_PA_RAMP_MASK);
vpcola 0:a1734fe1ec4b 1973 }
vpcola 0:a1734fe1ec4b 1974
vpcola 0:a1734fe1ec4b 1975 /* Sets the PA_POWER_0 register */
vpcola 0:a1734fe1ec4b 1976 g_xStatus = SpiritSpiWriteRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1977
vpcola 0:a1734fe1ec4b 1978 }
vpcola 0:a1734fe1ec4b 1979
vpcola 0:a1734fe1ec4b 1980 /**
vpcola 0:a1734fe1ec4b 1981 * @brief Returns the Power Ramping enable bit.
vpcola 0:a1734fe1ec4b 1982 * @param xNewState new state for power ramping.
vpcola 0:a1734fe1ec4b 1983 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 1984 * @retval None.
vpcola 0:a1734fe1ec4b 1985 */
vpcola 0:a1734fe1ec4b 1986 SpiritFunctionalState SpiritRadioGetPARamping(void)
vpcola 0:a1734fe1ec4b 1987 {
vpcola 0:a1734fe1ec4b 1988 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 1989
vpcola 0:a1734fe1ec4b 1990 /* Reads the PA_POWER_0 register and configure the PA_RAMP_ENABLE field */
vpcola 0:a1734fe1ec4b 1991 g_xStatus = SpiritSpiReadRegisters(PA_POWER0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 1992
vpcola 0:a1734fe1ec4b 1993 /* Mask and return data */
vpcola 0:a1734fe1ec4b 1994 return (SpiritFunctionalState)((tempRegValue>>5) & 0x01);
vpcola 0:a1734fe1ec4b 1995
vpcola 0:a1734fe1ec4b 1996 }
vpcola 0:a1734fe1ec4b 1997
vpcola 0:a1734fe1ec4b 1998
vpcola 0:a1734fe1ec4b 1999 /**
vpcola 0:a1734fe1ec4b 2000 * @brief Enables or Disables the AFC.
vpcola 0:a1734fe1ec4b 2001 * @param xNewState new state for AFC.
vpcola 0:a1734fe1ec4b 2002 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 2003 * @retval None.
vpcola 0:a1734fe1ec4b 2004 */
vpcola 0:a1734fe1ec4b 2005 void SpiritRadioAFC(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2006 {
vpcola 0:a1734fe1ec4b 2007 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2008
vpcola 0:a1734fe1ec4b 2009 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2010 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2011
vpcola 0:a1734fe1ec4b 2012 /* Reads the AFC_2 register and configure the AFC Enabled field */
vpcola 0:a1734fe1ec4b 2013 SpiritSpiReadRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2014 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2015 {
vpcola 0:a1734fe1ec4b 2016 tempRegValue |= AFC2_AFC_MASK;
vpcola 0:a1734fe1ec4b 2017 }
vpcola 0:a1734fe1ec4b 2018 else
vpcola 0:a1734fe1ec4b 2019 {
vpcola 0:a1734fe1ec4b 2020 tempRegValue &= (~AFC2_AFC_MASK);
vpcola 0:a1734fe1ec4b 2021 }
vpcola 0:a1734fe1ec4b 2022
vpcola 0:a1734fe1ec4b 2023 /* Sets the AFC_2 register */
vpcola 0:a1734fe1ec4b 2024 g_xStatus = SpiritSpiWriteRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2025
vpcola 0:a1734fe1ec4b 2026 }
vpcola 0:a1734fe1ec4b 2027
vpcola 0:a1734fe1ec4b 2028
vpcola 0:a1734fe1ec4b 2029 /**
vpcola 0:a1734fe1ec4b 2030 * @brief Enables or Disables the AFC freeze on sync word detection.
vpcola 0:a1734fe1ec4b 2031 * @param xNewState new state for AFC freeze on sync word detection.
vpcola 0:a1734fe1ec4b 2032 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 2033 * @retval None.
vpcola 0:a1734fe1ec4b 2034 */
vpcola 0:a1734fe1ec4b 2035 void SpiritRadioAFCFreezeOnSync(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2036 {
vpcola 0:a1734fe1ec4b 2037 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2038
vpcola 0:a1734fe1ec4b 2039 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2040 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2041
vpcola 0:a1734fe1ec4b 2042 /* Reads the AFC_2 register and configure the AFC Freeze on Sync field */
vpcola 0:a1734fe1ec4b 2043 SpiritSpiReadRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2044 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2045 {
vpcola 0:a1734fe1ec4b 2046 tempRegValue |= AFC2_AFC_FREEZE_ON_SYNC_MASK;
vpcola 0:a1734fe1ec4b 2047 }
vpcola 0:a1734fe1ec4b 2048 else
vpcola 0:a1734fe1ec4b 2049 {
vpcola 0:a1734fe1ec4b 2050 tempRegValue &= (~AFC2_AFC_FREEZE_ON_SYNC_MASK);
vpcola 0:a1734fe1ec4b 2051 }
vpcola 0:a1734fe1ec4b 2052
vpcola 0:a1734fe1ec4b 2053 /* Sets the AFC_2 register */
vpcola 0:a1734fe1ec4b 2054 g_xStatus = SpiritSpiWriteRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2055
vpcola 0:a1734fe1ec4b 2056 }
vpcola 0:a1734fe1ec4b 2057
vpcola 0:a1734fe1ec4b 2058
vpcola 0:a1734fe1ec4b 2059 /**
vpcola 0:a1734fe1ec4b 2060 * @brief Sets the AFC working mode.
vpcola 0:a1734fe1ec4b 2061 * @param xMode the AFC mode. This parameter can be one of the values defined in @ref AFCMode :
vpcola 0:a1734fe1ec4b 2062 * @arg AFC_SLICER_CORRECTION AFC loop closed on slicer
vpcola 0:a1734fe1ec4b 2063 * @arg AFC_2ND_IF_CORRECTION AFC loop closed on 2nd conversion stage
vpcola 0:a1734fe1ec4b 2064 * @retval None.
vpcola 0:a1734fe1ec4b 2065 */
vpcola 0:a1734fe1ec4b 2066 void SpiritRadioSetAFCMode(AFCMode xMode)
vpcola 0:a1734fe1ec4b 2067 {
vpcola 0:a1734fe1ec4b 2068 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2069
vpcola 0:a1734fe1ec4b 2070 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2071 s_assert_param(IS_AFC_MODE(xMode));
vpcola 0:a1734fe1ec4b 2072
vpcola 0:a1734fe1ec4b 2073 /* Reads the AFC_2 register and configure the AFC Mode field */
vpcola 0:a1734fe1ec4b 2074 SpiritSpiReadRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2075 if(xMode == AFC_2ND_IF_CORRECTION)
vpcola 0:a1734fe1ec4b 2076 {
vpcola 0:a1734fe1ec4b 2077 tempRegValue |= AFC_2ND_IF_CORRECTION;
vpcola 0:a1734fe1ec4b 2078 }
vpcola 0:a1734fe1ec4b 2079 else
vpcola 0:a1734fe1ec4b 2080 {
vpcola 0:a1734fe1ec4b 2081 tempRegValue &= (~AFC_2ND_IF_CORRECTION);
vpcola 0:a1734fe1ec4b 2082 }
vpcola 0:a1734fe1ec4b 2083
vpcola 0:a1734fe1ec4b 2084 /* Sets the AFC_2 register */
vpcola 0:a1734fe1ec4b 2085 g_xStatus = SpiritSpiWriteRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2086
vpcola 0:a1734fe1ec4b 2087 }
vpcola 0:a1734fe1ec4b 2088
vpcola 0:a1734fe1ec4b 2089
vpcola 0:a1734fe1ec4b 2090 /**
vpcola 0:a1734fe1ec4b 2091 * @brief Returns the AFC working mode.
vpcola 0:a1734fe1ec4b 2092 * @param None.
vpcola 0:a1734fe1ec4b 2093 * @retval AFCMode Settled AFC mode. This parameter will be one of the values defined in @ref AFCMode :
vpcola 0:a1734fe1ec4b 2094 * @arg AFC_SLICER_CORRECTION AFC loop closed on slicer
vpcola 0:a1734fe1ec4b 2095 * @arg AFC_2ND_IF_CORRECTION AFC loop closed on 2nd conversion stage
vpcola 0:a1734fe1ec4b 2096 */
vpcola 0:a1734fe1ec4b 2097 AFCMode SpiritRadioGetAFCMode(void)
vpcola 0:a1734fe1ec4b 2098 {
vpcola 0:a1734fe1ec4b 2099 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2100
vpcola 0:a1734fe1ec4b 2101 /* Reads the AFC_2 register */
vpcola 0:a1734fe1ec4b 2102 g_xStatus = SpiritSpiReadRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2103
vpcola 0:a1734fe1ec4b 2104 /* Mask the AFC Mode field and returns the value */
vpcola 0:a1734fe1ec4b 2105 return (AFCMode)(tempRegValue & 0x20);
vpcola 0:a1734fe1ec4b 2106
vpcola 0:a1734fe1ec4b 2107 }
vpcola 0:a1734fe1ec4b 2108
vpcola 0:a1734fe1ec4b 2109
vpcola 0:a1734fe1ec4b 2110 /**
vpcola 0:a1734fe1ec4b 2111 * @brief Sets the AFC peak detector leakage.
vpcola 0:a1734fe1ec4b 2112 * @param cLeakage the peak detector leakage. This parameter shall be in the range:
vpcola 0:a1734fe1ec4b 2113 * [0:31].
vpcola 0:a1734fe1ec4b 2114 * @retval None.
vpcola 0:a1734fe1ec4b 2115 */
vpcola 0:a1734fe1ec4b 2116 void SpiritRadioSetAFCPDLeakage(uint8_t cLeakage)
vpcola 0:a1734fe1ec4b 2117 {
vpcola 0:a1734fe1ec4b 2118 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2119
vpcola 0:a1734fe1ec4b 2120 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2121 s_assert_param(IS_AFC_PD_LEAKAGE(cLeakage));
vpcola 0:a1734fe1ec4b 2122
vpcola 0:a1734fe1ec4b 2123 /* Reads the AFC_2 register and configure the AFC PD leakage field */
vpcola 0:a1734fe1ec4b 2124 SpiritSpiReadRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2125 tempRegValue &= 0xE0;
vpcola 0:a1734fe1ec4b 2126 tempRegValue |= cLeakage;
vpcola 0:a1734fe1ec4b 2127
vpcola 0:a1734fe1ec4b 2128 /* Sets the AFC_2 register */
vpcola 0:a1734fe1ec4b 2129 g_xStatus = SpiritSpiWriteRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2130
vpcola 0:a1734fe1ec4b 2131 }
vpcola 0:a1734fe1ec4b 2132
vpcola 0:a1734fe1ec4b 2133
vpcola 0:a1734fe1ec4b 2134 /**
vpcola 0:a1734fe1ec4b 2135 * @brief Returns the AFC peak detector leakage.
vpcola 0:a1734fe1ec4b 2136 * @param None.
vpcola 0:a1734fe1ec4b 2137 * @retval uint8_t Peak detector leakage value. This parameter will be in the range:
vpcola 0:a1734fe1ec4b 2138 * [0:31].
vpcola 0:a1734fe1ec4b 2139 */
vpcola 0:a1734fe1ec4b 2140 uint8_t SpiritRadioGetAFCPDLeakage(void)
vpcola 0:a1734fe1ec4b 2141 {
vpcola 0:a1734fe1ec4b 2142 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2143
vpcola 0:a1734fe1ec4b 2144 /* Reads the AFC_2 register */
vpcola 0:a1734fe1ec4b 2145 g_xStatus = SpiritSpiReadRegisters(AFC2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2146
vpcola 0:a1734fe1ec4b 2147 /* Mask the AFC PD leakage field and return the value */
vpcola 0:a1734fe1ec4b 2148 return (tempRegValue & 0x1F);
vpcola 0:a1734fe1ec4b 2149
vpcola 0:a1734fe1ec4b 2150 }
vpcola 0:a1734fe1ec4b 2151
vpcola 0:a1734fe1ec4b 2152
vpcola 0:a1734fe1ec4b 2153 /**
vpcola 0:a1734fe1ec4b 2154 * @brief Sets the length of the AFC fast period expressed as number of samples.
vpcola 0:a1734fe1ec4b 2155 * @param cLength length of the fast period in number of samples.
vpcola 0:a1734fe1ec4b 2156 * @retval None.
vpcola 0:a1734fe1ec4b 2157 */
vpcola 0:a1734fe1ec4b 2158 void SpiritRadioSetAFCFastPeriod(uint8_t cLength)
vpcola 0:a1734fe1ec4b 2159 {
vpcola 0:a1734fe1ec4b 2160 /* Sets the AFC_1 register */
vpcola 0:a1734fe1ec4b 2161 g_xStatus = SpiritSpiWriteRegisters(AFC1_BASE, 1, &cLength);
vpcola 0:a1734fe1ec4b 2162
vpcola 0:a1734fe1ec4b 2163 }
vpcola 0:a1734fe1ec4b 2164
vpcola 0:a1734fe1ec4b 2165
vpcola 0:a1734fe1ec4b 2166 /**
vpcola 0:a1734fe1ec4b 2167 * @brief Returns the AFC fast period expressed as number of samples.
vpcola 0:a1734fe1ec4b 2168 * @param None.
vpcola 0:a1734fe1ec4b 2169 * @retval uint8_t Length of the fast period in number of samples.
vpcola 0:a1734fe1ec4b 2170 */
vpcola 0:a1734fe1ec4b 2171 uint8_t SpiritRadioGetAFCFastPeriod(void)
vpcola 0:a1734fe1ec4b 2172 {
vpcola 0:a1734fe1ec4b 2173 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2174
vpcola 0:a1734fe1ec4b 2175 /* Reads the AFC 1 register and return the value */
vpcola 0:a1734fe1ec4b 2176 g_xStatus = SpiritSpiReadRegisters(AFC1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2177
vpcola 0:a1734fe1ec4b 2178 return tempRegValue;
vpcola 0:a1734fe1ec4b 2179
vpcola 0:a1734fe1ec4b 2180 }
vpcola 0:a1734fe1ec4b 2181
vpcola 0:a1734fe1ec4b 2182
vpcola 0:a1734fe1ec4b 2183 /**
vpcola 0:a1734fe1ec4b 2184 * @brief Sets the AFC loop gain in fast mode.
vpcola 0:a1734fe1ec4b 2185 * @param cGain AFC loop gain in fast mode. This parameter shall be in the range:
vpcola 0:a1734fe1ec4b 2186 * [0:15].
vpcola 0:a1734fe1ec4b 2187 * @retval None.
vpcola 0:a1734fe1ec4b 2188 */
vpcola 0:a1734fe1ec4b 2189 void SpiritRadioSetAFCFastGain(uint8_t cGain)
vpcola 0:a1734fe1ec4b 2190 {
vpcola 0:a1734fe1ec4b 2191 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2192
vpcola 0:a1734fe1ec4b 2193 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2194 s_assert_param(IS_AFC_FAST_GAIN(cGain));
vpcola 0:a1734fe1ec4b 2195
vpcola 0:a1734fe1ec4b 2196 /* Reads the AFC_0 register and configure the AFC Fast Gain field */
vpcola 0:a1734fe1ec4b 2197 SpiritSpiReadRegisters(AFC0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2198 tempRegValue &= 0x0F;
vpcola 0:a1734fe1ec4b 2199 tempRegValue |= cGain<<4;
vpcola 0:a1734fe1ec4b 2200
vpcola 0:a1734fe1ec4b 2201 /* Sets the AFC_0 register */
vpcola 0:a1734fe1ec4b 2202 g_xStatus = SpiritSpiWriteRegisters(AFC0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2203
vpcola 0:a1734fe1ec4b 2204 }
vpcola 0:a1734fe1ec4b 2205
vpcola 0:a1734fe1ec4b 2206
vpcola 0:a1734fe1ec4b 2207 /**
vpcola 0:a1734fe1ec4b 2208 * @brief Returns the AFC loop gain in fast mode.
vpcola 0:a1734fe1ec4b 2209 * @param None.
vpcola 0:a1734fe1ec4b 2210 * @retval uint8_t AFC loop gain in fast mode. This parameter will be in the range:
vpcola 0:a1734fe1ec4b 2211 * [0:15].
vpcola 0:a1734fe1ec4b 2212 */
vpcola 0:a1734fe1ec4b 2213 uint8_t SpiritRadioGetAFCFastGain(void)
vpcola 0:a1734fe1ec4b 2214 {
vpcola 0:a1734fe1ec4b 2215 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2216
vpcola 0:a1734fe1ec4b 2217 /* Reads the AFC_0 register, mask the AFC Fast Gain field and return the value */
vpcola 0:a1734fe1ec4b 2218 g_xStatus = SpiritSpiReadRegisters(AFC0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2219
vpcola 0:a1734fe1ec4b 2220 return ((tempRegValue & 0xF0)>>4);
vpcola 0:a1734fe1ec4b 2221
vpcola 0:a1734fe1ec4b 2222 }
vpcola 0:a1734fe1ec4b 2223
vpcola 0:a1734fe1ec4b 2224
vpcola 0:a1734fe1ec4b 2225 /**
vpcola 0:a1734fe1ec4b 2226 * @brief Sets the AFC loop gain in slow mode.
vpcola 0:a1734fe1ec4b 2227 * @param cGain AFC loop gain in slow mode. This parameter shall be in the range:
vpcola 0:a1734fe1ec4b 2228 * [0:15].
vpcola 0:a1734fe1ec4b 2229 * @retval None.
vpcola 0:a1734fe1ec4b 2230 */
vpcola 0:a1734fe1ec4b 2231 void SpiritRadioSetAFCSlowGain(uint8_t cGain)
vpcola 0:a1734fe1ec4b 2232 {
vpcola 0:a1734fe1ec4b 2233 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2234
vpcola 0:a1734fe1ec4b 2235 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2236 s_assert_param(IS_AFC_SLOW_GAIN(cGain));
vpcola 0:a1734fe1ec4b 2237
vpcola 0:a1734fe1ec4b 2238 /* Reads the AFC_0 register and configure the AFC Slow Gain field */
vpcola 0:a1734fe1ec4b 2239 SpiritSpiReadRegisters(AFC0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2240 tempRegValue &= 0xF0;
vpcola 0:a1734fe1ec4b 2241 tempRegValue |= cGain;
vpcola 0:a1734fe1ec4b 2242
vpcola 0:a1734fe1ec4b 2243 /* Sets the AFC_0 register */
vpcola 0:a1734fe1ec4b 2244 g_xStatus = SpiritSpiWriteRegisters(AFC0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2245
vpcola 0:a1734fe1ec4b 2246 }
vpcola 0:a1734fe1ec4b 2247
vpcola 0:a1734fe1ec4b 2248
vpcola 0:a1734fe1ec4b 2249 /**
vpcola 0:a1734fe1ec4b 2250 * @brief Returns the AFC loop gain in slow mode.
vpcola 0:a1734fe1ec4b 2251 * @param None.
vpcola 0:a1734fe1ec4b 2252 * @retval uint8_t AFC loop gain in slow mode. This parameter will be in the range:
vpcola 0:a1734fe1ec4b 2253 * [0:15].
vpcola 0:a1734fe1ec4b 2254 */
vpcola 0:a1734fe1ec4b 2255 uint8_t SpiritRadioGetAFCSlowGain(void)
vpcola 0:a1734fe1ec4b 2256 {
vpcola 0:a1734fe1ec4b 2257 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2258
vpcola 0:a1734fe1ec4b 2259 /* Reads the AFC_0 register, mask the AFC Slow Gain field and return the value */
vpcola 0:a1734fe1ec4b 2260 g_xStatus = SpiritSpiReadRegisters(AFC0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2261
vpcola 0:a1734fe1ec4b 2262 return (tempRegValue & 0x0F);
vpcola 0:a1734fe1ec4b 2263
vpcola 0:a1734fe1ec4b 2264 }
vpcola 0:a1734fe1ec4b 2265
vpcola 0:a1734fe1ec4b 2266
vpcola 0:a1734fe1ec4b 2267 /**
vpcola 0:a1734fe1ec4b 2268 * @brief Returns the AFC correction from the corresponding register.
vpcola 0:a1734fe1ec4b 2269 * @param None.
vpcola 0:a1734fe1ec4b 2270 * @retval int8_t AFC correction, read from the corresponding register.
vpcola 0:a1734fe1ec4b 2271 * This parameter will be in the range [-128:127].
vpcola 0:a1734fe1ec4b 2272 */
vpcola 0:a1734fe1ec4b 2273 int8_t SpiritRadioGetAFCCorrectionReg(void)
vpcola 0:a1734fe1ec4b 2274 {
vpcola 0:a1734fe1ec4b 2275 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2276
vpcola 0:a1734fe1ec4b 2277 /* Reads the AFC_CORR register, cast the read value as signed char and return it */
vpcola 0:a1734fe1ec4b 2278 g_xStatus = SpiritSpiReadRegisters(AFC_CORR_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2279
vpcola 0:a1734fe1ec4b 2280 return (int8_t)tempRegValue;
vpcola 0:a1734fe1ec4b 2281
vpcola 0:a1734fe1ec4b 2282 }
vpcola 0:a1734fe1ec4b 2283
vpcola 0:a1734fe1ec4b 2284
vpcola 0:a1734fe1ec4b 2285 /**
vpcola 0:a1734fe1ec4b 2286 * @brief Returns the AFC correction expressed in Hz.
vpcola 0:a1734fe1ec4b 2287 * @param None.
vpcola 0:a1734fe1ec4b 2288 * @retval int32_t AFC correction expressed in Hz
vpcola 0:a1734fe1ec4b 2289 * according to the following formula:<ul>
vpcola 0:a1734fe1ec4b 2290 * <li> Fafc[Hz]= (Fdig/(12*2^10))*AFC_CORR where </li>
vpcola 0:a1734fe1ec4b 2291 * <li> AFC_CORR is the value read in the AFC_CORR register </li> </ul>
vpcola 0:a1734fe1ec4b 2292 */
vpcola 0:a1734fe1ec4b 2293 int32_t SpiritRadioGetAFCCorrectionHz(void)
vpcola 0:a1734fe1ec4b 2294 {
vpcola 0:a1734fe1ec4b 2295 int8_t correction;
vpcola 0:a1734fe1ec4b 2296 uint32_t xtal = s_lXtalFrequency;
vpcola 0:a1734fe1ec4b 2297
vpcola 0:a1734fe1ec4b 2298 /* Reads the AFC correction register */
vpcola 0:a1734fe1ec4b 2299 correction = SpiritRadioGetAFCCorrectionReg();
vpcola 0:a1734fe1ec4b 2300
vpcola 0:a1734fe1ec4b 2301 if(xtal>DOUBLE_XTAL_THR)
vpcola 0:a1734fe1ec4b 2302 {
vpcola 0:a1734fe1ec4b 2303 xtal /= 2;
vpcola 0:a1734fe1ec4b 2304 }
vpcola 0:a1734fe1ec4b 2305
vpcola 0:a1734fe1ec4b 2306 /* Calculates and return the Frequency Correction */
vpcola 0:a1734fe1ec4b 2307 return (int32_t)(xtal/(12*pow(2,10))*correction);
vpcola 0:a1734fe1ec4b 2308
vpcola 0:a1734fe1ec4b 2309 }
vpcola 0:a1734fe1ec4b 2310
vpcola 0:a1734fe1ec4b 2311
vpcola 0:a1734fe1ec4b 2312 /**
vpcola 0:a1734fe1ec4b 2313 * @brief Enables or Disables the AGC.
vpcola 0:a1734fe1ec4b 2314 * @param xNewState new state for AGC.
vpcola 0:a1734fe1ec4b 2315 * This parameter can be: S_ENABLE or S_DISABLE
vpcola 0:a1734fe1ec4b 2316 * @retval None.
vpcola 0:a1734fe1ec4b 2317 */
vpcola 0:a1734fe1ec4b 2318 void SpiritRadioAGC(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2319 {
vpcola 0:a1734fe1ec4b 2320 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2321
vpcola 0:a1734fe1ec4b 2322 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2323 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2324
vpcola 0:a1734fe1ec4b 2325 /* Reads the AGCCTRL_0 register and configure the AGC Enabled field */
vpcola 0:a1734fe1ec4b 2326 SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2327 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2328 {
vpcola 0:a1734fe1ec4b 2329 tempRegValue |= AGCCTRL0_AGC_MASK;
vpcola 0:a1734fe1ec4b 2330 }
vpcola 0:a1734fe1ec4b 2331 else
vpcola 0:a1734fe1ec4b 2332 {
vpcola 0:a1734fe1ec4b 2333 tempRegValue &= (~AGCCTRL0_AGC_MASK);
vpcola 0:a1734fe1ec4b 2334 }
vpcola 0:a1734fe1ec4b 2335
vpcola 0:a1734fe1ec4b 2336 /* Sets the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2337 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2338
vpcola 0:a1734fe1ec4b 2339 }
vpcola 0:a1734fe1ec4b 2340
vpcola 0:a1734fe1ec4b 2341
vpcola 0:a1734fe1ec4b 2342 /**
vpcola 0:a1734fe1ec4b 2343 * @brief Sets the AGC working mode.
vpcola 0:a1734fe1ec4b 2344 * @param xMode the AGC mode. This parameter can be one of the values defined in @ref AGCMode :
vpcola 0:a1734fe1ec4b 2345 * @arg AGC_LINEAR_MODE AGC works in linear mode
vpcola 0:a1734fe1ec4b 2346 * @arg AGC_BINARY_MODE AGC works in binary mode
vpcola 0:a1734fe1ec4b 2347 * @retval None.
vpcola 0:a1734fe1ec4b 2348 */
vpcola 0:a1734fe1ec4b 2349 void SpiritRadioSetAGCMode(AGCMode xMode)
vpcola 0:a1734fe1ec4b 2350 {
vpcola 0:a1734fe1ec4b 2351 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2352
vpcola 0:a1734fe1ec4b 2353 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2354 s_assert_param(IS_AGC_MODE(xMode));
vpcola 0:a1734fe1ec4b 2355
vpcola 0:a1734fe1ec4b 2356 /* Reads the AGCCTRL_0 register and configure the AGC Mode field */
vpcola 0:a1734fe1ec4b 2357 SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2358 if(xMode == AGC_BINARY_MODE)
vpcola 0:a1734fe1ec4b 2359 {
vpcola 0:a1734fe1ec4b 2360 tempRegValue |= AGC_BINARY_MODE;
vpcola 0:a1734fe1ec4b 2361 }
vpcola 0:a1734fe1ec4b 2362 else
vpcola 0:a1734fe1ec4b 2363 {
vpcola 0:a1734fe1ec4b 2364 tempRegValue &= (~AGC_BINARY_MODE);
vpcola 0:a1734fe1ec4b 2365 }
vpcola 0:a1734fe1ec4b 2366
vpcola 0:a1734fe1ec4b 2367 /* Sets the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2368 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2369
vpcola 0:a1734fe1ec4b 2370 }
vpcola 0:a1734fe1ec4b 2371
vpcola 0:a1734fe1ec4b 2372
vpcola 0:a1734fe1ec4b 2373 /**
vpcola 0:a1734fe1ec4b 2374 * @brief Returns the AGC working mode.
vpcola 0:a1734fe1ec4b 2375 * @param None.
vpcola 0:a1734fe1ec4b 2376 * @retval AGCMode Settled AGC mode. This parameter can be one of the values defined in @ref AGCMode :
vpcola 0:a1734fe1ec4b 2377 * @arg AGC_LINEAR_MODE AGC works in linear mode
vpcola 0:a1734fe1ec4b 2378 * @arg AGC_BINARY_MODE AGC works in binary mode
vpcola 0:a1734fe1ec4b 2379 */
vpcola 0:a1734fe1ec4b 2380 AGCMode SpiritRadioGetAGCMode(void)
vpcola 0:a1734fe1ec4b 2381 {
vpcola 0:a1734fe1ec4b 2382 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2383
vpcola 0:a1734fe1ec4b 2384 /* Reads the AGCCTRL_0 register, mask the AGC Mode field and return the value */
vpcola 0:a1734fe1ec4b 2385 g_xStatus = SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2386
vpcola 0:a1734fe1ec4b 2387 return (AGCMode)(tempRegValue & 0x40);
vpcola 0:a1734fe1ec4b 2388
vpcola 0:a1734fe1ec4b 2389 }
vpcola 0:a1734fe1ec4b 2390
vpcola 0:a1734fe1ec4b 2391
vpcola 0:a1734fe1ec4b 2392 /**
vpcola 0:a1734fe1ec4b 2393 * @brief Enables or Disables the AGC freeze on steady state.
vpcola 0:a1734fe1ec4b 2394 * @param xNewState new state for AGC freeze on steady state.
vpcola 0:a1734fe1ec4b 2395 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 2396 * @retval None.
vpcola 0:a1734fe1ec4b 2397 */
vpcola 0:a1734fe1ec4b 2398 void SpiritRadioAGCFreezeOnSteady(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2399 {
vpcola 0:a1734fe1ec4b 2400 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2401
vpcola 0:a1734fe1ec4b 2402 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2403 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2404
vpcola 0:a1734fe1ec4b 2405 /* Reads the AGCCTRL_2 register and configure the AGC Freeze On Steady field */
vpcola 0:a1734fe1ec4b 2406 SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2407 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2408 {
vpcola 0:a1734fe1ec4b 2409 tempRegValue |= AGCCTRL2_FREEZE_ON_STEADY_MASK;
vpcola 0:a1734fe1ec4b 2410 }
vpcola 0:a1734fe1ec4b 2411 else
vpcola 0:a1734fe1ec4b 2412 {
vpcola 0:a1734fe1ec4b 2413 tempRegValue &= (~AGCCTRL2_FREEZE_ON_STEADY_MASK);
vpcola 0:a1734fe1ec4b 2414 }
vpcola 0:a1734fe1ec4b 2415
vpcola 0:a1734fe1ec4b 2416 /* Sets the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2417 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2418
vpcola 0:a1734fe1ec4b 2419 }
vpcola 0:a1734fe1ec4b 2420
vpcola 0:a1734fe1ec4b 2421
vpcola 0:a1734fe1ec4b 2422 /**
vpcola 0:a1734fe1ec4b 2423 * @brief Enable or Disable the AGC freeze on sync detection.
vpcola 0:a1734fe1ec4b 2424 * @param xNewState new state for AGC freeze on sync detection.
vpcola 0:a1734fe1ec4b 2425 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 2426 * @retval None.
vpcola 0:a1734fe1ec4b 2427 */
vpcola 0:a1734fe1ec4b 2428 void SpiritRadioAGCFreezeOnSync(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2429 {
vpcola 0:a1734fe1ec4b 2430 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2431
vpcola 0:a1734fe1ec4b 2432 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2433 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2434
vpcola 0:a1734fe1ec4b 2435 /* Reads the AGCCTRL_2 register and configure the AGC Freeze On Sync field */
vpcola 0:a1734fe1ec4b 2436 SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2437 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2438 {
vpcola 0:a1734fe1ec4b 2439 tempRegValue |= AGCCTRL2_FREEZE_ON_SYNC_MASK;
vpcola 0:a1734fe1ec4b 2440 }
vpcola 0:a1734fe1ec4b 2441 else
vpcola 0:a1734fe1ec4b 2442 {
vpcola 0:a1734fe1ec4b 2443 tempRegValue &= (~AGCCTRL2_FREEZE_ON_SYNC_MASK);
vpcola 0:a1734fe1ec4b 2444 }
vpcola 0:a1734fe1ec4b 2445
vpcola 0:a1734fe1ec4b 2446 /* Sets the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2447 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2448
vpcola 0:a1734fe1ec4b 2449 }
vpcola 0:a1734fe1ec4b 2450
vpcola 0:a1734fe1ec4b 2451
vpcola 0:a1734fe1ec4b 2452 /**
vpcola 0:a1734fe1ec4b 2453 * @brief Enable or Disable the AGC to start with max attenuation.
vpcola 0:a1734fe1ec4b 2454 * @param xNewState new state for AGC start with max attenuation mode.
vpcola 0:a1734fe1ec4b 2455 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:a1734fe1ec4b 2456 * @retval None.
vpcola 0:a1734fe1ec4b 2457 */
vpcola 0:a1734fe1ec4b 2458 void SpiritRadioAGCStartMaxAttenuation(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2459 {
vpcola 0:a1734fe1ec4b 2460 uint8_t tempRegValue = 0x00;
vpcola 0:a1734fe1ec4b 2461
vpcola 0:a1734fe1ec4b 2462 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2463 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2464
vpcola 0:a1734fe1ec4b 2465 /* Reads the AGCCTRL_2 register and configure the AGC Start Max Attenuation field */
vpcola 0:a1734fe1ec4b 2466 SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2467 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2468 {
vpcola 0:a1734fe1ec4b 2469 tempRegValue |= AGCCTRL2_START_MAX_ATTENUATION_MASK;
vpcola 0:a1734fe1ec4b 2470 }
vpcola 0:a1734fe1ec4b 2471 else
vpcola 0:a1734fe1ec4b 2472 {
vpcola 0:a1734fe1ec4b 2473 tempRegValue &= (~AGCCTRL2_START_MAX_ATTENUATION_MASK);
vpcola 0:a1734fe1ec4b 2474 }
vpcola 0:a1734fe1ec4b 2475
vpcola 0:a1734fe1ec4b 2476 /* Sets the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2477 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2478
vpcola 0:a1734fe1ec4b 2479 }
vpcola 0:a1734fe1ec4b 2480
vpcola 0:a1734fe1ec4b 2481
vpcola 0:a1734fe1ec4b 2482 /**
vpcola 0:a1734fe1ec4b 2483 * @brief Sets the AGC measure time.
vpcola 0:a1734fe1ec4b 2484 * @param nTime AGC measure time expressed in us. This parameter shall be in the range [0, 393216/F_Xo].
vpcola 0:a1734fe1ec4b 2485 * @retval None.
vpcola 0:a1734fe1ec4b 2486 */
vpcola 0:a1734fe1ec4b 2487 void SpiritRadioSetAGCMeasureTimeUs(uint16_t nTime)
vpcola 0:a1734fe1ec4b 2488 {
vpcola 0:a1734fe1ec4b 2489 uint8_t tempRegValue, measure;
vpcola 0:a1734fe1ec4b 2490
vpcola 0:a1734fe1ec4b 2491 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2492 s_assert_param(IS_AGC_MEASURE_TIME_US(nTime,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 2493
vpcola 0:a1734fe1ec4b 2494 /* Reads the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2495 SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2496
vpcola 0:a1734fe1ec4b 2497 /* Calculates the measure time value to write in the register */
vpcola 0:a1734fe1ec4b 2498 measure = (uint8_t)lroundf(log2((float)nTime/1e6 * s_lXtalFrequency/12));
vpcola 0:a1734fe1ec4b 2499 (measure>15) ? (measure=15):(measure);
vpcola 0:a1734fe1ec4b 2500
vpcola 0:a1734fe1ec4b 2501 /* Mask the MEAS_TIME field and write the new value */
vpcola 0:a1734fe1ec4b 2502 tempRegValue &= 0xF0;
vpcola 0:a1734fe1ec4b 2503 tempRegValue |= measure;
vpcola 0:a1734fe1ec4b 2504
vpcola 0:a1734fe1ec4b 2505 /* Sets the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2506 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2507
vpcola 0:a1734fe1ec4b 2508 }
vpcola 0:a1734fe1ec4b 2509
vpcola 0:a1734fe1ec4b 2510
vpcola 0:a1734fe1ec4b 2511 /**
vpcola 0:a1734fe1ec4b 2512 * @brief Returns the AGC measure time.
vpcola 0:a1734fe1ec4b 2513 * @param None.
vpcola 0:a1734fe1ec4b 2514 * @retval uint16_t AGC measure time expressed in us. This parameter will be in the range [0, 393216/F_Xo].
vpcola 0:a1734fe1ec4b 2515 */
vpcola 0:a1734fe1ec4b 2516 uint16_t SpiritRadioGetAGCMeasureTimeUs(void)
vpcola 0:a1734fe1ec4b 2517 {
vpcola 0:a1734fe1ec4b 2518 uint8_t measure;
vpcola 0:a1734fe1ec4b 2519
vpcola 0:a1734fe1ec4b 2520 /* Reads the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2521 g_xStatus = SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &measure);
vpcola 0:a1734fe1ec4b 2522
vpcola 0:a1734fe1ec4b 2523 /* Mask the MEAS_TIME field */
vpcola 0:a1734fe1ec4b 2524 measure &= 0x0F;
vpcola 0:a1734fe1ec4b 2525
vpcola 0:a1734fe1ec4b 2526 /* Calculates the measure time value to write in the register */
vpcola 0:a1734fe1ec4b 2527 return (uint16_t)((12.0/s_lXtalFrequency)*(float)pow(2,measure)*1e6);
vpcola 0:a1734fe1ec4b 2528
vpcola 0:a1734fe1ec4b 2529 }
vpcola 0:a1734fe1ec4b 2530
vpcola 0:a1734fe1ec4b 2531
vpcola 0:a1734fe1ec4b 2532 /**
vpcola 0:a1734fe1ec4b 2533 * @brief Sets the AGC measure time.
vpcola 0:a1734fe1ec4b 2534 * @param cTime AGC measure time to write in the MEAS_TIME field of AGCCTRL_2 register.
vpcola 0:a1734fe1ec4b 2535 * This parameter shall be in the range [0:15].
vpcola 0:a1734fe1ec4b 2536 * @retval None.
vpcola 0:a1734fe1ec4b 2537 */
vpcola 0:a1734fe1ec4b 2538 void SpiritRadioSetAGCMeasureTime(uint8_t cTime)
vpcola 0:a1734fe1ec4b 2539 {
vpcola 0:a1734fe1ec4b 2540 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2541
vpcola 0:a1734fe1ec4b 2542 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2543 s_assert_param(IS_AGC_MEASURE_TIME(cTime));
vpcola 0:a1734fe1ec4b 2544
vpcola 0:a1734fe1ec4b 2545 /* Reads the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2546 SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2547
vpcola 0:a1734fe1ec4b 2548 /* Mask the MEAS_TIME field and write the new value */
vpcola 0:a1734fe1ec4b 2549 tempRegValue &= 0xF0;
vpcola 0:a1734fe1ec4b 2550 tempRegValue |= cTime;
vpcola 0:a1734fe1ec4b 2551
vpcola 0:a1734fe1ec4b 2552 /* Sets the AGCCTRL_2 register */
vpcola 0:a1734fe1ec4b 2553 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2554
vpcola 0:a1734fe1ec4b 2555 }
vpcola 0:a1734fe1ec4b 2556
vpcola 0:a1734fe1ec4b 2557
vpcola 0:a1734fe1ec4b 2558 /**
vpcola 0:a1734fe1ec4b 2559 * @brief Returns the AGC measure time.
vpcola 0:a1734fe1ec4b 2560 * @param None.
vpcola 0:a1734fe1ec4b 2561 * @retval uint8_t AGC measure time read from the MEAS_TIME field of AGCCTRL_2 register.
vpcola 0:a1734fe1ec4b 2562 * This parameter will be in the range [0:15].
vpcola 0:a1734fe1ec4b 2563 */
vpcola 0:a1734fe1ec4b 2564 uint8_t SpiritRadioGetAGCMeasureTime(void)
vpcola 0:a1734fe1ec4b 2565 {
vpcola 0:a1734fe1ec4b 2566 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2567
vpcola 0:a1734fe1ec4b 2568 /* Reads the AGCCTRL_2 register, mask the MEAS_TIME field and return the value */
vpcola 0:a1734fe1ec4b 2569 g_xStatus = SpiritSpiReadRegisters(AGCCTRL2_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2570
vpcola 0:a1734fe1ec4b 2571 return (tempRegValue & 0x0F);
vpcola 0:a1734fe1ec4b 2572
vpcola 0:a1734fe1ec4b 2573 }
vpcola 0:a1734fe1ec4b 2574
vpcola 0:a1734fe1ec4b 2575
vpcola 0:a1734fe1ec4b 2576 /**
vpcola 0:a1734fe1ec4b 2577 * @brief Sets the AGC hold time.
vpcola 0:a1734fe1ec4b 2578 * @param cTime AGC hold time expressed in us. This parameter shall be in the range[0, 756/F_Xo].
vpcola 0:a1734fe1ec4b 2579 * @retval None.
vpcola 0:a1734fe1ec4b 2580 */
vpcola 0:a1734fe1ec4b 2581 void SpiritRadioSetAGCHoldTimeUs(uint8_t cTime)
vpcola 0:a1734fe1ec4b 2582 {
vpcola 0:a1734fe1ec4b 2583 uint8_t tempRegValue, hold;
vpcola 0:a1734fe1ec4b 2584
vpcola 0:a1734fe1ec4b 2585 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2586 s_assert_param(IS_AGC_HOLD_TIME_US(cTime,s_lXtalFrequency));
vpcola 0:a1734fe1ec4b 2587
vpcola 0:a1734fe1ec4b 2588 /* Reads the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2589 SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2590
vpcola 0:a1734fe1ec4b 2591 /* Calculates the hold time value to write in the register */
vpcola 0:a1734fe1ec4b 2592 hold = (uint8_t)lroundf(((float)cTime/1e6 * s_lXtalFrequency)/12);
vpcola 0:a1734fe1ec4b 2593 (hold>63) ? (hold=63):(hold);
vpcola 0:a1734fe1ec4b 2594
vpcola 0:a1734fe1ec4b 2595 /* Mask the HOLD_TIME field and write the new value */
vpcola 0:a1734fe1ec4b 2596 tempRegValue &= 0xC0;
vpcola 0:a1734fe1ec4b 2597 tempRegValue |= hold;
vpcola 0:a1734fe1ec4b 2598
vpcola 0:a1734fe1ec4b 2599 /* Sets the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2600 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2601
vpcola 0:a1734fe1ec4b 2602 }
vpcola 0:a1734fe1ec4b 2603
vpcola 0:a1734fe1ec4b 2604
vpcola 0:a1734fe1ec4b 2605 /**
vpcola 0:a1734fe1ec4b 2606 * @brief Returns the AGC hold time.
vpcola 0:a1734fe1ec4b 2607 * @param None.
vpcola 0:a1734fe1ec4b 2608 * @retval uint8_t AGC hold time expressed in us. This parameter will be in the range:
vpcola 0:a1734fe1ec4b 2609 * [0, 756/F_Xo].
vpcola 0:a1734fe1ec4b 2610 */
vpcola 0:a1734fe1ec4b 2611 uint8_t SpiritRadioGetAGCHoldTimeUs(void)
vpcola 0:a1734fe1ec4b 2612 {
vpcola 0:a1734fe1ec4b 2613 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2614
vpcola 0:a1734fe1ec4b 2615 /* Reads the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2616 g_xStatus = SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2617
vpcola 0:a1734fe1ec4b 2618 /* Mask the HOLD_TIME field */
vpcola 0:a1734fe1ec4b 2619 tempRegValue &= 0x3F;
vpcola 0:a1734fe1ec4b 2620
vpcola 0:a1734fe1ec4b 2621 /* Calculates the hold time value and return it */
vpcola 0:a1734fe1ec4b 2622 return (uint8_t)lroundf ((12.0/s_lXtalFrequency)*(tempRegValue*1e6));
vpcola 0:a1734fe1ec4b 2623
vpcola 0:a1734fe1ec4b 2624 }
vpcola 0:a1734fe1ec4b 2625
vpcola 0:a1734fe1ec4b 2626
vpcola 0:a1734fe1ec4b 2627 /**
vpcola 0:a1734fe1ec4b 2628 * @brief Sets the AGC hold time.
vpcola 0:a1734fe1ec4b 2629 * @param cTime AGC hold time to write in the HOLD_TIME field of AGCCTRL_0 register.
vpcola 0:a1734fe1ec4b 2630 * This parameter shall be in the range [0:63].
vpcola 0:a1734fe1ec4b 2631 * @retval None.
vpcola 0:a1734fe1ec4b 2632 */
vpcola 0:a1734fe1ec4b 2633 void SpiritRadioSetAGCHoldTime(uint8_t cTime)
vpcola 0:a1734fe1ec4b 2634 {
vpcola 0:a1734fe1ec4b 2635 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2636
vpcola 0:a1734fe1ec4b 2637 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2638 s_assert_param(IS_AGC_HOLD_TIME(cTime));
vpcola 0:a1734fe1ec4b 2639
vpcola 0:a1734fe1ec4b 2640 /* Reads the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2641 SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2642
vpcola 0:a1734fe1ec4b 2643 /* Mask the HOLD_TIME field and write the new value */
vpcola 0:a1734fe1ec4b 2644 tempRegValue &= 0xC0;
vpcola 0:a1734fe1ec4b 2645 tempRegValue |= cTime;
vpcola 0:a1734fe1ec4b 2646
vpcola 0:a1734fe1ec4b 2647 /* Sets the AGCCTRL_0 register */
vpcola 0:a1734fe1ec4b 2648 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2649
vpcola 0:a1734fe1ec4b 2650 }
vpcola 0:a1734fe1ec4b 2651
vpcola 0:a1734fe1ec4b 2652
vpcola 0:a1734fe1ec4b 2653 /**
vpcola 0:a1734fe1ec4b 2654 * @brief Returns the AGC hold time.
vpcola 0:a1734fe1ec4b 2655 * @param None.
vpcola 0:a1734fe1ec4b 2656 * @retval uint8_t AGC hold time read from the HOLD_TIME field of AGCCTRL_0 register.
vpcola 0:a1734fe1ec4b 2657 * This parameter will be in the range [0:63].
vpcola 0:a1734fe1ec4b 2658 */
vpcola 0:a1734fe1ec4b 2659 uint8_t SpiritRadioGetAGCHoldTime(void)
vpcola 0:a1734fe1ec4b 2660 {
vpcola 0:a1734fe1ec4b 2661 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2662
vpcola 0:a1734fe1ec4b 2663 /* Reads the AGCCTRL_0 register, mask the MEAS_TIME field and return the value */
vpcola 0:a1734fe1ec4b 2664 g_xStatus = SpiritSpiReadRegisters(AGCCTRL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2665
vpcola 0:a1734fe1ec4b 2666 return (tempRegValue & 0x3F);
vpcola 0:a1734fe1ec4b 2667
vpcola 0:a1734fe1ec4b 2668 }
vpcola 0:a1734fe1ec4b 2669
vpcola 0:a1734fe1ec4b 2670
vpcola 0:a1734fe1ec4b 2671 /**
vpcola 0:a1734fe1ec4b 2672 * @brief Sets the AGC high threshold.
vpcola 0:a1734fe1ec4b 2673 * @param cHighThreshold AGC high threshold to write in the THRESHOLD_HIGH field of AGCCTRL_1 register.
vpcola 0:a1734fe1ec4b 2674 * This parameter shall be in the range [0:15].
vpcola 0:a1734fe1ec4b 2675 * @retval None.
vpcola 0:a1734fe1ec4b 2676 */
vpcola 0:a1734fe1ec4b 2677 void SpiritRadioSetAGCHighThreshold(uint8_t cHighThreshold)
vpcola 0:a1734fe1ec4b 2678 {
vpcola 0:a1734fe1ec4b 2679 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2680
vpcola 0:a1734fe1ec4b 2681 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2682 s_assert_param(IS_AGC_THRESHOLD(cHighThreshold));
vpcola 0:a1734fe1ec4b 2683
vpcola 0:a1734fe1ec4b 2684 /* Reads the AGCCTRL_1 register */
vpcola 0:a1734fe1ec4b 2685 SpiritSpiReadRegisters(AGCCTRL1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2686
vpcola 0:a1734fe1ec4b 2687 /* Mask the THRESHOLD_HIGH field and write the new value */
vpcola 0:a1734fe1ec4b 2688 tempRegValue &= 0x0F;
vpcola 0:a1734fe1ec4b 2689 tempRegValue |= cHighThreshold<<4;
vpcola 0:a1734fe1ec4b 2690
vpcola 0:a1734fe1ec4b 2691 /* Sets the AGCCTRL_1 register */
vpcola 0:a1734fe1ec4b 2692 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2693
vpcola 0:a1734fe1ec4b 2694 }
vpcola 0:a1734fe1ec4b 2695
vpcola 0:a1734fe1ec4b 2696
vpcola 0:a1734fe1ec4b 2697 /**
vpcola 0:a1734fe1ec4b 2698 * @brief Returns the AGC high threshold.
vpcola 0:a1734fe1ec4b 2699 * @param None.
vpcola 0:a1734fe1ec4b 2700 * @retval uint8_t AGC high threshold read from the THRESHOLD_HIGH field of AGCCTRL_1 register.
vpcola 0:a1734fe1ec4b 2701 * This parameter will be in the range [0:15].
vpcola 0:a1734fe1ec4b 2702 */
vpcola 0:a1734fe1ec4b 2703 uint8_t SpiritRadioGetAGCHighThreshold(void)
vpcola 0:a1734fe1ec4b 2704 {
vpcola 0:a1734fe1ec4b 2705 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2706
vpcola 0:a1734fe1ec4b 2707 /* Reads the AGCCTRL_1 register, mask the THRESHOLD_HIGH field and return the value */
vpcola 0:a1734fe1ec4b 2708 g_xStatus = SpiritSpiReadRegisters(AGCCTRL1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2709
vpcola 0:a1734fe1ec4b 2710 return ((tempRegValue & 0xF0)>>4);
vpcola 0:a1734fe1ec4b 2711
vpcola 0:a1734fe1ec4b 2712 }
vpcola 0:a1734fe1ec4b 2713
vpcola 0:a1734fe1ec4b 2714
vpcola 0:a1734fe1ec4b 2715 /**
vpcola 0:a1734fe1ec4b 2716 * @brief Sets the AGC low threshold.
vpcola 0:a1734fe1ec4b 2717 * @param cLowThreshold AGC low threshold to write in the THRESHOLD_LOW field of AGCCTRL_1 register.
vpcola 0:a1734fe1ec4b 2718 * This parameter shall be in the range [0:15].
vpcola 0:a1734fe1ec4b 2719 * @retval None.
vpcola 0:a1734fe1ec4b 2720 */
vpcola 0:a1734fe1ec4b 2721 void SpiritRadioSetAGCLowThreshold(uint8_t cLowThreshold)
vpcola 0:a1734fe1ec4b 2722 {
vpcola 0:a1734fe1ec4b 2723 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2724
vpcola 0:a1734fe1ec4b 2725 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2726 s_assert_param(IS_AGC_THRESHOLD(cLowThreshold));
vpcola 0:a1734fe1ec4b 2727
vpcola 0:a1734fe1ec4b 2728 /* Reads the AGCCTRL_1 register */
vpcola 0:a1734fe1ec4b 2729 SpiritSpiReadRegisters(AGCCTRL1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2730
vpcola 0:a1734fe1ec4b 2731 /* Mask the THRESHOLD_LOW field and write the new value */
vpcola 0:a1734fe1ec4b 2732 tempRegValue &= 0xF0;
vpcola 0:a1734fe1ec4b 2733 tempRegValue |= cLowThreshold;
vpcola 0:a1734fe1ec4b 2734
vpcola 0:a1734fe1ec4b 2735 /* Sets the AGCCTRL_1 register */
vpcola 0:a1734fe1ec4b 2736 g_xStatus = SpiritSpiWriteRegisters(AGCCTRL1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2737
vpcola 0:a1734fe1ec4b 2738 }
vpcola 0:a1734fe1ec4b 2739
vpcola 0:a1734fe1ec4b 2740
vpcola 0:a1734fe1ec4b 2741 /**
vpcola 0:a1734fe1ec4b 2742 * @brief Returns the AGC low threshold.
vpcola 0:a1734fe1ec4b 2743 * @param None.
vpcola 0:a1734fe1ec4b 2744 * @retval uint8_t AGC low threshold read from the THRESHOLD_LOW field of AGCCTRL_1 register.
vpcola 0:a1734fe1ec4b 2745 * This parameter will be in the range [0:15].
vpcola 0:a1734fe1ec4b 2746 */
vpcola 0:a1734fe1ec4b 2747 uint8_t SpiritRadioGetAGCLowThreshold(void)
vpcola 0:a1734fe1ec4b 2748 {
vpcola 0:a1734fe1ec4b 2749 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2750
vpcola 0:a1734fe1ec4b 2751 /* Reads the AGCCTRL_1 register, mask the THRESHOLD_LOW field and return the value */
vpcola 0:a1734fe1ec4b 2752 g_xStatus = SpiritSpiReadRegisters(AGCCTRL1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2753
vpcola 0:a1734fe1ec4b 2754 return (tempRegValue & 0x0F);
vpcola 0:a1734fe1ec4b 2755
vpcola 0:a1734fe1ec4b 2756 }
vpcola 0:a1734fe1ec4b 2757
vpcola 0:a1734fe1ec4b 2758
vpcola 0:a1734fe1ec4b 2759 /**
vpcola 0:a1734fe1ec4b 2760 * @brief Sets the clock recovery algorithm.
vpcola 0:a1734fe1ec4b 2761 * @param xMode the Clock Recovery mode. This parameter can be one of the values defined in @ref ClkRecMode :
vpcola 0:a1734fe1ec4b 2762 * @arg CLK_REC_PLL PLL alogrithm for clock recovery
vpcola 0:a1734fe1ec4b 2763 * @arg CLK_REC_DLL DLL alogrithm for clock recovery
vpcola 0:a1734fe1ec4b 2764 * @retval None.
vpcola 0:a1734fe1ec4b 2765 */
vpcola 0:a1734fe1ec4b 2766 void SpiritRadioSetClkRecMode(ClkRecMode xMode)
vpcola 0:a1734fe1ec4b 2767 {
vpcola 0:a1734fe1ec4b 2768 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2769
vpcola 0:a1734fe1ec4b 2770 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2771 s_assert_param(IS_CLK_REC_MODE(xMode));
vpcola 0:a1734fe1ec4b 2772
vpcola 0:a1734fe1ec4b 2773 /* Reads the FDEV_0 register */
vpcola 0:a1734fe1ec4b 2774 SpiritSpiReadRegisters(FDEV0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2775
vpcola 0:a1734fe1ec4b 2776 /* Mask the CLOCK_REC_ALGO_SEL field and write the new value */
vpcola 0:a1734fe1ec4b 2777 tempRegValue &= 0xF7;
vpcola 0:a1734fe1ec4b 2778 tempRegValue |= (uint8_t)xMode;
vpcola 0:a1734fe1ec4b 2779
vpcola 0:a1734fe1ec4b 2780 /* Sets the FDEV_0 register */
vpcola 0:a1734fe1ec4b 2781 g_xStatus = SpiritSpiWriteRegisters(FDEV0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2782
vpcola 0:a1734fe1ec4b 2783 }
vpcola 0:a1734fe1ec4b 2784
vpcola 0:a1734fe1ec4b 2785
vpcola 0:a1734fe1ec4b 2786 /**
vpcola 0:a1734fe1ec4b 2787 * @brief Returns the Clock Recovery working mode.
vpcola 0:a1734fe1ec4b 2788 * @param None.
vpcola 0:a1734fe1ec4b 2789 * @retval ClkRecMode Clock Recovery mode. This parameter can be one of the values defined in @ref ClkRecMode :
vpcola 0:a1734fe1ec4b 2790 * @arg CLK_REC_PLL PLL alogrithm for clock recovery
vpcola 0:a1734fe1ec4b 2791 * @arg CLK_REC_DLL DLL alogrithm for clock recovery
vpcola 0:a1734fe1ec4b 2792 */
vpcola 0:a1734fe1ec4b 2793 ClkRecMode SpiritRadioGetClkRecMode(void)
vpcola 0:a1734fe1ec4b 2794 {
vpcola 0:a1734fe1ec4b 2795 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2796
vpcola 0:a1734fe1ec4b 2797 /* Reads the FDEV_0 register, mask the CLOCK_REC_ALGO_SEL field and return the value */
vpcola 0:a1734fe1ec4b 2798 g_xStatus = SpiritSpiReadRegisters(FDEV0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2799
vpcola 0:a1734fe1ec4b 2800 return (ClkRecMode)(tempRegValue & 0x08);
vpcola 0:a1734fe1ec4b 2801
vpcola 0:a1734fe1ec4b 2802 }
vpcola 0:a1734fe1ec4b 2803
vpcola 0:a1734fe1ec4b 2804
vpcola 0:a1734fe1ec4b 2805 /**
vpcola 0:a1734fe1ec4b 2806 * @brief Sets the clock recovery proportional gain.
vpcola 0:a1734fe1ec4b 2807 * @param cPGain the Clock Recovery proportional gain to write in the CLK_REC_P_GAIN field of CLOCKREC register.
vpcola 0:a1734fe1ec4b 2808 * It represents is log2 value of the clock recovery proportional gain.
vpcola 0:a1734fe1ec4b 2809 * This parameter shall be in the range [0:7].
vpcola 0:a1734fe1ec4b 2810 * @retval None.
vpcola 0:a1734fe1ec4b 2811 */
vpcola 0:a1734fe1ec4b 2812 void SpiritRadioSetClkRecPGain(uint8_t cPGain)
vpcola 0:a1734fe1ec4b 2813 {
vpcola 0:a1734fe1ec4b 2814 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2815
vpcola 0:a1734fe1ec4b 2816 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2817 s_assert_param(IS_CLK_REC_P_GAIN(cPGain));
vpcola 0:a1734fe1ec4b 2818
vpcola 0:a1734fe1ec4b 2819 /* Reads the CLOCKREC register */
vpcola 0:a1734fe1ec4b 2820 SpiritSpiReadRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2821
vpcola 0:a1734fe1ec4b 2822 /* Mask the CLK_REC_P_GAIN field and write the new value */
vpcola 0:a1734fe1ec4b 2823 tempRegValue &= 0x1F;
vpcola 0:a1734fe1ec4b 2824 tempRegValue |= (cPGain<<5);
vpcola 0:a1734fe1ec4b 2825
vpcola 0:a1734fe1ec4b 2826 /* Sets the CLOCKREC register */
vpcola 0:a1734fe1ec4b 2827 g_xStatus = SpiritSpiWriteRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2828
vpcola 0:a1734fe1ec4b 2829 }
vpcola 0:a1734fe1ec4b 2830
vpcola 0:a1734fe1ec4b 2831
vpcola 0:a1734fe1ec4b 2832 /**
vpcola 0:a1734fe1ec4b 2833 * @brief Returns the log2 of the clock recovery proportional gain.
vpcola 0:a1734fe1ec4b 2834 * @param None.
vpcola 0:a1734fe1ec4b 2835 * @retval uint8_t Clock Recovery proportional gain read from the CLK_REC_P_GAIN field of CLOCKREC register.
vpcola 0:a1734fe1ec4b 2836 * This parameter will be in the range [0:7].
vpcola 0:a1734fe1ec4b 2837 */
vpcola 0:a1734fe1ec4b 2838 uint8_t SpiritRadioGetClkRecPGain(void)
vpcola 0:a1734fe1ec4b 2839 {
vpcola 0:a1734fe1ec4b 2840 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2841
vpcola 0:a1734fe1ec4b 2842 /* Reads the CLOCKREC register, mask the CLK_REC_P_GAIN field and return the value */
vpcola 0:a1734fe1ec4b 2843 g_xStatus = SpiritSpiReadRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2844
vpcola 0:a1734fe1ec4b 2845 return ((tempRegValue & 0xEF)>>5);
vpcola 0:a1734fe1ec4b 2846
vpcola 0:a1734fe1ec4b 2847 }
vpcola 0:a1734fe1ec4b 2848
vpcola 0:a1734fe1ec4b 2849
vpcola 0:a1734fe1ec4b 2850 /**
vpcola 0:a1734fe1ec4b 2851 * @brief Sets the clock recovery integral gain.
vpcola 0:a1734fe1ec4b 2852 * @param cIGain the Clock Recovery integral gain to write in the CLK_REC_I_GAIN field of CLOCKREC register.
vpcola 0:a1734fe1ec4b 2853 * This parameter shall be in the range [0:15].
vpcola 0:a1734fe1ec4b 2854 * @retval None.
vpcola 0:a1734fe1ec4b 2855 */
vpcola 0:a1734fe1ec4b 2856 void SpiritRadioSetClkRecIGain(uint8_t cIGain)
vpcola 0:a1734fe1ec4b 2857 {
vpcola 0:a1734fe1ec4b 2858 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2859
vpcola 0:a1734fe1ec4b 2860 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2861 s_assert_param(IS_CLK_REC_I_GAIN(cIGain));
vpcola 0:a1734fe1ec4b 2862
vpcola 0:a1734fe1ec4b 2863 /* Reads the CLOCKREC register */
vpcola 0:a1734fe1ec4b 2864 SpiritSpiReadRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2865
vpcola 0:a1734fe1ec4b 2866 /* Mask the CLK_REC_P_GAIN field and write the new value */
vpcola 0:a1734fe1ec4b 2867 tempRegValue &= 0xF0;
vpcola 0:a1734fe1ec4b 2868 tempRegValue |= cIGain;
vpcola 0:a1734fe1ec4b 2869
vpcola 0:a1734fe1ec4b 2870 /* Sets the CLOCKREC register */
vpcola 0:a1734fe1ec4b 2871 g_xStatus = SpiritSpiWriteRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2872
vpcola 0:a1734fe1ec4b 2873 }
vpcola 0:a1734fe1ec4b 2874
vpcola 0:a1734fe1ec4b 2875
vpcola 0:a1734fe1ec4b 2876 /**
vpcola 0:a1734fe1ec4b 2877 * @brief Returns the clock recovery integral gain.
vpcola 0:a1734fe1ec4b 2878 * @param None.
vpcola 0:a1734fe1ec4b 2879 * @retval uint8_t Clock Recovery integral gain read from the
vpcola 0:a1734fe1ec4b 2880 * CLK_REC_I_GAIN field of CLOCKREC register.
vpcola 0:a1734fe1ec4b 2881 * This parameter will be in the range [0:15].
vpcola 0:a1734fe1ec4b 2882 */
vpcola 0:a1734fe1ec4b 2883 uint8_t SpiritRadioGetClkRecIGain(void)
vpcola 0:a1734fe1ec4b 2884 {
vpcola 0:a1734fe1ec4b 2885 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2886
vpcola 0:a1734fe1ec4b 2887 /* Reads the CLOCKREC register, mask the CLK_REC_I_GAIN field and return the value */
vpcola 0:a1734fe1ec4b 2888 g_xStatus = SpiritSpiReadRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2889
vpcola 0:a1734fe1ec4b 2890 return (tempRegValue & 0x0F);
vpcola 0:a1734fe1ec4b 2891
vpcola 0:a1734fe1ec4b 2892 }
vpcola 0:a1734fe1ec4b 2893
vpcola 0:a1734fe1ec4b 2894
vpcola 0:a1734fe1ec4b 2895 /**
vpcola 0:a1734fe1ec4b 2896 * @brief Sets the postfilter length for clock recovery algorithm.
vpcola 0:a1734fe1ec4b 2897 * @param xLength the postfilter length in symbols. This parameter can be one of the values defined in @ref PstFltLength :
vpcola 0:a1734fe1ec4b 2898 * @arg PSTFLT_LENGTH_8 Postfilter length is 8 symbols
vpcola 0:a1734fe1ec4b 2899 * @arg PSTFLT_LENGTH_16 Postfilter length is 16 symbols
vpcola 0:a1734fe1ec4b 2900 * @retval None.
vpcola 0:a1734fe1ec4b 2901 */
vpcola 0:a1734fe1ec4b 2902 void SpiritRadioSetClkRecPstFltLength(PstFltLength xLength)
vpcola 0:a1734fe1ec4b 2903 {
vpcola 0:a1734fe1ec4b 2904 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2905
vpcola 0:a1734fe1ec4b 2906 /* Check the parameter */
vpcola 0:a1734fe1ec4b 2907 s_assert_param(IS_PST_FLT_LENGTH(xLength));
vpcola 0:a1734fe1ec4b 2908
vpcola 0:a1734fe1ec4b 2909 /* Reads the CLOCKREC register */
vpcola 0:a1734fe1ec4b 2910 SpiritSpiReadRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2911
vpcola 0:a1734fe1ec4b 2912 /* Mask the PSTFLT_LEN field and write the new value */
vpcola 0:a1734fe1ec4b 2913 tempRegValue &= 0xEF;
vpcola 0:a1734fe1ec4b 2914 tempRegValue |= (uint8_t)xLength;
vpcola 0:a1734fe1ec4b 2915
vpcola 0:a1734fe1ec4b 2916 /* Sets the CLOCKREC register */
vpcola 0:a1734fe1ec4b 2917 g_xStatus = SpiritSpiWriteRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2918
vpcola 0:a1734fe1ec4b 2919 }
vpcola 0:a1734fe1ec4b 2920
vpcola 0:a1734fe1ec4b 2921
vpcola 0:a1734fe1ec4b 2922 /**
vpcola 0:a1734fe1ec4b 2923 * @brief Returns the postfilter length for clock recovery algorithm.
vpcola 0:a1734fe1ec4b 2924 * @param None.
vpcola 0:a1734fe1ec4b 2925 * @retval PstFltLength Postfilter length in symbols. This parameter can be one of the values defined in @ref PstFltLength :
vpcola 0:a1734fe1ec4b 2926 * @arg PSTFLT_LENGTH_8 Postfilter length is 8 symbols
vpcola 0:a1734fe1ec4b 2927 * @arg PSTFLT_LENGTH_16 Postfilter length is 16 symbols
vpcola 0:a1734fe1ec4b 2928 */
vpcola 0:a1734fe1ec4b 2929 PstFltLength SpiritRadioGetClkRecPstFltLength(void)
vpcola 0:a1734fe1ec4b 2930 {
vpcola 0:a1734fe1ec4b 2931 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2932
vpcola 0:a1734fe1ec4b 2933 /* Reads the CLOCKREC register, mask the PSTFLT_LEN field and return the value */
vpcola 0:a1734fe1ec4b 2934 g_xStatus = SpiritSpiReadRegisters(CLOCKREC_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2935
vpcola 0:a1734fe1ec4b 2936 return (PstFltLength)(tempRegValue & 0x10);
vpcola 0:a1734fe1ec4b 2937
vpcola 0:a1734fe1ec4b 2938 }
vpcola 0:a1734fe1ec4b 2939
vpcola 0:a1734fe1ec4b 2940
vpcola 0:a1734fe1ec4b 2941 /**
vpcola 0:a1734fe1ec4b 2942 * @brief Enables or Disables the received data blanking when the CS is under the threshold.
vpcola 0:a1734fe1ec4b 2943 * @param xNewState new state of this mode.
vpcola 0:a1734fe1ec4b 2944 * This parameter can be: S_ENABLE or S_DISABLE .
vpcola 0:a1734fe1ec4b 2945 * @retval None.
vpcola 0:a1734fe1ec4b 2946 */
vpcola 0:a1734fe1ec4b 2947 void SpiritRadioCsBlanking(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2948 {
vpcola 0:a1734fe1ec4b 2949 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2950
vpcola 0:a1734fe1ec4b 2951 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2952 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2953
vpcola 0:a1734fe1ec4b 2954 /* Reads the ANT_SELECT_CONF_BASE and mask the CS_BLANKING BIT field */
vpcola 0:a1734fe1ec4b 2955 SpiritSpiReadRegisters(ANT_SELECT_CONF_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2956
vpcola 0:a1734fe1ec4b 2957 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2958 {
vpcola 0:a1734fe1ec4b 2959 tempRegValue |= ANT_SELECT_CS_BLANKING_MASK;
vpcola 0:a1734fe1ec4b 2960 }
vpcola 0:a1734fe1ec4b 2961 else
vpcola 0:a1734fe1ec4b 2962 {
vpcola 0:a1734fe1ec4b 2963 tempRegValue &= (~ANT_SELECT_CS_BLANKING_MASK);
vpcola 0:a1734fe1ec4b 2964 }
vpcola 0:a1734fe1ec4b 2965
vpcola 0:a1734fe1ec4b 2966 /* Writes the new value in the ANT_SELECT_CONF register */
vpcola 0:a1734fe1ec4b 2967 g_xStatus = SpiritSpiWriteRegisters(ANT_SELECT_CONF_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2968
vpcola 0:a1734fe1ec4b 2969
vpcola 0:a1734fe1ec4b 2970 }
vpcola 0:a1734fe1ec4b 2971
vpcola 0:a1734fe1ec4b 2972 /**
vpcola 0:a1734fe1ec4b 2973 * @brief Enables or Disables the persistent RX mode.
vpcola 0:a1734fe1ec4b 2974 * @param xNewState new state of this mode.
vpcola 0:a1734fe1ec4b 2975 * This parameter can be: S_ENABLE or S_DISABLE .
vpcola 0:a1734fe1ec4b 2976 * @retval None.
vpcola 0:a1734fe1ec4b 2977 */
vpcola 0:a1734fe1ec4b 2978 void SpiritRadioPersistenRx(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 2979 {
vpcola 0:a1734fe1ec4b 2980 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 2981
vpcola 0:a1734fe1ec4b 2982 /* Check the parameters */
vpcola 0:a1734fe1ec4b 2983 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 2984
vpcola 0:a1734fe1ec4b 2985 /* Reads the PROTOCOL0_BASE and mask the PROTOCOL0_PERS_RX_MASK bitfield */
vpcola 0:a1734fe1ec4b 2986 SpiritSpiReadRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2987
vpcola 0:a1734fe1ec4b 2988 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 2989 {
vpcola 0:a1734fe1ec4b 2990 tempRegValue |= PROTOCOL0_PERS_RX_MASK;
vpcola 0:a1734fe1ec4b 2991 }
vpcola 0:a1734fe1ec4b 2992 else
vpcola 0:a1734fe1ec4b 2993 {
vpcola 0:a1734fe1ec4b 2994 tempRegValue &= (~PROTOCOL0_PERS_RX_MASK);
vpcola 0:a1734fe1ec4b 2995 }
vpcola 0:a1734fe1ec4b 2996
vpcola 0:a1734fe1ec4b 2997 /* Writes the new value in the PROTOCOL0_BASE register */
vpcola 0:a1734fe1ec4b 2998 g_xStatus = SpiritSpiWriteRegisters(PROTOCOL0_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 2999
vpcola 0:a1734fe1ec4b 3000 }
vpcola 0:a1734fe1ec4b 3001
vpcola 0:a1734fe1ec4b 3002 /**
vpcola 0:a1734fe1ec4b 3003 * @brief Enables or Disables the synthesizer reference divider.
vpcola 0:a1734fe1ec4b 3004 * @param xNewState new state for synthesizer reference divider.
vpcola 0:a1734fe1ec4b 3005 * This parameter can be: S_ENABLE or S_DISABLE .
vpcola 0:a1734fe1ec4b 3006 * @retval None.
vpcola 0:a1734fe1ec4b 3007 */
vpcola 0:a1734fe1ec4b 3008 void SpiritRadioSetRefDiv(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 3009 {
vpcola 0:a1734fe1ec4b 3010 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 3011
vpcola 0:a1734fe1ec4b 3012 /* Check the parameters */
vpcola 0:a1734fe1ec4b 3013 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 3014
vpcola 0:a1734fe1ec4b 3015 /* Reads the SYNTH_CONFIG1_BASE and mask the REFDIV bit field */
vpcola 0:a1734fe1ec4b 3016 SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 3017
vpcola 0:a1734fe1ec4b 3018 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 3019 {
vpcola 0:a1734fe1ec4b 3020 tempRegValue |= 0x80;
vpcola 0:a1734fe1ec4b 3021 }
vpcola 0:a1734fe1ec4b 3022 else
vpcola 0:a1734fe1ec4b 3023 {
vpcola 0:a1734fe1ec4b 3024 tempRegValue &= 0x7F;
vpcola 0:a1734fe1ec4b 3025 }
vpcola 0:a1734fe1ec4b 3026
vpcola 0:a1734fe1ec4b 3027 /* Writes the new value in the SYNTH_CONFIG1_BASE register */
vpcola 0:a1734fe1ec4b 3028 g_xStatus = SpiritSpiWriteRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 3029
vpcola 0:a1734fe1ec4b 3030 }
vpcola 0:a1734fe1ec4b 3031
vpcola 0:a1734fe1ec4b 3032 /**
vpcola 0:a1734fe1ec4b 3033 * @brief Get the the synthesizer reference divider state.
vpcola 0:a1734fe1ec4b 3034 * @param void.
vpcola 0:a1734fe1ec4b 3035 * @retval None.
vpcola 0:a1734fe1ec4b 3036 */
vpcola 0:a1734fe1ec4b 3037 SpiritFunctionalState SpiritRadioGetRefDiv(void)
vpcola 0:a1734fe1ec4b 3038 {
vpcola 0:a1734fe1ec4b 3039 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 3040
vpcola 0:a1734fe1ec4b 3041 g_xStatus = SpiritSpiReadRegisters(SYNTH_CONFIG1_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 3042
vpcola 0:a1734fe1ec4b 3043 if(((tempRegValue>>7)&0x1))
vpcola 0:a1734fe1ec4b 3044 {
vpcola 0:a1734fe1ec4b 3045 return S_ENABLE;
vpcola 0:a1734fe1ec4b 3046 }
vpcola 0:a1734fe1ec4b 3047 else
vpcola 0:a1734fe1ec4b 3048 {
vpcola 0:a1734fe1ec4b 3049 return S_DISABLE;
vpcola 0:a1734fe1ec4b 3050 }
vpcola 0:a1734fe1ec4b 3051
vpcola 0:a1734fe1ec4b 3052 }
vpcola 0:a1734fe1ec4b 3053
vpcola 0:a1734fe1ec4b 3054 /**
vpcola 0:a1734fe1ec4b 3055 * @brief Enables or Disables the synthesizer reference divider.
vpcola 0:a1734fe1ec4b 3056 * @param xNewState new state for synthesizer reference divider.
vpcola 0:a1734fe1ec4b 3057 * This parameter can be: S_ENABLE or S_DISABLE .
vpcola 0:a1734fe1ec4b 3058 * @retval None.
vpcola 0:a1734fe1ec4b 3059 */
vpcola 0:a1734fe1ec4b 3060 void SpiritRadioSetDigDiv(SpiritFunctionalState xNewState)
vpcola 0:a1734fe1ec4b 3061 {
vpcola 0:a1734fe1ec4b 3062 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 3063
vpcola 0:a1734fe1ec4b 3064 /* Check the parameters */
vpcola 0:a1734fe1ec4b 3065 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:a1734fe1ec4b 3066
vpcola 0:a1734fe1ec4b 3067 /* Reads the XO_RCO_TEST_BASE and mask the PD_CLKDIV bit field */
vpcola 0:a1734fe1ec4b 3068 SpiritSpiReadRegisters(XO_RCO_TEST_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 3069
vpcola 0:a1734fe1ec4b 3070 if(xNewState == S_ENABLE)
vpcola 0:a1734fe1ec4b 3071 {
vpcola 0:a1734fe1ec4b 3072 tempRegValue &= 0xf7;
vpcola 0:a1734fe1ec4b 3073 }
vpcola 0:a1734fe1ec4b 3074 else
vpcola 0:a1734fe1ec4b 3075 {
vpcola 0:a1734fe1ec4b 3076
vpcola 0:a1734fe1ec4b 3077 tempRegValue |= 0x08;
vpcola 0:a1734fe1ec4b 3078 }
vpcola 0:a1734fe1ec4b 3079
vpcola 0:a1734fe1ec4b 3080 /* Writes the new value in the XO_RCO_TEST_BASE register */
vpcola 0:a1734fe1ec4b 3081 g_xStatus = SpiritSpiWriteRegisters(XO_RCO_TEST_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 3082
vpcola 0:a1734fe1ec4b 3083 }
vpcola 0:a1734fe1ec4b 3084
vpcola 0:a1734fe1ec4b 3085 /**
vpcola 0:a1734fe1ec4b 3086 * @brief Get the the synthesizer reference divider state.
vpcola 0:a1734fe1ec4b 3087 * @param void.
vpcola 0:a1734fe1ec4b 3088 * @retval None.
vpcola 0:a1734fe1ec4b 3089 */
vpcola 0:a1734fe1ec4b 3090 SpiritFunctionalState SpiritRadioGetDigDiv(void)
vpcola 0:a1734fe1ec4b 3091 {
vpcola 0:a1734fe1ec4b 3092 uint8_t tempRegValue;
vpcola 0:a1734fe1ec4b 3093
vpcola 0:a1734fe1ec4b 3094 g_xStatus = SpiritSpiReadRegisters(XO_RCO_TEST_BASE, 1, &tempRegValue);
vpcola 0:a1734fe1ec4b 3095
vpcola 0:a1734fe1ec4b 3096 if(((tempRegValue>>3)&0x1))
vpcola 0:a1734fe1ec4b 3097 {
vpcola 0:a1734fe1ec4b 3098 return S_DISABLE;
vpcola 0:a1734fe1ec4b 3099 }
vpcola 0:a1734fe1ec4b 3100 else
vpcola 0:a1734fe1ec4b 3101 {
vpcola 0:a1734fe1ec4b 3102 return S_ENABLE;
vpcola 0:a1734fe1ec4b 3103 }
vpcola 0:a1734fe1ec4b 3104
vpcola 0:a1734fe1ec4b 3105 }
vpcola 0:a1734fe1ec4b 3106
vpcola 0:a1734fe1ec4b 3107 /**
vpcola 0:a1734fe1ec4b 3108 * @brief Returns the XTAL frequency.
vpcola 0:a1734fe1ec4b 3109 * @param void.
vpcola 0:a1734fe1ec4b 3110 * @retval uint32_t XTAL frequency.
vpcola 0:a1734fe1ec4b 3111 */
vpcola 0:a1734fe1ec4b 3112 uint32_t SpiritRadioGetXtalFrequency(void)
vpcola 0:a1734fe1ec4b 3113 {
vpcola 0:a1734fe1ec4b 3114 return s_lXtalFrequency;
vpcola 0:a1734fe1ec4b 3115 }
vpcola 0:a1734fe1ec4b 3116
vpcola 0:a1734fe1ec4b 3117 /**
vpcola 0:a1734fe1ec4b 3118 * @brief Sets the XTAL frequency.
vpcola 0:a1734fe1ec4b 3119 * @param uint32_t XTAL frequency.
vpcola 0:a1734fe1ec4b 3120 * @retval void.
vpcola 0:a1734fe1ec4b 3121 */
vpcola 0:a1734fe1ec4b 3122 void SpiritRadioSetXtalFrequency(uint32_t lXtalFrequency)
vpcola 0:a1734fe1ec4b 3123 {
vpcola 0:a1734fe1ec4b 3124 s_lXtalFrequency = lXtalFrequency;
vpcola 0:a1734fe1ec4b 3125 }
vpcola 0:a1734fe1ec4b 3126
vpcola 0:a1734fe1ec4b 3127 /**
vpcola 0:a1734fe1ec4b 3128 * @}
vpcola 0:a1734fe1ec4b 3129 */
vpcola 0:a1734fe1ec4b 3130
vpcola 0:a1734fe1ec4b 3131
vpcola 0:a1734fe1ec4b 3132 /**
vpcola 0:a1734fe1ec4b 3133 * @}
vpcola 0:a1734fe1ec4b 3134 */
vpcola 0:a1734fe1ec4b 3135
vpcola 0:a1734fe1ec4b 3136
vpcola 0:a1734fe1ec4b 3137 /**
vpcola 0:a1734fe1ec4b 3138 * @}
vpcola 0:a1734fe1ec4b 3139 */
vpcola 0:a1734fe1ec4b 3140
vpcola 0:a1734fe1ec4b 3141
vpcola 0:a1734fe1ec4b 3142
vpcola 0:a1734fe1ec4b 3143 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
vpcola 0:a1734fe1ec4b 3144