2 #include "InterruptManager.h"
6 #if defined(TARGET_LPC1768) || defined(TARGET_LPC4088)
7 #define TIMER_IRQ TIMER3_IRQn
8 #elif defined(TARGET_LPC11U24) || defined(TARGET_LPC1114)
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
15 #error This test can't run on this target.
18 Serial pc(USBTX, USBRX);
21 DigitalOut led1(LED1);
25 led1 = 0; led1_state = 0;
27 led1 = 1; led1_state = 1;
33 Sender(Serial&s, char c): _s(s), _c(c) {}
34 void send() { _s.putc(_c); }
43 #if defined(TARGET_LPC1768) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088) || defined(TARGET_LPC2368) || defined(TARGET_LPC1114)
44 # define LED_NAME LED2
45 #elif defined(TARGET_KL05Z)
46 # define LED_NAME LED2
48 # define LED_NAME PTE31
51 DigitalOut led2(LED_NAME);
55 led2 = 0; led2_state = 0;
57 led2 = 1; led2_state = 1;
70 int get_count(void) const {
77 int Counter::count = 0;
82 uint32_t initial_handler, final_handler;
85 // Test chaining inside Serial class
86 flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second)
87 flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds)
89 // Test global chaining (InterruptManager)
90 printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ));
91 InterruptManager *pManager = InterruptManager::get();
92 pFunctionPointer_t ptm = pManager->add_handler(testme, TIMER_IRQ);
93 pFunctionPointer_t pinc = pManager->add_handler_front(&c, &Counter::inc, TIMER_IRQ);
94 printf("Handler after calling InterruptManager: %08X\n", NVIC_GetVector(TIMER_IRQ));
98 if (!pManager->remove_handler(ptm, TIMER_IRQ) || !pManager->remove_handler(pinc, TIMER_IRQ)) {
99 printf ("remove handler failed.\n");
100 notify_completion(false);
102 printf("Interrupt handler calls: %d\n", c.get_count());
103 printf("Handler after removing previously added functions: %08X\n", final_handler = NVIC_GetVector(TIMER_IRQ));
105 if (initial_handler != final_handler) {
106 printf( "InteruptManager test failed.\n");
107 notify_completion(false);