at32f413_exint.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. /**
  2. **************************************************************************
  3. * @file at32f413_exint.c
  4. * @brief contains all the functions for the exint firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f413_conf.h"
  25. /** @addtogroup AT32F413_periph_driver
  26. * @{
  27. */
  28. /** @defgroup EXINT
  29. * @brief EXINT driver modules
  30. * @{
  31. */
  32. #ifdef EXINT_MODULE_ENABLED
  33. /** @defgroup EXINT_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief exint reset
  38. * @param none
  39. * @retval none
  40. */
  41. void exint_reset(void)
  42. {
  43. EXINT->inten = 0x00000000;
  44. EXINT->polcfg1 = 0x00000000;
  45. EXINT->polcfg2 = 0x00000000;
  46. EXINT->evten = 0x00000000;
  47. EXINT->intsts = 0x0007FFFF;
  48. }
  49. /**
  50. * @brief exint default para init
  51. * @param exint_struct
  52. * - to the structure of exint_init_type
  53. * @retval none
  54. */
  55. void exint_default_para_init(exint_init_type *exint_struct)
  56. {
  57. exint_struct->line_enable = FALSE;
  58. exint_struct->line_select = EXINT_LINE_NONE;
  59. exint_struct->line_polarity = EXINT_TRIGGER_FALLING_EDGE;
  60. exint_struct->line_mode = EXINT_LINE_EVENT;
  61. }
  62. /**
  63. * @brief exint init
  64. * @param exint_struct
  65. * - to the structure of exint_init_type
  66. * @retval none
  67. */
  68. void exint_init(exint_init_type *exint_struct)
  69. {
  70. uint32_t line_index = 0;
  71. line_index = exint_struct->line_select;
  72. EXINT->inten &= ~line_index;
  73. EXINT->evten &= ~line_index;
  74. if(exint_struct->line_enable != FALSE)
  75. {
  76. if(exint_struct->line_mode == EXINT_LINE_INTERRUPUT)
  77. {
  78. EXINT->inten |= line_index;
  79. }
  80. else
  81. {
  82. EXINT->evten |= line_index;
  83. }
  84. EXINT->polcfg1 &= ~line_index;
  85. EXINT->polcfg2 &= ~line_index;
  86. if(exint_struct->line_polarity == EXINT_TRIGGER_RISING_EDGE)
  87. {
  88. EXINT->polcfg1 |= line_index;
  89. }
  90. else if(exint_struct->line_polarity == EXINT_TRIGGER_FALLING_EDGE)
  91. {
  92. EXINT->polcfg2 |= line_index;
  93. }
  94. else
  95. {
  96. EXINT->polcfg1 |= line_index;
  97. EXINT->polcfg2 |= line_index;
  98. }
  99. }
  100. }
  101. /**
  102. * @brief clear exint flag
  103. * @param exint_line
  104. * this parameter can be any combination of the following values:
  105. * - EXINT_LINE_0
  106. * - EXINT_LINE_1
  107. * ...
  108. * - EXINT_LINE_17
  109. * - EXINT_LINE_18
  110. * @retval none
  111. */
  112. void exint_flag_clear(uint32_t exint_line)
  113. {
  114. EXINT->intsts = exint_line;
  115. }
  116. /**
  117. * @brief get exint flag
  118. * @param exint_line
  119. * this parameter can be one of the following values:
  120. * - EXINT_LINE_0
  121. * - EXINT_LINE_1
  122. * ...
  123. * - EXINT_LINE_17
  124. * - EXINT_LINE_18
  125. * @retval the new state of exint flag(SET or RESET).
  126. */
  127. flag_status exint_flag_get(uint32_t exint_line)
  128. {
  129. flag_status status = RESET;
  130. uint32_t exint_flag =0;
  131. exint_flag = EXINT->intsts & exint_line;
  132. if((exint_flag != (uint16_t)RESET))
  133. {
  134. status = SET;
  135. }
  136. else
  137. {
  138. status = RESET;
  139. }
  140. return status;
  141. }
  142. /**
  143. * @brief generate exint software interrupt event
  144. * @param exint_line
  145. * this parameter can be one of the following values:
  146. * - EXINT_LINE_0
  147. * - EXINT_LINE_1
  148. * ...
  149. * - EXINT_LINE_17
  150. * - EXINT_LINE_18
  151. * @retval none
  152. */
  153. void exint_software_interrupt_event_generate(uint32_t exint_line)
  154. {
  155. EXINT->swtrg |= exint_line;
  156. }
  157. /**
  158. * @brief enable or disable exint interrupt
  159. * @param exint_line
  160. * this parameter can be any combination of the following values:
  161. * - EXINT_LINE_0
  162. * - EXINT_LINE_1
  163. * ...
  164. * - EXINT_LINE_17
  165. * - EXINT_LINE_18
  166. * @param new_state: new state of exint interrupt.
  167. * this parameter can be: TRUE or FALSE.
  168. * @retval none
  169. */
  170. void exint_interrupt_enable(uint32_t exint_line, confirm_state new_state)
  171. {
  172. if(new_state == TRUE)
  173. {
  174. EXINT->inten |= exint_line;
  175. }
  176. else
  177. {
  178. EXINT->inten &= ~exint_line;
  179. }
  180. }
  181. /**
  182. * @brief enable or disable exint event
  183. * @param exint_line
  184. * this parameter can be any combination of the following values:
  185. * - EXINT_LINE_0
  186. * - EXINT_LINE_1
  187. * ...
  188. * - EXINT_LINE_17
  189. * - EXINT_LINE_18
  190. * @param new_state: new state of exint event.
  191. * this parameter can be: TRUE or FALSE.
  192. * @retval none
  193. */
  194. void exint_event_enable(uint32_t exint_line, confirm_state new_state)
  195. {
  196. if(new_state == TRUE)
  197. {
  198. EXINT->evten |= exint_line;
  199. }
  200. else
  201. {
  202. EXINT->evten &= ~exint_line;
  203. }
  204. }
  205. /**
  206. * @}
  207. */
  208. #endif
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */