misc.c 6.9 KB

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