Fork of my MQTTGateway

Dependencies:   mbed-http

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

Who changed what in which revision?

UserRevisionLine numberNew contents of line
vpcola 0:f1d3878b8dd9 1 /**
vpcola 0:f1d3878b8dd9 2 ******************************************************************************
vpcola 0:f1d3878b8dd9 3 * @file SPIRIT_General.c
vpcola 0:f1d3878b8dd9 4 * @author VMA division - AMS
vpcola 0:f1d3878b8dd9 5 * @version 3.2.2
vpcola 0:f1d3878b8dd9 6 * @date 08-July-2015
vpcola 0:f1d3878b8dd9 7 * @brief Configuration and management of SPIRIT General functionalities.
vpcola 0:f1d3878b8dd9 8 * @details
vpcola 0:f1d3878b8dd9 9 *
vpcola 0:f1d3878b8dd9 10 * @attention
vpcola 0:f1d3878b8dd9 11 *
vpcola 0:f1d3878b8dd9 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
vpcola 0:f1d3878b8dd9 13 *
vpcola 0:f1d3878b8dd9 14 * Redistribution and use in source and binary forms, with or without modification,
vpcola 0:f1d3878b8dd9 15 * are permitted provided that the following conditions are met:
vpcola 0:f1d3878b8dd9 16 * 1. Redistributions of source code must retain the above copyright notice,
vpcola 0:f1d3878b8dd9 17 * this list of conditions and the following disclaimer.
vpcola 0:f1d3878b8dd9 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
vpcola 0:f1d3878b8dd9 19 * this list of conditions and the following disclaimer in the documentation
vpcola 0:f1d3878b8dd9 20 * and/or other materials provided with the distribution.
vpcola 0:f1d3878b8dd9 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
vpcola 0:f1d3878b8dd9 22 * may be used to endorse or promote products derived from this software
vpcola 0:f1d3878b8dd9 23 * without specific prior written permission.
vpcola 0:f1d3878b8dd9 24 *
vpcola 0:f1d3878b8dd9 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
vpcola 0:f1d3878b8dd9 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
vpcola 0:f1d3878b8dd9 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
vpcola 0:f1d3878b8dd9 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
vpcola 0:f1d3878b8dd9 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
vpcola 0:f1d3878b8dd9 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
vpcola 0:f1d3878b8dd9 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
vpcola 0:f1d3878b8dd9 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
vpcola 0:f1d3878b8dd9 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
vpcola 0:f1d3878b8dd9 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vpcola 0:f1d3878b8dd9 35 *
vpcola 0:f1d3878b8dd9 36 ******************************************************************************
vpcola 0:f1d3878b8dd9 37 */
vpcola 0:f1d3878b8dd9 38
vpcola 0:f1d3878b8dd9 39 /* Includes ------------------------------------------------------------------*/
vpcola 0:f1d3878b8dd9 40 #include "SPIRIT_General.h"
vpcola 0:f1d3878b8dd9 41 #include "MCU_Interface.h"
vpcola 0:f1d3878b8dd9 42
vpcola 0:f1d3878b8dd9 43
vpcola 0:f1d3878b8dd9 44 /**
vpcola 0:f1d3878b8dd9 45 * @addtogroup SPIRIT_Libraries
vpcola 0:f1d3878b8dd9 46 * @{
vpcola 0:f1d3878b8dd9 47 */
vpcola 0:f1d3878b8dd9 48
vpcola 0:f1d3878b8dd9 49
vpcola 0:f1d3878b8dd9 50 /**
vpcola 0:f1d3878b8dd9 51 * @addtogroup SPIRIT_General
vpcola 0:f1d3878b8dd9 52 * @{
vpcola 0:f1d3878b8dd9 53 */
vpcola 0:f1d3878b8dd9 54
vpcola 0:f1d3878b8dd9 55
vpcola 0:f1d3878b8dd9 56 /**
vpcola 0:f1d3878b8dd9 57 * @defgroup General_Private_TypesDefinitions General Private Types Definitions
vpcola 0:f1d3878b8dd9 58 * @{
vpcola 0:f1d3878b8dd9 59 */
vpcola 0:f1d3878b8dd9 60
vpcola 0:f1d3878b8dd9 61 /**
vpcola 0:f1d3878b8dd9 62 *@}
vpcola 0:f1d3878b8dd9 63 */
vpcola 0:f1d3878b8dd9 64
vpcola 0:f1d3878b8dd9 65
vpcola 0:f1d3878b8dd9 66 /**
vpcola 0:f1d3878b8dd9 67 * @defgroup General_Private_Defines General Private Defines
vpcola 0:f1d3878b8dd9 68 * @{
vpcola 0:f1d3878b8dd9 69 */
vpcola 0:f1d3878b8dd9 70
vpcola 0:f1d3878b8dd9 71 /**
vpcola 0:f1d3878b8dd9 72 *@}
vpcola 0:f1d3878b8dd9 73 */
vpcola 0:f1d3878b8dd9 74
vpcola 0:f1d3878b8dd9 75
vpcola 0:f1d3878b8dd9 76 /**
vpcola 0:f1d3878b8dd9 77 * @defgroup General_Private_Macros General Private Macros
vpcola 0:f1d3878b8dd9 78 * @{
vpcola 0:f1d3878b8dd9 79 */
vpcola 0:f1d3878b8dd9 80
vpcola 0:f1d3878b8dd9 81 /**
vpcola 0:f1d3878b8dd9 82 *@}
vpcola 0:f1d3878b8dd9 83 */
vpcola 0:f1d3878b8dd9 84
vpcola 0:f1d3878b8dd9 85
vpcola 0:f1d3878b8dd9 86 /**
vpcola 0:f1d3878b8dd9 87 * @defgroup General_Private_Variables General Private Variables
vpcola 0:f1d3878b8dd9 88 * @{
vpcola 0:f1d3878b8dd9 89 */
vpcola 0:f1d3878b8dd9 90
vpcola 0:f1d3878b8dd9 91
vpcola 0:f1d3878b8dd9 92 /**
vpcola 0:f1d3878b8dd9 93 *@}
vpcola 0:f1d3878b8dd9 94 */
vpcola 0:f1d3878b8dd9 95
vpcola 0:f1d3878b8dd9 96
vpcola 0:f1d3878b8dd9 97 /**
vpcola 0:f1d3878b8dd9 98 * @defgroup General_Private_FunctionPrototypes General Private Function Prototypes
vpcola 0:f1d3878b8dd9 99 * @{
vpcola 0:f1d3878b8dd9 100 */
vpcola 0:f1d3878b8dd9 101
vpcola 0:f1d3878b8dd9 102 /**
vpcola 0:f1d3878b8dd9 103 *@}
vpcola 0:f1d3878b8dd9 104 */
vpcola 0:f1d3878b8dd9 105
vpcola 0:f1d3878b8dd9 106
vpcola 0:f1d3878b8dd9 107 /**
vpcola 0:f1d3878b8dd9 108 * @defgroup General_Private_Functions General Private Functions
vpcola 0:f1d3878b8dd9 109 * @{
vpcola 0:f1d3878b8dd9 110 */
vpcola 0:f1d3878b8dd9 111
vpcola 0:f1d3878b8dd9 112 /**
vpcola 0:f1d3878b8dd9 113 * @brief Enables or Disables the output of battery level detector.
vpcola 0:f1d3878b8dd9 114 * @param xNewState new state for battery level detector.
vpcola 0:f1d3878b8dd9 115 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 116 * @retval None
vpcola 0:f1d3878b8dd9 117 */
vpcola 0:f1d3878b8dd9 118 void SpiritGeneralBatteryLevel(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 119 {
vpcola 0:f1d3878b8dd9 120 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 121
vpcola 0:f1d3878b8dd9 122 /* Check the parameters */
vpcola 0:f1d3878b8dd9 123 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 124
vpcola 0:f1d3878b8dd9 125 /* Reads the ANA_FUNC_CONF0_BASE register value */
vpcola 0:f1d3878b8dd9 126 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 127
vpcola 0:f1d3878b8dd9 128 /* Build the value to be stored */
vpcola 0:f1d3878b8dd9 129 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 130 {
vpcola 0:f1d3878b8dd9 131 tempRegValue |= BATTERY_LEVEL_MASK;
vpcola 0:f1d3878b8dd9 132 }
vpcola 0:f1d3878b8dd9 133 else
vpcola 0:f1d3878b8dd9 134 {
vpcola 0:f1d3878b8dd9 135 tempRegValue &= ~BATTERY_LEVEL_MASK;
vpcola 0:f1d3878b8dd9 136 }
vpcola 0:f1d3878b8dd9 137
vpcola 0:f1d3878b8dd9 138 /* Writes the new value */
vpcola 0:f1d3878b8dd9 139 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 140
vpcola 0:f1d3878b8dd9 141 }
vpcola 0:f1d3878b8dd9 142
vpcola 0:f1d3878b8dd9 143
vpcola 0:f1d3878b8dd9 144 /**
vpcola 0:f1d3878b8dd9 145 * @brief Sets the battery level.
vpcola 0:f1d3878b8dd9 146 * @param xBatteryLevel new state for battery level.
vpcola 0:f1d3878b8dd9 147 * This parameter can be a value of @ref BatteryLevel.
vpcola 0:f1d3878b8dd9 148 * @retval None.
vpcola 0:f1d3878b8dd9 149 */
vpcola 0:f1d3878b8dd9 150 void SpiritGeneralSetBatteryLevel(BatteryLevel xBatteryLevel)
vpcola 0:f1d3878b8dd9 151 {
vpcola 0:f1d3878b8dd9 152 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 153
vpcola 0:f1d3878b8dd9 154 /* Check the parameters */
vpcola 0:f1d3878b8dd9 155 s_assert_param(IS_BLD_LVL(xBatteryLevel));
vpcola 0:f1d3878b8dd9 156
vpcola 0:f1d3878b8dd9 157 /* Reads the ANA_FUNC_CONF1_BASE register value */
vpcola 0:f1d3878b8dd9 158 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 159
vpcola 0:f1d3878b8dd9 160 /* Build the value to be stored */
vpcola 0:f1d3878b8dd9 161 tempRegValue &= ~ANA_FUNC_CONF1_SET_BLD_LVL_MASK;
vpcola 0:f1d3878b8dd9 162 switch(xBatteryLevel)
vpcola 0:f1d3878b8dd9 163 {
vpcola 0:f1d3878b8dd9 164 case BLD_LVL_2_7_V:
vpcola 0:f1d3878b8dd9 165 tempRegValue |= BLD_LVL_2_7;
vpcola 0:f1d3878b8dd9 166 break;
vpcola 0:f1d3878b8dd9 167 case BLD_LVL_2_5_V:
vpcola 0:f1d3878b8dd9 168 tempRegValue |= BLD_LVL_2_5;
vpcola 0:f1d3878b8dd9 169 break;
vpcola 0:f1d3878b8dd9 170 case BLD_LVL_2_3_V:
vpcola 0:f1d3878b8dd9 171 tempRegValue |= BLD_LVL_2_3;
vpcola 0:f1d3878b8dd9 172 break;
vpcola 0:f1d3878b8dd9 173 case BLD_LVL_2_1_V:
vpcola 0:f1d3878b8dd9 174 tempRegValue |= BLD_LVL_2_1;
vpcola 0:f1d3878b8dd9 175 break;
vpcola 0:f1d3878b8dd9 176 }
vpcola 0:f1d3878b8dd9 177
vpcola 0:f1d3878b8dd9 178 /* Writes the new value */
vpcola 0:f1d3878b8dd9 179 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 180
vpcola 0:f1d3878b8dd9 181 }
vpcola 0:f1d3878b8dd9 182
vpcola 0:f1d3878b8dd9 183
vpcola 0:f1d3878b8dd9 184 /**
vpcola 0:f1d3878b8dd9 185 * @brief Returns the settled battery level.
vpcola 0:f1d3878b8dd9 186 * @param None.
vpcola 0:f1d3878b8dd9 187 * @retval BatteryLevel Settled battery level. This parameter can be a value of @ref BatteryLevel.
vpcola 0:f1d3878b8dd9 188 */
vpcola 0:f1d3878b8dd9 189 BatteryLevel SpiritGeneralGetBatteryLevel(void)
vpcola 0:f1d3878b8dd9 190 {
vpcola 0:f1d3878b8dd9 191 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 192
vpcola 0:f1d3878b8dd9 193 /* Reads the ANA_FUNC_CONF1_BASE register value */
vpcola 0:f1d3878b8dd9 194 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 195
vpcola 0:f1d3878b8dd9 196 /* Mask the battery level field and returns the settled battery level */
vpcola 0:f1d3878b8dd9 197 return ((BatteryLevel)(tempRegValue & ANA_FUNC_CONF1_SET_BLD_LVL_MASK));
vpcola 0:f1d3878b8dd9 198
vpcola 0:f1d3878b8dd9 199 }
vpcola 0:f1d3878b8dd9 200
vpcola 0:f1d3878b8dd9 201
vpcola 0:f1d3878b8dd9 202 /**
vpcola 0:f1d3878b8dd9 203 * @brief Enables or Disables the output of brown out detector.
vpcola 0:f1d3878b8dd9 204 * @param xNewState new state for brown out detector.
vpcola 0:f1d3878b8dd9 205 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 206 * @retval None.
vpcola 0:f1d3878b8dd9 207 */
vpcola 0:f1d3878b8dd9 208 void SpiritGeneralBrownOut(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 209 {
vpcola 0:f1d3878b8dd9 210 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 211
vpcola 0:f1d3878b8dd9 212 /* Check the parameters */
vpcola 0:f1d3878b8dd9 213 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 214
vpcola 0:f1d3878b8dd9 215 /* Reads the ANA_FUNC_CONF0_BASE register value */
vpcola 0:f1d3878b8dd9 216 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 217
vpcola 0:f1d3878b8dd9 218 /* Build the value to be stored */
vpcola 0:f1d3878b8dd9 219 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 220 {
vpcola 0:f1d3878b8dd9 221 tempRegValue |= BROWN_OUT_MASK;
vpcola 0:f1d3878b8dd9 222 }
vpcola 0:f1d3878b8dd9 223 else
vpcola 0:f1d3878b8dd9 224 {
vpcola 0:f1d3878b8dd9 225 tempRegValue &= ~BROWN_OUT_MASK;
vpcola 0:f1d3878b8dd9 226 }
vpcola 0:f1d3878b8dd9 227
vpcola 0:f1d3878b8dd9 228 /* Writes value on register */
vpcola 0:f1d3878b8dd9 229 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 230
vpcola 0:f1d3878b8dd9 231 }
vpcola 0:f1d3878b8dd9 232
vpcola 0:f1d3878b8dd9 233
vpcola 0:f1d3878b8dd9 234 /**
vpcola 0:f1d3878b8dd9 235 * @brief Sets High Power Mode.
vpcola 0:f1d3878b8dd9 236 * @param xNewState new state for High Power Mode.
vpcola 0:f1d3878b8dd9 237 * This parameter can be: S_ENABLE or S_DISABLE.
vpcola 0:f1d3878b8dd9 238 * @retval None.
vpcola 0:f1d3878b8dd9 239 */
vpcola 0:f1d3878b8dd9 240 void SpiritGeneralHighPwr(SpiritFunctionalState xNewState)
vpcola 0:f1d3878b8dd9 241 {
vpcola 0:f1d3878b8dd9 242 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 243
vpcola 0:f1d3878b8dd9 244 /* Check the parameters */
vpcola 0:f1d3878b8dd9 245 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
vpcola 0:f1d3878b8dd9 246
vpcola 0:f1d3878b8dd9 247 /* Reads the ANA_FUNC_CONF0_BASE register value */
vpcola 0:f1d3878b8dd9 248 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 249
vpcola 0:f1d3878b8dd9 250 /* Build the value to write */
vpcola 0:f1d3878b8dd9 251 if(xNewState == S_ENABLE)
vpcola 0:f1d3878b8dd9 252 {
vpcola 0:f1d3878b8dd9 253 tempRegValue |= HIGH_POWER_MODE_MASK;
vpcola 0:f1d3878b8dd9 254 }
vpcola 0:f1d3878b8dd9 255 else
vpcola 0:f1d3878b8dd9 256 {
vpcola 0:f1d3878b8dd9 257 tempRegValue &= ~HIGH_POWER_MODE_MASK;
vpcola 0:f1d3878b8dd9 258 }
vpcola 0:f1d3878b8dd9 259
vpcola 0:f1d3878b8dd9 260 /* Writes the new value on register */
vpcola 0:f1d3878b8dd9 261 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 262
vpcola 0:f1d3878b8dd9 263 }
vpcola 0:f1d3878b8dd9 264
vpcola 0:f1d3878b8dd9 265
vpcola 0:f1d3878b8dd9 266 /**
vpcola 0:f1d3878b8dd9 267 * @brief Sets External Reference.
vpcola 0:f1d3878b8dd9 268 * @param xExtMode new state for the external reference.
vpcola 0:f1d3878b8dd9 269 * This parameter can be: MODE_EXT_XO or MODE_EXT_XIN.
vpcola 0:f1d3878b8dd9 270 * @retval None.
vpcola 0:f1d3878b8dd9 271 */
vpcola 0:f1d3878b8dd9 272 void SpiritGeneralSetExtRef(ModeExtRef xExtMode)
vpcola 0:f1d3878b8dd9 273 {
vpcola 0:f1d3878b8dd9 274 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 275
vpcola 0:f1d3878b8dd9 276 /* Check the parameters */
vpcola 0:f1d3878b8dd9 277 s_assert_param(IS_MODE_EXT(xExtMode));
vpcola 0:f1d3878b8dd9 278
vpcola 0:f1d3878b8dd9 279 /* Reads the ANA_FUNC_CONF0_BASE register value */
vpcola 0:f1d3878b8dd9 280 SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 281
vpcola 0:f1d3878b8dd9 282 /* Build the value to write */
vpcola 0:f1d3878b8dd9 283 if(xExtMode == MODE_EXT_XO)
vpcola 0:f1d3878b8dd9 284 {
vpcola 0:f1d3878b8dd9 285 tempRegValue &= ~EXT_REF_MASK;
vpcola 0:f1d3878b8dd9 286 }
vpcola 0:f1d3878b8dd9 287 else
vpcola 0:f1d3878b8dd9 288 {
vpcola 0:f1d3878b8dd9 289 tempRegValue |= EXT_REF_MASK;
vpcola 0:f1d3878b8dd9 290 }
vpcola 0:f1d3878b8dd9 291
vpcola 0:f1d3878b8dd9 292 /* Writes value on register */
vpcola 0:f1d3878b8dd9 293 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 294
vpcola 0:f1d3878b8dd9 295 }
vpcola 0:f1d3878b8dd9 296
vpcola 0:f1d3878b8dd9 297
vpcola 0:f1d3878b8dd9 298 /**
vpcola 0:f1d3878b8dd9 299 * @brief Returns External Reference.
vpcola 0:f1d3878b8dd9 300 * @param None.
vpcola 0:f1d3878b8dd9 301 * @retval ModeExtRef Settled external reference.
vpcola 0:f1d3878b8dd9 302 * This parameter can be: MODE_EXT_XO or MODE_EXT_XIN.
vpcola 0:f1d3878b8dd9 303 */
vpcola 0:f1d3878b8dd9 304 ModeExtRef SpiritGeneralGetExtRef(void)
vpcola 0:f1d3878b8dd9 305 {
vpcola 0:f1d3878b8dd9 306 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 307
vpcola 0:f1d3878b8dd9 308 /* Reads the ANA_FUNC_CONF0_BASE register value and return the result */
vpcola 0:f1d3878b8dd9 309 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 310
vpcola 0:f1d3878b8dd9 311 /* Mask the EXT_REF field field and returns the settled reference signal */
vpcola 0:f1d3878b8dd9 312 return ((ModeExtRef)((tempRegValue & 0x10)>>4));
vpcola 0:f1d3878b8dd9 313
vpcola 0:f1d3878b8dd9 314 }
vpcola 0:f1d3878b8dd9 315
vpcola 0:f1d3878b8dd9 316
vpcola 0:f1d3878b8dd9 317 /**
vpcola 0:f1d3878b8dd9 318 * @brief Sets XO gm at startup.
vpcola 0:f1d3878b8dd9 319 * @param xGm transconductance value of XO at startup.
vpcola 0:f1d3878b8dd9 320 * This parameter can be a value of @ref GmConf.
vpcola 0:f1d3878b8dd9 321 * @retval None.
vpcola 0:f1d3878b8dd9 322 */
vpcola 0:f1d3878b8dd9 323 void SpiritGeneralSetXoGm(GmConf xGm)
vpcola 0:f1d3878b8dd9 324 {
vpcola 0:f1d3878b8dd9 325 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 326
vpcola 0:f1d3878b8dd9 327 /* Check the parameters */
vpcola 0:f1d3878b8dd9 328 s_assert_param(IS_GM_CONF(xGm));
vpcola 0:f1d3878b8dd9 329
vpcola 0:f1d3878b8dd9 330 /* Reads the ANA_FUNC_CONF1_BASE register value */
vpcola 0:f1d3878b8dd9 331 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 332
vpcola 0:f1d3878b8dd9 333 /* Build the value to write */
vpcola 0:f1d3878b8dd9 334 tempRegValue &= ~ANA_FUNC_CONF1_GMCONF_MASK;
vpcola 0:f1d3878b8dd9 335 switch(xGm)
vpcola 0:f1d3878b8dd9 336 {
vpcola 0:f1d3878b8dd9 337 case GM_SU_13_2:
vpcola 0:f1d3878b8dd9 338 tempRegValue |= GM_13_2;
vpcola 0:f1d3878b8dd9 339 break;
vpcola 0:f1d3878b8dd9 340 case GM_SU_18_2:
vpcola 0:f1d3878b8dd9 341 tempRegValue |= GM_18_2;
vpcola 0:f1d3878b8dd9 342 break;
vpcola 0:f1d3878b8dd9 343 case GM_SU_21_5:
vpcola 0:f1d3878b8dd9 344 tempRegValue |= GM_21_5;
vpcola 0:f1d3878b8dd9 345 break;
vpcola 0:f1d3878b8dd9 346 case GM_SU_25_6:
vpcola 0:f1d3878b8dd9 347 tempRegValue |= GM_25_6;
vpcola 0:f1d3878b8dd9 348 break;
vpcola 0:f1d3878b8dd9 349 case GM_SU_28_8:
vpcola 0:f1d3878b8dd9 350 tempRegValue |= GM_28_8;
vpcola 0:f1d3878b8dd9 351 break;
vpcola 0:f1d3878b8dd9 352 case GM_SU_33_9:
vpcola 0:f1d3878b8dd9 353 tempRegValue |= GM_33_9;
vpcola 0:f1d3878b8dd9 354 break;
vpcola 0:f1d3878b8dd9 355 case GM_SU_38_5:
vpcola 0:f1d3878b8dd9 356 tempRegValue |= GM_38_5;
vpcola 0:f1d3878b8dd9 357 break;
vpcola 0:f1d3878b8dd9 358 case GM_SU_43_0:
vpcola 0:f1d3878b8dd9 359 tempRegValue |= GM_43_0;
vpcola 0:f1d3878b8dd9 360 break;
vpcola 0:f1d3878b8dd9 361 }
vpcola 0:f1d3878b8dd9 362
vpcola 0:f1d3878b8dd9 363 /* Writes new value on register */
vpcola 0:f1d3878b8dd9 364 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 365
vpcola 0:f1d3878b8dd9 366 }
vpcola 0:f1d3878b8dd9 367
vpcola 0:f1d3878b8dd9 368
vpcola 0:f1d3878b8dd9 369 /**
vpcola 0:f1d3878b8dd9 370 * @brief Returns the configured XO gm at startup.
vpcola 0:f1d3878b8dd9 371 * @param None.
vpcola 0:f1d3878b8dd9 372 * @retval GmConf Settled XO gm. This parameter can be a value of @ref GmConf.
vpcola 0:f1d3878b8dd9 373 */
vpcola 0:f1d3878b8dd9 374 GmConf SpiritGeneralGetXoGm(void)
vpcola 0:f1d3878b8dd9 375 {
vpcola 0:f1d3878b8dd9 376 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 377
vpcola 0:f1d3878b8dd9 378 /* Reads the ANA_FUNC_CONF1_BASE register value */
vpcola 0:f1d3878b8dd9 379 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 380
vpcola 0:f1d3878b8dd9 381 /* Mask the GM_CONF field field and returns the settled transconductance of the XO at startup */
vpcola 0:f1d3878b8dd9 382 return ((GmConf)((tempRegValue & 0x1C)>>2));
vpcola 0:f1d3878b8dd9 383
vpcola 0:f1d3878b8dd9 384 }
vpcola 0:f1d3878b8dd9 385
vpcola 0:f1d3878b8dd9 386
vpcola 0:f1d3878b8dd9 387 /**
vpcola 0:f1d3878b8dd9 388 * @brief Returns the settled packet format.
vpcola 0:f1d3878b8dd9 389 * @param None.
vpcola 0:f1d3878b8dd9 390 * @retval PacketType Settled packet type. This parameter can be a value of @ref PacketType.
vpcola 0:f1d3878b8dd9 391 */
vpcola 0:f1d3878b8dd9 392 PacketType SpiritGeneralGetPktType(void)
vpcola 0:f1d3878b8dd9 393 {
vpcola 0:f1d3878b8dd9 394 uint8_t tempRegValue;
vpcola 0:f1d3878b8dd9 395
vpcola 0:f1d3878b8dd9 396 /* Reads the PROTOCOL1 register */
vpcola 0:f1d3878b8dd9 397 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue);
vpcola 0:f1d3878b8dd9 398
vpcola 0:f1d3878b8dd9 399 /* cast and return value */
vpcola 0:f1d3878b8dd9 400 return (PacketType)(tempRegValue>>6);
vpcola 0:f1d3878b8dd9 401
vpcola 0:f1d3878b8dd9 402 }
vpcola 0:f1d3878b8dd9 403
vpcola 0:f1d3878b8dd9 404
vpcola 0:f1d3878b8dd9 405
vpcola 0:f1d3878b8dd9 406 /**
vpcola 0:f1d3878b8dd9 407 * @brief Returns device part number.
vpcola 0:f1d3878b8dd9 408 * @param None.
vpcola 0:f1d3878b8dd9 409 * @retval uint16_t Device part number.
vpcola 0:f1d3878b8dd9 410 */
vpcola 0:f1d3878b8dd9 411 uint16_t SpiritGeneralGetDevicePartNumber(void)
vpcola 0:f1d3878b8dd9 412 {
vpcola 0:f1d3878b8dd9 413 uint8_t tempRegValue[2];
vpcola 0:f1d3878b8dd9 414
vpcola 0:f1d3878b8dd9 415 /* Reads the register value containing the device part number */
vpcola 0:f1d3878b8dd9 416 g_xStatus = SpiritSpiReadRegisters(DEVICE_INFO1_PARTNUM, 2, tempRegValue);
vpcola 0:f1d3878b8dd9 417
vpcola 0:f1d3878b8dd9 418 return ((((uint16_t)tempRegValue[0])<<8) | ((uint16_t)tempRegValue[1]));
vpcola 0:f1d3878b8dd9 419
vpcola 0:f1d3878b8dd9 420 }
vpcola 0:f1d3878b8dd9 421
vpcola 0:f1d3878b8dd9 422 /**
vpcola 0:f1d3878b8dd9 423 * @brief Returns SPIRIT RF board version.
vpcola 0:f1d3878b8dd9 424 * @param None.
vpcola 0:f1d3878b8dd9 425 * @retval SPIRIT RF board version: 0x30 is the only admitted value
vpcola 0:f1d3878b8dd9 426 */
vpcola 0:f1d3878b8dd9 427 uint8_t SpiritGeneralGetSpiritVersion(void)
vpcola 0:f1d3878b8dd9 428 {
vpcola 0:f1d3878b8dd9 429 uint8_t ver;
vpcola 0:f1d3878b8dd9 430 SpiritSpiReadRegisters(DEVICE_INFO0_VERSION, 1, &ver);
vpcola 0:f1d3878b8dd9 431 return ver;
vpcola 0:f1d3878b8dd9 432 }
vpcola 0:f1d3878b8dd9 433
vpcola 0:f1d3878b8dd9 434 /**
vpcola 0:f1d3878b8dd9 435 *@}
vpcola 0:f1d3878b8dd9 436 */
vpcola 0:f1d3878b8dd9 437
vpcola 0:f1d3878b8dd9 438
vpcola 0:f1d3878b8dd9 439 /**
vpcola 0:f1d3878b8dd9 440 *@}
vpcola 0:f1d3878b8dd9 441 */
vpcola 0:f1d3878b8dd9 442
vpcola 0:f1d3878b8dd9 443
vpcola 0:f1d3878b8dd9 444 /**
vpcola 0:f1d3878b8dd9 445 *@}
vpcola 0:f1d3878b8dd9 446 */
vpcola 0:f1d3878b8dd9 447
vpcola 0:f1d3878b8dd9 448
vpcola 0:f1d3878b8dd9 449 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/