找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 3404|回复: 0
打印 上一主题 下一主题
收起左侧

stm32f10x_exti.c

[复制链接]
跳转到指定楼层
楼主
ID:72519 发表于 2015-1-23 03:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. /**
  2.   ******************************************************************************
  3.   * @file    stm32f10x_exti.c
  4.   * @author  MCD Application Team
  5.   * @version V3.5.0
  6.   * @date    11-March-2011
  7.   * @brief   This file provides all the EXTI firmware functions.
  8.   ******************************************************************************
  9.   * @attention
  10.   *
  11.   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12.   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13.   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14.   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15.   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16.   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17.   *
  18.   * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
  19.   ******************************************************************************
  20.   */
  21. /* Includes ------------------------------------------------------------------*/
  22. #include "stm32f10x_exti.h"
  23. /** @addtogroup STM32F10x_StdPeriph_Driver
  24.   * @{
  25.   */
  26. /** @defgroup EXTI
  27.   * @brief EXTI driver modules
  28.   * @{
  29.   */
  30. /** @defgroup EXTI_Private_TypesDefinitions
  31.   * @{
  32.   */
  33. /**
  34.   * @}
  35.   */
  36. /** @defgroup EXTI_Private_Defines
  37.   * @{
  38.   */
  39. #define EXTI_LINENONE    ((uint32_t)0x00000)  /* No interrupt selected */
  40. /**
  41.   * @}
  42.   */
  43. /** @defgroup EXTI_Private_Macros
  44.   * @{
  45.   */
  46. /**
  47.   * @}
  48.   */
  49. /** @defgroup EXTI_Private_Variables
  50.   * @{
  51.   */
  52. /**
  53.   * @}
  54.   */
  55. /** @defgroup EXTI_Private_FunctionPrototypes
  56.   * @{
  57.   */
  58. /**
  59.   * @}
  60.   */
  61. /** @defgroup EXTI_Private_Functions
  62.   * @{
  63.   */
  64. /**
  65.   * @brief  Deinitializes the EXTI peripheral registers to their default reset values.
  66.   * @param  None
  67.   * @retval None
  68.   */
  69. void EXTI_DeInit(void)//外部中断初始化为默认值
  70. {
  71.   EXTI->IMR = 0x00000000;
  72.   EXTI->EMR = 0x00000000;
  73.   EXTI->RTSR = 0x00000000;
  74.   EXTI->FTSR = 0x00000000;
  75.   EXTI->PR = 0x000FFFFF;
  76. }
  77. /**
  78.   * @brief  Initializes the EXTI peripheral according to the specified
  79.   *         parameters in the EXTI_InitStruct.
  80.   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  81.   *         that contains the configuration information for the EXTI peripheral.
  82.   * @retval None
  83.   */
  84. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)//外部中断根据结构体的参数进行初始化
  85. {
  86.   uint32_t tmp = 0;
  87.   /* Check the parameters */
  88.   assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  89.   assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  90.   assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  91.   assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  92.   tmp = (uint32_t)EXTI_BASE;
  93.    
  94.   if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  95.   {
  96.     /* Clear EXTI line configuration */
  97.     EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  98.     EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  99.    
  100.     tmp += EXTI_InitStruct->EXTI_Mode;
  101.     *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  102.     /* Clear Rising Falling edge configuration */
  103.     EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  104.     EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  105.    
  106.     /* Select the trigger for the selected external interrupts */
  107.     if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  108.     {
  109.       /* Rising Falling edge */
  110.       EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  111.       EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  112.     }
  113.     else
  114.     {
  115.       tmp = (uint32_t)EXTI_BASE;
  116.       tmp += EXTI_InitStruct->EXTI_Trigger;
  117.       *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  118.     }
  119.   }
  120.   else
  121.   {
  122.     tmp += EXTI_InitStruct->EXTI_Mode;
  123.     /* Disable the selected external lines */
  124.     *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  125.   }
  126. }
  127. /**
  128.   * @brief  Fills each EXTI_InitStruct member with its reset value.
  129.   * @param  EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  130.   *         be initialized.
  131.   * @retval None
  132.   */
  133. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)//外部中断的结构体参数恢复为默认值
  134. {
  135.   EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  136.   EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  137.   EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  138.   EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  139. }
  140. /**
  141.   * @brief  Generates a Software interrupt.
  142.   * @param  EXTI_Line: specifies the EXTI lines to be enabled or disabled.
  143.   *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
  144.   * @retval None
  145.   */
  146. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)//产生一个软件中断
  147. {
  148.   /* Check the parameters */
  149.   assert_param(IS_EXTI_LINE(EXTI_Line));

  150.   EXTI->SWIER |= EXTI_Line;
  151. }
  152. /**
  153.   * @brief  Checks whether the specified EXTI line flag is set or not.
  154.   * @param  EXTI_Line: specifies the EXTI line flag to check.
  155.   *   This parameter can be:
  156.   *     @arg EXTI_Linex: External interrupt line x where x(0..19)
  157.   * @retval The new state of EXTI_Line (SET or RESET).
  158.   */
  159. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)//检测外部中断的标志的状态
  160. {
  161.   FlagStatus bitstatus = RESET;
  162.   /* Check the parameters */
  163.   assert_param(IS_GET_EXTI_LINE(EXTI_Line));

  164.   if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  165.   {
  166.     bitstatus = SET;
  167.   }
  168.   else
  169.   {
  170.     bitstatus = RESET;
  171.   }
  172.   return bitstatus;
  173. }
  174. /**
  175.   * @brief  Clears the EXTI's line pending flags.
  176.   * @param  EXTI_Line: specifies the EXTI lines flags to clear.
  177.   *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
  178.   * @retval None
  179.   */
  180. void EXTI_ClearFlag(uint32_t EXTI_Line)//清除外部中断的标志
  181. {
  182.   /* Check the parameters */
  183.   assert_param(IS_EXTI_LINE(EXTI_Line));

  184.   EXTI->PR = EXTI_Line;
  185. }
  186. /**
  187.   * @brief  Checks whether the specified EXTI line is asserted or not.
  188.   * @param  EXTI_Line: specifies the EXTI line to check.
  189.   *   This parameter can be:
  190.   *     @arg EXTI_Linex: External interrupt line x where x(0..19)
  191.   * @retval The new state of EXTI_Line (SET or RESET).
  192.   */
  193. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)//检测使能的外部中断的标志的状态
  194. {
  195.   ITStatus bitstatus = RESET;
  196.   uint32_t enablestatus = 0;
  197.   /* Check the parameters */
  198.   assert_param(IS_GET_EXTI_LINE(EXTI_Line));

  199.   enablestatus =  EXTI->IMR & EXTI_Line;
  200.   if (((EXTI->PR & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  201.   {
  202.     bitstatus = SET;
  203.   }
  204.   else
  205.   {
  206.     bitstatus = RESET;
  207.   }
  208.   return bitstatus;
  209. }
  210. /**
  211.   * @brief  Clears the EXTI's line pending bits.
  212.   * @param  EXTI_Line: specifies the EXTI lines to clear.
  213.   *   This parameter can be any combination of EXTI_Linex where x can be (0..19).
  214.   * @retval None
  215.   */
  216. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)//清除外部中断的挂起位
  217. {
  218.   /* Check the parameters */
  219.   assert_param(IS_EXTI_LINE(EXTI_Line));

  220.   EXTI->PR = EXTI_Line;
  221. }
  222. /**
  223.   * @}
  224.   */
  225. /**
  226.   * @}
  227.   */
  228. /**
  229.   * @}
  230.   */
  231. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表