misc.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. ******************************************************************************
  3. * @file misc.c
  4. * @author MCD Application Team
  5. * @version V3.3.0
  6. * @date 04/16/2010
  7. * @brief This file provides all the miscellaneous firmware functions (add-on
  8. * to CMSIS functions).
  9. ******************************************************************************
  10. * @copy
  11. *
  12. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  13. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  14. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  15. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  16. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  17. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  18. *
  19. * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  20. */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "misc.h"
  23. /** @addtogroup STM32F10x_StdPeriph_Driver
  24. * @{
  25. */
  26. /** @defgroup MISC
  27. * @brief MISC driver modules
  28. * @{
  29. */
  30. /** @defgroup MISC_Private_TypesDefinitions
  31. * @{
  32. */
  33. /**
  34. * @}
  35. */
  36. /** @defgroup MISC_Private_Defines
  37. * @{
  38. */
  39. #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000)
  40. /**
  41. * @}
  42. */
  43. /** @defgroup MISC_Private_Macros
  44. * @{
  45. */
  46. /**
  47. * @}
  48. */
  49. /** @defgroup MISC_Private_Variables
  50. * @{
  51. */
  52. /**
  53. * @}
  54. */
  55. /** @defgroup MISC_Private_FunctionPrototypes
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /** @defgroup MISC_Private_Functions
  62. * @{
  63. */
  64. /**
  65. * @brief Configures the priority grouping: pre-emption priority and subpriority.
  66. * @param NVIC_PriorityGroup: specifies the priority grouping bits length.
  67. * This parameter can be one of the following values:
  68. * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
  69. * 4 bits for subpriority
  70. * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
  71. * 3 bits for subpriority
  72. * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
  73. * 2 bits for subpriority
  74. * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
  75. * 1 bits for subpriority
  76. * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
  77. * 0 bits for subpriority
  78. * @retval None
  79. */
  80. void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
  81. {
  82. /* Check the parameters */
  83. assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
  84. /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  85. SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
  86. }
  87. /**
  88. * @brief Initializes the NVIC peripheral according to the specified
  89. * parameters in the NVIC_InitStruct.
  90. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  91. * the configuration information for the specified NVIC peripheral.
  92. * @retval None
  93. */
  94. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  95. {
  96. uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
  97. /* Check the parameters */
  98. assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
  99. assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));
  100. assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
  101. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  102. {
  103. /* Compute the Corresponding IRQ Priority --------------------------------*/
  104. tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
  105. tmppre = (0x4 - tmppriority);
  106. tmpsub = tmpsub >> tmppriority;
  107. tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
  108. tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
  109. tmppriority = tmppriority << 0x04;
  110. NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
  111. /* Enable the Selected IRQ Channels --------------------------------------*/
  112. NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
  113. (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  114. }
  115. else
  116. {
  117. /* Disable the Selected IRQ Channels -------------------------------------*/
  118. NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
  119. (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  120. }
  121. }
  122. /**
  123. * @brief Sets the vector table location and Offset.
  124. * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
  125. * This parameter can be one of the following values:
  126. * @arg NVIC_VectTab_RAM
  127. * @arg NVIC_VectTab_FLASH
  128. * @param Offset: Vector Table base offset field. This value must be a multiple of 0x100.
  129. * @retval None
  130. */
  131. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
  132. {
  133. /* Check the parameters */
  134. assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
  135. assert_param(IS_NVIC_OFFSET(Offset));
  136. SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
  137. }
  138. /**
  139. * @brief Selects the condition for the system to enter low power mode.
  140. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  141. * This parameter can be one of the following values:
  142. * @arg NVIC_LP_SEVONPEND
  143. * @arg NVIC_LP_SLEEPDEEP
  144. * @arg NVIC_LP_SLEEPONEXIT
  145. * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
  146. * @retval None
  147. */
  148. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
  149. {
  150. /* Check the parameters */
  151. assert_param(IS_NVIC_LP(LowPowerMode));
  152. assert_param(IS_FUNCTIONAL_STATE(NewState));
  153. if (NewState != DISABLE)
  154. {
  155. SCB->SCR |= LowPowerMode;
  156. }
  157. else
  158. {
  159. SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
  160. }
  161. }
  162. /**
  163. * @brief Configures the SysTick clock source.
  164. * @param SysTick_CLKSource: specifies the SysTick clock source.
  165. * This parameter can be one of the following values:
  166. * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
  167. * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
  168. * @retval None
  169. */
  170. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
  171. {
  172. /* Check the parameters */
  173. assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
  174. if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
  175. {
  176. SysTick->CTRL |= SysTick_CLKSource_HCLK;
  177. }
  178. else
  179. {
  180. SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
  181. }
  182. }
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @}
  188. */
  189. /**
  190. * @}
  191. */
  192. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/