STM32F10x Standard Peripherals Library  3.5.0
/opt/STM32F10x_StdPeriph_Lib_V3.5.0/Libraries/STM32F10x_StdPeriph_Driver/src/stm32f10x_exti.c
Go to the documentation of this file.
00001 
00022 /* Includes ------------------------------------------------------------------*/
00023 #include "stm32f10x_exti.h"
00024 
00046 #define EXTI_LINENONE    ((uint32_t)0x00000)  /* No interrupt selected */
00047 
00085 void EXTI_DeInit(void)
00086 {
00087   EXTI->IMR = 0x00000000;
00088   EXTI->EMR = 0x00000000;
00089   EXTI->RTSR = 0x00000000; 
00090   EXTI->FTSR = 0x00000000; 
00091   EXTI->PR = 0x000FFFFF;
00092 }
00093 
00101 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
00102 {
00103   uint32_t tmp = 0;
00104 
00105   /* Check the parameters */
00106   assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
00107   assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
00108   assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));  
00109   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
00110 
00111   tmp = (uint32_t)EXTI_BASE;
00112      
00113   if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
00114   {
00115     /* Clear EXTI line configuration */
00116     EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
00117     EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
00118     
00119     tmp += EXTI_InitStruct->EXTI_Mode;
00120 
00121     *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
00122 
00123     /* Clear Rising Falling edge configuration */
00124     EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
00125     EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
00126     
00127     /* Select the trigger for the selected external interrupts */
00128     if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
00129     {
00130       /* Rising Falling edge */
00131       EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
00132       EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
00133     }
00134     else
00135     {
00136       tmp = (uint32_t)EXTI_BASE;
00137       tmp += EXTI_InitStruct->EXTI_Trigger;
00138 
00139       *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
00140     }
00141   }
00142   else
00143   {
00144     tmp += EXTI_InitStruct->EXTI_Mode;
00145 
00146     /* Disable the selected external lines */
00147     *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
00148   }
00149 }
00150 
00157 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
00158 {
00159   EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
00160   EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
00161   EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
00162   EXTI_InitStruct->EXTI_LineCmd = DISABLE;
00163 }
00164 
00171 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
00172 {
00173   /* Check the parameters */
00174   assert_param(IS_EXTI_LINE(EXTI_Line));
00175   
00176   EXTI->SWIER |= EXTI_Line;
00177 }
00178 
00186 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
00187 {
00188   FlagStatus bitstatus = RESET;
00189   /* Check the parameters */
00190   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
00191   
00192   if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
00193   {
00194     bitstatus = SET;
00195   }
00196   else
00197   {
00198     bitstatus = RESET;
00199   }
00200   return bitstatus;
00201 }
00202 
00209 void EXTI_ClearFlag(uint32_t EXTI_Line)
00210 {
00211   /* Check the parameters */
00212   assert_param(IS_EXTI_LINE(EXTI_Line));
00213   
00214   EXTI->PR = EXTI_Line;
00215 }
00216 
00224 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
00225 {
00226   ITStatus bitstatus = RESET;
00227   uint32_t enablestatus = 0;
00228   /* Check the parameters */
00229   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
00230   
00231   enablestatus =  EXTI->IMR & EXTI_Line;
00232   if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
00233   {
00234     bitstatus = SET;
00235   }
00236   else
00237   {
00238     bitstatus = RESET;
00239   }
00240   return bitstatus;
00241 }
00242 
00249 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
00250 {
00251   /* Check the parameters */
00252   assert_param(IS_EXTI_LINE(EXTI_Line));
00253   
00254   EXTI->PR = EXTI_Line;
00255 }
00256 
00269 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/