-
Notifications
You must be signed in to change notification settings - Fork 130
/
vectors.c.in
81 lines (73 loc) · 2.94 KB
/
vectors.c.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (c) 2018, Niklas Hauser
*
* This file is part of the modm project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <modm/architecture/utils.hpp>
// ----------------------------------------------------------------------------
void Undefined_Handler(void);
/* Provide weak aliases for each Exception handler to Undefined_Handler.
* As they are weak aliases, any function with the same name will override
* this definition. */
void Reset_Handler(void);
void NMI_Handler(void) __attribute__((weak, alias("Undefined_Handler")));
void HardFault_Handler(void) __attribute__((weak, alias("Undefined_Handler")));
%% for pos in range(4 - 16, highest_irq + 1)
%% if pos in vector_table
{{ ("void " ~ vector_table[pos] ~ "(void)") | lbuild.pad(47)}}__attribute__((weak, alias("Undefined_Handler")));
%% endif
%% endfor
// ----------------------------------------------------------------------------
typedef void (* const FunctionPointer)(void);
// defined in the linkerscript
extern uint32_t __main_stack_top[];
// Define the vector table
modm_section(".vector_rom")
FunctionPointer vectorsRom[] =
{
(FunctionPointer)__main_stack_top, // -16: stack pointer
Reset_Handler, // -15: code entry point
NMI_Handler, // -14: Non Maskable Interrupt handler
HardFault_Handler, // -13: hard fault handler
%% for pos in range(4 - 16, highest_irq)
%% if pos in vector_table
{{ (vector_table[pos] ~ ",") | lbuild.pad(39) }}// {{ (pos|string).rjust(3) }}
%% else
Undefined_Handler, // {{ (pos|string).rjust(3) }}
%% endif
%% endfor
};
%% if vector_table_location == "ram"
// reserve space for the remapped vector table in RAM
modm_section(".vector_ram")
FunctionPointer vectorsRam[sizeof(vectorsRom) / sizeof(FunctionPointer)];
%% endif
// ----------------------------------------------------------------------------
// Ignore redeclaration of interrupt handlers in vendor headers
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
// Explicitly include this BELOW the vector table to *not deal* with potential
// re-#defines of interrupt vector names! Bad vendors!! BAD!!!
#include <modm/platform/device.hpp>
%% if with_assert
#include <modm/architecture/interface/assert.h>
%% endif
void Undefined_Handler(void)
{
%% if with_assert
const int32_t irqn = ((int32_t)__get_IPSR()) - 16;
// Set the currently executing interrupt to the lowest priority to allow
// reporting of the assertion failure and disable it from firing again.
NVIC_SetPriority((IRQn_Type)irqn, (1ul << __NVIC_PRIO_BITS) - 1ul);
NVIC_DisableIRQ((IRQn_Type)irqn);
modm_assert_continue_fail(0, "nvic.undef",
"An undefined NVIC interrupt was raised!", irqn);
%% endif
}
#pragma GCC diagnostic pop