Vergil Cola
/
MQTTGateway2
Fork of my original MQTTGateway
Embed:
(wiki syntax)
Show/hide line numbers
SPIRIT_General.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file SPIRIT_General.c 00004 * @author VMA division - AMS 00005 * @version 3.2.2 00006 * @date 08-July-2015 00007 * @brief Configuration and management of SPIRIT General functionalities. 00008 * @details 00009 * 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 #include "SPIRIT_General.h" 00041 #include "MCU_Interface.h" 00042 00043 00044 /** 00045 * @addtogroup SPIRIT_Libraries 00046 * @{ 00047 */ 00048 00049 00050 /** 00051 * @addtogroup SPIRIT_General 00052 * @{ 00053 */ 00054 00055 00056 /** 00057 * @defgroup General_Private_TypesDefinitions General Private Types Definitions 00058 * @{ 00059 */ 00060 00061 /** 00062 *@} 00063 */ 00064 00065 00066 /** 00067 * @defgroup General_Private_Defines General Private Defines 00068 * @{ 00069 */ 00070 00071 /** 00072 *@} 00073 */ 00074 00075 00076 /** 00077 * @defgroup General_Private_Macros General Private Macros 00078 * @{ 00079 */ 00080 00081 /** 00082 *@} 00083 */ 00084 00085 00086 /** 00087 * @defgroup General_Private_Variables General Private Variables 00088 * @{ 00089 */ 00090 00091 00092 /** 00093 *@} 00094 */ 00095 00096 00097 /** 00098 * @defgroup General_Private_FunctionPrototypes General Private Function Prototypes 00099 * @{ 00100 */ 00101 00102 /** 00103 *@} 00104 */ 00105 00106 00107 /** 00108 * @defgroup General_Private_Functions General Private Functions 00109 * @{ 00110 */ 00111 00112 /** 00113 * @brief Enables or Disables the output of battery level detector. 00114 * @param xNewState new state for battery level detector. 00115 * This parameter can be: S_ENABLE or S_DISABLE. 00116 * @retval None 00117 */ 00118 void SpiritGeneralBatteryLevel(SpiritFunctionalState xNewState) 00119 { 00120 uint8_t tempRegValue; 00121 00122 /* Check the parameters */ 00123 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00124 00125 /* Reads the ANA_FUNC_CONF0_BASE register value */ 00126 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00127 00128 /* Build the value to be stored */ 00129 if(xNewState == S_ENABLE) 00130 { 00131 tempRegValue |= BATTERY_LEVEL_MASK; 00132 } 00133 else 00134 { 00135 tempRegValue &= ~BATTERY_LEVEL_MASK; 00136 } 00137 00138 /* Writes the new value */ 00139 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00140 00141 } 00142 00143 00144 /** 00145 * @brief Sets the battery level. 00146 * @param xBatteryLevel new state for battery level. 00147 * This parameter can be a value of @ref BatteryLevel. 00148 * @retval None. 00149 */ 00150 void SpiritGeneralSetBatteryLevel(BatteryLevel xBatteryLevel) 00151 { 00152 uint8_t tempRegValue; 00153 00154 /* Check the parameters */ 00155 s_assert_param(IS_BLD_LVL(xBatteryLevel)); 00156 00157 /* Reads the ANA_FUNC_CONF1_BASE register value */ 00158 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue); 00159 00160 /* Build the value to be stored */ 00161 tempRegValue &= ~ANA_FUNC_CONF1_SET_BLD_LVL_MASK; 00162 switch(xBatteryLevel) 00163 { 00164 case BLD_LVL_2_7_V: 00165 tempRegValue |= BLD_LVL_2_7; 00166 break; 00167 case BLD_LVL_2_5_V: 00168 tempRegValue |= BLD_LVL_2_5; 00169 break; 00170 case BLD_LVL_2_3_V: 00171 tempRegValue |= BLD_LVL_2_3; 00172 break; 00173 case BLD_LVL_2_1_V: 00174 tempRegValue |= BLD_LVL_2_1; 00175 break; 00176 } 00177 00178 /* Writes the new value */ 00179 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue); 00180 00181 } 00182 00183 00184 /** 00185 * @brief Returns the settled battery level. 00186 * @param None. 00187 * @retval BatteryLevel Settled battery level. This parameter can be a value of @ref BatteryLevel. 00188 */ 00189 BatteryLevel SpiritGeneralGetBatteryLevel(void) 00190 { 00191 uint8_t tempRegValue; 00192 00193 /* Reads the ANA_FUNC_CONF1_BASE register value */ 00194 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue); 00195 00196 /* Mask the battery level field and returns the settled battery level */ 00197 return ((BatteryLevel)(tempRegValue & ANA_FUNC_CONF1_SET_BLD_LVL_MASK)); 00198 00199 } 00200 00201 00202 /** 00203 * @brief Enables or Disables the output of brown out detector. 00204 * @param xNewState new state for brown out detector. 00205 * This parameter can be: S_ENABLE or S_DISABLE. 00206 * @retval None. 00207 */ 00208 void SpiritGeneralBrownOut(SpiritFunctionalState xNewState) 00209 { 00210 uint8_t tempRegValue; 00211 00212 /* Check the parameters */ 00213 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00214 00215 /* Reads the ANA_FUNC_CONF0_BASE register value */ 00216 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00217 00218 /* Build the value to be stored */ 00219 if(xNewState == S_ENABLE) 00220 { 00221 tempRegValue |= BROWN_OUT_MASK; 00222 } 00223 else 00224 { 00225 tempRegValue &= ~BROWN_OUT_MASK; 00226 } 00227 00228 /* Writes value on register */ 00229 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00230 00231 } 00232 00233 00234 /** 00235 * @brief Sets High Power Mode. 00236 * @param xNewState new state for High Power Mode. 00237 * This parameter can be: S_ENABLE or S_DISABLE. 00238 * @retval None. 00239 */ 00240 void SpiritGeneralHighPwr(SpiritFunctionalState xNewState) 00241 { 00242 uint8_t tempRegValue; 00243 00244 /* Check the parameters */ 00245 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00246 00247 /* Reads the ANA_FUNC_CONF0_BASE register value */ 00248 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00249 00250 /* Build the value to write */ 00251 if(xNewState == S_ENABLE) 00252 { 00253 tempRegValue |= HIGH_POWER_MODE_MASK; 00254 } 00255 else 00256 { 00257 tempRegValue &= ~HIGH_POWER_MODE_MASK; 00258 } 00259 00260 /* Writes the new value on register */ 00261 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00262 00263 } 00264 00265 00266 /** 00267 * @brief Sets External Reference. 00268 * @param xExtMode new state for the external reference. 00269 * This parameter can be: MODE_EXT_XO or MODE_EXT_XIN. 00270 * @retval None. 00271 */ 00272 void SpiritGeneralSetExtRef(ModeExtRef xExtMode) 00273 { 00274 uint8_t tempRegValue; 00275 00276 /* Check the parameters */ 00277 s_assert_param(IS_MODE_EXT(xExtMode)); 00278 00279 /* Reads the ANA_FUNC_CONF0_BASE register value */ 00280 SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00281 00282 /* Build the value to write */ 00283 if(xExtMode == MODE_EXT_XO) 00284 { 00285 tempRegValue &= ~EXT_REF_MASK; 00286 } 00287 else 00288 { 00289 tempRegValue |= EXT_REF_MASK; 00290 } 00291 00292 /* Writes value on register */ 00293 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00294 00295 } 00296 00297 00298 /** 00299 * @brief Returns External Reference. 00300 * @param None. 00301 * @retval ModeExtRef Settled external reference. 00302 * This parameter can be: MODE_EXT_XO or MODE_EXT_XIN. 00303 */ 00304 ModeExtRef SpiritGeneralGetExtRef(void) 00305 { 00306 uint8_t tempRegValue; 00307 00308 /* Reads the ANA_FUNC_CONF0_BASE register value and return the result */ 00309 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00310 00311 /* Mask the EXT_REF field field and returns the settled reference signal */ 00312 return ((ModeExtRef)((tempRegValue & 0x10)>>4)); 00313 00314 } 00315 00316 00317 /** 00318 * @brief Sets XO gm at startup. 00319 * @param xGm transconductance value of XO at startup. 00320 * This parameter can be a value of @ref GmConf. 00321 * @retval None. 00322 */ 00323 void SpiritGeneralSetXoGm(GmConf xGm) 00324 { 00325 uint8_t tempRegValue; 00326 00327 /* Check the parameters */ 00328 s_assert_param(IS_GM_CONF(xGm)); 00329 00330 /* Reads the ANA_FUNC_CONF1_BASE register value */ 00331 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue); 00332 00333 /* Build the value to write */ 00334 tempRegValue &= ~ANA_FUNC_CONF1_GMCONF_MASK; 00335 switch(xGm) 00336 { 00337 case GM_SU_13_2: 00338 tempRegValue |= GM_13_2; 00339 break; 00340 case GM_SU_18_2: 00341 tempRegValue |= GM_18_2; 00342 break; 00343 case GM_SU_21_5: 00344 tempRegValue |= GM_21_5; 00345 break; 00346 case GM_SU_25_6: 00347 tempRegValue |= GM_25_6; 00348 break; 00349 case GM_SU_28_8: 00350 tempRegValue |= GM_28_8; 00351 break; 00352 case GM_SU_33_9: 00353 tempRegValue |= GM_33_9; 00354 break; 00355 case GM_SU_38_5: 00356 tempRegValue |= GM_38_5; 00357 break; 00358 case GM_SU_43_0: 00359 tempRegValue |= GM_43_0; 00360 break; 00361 } 00362 00363 /* Writes new value on register */ 00364 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue); 00365 00366 } 00367 00368 00369 /** 00370 * @brief Returns the configured XO gm at startup. 00371 * @param None. 00372 * @retval GmConf Settled XO gm. This parameter can be a value of @ref GmConf. 00373 */ 00374 GmConf SpiritGeneralGetXoGm(void) 00375 { 00376 uint8_t tempRegValue; 00377 00378 /* Reads the ANA_FUNC_CONF1_BASE register value */ 00379 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF1_BASE, 1, &tempRegValue); 00380 00381 /* Mask the GM_CONF field field and returns the settled transconductance of the XO at startup */ 00382 return ((GmConf)((tempRegValue & 0x1C)>>2)); 00383 00384 } 00385 00386 00387 /** 00388 * @brief Returns the settled packet format. 00389 * @param None. 00390 * @retval PacketType Settled packet type. This parameter can be a value of @ref PacketType. 00391 */ 00392 PacketType SpiritGeneralGetPktType(void) 00393 { 00394 uint8_t tempRegValue; 00395 00396 /* Reads the PROTOCOL1 register */ 00397 g_xStatus = SpiritSpiReadRegisters(PCKTCTRL3_BASE, 1, &tempRegValue); 00398 00399 /* cast and return value */ 00400 return (PacketType)(tempRegValue>>6); 00401 00402 } 00403 00404 00405 00406 /** 00407 * @brief Returns device part number. 00408 * @param None. 00409 * @retval uint16_t Device part number. 00410 */ 00411 uint16_t SpiritGeneralGetDevicePartNumber(void) 00412 { 00413 uint8_t tempRegValue[2]; 00414 00415 /* Reads the register value containing the device part number */ 00416 g_xStatus = SpiritSpiReadRegisters(DEVICE_INFO1_PARTNUM, 2, tempRegValue); 00417 00418 return ((((uint16_t)tempRegValue[0])<<8) | ((uint16_t)tempRegValue[1])); 00419 00420 } 00421 00422 /** 00423 * @brief Returns SPIRIT RF board version. 00424 * @param None. 00425 * @retval SPIRIT RF board version: 0x30 is the only admitted value 00426 */ 00427 uint8_t SpiritGeneralGetSpiritVersion(void) 00428 { 00429 uint8_t ver; 00430 SpiritSpiReadRegisters(DEVICE_INFO0_VERSION, 1, &ver); 00431 return ver; 00432 } 00433 00434 /** 00435 *@} 00436 */ 00437 00438 00439 /** 00440 *@} 00441 */ 00442 00443 00444 /** 00445 *@} 00446 */ 00447 00448 00449 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 18:06:46 by 1.7.2