apm32f10x_eint.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*!
  2. * @file apm32f10x_eint.c
  3. *
  4. * @brief This file provides all the EINT firmware functions
  5. *
  6. * @version V1.0.4
  7. *
  8. * @date 2022-12-01
  9. *
  10. * @attention
  11. *
  12. * Copyright (C) 2020-2022 Geehy Semiconductor
  13. *
  14. * You may not use this file except in compliance with the
  15. * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
  16. *
  17. * The program is only for reference, which is distributed in the hope
  18. * that it will be useful and instructional for customers to develop
  19. * their software. Unless required by applicable law or agreed to in
  20. * writing, the program is distributed on an "AS IS" BASIS, WITHOUT
  21. * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
  23. * and limitations under the License.
  24. */
  25. #include "apm32f10x_eint.h"
  26. /** @addtogroup APM32F10x_StdPeriphDriver
  27. @{
  28. */
  29. /** @addtogroup EINT_Driver EINT Driver
  30. * @brief EINT driver modules
  31. @{
  32. */
  33. /** @defgroup EINT_Functions Functions
  34. @{
  35. */
  36. /*!
  37. * @brief Reset the EINT peripheral registers to their default reset values.
  38. *
  39. * @param None
  40. *
  41. * @retval None
  42. */
  43. void EINT_Reset(void)
  44. {
  45. EINT->IMASK = 0x00000000;
  46. EINT->EMASK = 0x00000000;
  47. EINT->RTEN = 0x00000000;
  48. EINT->FTEN = 0x00000000;
  49. EINT->IPEND = 0x000FFFFF;
  50. }
  51. /*!
  52. * @brief Configure the EINT
  53. *
  54. * @param eintConfig: pointer to a EINT_Config_T structure.
  55. *
  56. * @retval None
  57. */
  58. void EINT_Config(EINT_Config_T* eintConfig)
  59. {
  60. uint32_t temp = 0;
  61. temp = (uint32_t)EINT_BASE;
  62. if (eintConfig->lineCmd != DISABLE)
  63. {
  64. EINT->IMASK &= ~eintConfig->line;
  65. EINT->EMASK &= ~eintConfig->line;
  66. temp += eintConfig->mode;
  67. *(__IOM uint32_t*) temp |= eintConfig->line;
  68. EINT->RTEN &= ~eintConfig->line;
  69. EINT->FTEN &= ~eintConfig->line;
  70. if (eintConfig->trigger == EINT_TRIGGER_RISING_FALLING)
  71. {
  72. EINT->RTEN |= eintConfig->line;
  73. EINT->FTEN |= eintConfig->line;
  74. }
  75. else
  76. {
  77. temp = (uint32_t)EINT_BASE;
  78. temp += eintConfig->trigger;
  79. *(__IOM uint32_t*) temp |= eintConfig->line;
  80. }
  81. }
  82. else
  83. {
  84. temp += eintConfig->mode;
  85. *(__IOM uint32_t*) temp &= ~eintConfig->line;
  86. }
  87. }
  88. /*!
  89. * @brief Fills each EINT_Config_T member with its reset value.
  90. *
  91. * @param eintConfig: pointer to a EINT_Config_T structure
  92. *
  93. * @retval None
  94. */
  95. void EINT_ConfigStructInit(EINT_Config_T* eintConfig)
  96. {
  97. eintConfig->line = EINT_LINENONE;
  98. eintConfig->mode = EINT_MODE_INTERRUPT;
  99. eintConfig->trigger = EINT_TRIGGER_FALLING;
  100. eintConfig->lineCmd = DISABLE;
  101. }
  102. /*!
  103. * @brief Select Software interrupt on EINT line
  104. *
  105. * @param line: specifies the EINT lines.
  106. * This parameter can be any combination of EINT_LINE_T(can be from 0 to 18)
  107. *
  108. * @retval None
  109. */
  110. void EINT_SelectSWInterrupt(uint32_t line)
  111. {
  112. EINT->SWINTE |= line;
  113. }
  114. /*!
  115. * @brief Read the specified EINT_Line flag
  116. *
  117. * @param line: Select the EINT_Line.
  118. * This parameter can be one of EINT_LINE_T(can be from 0 to 18)
  119. *
  120. * @retval status: The new state of flag (SET or RESET)
  121. */
  122. uint8_t EINT_ReadStatusFlag(EINT_LINE_T line)
  123. {
  124. uint8_t status = RESET;
  125. if ((EINT->IPEND & line) != (uint32_t)RESET)
  126. {
  127. status = SET;
  128. }
  129. else
  130. {
  131. status = RESET;
  132. }
  133. return status;
  134. }
  135. /*!
  136. * @brief Clears the EINT_Line pending bits
  137. *
  138. * @param line: Select the EINT_Line.
  139. * This parameter can be any combination of EINT_LINE_T(can be from 0 to 18)
  140. *
  141. * @retval None
  142. */
  143. void EINT_ClearStatusFlag(uint32_t line)
  144. {
  145. EINT->IPEND = line;
  146. }
  147. /*!
  148. * @brief Read the specified EINT_Line Interrupt Flag.
  149. *
  150. * @param line: Select the EINT_Line.
  151. * This parameter can be one of EINT_LINE_T(can be from 0 to 18)
  152. *
  153. * @retval None
  154. */
  155. uint8_t EINT_ReadIntFlag(EINT_LINE_T line)
  156. {
  157. uint8_t status = RESET;
  158. uint32_t enablestatus = 0;
  159. enablestatus = EINT->IMASK & line;
  160. if ((EINT->IPEND & line) != ((uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
  161. {
  162. status = SET;
  163. }
  164. else
  165. {
  166. status = RESET;
  167. }
  168. return status;
  169. }
  170. /*!
  171. * @brief Clears the EINT_Line pending bits
  172. *
  173. * @param line: Select the EINT_Line
  174. * This parameter can be any combination of EINT_LINE_T(can be from 0 to 18)
  175. *
  176. * @retval None
  177. */
  178. void EINT_ClearIntFlag(uint32_t line)
  179. {
  180. EINT->IPEND = line;
  181. }
  182. /**@} end of group EINT_Functions*/
  183. /**@} end of group EINT_Driver */
  184. /**@} end of group APM32F10x_StdPeriphDriver*/