]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/vtor_reloc/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / tests / mbed / vtor_reloc / main.cpp
1 // Interrupt table relocation test, based on the 'interrupt_in' test
2 // It will test an interrupt pin before and after the interrupt table is relocated
3 // Works only on LPC1768
4
5 #include "test_env.h"
6 #include "cmsis_nvic.h"
7 #include <string.h>
8
9 #define PIN_IN (p5)
10 #define PIN_OUT (p25)
11 #define NUM_VECTORS (16+33)
12
13 DigitalOut out(PIN_OUT);
14 DigitalOut myled(LED1);
15
16 volatile int checks = 0;
17 uint32_t int_table[NUM_VECTORS] __attribute__ ((aligned(256)));
18
19 #define FALLING_EDGE_COUNT 5
20
21 void flipper() {
22 for (int i = 0; i < FALLING_EDGE_COUNT; i++) {
23 out = 1;
24 wait(0.2);
25 out = 0;
26 wait(0.2);
27 }
28 }
29
30 void in_handler() {
31 checks++;
32 myled = !myled;
33 }
34
35 static bool test_once() {
36 InterruptIn in(PIN_IN);
37 checks = 0;
38 printf("Interrupt table location: 0x%08X\r\n", SCB->VTOR);
39 in.rise(NULL);
40 in.fall(in_handler);
41 flipper();
42 in.fall(NULL);
43 bool result = (checks == FALLING_EDGE_COUNT);
44 printf("Falling edge checks counted: %d ... [%s]\r\n", checks, result ? "OK" : "FAIL");
45 return result;
46 }
47
48 int main() {
49 MBED_HOSTTEST_TIMEOUT(15);
50 MBED_HOSTTEST_SELECT(default_auto);
51 MBED_HOSTTEST_DESCRIPTION(Interrupt vector relocation);
52 MBED_HOSTTEST_START("MBED_A18");
53
54 // First test, no table reallocation
55 {
56 printf("Starting first test (interrupts not relocated).\r\n");
57 bool ret = test_once();
58 if (ret == false) {
59 MBED_HOSTTEST_RESULT(false);
60 }
61 }
62
63 // Relocate interrupt table and test again
64 {
65 printf("Starting second test (interrupts relocated).\r\n");
66 memcpy(int_table, (void*)SCB->VTOR, sizeof(int_table));
67 SCB->VTOR = (uint32_t)int_table;
68
69 bool ret = test_once();
70 if (ret == false) {
71 MBED_HOSTTEST_RESULT(false);
72 }
73 }
74
75 MBED_HOSTTEST_RESULT(true);
76 }
Imprint / Impressum