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