stm32f10x_exti.c

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32f10x_exti.c
00004   * @author  MCD Application Team
00005   * @version V3.4.0
00006   * @date    10/15/2010
00007   * @brief   This file provides all the EXTI firmware functions.
00008   ******************************************************************************
00009   * @copy
00010   *
00011   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
00012   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
00013   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
00014   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
00015   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
00016   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
00017   *
00018   * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
00019   */ 
00020 
00021 /* Includes ------------------------------------------------------------------*/
00022 #include "stm32f10x_exti.h"
00023 
00024 /** @addtogroup STM32F10x_StdPeriph_Driver
00025   * @{
00026   */
00027 
00028 /** @defgroup EXTI 
00029   * @brief EXTI driver modules
00030   * @{
00031   */
00032 
00033 /** @defgroup EXTI_Private_TypesDefinitions
00034   * @{
00035   */
00036 
00037 /**
00038   * @}
00039   */
00040 
00041 /** @defgroup EXTI_Private_Defines
00042   * @{
00043   */
00044 
00045 #define EXTI_LINENONE    ((uint32_t)0x00000)  /* No interrupt selected */
00046 
00047 /**
00048   * @}
00049   */
00050 
00051 /** @defgroup EXTI_Private_Macros
00052   * @{
00053   */
00054 
00055 /**
00056   * @}
00057   */
00058 
00059 /** @defgroup EXTI_Private_Variables
00060   * @{
00061   */
00062 
00063 /**
00064   * @}
00065   */
00066 
00067 /** @defgroup EXTI_Private_FunctionPrototypes
00068   * @{
00069   */
00070 
00071 /**
00072   * @}
00073   */
00074 
00075 /** @defgroup EXTI_Private_Functions
00076   * @{
00077   */
00078 
00079 /**
00080   * @brief  Deinitializes the EXTI peripheral registers to their default reset values.
00081   * @param  None
00082   * @retval None
00083   */
00084 void EXTI_DeInit(void)
00085 {
00086   EXTI->IMR = 0x00000000;
00087   EXTI->EMR = 0x00000000;
00088   EXTI->RTSR = 0x00000000; 
00089   EXTI->FTSR = 0x00000000; 
00090   EXTI->PR = 0x000FFFFF;
00091 }
00092 
00093 /**
00094   * @brief  Initializes the EXTI peripheral according to the specified
00095   *   parameters in the EXTI_InitStruct.
00096   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
00097   *   that contains the configuration information for the EXTI peripheral.
00098   * @retval None
00099   */
00100 void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
00101 {
00102   uint32_t tmp = 0;
00103 
00104   /* Check the parameters */
00105   assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
00106   assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
00107   assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));  
00108   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
00109 
00110   tmp = (uint32_t)EXTI_BASE;
00111      
00112   if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
00113   {
00114     /* Clear EXTI line configuration */
00115     EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
00116     EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
00117     
00118     tmp += EXTI_InitStruct->EXTI_Mode;
00119 
00120     *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
00121 
00122     /* Clear Rising Falling edge configuration */
00123     EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
00124     EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
00125     
00126     /* Select the trigger for the selected external interrupts */
00127     if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
00128     {
00129       /* Rising Falling edge */
00130       EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
00131       EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
00132     }
00133     else
00134     {
00135       tmp = (uint32_t)EXTI_BASE;
00136       tmp += EXTI_InitStruct->EXTI_Trigger;
00137 
00138       *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
00139     }
00140   }
00141   else
00142   {
00143     tmp += EXTI_InitStruct->EXTI_Mode;
00144 
00145     /* Disable the selected external lines */
00146     *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
00147   }
00148 }
00149 
00150 /**
00151   * @brief  Fills each EXTI_InitStruct member with its reset value.
00152   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
00153   *   be initialized.
00154   * @retval None
00155   */
00156 void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
00157 {
00158   EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
00159   EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
00160   EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
00161   EXTI_InitStruct->EXTI_LineCmd = DISABLE;
00162 }
00163 
00164 /**
00165   * @brief  Generates a Software interrupt.
00166   * @param  EXTI_Line: specifies the EXTI lines to be enabled or disabled.
00167   *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
00168   * @retval None
00169   */
00170 void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
00171 {
00172   /* Check the parameters */
00173   assert_param(IS_EXTI_LINE(EXTI_Line));
00174   
00175   EXTI->SWIER |= EXTI_Line;
00176 }
00177 
00178 /**
00179   * @brief  Checks whether the specified EXTI line flag is set or not.
00180   * @param  EXTI_Line: specifies the EXTI line flag to check.
00181   *   This parameter can be:
00182   *     @arg EXTI_Linex: External interrupt line x where x(0..19)
00183   * @retval The new state of EXTI_Line (SET or RESET).
00184   */
00185 FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
00186 {
00187   FlagStatus bitstatus = RESET;
00188   /* Check the parameters */
00189   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
00190   
00191   if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
00192   {
00193     bitstatus = SET;
00194   }
00195   else
00196   {
00197     bitstatus = RESET;
00198   }
00199   return bitstatus;
00200 }
00201 
00202 /**
00203   * @brief  Clears the EXTIís line pending flags.
00204   * @param  EXTI_Line: specifies the EXTI lines flags to clear.
00205   *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
00206   * @retval None
00207   */
00208 void EXTI_ClearFlag(uint32_t EXTI_Line)
00209 {
00210   /* Check the parameters */
00211   assert_param(IS_EXTI_LINE(EXTI_Line));
00212   
00213   EXTI->PR = EXTI_Line;
00214 }
00215 
00216 /**
00217   * @brief  Checks whether the specified EXTI line is asserted or not.
00218   * @param  EXTI_Line: specifies the EXTI line to check.
00219   *   This parameter can be:
00220   *     @arg EXTI_Linex: External interrupt line x where x(0..19)
00221   * @retval The new state of EXTI_Line (SET or RESET).
00222   */
00223 ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
00224 {
00225   ITStatus bitstatus = RESET;
00226   uint32_t enablestatus = 0;
00227   /* Check the parameters */
00228   assert_param(IS_GET_EXTI_LINE(EXTI_Line));
00229   
00230   enablestatus =  EXTI->IMR & EXTI_Line;
00231   if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
00232   {
00233     bitstatus = SET;
00234   }
00235   else
00236   {
00237     bitstatus = RESET;
00238   }
00239   return bitstatus;
00240 }
00241 
00242 /**
00243   * @brief  Clears the EXTIís line pending bits.
00244   * @param  EXTI_Line: specifies the EXTI lines to clear.
00245   *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
00246   * @retval None
00247   */
00248 void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
00249 {
00250   /* Check the parameters */
00251   assert_param(IS_EXTI_LINE(EXTI_Line));
00252   
00253   EXTI->PR = EXTI_Line;
00254 }
00255 
00256 /**
00257   * @}
00258   */
00259 
00260 /**
00261   * @}
00262   */
00263 
00264 /**
00265   * @}
00266   */
00267 
00268 /******************* (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