n32g45x_exti.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_exti.c
  29. * @author Nations
  30. * @version v1.0.1
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #include "n32g45x_exti.h"
  35. /** @addtogroup N32G45X_StdPeriph_Driver
  36. * @{
  37. */
  38. /** @addtogroup EXTI
  39. * @brief EXTI driver modules
  40. * @{
  41. */
  42. /** @addtogroup EXTI_Private_TypesDefinitions
  43. * @{
  44. */
  45. /**
  46. * @}
  47. */
  48. /** @addtogroup EXTI_Private_Defines
  49. * @{
  50. */
  51. #define EXTI_LINENONE ((uint32_t)0x00000) /* No interrupt selected */
  52. /**
  53. * @}
  54. */
  55. /** @addtogroup EXTI_Private_Macros
  56. * @{
  57. */
  58. /**
  59. * @}
  60. */
  61. /** @addtogroup EXTI_Private_Variables
  62. * @{
  63. */
  64. /**
  65. * @}
  66. */
  67. /** @addtogroup EXTI_Private_FunctionPrototypes
  68. * @{
  69. */
  70. /**
  71. * @}
  72. */
  73. /** @addtogroup EXTI_Private_Functions
  74. * @{
  75. */
  76. /**
  77. * @brief Deinitializes the EXTI peripheral registers to their default reset values.
  78. */
  79. void EXTI_DeInit(void)
  80. {
  81. EXTI->IMASK = 0x00000000;
  82. EXTI->EMASK = 0x00000000;
  83. EXTI->RT_CFG = 0x00000000;
  84. EXTI->FT_CFG = 0x00000000;
  85. EXTI->PEND = 0x003FFFFF;
  86. }
  87. /**
  88. * @brief Initializes the EXTI peripheral according to the specified
  89. * parameters in the EXTI_InitStruct.
  90. * @param EXTI_InitStruct pointer to a EXTI_InitType structure
  91. * that contains the configuration information for the EXTI peripheral.
  92. */
  93. void EXTI_InitPeripheral(EXTI_InitType* EXTI_InitStruct)
  94. {
  95. uint32_t tmp = 0;
  96. /* Check the parameters */
  97. assert_param(IS_EXTI_MODE(EXTI_InitStruct->EXTI_Mode));
  98. assert_param(IS_EXTI_TRIGGER(EXTI_InitStruct->EXTI_Trigger));
  99. assert_param(IS_EXTI_LINE(EXTI_InitStruct->EXTI_Line));
  100. assert_param(IS_FUNCTIONAL_STATE(EXTI_InitStruct->EXTI_LineCmd));
  101. tmp = (uint32_t)EXTI_BASE;
  102. if (EXTI_InitStruct->EXTI_LineCmd != DISABLE)
  103. {
  104. /* Clear EXTI line configuration */
  105. EXTI->IMASK &= ~EXTI_InitStruct->EXTI_Line;
  106. EXTI->EMASK &= ~EXTI_InitStruct->EXTI_Line;
  107. tmp += EXTI_InitStruct->EXTI_Mode;
  108. *(__IO uint32_t*)tmp |= EXTI_InitStruct->EXTI_Line;
  109. /* Clear Rising Falling edge configuration */
  110. EXTI->RT_CFG &= ~EXTI_InitStruct->EXTI_Line;
  111. EXTI->FT_CFG &= ~EXTI_InitStruct->EXTI_Line;
  112. /* Select the trigger for the selected external interrupts */
  113. if (EXTI_InitStruct->EXTI_Trigger == EXTI_Trigger_Rising_Falling)
  114. {
  115. /* Rising Falling edge */
  116. EXTI->RT_CFG |= EXTI_InitStruct->EXTI_Line;
  117. EXTI->FT_CFG |= EXTI_InitStruct->EXTI_Line;
  118. }
  119. else
  120. {
  121. tmp = (uint32_t)EXTI_BASE;
  122. tmp += EXTI_InitStruct->EXTI_Trigger;
  123. *(__IO uint32_t*)tmp |= EXTI_InitStruct->EXTI_Line;
  124. }
  125. }
  126. else
  127. {
  128. tmp += EXTI_InitStruct->EXTI_Mode;
  129. /* Disable the selected external lines */
  130. *(__IO uint32_t*)tmp &= ~EXTI_InitStruct->EXTI_Line;
  131. }
  132. }
  133. /**
  134. * @brief Fills each EXTI_InitStruct member with its reset value.
  135. * @param EXTI_InitStruct pointer to a EXTI_InitType structure which will
  136. * be initialized.
  137. */
  138. void EXTI_InitStruct(EXTI_InitType* EXTI_InitStruct)
  139. {
  140. EXTI_InitStruct->EXTI_Line = EXTI_LINENONE;
  141. EXTI_InitStruct->EXTI_Mode = EXTI_Mode_Interrupt;
  142. EXTI_InitStruct->EXTI_Trigger = EXTI_Trigger_Falling;
  143. EXTI_InitStruct->EXTI_LineCmd = DISABLE;
  144. }
  145. /**
  146. * @brief Generates a Software interrupt.
  147. * @param EXTI_Line specifies the EXTI lines to be enabled or disabled.
  148. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  149. */
  150. void EXTI_TriggerSWInt(uint32_t EXTI_Line)
  151. {
  152. /* Check the parameters */
  153. assert_param(IS_EXTI_LINE(EXTI_Line));
  154. EXTI->SWIE |= EXTI_Line;
  155. }
  156. /**
  157. * @brief Checks whether the specified EXTI line flag is set or not.
  158. * @param EXTI_Line specifies the EXTI line flag to check.
  159. * This parameter can be:
  160. * @arg EXTI_Linex External interrupt line x where x(0..19)
  161. * @return The new state of EXTI_Line (SET or RESET).
  162. */
  163. FlagStatus EXTI_GetStatusFlag(uint32_t EXTI_Line)
  164. {
  165. FlagStatus bitstatus = RESET;
  166. /* Check the parameters */
  167. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  168. if ((EXTI->PEND & EXTI_Line) != (uint32_t)RESET)
  169. {
  170. bitstatus = SET;
  171. }
  172. else
  173. {
  174. bitstatus = RESET;
  175. }
  176. return bitstatus;
  177. }
  178. /**
  179. * @brief Clears the EXTI's line pending flags.
  180. * @param EXTI_Line specifies the EXTI lines flags to clear.
  181. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  182. */
  183. void EXTI_ClrStatusFlag(uint32_t EXTI_Line)
  184. {
  185. /* Check the parameters */
  186. assert_param(IS_EXTI_LINE(EXTI_Line));
  187. EXTI->PEND = EXTI_Line;
  188. }
  189. /**
  190. * @brief Checks whether the specified EXTI line is asserted or not.
  191. * @param EXTI_Line specifies the EXTI line to check.
  192. * This parameter can be:
  193. * @arg EXTI_Linex External interrupt line x where x(0..19)
  194. * @return The new state of EXTI_Line (SET or RESET).
  195. */
  196. INTStatus EXTI_GetITStatus(uint32_t EXTI_Line)
  197. {
  198. INTStatus bitstatus = RESET;
  199. uint32_t enablestatus = 0;
  200. /* Check the parameters */
  201. assert_param(IS_GET_EXTI_LINE(EXTI_Line));
  202. enablestatus = EXTI->IMASK & EXTI_Line;
  203. if (((EXTI->PEND & EXTI_Line) != (uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  204. {
  205. bitstatus = SET;
  206. }
  207. else
  208. {
  209. bitstatus = RESET;
  210. }
  211. return bitstatus;
  212. }
  213. /**
  214. * @brief Clears the EXTI's line pending bits.
  215. * @param EXTI_Line specifies the EXTI lines to clear.
  216. * This parameter can be any combination of EXTI_Linex where x can be (0..19).
  217. */
  218. void EXTI_ClrITPendBit(uint32_t EXTI_Line)
  219. {
  220. /* Check the parameters */
  221. assert_param(IS_EXTI_LINE(EXTI_Line));
  222. EXTI->PEND = EXTI_Line;
  223. }
  224. /**
  225. * @brief Select one of EXTI inputs to the RTC TimeStamp event.
  226. * @param EXTI_TSSEL_Line specifies the EXTI lines to select.
  227. * This parameter can be any combination of EXTI_TSSEL_Line where x can be (0..15).
  228. */
  229. void EXTI_RTCTimeStampSel(uint32_t EXTI_TSSEL_Line)
  230. {
  231. /* Check the parameters */
  232. assert_param(IS_EXTI_TSSEL_LINE(EXTI_TSSEL_Line));
  233. EXTI->TSSEL &= EXTI_TSSEL_TSSEL_ALL;
  234. EXTI->TSSEL |= EXTI_TSSEL_Line;
  235. }
  236. /**
  237. * @}
  238. */
  239. /**
  240. * @}
  241. */
  242. /**
  243. * @}
  244. */