Skip to content

Commit 513cbc2

Browse files
committed
Try #258:
2 parents 41f1908 + 376940c commit 513cbc2

File tree

3 files changed

+89
-71
lines changed

3 files changed

+89
-71
lines changed

ci/script.sh

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,22 @@ main() {
5757
echo '[dependencies.bare-metal]' >> $td/Cargo.toml
5858
echo 'version = "0.2.0"' >> $td/Cargo.toml
5959

60-
# BAD-SVD missing resetValue
60+
# OK
61+
# NOTE it would take too long to test all these so we only test a few
6162
# test_svd AT91SAM9CN11
62-
# test_svd AT91SAM9CN12
63+
test_svd AT91SAM9CN12
6364
# test_svd AT91SAM9G10
6465
# test_svd AT91SAM9G15
6566
# test_svd AT91SAM9G20
6667
# test_svd AT91SAM9G25
67-
# test_svd AT91SAM9G35
68+
test_svd AT91SAM9G35
6869
# test_svd AT91SAM9M10
69-
# test_svd AT91SAM9M11
70-
# test_svd AT91SAM9N12
70+
test_svd AT91SAM9M11
71+
test_svd AT91SAM9N12
7172
# test_svd AT91SAM9X25
72-
# test_svd AT91SAM9X35
73+
test_svd AT91SAM9X35
74+
75+
# BAD-SVD duplicate enumeration values
7376
# test_svd ATSAM3A4C
7477
# test_svd ATSAM3A8C
7578
# test_svd ATSAM3N00A
@@ -115,10 +118,12 @@ main() {
115118
# test_svd ATSAM4S8C
116119
# test_svd ATSAM4SD32B
117120
# test_svd ATSAM4SD32C
121+
122+
# OK
118123
# test_svd ATSAMA5D31
119124
# test_svd ATSAMA5D33
120125
# test_svd ATSAMA5D34
121-
# test_svd ATSAMA5D35
126+
test_svd ATSAMA5D35
122127

123128
# FIXME(#107) "failed to resolve. Use of undeclared type or module `sercom0`"
124129
# test_svd ATSAMD21E15A

ci/svd2rust-regress/src/tests.rs

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -167,103 +167,103 @@ impl ToSanitizedSnakeCase for str {
167167

168168
// NOTE: All chip names must be unique!
169169
pub const TESTS: &'static [&'static TestCase] = &[
170-
// BAD-SVD missing resetValue
171170
&TestCase {
172171
arch: CortexM,
173172
mfgr: Atmel,
174173
chip: "AT91SAM9CN11",
175174
svd_url: None,
176-
should_pass: false,
177-
run_when: Never,
175+
should_pass: true,
176+
run_when: NotShort,
178177
},
179178
&TestCase {
180179
arch: CortexM,
181180
mfgr: Atmel,
182181
chip: "AT91SAM9CN12",
183182
svd_url: None,
184-
should_pass: false,
185-
run_when: Never,
183+
should_pass: true,
184+
run_when: Always,
186185
},
187186
&TestCase {
188187
arch: CortexM,
189188
mfgr: Atmel,
190189
chip: "AT91SAM9G10",
191190
svd_url: None,
192-
should_pass: false,
193-
run_when: Never,
191+
should_pass: true,
192+
run_when: NotShort,
194193
},
195194
&TestCase {
196195
arch: CortexM,
197196
mfgr: Atmel,
198197
chip: "AT91SAM9G15",
199198
svd_url: None,
200-
should_pass: false,
201-
run_when: Never,
199+
should_pass: true,
200+
run_when: NotShort,
202201
},
203202
&TestCase {
204203
arch: CortexM,
205204
mfgr: Atmel,
206205
chip: "AT91SAM9G20",
207206
svd_url: None,
208-
should_pass: false,
209-
run_when: Never,
207+
should_pass: true,
208+
run_when: NotShort,
210209
},
211210
&TestCase {
212211
arch: CortexM,
213212
mfgr: Atmel,
214213
chip: "AT91SAM9G25",
215214
svd_url: None,
216-
should_pass: false,
217-
run_when: Never,
215+
should_pass: true,
216+
run_when: NotShort,
218217
},
219218
&TestCase {
220219
arch: CortexM,
221220
mfgr: Atmel,
222221
chip: "AT91SAM9G35",
223222
svd_url: None,
224-
should_pass: false,
225-
run_when: Never,
223+
should_pass: true,
224+
run_when: Always,
226225
},
227226
&TestCase {
228227
arch: CortexM,
229228
mfgr: Atmel,
230229
chip: "AT91SAM9M10",
231230
svd_url: None,
232-
should_pass: false,
233-
run_when: Never,
231+
should_pass: true,
232+
run_when: NotShort,
234233
},
235234
&TestCase {
236235
arch: CortexM,
237236
mfgr: Atmel,
238237
chip: "AT91SAM9M11",
239238
svd_url: None,
240-
should_pass: false,
241-
run_when: Never,
239+
should_pass: true,
240+
run_when: NotShort,
242241
},
243242
&TestCase {
244243
arch: CortexM,
245244
mfgr: Atmel,
246245
chip: "AT91SAM9N12",
247246
svd_url: None,
248-
should_pass: false,
249-
run_when: Never,
247+
should_pass: true,
248+
run_when: Always,
250249
},
251250
&TestCase {
252251
arch: CortexM,
253252
mfgr: Atmel,
254253
chip: "AT91SAM9X25",
255254
svd_url: None,
256-
should_pass: false,
257-
run_when: Never,
255+
should_pass: true,
256+
run_when: NotShort,
258257
},
259258
&TestCase {
260259
arch: CortexM,
261260
mfgr: Atmel,
262261
chip: "AT91SAM9X35",
263262
svd_url: None,
264-
should_pass: false,
265-
run_when: Never,
263+
should_pass: true,
264+
run_when: Always,
266265
},
266+
// BAD-SVD duplicate enumeration values
267267
&TestCase {
268268
arch: CortexM,
269269
mfgr: Atmel,
@@ -624,37 +624,38 @@ pub const TESTS: &'static [&'static TestCase] = &[
624624
should_pass: false,
625625
run_when: Never,
626626
},
627+
// OK
627628
&TestCase {
628629
arch: CortexM,
629630
mfgr: Atmel,
630631
chip: "ATSAMA5D31",
631632
svd_url: None,
632-
should_pass: false,
633-
run_when: Never,
633+
should_pass: true,
634+
run_when: NotShort,
634635
},
635636
&TestCase {
636637
arch: CortexM,
637638
mfgr: Atmel,
638639
chip: "ATSAMA5D33",
639640
svd_url: None,
640-
should_pass: false,
641-
run_when: Never,
641+
should_pass: true,
642+
run_when: NotShort,
642643
},
643644
&TestCase {
644645
arch: CortexM,
645646
mfgr: Atmel,
646647
chip: "ATSAMA5D34",
647648
svd_url: None,
648-
should_pass: false,
649-
run_when: Never,
649+
should_pass: true,
650+
run_when: NotShort,
650651
},
651652
&TestCase {
652653
arch: CortexM,
653654
mfgr: Atmel,
654655
chip: "ATSAMA5D35",
655656
svd_url: None,
656-
should_pass: false,
657-
run_when: Never,
657+
should_pass: true,
658+
run_when: NotShort,
658659
},
659660
// FIXME(#107) "failed to resolve. Use of undeclared type or module `sercom0`"
660661
&TestCase {

src/generate/register.rs

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,6 @@ pub fn render(
8383
}
8484

8585
if access == Access::WriteOnly || access == Access::ReadWrite {
86-
reg_impl_items.push(quote! {
87-
/// Writes to the register
88-
#[inline]
89-
pub fn write<F>(&self, f: F)
90-
where
91-
F: FnOnce(&mut W) -> &mut W
92-
{
93-
let mut w = W::reset_value();
94-
f(&mut w);
95-
self.register.set(w.bits);
96-
}
97-
});
98-
9986
mod_items.push(quote! {
10087
/// Value to write to the register
10188
pub struct W {
@@ -106,16 +93,51 @@ pub fn render(
10693
let rv = register
10794
.reset_value
10895
.or(defs.reset_value)
109-
.map(util::hex)
110-
.ok_or_else(|| format!("Register {} has no reset value", register.name))?;
96+
.map(util::hex);
11197

112-
w_impl_items.push(quote! {
113-
/// Reset value of the register
114-
#[inline]
115-
pub fn reset_value() -> W {
116-
W { bits: #rv }
117-
}
98+
if let Some(rv) = rv {
99+
w_impl_items.push(quote! {
100+
/// Reset value of the register
101+
#[inline]
102+
pub fn reset_value() -> W {
103+
W { bits: #rv }
104+
}
105+
});
106+
107+
reg_impl_items.push(quote! {
108+
/// Writes to the register
109+
#[inline]
110+
pub fn write<F>(&self, f: F)
111+
where
112+
F: FnOnce(&mut W) -> &mut W
113+
{
114+
let mut w = W::reset_value();
115+
f(&mut w);
116+
self.register.set(w.bits);
117+
}
118118

119+
/// Writes the reset value to the register
120+
#[inline]
121+
pub fn reset(&self) {
122+
self.write(|w| w)
123+
}
124+
});
125+
} else {
126+
reg_impl_items.push(quote! {
127+
/// Writes to the register
128+
#[inline]
129+
pub fn write<F>(&self, f: F)
130+
where
131+
F: FnOnce(&mut W) -> &mut W
132+
{
133+
let mut w = W { bits: 0 };
134+
f(&mut w);
135+
self.register.set(w.bits);
136+
}
137+
});
138+
}
139+
140+
w_impl_items.push(quote! {
119141
/// Writes raw bits to the register
120142
#[inline]
121143
pub #unsafety fn bits(&mut self, bits: #rty) -> &mut Self {
@@ -125,16 +147,6 @@ pub fn render(
125147
});
126148
}
127149

128-
if access == Access::ReadWrite {
129-
reg_impl_items.push(quote! {
130-
/// Writes the reset value to the register
131-
#[inline]
132-
pub fn reset(&self) {
133-
self.write(|w| w)
134-
}
135-
})
136-
}
137-
138150
mod_items.push(quote! {
139151
impl super::#name_pc {
140152
#(#reg_impl_items)*

0 commit comments

Comments
 (0)