Added support for the WNC M14A2A Cellular LTE Data Module.

Dependencies:   WNC14A2AInterface

Easy Connect

Easily add all supported connectivity methods to your mbed OS project

This project is derived from https://developer.mbed.org/teams/sandbox/code/simple-mbed-client-example/file/dd6231df71bb/easy-connect.lib. It give user the ability to switch between connectivity methods and includes support for the WNC14A2A Data Module. The `NetworkInterface` API makes this easy, but you still need a mechanism for the user to select the connection method, The selection is made by modifying the `mbed_app.json` file and using `easy_connect()` from your application.

Specifying connectivity method

To add support for the WNC14A2A, add the following to your ``mbed_app.json`` file:

mbed_app.json

{
    "config": {
        "network-interface":{
            "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD,WNC14A2A",
            "value": "WNC14A2A"
        }
    },
}

After you choose `WNC14A2A` you'll also need to indicate if you want debug output or not by Enabling (true) or Disabling (false) WNC_DEBUG.

If WNC_DEBUG is enabled, there are 3 different levels of debug output (selected via bit settings). These debug levels are set using the following values:

ValueDescription
1Basic WNC driver debug output
2Comprehensive WNC driver debug output
4Network Layer debug output

You can have any combination of these three bit values for a total value of 0 – 7.

WNC Debug Settings

    "config": {
        "WNC_DEBUG": {
            "value": false
        },
        "WNC_DEBUG_SETTING": {
            "value": 4
        },
    }

Using Easy Connect from your application

Easy Connect has just one function which will either return a `NetworkInterface`-pointer or `NULL`:

Sample Code

#include "easy-connect.h"

int main(int, char**) {
    NetworkInterface* network = easy_connect(true); /* has 1 argument, enable_logging (pass in true to log to serial port) */
    if (!network) {
        printf("Connecting to the network failed... See serial output.\r\n");
        return 1;
    }
 
    // Rest of your program
}

Tested on

  • K64F with Ethernet.
  • AT&T Cellular IoT Starter Kit with WNC M14A2A Cellular Data Module

The WNCInterface class currently supports the following version(s):

  • MPSS: M14A2A_v11.50.164451 APSS: M14A2A_v11.53.164451

License

This library is released under the Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License and may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Committer:
group-Avnet
Date:
Wed Apr 19 01:08:11 2017 +0000
Revision:
0:478cfd88041f
Initial commit

Who changed what in which revision?

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