1 /*!
2  * @file       apm32e10x_eint.c
3  *
4  * @brief      This file provides all the EINT firmware functions
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-12-31
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-2023 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 "apm32e10x_eint.h"
27 
28 /** @addtogroup APM32E10x_StdPeriphDriver
29   @{
30 */
31 
32 /** @addtogroup EINT_Driver
33   * @brief EINT driver modules
34   @{
35 */
36 
37 /** @defgroup EINT_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)48 void 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)64 void 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  * @brief        Fills each EINT_Config_T member with its reset value.
102  *
103  * @param        eintConfig: pointer to a EINT_Config_T structure
104  *
105  * @retval       None
106  */
EINT_ConfigStructInit(EINT_Config_T * eintConfig)107 void EINT_ConfigStructInit(EINT_Config_T* eintConfig)
108 {
109     eintConfig->line = EINT_LINENONE;
110     eintConfig->mode = EINT_MODE_INTERRUPT;
111     eintConfig->trigger = EINT_TRIGGER_FALLING;
112     eintConfig->lineCmd = DISABLE;
113 }
114 
115 /*!
116  * @brief    Select Software interrupt on EINT line
117  *
118  * @param    line: specifies the EINT lines.
119  *                 This parameter can be any combination of EINT_LINE_T(can be from 0 to 18)
120  *
121  * @retval   None
122  */
EINT_SelectSWInterrupt(uint32_t line)123 void EINT_SelectSWInterrupt(uint32_t line)
124 {
125     EINT->SWINTE |= line;
126 }
127 
128 /*!
129  * @brief        Read the specified EINT_Line flag
130  *
131  * @param        line: Select the EINT_Line.
132  *                     This parameter can be one of EINT_LINE_T(can be from 0 to 18)
133  *
134  * @retval       status: The new state of flag (SET or RESET)
135  */
EINT_ReadStatusFlag(EINT_LINE_T line)136 uint8_t EINT_ReadStatusFlag(EINT_LINE_T line)
137 {
138     uint8_t status = RESET;
139 
140     if((EINT->IPEND & line) != (uint32_t)RESET)
141     {
142         status = SET;
143     }
144     else
145     {
146         status = RESET;
147     }
148     return status;
149 }
150 
151 /*!
152  * @brief        Clears the EINT_Line pending bits
153  *
154  * @param        line: Select the EINT_Line.
155  *                     This parameter can be any combination of EINT_LINE_T(can be from 0 to 18)
156  *
157  * @retval        None
158  */
EINT_ClearStatusFlag(uint32_t line)159 void EINT_ClearStatusFlag(uint32_t line)
160 {
161     EINT->IPEND = line;
162 }
163 
164 /*!
165  * @brief        Read the specified EINT_Line Interrupt Flag.
166  *
167  * @param        line: Select the EINT_Line.
168  *                     This parameter can be one of EINT_LINE_T(can be from 0 to 18)
169  *
170  * @retval        None
171  */
EINT_ReadIntFlag(EINT_LINE_T line)172 uint8_t EINT_ReadIntFlag(EINT_LINE_T line)
173 {
174     uint8_t status = RESET;
175     uint32_t enablestatus = 0;
176 
177     enablestatus = EINT->IMASK & line;
178 
179     if((EINT->IPEND & line) != ((uint32_t)RESET) && (enablestatus != (uint32_t)RESET))
180     {
181         status = SET;
182     }
183     else
184     {
185         status = RESET;
186     }
187     return status;
188 }
189 
190 /*!
191  * @brief        Clears the EINT_Line pending bits
192  *
193  * @param        line: Select the EINT_Line
194  *                     This parameter can be any combination of EINT_LINE_T(can be from 0 to 18)
195  *
196  * @retval        None
197  */
EINT_ClearIntFlag(uint32_t line)198 void EINT_ClearIntFlag(uint32_t line)
199 {
200     EINT->IPEND = line;
201 }
202 
203 /**@} end of group EINT_Functions */
204 /**@} end of group EINT_Driver */
205 /**@} end of group APM32E10x_StdPeriphDriver */
206