hal_misc.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_misc.c
  3. /// @author AE TEAM
  4. /// @brief THIS FILE PROVIDES ALL THE MSIC FIRMWARE FUNCTIONS.
  5. ////////////////////////////////////////////////////////////////////////////////
  6. /// @attention
  7. ///
  8. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  9. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  10. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  11. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  12. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  13. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  14. ///
  15. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // Define to prevent recursive inclusion
  18. #define _HAL_MISC_C_
  19. // Files includes
  20. #include "hal_misc.h"
  21. ////////////////////////////////////////////////////////////////////////////////
  22. /// @addtogroup MM32_Hardware_Abstract_Layer
  23. /// @{
  24. ////////////////////////////////////////////////////////////////////////////////
  25. /// @addtogroup MSIC_HAL
  26. /// @{
  27. ////////////////////////////////////////////////////////////////////////////////
  28. /// @addtogroup MISC_Exported_Functions
  29. /// @{
  30. ////////////////////////////////////////////////////////////////////////////////
  31. /// @brief Set the NVIC interrupt vector table.
  32. /// @param vect_tab
  33. /// This parameter can be any combination of the following values:
  34. /// @arg NVIC_VectTab_RAM
  35. /// @arg NVIC_VectTab_FLASH
  36. /// @param offset
  37. /// @retval None.
  38. ////////////////////////////////////////////////////////////////////////////////
  39. void NVIC_SetVectorTable(u32 vect_tab, u32 offset)
  40. {
  41. SCB->VTOR = vect_tab | (offset & (u32)0x1FFFFF80);
  42. }
  43. ////////////////////////////////////////////////////////////////////////////////
  44. /// @brief Set the NVIC interrupt priority group.
  45. /// @param priority_group
  46. /// This parameter can be any combination of the following values:
  47. /// @arg NVIC_PriorityGroup_0
  48. /// @arg NVIC_PriorityGroup_1
  49. /// @arg NVIC_PriorityGroup_2
  50. /// @arg NVIC_PriorityGroup_3
  51. /// @arg NVIC_PriorityGroup_4
  52. /// @retval None.
  53. ////////////////////////////////////////////////////////////////////////////////
  54. void NVIC_PriorityGroupConfig(u32 priority_group)
  55. {
  56. SCB->AIRCR = AIRCR_VECTKEY_MASK | priority_group;
  57. }
  58. ////////////////////////////////////////////////////////////////////////////////
  59. /// @brief NVIC initialization.
  60. /// @param init_struct
  61. /// @retval None.
  62. ////////////////////////////////////////////////////////////////////////////////
  63. void NVIC_Init(NVIC_InitTypeDef* init_struct)
  64. {
  65. if (init_struct->NVIC_IRQChannelCmd != DISABLE) {
  66. u32 pri = (SCB_AIRCR_PRIGROUP & ~(SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk)) >> SCB_AIRCR_PRIGROUP_Pos;
  67. pri = (((u32)init_struct->NVIC_IRQChannelPreemptionPriority << (0x4 - pri)) |
  68. (init_struct->NVIC_IRQChannelSubPriority & (0x0F >> pri)))
  69. << 0x04;
  70. NVIC->IP[init_struct->NVIC_IRQChannel] = pri;
  71. NVIC->ISER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F);
  72. }
  73. else {
  74. NVIC->ICER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F);
  75. }
  76. }
  77. ////////////////////////////////////////////////////////////////////////////////
  78. /// @brief NVIC initialized extension function.
  79. /// @param init_struct
  80. /// @retval None.
  81. ////////////////////////////////////////////////////////////////////////////////
  82. void exNVIC_Init(exNVIC_Init_TypeDef* init_struct)
  83. {
  84. u32 pri;
  85. if (init_struct->NVIC_IRQChannelCmd != DISABLE) {
  86. pri = (SCB_AIRCR_PRIGROUP & ~(SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk)) >> SCB_AIRCR_PRIGROUP_Pos;
  87. pri = (((u32)init_struct->NVIC_IRQChannelPreemptionPriority << (0x4 - pri)) |
  88. (init_struct->NVIC_IRQChannelSubPriority & (0x0F >> pri))) << 0x04;
  89. NVIC->IP[init_struct->NVIC_IRQChannel] = pri;
  90. NVIC->ISER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F);
  91. }
  92. else {
  93. NVIC->ICER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F);
  94. }
  95. }
  96. ////////////////////////////////////////////////////////////////////////////////
  97. /// @brief System low power mode configuration.
  98. /// @param low_power_mode
  99. /// This parameter can be any combination of the following values:
  100. /// @arg NVIC_LP_SEVONPEND
  101. /// @arg NVIC_LP_SLEEPDEEP
  102. /// @arg NVIC_LP_SLEEPONEXIT
  103. /// @param state: new state of the low power mode.
  104. /// This parameter can be: ENABLE or DISABLE.
  105. /// @retval None.
  106. ////////////////////////////////////////////////////////////////////////////////
  107. void NVIC_SystemLPConfig(u8 low_power_mode, FunctionalState state)
  108. {
  109. (state) ? (SCB->SCR |= low_power_mode) : (SCB->SCR &= ~(u32)low_power_mode);
  110. }
  111. ////////////////////////////////////////////////////////////////////////////////
  112. /// @brief SysTick clock source configuration.
  113. /// @param systick_clk_source
  114. /// This parameter can be any combination of the following values:
  115. /// @arg SysTick_CLKSource_EXTCLK
  116. /// @arg SysTick_CLKSource_HCLK
  117. /// @retval None.
  118. ////////////////////////////////////////////////////////////////////////////////
  119. void SysTick_CLKSourceConfig(u32 systick_clk_source)
  120. {
  121. (systick_clk_source == SysTick_CLKSource_HCLK) ? (SysTick->CTRL |= SysTick_CLKSource_HCLK) \
  122. : (SysTick->CTRL &= ~SysTick_CLKSource_HCLK);
  123. }
  124. /// @}
  125. /// @}
  126. /// @}