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 26 #include "apm32f10x_eint.h" 27 28 /** @addtogroup APM32F10x_StdPeriphDriver 29 @{ 30 */ 31 32 /** @addtogroup EINT_Driver EINT Driver 33 * @brief EINT driver modules 34 @{ 35 */ 36 37 /** @defgroup EINT_Functions Functions 38 @{ 39 */ 40 41 /*! 42 * @brief Reset the EINT peripheral registers to their default reset values. 43 * 44 * @param None 45 * 46 * @retval None 47 */ EINT_Reset(void)48void EINT_Reset(void) 49 { 50 EINT->IMASK = 0x00000000; 51 EINT->EMASK = 0x00000000; 52 EINT->RTEN = 0x00000000; 53 EINT->FTEN = 0x00000000; 54 EINT->IPEND = 0x000FFFFF; 55 } 56 57 /*! 58 * @brief Configure the EINT 59 * 60 * @param eintConfig: pointer to a EINT_Config_T structure. 61 * 62 * @retval None 63 */ EINT_Config(EINT_Config_T * eintConfig)64void EINT_Config(EINT_Config_T* eintConfig) 65 { 66 uint32_t temp = 0; 67 temp = (uint32_t)EINT_BASE; 68 69 if (eintConfig->lineCmd != DISABLE) 70 { 71 EINT->IMASK &= ~eintConfig->line; 72 EINT->EMASK &= ~eintConfig->line; 73 74 temp += eintConfig->mode; 75 *(__IOM uint32_t*) temp |= eintConfig->line; 76 77 EINT->RTEN &= ~eintConfig->line; 78 EINT->FTEN &= ~eintConfig->line; 79 80 if (eintConfig->trigger == EINT_TRIGGER_RISING_FALLING) 81 { 82 EINT->RTEN |= eintConfig->line; 83 EINT->FTEN |= eintConfig->line; 84 } 85 else 86 { 87 temp = (uint32_t)EINT_BASE; 88 temp += eintConfig->trigger; 89 90 *(__IOM uint32_t*) temp |= eintConfig->line; 91 } 92 } 93 else 94 { 95 temp += eintConfig->mode; 96 97 *(__IOM uint32_t*) temp &= ~eintConfig->line; 98 } 99 } 100 101 /*! 102 * @brief Fills each EINT_Config_T member with its reset value. 103 * 104 * @param eintConfig: pointer to a EINT_Config_T structure 105 * 106 * @retval None 107 */ EINT_ConfigStructInit(EINT_Config_T * eintConfig)108void EINT_ConfigStructInit(EINT_Config_T* eintConfig) 109 { 110 eintConfig->line = EINT_LINENONE; 111 eintConfig->mode = EINT_MODE_INTERRUPT; 112 eintConfig->trigger = EINT_TRIGGER_FALLING; 113 eintConfig->lineCmd = DISABLE; 114 } 115 116 /*! 117 * @brief Select Software interrupt on EINT line 118 * 119 * @param line: specifies the EINT lines. 120 * This parameter can be any combination of EINT_LINE_T(can be from 0 to 18) 121 * 122 * @retval None 123 */ EINT_SelectSWInterrupt(uint32_t line)124void EINT_SelectSWInterrupt(uint32_t line) 125 { 126 EINT->SWINTE |= line; 127 } 128 129 /*! 130 * @brief Read the specified EINT_Line flag 131 * 132 * @param line: Select the EINT_Line. 133 * This parameter can be one of EINT_LINE_T(can be from 0 to 18) 134 * 135 * @retval status: The new state of flag (SET or RESET) 136 */ EINT_ReadStatusFlag(EINT_LINE_T line)137uint8_t EINT_ReadStatusFlag(EINT_LINE_T line) 138 { 139 uint8_t status = RESET; 140 141 if ((EINT->IPEND & line) != (uint32_t)RESET) 142 { 143 status = SET; 144 } 145 else 146 { 147 status = RESET; 148 } 149 return status; 150 } 151 152 /*! 153 * @brief Clears the EINT_Line pending bits 154 * 155 * @param line: Select the EINT_Line. 156 * This parameter can be any combination of EINT_LINE_T(can be from 0 to 18) 157 * 158 * @retval None 159 */ EINT_ClearStatusFlag(uint32_t line)160void EINT_ClearStatusFlag(uint32_t line) 161 { 162 EINT->IPEND = line; 163 } 164 165 /*! 166 * @brief Read the specified EINT_Line Interrupt Flag. 167 * 168 * @param line: Select the EINT_Line. 169 * This parameter can be one of EINT_LINE_T(can be from 0 to 18) 170 * 171 * @retval None 172 */ EINT_ReadIntFlag(EINT_LINE_T line)173uint8_t EINT_ReadIntFlag(EINT_LINE_T line) 174 { 175 uint8_t status = RESET; 176 uint32_t enablestatus = 0; 177 178 enablestatus = EINT->IMASK & line; 179 180 if ((EINT->IPEND & line) != ((uint32_t)RESET) && (enablestatus != (uint32_t)RESET)) 181 { 182 status = SET; 183 } 184 else 185 { 186 status = RESET; 187 } 188 return status; 189 } 190 191 /*! 192 * @brief Clears the EINT_Line pending bits 193 * 194 * @param line: Select the EINT_Line 195 * This parameter can be any combination of EINT_LINE_T(can be from 0 to 18) 196 * 197 * @retval None 198 */ EINT_ClearIntFlag(uint32_t line)199void EINT_ClearIntFlag(uint32_t line) 200 { 201 EINT->IPEND = line; 202 } 203 204 /**@} end of group EINT_Functions*/ 205 /**@} end of group EINT_Driver */ 206 /**@} end of group APM32F10x_StdPeriphDriver*/ 207