Skip to content

Commit 983cfd6

Browse files
committed
Add irq_has_handler() and use it to fix GPIO IRQ assert
1 parent 1ca3868 commit 983cfd6

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

src/rp2_common/hardware_gpio/gpio.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,9 @@ static void _gpio_set_irq_enabled(uint gpio, uint32_t events, bool enabled, io_b
184184
}
185185

186186
void gpio_set_irq_enabled(uint gpio, uint32_t events, bool enabled) {
187-
// either this call disables the interrupt
188-
// or callback should already be set (raw or using gpio_set_irq_callback)
187+
// either this call disables the interrupt or callback should already be set.
189188
// this protects against enabling the interrupt without callback set
190-
assert(!enabled
191-
|| (raw_irq_mask[get_core_num()] & (1ull<<gpio))
192-
|| callbacks[get_core_num()]);
189+
assert(!enabled || irq_has_handler(IO_IRQ_BANK0));
193190

194191
// Separate mask/force/status per-core, so check which core called, and
195192
// set the relevant IRQ controls.

src/rp2_common/hardware_irq/include/hardware/irq.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,9 +403,23 @@ void irq_add_shared_handler(uint num, irq_handler_t handler, uint8_t order_prior
403403
*/
404404
void irq_remove_handler(uint num, irq_handler_t handler);
405405

406-
/*! \brief Determine if the current handler for the given number is shared
406+
/*! \brief Determine if there is an installed IRQ handler for the given interrupt number
407407
* \ingroup hardware_irq
408408
*
409+
* See \ref irq_set_exclusive_handler() for discussion on the scope of handlers
410+
* when using both cores.
411+
*
412+
* \param num Interrupt number \ref interrupt_nums
413+
* \return true if the specified IRQ has a handler
414+
*/
415+
bool irq_has_handler(uint num);
416+
417+
/*! \brief Determine if the current IRQ andler for the given interrupt number is shared
418+
* \ingroup hardware_irq
419+
*
420+
* See \ref irq_set_exclusive_handler() for discussion on the scope of handlers
421+
* when using both cores.
422+
*
409423
* \param num Interrupt number \ref interrupt_nums
410424
* \return true if the specified IRQ has a shared handler
411425
*/

src/rp2_common/hardware_irq/irq.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,16 @@ static inline bool is_shared_irq_raw_handler(irq_handler_t raw_handler) {
197197
return (uintptr_t)raw_handler - (uintptr_t)irq_handler_chain_slots < sizeof(irq_handler_chain_slots);
198198
}
199199

200+
bool irq_has_handler(uint irq_num) {
201+
check_irq_param(irq_num);
202+
irq_handler_t handler = irq_get_vtable_handler(irq_num);
203+
return handler && handler != __unhandled_user_irq;
204+
}
205+
200206
bool irq_has_shared_handler(uint irq_num) {
201207
check_irq_param(irq_num);
202208
irq_handler_t handler = irq_get_vtable_handler(irq_num);
203-
return handler && is_shared_irq_raw_handler(handler);
209+
return is_shared_irq_raw_handler(handler);
204210
}
205211

206212
#else // PICO_DISABLE_SHARED_IRQ_HANDLERS

0 commit comments

Comments
 (0)