HAL_misc.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**
  2. ******************************************************************************
  3. * @file HAL_misc.c
  4. * @author AE Team
  5. * @version V1.0.0
  6. * @date 28/7/2017
  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, MindMotion 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 2017 MindMotion</center></h2>
  20. ******************************************************************************
  21. */
  22. /* Includes ------------------------------------------------------------------*/
  23. #include "HAL_misc.h"
  24. /** @addtogroup 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. /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
  84. SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
  85. }
  86. /**
  87. * @brief Initializes the NVIC peripheral according to the specified
  88. * parameters in the NVIC_InitStruct.
  89. * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
  90. * the configuration information for the specified NVIC peripheral.
  91. * @retval None
  92. */
  93. void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
  94. {
  95. uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
  96. if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
  97. {
  98. /* Compute the Corresponding IRQ Priority --------------------------------*/
  99. tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
  100. tmppre = (0x4 - tmppriority);
  101. tmpsub = tmpsub >> tmppriority;
  102. tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
  103. tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
  104. tmppriority = tmppriority << 0x04;
  105. NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
  106. /* Enable the Selected IRQ Channels --------------------------------------*/
  107. NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
  108. (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  109. }
  110. else
  111. {
  112. /* Disable the Selected IRQ Channels -------------------------------------*/
  113. NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
  114. (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
  115. }
  116. tmppre = NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05];
  117. }
  118. /**
  119. * @brief Sets the vector table location and Offset.
  120. * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
  121. * This parameter can be one of the following values:
  122. * @arg NVIC_VectTab_RAM
  123. * @arg NVIC_VectTab_FLASH
  124. * @param Offset: Vector Table base offset field. This value must be a multiple
  125. * of 0x200.
  126. * @retval None
  127. */
  128. void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
  129. {
  130. SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
  131. }
  132. /**
  133. * @brief Selects the condition for the system to enter low power mode.
  134. * @param LowPowerMode: Specifies the new mode for the system to enter low power mode.
  135. * This parameter can be one of the following values:
  136. * @arg NVIC_LP_SEVONPEND
  137. * @arg NVIC_LP_SLEEPDEEP
  138. * @arg NVIC_LP_SLEEPONEXIT
  139. * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
  140. * @retval None
  141. */
  142. void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
  143. {
  144. if (NewState != DISABLE)
  145. {
  146. SCB->SCR |= LowPowerMode;
  147. }
  148. else
  149. {
  150. SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
  151. }
  152. }
  153. /**
  154. * @brief Configures the SysTick clock source.
  155. * @param SysTick_CLKSource: specifies the SysTick clock source.
  156. * This parameter can be one of the following values:
  157. * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
  158. * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
  159. * @retval None
  160. */
  161. void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
  162. {
  163. /* Check the parameters */
  164. if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
  165. {
  166. SysTick->CTRL |= SysTick_CLKSource_HCLK;
  167. }
  168. else
  169. {
  170. SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
  171. }
  172. }
  173. /**
  174. * @}
  175. */
  176. /**
  177. * @}
  178. */
  179. /**
  180. * @}
  181. */
  182. /*-------------------------(C) COPYRIGHT 2017 MindMotion ----------------------*/