Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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