Added support for the WNC M14A2A Cellular LTE Data Module.
Dependencies: WNC14A2AInterface
SPIRIT_Gpio.c
00001 /** 00002 ****************************************************************************** 00003 * @file SPIRIT_Gpio.c 00004 * @author VMA division - AMS 00005 * @version 3.2.2 00006 * @date 08-July-2015 00007 * @brief This file provides all the low level API to manage SPIRIT GPIO. 00008 * @details 00009 * 00010 * @attention 00011 * 00012 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2> 00013 * 00014 * Redistribution and use in source and binary forms, with or without modification, 00015 * are permitted provided that the following conditions are met: 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 2. Redistributions in binary form must reproduce the above copyright notice, 00019 * this list of conditions and the following disclaimer in the documentation 00020 * and/or other materials provided with the distribution. 00021 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00022 * may be used to endorse or promote products derived from this software 00023 * without specific prior written permission. 00024 * 00025 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00026 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00027 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00028 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00029 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00030 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00031 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00032 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00033 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00034 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 * 00036 ****************************************************************************** 00037 */ 00038 00039 /* Includes ------------------------------------------------------------------*/ 00040 #include "SPIRIT_Gpio.h" 00041 #include "MCU_Interface.h" 00042 00043 00044 /** @addtogroup SPIRIT_Libraries 00045 * @{ 00046 */ 00047 00048 00049 /** @addtogroup SPIRIT_Gpio 00050 * @{ 00051 */ 00052 00053 00054 /** @defgroup Gpio_Private_TypesDefinitions GPIO Private Types Definitions 00055 * @{ 00056 */ 00057 00058 00059 /** 00060 * @} 00061 */ 00062 00063 00064 /** @defgroup Gpio_Private_Defines GPIO Private Defines 00065 * @{ 00066 */ 00067 00068 00069 /** 00070 * @} 00071 */ 00072 00073 00074 00075 /** @defgroup Gpio_Private_Macros GPIO Private Macros 00076 * @{ 00077 */ 00078 00079 00080 /** 00081 * @} 00082 */ 00083 00084 00085 00086 /** @defgroup Gpio_Private_Variables GPIO Private Variables 00087 * @{ 00088 */ 00089 00090 00091 /** 00092 * @} 00093 */ 00094 00095 00096 00097 /** @defgroup Gpio_Private_FunctionPrototypes GPIO Private Function Prototypes 00098 * @{ 00099 */ 00100 00101 00102 /** 00103 * @} 00104 */ 00105 00106 00107 00108 /** @defgroup Gpio_Private_Functions GPIO Private Functions 00109 * @{ 00110 */ 00111 00112 /** 00113 * @brief Initializes the SPIRIT GPIOx according to the specified 00114 * parameters in the pxGpioInitStruct. 00115 * @param pxGpioInitStruct pointer to a SGpioInit structure that 00116 * contains the configuration information for the specified SPIRIT GPIO. 00117 * @retval None. 00118 */ 00119 void SpiritGpioInit(SGpioInit* pxGpioInitStruct) 00120 { 00121 uint8_t tempRegValue = 0x00; 00122 00123 /* Check the parameters */ 00124 s_assert_param(IS_SPIRIT_GPIO(pxGpioInitStruct->xSpiritGpioPin )); 00125 s_assert_param(IS_SPIRIT_GPIO_MODE(pxGpioInitStruct->xSpiritGpioMode )); 00126 s_assert_param(IS_SPIRIT_GPIO_IO(pxGpioInitStruct->xSpiritGpioIO )); 00127 00128 tempRegValue = ((uint8_t)(pxGpioInitStruct->xSpiritGpioMode ) | (uint8_t)(pxGpioInitStruct->xSpiritGpioIO )); 00129 00130 g_xStatus = SpiritSpiWriteRegisters(pxGpioInitStruct->xSpiritGpioPin , 1, &tempRegValue); 00131 00132 } 00133 00134 00135 /** 00136 * @brief Enables or Disables the output of temperature sensor on SPIRIT GPIO_0. 00137 * @param xNewState new state for temperature sensor. 00138 * This parameter can be: S_ENABLE or S_DISABLE. 00139 * @retval None. 00140 */ 00141 void SpiritGpioTemperatureSensor(SpiritFunctionalState xNewState) 00142 { 00143 uint8_t tempRegValue = 0x00; 00144 uint8_t gpio0tempRegValue = 0x00; 00145 00146 /* Check the parameters */ 00147 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00148 00149 /* Reads the ANA_FUNC_CONF0 register and mask the result to enable or disable the 00150 temperature sensor */ 00151 g_xStatus = SpiritSpiReadRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00152 if(xNewState == S_ENABLE) 00153 { 00154 tempRegValue |= TEMPERATURE_SENSOR_MASK; 00155 } 00156 else 00157 { 00158 tempRegValue &= (~TEMPERATURE_SENSOR_MASK); 00159 gpio0tempRegValue = 0x0A; /* Default value */ 00160 } 00161 g_xStatus = SpiritSpiWriteRegisters(ANA_FUNC_CONF0_BASE, 1, &tempRegValue); 00162 00163 /* Sets the SPIRIT GPIO_0 according to input request */ 00164 g_xStatus = SpiritSpiWriteRegisters(GPIO0_CONF_BASE, 1, &gpio0tempRegValue); 00165 00166 } 00167 00168 00169 /** 00170 * @brief Forces SPIRIT GPIO_x configured as digital output, to VDD or GND. 00171 * @param xGpioX Specifies the GPIO to be configured. 00172 * This parameter can be one of following parameters: 00173 * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0 00174 * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1 00175 * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2 00176 * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3 00177 * @param xLevel Specifies the level. 00178 * This parameter can be: HIGH or LOW. 00179 * @retval None. 00180 */ 00181 void SpiritGpioSetLevel(SpiritGpioPin xGpioX, OutputLevel xLevel) 00182 { 00183 uint8_t tempRegValue = 0x00; 00184 00185 /* Check the parameters */ 00186 s_assert_param(IS_SPIRIT_GPIO(xGpioX)); 00187 s_assert_param(IS_SPIRIT_GPIO_LEVEL(xLevel)); 00188 00189 /* Reads the SPIRIT_GPIOx register and mask the GPIO_SELECT field */ 00190 g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue); 00191 tempRegValue &= 0x04; 00192 00193 /* Sets the value of the SPIRIT GPIO register according to the specified level */ 00194 if(xLevel == HIGH) 00195 { 00196 tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_VDD | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP ; 00197 } 00198 else 00199 { 00200 tempRegValue |= (uint8_t)SPIRIT_GPIO_DIG_OUT_GND | (uint8_t)SPIRIT_GPIO_MODE_DIGITAL_OUTPUT_HP ; 00201 } 00202 00203 /* Writes the SPIRIT GPIO register */ 00204 g_xStatus = SpiritSpiWriteRegisters(xGpioX, 1, &tempRegValue); 00205 00206 } 00207 00208 00209 /** 00210 * @brief Returns output value (VDD or GND) of SPIRIT GPIO_x, when it is configured as digital output. 00211 * @param xGpioX Specifies the GPIO to be read. 00212 * This parameter can be one of following parameters: 00213 * @arg SPIRIT_GPIO_0: SPIRIT GPIO_0 00214 * @arg SPIRIT_GPIO_1: SPIRIT GPIO_1 00215 * @arg SPIRIT_GPIO_2: SPIRIT GPIO_2 00216 * @arg SPIRIT_GPIO_3: SPIRIT GPIO_3 00217 * @retval OutputLevel Logical level of selected GPIO configured as digital output. 00218 * This parameter can be: HIGH or LOW. 00219 */ 00220 OutputLevel SpiritGpioGetLevel(SpiritGpioPin xGpioX) 00221 { 00222 uint8_t tempRegValue = 0x00; 00223 OutputLevel level; 00224 00225 /* Check the parameters */ 00226 s_assert_param(IS_SPIRIT_GPIO(xGpioX)); 00227 00228 /* Reads the SPIRIT_GPIOx register */ 00229 g_xStatus = SpiritSpiReadRegisters(xGpioX, 1, &tempRegValue); 00230 00231 /* Mask the GPIO_SELECT field and returns the value according */ 00232 tempRegValue &= 0xF8; 00233 if(tempRegValue == SPIRIT_GPIO_DIG_OUT_VDD ) 00234 { 00235 level = HIGH; 00236 } 00237 else 00238 { 00239 level = LOW; 00240 } 00241 00242 return level; 00243 00244 } 00245 00246 00247 /** 00248 * @brief Enables or Disables the MCU clock output. 00249 * @param xNewState new state for the MCU clock output. 00250 * This parameter can be: S_ENABLE or S_DISABLE. 00251 * @retval None. 00252 */ 00253 void SpiritGpioClockOutput(SpiritFunctionalState xNewState) 00254 { 00255 uint8_t tempRegValue; 00256 00257 /* Check the parameters */ 00258 s_assert_param(IS_SPIRIT_FUNCTIONAL_STATE(xNewState)); 00259 00260 /* Reads the MCU_CK_CONF register and mask the result to enable or disable the clock output */ 00261 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00262 00263 if(xNewState) 00264 { 00265 tempRegValue |= MCU_CK_ENABLE; 00266 } 00267 else 00268 { 00269 tempRegValue &= (~MCU_CK_ENABLE); 00270 } 00271 00272 /* Writes the MCU_CK_CONF register */ 00273 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00274 00275 } 00276 00277 00278 /** 00279 * @brief Initializes the SPIRIT Clock Output according to the specified 00280 * parameters in the xClockOutputInitStruct. 00281 * @param pxClockOutputInitStruct pointer to a ClockOutputInit structure that 00282 * contains the configuration information for the SPIRIT Clock Output. 00283 * @retval None. 00284 * @note The function SpiritGpioClockOutput() must be called in order to enable 00285 * or disable the MCU clock dividers. 00286 */ 00287 void SpiritGpioClockOutputInit(ClockOutputInit* pxClockOutputInitStruct) 00288 { 00289 uint8_t tempRegValue = 0x00; 00290 00291 /* Check the parameters */ 00292 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(pxClockOutputInitStruct->xClockOutputXOPrescaler )); 00293 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(pxClockOutputInitStruct->xClockOutputRCOPrescaler )); 00294 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(pxClockOutputInitStruct->xExtraClockCycles )); 00295 00296 /* Calculates the register value to write according to the specified configuration */ 00297 tempRegValue = ((uint8_t)(pxClockOutputInitStruct->xClockOutputXOPrescaler ) | (uint8_t)(pxClockOutputInitStruct->xClockOutputRCOPrescaler ) | \ 00298 (uint8_t)(pxClockOutputInitStruct->xExtraClockCycles )); 00299 00300 /* Writes the MCU_CLOCK register */ 00301 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00302 00303 } 00304 00305 00306 /** 00307 * @brief Sets the XO ratio as clock output. 00308 * @param xXOPrescaler the XO prescaler to be used as clock output. 00309 * This parameter can be any value of @ref ClockOutputXOPrescaler . 00310 * @retval None 00311 */ 00312 void SpiritGpioSetXOPrescaler(ClockOutputXOPrescaler xXOPrescaler) 00313 { 00314 uint8_t tempRegValue = 0x00; 00315 00316 /* Check the parameters */ 00317 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_XO(xXOPrescaler)); 00318 00319 /* Reads the MCU_CLK_CONFIG register */ 00320 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00321 00322 /* Mask the XO_RATIO field and writes the new value */ 00323 tempRegValue &= 0x61; 00324 tempRegValue |= ((uint8_t)xXOPrescaler); 00325 00326 /* Writes the new XO prescaler in the MCU_CLOCK register */ 00327 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00328 00329 } 00330 00331 00332 /** 00333 * @brief Returns the settled XO prescaler as clock output. 00334 * @param None. 00335 * @retval ClockOutputXOPrescaler Settled XO prescaler used for clock 00336 * output. This parameter can be a value of @ref ClockOutputXOPrescaler . 00337 */ 00338 ClockOutputXOPrescaler SpiritGpioGetXOPrescaler(void) 00339 { 00340 uint8_t tempRegValue = 0x00; 00341 00342 /* Reads the MCU_CLK_CONFIG register */ 00343 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00344 00345 /* Mask the XO_RATIO field and return the value */ 00346 return ((ClockOutputXOPrescaler)(tempRegValue & 0x1E)); 00347 00348 } 00349 00350 00351 /** 00352 * @brief Sets the RCO ratio as clock output 00353 * @param xRCOPrescaler the RCO prescaler to be used as clock output. 00354 * This parameter can be any value of @ref ClockOutputRCOPrescaler . 00355 * @retval None. 00356 */ 00357 void SpiritGpioSetRCOPrescaler(ClockOutputRCOPrescaler xRCOPrescaler) 00358 { 00359 uint8_t tempRegValue = 0x00; 00360 00361 /* Check the parameters */ 00362 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_RCO(xRCOPrescaler)); 00363 00364 /* Reads the MCU_CLK_CONFIG register */ 00365 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00366 00367 /* Mask the RCO_RATIO field and writes the new value */ 00368 tempRegValue &= 0xFE; 00369 tempRegValue |= ((uint8_t)xRCOPrescaler); 00370 00371 /* Writes the new RCO prescaler in the MCU_CLOCK register */ 00372 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00373 00374 } 00375 00376 00377 /** 00378 * @brief Returns the settled RCO prescaler as clock output. 00379 * @param None. 00380 * @retval ClockOutputRCOPrescaler Settled RCO prescaler used for clock 00381 * output. This parameter can be a value of @ref ClockOutputRCOPrescaler. 00382 */ 00383 ClockOutputRCOPrescaler SpiritGpioGetRCOPrescaler(void) 00384 { 00385 uint8_t tempRegValue = 0x00; 00386 00387 /* Reads the MCU_CLK_CONFIG register */ 00388 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00389 00390 /* Mask the RCO_RATIO field and returns the value */ 00391 return ((ClockOutputRCOPrescaler)(tempRegValue & 0x01)); 00392 00393 } 00394 00395 00396 /** 00397 * @brief Sets the RCO ratio as clock output. 00398 * @param xExtraCycles the number of extra clock cycles provided before switching 00399 * to STANDBY state. This parameter can be any value of @ref ExtraClockCycles . 00400 * @retval None. 00401 */ 00402 void SpiritGpioSetExtraClockCycles(ExtraClockCycles xExtraCycles) 00403 { 00404 uint8_t tempRegValue = 0x00; 00405 00406 /* Check the parameters */ 00407 s_assert_param(IS_SPIRIT_CLOCK_OUTPUT_EXTRA_CYCLES(xExtraCycles)); 00408 00409 /* Reads the MCU_CLK_CONFIG register */ 00410 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00411 00412 /* Mask the CLOCK_TAIL field and writes the new value */ 00413 tempRegValue &= 0x9F; 00414 tempRegValue |= ((uint8_t)xExtraCycles); 00415 00416 /* Writes the new number of extra clock cycles in the MCU_CLOCK register */ 00417 g_xStatus = SpiritSpiWriteRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00418 00419 } 00420 00421 00422 /** 00423 * @brief Returns the settled RCO prescaler as clock output. 00424 * @param None. 00425 * @retval ExtraClockCycles Settled number of extra clock cycles 00426 * provided before switching to STANDBY state. This parameter can be 00427 * any value of @ref ExtraClockCycles . 00428 */ 00429 ExtraClockCycles SpiritGpioGetExtraClockCycles(void) 00430 { 00431 uint8_t tempRegValue = 0x00; 00432 00433 /* Reads the MCU_CLK_CONFIG register */ 00434 g_xStatus = SpiritSpiReadRegisters(MCU_CK_CONF_BASE, 1, &tempRegValue); 00435 00436 /* Mask the CLOCK_TAIL field and returns the value */ 00437 return ((ExtraClockCycles)(tempRegValue & 0x60)); 00438 00439 } 00440 00441 00442 /** 00443 * @} 00444 */ 00445 00446 00447 /** 00448 * @} 00449 */ 00450 00451 00452 /** 00453 * @} 00454 */ 00455 00456 00457 00458 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 19:09:04 by 1.7.2