STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/misc.c
Go to the documentation of this file.
00001 
00023 /* Includes ------------------------------------------------------------------*/
00024 #include "misc.h"
00025 
00047 #define AIRCR_VECTKEY_MASK    ((uint32_t)0x05FA0000)
00048 
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 
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 
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 
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 
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 
00225 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/