misc.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    misc.c
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   This file provides all the miscellaneous firmware functions (add-on
00008   *          to CMSIS functions).
00009   ******************************************************************************
00010   * @copy
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>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00020   */ 
00021 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "misc.h"
00024 
00025 /** @addtogroup STM32F10x_StdPeriph_Driver
00026   * @{
00027   */
00028 
00029 /** @defgroup MISC 
00030   * @brief MISC driver modules
00031   * @{
00032   */
00033 
00034 /** @defgroup MISC_Private_TypesDefinitions
00035   * @{
00036   */
00037 
00038 /**
00039   * @}
00040   */ 
00041 
00042 /** @defgroup MISC_Private_Defines
00043   * @{
00044   */
00045 
00046 #define AIRCR_VECTKEY_MASK    ((uint32_t)0x05FA0000)
00047 /**
00048   * @}
00049   */
00050 
00051 /** @defgroup MISC_Private_Macros
00052   * @{
00053   */
00054 
00055 /**
00056   * @}
00057   */
00058 
00059 /** @defgroup MISC_Private_Variables
00060   * @{
00061   */
00062 
00063 /**
00064   * @}
00065   */
00066 
00067 /** @defgroup MISC_Private_FunctionPrototypes
00068   * @{
00069   */
00070 
00071 /**
00072   * @}
00073   */
00074 
00075 /** @defgroup MISC_Private_Functions
00076   * @{
00077   */
00078 
00079 /**
00080   * @brief  Configures the priority grouping: pre-emption priority and subpriority.
00081   * @param  NVIC_PriorityGroup: specifies the priority grouping bits length. 
00082   *   This parameter can be one of the following values:
00083   *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority
00084   *                                4 bits for subpriority
00085   *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority
00086   *                                3 bits for subpriority
00087   *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority
00088   *                                2 bits for subpriority
00089   *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority
00090   *                                1 bits for subpriority
00091   *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority
00092   *                                0 bits for subpriority
00093   * @retval None
00094   */
00095 void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup)
00096 {
00097   /* Check the parameters */
00098   assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));
00099   
00100   /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */
00101   SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;
00102 }
00103 
00104 /**
00105   * @brief  Initializes the NVIC peripheral according to the specified
00106   *   parameters in the NVIC_InitStruct.
00107   * @param  NVIC_InitStruct: pointer to a NVIC_InitTypeDef structure that contains
00108   *   the configuration information for the specified NVIC peripheral.
00109   * @retval None
00110   */
00111 void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct)
00112 {
00113   uint32_t tmppriority = 0x00, tmppre = 0x00, tmpsub = 0x0F;
00114   
00115   /* Check the parameters */
00116   assert_param(IS_FUNCTIONAL_STATE(NVIC_InitStruct->NVIC_IRQChannelCmd));
00117   assert_param(IS_NVIC_PREEMPTION_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority));  
00118   assert_param(IS_NVIC_SUB_PRIORITY(NVIC_InitStruct->NVIC_IRQChannelSubPriority));
00119     
00120   if (NVIC_InitStruct->NVIC_IRQChannelCmd != DISABLE)
00121   {
00122     /* Compute the Corresponding IRQ Priority --------------------------------*/    
00123     tmppriority = (0x700 - ((SCB->AIRCR) & (uint32_t)0x700))>> 0x08;
00124     tmppre = (0x4 - tmppriority);
00125     tmpsub = tmpsub >> tmppriority;
00126 
00127     tmppriority = (uint32_t)NVIC_InitStruct->NVIC_IRQChannelPreemptionPriority << tmppre;
00128     tmppriority |=  NVIC_InitStruct->NVIC_IRQChannelSubPriority & tmpsub;
00129     tmppriority = tmppriority << 0x04;
00130         
00131     NVIC->IP[NVIC_InitStruct->NVIC_IRQChannel] = tmppriority;
00132     
00133     /* Enable the Selected IRQ Channels --------------------------------------*/
00134     NVIC->ISER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
00135       (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
00136   }
00137   else
00138   {
00139     /* Disable the Selected IRQ Channels -------------------------------------*/
00140     NVIC->ICER[NVIC_InitStruct->NVIC_IRQChannel >> 0x05] =
00141       (uint32_t)0x01 << (NVIC_InitStruct->NVIC_IRQChannel & (uint8_t)0x1F);
00142   }
00143 }
00144 
00145 /**
00146   * @brief  Sets the vector table location and Offset.
00147   * @param  NVIC_VectTab: specifies if the vector table is in RAM or FLASH memory.
00148   *   This parameter can be one of the following values:
00149   *     @arg NVIC_VectTab_RAM
00150   *     @arg NVIC_VectTab_FLASH
00151   * @param  Offset: Vector Table base offset field. This value must be a multiple of 0x100.
00152   * @retval None
00153   */
00154 void NVIC_SetVectorTable(uint32_t NVIC_VectTab, uint32_t Offset)
00155 { 
00156   /* Check the parameters */
00157   assert_param(IS_NVIC_VECTTAB(NVIC_VectTab));
00158   assert_param(IS_NVIC_OFFSET(Offset));  
00159    
00160   SCB->VTOR = NVIC_VectTab | (Offset & (uint32_t)0x1FFFFF80);
00161 }
00162 
00163 /**
00164   * @brief  Selects the condition for the system to enter low power mode.
00165   * @param  LowPowerMode: Specifies the new mode for the system to enter low power mode.
00166   *   This parameter can be one of the following values:
00167   *     @arg NVIC_LP_SEVONPEND
00168   *     @arg NVIC_LP_SLEEPDEEP
00169   *     @arg NVIC_LP_SLEEPONEXIT
00170   * @param  NewState: new state of LP condition. This parameter can be: ENABLE or DISABLE.
00171   * @retval None
00172   */
00173 void NVIC_SystemLPConfig(uint8_t LowPowerMode, FunctionalState NewState)
00174 {
00175   /* Check the parameters */
00176   assert_param(IS_NVIC_LP(LowPowerMode));
00177   assert_param(IS_FUNCTIONAL_STATE(NewState));  
00178   
00179   if (NewState != DISABLE)
00180   {
00181     SCB->SCR |= LowPowerMode;
00182   }
00183   else
00184   {
00185     SCB->SCR &= (uint32_t)(~(uint32_t)LowPowerMode);
00186   }
00187 }
00188 
00189 /**
00190   * @brief  Configures the SysTick clock source.
00191   * @param  SysTick_CLKSource: specifies the SysTick clock source.
00192   *   This parameter can be one of the following values:
00193   *     @arg SysTick_CLKSource_HCLK_Div8: AHB clock divided by 8 selected as SysTick clock source.
00194   *     @arg SysTick_CLKSource_HCLK: AHB clock selected as SysTick clock source.
00195   * @retval None
00196   */
00197 void SysTick_CLKSourceConfig(uint32_t SysTick_CLKSource)
00198 {
00199   /* Check the parameters */
00200   assert_param(IS_SYSTICK_CLK_SOURCE(SysTick_CLKSource));
00201   if (SysTick_CLKSource == SysTick_CLKSource_HCLK)
00202   {
00203     SysTick->CTRL |= SysTick_CLKSource_HCLK;
00204   }
00205   else
00206   {
00207     SysTick->CTRL &= SysTick_CLKSource_HCLK_Div8;
00208   }
00209 }
00210 
00211 /**
00212   * @}
00213   */
00214 
00215 /**
00216   * @}
00217   */
00218 
00219 /**
00220   * @}
00221   */
00222 
00223 /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
STM32F10x Standard Peripherals Library: Footer

 

 

 

      For complete documentation on STM32(CORTEX M3) 32-bit Microcontrollers platform visit  www.st.com/STM32