stm32f0xx_misc.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_misc.c
  4. * @author MCD Application Team
  5. * @version V1.0.0
  6. * @date 23-March-2012
  7. * @brief This file provides all the miscellaneous firmware functions (add-on
  8. * to CMSIS functions).
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2012 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Includes ------------------------------------------------------------------*/
  29. #include "stm32f0xx_misc.h"
  30. /** @addtogroup STM32F0xx_StdPeriph_Driver
  31. * @{
  32. */
  33. /** @defgroup MISC
  34. * @brief MISC driver modules
  35. * @{
  36. */
  37. /* Private typedef -----------------------------------------------------------*/
  38. /* Private define ------------------------------------------------------------*/
  39. /* Private macro -------------------------------------------------------------*/
  40. /* Private variables ---------------------------------------------------------*/
  41. /* Private function prototypes -----------------------------------------------*/
  42. /* Private functions ---------------------------------------------------------*/
  43. /** @defgroup MISC_Private_Functions
  44. * @{
  45. */
  46. /**
  47. *
  48. @verbatim
  49. *******************************************************************************
  50. ##### Interrupts configuration functions #####
  51. *******************************************************************************
  52. [..] This section provide functions allowing to configure the NVIC interrupts
  53. (IRQ). The Cortex-M0 exceptions are managed by CMSIS functions.
  54. (#) Enable and Configure the priority of the selected IRQ Channels.
  55. The priority can be 0..3.
  56. -@- Lower priority values gives higher priority.
  57. -@- Priority Order:
  58. (#@) Lowest priority.
  59. (#@) Lowest hardware priority (IRQn position).
  60. @endverbatim
  61. */
  62. /**
  63. * @brief Initializes the NVIC peripheral according to the specified
  64. * parameters in the NVIC_InitStruct.
  65. * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig()
  66. * function should be called before.
  67. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  68. * the configuration information for the specified NVIC peripheral.
  69. * @retval None
  70. */
  71. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  72. {
  73. uint32_t tmppriority = 0x00;
  74. /* Check the parameters */
  75. assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
  76. assert_param(IS_NVIC_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPriority));
  77. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  78. {
  79. /* Compute the Corresponding IRQ Priority --------------------------------*/
  80. tmppriority = NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02];
  81. tmppriority &= (uint32_t)(~(((uint32_t)0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8)));
  82. tmppriority |= (uint32_t)((((uint32_t)NVIC_InitStruct->NVIC_IRQChannelPriority << 6) & 0xFF) << ((NVIC_InitStruct->NVIC_IRQChannel & 0x03) * 8));
  83. NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel >> 0x02] = tmppriority;
  84. /* Enable the Selected IRQ Channels --------------------------------------*/
  85. NVIC->ISER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  86. }
  87. else
  88. {
  89. /* Disable the Selected IRQ Channels -------------------------------------*/
  90. NVIC->ICER[0] = (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  91. }
  92. }
  93. /**
  94. * @brief Selects the condition for the system to enter low power mode.
  95. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  96. * This parameter can be one of the following values:
  97. * @arg NVIC_LP_SEVONPEND: Low Power SEV on Pend.
  98. * @arg NVIC_LP_SLEEPDEEP: Low Power DEEPSLEEP request.
  99. * @arg NVIC_LP_SLEEPONEXIT: Low Power Sleep on Exit.
  100. * @param NewState: new state of LP condition.
  101. * This parameter can be: ENABLE or DISABLE.
  102. * @retval None
  103. */
  104. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
  105. {
  106. /* Check the parameters */
  107. assert_param(IS_NVIC_LP(LowPowerMode));
  108. assert_param(IS_FUNCTIONAL_STATE(NewState));
  109. if (NewState != DISABLE)
  110. {
  111. SCB->SCR |= LowPowerMode;
  112. }
  113. else
  114. {
  115. SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
  116. }
  117. }
  118. /**
  119. * @brief Configures the SysTick clock source.
  120. * @param SysTick_CLKSource: specifies the SysTick clock source.
  121. * This parameter can be one of the following values:
  122. * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
  123. * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
  124. * @retval None
  125. */
  126. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
  127. {
  128. /* Check the parameters */
  129. assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
  130. if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
  131. {
  132. SysTick->CTRL |= SysTick_CLKSource_HCLK;
  133. }
  134. else
  135. {
  136. SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
  137. }
  138. }
  139. /**
  140. * @}
  141. */
  142. /**
  143. * @}
  144. */
  145. /**
  146. * @}
  147. */
  148. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/