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>© COPYRIGHT MINDMOTION </CENTER></H2> 16 //////////////////////////////////////////////////////////////////////////////// 17 18 // Define to prevent recursive inclusion 19 #define _HAL_MISC_C_ 20 21 // Files includes 22 #include "hal_misc.h" 23 24 //////////////////////////////////////////////////////////////////////////////// 25 /// @addtogroup MM32_Hardware_Abstract_Layer 26 /// @{ 27 28 //////////////////////////////////////////////////////////////////////////////// 29 /// @addtogroup MSIC_HAL 30 /// @{ 31 32 //////////////////////////////////////////////////////////////////////////////// 33 /// @addtogroup MISC_Exported_Functions 34 /// @{ 35 36 //////////////////////////////////////////////////////////////////////////////// 37 /// @brief Set the NVIC interrupt vector table. 38 /// @param vect_tab 39 /// This parameter can be any combination of the following values: 40 /// @arg NVIC_VectTab_RAM 41 /// @arg NVIC_VectTab_FLASH 42 /// @param offset 43 /// @retval None. 44 //////////////////////////////////////////////////////////////////////////////// NVIC_SetVectorTable(u32 vect_tab,u32 offset)45void NVIC_SetVectorTable(u32 vect_tab, u32 offset) 46 { 47 SCB->VTOR = vect_tab | (offset & (u32)0x1FFFFF80); 48 } 49 50 //////////////////////////////////////////////////////////////////////////////// 51 /// @brief Set the NVIC interrupt priority group. 52 /// @param priority_group 53 /// This parameter can be any combination of the following values: 54 /// @arg NVIC_PriorityGroup_0 55 /// @arg NVIC_PriorityGroup_1 56 /// @arg NVIC_PriorityGroup_2 57 /// @arg NVIC_PriorityGroup_3 58 /// @arg NVIC_PriorityGroup_4 59 /// @retval None. 60 //////////////////////////////////////////////////////////////////////////////// NVIC_PriorityGroupConfig(u32 priority_group)61void NVIC_PriorityGroupConfig(u32 priority_group) 62 { 63 SCB->AIRCR = AIRCR_VECTKEY_MASK | priority_group; 64 } 65 66 //////////////////////////////////////////////////////////////////////////////// 67 /// @brief NVIC initialization. 68 /// @param init_struct 69 /// @retval None. 70 //////////////////////////////////////////////////////////////////////////////// NVIC_Init(NVIC_InitTypeDef * init_struct)71void NVIC_Init(NVIC_InitTypeDef* init_struct) 72 { 73 if (init_struct->NVIC_IRQChannelCmd != DISABLE) { 74 u32 pri = (SCB_AIRCR_PRIGROUP & ~(SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk)) >> SCB_AIRCR_PRIGROUP_Pos; 75 76 pri = (((u32)init_struct->NVIC_IRQChannelPreemptionPriority << (0x4 - pri)) | 77 (init_struct->NVIC_IRQChannelSubPriority & (0x0F >> pri))) 78 << 0x04; 79 80 NVIC->IP[init_struct->NVIC_IRQChannel] = pri; 81 NVIC->ISER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F); 82 } 83 else { 84 NVIC->ICER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F); 85 } 86 87 } 88 89 //////////////////////////////////////////////////////////////////////////////// 90 /// @brief NVIC initialized extension function. 91 /// @param init_struct 92 /// @retval None. 93 //////////////////////////////////////////////////////////////////////////////// exNVIC_Init(exNVIC_Init_TypeDef * init_struct)94void exNVIC_Init(exNVIC_Init_TypeDef* init_struct) 95 { 96 u32 pri; 97 98 if (init_struct->NVIC_IRQChannelCmd != DISABLE) { 99 pri = (SCB_AIRCR_PRIGROUP & ~(SCB->AIRCR & SCB_AIRCR_PRIGROUP_Msk)) >> SCB_AIRCR_PRIGROUP_Pos; 100 101 pri = (((u32)init_struct->NVIC_IRQChannelPreemptionPriority << (0x4 - pri)) | 102 (init_struct->NVIC_IRQChannelSubPriority & (0x0F >> pri))) << 0x04; 103 104 NVIC->IP[init_struct->NVIC_IRQChannel] = pri; 105 NVIC->ISER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F); 106 } 107 else { 108 NVIC->ICER[init_struct->NVIC_IRQChannel >> 0x05] = 0x01 << (init_struct->NVIC_IRQChannel & 0x1F); 109 } 110 111 } 112 113 //////////////////////////////////////////////////////////////////////////////// 114 /// @brief System low power mode configuration. 115 /// @param low_power_mode 116 /// This parameter can be any combination of the following values: 117 /// @arg NVIC_LP_SEVONPEND 118 /// @arg NVIC_LP_SLEEPDEEP 119 /// @arg NVIC_LP_SLEEPONEXIT 120 /// @param state: new state of the low power mode. 121 /// This parameter can be: ENABLE or DISABLE. 122 /// @retval None. 123 //////////////////////////////////////////////////////////////////////////////// NVIC_SystemLPConfig(u8 low_power_mode,FunctionalState state)124void NVIC_SystemLPConfig(u8 low_power_mode, FunctionalState state) 125 { 126 (state) ? (SCB->SCR |= low_power_mode) : (SCB->SCR &= ~(u32)low_power_mode); 127 } 128 129 //////////////////////////////////////////////////////////////////////////////// 130 /// @brief SysTick clock source configuration. 131 /// @param systick_clk_source 132 /// This parameter can be any combination of the following values: 133 /// @arg SysTick_CLKSource_EXTCLK 134 /// @arg SysTick_CLKSource_HCLK 135 /// @retval None. 136 //////////////////////////////////////////////////////////////////////////////// SysTick_CLKSourceConfig(u32 systick_clk_source)137void SysTick_CLKSourceConfig(u32 systick_clk_source) 138 { 139 (systick_clk_source == SysTick_CLKSource_HCLK) ? (SysTick->CTRL |= SysTick_CLKSource_HCLK) \ 140 : (SysTick->CTRL &= ~SysTick_CLKSource_HCLK); 141 } 142 143 /// @} 144 145 /// @} 146 147 /// @} 148