PageRenderTime 26ms CodeModel.GetById 30ms RepoModel.GetById 1ms app.codeStats 0ms

/pinokernel/src/iodriver/STM32F4XX/stm32f4xx_exti.c

https://github.com/monyuonyu/pinoc
C | 311 lines | 94 code | 38 blank | 179 comment | 8 complexity | b8ea7966b63cbd099afeaa43bc97fef6 MD5 | raw file
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_exti.c
  4. * @author MCD Application Team
  5. * @version V1.5.1
  6. * @date 22-May-2015
  7. * @brief This file provides firmware functions to manage the following
  8. * functionalities of the EXTI peripheral:
  9. * + Initialization and Configuration
  10. * + Interrupts and flags management
  11. *
  12. @verbatim
  13. ===============================================================================
  14. ##### EXTI features #####
  15. ===============================================================================
  16. [..] External interrupt/event lines are mapped as following:
  17. (#) All available GPIO pins are connected to the 16 external
  18. interrupt/event lines from EXTI0 to EXTI15.
  19. (#) EXTI line 16 is connected to the PVD Output
  20. (#) EXTI line 17 is connected to the RTC Alarm event
  21. (#) EXTI line 18 is connected to the USB OTG FS Wakeup from suspend event
  22. (#) EXTI line 19 is connected to the Ethernet Wakeup event
  23. (#) EXTI line 20 is connected to the USB OTG HS (configured in FS) Wakeup event
  24. (#) EXTI line 21 is connected to the RTC Tamper and Time Stamp events
  25. (#) EXTI line 22 is connected to the RTC Wakeup event
  26. ##### How to use this driver #####
  27. ===============================================================================
  28. [..] In order to use an I/O pin as an external interrupt source, follow steps
  29. below:
  30. (#) Configure the I/O in input mode using GPIO_Init()
  31. (#) Select the input source pin for the EXTI line using SYSCFG_EXTILineConfig()
  32. (#) Select the mode(interrupt, event) and configure the trigger
  33. selection (Rising, falling or both) using EXTI_Init()
  34. (#) Configure NVIC IRQ channel mapped to the EXTI line using NVIC_Init()
  35. [..]
  36. (@) SYSCFG APB clock must be enabled to get write access to SYSCFG_EXTICRx
  37. registers using RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
  38. @endverbatim
  39. *
  40. ******************************************************************************
  41. * @attention
  42. *
  43. * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
  44. *
  45. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  46. * You may not use this file except in compliance with the License.
  47. * You may obtain a copy of the License at:
  48. *
  49. * http://www.st.com/software_license_agreement_liberty_v2
  50. *
  51. * Unless required by applicable law or agreed to in writing, software
  52. * distributed under the License is distributed on an "AS IS" BASIS,
  53. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  54. * See the License for the specific language governing permissions and
  55. * limitations under the License.
  56. *
  57. ******************************************************************************
  58. */
  59. /* Includes ------------------------------------------------------------------*/
  60. #include "stm32f4xx_exti.h"
  61. /** @addtogroup STM32F4xx_StdPeriph_Driver
  62. * @{
  63. */
  64. /** @defgroup EXTI
  65. * @brief EXTI driver modules
  66. * @{
  67. */
  68. /* Private typedef -----------------------------------------------------------*/
  69. /* Private define ------------------------------------------------------------*/
  70. #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
  71. /* Private macro -------------------------------------------------------------*/
  72. /* Private variables ---------------------------------------------------------*/
  73. /* Private function prototypes -----------------------------------------------*/
  74. /* Private functions ---------------------------------------------------------*/
  75. /** @defgroup EXTI_Private_Functions
  76. * @{
  77. */
  78. /** @defgroup EXTI_Group1 Initialization and Configuration functions
  79. * @brief Initialization and Configuration functions
  80. *
  81. @verbatim
  82. ===============================================================================
  83. ##### Initialization and Configuration functions #####
  84. ===============================================================================
  85. @endverbatim
  86. * @{
  87. */
  88. /**
  89. * @brief Deinitializes the EXTI peripheral registers to their default reset values.
  90. * @param None
  91. * @retval None
  92. */
  93. void EXTI_DeInit(void)
  94. {
  95. EXTI->IMR = 0x00000000;
  96. EXTI->EMR = 0x00000000;
  97. EXTI->RTSR = 0x00000000;
  98. EXTI->FTSR = 0x00000000;
  99. EXTI->PR = 0x007FFFFF;
  100. }
  101. /**
  102. * @brief Initializes the EXTI peripheral according to the specified
  103. * parameters in the EXTI_InitStruct.
  104. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure
  105. * that contains the configuration information for the EXTI peripheral.
  106. * @retval None
  107. */
  108. void EXTI_Init(EXTI_InitTypeDef* EXTI_InitStruct)
  109. {
  110. uint32_t tmp = 0;
  111. /* Check the parameters */
  112. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  113. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  114. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  115. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  116. tmp = (uint32_t)EXTI_BASE;
  117. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  118. {
  119. /* Clear EXTI line configuration */
  120. EXTI->IMR &= ~EXTI_InitStruct->EXTI_Line;
  121. EXTI->EMR &= ~EXTI_InitStruct->EXTI_Line;
  122. tmp += EXTI_InitStruct->EXTI_Mode;
  123. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  124. /* Clear Rising Falling edge configuration */
  125. EXTI->RTSR &= ~EXTI_InitStruct->EXTI_Line;
  126. EXTI->FTSR &= ~EXTI_InitStruct->EXTI_Line;
  127. /* Select the trigger for the selected external interrupts */
  128. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  129. {
  130. /* Rising Falling edge */
  131. EXTI->RTSR |= EXTI_InitStruct->EXTI_Line;
  132. EXTI->FTSR |= EXTI_InitStruct->EXTI_Line;
  133. }
  134. else
  135. {
  136. tmp = (uint32_t)EXTI_BASE;
  137. tmp += EXTI_InitStruct->EXTI_Trigger;
  138. *(__IO uint32_t *) tmp |= EXTI_InitStruct->EXTI_Line;
  139. }
  140. }
  141. else
  142. {
  143. tmp += EXTI_InitStruct->EXTI_Mode;
  144. /* Disable the selected external lines */
  145. *(__IO uint32_t *) tmp &= ~EXTI_InitStruct->EXTI_Line;
  146. }
  147. }
  148. /**
  149. * @brief Fills each EXTI_InitStruct member with its reset value.
  150. * @param EXTI_InitStruct: pointer to a EXTI_InitTypeDef structure which will
  151. * be initialized.
  152. * @retval None
  153. */
  154. void EXTI_StructInit(EXTI_InitTypeDef* EXTI_InitStruct)
  155. {
  156. EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  157. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  158. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  159. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  160. }
  161. /**
  162. * @brief Generates a Software interrupt on selected EXTI line.
  163. * @param EXTI_Line: specifies the EXTI line on which the software interrupt
  164. * will be generated.
  165. * This parameter can be any combination of EXTI_Linex where x can be (0..22)
  166. * @retval None
  167. */
  168. void EXTI_GenerateSWInterrupt(uint32_t EXTI_Line)
  169. {
  170. /* Check the parameters */
  171. assert_param(IS_EXTI_LINE(EXTI_Line));
  172. EXTI->SWIER |= EXTI_Line;
  173. }
  174. /**
  175. * @}
  176. */
  177. /** @defgroup EXTI_Group2 Interrupts and flags management functions
  178. * @brief Interrupts and flags management functions
  179. *
  180. @verbatim
  181. ===============================================================================
  182. ##### Interrupts and flags management functions #####
  183. ===============================================================================
  184. @endverbatim
  185. * @{
  186. */
  187. /**
  188. * @brief Checks whether the specified EXTI line flag is set or not.
  189. * @param EXTI_Line: specifies the EXTI line flag to check.
  190. * This parameter can be EXTI_Linex where x can be(0..22)
  191. * @retval The new state of EXTI_Line (SET or RESET).
  192. */
  193. FlagStatus EXTI_GetFlagStatus(uint32_t EXTI_Line)
  194. {
  195. FlagStatus bitstatus = RESET;
  196. /* Check the parameters */
  197. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  198. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  199. {
  200. bitstatus = SET;
  201. }
  202. else
  203. {
  204. bitstatus = RESET;
  205. }
  206. return bitstatus;
  207. }
  208. /**
  209. * @brief Clears the EXTI's line pending flags.
  210. * @param EXTI_Line: specifies the EXTI lines flags to clear.
  211. * This parameter can be any combination of EXTI_Linex where x can be (0..22)
  212. * @retval None
  213. */
  214. void EXTI_ClearFlag(uint32_t EXTI_Line)
  215. {
  216. /* Check the parameters */
  217. assert_param(IS_EXTI_LINE(EXTI_Line));
  218. EXTI->PR = EXTI_Line;
  219. }
  220. /**
  221. * @brief Checks whether the specified EXTI line is asserted or not.
  222. * @param EXTI_Line: specifies the EXTI line to check.
  223. * This parameter can be EXTI_Linex where x can be(0..22)
  224. * @retval The new state of EXTI_Line (SET or RESET).
  225. */
  226. ITStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  227. {
  228. FlagStatus bitstatus = RESET;
  229. /* Check the parameters */
  230. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  231. if ((EXTI->PR & EXTI_Line) != (uint32_t)RESET)
  232. {
  233. bitstatus = SET;
  234. }
  235. else
  236. {
  237. bitstatus = RESET;
  238. }
  239. return bitstatus;
  240. }
  241. /**
  242. * @brief Clears the EXTI's line pending bits.
  243. * @param EXTI_Line: specifies the EXTI lines to clear.
  244. * This parameter can be any combination of EXTI_Linex where x can be (0..22)
  245. * @retval None
  246. */
  247. void EXTI_ClearITPendingBit(uint32_t EXTI_Line)
  248. {
  249. /* Check the parameters */
  250. assert_param(IS_EXTI_LINE(EXTI_Line));
  251. EXTI->PR = EXTI_Line;
  252. }
  253. /**
  254. * @}
  255. */
  256. /**
  257. * @}
  258. */
  259. /**
  260. * @}
  261. */
  262. /**
  263. * @}
  264. */
  265. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/