Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
misc.c
00001 /** 00002 ****************************************************************************** 00003 * @file misc.c 00004 * @author MCD Application Team 00005 * @version V3.5.0 00006 * @date 11-March-2011 00007 * @brief This file provides all the miscellaneous firmware functions (add-on 00008 * to CMSIS functions). 00009 ****************************************************************************** 00010 * @attention 00011 * 00012 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 00013 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE 00014 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY 00015 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING 00016 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE 00017 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 00018 * 00019 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> 00020 ****************************************************************************** 00021 */ 00022 00023 /* Includes ------------------------------------------------------------------*/ 00024 #include "misc.h" 00025 00026 /** @addtogroup STM32F10x_StdPeriph_Driver 00027 * @{ 00028 */ 00029 00030 /** @defgroup MISC 00031 * @brief MISC driver modules 00032 * @{ 00033 */ 00034 00035 /** @defgroup MISC_Private_TypesDefinitions 00036 * @{ 00037 */ 00038 00039 /** 00040 * @} 00041 */ 00042 00043 /** @defgroup MISC_Private_Defines 00044 * @{ 00045 */ 00046 00047 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 00048 /** 00049 * @} 00050 */ 00051 00052 /** @defgroup MISC_Private_Macros 00053 * @{ 00054 */ 00055 00056 /** 00057 * @} 00058 */ 00059 00060 /** @defgroup MISC_Private_Variables 00061 * @{ 00062 */ 00063 00064 /** 00065 * @} 00066 */ 00067 00068 /** @defgroup MISC_Private_FunctionPrototypes 00069 * @{ 00070 */ 00071 00072 /** 00073 * @} 00074 */ 00075 00076 /** @defgroup MISC_Private_Functions 00077 * @{ 00078 */ 00079 00080 /** 00081 * @brief Configures the priority grouping: pre-emption priority and subpriority. 00082 * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 00083 * This parameter can be one of the following values: 00084 * @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority 00085 * 4 bits for subpriority 00086 * @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority 00087 * 3 bits for subpriority 00088 * @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority 00089 * 2 bits for subpriority 00090 * @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority 00091 * 1 bits for subpriority 00092 * @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority 00093 * 0 bits for subpriority 00094 * @retval None 00095 */ 00096 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup) 00097 { 00098 /* Check the parameters */ 00099 assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup)); 00100 00101 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 00102 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 00103 } 00104 00105 /** 00106 * @brief Initializes the NVIC peripheral according to the specified 00107 * parameters in the NVIC_InitStruct. 00108 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains 00109 * the configuration information for the specified NVIC peripheral. 00110 * @retval None 00111 */ 00112 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) 00113 { 00114 uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 00115 00116 /* Check the parameters */ 00117 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 00118 assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 00119 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 00120 00121 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 00122 { 00123 /* Compute the Corresponding IRQ Priority --------------------------------*/ 00124 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 00125 tmppre = (0x4 - tmppriority); 00126 tmpsub = tmpsub >> tmppriority; 00127 00128 tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 00129 tmppriority |= NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub; 00130 tmppriority = tmppriority << 0x04; 00131 00132 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 00133 00134 /* Enable the Selected IRQ Channels --------------------------------------*/ 00135 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 00136 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 00137 } 00138 else 00139 { 00140 /* Disable the Selected IRQ Channels -------------------------------------*/ 00141 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 00142 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 00143 } 00144 } 00145 00146 /** 00147 * @brief Sets the vector table location and Offset. 00148 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 00149 * This parameter can be one of the following values: 00150 * @arg NVIC_VectTab_RAM 00151 * @arg NVIC_VectTab_FLASH 00152 * @param Offset: Vector Table base offset field. This value must be a multiple 00153 * of 0x200. 00154 * @retval None 00155 */ 00156 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset) 00157 { 00158 /* Check the parameters */ 00159 assert_param(IS_NVIC_VECTTAB(NVIC_VectTab)); 00160 assert_param(IS_NVIC_OFFSET(Offset)); 00161 00162 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 00163 } 00164 00165 /** 00166 * @brief Selects the condition for the system to enter low power mode. 00167 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 00168 * This parameter can be one of the following values: 00169 * @arg NVIC_LP_SEVONPEND 00170 * @arg NVIC_LP_SLEEPDEEP 00171 * @arg NVIC_LP_SLEEPONEXIT 00172 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 00173 * @retval None 00174 */ 00175 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState) 00176 { 00177 /* Check the parameters */ 00178 assert_param(IS_NVIC_LP(LowPowerMode)); 00179 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00180 00181 if (NewState != DISABLE) 00182 { 00183 SCB->SCR |= LowPowerMode; 00184 } 00185 else 00186 { 00187 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 00188 } 00189 } 00190 00191 /** 00192 * @brief Configures the SysTick clock source. 00193 * @param SysTick_CLKSource: specifies the SysTick clock source. 00194 * This parameter can be one of the following values: 00195 * @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source. 00196 * @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source. 00197 * @retval None 00198 */ 00199 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource) 00200 { 00201 /* Check the parameters */ 00202 assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource)); 00203 if (SysTick_CLKSource == SysTick_CLKSource_HCLK) 00204 { 00205 SysTick->CTRL |= SysTick_CLKSource_HCLK; 00206 } 00207 else 00208 { 00209 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8; 00210 } 00211 } 00212 00213 /** 00214 * @} 00215 */ 00216 00217 /** 00218 * @} 00219 */ 00220 00221 /** 00222 * @} 00223 */ 00224 00225 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
Generated on Tue Jul 12 2022 20:45:31 by
 1.7.2
 1.7.2