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