-
Notifications
You must be signed in to change notification settings - Fork 1
/
common.xsl
191 lines (176 loc) · 7.31 KB
/
common.xsl
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
xmlns:thi="http://thi.ng/">
<!-- http://www.ibm.com/developerworks/xml/library/x-xsltip.html -->
<xsl:key name="access-lookup" match="thi:access" use="@exp"/>
<xsl:variable name="access-modes" select="document('')/*/thi:accessModes"/>
<thi:accessModes>
<thi:access abbr="R only" exp="read-only"/>
<thi:access abbr="W only" exp="write-only"/>
<thi:access abbr="R/W" exp="read-write"/>
</thi:accessModes>
<xsl:param name="only" as="xs:string" required="no">
<xsl:value-of select="''"/>
</xsl:param>
<xsl:param name="excl" as="xs:string" required="no">
<xsl:value-of select="''"/>
</xsl:param>
<xsl:variable name="NL" select="'
'"/>
<!-- http://stackoverflow.com/questions/3299938/creating-arrays-in-xslt -->
<xsl:variable name="bitMasks" as="element()*">
<Item>0x1</Item>
<Item>0x3</Item>
<Item>0x7</Item>
<Item>0xf</Item>
<Item>0x1f</Item>
<Item>0x3f</Item>
<Item>0x7f</Item>
<Item>0xff</Item>
<Item>0x1ff</Item>
<Item>0x3ff</Item>
<Item>0x7ff</Item>
<Item>0xfff</Item>
<Item>0x1fff</Item>
<Item>0x3fff</Item>
<Item>0x7fff</Item>
<Item>0xffff</Item>
<Item>0x1ffff</Item>
<Item>0x3ffff</Item>
<Item>0x7ffff</Item>
<Item>0xfffff</Item>
<Item>0x1fffff</Item>
<Item>0x3fffff</Item>
<Item>0x7fffff</Item>
<Item>0xffffff</Item>
<Item>0x1ffffff</Item>
<Item>0x3ffffff</Item>
<Item>0x7ffffff</Item>
<Item>0xfffffff</Item>
<Item>0x1fffffff</Item>
<Item>0x3fffffff</Item>
<Item>0x7fffffff</Item>
<Item>0xffffffff</Item>
</xsl:variable>
<xsl:function name="thi:line-comment">
<xsl:param name="body" as="xs:string"/>
<xsl:value-of select="concat(' ',$lcommentPrefix,fn:normalize-space($body),$lcommentSuffix,$NL)"/>
</xsl:function>
<xsl:function name="thi:block-comment">
<xsl:param name="body" as="xs:string"/>
<xsl:value-of select="concat($bcommentPrefix,$NL,$bcommentLPrefix,replace($body,$NL,concat($NL,$bcommentLPrefix)),$NL,$bcommentSuffix,$NL)"/>
</xsl:function>
<xsl:template match="/device">
<xsl:variable name="header">
<xsl:value-of select="concat(name,' v',version,' SVD peripherals & registers
generated @ ')"/>
<xsl:value-of select="format-dateTime(current-dateTime(), '[Y0001]-[M01]-[D01] [H01]:[m01]:[s01]', 'en', (), ())"/>
<xsl:text>

DO NOT EDIT! This file was auto-generated with:</xsl:text>
<xsl:text>
http://github.com/postspectacular/cmsis-svd-srcgen</xsl:text>
</xsl:variable>
<xsl:value-of select="thi:block-comment($header)"/>
<xsl:text>
</xsl:text>
<xsl:value-of select="thi:lang-prologue()"/>
<xsl:for-each select="peripherals/peripheral/name[(not($only) or fn:contains($only, text())) and (not($excl) or not(fn:contains($excl, text())))]/..">
<xsl:variable name="derived" select="@derivedFrom"/>
<xsl:choose>
<xsl:when test="$derived">
<xsl:call-template name="peripheral-derived">
<xsl:with-param name="src" select="../peripheral/name[text()=$derived]/.."/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="peripheral"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>
</xsl:text>
</xsl:for-each>
<!-- Interrupts -->
<xsl:value-of select="thi:block-comment('Interrupt handlers')"/>
<xsl:for-each select="peripherals/peripheral/interrupt">
<xsl:sort select="value" data-type="number"/>
<xsl:call-template name="irq"/>
</xsl:for-each>
<xsl:value-of select="thi:lang-epilogue()"/>
</xsl:template>
<xsl:template name="peripheral">
<xsl:variable name="device" select="thi:lang-symbolname(name)"/>
<xsl:choose>
<xsl:when test="description">
<xsl:value-of select="thi:block-comment(fn:normalize-space(description))"/>
</xsl:when>
</xsl:choose>
<xsl:value-of select="concat(thi:lang-def($device,fn:lower-case(baseAddress)),$NL)"/>
<xsl:for-each select="registers/register">
<xsl:call-template name="register">
<xsl:with-param name="device" select="$device"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="peripheral-derived">
<xsl:param name="src"/>
<xsl:variable name="srcName" select="$src/name"/>
<xsl:variable name="device" select="thi:lang-symbolname(name)"/>
<xsl:choose>
<xsl:when test="$src/description">
<xsl:value-of select="thi:block-comment(concat(fn:normalize-space($src/description), ' (derived from ', $srcName, ')'))"/>
</xsl:when>
</xsl:choose>
<xsl:value-of select="concat(thi:lang-def($device,fn:lower-case(baseAddress)),$NL)"/>
<xsl:for-each select="$src/registers/register">
<xsl:call-template name="register">
<xsl:with-param name="device" select="$device"/>
</xsl:call-template>
</xsl:for-each>
</xsl:template>
<xsl:template name="register" >
<xsl:param name="device"/>
<xsl:variable name="reg" select="concat($device,$sep,name)"/>
<xsl:variable name="offset" select="fn:lower-case(addressOffset)"/>
<xsl:variable name="access">
<xsl:apply-templates select="$access-modes">
<xsl:with-param name="mode" select="access"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:value-of select="thi:lang-def($reg,thi:lang-expr('+',$device,$offset))"/>
<xsl:value-of select="thi:line-comment(concat(description, ' (',$access,')'))"/>
<xsl:value-of select="concat(thi:lang-def(concat($reg,$sep,'OFFSET'),$offset),$NL)"/>
<xsl:choose>
<xsl:when test="resetValue">
<xsl:value-of select="concat(thi:lang-def(concat($reg,$sep,'RESET'),resetValue),$NL)"/>
</xsl:when>
</xsl:choose>
<xsl:for-each select="fields/field">
<xsl:variable name="bw" as="xs:integer" select="bitWidth"/>
<xsl:variable name="boff" as="xs:integer" select="bitOffset"/>
<xsl:variable name="zmask" as="xs:string" select="$bitMasks[$bw]"/>
<xsl:variable name="fname" as="xs:string" select="concat($reg,$sep,name)"/>
<xsl:variable name="mask">
<xsl:choose>
<xsl:when test="$boff > 0">
<xsl:value-of select="thi:lang-expr('<<',$zmask,$boff)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$zmask"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- field shifted bitmask -->
<xsl:value-of select="concat(thi:lang-def($fname,$mask),$NL)"/>
<!-- field bit shift -->
<xsl:value-of
select="concat(thi:lang-def(concat($fname,$sep,'SHIFT'),$boff),$NL)"/>
</xsl:for-each>
</xsl:template>
<xsl:template name="irq">
<xsl:value-of select="thi:lang-def(concat('IRQ_',name),value)"/>
<xsl:value-of select="thi:line-comment(description)"/>
</xsl:template>
<xsl:template match="thi:accessModes">
<xsl:param name="mode"/>
<xsl:value-of select="key('access-lookup', $mode)/@abbr"/>
</xsl:template>
</xsl:stylesheet>