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_mort.c
00001 /** 00002 ****************************************************************************** 00003 * @file misc.c 00004 * @author MCD Application Team 00005 * @version V1.8.0 00006 * @date 04-November-2016 00007 * @brief This file provides all the miscellaneous firmware functions (add-on 00008 * to CMSIS functions). 00009 * 00010 * @verbatim 00011 * 00012 * =================================================================== 00013 * How to configure Interrupts using driver 00014 * =================================================================== 00015 * 00016 * This section provide functions allowing to configure the NVIC interrupts (IRQ). 00017 * The Cortex-M4 exceptions are managed by CMSIS functions. 00018 * 00019 * 1. Configure the NVIC Priority Grouping using NVIC_PriorityGroupConfig_mort() 00020 * function according to the following table. 00021 00022 * The table below gives the allowed values of the pre-emption priority and subpriority according 00023 * to the Priority Grouping configuration performed by NVIC_PriorityGroupConfig_mort function 00024 * ========================================================================================================================== 00025 * NVIC_PriorityGroup | NVIC_IRQChannelPreemptionPriority | NVIC_IRQChannelSubPriority | Description 00026 * ========================================================================================================================== 00027 * NVIC_PriorityGroup_0_MORT | 0 | 0-15 | 0 bits for pre-emption priority 00028 * | | | 4 bits for subpriority 00029 * -------------------------------------------------------------------------------------------------------------------------- 00030 * NVIC_PriorityGroup_1_MORT | 0-1 | 0-7 | 1 bits for pre-emption priority 00031 * | | | 3 bits for subpriority 00032 * -------------------------------------------------------------------------------------------------------------------------- 00033 * NVIC_PriorityGroup_2_MORT | 0-3 | 0-3 | 2 bits for pre-emption priority 00034 * | | | 2 bits for subpriority 00035 * -------------------------------------------------------------------------------------------------------------------------- 00036 * NVIC_PriorityGroup_3_MORT | 0-7 | 0-1 | 3 bits for pre-emption priority 00037 * | | | 1 bits for subpriority 00038 * -------------------------------------------------------------------------------------------------------------------------- 00039 * NVIC_PriorityGroup_4_MORT | 0-15 | 0 | 4 bits for pre-emption priority 00040 * | | | 0 bits for subpriority 00041 * ========================================================================================================================== 00042 * 00043 * 2. Enable and Configure the priority of the selected IRQ Channels using NVIC_Init_mort() 00044 * 00045 * @note When the NVIC_PriorityGroup_0_MORT is selected, IRQ pre-emption is no more possible. 00046 * The pending IRQ priority will be managed only by the subpriority. 00047 * 00048 * @note IRQ priority order (sorted by highest to lowest priority): 00049 * - Lowest pre-emption priority 00050 * - Lowest subpriority 00051 * - Lowest hardware priority (IRQ number) 00052 * 00053 * @endverbatim 00054 * 00055 ****************************************************************************** 00056 * @attention 00057 * 00058 * <h2><center>© COPYRIGHT 2016 STMicroelectronics</center></h2> 00059 * 00060 * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License"); 00061 * You may not use this file except in compliance with the License. 00062 * You may obtain a copy of the License at: 00063 * 00064 * http://www.st.com/software_license_agreement_liberty_v2 00065 * 00066 * Unless required by applicable law or agreed to in writing, software 00067 * distributed under the License is distributed on an "AS IS" BASIS, 00068 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00069 * See the License for the specific language governing permissions and 00070 * limitations under the License. 00071 * 00072 ****************************************************************************** 00073 */ 00074 00075 /* Includes ------------------------------------------------------------------*/ 00076 #include "misc_mort.h" 00077 00078 /** @addtogroup STM32F4xx_StdPeriph_Driver 00079 * @{ 00080 */ 00081 00082 /** @defgroup MISC 00083 * @brief MISC driver modules 00084 * @{ 00085 */ 00086 00087 /* Private typedef -----------------------------------------------------------*/ 00088 /* Private define ------------------------------------------------------------*/ 00089 #define AIRCR_VECTKEY_MASK ((uint32_t)0x05FA0000) 00090 00091 /* Private macro -------------------------------------------------------------*/ 00092 /* Private variables ---------------------------------------------------------*/ 00093 /* Private function prototypes -----------------------------------------------*/ 00094 /* Private functions ---------------------------------------------------------*/ 00095 00096 /** @defgroup MISC_Private_Functions 00097 * @{ 00098 */ 00099 00100 /** 00101 * @brief Configures the priority grouping: pre-emption priority and subpriority. 00102 * @param NVIC_PriorityGroup: specifies the priority grouping bits length. 00103 * This parameter can be one of the following values: 00104 * @arg NVIC_PriorityGroup_0_MORT: 0 bits for pre-emption priority 00105 * 4 bits for subpriority 00106 * @arg NVIC_PriorityGroup_1_MORT: 1 bits for pre-emption priority 00107 * 3 bits for subpriority 00108 * @arg NVIC_PriorityGroup_2_MORT: 2 bits for pre-emption priority 00109 * 2 bits for subpriority 00110 * @arg NVIC_PriorityGroup_3_MORT: 3 bits for pre-emption priority 00111 * 1 bits for subpriority 00112 * @arg NVIC_PriorityGroup_4_MORT: 4 bits for pre-emption priority 00113 * 0 bits for subpriority 00114 * @note When the NVIC_PriorityGroup_0_MORT is selected, IRQ pre-emption is no more possible. 00115 * The pending IRQ priority will be managed only by the subpriority. 00116 * @retval None 00117 */ 00118 void NVIC_PriorityGroupConfig_mort(uint32_t NVIC_PriorityGroup) 00119 { 00120 /* Check the parameters */ 00121 assert_param(IS_NVIC_PRIORITY_GROUP_MORT(NVIC_PriorityGroup)); 00122 00123 /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */ 00124 SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup; 00125 } 00126 00127 /** 00128 * @brief Initializes the NVIC peripheral according to the specified 00129 * parameters in the NVIC_InitStruct. 00130 * @note To configure interrupts priority correctly, the NVIC_PriorityGroupConfig_mort() 00131 * function should be called before. 00132 * @param NVIC_InitStruct: pointer to a NVIC_InitTypeDef_mort structure that contains 00133 * the configuration information for the specified NVIC peripheral. 00134 * @retval None 00135 */ 00136 void NVIC_Init_mort(NVIC_InitTypeDef_mort* NVIC_InitStruct) 00137 { 00138 uint8_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F; 00139 00140 /* Check the parameters */ 00141 assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd)); 00142 assert_param(IS_NVIC_PREEMPTION_PRIORITY_MORT(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority)); 00143 assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority)); 00144 00145 if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE) 00146 { 00147 /* Compute the Corresponding IRQ Priority --------------------------------*/ 00148 tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08; 00149 tmppre = (0x4 - tmppriority); 00150 tmpsub = tmpsub >> tmppriority; 00151 00152 tmppriority = NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre; 00153 tmppriority |= (uint8_t)(NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub); 00154 00155 tmppriority = tmppriority << 0x04; 00156 00157 NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority; 00158 00159 /* Enable the Selected IRQ Channels --------------------------------------*/ 00160 NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 00161 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 00162 } 00163 else 00164 { 00165 /* Disable the Selected IRQ Channels -------------------------------------*/ 00166 NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] = 00167 (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F); 00168 } 00169 } 00170 00171 /** 00172 * @brief Sets the vector table location and Offset. 00173 * @param NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory. 00174 * This parameter can be one of the following values: 00175 * @arg NVIC_VectTab_RAM_MORT: Vector Table in internal SRAM. 00176 * @arg NVIC_VectTab_FLASH_MORT: Vector Table in internal FLASH. 00177 * @param Offset: Vector Table base offset field. This value must be a multiple of 0x200. 00178 * @retval None 00179 */ 00180 void NVIC_SetVectorTable_mort(uint32_t NVIC_VectTab, uint32_t Offset) 00181 { 00182 /* Check the parameters */ 00183 assert_param(IS_NVIC_VECTTAB_MORT(NVIC_VectTab)); 00184 assert_param(IS_NVIC_OFFSET_MORT(Offset)); 00185 00186 SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80); 00187 } 00188 00189 /** 00190 * @brief Selects the condition for the system to enter low power mode. 00191 * @param LowPowerMode: Specifies the new mode for the system to enter low power mode. 00192 * This parameter can be one of the following values: 00193 * @arg NVIC_LP_SEVONPEND_MORT: Low Power SEV on Pend. 00194 * @arg NVIC_LP_SLEEPDEEP_MORT: Low Power DEEPSLEEP request. 00195 * @arg NVIC_LP_SLEEPONEXIT_MORT: Low Power Sleep on Exit. 00196 * @param NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE. 00197 * @retval None 00198 */ 00199 void NVIC_SystemLPConfig_mort(uint8_t LowPowerMode, FunctionalState NewState) 00200 { 00201 /* Check the parameters */ 00202 assert_param(IS_NVIC_LP_MORT(LowPowerMode)); 00203 assert_param(IS_FUNCTIONAL_STATE(NewState)); 00204 00205 if (NewState != DISABLE) 00206 { 00207 SCB->SCR |= LowPowerMode; 00208 } 00209 else 00210 { 00211 SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode); 00212 } 00213 } 00214 00215 /** 00216 * @brief Configures the SysTick clock source. 00217 * @param SysTick_CLKSource: specifies the SysTick clock source. 00218 * This parameter can be one of the following values: 00219 * @arg SysTick_CLKSource_HCLK_Div8_MORT: AHB clock divided by 8 selected as SysTick clock source. 00220 * @arg SysTick_CLKSource_HCLK_MORT: AHB clock selected as SysTick clock source. 00221 * @retval None 00222 */ 00223 void SysTick_CLKSourceConfig_mort(uint32_t SysTick_CLKSource) 00224 { 00225 /* Check the parameters */ 00226 assert_param(IS_SYSTICK_CLK_SOURCE_MORT(SysTick_CLKSource)); 00227 if (SysTick_CLKSource == SysTick_CLKSource_HCLK_MORT) 00228 { 00229 SysTick->CTRL |= SysTick_CLKSource_HCLK_MORT; 00230 } 00231 else 00232 { 00233 SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8_MORT; 00234 } 00235 } 00236 00237 /** 00238 * @} 00239 */ 00240 00241 /** 00242 * @} 00243 */ 00244 00245 /** 00246 * @} 00247 */ 00248 00249 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00250 00251 00252 00253 00254
Generated on Mon Jan 16 2023 14:41:56 by
1.7.2