-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_int.sh
executable file
·63 lines (49 loc) · 1 KB
/
gen_int.sh
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
#!/bin/sh
set -e
src="$1"
test -f "$src"
test -f ../../../common/include/interrupt/base
gen_int()
{
local name="$1"
cat > $int.hpp <<EOF
#pragma once
#include <avr/io.h>
#include <interrupt/base>
typedef Interrupt<${int}_vect_num> ${int}Interrupt;
EOF
cat > $int.cpp <<EOF
#include <avr/interrupt.h>
#include <interrupt/${int}.hpp>
ISR(${int}_vect, ISR_NAKED)
{
asm(
"push r24\\n"
"ldi r24, 1\\n"
"sts %0, r24\\n"
"pop r24\\n"
"reti\\n"
:
: "m" (${int}Interrupt::fire_)
);
}
template <>
volatile bool ${int}Interrupt::fire_ = false;
EOF
cat > ${int}_cb.cpp <<EOF
#include <avr/interrupt.h>
#include <interrupt/${int}.hpp>
template <>
callback_t ${int}Interrupt::callback_ = nullptr;
EOF
}
rm -f *.cpp *.hpp
cat > CMakeLists.txt <<EOF
# generated as: $0 $@
add_library("\${MCU}_interrupt" STATIC
EOF
for int in $(sed -n -r -e '/_vect_num/{s/^.*define[[:space:]]+//; s/_vect_num.*//; p}' "$src"); do
gen_int $int
echo " $int.cpp ${int}_cb.cpp" >> CMakeLists.txt
done
echo ")" >> CMakeLists.txt