@@ -79,17 +79,17 @@ 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
{
87
87
uint8_t index ;
88
88
uint32_t active_interrupts = 0 ;
89
- gpio_irq_event event ;
89
+ gpio_irq_event event = IRQ_NONE ;
90
90
GpioReg_pt gpioBase ;
91
91
92
- /* Enable the GPIO clock */
92
+ /* Enable the GPIO clock which may have been switched off by other drivers */
93
93
CLOCK_ENABLE (CLOCK_GPIO );
94
94
95
95
gpioBase = GPIOREG ;
@@ -106,15 +106,12 @@ void fGpioHandler(void)
106
106
if ((gpioBase -> IRQ_POLARITY_SET >> index ) & 0x01 ) {
107
107
/* Edge triggered high */
108
108
event = IRQ_RISE ;
109
- } else if (( gpioBase -> IRQ_POLARITY_CLEAR >> index ) & 0x01 ) {
109
+ } else {
110
110
/* Edge triggered low */
111
111
event = IRQ_FALL ;
112
- } else {
113
- /* Edge none */
114
- event = IRQ_NONE ;
115
112
}
116
113
}
117
- gpioBase -> IRQ_CLEAR | = (0x1 << index );
114
+ gpioBase -> IRQ_CLEAR = (0x1 << index );
118
115
119
116
/* Call the handler registered to the pin */
120
117
irq_handler (gpioIds [index ], event );
@@ -145,22 +142,16 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
145
142
/* Store the ID, this is required by registered handler function */
146
143
gpioIds [pin ] = id ;
147
144
148
- /* Enable the GPIO clock */
145
+ /* Enable the GPIO clock which may have been switched off by other drivers */
149
146
CLOCK_ENABLE (CLOCK_GPIO );
150
147
151
148
/* Initialize the GPIO membase */
152
149
obj -> GPIOMEMBASE = GPIOREG ;
153
150
154
151
/* Set default values for the pin interrupt */
155
- /* TODO: Only one DIO line is configured using this function; overrides other DIO line setting
156
- * If mbed layer wants to call this function repeatedly for setting multiple DIO lines as input
157
- * then change this setting to obj->GPIOMEMBASE->W_IN |= obj->pinMask. All parameter setting needs to change from = to |=
158
- */
159
152
obj -> GPIOMEMBASE -> W_IN = obj -> pinMask ;
160
- obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
161
153
obj -> GPIOMEMBASE -> IRQ_EDGE = obj -> pinMask ;
162
- obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = (obj -> pinMask );
163
- obj -> GPIOMEMBASE -> ANYEDGE_SET = IO_NONE ;
154
+ obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = obj -> pinMask ;
164
155
165
156
/* Register the handler for this pin */
166
157
irq_handler = handler ;
@@ -178,10 +169,11 @@ int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32
178
169
*/
179
170
void gpio_irq_free (gpio_irq_t * obj )
180
171
{
181
- /* Enable the GPIO clock */
172
+ /* Enable the GPIO clock which may have been switched off by other drivers */
182
173
CLOCK_ENABLE (CLOCK_GPIO );
183
174
184
- obj -> GPIOMEMBASE -> W_IN = (IO_ALL ^ (obj -> pinMask ));
175
+ /* Disable IRQs to indicate that it is now free */
176
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = obj -> pinMask ;
185
177
gpioIds [obj -> pin ] = 0 ;
186
178
}
187
179
@@ -193,42 +185,35 @@ void gpio_irq_free(gpio_irq_t *obj)
193
185
*/
194
186
void gpio_irq_set (gpio_irq_t * obj , gpio_irq_event event , uint32_t enable )
195
187
{
196
-
197
- /* Enable the GPIO clock */
188
+ /* Enable the GPIO clock which may have been switched off by other drivers */
198
189
CLOCK_ENABLE (CLOCK_GPIO );
199
-
190
+ obj -> GPIOMEMBASE -> IRQ_EDGE = obj -> pinMask ;
191
+
200
192
switch (event ) {
201
- 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*/
205
- if (enable == 1 ) {
206
- /* Enable rising edge */
207
- obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = (obj -> pinMask );
208
- } else if (enable == 0 ) {
209
- /* Disable rising edge */
210
- obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = (IO_ALL ^ (obj -> pinMask ));
211
- }
212
- break ;
193
+ case IRQ_RISE :
194
+
195
+ /* Enable rising edge */
196
+ obj -> GPIOMEMBASE -> IRQ_POLARITY_SET = obj -> pinMask ;
197
+ break ;
213
198
214
199
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*/
218
- if (enable == 1 ) {
219
- /* Enable falling edge */
220
- obj -> GPIOMEMBASE -> IRQ_POLARITY_CLEAR = (obj -> pinMask );
221
- } else if (enable == 0 ) {
222
- /* Disable falling edge */
223
- obj -> GPIOMEMBASE -> IRQ_POLARITY_CLEAR = (IO_ALL ^ (obj -> pinMask ));
224
- }
200
+
201
+ /* Enable falling edge */
202
+ obj -> GPIOMEMBASE -> IRQ_POLARITY_CLEAR = obj -> pinMask ;
225
203
break ;
226
204
227
205
default :
228
206
/* No event is set */
229
207
break ;
230
208
}
209
+ /* Enable the IRQ based on enable parameter */
210
+ if (enable ) {
211
+
212
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
213
+ } else {
231
214
215
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = obj -> pinMask ;
216
+ }
232
217
}
233
218
234
219
/** Enable GPIO IRQ
@@ -238,10 +223,10 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
238
223
*/
239
224
void gpio_irq_enable (gpio_irq_t * obj )
240
225
{
241
- /* Enable the GPIO clock */
226
+ /* Enable the GPIO clock which may have been switched off by other drivers */
242
227
CLOCK_ENABLE (CLOCK_GPIO );
243
228
244
- obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = ( obj -> pinMask ) ;
229
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_SET = obj -> pinMask ;
245
230
}
246
231
247
232
/** Disable GPIO IRQ
@@ -251,10 +236,11 @@ void gpio_irq_enable(gpio_irq_t *obj)
251
236
*/
252
237
void gpio_irq_disable (gpio_irq_t * obj )
253
238
{
254
- /* Enable the GPIO clock */
239
+
240
+ /* Enable the GPIO clock which may have been switched off by other drivers */
255
241
CLOCK_ENABLE (CLOCK_GPIO );
256
242
257
- obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = ( obj -> pinMask ) ;
243
+ obj -> GPIOMEMBASE -> IRQ_ENABLE_CLEAR = obj -> pinMask ;
258
244
}
259
245
260
246
#endif //DEVICE_INTERRUPTIN
0 commit comments