Skip to content

Commit d399e51

Browse files
author
Bogdan Marinescu
committed
Interrupt chaining: now working on all targets.
Tested on LPC1768, LPC11U24, KL25Z, LPC2368.
1 parent 43d4445 commit d399e51

File tree

25 files changed

+63
-23
lines changed

25 files changed

+63
-23
lines changed

libraries/mbed/api/InterruptManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MBED_INTERRUPTMANAGER_H
22
#define MBED_INTERRUPTMANAGER_H
33

4-
#include "cmsis_nvic.h"
4+
#include "cmsis.h"
55
#include "CallChain.h"
66
#include <string.h>
77

libraries/mbed/common/InterruptManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ bool InterruptManager::remove_handler(pFunctionPointer_t handler, IRQn_Type irq)
7474
}
7575

7676
void InterruptManager::irq_helper() {
77-
_chains[get_irq_index(NVIC_GetActiveInterrupt())]->call();
77+
_chains[__get_IPSR()]->call();
7878
}
7979

8080
int InterruptManager::get_irq_index(IRQn_Type irq) {

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x1FFFFC00) // Vectors positioned at start of RAM
109
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
1110

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL05Z/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include "cmsis.h"
1111

12+
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
13+
#define NVIC_USER_IRQ_OFFSET 16
14+
1215
#ifdef __cplusplus
1316
extern "C" {
1417
#endif

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL25Z/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x1FFFF000) // Vectors positioned at start of RAM
109
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
1110

libraries/mbed/targets/cmsis/TARGET_Freescale/TARGET_KL25Z/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef MBED_CMSIS_NVIC_H
88
#define MBED_CMSIS_NVIC_H
99

10+
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
11+
#define NVIC_USER_IRQ_OFFSET 16
12+
1013
#include "cmsis.h"
1114

1215
#ifdef __cplusplus

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
* Option 2 is the one to go for, as RAM is the most valuable resource
2828
*/
2929

30-
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
3130
#define NVIC_RAM_VECTOR_ADDRESS (0x10000000) // Vectors positioned at start of RAM
3231

3332
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) {

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11UXX/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include "cmsis.h"
1111

12+
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
13+
#define NVIC_USER_IRQ_OFFSET 16
14+
1215
#ifdef __cplusplus
1316
extern "C" {
1417
#endif

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC13XX/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x10000000) // Location of vectors in RAM
109
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
1110

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC13XX/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
#include "cmsis.h"
1111

12+
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
13+
#define NVIC_USER_IRQ_OFFSET 16
14+
1215
#ifdef __cplusplus
1316
extern "C" {
1417
#endif

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC176X/cmsis_nvic.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,3 @@ uint32_t NVIC_GetVector(IRQn_Type IRQn) {
2929
return vectors[IRQn + NVIC_USER_IRQ_OFFSET];
3030
}
3131

32-
IRQn_Type NVIC_GetActiveInterrupt(void) {
33-
return (IRQn_Type)((SCB->ICSR & 0x1FF) - NVIC_USER_IRQ_OFFSET);
34-
}

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC176X/cmsis_nvic.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ extern "C" {
1818

1919
void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector);
2020
uint32_t NVIC_GetVector(IRQn_Type IRQn);
21-
IRQn_Type NVIC_GetActiveInterrupt(void);
2221

2322
#ifdef __cplusplus
2423
}

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC23XX/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef MBED_CMSIS_NVIC_H
88
#define MBED_CMSIS_NVIC_H
99

10+
#define NVIC_NUM_VECTORS 32
11+
#define NVIC_USER_IRQ_OFFSET 0
12+
1013
#include "cmsis.h"
1114

1215
#ifdef __cplusplus

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC23XX/core_arm7.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#ifndef __ARM7_CORE_H__
99
#define __ARM7_CORE_H__
1010

11+
#include "vector_defns.h"
12+
1113
#ifdef __cplusplus
1214
extern "C" {
1315
#endif
@@ -255,6 +257,15 @@ static __INLINE void NVIC_DisableIRQ(IRQn_Type IRQn)
255257
NVIC->IntEnClr = 1 << (uint32_t)IRQn;
256258
}
257259

260+
static __INLINE uint32_t __get_IPSR(void)
261+
{
262+
unsigned i;
263+
264+
for(i = 0; i < 32; i ++)
265+
if(NVIC->Address == NVIC->VectAddr[i])
266+
return i;
267+
return 1; // 1 is an invalid entry in the interrupt table on LPC2368
268+
}
258269

259270
#ifdef __cplusplus
260271
}

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC23XX/vector_defns.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@
3737
// VIC register addresses
3838
#define VIC_Base 0xfffff000
3939
#define VICAddress_Offset 0xf00
40+
#define VICVectAddr0_Offset 0x100
4041
#define VICVectAddr2_Offset 0x108
4142
#define VICVectAddr3_Offset 0x10c
43+
#define VICVectAddr31_Offset 0x17c
4244
#define VICIntEnClr_Offset 0x014
4345
#define VICIntEnClr (*(volatile unsigned long *)(VIC_Base + 0x014))
4446
#define VICVectAddr2 (*(volatile unsigned long *)(VIC_Base + 0x108))

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 41) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x10000000) // Location of vectors in RAM
109
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
1110

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC408X/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef MBED_CMSIS_NVIC_H
88
#define MBED_CMSIS_NVIC_H
99

10+
#define NVIC_NUM_VECTORS (16 + 41) // CORE + MCU Peripherals
11+
#define NVIC_USER_IRQ_OFFSET 16
12+
1013
#include "cmsis.h"
1114

1215
#ifdef __cplusplus

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC43XX/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 53) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x10000000) // Location of vectors in RAM
109

1110
// The LPC43xx can boot from multiple memories (internal Flash, external NOR,

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC43XX/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef MBED_CMSIS_NVIC_H
88
#define MBED_CMSIS_NVIC_H
99

10+
#define NVIC_NUM_VECTORS (16 + 53) // CORE + MCU Peripherals
11+
#define NVIC_USER_IRQ_OFFSET 16
12+
1013
#include "cmsis.h"
1114

1215
#ifdef __cplusplus

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x10000000) // Vectors positioned at start of RAM
109
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
1110

libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC81X/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef MBED_CMSIS_NVIC_H
88
#define MBED_CMSIS_NVIC_H
99

10+
#define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals
11+
#define NVIC_USER_IRQ_OFFSET 16
12+
1013
#include "cmsis.h"
1114

1215
#ifdef __cplusplus

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
#include "cmsis_nvic.h"
77

8-
#define NVIC_NUM_VECTORS (16 + 81) // CORE + MCU Peripherals
98
#define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Location of vectors in RAM
109
#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash
1110

libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#ifndef MBED_CMSIS_NVIC_H
88
#define MBED_CMSIS_NVIC_H
99

10+
#define NVIC_NUM_VECTORS (16 + 81) // CORE + MCU Peripherals
11+
#define NVIC_USER_IRQ_OFFSET 16
12+
1013
#include "cmsis.h"
1114

1215
#ifdef __cplusplus

libraries/tests/mbed/interrupt_chaining/interruptin/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ void in_handler() {
1212
}
1313

1414
#if defined(TARGET_KL25Z)
15-
#define PIN_OUT PTC7
16-
#define PIN_IN PTA1
15+
#define PIN_OUT PTC6
16+
#define PIN_IN PTA5
1717

1818
#elif defined(TARGET_KL05Z)
1919
#define PIN_OUT PTB11

libraries/tests/mbed/interrupt_chaining/ticker/main.cpp

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,18 @@
33
#include "cmsis.h"
44
#include "test_env.h"
55

6+
#if defined(TARGET_LPC1768)
7+
#define TIMER_IRQ TIMER3_IRQn
8+
#elif defined(TARGET_LPC11U24)
9+
#define TIMER_IRQ TIMER_32_1_IRQn
10+
#elif defined(TARGET_KL25Z)
11+
#define TIMER_IRQ LPTimer_IRQn
12+
#elif defined(TARGET_LPC2368)
13+
#define TIMER_IRQ TIMER3_IRQn
14+
#else
15+
#error This test can't run on this target.
16+
#endif
17+
618
Serial pc(USBTX, USBRX);
719

820
Ticker flipper_1;
@@ -28,7 +40,7 @@ Ticker flipper_2;
2840
Sender s1(pc, '1');
2941
Sender s2(pc, '2');
3042

31-
#if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088)
43+
#if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2368)
3244
# define LED_NAME LED2
3345
#elif defined(TARGET_KL05Z)
3446
# define LED_NAME LED2
@@ -77,20 +89,20 @@ int main() {
7789
flipper_2.add_function(&s2, &Sender::send);
7890

7991
// Test global chaining (InterruptManager)
80-
printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER3_IRQn));
92+
printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ));
8193
InterruptManager *pManager = InterruptManager::get();
82-
pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER3_IRQn);
83-
pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER3_IRQn);
84-
printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER3_IRQn));
94+
pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER_IRQ);
95+
pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER_IRQ);
96+
printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER_IRQ));
8597

8698
wait(4.0);
8799

88-
if (!pManager->remove_handler(ptm, TIMER3_IRQn) || !pManager->remove_handler(pinc, TIMER3_IRQn)) {
100+
if (!pManager->remove_handler(ptm, TIMER_IRQ) || !pManager->remove_handler(pinc, TIMER_IRQ)) {
89101
printf ("remove handler failed.\n");
90102
notify_completion(false);
91103
}
92104
printf("Interrupt handler calls: %d\n", c.get_count());
93-
printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER3_IRQn));
105+
printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER_IRQ));
94106

95107
if (initial_handler != final_handler) {
96108
printf( "InteruptManager test failed.\n");

0 commit comments

Comments
 (0)