13
13
DigitalOut out (PIN_OUT);
14
14
DigitalOut myled (LED1);
15
15
16
- static volatile int checks;
17
- static uint32_t int_table[NUM_VECTORS];
16
+ volatile int checks = 0 ;
17
+ uint32_t int_table[NUM_VECTORS];
18
+
19
+ #define FALLING_EDGE_COUNT 5
18
20
19
21
void flipper () {
20
- for (int i = 0 ; i < 5 ; i++) {
22
+ for (int i = 0 ; i < FALLING_EDGE_COUNT ; i++) {
21
23
out = 1 ;
22
24
wait (0.2 );
23
25
out = 0 ;
@@ -38,24 +40,36 @@ static bool test_once() {
38
40
in.fall (in_handler);
39
41
flipper ();
40
42
in.fall (NULL );
41
- bool result = (checks == 5 );
42
- printf (result ? " Test passed. \r\n " : " Test failed. \r\n " );
43
+ bool result = (checks == FALLING_EDGE_COUNT );
44
+ printf (" Falling edge checks counted: %d ... [%s] \r\n " , checks, result ? " OK " : " FAIL " );
43
45
return result;
44
46
}
45
47
46
48
int main () {
47
- printf (" Starting first test (interrupts not relocated).\r\n " );
48
- if (!test_once ()) {
49
- notify_completion (false );
50
- return 1 ;
49
+
50
+ // First test, no table reallocation
51
+ {
52
+ printf (" Starting first test (interrupts not relocated).\r\n " );
53
+ bool ret = test_once ();
54
+ if (ret == false ) {
55
+ notify_completion (false );
56
+ return 1 ;
57
+ }
51
58
}
52
59
53
60
// Relocate interrupt table and test again
54
- memcpy (int_table, (void *)SCB->VTOR , sizeof (int_table));
55
- SCB->VTOR = (uint32_t )int_table;
56
- printf (" Starting second test (interrupts relocated).\r\n " );
61
+ {
62
+ printf (" Starting second test (interrupts relocated).\r\n " );
63
+ memcpy (int_table, (void *)SCB->VTOR , sizeof (int_table));
64
+ SCB->VTOR = (uint32_t )int_table;
57
65
58
- notify_completion (test_once ());
66
+ bool ret = test_once ();
67
+ if (ret == false ) {
68
+ notify_completion (false );
69
+ return 1 ;
70
+ }
71
+ }
72
+
73
+ notify_completion (true );
59
74
return 0 ;
60
75
}
61
-
0 commit comments