-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmsp430_c2nim.ed
63 lines (63 loc) · 2 KB
/
msp430_c2nim.ed
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
# TODO: Translate this whole mess into Nim.
# Strip underscores from beginning and end
,s/\b_\+//g
,s/__\b//g
# Except for addresses, where we append ADDR
,s/_\b/_ADDR/g
# Comment out totally unhelpful bit or value definitions
g/\b\(ADC[0-9]\+PDIV\|ID\|TBIDEX\|FLL[A-Z]\+\|DIV[SMAP]\+\)_\([0-9]\+\)\*/s/^/#/
# Some parts have __ for symbolic part values
,s/\([A-Z0-9]\)__\([A-Z]\)/\1_\2/g
# Others have it for numeric values, avoid clashing with bit names
,s/\B__\B/_VAL_/g
# Some registers have _3 for value, not bit position
,s/\b\([A-Z0-9]\+\)_\([0-9]\+\)\b/\1_VAL_\2/g
# Some parts have _0 for bit and __1 for divider, for instance
#,s/\([^V]AL\|[^A]L\|[^L0-9]\|[^_0-9][0-9]\|[^_][0-9][0-9]\)_\([0-9]\+\)\b/\1_BIT\2/g
# .. and the consts that broke
g/REFVSEL_0\|PMMCOREV_0/-s/^ const/ #const/
# Some use _ for decimal point
,s/_\([0-9]\+\)_\([0-9]\+\)\b/_VAL_\1P\2/g
# These are indices, not values
,s/\(USB[A-Z0-9]*\)_VAL/\1/g
# RTCYEARL is already RTCYEAR_L
,s/\(\b\([A-Z0-9]\+\)\([LH]\)\* = \2_\3\)/# \1/g
# Move the interrupt vectors to avoid forward references
/Interrupt Vectors/,/End of Modules/m/STANDARD BITS/
# Doubly defined constants
/UCRXIE/s/^/#/
-s/^/#/
-s/^/#/
/UCRXIFG/s/^/#/
-s/^/#/
-s/^/#/
# A lot of the defines are aliases, not constants
# Move const line to below the template replacements
/P4MAP0\*/-m/P4MAP7/
/USBKEYPID\*/-m/USBKEYPID\*/
/UCA0CTL1\*/-m/UCA0CTL0\*/
/UCA0BR0\*/-m/UCA0BR1\*/
/UCA0IRTCTL\*/-m/UCA0IRRCTL\*/
/UCA0IE\*/-m/UCA0IFG\*/
/UCB0CTL1\*/-m/UCB0CTL0\*/
/UCB0BR0\*/-m/UCB0BR1\*/
/UCB0IE\*/-m/UCB0IFG\*/
/UCA1CTL1\*/-m/UCA1CTL0\*/
/UCA1BR0\*/-m/UCA1BR1\*/
/UCA1IRTCTL\*/-m/UCA1IRRCTL\*/
/UCA1IE\*/-m/UCA1IFG\*/
/UCB1CTL1\*/-m/UCB1CTL0\*/
/UCB1BR0\*/-m/UCB1BR1\*/
/UCB1IE\*/-m/UCB1IFG\*/
# Replace direct symbol macros with templates
,s/^ \([A-Z][A-Z0-9_]*\* = (\?[A-Z][A-Z0-9_]*)\? *\(#.*\)\?\)$/ template \1/
g/^ template/-s/^ const/ #const/
# Remove some legacy aliases (easier than fixing them up)
g/^ PMAPPW/d
g/sfrb(OP2_[LHB],/d
# Inject iomacros import
0i
import iomacros
.
# Save
w