@@ -79,8 +79,8 @@ static uint32_t gpioIds[NUMBER_OF_GPIO] = {0};
79
79
80
80
/** Main GPIO IRQ handler called from vector table handler
81
81
*
82
- * @param gpioBase The GPIO register base address
83
- * @return void
82
+ * @param gpioBase The GPIO register base address
83
+ * @return void
84
84
*/
85
85
void fGpioHandler (void )
86
86
{
@@ -90,7 +90,9 @@ void fGpioHandler(void)
90
90
GpioReg_pt gpioBase ;
91
91
92
92
/* Enable the GPIO clock */
93
- CLOCK_ENABLE (CLOCK_GPIO );
93
+ if (!CLOCK_IS_ENABLED (CLOCK_GPIO )) {
94
+ CLOCK_ENABLE (CLOCK_GPIO );
95
+ }
94
96
95
97
gpioBase = GPIOREG ;
96
98
@@ -114,7 +116,7 @@ void fGpioHandler(void)
114
116
event = IRQ_NONE ;
115
117
}
116
118
}
117
- gpioBase -> IRQ_CLEAR | = (0x1 << index );
119
+ gpioBase -> IRQ_CLEAR = (0x1 << index );
118
120
119
121
/* Call the handler registered to the pin */
120
122
irq_handler (gpioIds [index ], event );
@@ -146,7 +148,9 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
146
148
gpioIds [pin ] = id ;
147
149
148
150
/* Enable the GPIO clock */
149
- CLOCK_ENABLE (CLOCK_GPIO );
151
+ if (!CLOCK_IS_ENABLED (CLOCK_GPIO )) {
152
+ CLOCK_ENABLE (CLOCK_GPIO );
153
+ }
150
154
151
155
/* Initialize the GPIO membase */
152
156
obj -> GPIOMEMBASE = GPIOREG ;
@@ -157,10 +161,8 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
157
161
* then change this setting to obj->GPIOMEMBASE->W_IN |= obj->pinMask. All parameter setting needs to change from = to |=
158
162
*/
159
163
obj -> GPIOMEMBASE -> W_IN = obj -> pinMask ;
160
- obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
161
164
obj -> GPIOMEMBASE -> IRQ_EDGE = obj -> pinMask ;
162
- obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = (obj -> pinMask );
163
- obj -> GPIOMEMBASE -> ANYEDGE_SET = IO_NONE ;
165
+ obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = obj -> pinMask ;
164
166
165
167
/* Register the handler for this pin */
166
168
irq_handler = handler ;
@@ -179,9 +181,12 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
179
181
void gpio_irq_free (gpio_irq_t * obj )
180
182
{
181
183
/* Enable the GPIO clock */
182
- CLOCK_ENABLE (CLOCK_GPIO );
184
+ if (!CLOCK_IS_ENABLED (CLOCK_GPIO )) {
185
+ CLOCK_ENABLE (CLOCK_GPIO );
186
+ }
183
187
184
- obj -> GPIOMEMBASE -> W_IN = (IO_ALL ^ (obj -> pinMask ));
188
+ /* Make the pin as output in order to release it */
189
+ obj -> GPIOMEMBASE -> W_OUT = obj -> pinMask ;
185
190
gpioIds [obj -> pin ] = 0 ;
186
191
}
187
192
@@ -195,32 +200,40 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
195
200
{
196
201
197
202
/* Enable the GPIO clock */
198
- CLOCK_ENABLE (CLOCK_GPIO );
203
+ if (!CLOCK_IS_ENABLED (CLOCK_GPIO )) {
204
+ CLOCK_ENABLE (CLOCK_GPIO );
205
+ }
199
206
200
207
switch (event ) {
201
208
case IRQ_RISE :
202
- obj -> GPIOMEMBASE -> IRQ_EDGE = (obj -> pinMask );
203
- obj -> GPIOMEMBASE -> IRQ_LEVEL = (IO_ALL ^ (obj -> pinMask ));
204
- /* Enable is an integer; hence checking for 1 or 0*/
209
+ obj -> GPIOMEMBASE -> IRQ_EDGE = obj -> pinMask ;
210
+
211
+ /* Enable rising edge */
212
+ obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = obj -> pinMask ;
213
+
214
+ /* Enable the IRQ based on enable parameter */
205
215
if (enable == 1 ) {
206
- /* Enable rising edge */
207
- obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = ( obj -> pinMask ) ;
216
+
217
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
208
218
} else if (enable == 0 ) {
209
- /* Disable rising edge */
210
- obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = ( IO_ALL ^ ( obj -> pinMask )) ;
219
+
220
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = obj -> pinMask ;
211
221
}
212
222
break ;
213
223
214
224
case IRQ_FALL :
215
- obj -> GPIOMEMBASE -> IRQ_EDGE = (obj -> pinMask );
216
- obj -> GPIOMEMBASE -> IRQ_LEVEL = (IO_ALL ^ (obj -> pinMask ));
217
- /* Enable is an integer; hence checking for 1 or 0*/
225
+ obj -> GPIOMEMBASE -> IRQ_EDGE = obj -> pinMask ;
226
+
227
+ /* Enable falling edge */
228
+ obj -> GPIOMEMBASE -> IRQ_POLARITY_CLEAR = obj -> pinMask ;
229
+
230
+ /* Enable the IRQ based on enable parameter */
218
231
if (enable == 1 ) {
219
- /* Enable falling edge */
220
- obj -> GPIOMEMBASE -> IRQ_POLARITY_CLEAR = ( obj -> pinMask ) ;
232
+
233
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
221
234
} else if (enable == 0 ) {
222
- /* Disable falling edge */
223
- obj -> GPIOMEMBASE -> IRQ_POLARITY_CLEAR = ( IO_ALL ^ ( obj -> pinMask )) ;
235
+
236
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = obj -> pinMask ;
224
237
}
225
238
break ;
226
239
@@ -239,9 +252,11 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
239
252
void gpio_irq_enable (gpio_irq_t * obj )
240
253
{
241
254
/* Enable the GPIO clock */
242
- CLOCK_ENABLE (CLOCK_GPIO );
255
+ if (!CLOCK_IS_ENABLED (CLOCK_GPIO )) {
256
+ CLOCK_ENABLE (CLOCK_GPIO );
257
+ }
243
258
244
- obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = ( obj -> pinMask ) ;
259
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
245
260
}
246
261
247
262
/** Disable GPIO IRQ
@@ -252,9 +267,11 @@ void gpio_irq_enable(gpio_irq_t *obj)
252
267
void gpio_irq_disable (gpio_irq_t * obj )
253
268
{
254
269
/* Enable the GPIO clock */
255
- CLOCK_ENABLE (CLOCK_GPIO );
270
+ if (!CLOCK_IS_ENABLED (CLOCK_GPIO )) {
271
+ CLOCK_ENABLE (CLOCK_GPIO );
272
+ }
256
273
257
- obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = ( obj -> pinMask ) ;
274
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = obj -> pinMask ;
258
275
}
259
276
260
277
#endif //DEVICE_INTERRUPTIN
0 commit comments