Prototype RF driver for STM Sub-1 GHz RF expansion board based on the SPSGRF-868 module for STM32 Nucleo.

Prototype RF Driver for STM Sub-1 GHz RF Expansion Boards based on the SPSGRF-868 and SPSGRF-915 Modules for STM32 Nucleo

Currently supported boards:

Note, in order to use expansion board X-NUCLEO-IDS01A4 in mbed you need to perform the following HW modifications on the board:

  • Unmount resistor R4
  • Mount resistor R7

Furthermore, on some Nucleo development boards (e.g. the NUCLEO_F429ZI), in order to be able to use Ethernet together with these Sub-1 GHz RF expansion boards, you need to compile this driver with macro SPIRIT1_SPI_MOSI=PB_5 defined, while the development board typically requires some HW modification as e.g. described here!

This driver can be used together with the 6LoWPAN stack (a.k.a. Nanostack).

Committer:
Wolfgang Betz
Date:
Thu Oct 13 15:41:39 2016 +0200
Revision:
0:4fb29d9ee571
First compiling version (without warnings)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Wolfgang Betz 0:4fb29d9ee571 1 /**
Wolfgang Betz 0:4fb29d9ee571 2 ******************************************************************************
Wolfgang Betz 0:4fb29d9ee571 3 * @file SPIRIT_Gpio.c
Wolfgang Betz 0:4fb29d9ee571 4 * @author VMA division - AMS
Wolfgang Betz 0:4fb29d9ee571 5 * @version 3.2.2
Wolfgang Betz 0:4fb29d9ee571 6 * @date 08-July-2015
Wolfgang Betz 0:4fb29d9ee571 7 * @brief This file provides all the low level API to manage SPIRIT GPIO.
Wolfgang Betz 0:4fb29d9ee571 8 * @details
Wolfgang Betz 0:4fb29d9ee571 9 *
Wolfgang Betz 0:4fb29d9ee571 10 * @attention
Wolfgang Betz 0:4fb29d9ee571 11 *
Wolfgang Betz 0:4fb29d9ee571 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Wolfgang Betz 0:4fb29d9ee571 13 *
Wolfgang Betz 0:4fb29d9ee571 14 * Redistribution and use in source and binary forms, with or without modification,
Wolfgang Betz 0:4fb29d9ee571 15 * are permitted provided that the following conditions are met:
Wolfgang Betz 0:4fb29d9ee571 16 * 1. Redistributions of source code must retain the above copyright notice,
Wolfgang Betz 0:4fb29d9ee571 17 * this list of conditions and the following disclaimer.
Wolfgang Betz 0:4fb29d9ee571 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Wolfgang Betz 0:4fb29d9ee571 19 * this list of conditions and the following disclaimer in the documentation
Wolfgang Betz 0:4fb29d9ee571 20 * and/or other materials provided with the distribution.
Wolfgang Betz 0:4fb29d9ee571 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Wolfgang Betz 0:4fb29d9ee571 22 * may be used to endorse or promote products derived from this software
Wolfgang Betz 0:4fb29d9ee571 23 * without specific prior written permission.
Wolfgang Betz 0:4fb29d9ee571 24 *
Wolfgang Betz 0:4fb29d9ee571 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Wolfgang Betz 0:4fb29d9ee571 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Wolfgang Betz 0:4fb29d9ee571 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Wolfgang Betz 0:4fb29d9ee571 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Wolfgang Betz 0:4fb29d9ee571 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Wolfgang Betz 0:4fb29d9ee571 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Wolfgang Betz 0:4fb29d9ee571 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Wolfgang Betz 0:4fb29d9ee571 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Wolfgang Betz 0:4fb29d9ee571 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Wolfgang Betz 0:4fb29d9ee571 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wolfgang Betz 0:4fb29d9ee571 35 *
Wolfgang Betz 0:4fb29d9ee571 36 ******************************************************************************
Wolfgang Betz 0:4fb29d9ee571 37 */
Wolfgang Betz 0:4fb29d9ee571 38
Wolfgang Betz 0:4fb29d9ee571 39 /* Includes ------------------------------------------------------------------*/
Wolfgang Betz 0:4fb29d9ee571 40 #include "SPIRIT_Gpio.h"
Wolfgang Betz 0:4fb29d9ee571 41 #include "MCU_Interface.h"
Wolfgang Betz 0:4fb29d9ee571 42
Wolfgang Betz 0:4fb29d9ee571 43
Wolfgang Betz 0:4fb29d9ee571 44 /** @addtogroup SPIRIT_Libraries
Wolfgang Betz 0:4fb29d9ee571 45 * @{
Wolfgang Betz 0:4fb29d9ee571 46 */
Wolfgang Betz 0:4fb29d9ee571 47
Wolfgang Betz 0:4fb29d9ee571 48
Wolfgang Betz 0:4fb29d9ee571 49 /** @addtogroup SPIRIT_Gpio
Wolfgang Betz 0:4fb29d9ee571 50 * @{
Wolfgang Betz 0:4fb29d9ee571 51 */
Wolfgang Betz 0:4fb29d9ee571 52
Wolfgang Betz 0:4fb29d9ee571 53
Wolfgang Betz 0:4fb29d9ee571 54 /** @defgroup Gpio_Private_TypesDefinitions GPIO Private Types Definitions
Wolfgang Betz 0:4fb29d9ee571 55 * @{
Wolfgang Betz 0:4fb29d9ee571 56 */
Wolfgang Betz 0:4fb29d9ee571 57
Wolfgang Betz 0:4fb29d9ee571 58
Wolfgang Betz 0:4fb29d9ee571 59 /**
Wolfgang Betz 0:4fb29d9ee571 60 * @}
Wolfgang Betz 0:4fb29d9ee571 61 */
Wolfgang Betz 0:4fb29d9ee571 62
Wolfgang Betz 0:4fb29d9ee571 63
Wolfgang Betz 0:4fb29d9ee571 64 /** @defgroup Gpio_Private_Defines GPIO Private Defines
Wolfgang Betz 0:4fb29d9ee571 65 * @{
Wolfgang Betz 0:4fb29d9ee571 66 */
Wolfgang Betz 0:4fb29d9ee571 67
Wolfgang Betz 0:4fb29d9ee571 68
Wolfgang Betz 0:4fb29d9ee571 69 /**
Wolfgang Betz 0:4fb29d9ee571 70 * @}
Wolfgang Betz 0:4fb29d9ee571 71 */
Wolfgang Betz 0:4fb29d9ee571 72
Wolfgang Betz 0:4fb29d9ee571 73
Wolfgang Betz 0:4fb29d9ee571 74
Wolfgang Betz 0:4fb29d9ee571 75 /** @defgroup Gpio_Private_Macros GPIO Private Macros
Wolfgang Betz 0:4fb29d9ee571 76 * @{
Wolfgang Betz 0:4fb29d9ee571 77 */
Wolfgang Betz 0:4fb29d9ee571 78
Wolfgang Betz 0:4fb29d9ee571 79
Wolfgang Betz 0:4fb29d9ee571 80 /**
Wolfgang Betz 0:4fb29d9ee571 81 * @}
Wolfgang Betz 0:4fb29d9ee571 82 */
Wolfgang Betz 0:4fb29d9ee571 83
Wolfgang Betz 0:4fb29d9ee571 84
Wolfgang Betz 0:4fb29d9ee571 85
Wolfgang Betz 0:4fb29d9ee571 86 /** @defgroup Gpio_Private_Variables GPIO Private Variables
Wolfgang Betz 0:4fb29d9ee571 87 * @{
Wolfgang Betz 0:4fb29d9ee571 88 */
Wolfgang Betz 0:4fb29d9ee571 89
Wolfgang Betz 0:4fb29d9ee571 90
Wolfgang Betz 0:4fb29d9ee571 91 /**
Wolfgang Betz 0:4fb29d9ee571 92 * @}
Wolfgang Betz 0:4fb29d9ee571 93 */
Wolfgang Betz 0:4fb29d9ee571 94
Wolfgang Betz 0:4fb29d9ee571 95
Wolfgang Betz 0:4fb29d9ee571 96
Wolfgang Betz 0:4fb29d9ee571 97 /** @defgroup Gpio_Private_FunctionPrototypes GPIO Private Function Prototypes
Wolfgang Betz 0:4fb29d9ee571 98 * @{
Wolfgang Betz 0:4fb29d9ee571 99 */
Wolfgang Betz 0:4fb29d9ee571 100
Wolfgang Betz 0:4fb29d9ee571 101
Wolfgang Betz 0:4fb29d9ee571 102 /**
Wolfgang Betz 0:4fb29d9ee571 103 * @}
Wolfgang Betz 0:4fb29d9ee571 104 */
Wolfgang Betz 0:4fb29d9ee571 105
Wolfgang Betz 0:4fb29d9ee571 106
Wolfgang Betz 0:4fb29d9ee571 107
Wolfgang Betz 0:4fb29d9ee571 108 /** @defgroup Gpio_Private_Functions GPIO Private Functions
Wolfgang Betz 0:4fb29d9ee571 109 * @{
Wolfgang Betz 0:4fb29d9ee571 110 */
Wolfgang Betz 0:4fb29d9ee571 111
Wolfgang Betz 0:4fb29d9ee571 112 /**
Wolfgang Betz 0:4fb29d9ee571 113 * @brief Initializes the SPIRIT GPIOx according to the specified
Wolfgang Betz 0:4fb29d9ee571 114 * parameters in the pxGpioInitStruct.
Wolfgang Betz 0:4fb29d9ee571 115 * @param pxGpioInitStruct pointer to a SGpioInit structure that
Wolfgang Betz 0:4fb29d9ee571 116 * contains the configuration information for the specified SPIRIT GPIO.
Wolfgang Betz 0:4fb29d9ee571 117 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 118 */
Wolfgang Betz 0:4fb29d9ee571 119 void SpiritGpioInit(SGpioInit* pxGpioInitStruct)
Wolfgang Betz 0:4fb29d9ee571 120 {
Wolfgang Betz 0:4fb29d9ee571 121 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 122
Wolfgang Betz 0:4fb29d9ee571 123 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 124 s_assert_param(IS_SPIRIT_GPIO(pxGpioInitStruct->xSpiritGpioPin));
Wolfgang Betz 0:4fb29d9ee571 125 s_assert_param(IS_SPIRIT_GPIO_MODE(pxGpioInitStruct->xSpiritGpioMode));
Wolfgang Betz 0:4fb29d9ee571 126 s_assert_param(IS_SPIRIT_GPIO_IO(pxGpioInitStruct->xSpiritGpioIO));
Wolfgang Betz 0:4fb29d9ee571 127
Wolfgang Betz 0:4fb29d9ee571 128 tempRegValue = ((uint8_t)(pxGpioInitStruct->xSpiritGpioMode) | (uint8_t)(pxGpioInitStruct->xSpiritGpioIO));
Wolfgang Betz 0:4fb29d9ee571 129
Wolfgang Betz 0:4fb29d9ee571 130 g_xStatus = SpiritSpiWriteRegisters(pxGpioInitStruct->xSpiritGpioPin, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 131
Wolfgang Betz 0:4fb29d9ee571 132 }
Wolfgang Betz 0:4fb29d9ee571 133
Wolfgang Betz 0:4fb29d9ee571 134
Wolfgang Betz 0:4fb29d9ee571 135 /**
Wolfgang Betz 0:4fb29d9ee571 136 * @brief Enables or Disables the output of temperature sensor on SPIRIT GPIO_0.
Wolfgang Betz 0:4fb29d9ee571 137 * @param xNewState new state for temperature sensor.
Wolfgang Betz 0:4fb29d9ee571 138 * This parameter can be: S_ENABLE or S_DISABLE.
Wolfgang Betz 0:4fb29d9ee571 139 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 140 */
Wolfgang Betz 0:4fb29d9ee571 141 void SpiritGpioTemperatureSensor(SpiritFunctionalState xNewState)
Wolfgang Betz 0:4fb29d9ee571 142 {
Wolfgang Betz 0:4fb29d9ee571 143 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 144 uint8_t gpio0tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 145
Wolfgang Betz 0:4fb29d9ee571 146 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 147 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
Wolfgang Betz 0:4fb29d9ee571 148
Wolfgang Betz 0:4fb29d9ee571 149 /* Reads the ANA_FUNC_CONF0 register and mask the result to enable or disable the
Wolfgang Betz 0:4fb29d9ee571 150 temperature sensor */
Wolfgang Betz 0:4fb29d9ee571 151 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 152 if(xNewState == S_ENABLE)
Wolfgang Betz 0:4fb29d9ee571 153 {
Wolfgang Betz 0:4fb29d9ee571 154 tempRegValue |= TEMPERATURE_SENSOR_MASK;
Wolfgang Betz 0:4fb29d9ee571 155 }
Wolfgang Betz 0:4fb29d9ee571 156 else
Wolfgang Betz 0:4fb29d9ee571 157 {
Wolfgang Betz 0:4fb29d9ee571 158 tempRegValue &= (~TEMPERATURE_SENSOR_MASK);
Wolfgang Betz 0:4fb29d9ee571 159 gpio0tempRegValue = 0x0A; /* Default value */
Wolfgang Betz 0:4fb29d9ee571 160 }
Wolfgang Betz 0:4fb29d9ee571 161 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 162
Wolfgang Betz 0:4fb29d9ee571 163 /* Sets the SPIRIT GPIO_0 according to input request */
Wolfgang Betz 0:4fb29d9ee571 164 g_xStatus = SpiritSpiWriteRegisters(GPIO0_CONF_BASE, 1, &gpio0tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 165
Wolfgang Betz 0:4fb29d9ee571 166 }
Wolfgang Betz 0:4fb29d9ee571 167
Wolfgang Betz 0:4fb29d9ee571 168
Wolfgang Betz 0:4fb29d9ee571 169 /**
Wolfgang Betz 0:4fb29d9ee571 170 * @brief Forces SPIRIT GPIO_x configured as digital output, to VDD or GND.
Wolfgang Betz 0:4fb29d9ee571 171 * @param xGpioX Specifies the GPIO to be configured.
Wolfgang Betz 0:4fb29d9ee571 172 * This parameter can be one of following parameters:
Wolfgang Betz 0:4fb29d9ee571 173 * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0
Wolfgang Betz 0:4fb29d9ee571 174 * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1
Wolfgang Betz 0:4fb29d9ee571 175 * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2
Wolfgang Betz 0:4fb29d9ee571 176 * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3
Wolfgang Betz 0:4fb29d9ee571 177 * @param xLevel Specifies the level.
Wolfgang Betz 0:4fb29d9ee571 178 * This parameter can be: HIGH or LOW.
Wolfgang Betz 0:4fb29d9ee571 179 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 180 */
Wolfgang Betz 0:4fb29d9ee571 181 void SpiritGpioSetLevel(SpiritGpioPin xGpioX, OutputLevel xLevel)
Wolfgang Betz 0:4fb29d9ee571 182 {
Wolfgang Betz 0:4fb29d9ee571 183 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 184
Wolfgang Betz 0:4fb29d9ee571 185 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 186 s_assert_param(IS_SPIRIT_GPIO(xGpioX));
Wolfgang Betz 0:4fb29d9ee571 187 s_assert_param(IS_SPIRIT_GPIO_LEVEL(xLevel));
Wolfgang Betz 0:4fb29d9ee571 188
Wolfgang Betz 0:4fb29d9ee571 189 /* Reads the SPIRIT_GPIOx register and mask the GPIO_SELECT field */
Wolfgang Betz 0:4fb29d9ee571 190 g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 191 tempRegValue &= 0x04;
Wolfgang Betz 0:4fb29d9ee571 192
Wolfgang Betz 0:4fb29d9ee571 193 /* Sets the value of the SPIRIT GPIO register according to the specified level */
Wolfgang Betz 0:4fb29d9ee571 194 if(xLevel == HIGH)
Wolfgang Betz 0:4fb29d9ee571 195 {
Wolfgang Betz 0:4fb29d9ee571 196 tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_VDD | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP;
Wolfgang Betz 0:4fb29d9ee571 197 }
Wolfgang Betz 0:4fb29d9ee571 198 else
Wolfgang Betz 0:4fb29d9ee571 199 {
Wolfgang Betz 0:4fb29d9ee571 200 tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_GND | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP;
Wolfgang Betz 0:4fb29d9ee571 201 }
Wolfgang Betz 0:4fb29d9ee571 202
Wolfgang Betz 0:4fb29d9ee571 203 /* Writes the SPIRIT GPIO register */
Wolfgang Betz 0:4fb29d9ee571 204 g_xStatus = SpiritSpiWriteRegisters(xGpioX, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 205
Wolfgang Betz 0:4fb29d9ee571 206 }
Wolfgang Betz 0:4fb29d9ee571 207
Wolfgang Betz 0:4fb29d9ee571 208
Wolfgang Betz 0:4fb29d9ee571 209 /**
Wolfgang Betz 0:4fb29d9ee571 210 * @brief Returns output value (VDD or GND) of SPIRIT GPIO_x, when it is configured as digital output.
Wolfgang Betz 0:4fb29d9ee571 211 * @param xGpioX Specifies the GPIO to be read.
Wolfgang Betz 0:4fb29d9ee571 212 * This parameter can be one of following parameters:
Wolfgang Betz 0:4fb29d9ee571 213 * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0
Wolfgang Betz 0:4fb29d9ee571 214 * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1
Wolfgang Betz 0:4fb29d9ee571 215 * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2
Wolfgang Betz 0:4fb29d9ee571 216 * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3
Wolfgang Betz 0:4fb29d9ee571 217 * @retval OutputLevel Logical level of selected GPIO configured as digital output.
Wolfgang Betz 0:4fb29d9ee571 218 * This parameter can be: HIGH or LOW.
Wolfgang Betz 0:4fb29d9ee571 219 */
Wolfgang Betz 0:4fb29d9ee571 220 OutputLevel SpiritGpioGetLevel(SpiritGpioPin xGpioX)
Wolfgang Betz 0:4fb29d9ee571 221 {
Wolfgang Betz 0:4fb29d9ee571 222 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 223 OutputLevel level;
Wolfgang Betz 0:4fb29d9ee571 224
Wolfgang Betz 0:4fb29d9ee571 225 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 226 s_assert_param(IS_SPIRIT_GPIO(xGpioX));
Wolfgang Betz 0:4fb29d9ee571 227
Wolfgang Betz 0:4fb29d9ee571 228 /* Reads the SPIRIT_GPIOx register */
Wolfgang Betz 0:4fb29d9ee571 229 g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 230
Wolfgang Betz 0:4fb29d9ee571 231 /* Mask the GPIO_SELECT field and returns the value according */
Wolfgang Betz 0:4fb29d9ee571 232 tempRegValue &= 0xF8;
Wolfgang Betz 0:4fb29d9ee571 233 if(tempRegValue == SPIRIT_GPIO_DIG_OUT_VDD)
Wolfgang Betz 0:4fb29d9ee571 234 {
Wolfgang Betz 0:4fb29d9ee571 235 level = HIGH;
Wolfgang Betz 0:4fb29d9ee571 236 }
Wolfgang Betz 0:4fb29d9ee571 237 else
Wolfgang Betz 0:4fb29d9ee571 238 {
Wolfgang Betz 0:4fb29d9ee571 239 level = LOW;
Wolfgang Betz 0:4fb29d9ee571 240 }
Wolfgang Betz 0:4fb29d9ee571 241
Wolfgang Betz 0:4fb29d9ee571 242 return level;
Wolfgang Betz 0:4fb29d9ee571 243
Wolfgang Betz 0:4fb29d9ee571 244 }
Wolfgang Betz 0:4fb29d9ee571 245
Wolfgang Betz 0:4fb29d9ee571 246
Wolfgang Betz 0:4fb29d9ee571 247 /**
Wolfgang Betz 0:4fb29d9ee571 248 * @brief Enables or Disables the MCU clock output.
Wolfgang Betz 0:4fb29d9ee571 249 * @param xNewState new state for the MCU clock output.
Wolfgang Betz 0:4fb29d9ee571 250 * This parameter can be: S_ENABLE or S_DISABLE.
Wolfgang Betz 0:4fb29d9ee571 251 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 252 */
Wolfgang Betz 0:4fb29d9ee571 253 void SpiritGpioClockOutput(SpiritFunctionalState xNewState)
Wolfgang Betz 0:4fb29d9ee571 254 {
Wolfgang Betz 0:4fb29d9ee571 255 uint8_t tempRegValue;
Wolfgang Betz 0:4fb29d9ee571 256
Wolfgang Betz 0:4fb29d9ee571 257 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 258 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState));
Wolfgang Betz 0:4fb29d9ee571 259
Wolfgang Betz 0:4fb29d9ee571 260 /* Reads the MCU_CK_CONF register and mask the result to enable or disable the clock output */
Wolfgang Betz 0:4fb29d9ee571 261 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 262
Wolfgang Betz 0:4fb29d9ee571 263 if(xNewState)
Wolfgang Betz 0:4fb29d9ee571 264 {
Wolfgang Betz 0:4fb29d9ee571 265 tempRegValue |= MCU_CK_ENABLE;
Wolfgang Betz 0:4fb29d9ee571 266 }
Wolfgang Betz 0:4fb29d9ee571 267 else
Wolfgang Betz 0:4fb29d9ee571 268 {
Wolfgang Betz 0:4fb29d9ee571 269 tempRegValue &= (~MCU_CK_ENABLE);
Wolfgang Betz 0:4fb29d9ee571 270 }
Wolfgang Betz 0:4fb29d9ee571 271
Wolfgang Betz 0:4fb29d9ee571 272 /* Writes the MCU_CK_CONF register */
Wolfgang Betz 0:4fb29d9ee571 273 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 274
Wolfgang Betz 0:4fb29d9ee571 275 }
Wolfgang Betz 0:4fb29d9ee571 276
Wolfgang Betz 0:4fb29d9ee571 277
Wolfgang Betz 0:4fb29d9ee571 278 /**
Wolfgang Betz 0:4fb29d9ee571 279 * @brief Initializes the SPIRIT Clock Output according to the specified
Wolfgang Betz 0:4fb29d9ee571 280 * parameters in the xClockOutputInitStruct.
Wolfgang Betz 0:4fb29d9ee571 281 * @param pxClockOutputInitStruct pointer to a ClockOutputInit structure that
Wolfgang Betz 0:4fb29d9ee571 282 * contains the configuration information for the SPIRIT Clock Output.
Wolfgang Betz 0:4fb29d9ee571 283 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 284 * @note The function SpiritGpioClockOutput() must be called in order to enable
Wolfgang Betz 0:4fb29d9ee571 285 * or disable the MCU clock dividers.
Wolfgang Betz 0:4fb29d9ee571 286 */
Wolfgang Betz 0:4fb29d9ee571 287 void SpiritGpioClockOutputInit(ClockOutputInit* pxClockOutputInitStruct)
Wolfgang Betz 0:4fb29d9ee571 288 {
Wolfgang Betz 0:4fb29d9ee571 289 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 290
Wolfgang Betz 0:4fb29d9ee571 291 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 292 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(pxClockOutputInitStruct->xClockOutputXOPrescaler));
Wolfgang Betz 0:4fb29d9ee571 293 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(pxClockOutputInitStruct->xClockOutputRCOPrescaler));
Wolfgang Betz 0:4fb29d9ee571 294 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(pxClockOutputInitStruct->xExtraClockCycles));
Wolfgang Betz 0:4fb29d9ee571 295
Wolfgang Betz 0:4fb29d9ee571 296 /* Calculates the register value to write according to the specified configuration */
Wolfgang Betz 0:4fb29d9ee571 297 tempRegValue = ((uint8_t)(pxClockOutputInitStruct->xClockOutputXOPrescaler) | (uint8_t)(pxClockOutputInitStruct->xClockOutputRCOPrescaler) | \
Wolfgang Betz 0:4fb29d9ee571 298 (uint8_t)(pxClockOutputInitStruct->xExtraClockCycles));
Wolfgang Betz 0:4fb29d9ee571 299
Wolfgang Betz 0:4fb29d9ee571 300 /* Writes the MCU_CLOCK register */
Wolfgang Betz 0:4fb29d9ee571 301 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 302
Wolfgang Betz 0:4fb29d9ee571 303 }
Wolfgang Betz 0:4fb29d9ee571 304
Wolfgang Betz 0:4fb29d9ee571 305
Wolfgang Betz 0:4fb29d9ee571 306 /**
Wolfgang Betz 0:4fb29d9ee571 307 * @brief Sets the XO ratio as clock output.
Wolfgang Betz 0:4fb29d9ee571 308 * @param xXOPrescaler the XO prescaler to be used as clock output.
Wolfgang Betz 0:4fb29d9ee571 309 * This parameter can be any value of @ref ClockOutputXOPrescaler .
Wolfgang Betz 0:4fb29d9ee571 310 * @retval None
Wolfgang Betz 0:4fb29d9ee571 311 */
Wolfgang Betz 0:4fb29d9ee571 312 void SpiritGpioSetXOPrescaler(ClockOutputXOPrescaler xXOPrescaler)
Wolfgang Betz 0:4fb29d9ee571 313 {
Wolfgang Betz 0:4fb29d9ee571 314 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 315
Wolfgang Betz 0:4fb29d9ee571 316 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 317 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(xXOPrescaler));
Wolfgang Betz 0:4fb29d9ee571 318
Wolfgang Betz 0:4fb29d9ee571 319 /* Reads the MCU_CLK_CONFIG register */
Wolfgang Betz 0:4fb29d9ee571 320 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 321
Wolfgang Betz 0:4fb29d9ee571 322 /* Mask the XO_RATIO field and writes the new value */
Wolfgang Betz 0:4fb29d9ee571 323 tempRegValue &= 0x61;
Wolfgang Betz 0:4fb29d9ee571 324 tempRegValue |= ((uint8_t)xXOPrescaler);
Wolfgang Betz 0:4fb29d9ee571 325
Wolfgang Betz 0:4fb29d9ee571 326 /* Writes the new XO prescaler in the MCU_CLOCK register */
Wolfgang Betz 0:4fb29d9ee571 327 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 328
Wolfgang Betz 0:4fb29d9ee571 329 }
Wolfgang Betz 0:4fb29d9ee571 330
Wolfgang Betz 0:4fb29d9ee571 331
Wolfgang Betz 0:4fb29d9ee571 332 /**
Wolfgang Betz 0:4fb29d9ee571 333 * @brief Returns the settled XO prescaler as clock output.
Wolfgang Betz 0:4fb29d9ee571 334 * @param None.
Wolfgang Betz 0:4fb29d9ee571 335 * @retval ClockOutputXOPrescaler Settled XO prescaler used for clock
Wolfgang Betz 0:4fb29d9ee571 336 * output. This parameter can be a value of @ref ClockOutputXOPrescaler .
Wolfgang Betz 0:4fb29d9ee571 337 */
Wolfgang Betz 0:4fb29d9ee571 338 ClockOutputXOPrescaler SpiritGpioGetXOPrescaler(void)
Wolfgang Betz 0:4fb29d9ee571 339 {
Wolfgang Betz 0:4fb29d9ee571 340 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 341
Wolfgang Betz 0:4fb29d9ee571 342 /* Reads the MCU_CLK_CONFIG register */
Wolfgang Betz 0:4fb29d9ee571 343 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 344
Wolfgang Betz 0:4fb29d9ee571 345 /* Mask the XO_RATIO field and return the value */
Wolfgang Betz 0:4fb29d9ee571 346 return ((ClockOutputXOPrescaler)(tempRegValue & 0x1E));
Wolfgang Betz 0:4fb29d9ee571 347
Wolfgang Betz 0:4fb29d9ee571 348 }
Wolfgang Betz 0:4fb29d9ee571 349
Wolfgang Betz 0:4fb29d9ee571 350
Wolfgang Betz 0:4fb29d9ee571 351 /**
Wolfgang Betz 0:4fb29d9ee571 352 * @brief Sets the RCO ratio as clock output
Wolfgang Betz 0:4fb29d9ee571 353 * @param xRCOPrescaler the RCO prescaler to be used as clock output.
Wolfgang Betz 0:4fb29d9ee571 354 * This parameter can be any value of @ref ClockOutputRCOPrescaler .
Wolfgang Betz 0:4fb29d9ee571 355 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 356 */
Wolfgang Betz 0:4fb29d9ee571 357 void SpiritGpioSetRCOPrescaler(ClockOutputRCOPrescaler xRCOPrescaler)
Wolfgang Betz 0:4fb29d9ee571 358 {
Wolfgang Betz 0:4fb29d9ee571 359 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 360
Wolfgang Betz 0:4fb29d9ee571 361 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 362 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(xRCOPrescaler));
Wolfgang Betz 0:4fb29d9ee571 363
Wolfgang Betz 0:4fb29d9ee571 364 /* Reads the MCU_CLK_CONFIG register */
Wolfgang Betz 0:4fb29d9ee571 365 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 366
Wolfgang Betz 0:4fb29d9ee571 367 /* Mask the RCO_RATIO field and writes the new value */
Wolfgang Betz 0:4fb29d9ee571 368 tempRegValue &= 0xFE;
Wolfgang Betz 0:4fb29d9ee571 369 tempRegValue |= ((uint8_t)xRCOPrescaler);
Wolfgang Betz 0:4fb29d9ee571 370
Wolfgang Betz 0:4fb29d9ee571 371 /* Writes the new RCO prescaler in the MCU_CLOCK register */
Wolfgang Betz 0:4fb29d9ee571 372 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 373
Wolfgang Betz 0:4fb29d9ee571 374 }
Wolfgang Betz 0:4fb29d9ee571 375
Wolfgang Betz 0:4fb29d9ee571 376
Wolfgang Betz 0:4fb29d9ee571 377 /**
Wolfgang Betz 0:4fb29d9ee571 378 * @brief Returns the settled RCO prescaler as clock output.
Wolfgang Betz 0:4fb29d9ee571 379 * @param None.
Wolfgang Betz 0:4fb29d9ee571 380 * @retval ClockOutputRCOPrescaler Settled RCO prescaler used for clock
Wolfgang Betz 0:4fb29d9ee571 381 * output. This parameter can be a value of @ref ClockOutputRCOPrescaler.
Wolfgang Betz 0:4fb29d9ee571 382 */
Wolfgang Betz 0:4fb29d9ee571 383 ClockOutputRCOPrescaler SpiritGpioGetRCOPrescaler(void)
Wolfgang Betz 0:4fb29d9ee571 384 {
Wolfgang Betz 0:4fb29d9ee571 385 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 386
Wolfgang Betz 0:4fb29d9ee571 387 /* Reads the MCU_CLK_CONFIG register */
Wolfgang Betz 0:4fb29d9ee571 388 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 389
Wolfgang Betz 0:4fb29d9ee571 390 /* Mask the RCO_RATIO field and returns the value */
Wolfgang Betz 0:4fb29d9ee571 391 return ((ClockOutputRCOPrescaler)(tempRegValue & 0x01));
Wolfgang Betz 0:4fb29d9ee571 392
Wolfgang Betz 0:4fb29d9ee571 393 }
Wolfgang Betz 0:4fb29d9ee571 394
Wolfgang Betz 0:4fb29d9ee571 395
Wolfgang Betz 0:4fb29d9ee571 396 /**
Wolfgang Betz 0:4fb29d9ee571 397 * @brief Sets the RCO ratio as clock output.
Wolfgang Betz 0:4fb29d9ee571 398 * @param xExtraCycles the number of extra clock cycles provided before switching
Wolfgang Betz 0:4fb29d9ee571 399 * to STANDBY state. This parameter can be any value of @ref ExtraClockCycles .
Wolfgang Betz 0:4fb29d9ee571 400 * @retval None.
Wolfgang Betz 0:4fb29d9ee571 401 */
Wolfgang Betz 0:4fb29d9ee571 402 void SpiritGpioSetExtraClockCycles(ExtraClockCycles xExtraCycles)
Wolfgang Betz 0:4fb29d9ee571 403 {
Wolfgang Betz 0:4fb29d9ee571 404 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 405
Wolfgang Betz 0:4fb29d9ee571 406 /* Check the parameters */
Wolfgang Betz 0:4fb29d9ee571 407 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(xExtraCycles));
Wolfgang Betz 0:4fb29d9ee571 408
Wolfgang Betz 0:4fb29d9ee571 409 /* Reads the MCU_CLK_CONFIG register */
Wolfgang Betz 0:4fb29d9ee571 410 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 411
Wolfgang Betz 0:4fb29d9ee571 412 /* Mask the CLOCK_TAIL field and writes the new value */
Wolfgang Betz 0:4fb29d9ee571 413 tempRegValue &= 0x9F;
Wolfgang Betz 0:4fb29d9ee571 414 tempRegValue |= ((uint8_t)xExtraCycles);
Wolfgang Betz 0:4fb29d9ee571 415
Wolfgang Betz 0:4fb29d9ee571 416 /* Writes the new number of extra clock cycles in the MCU_CLOCK register */
Wolfgang Betz 0:4fb29d9ee571 417 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 418
Wolfgang Betz 0:4fb29d9ee571 419 }
Wolfgang Betz 0:4fb29d9ee571 420
Wolfgang Betz 0:4fb29d9ee571 421
Wolfgang Betz 0:4fb29d9ee571 422 /**
Wolfgang Betz 0:4fb29d9ee571 423 * @brief Returns the settled RCO prescaler as clock output.
Wolfgang Betz 0:4fb29d9ee571 424 * @param None.
Wolfgang Betz 0:4fb29d9ee571 425 * @retval ExtraClockCycles Settled number of extra clock cycles
Wolfgang Betz 0:4fb29d9ee571 426 * provided before switching to STANDBY state. This parameter can be
Wolfgang Betz 0:4fb29d9ee571 427 * any value of @ref ExtraClockCycles .
Wolfgang Betz 0:4fb29d9ee571 428 */
Wolfgang Betz 0:4fb29d9ee571 429 ExtraClockCycles SpiritGpioGetExtraClockCycles(void)
Wolfgang Betz 0:4fb29d9ee571 430 {
Wolfgang Betz 0:4fb29d9ee571 431 uint8_t tempRegValue = 0x00;
Wolfgang Betz 0:4fb29d9ee571 432
Wolfgang Betz 0:4fb29d9ee571 433 /* Reads the MCU_CLK_CONFIG register */
Wolfgang Betz 0:4fb29d9ee571 434 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue);
Wolfgang Betz 0:4fb29d9ee571 435
Wolfgang Betz 0:4fb29d9ee571 436 /* Mask the CLOCK_TAIL field and returns the value */
Wolfgang Betz 0:4fb29d9ee571 437 return ((ExtraClockCycles)(tempRegValue & 0x60));
Wolfgang Betz 0:4fb29d9ee571 438
Wolfgang Betz 0:4fb29d9ee571 439 }
Wolfgang Betz 0:4fb29d9ee571 440
Wolfgang Betz 0:4fb29d9ee571 441
Wolfgang Betz 0:4fb29d9ee571 442 /**
Wolfgang Betz 0:4fb29d9ee571 443 * @}
Wolfgang Betz 0:4fb29d9ee571 444 */
Wolfgang Betz 0:4fb29d9ee571 445
Wolfgang Betz 0:4fb29d9ee571 446
Wolfgang Betz 0:4fb29d9ee571 447 /**
Wolfgang Betz 0:4fb29d9ee571 448 * @}
Wolfgang Betz 0:4fb29d9ee571 449 */
Wolfgang Betz 0:4fb29d9ee571 450
Wolfgang Betz 0:4fb29d9ee571 451
Wolfgang Betz 0:4fb29d9ee571 452 /**
Wolfgang Betz 0:4fb29d9ee571 453 * @}
Wolfgang Betz 0:4fb29d9ee571 454 */
Wolfgang Betz 0:4fb29d9ee571 455
Wolfgang Betz 0:4fb29d9ee571 456
Wolfgang Betz 0:4fb29d9ee571 457
Wolfgang Betz 0:4fb29d9ee571 458 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/