Skip to content

Commit

Permalink
irq: multilevel: allow to APIs to always work
Browse files Browse the repository at this point in the history
When `CONFIG_MULTI_LEVEL_INTERRUPTS` is enabled, bits in a
`uint32_t` is always partitioned into 3 levels, we can safely
remove the `CONFIG_*_LEVEL_INTERRUPTS` checks so that the
APIs always works.

Signed-off-by: Yong Cong Sin <ycsin@meta.com>
Signed-off-by: Yong Cong Sin <yongcong.sin@gmail.com>
  • Loading branch information
ycsin authored and aescolar committed Oct 2, 2024
1 parent cb6417c commit 3fa7d78
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions include/zephyr/irq_multilevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ static inline unsigned int irq_get_level(unsigned int irq)
const uint32_t mask3 = BIT_MASK(CONFIG_3RD_LEVEL_INTERRUPT_BITS) <<
(CONFIG_1ST_LEVEL_INTERRUPT_BITS + CONFIG_2ND_LEVEL_INTERRUPT_BITS);

if (IS_ENABLED(CONFIG_3RD_LEVEL_INTERRUPTS) && (irq & mask3) != 0) {
if ((irq & mask3) != 0) {
return 3;
}

if (IS_ENABLED(CONFIG_2ND_LEVEL_INTERRUPTS) && (irq & mask2) != 0) {
if ((irq & mask2) != 0) {
return 2;
}

Expand All @@ -59,7 +59,9 @@ static inline unsigned int irq_get_level(unsigned int irq)
*/
static inline unsigned int irq_from_level_2(unsigned int irq)
{
if (IS_ENABLED(CONFIG_3RD_LEVEL_INTERRUPTS)) {
unsigned int level = irq_get_level(irq);

if (level == 3) {
return ((irq >> CONFIG_1ST_LEVEL_INTERRUPT_BITS) &
BIT_MASK(CONFIG_2ND_LEVEL_INTERRUPT_BITS)) - 1;
} else {
Expand Down Expand Up @@ -249,10 +251,14 @@ static inline unsigned int irq_get_intc_irq(unsigned int irq)
{
const unsigned int level = irq_get_level(irq);

__ASSERT_NO_MSG(level > 1 && level <= 3);

return irq & BIT_MASK(CONFIG_1ST_LEVEL_INTERRUPT_BITS +
(level == 3 ? CONFIG_2ND_LEVEL_INTERRUPT_BITS : 0));
if (level == 3) {
return irq &
BIT_MASK(CONFIG_1ST_LEVEL_INTERRUPT_BITS + CONFIG_2ND_LEVEL_INTERRUPT_BITS);
} else if (level == 2) {
return irq & BIT_MASK(CONFIG_1ST_LEVEL_INTERRUPT_BITS);
} else {
return irq;
}
}

#endif /* CONFIG_MULTI_LEVEL_INTERRUPTS */
Expand Down

0 comments on commit 3fa7d78

Please sign in to comment.