Fork of my MQTTGateway

Dependencies:   mbed-http

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

Who changed what in which revision?

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