From e1218c4b4bea7ae00c750d79cecaeee9fd1804a9 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 3 Mar 2017 10:20:40 -0600 Subject: [PATCH] Smaller vector tables: Add irq_mapped_t. --- arch/Kconfig | 14 +++++++------- include/nuttx/irq.h | 32 +++++++++++++++++++++++++++++++- sched/irq/irq.h | 11 +++++++++-- sched/irq/irq_dispatch.c | 4 ++-- 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/arch/Kconfig b/arch/Kconfig index 4c791777c5..9e98363d85 100644 --- a/arch/Kconfig +++ b/arch/Kconfig @@ -636,19 +636,19 @@ config ARCH_MINIMAL_VECTORTABLE provides: #include - const irq_t g_irqmap[NR_IRQS] = + const irq_mapped_t g_irqmap[NR_IRQS] = { ... IRQ to index mapping values ... }; This table is index by the hardware IRQ number and provides a value - in the range of 0 to CONFIG_ARCH_NUSER_INTERRUPTS that the new, + in the range of 0 to CONFIG_ARCH_NUSER_INTERRUPTS that is the new, mapped index into the vector table. Unused, unmapped interrupts - should be set to (irq_t)-1. So, for example, if g_irqmap[37] == 24, - Then the hardware interrupt vector 37 will be mapped to the interrupt - vector table at index 24. if g_irqmap[42] == (irq_t)-1, then hardware - interrupt vector 42 is not used and if it occurs will result in an - unexpected interrupt crash. + should be set to (irq_mapped_t)-1. So, for example, if g_irqmap[37] + == 24, then the hardware interrupt vector 37 will be mapped to the + interrupt vector table at index 24. if g_irqmap[42] == + (irq_mapped_t)-1, then hardware interrupt vector 42 is not used and + if it occurs will result in an unexpected interrupt crash. config ARCH_NUSER_INTERRUPTS int "Number of interrupts" diff --git a/include/nuttx/irq.h b/include/nuttx/irq.h index 7afca9f09c..a128482566 100644 --- a/include/nuttx/irq.h +++ b/include/nuttx/irq.h @@ -65,7 +65,9 @@ ****************************************************************************/ #ifndef __ASSEMBLY__ -/* This type is an integer type large enough to hold the largest IRQ number. */ +/* This type is an unsigned integer type large enough to hold the largest + * IRQ number. + */ #if NR_IRQS <= 256 typedef uint8_t irq_t; @@ -75,6 +77,20 @@ typedef uint16_t irq_t; typedef uint32_t irq_t; #endif +/* This type is an unsigned integer type large enough to hold the largest + * mapped vector table index. + */ + +#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE +#if CONFIG_ARCH_NUSER_INTERRUPTS <= 256 +typedef uint8_t irq_mapped_t; +#elif CONFIG_ARCH_NUSER_INTERRUPTS <= 65536 +typedef uint16_t irq_mapped_t; +#else +typedef uint32_t irq_mapped_t; +#endif +#endif /* CONFIG_ARCH_MINIMAL_VECTORTABLE */ + /* This struct defines the form of an interrupt service routine */ typedef int (*xcpt_t)(int irq, FAR void *context, FAR void *arg); @@ -97,6 +113,20 @@ extern "C" #define EXTERN extern #endif +#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE +/* This is the interrupt vector mapping table. This must be provided by + * architecture specific logic if CONFIG_ARCH_MINIMAL_VECTORTABLE is define + * in the configuration. + * + * REVISIT: Currently declared in sched/irq/irq.h. This declaration here + * introduces a circular dependency since it depends on NR_IRQS which is + * defined in arch/irq.h but arch/irq.h includes nuttx/irq.h and we get + * here with NR_IRQS undefined. + */ + +/* EXTERN const irq_mapped_t g_irqmap[NR_IRQS]; */ +#endif + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/sched/irq/irq.h b/sched/irq/irq.h index 817149b33d..ffb6e9859a 100644 --- a/sched/irq/irq.h +++ b/sched/irq/irq.h @@ -91,9 +91,16 @@ extern struct irq_info_s g_irqvector[NR_IRQS]; #endif #ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE -/* This is the interrupt vector mapping table */ +/* This is the interrupt vector mapping table. This must be provided by + * architecture specific logic if CONFIG_ARCH_MINIMAL_VECTORTABLE is define + * in the configuration. + * + * REVISIT: This should be declared in include/nuttx/irq.h. The declaration + * at that location, however, introduces a circular include dependency so the + * declaration is here for the time being. + */ -extern const irq_t g_irqmap[NR_IRQS]; +extern const irq_mapped_t g_irqmap[NR_IRQS]; #endif #ifdef CONFIG_SMP diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c index f975812839..b507c065b1 100644 --- a/sched/irq/irq_dispatch.c +++ b/sched/irq/irq_dispatch.c @@ -75,8 +75,8 @@ void irq_dispatch(int irq, FAR void *context) else { #ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE - int ndx = g_irqmap[irq]; - if ((unsigned)ndx >= CONFIG_ARCH_NUSER_INTERRUPTS) + irq_mapped_t ndx = g_irqmap[irq]; + if (ndx >= CONFIG_ARCH_NUSER_INTERRUPTS) { vector = irq_unexpected_isr; arg = NULL;