Fork of my MQTTGateway

Dependencies:   mbed-http

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

Who changed what in which revision?

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