1use super::*;
2use crate::svd::{Cpu, Endian};
3use crate::types::BoolParse;
4
5impl Parse for Cpu {
6 type Object = Self;
7 type Error = SVDErrorAt;
8 type Config = Config;
9
10 fn parse(tree: &Node, config: &Config) -> Result<Self, Self::Error> {
11 if !tree.has_tag_name("cpu") {
12 return Err(SVDError::NotExpectedTag("cpu".to_string()).at(tree.id()));
13 }
14
15 let has_vendor_systick = match tree.get_child_bool("vendorSystickConfig") {
18 Ok(v) => v,
19 Err(e) if config.target == Target::CortexM => return Err(e),
20 _ => false,
21 };
22
23 let has_mpu_present = match tree.get_child_bool("mpuPresent") {
24 Ok(v) => v,
25 _ => false,
26 };
27
28 let has_fpu_present = match tree.get_child_bool("fpuPresent") {
29 Ok(v) => v,
30 _ => false,
31 };
32
33 Cpu::builder()
34 .name(tree.get_child_text("name")?)
35 .revision(tree.get_child_text("revision")?)
36 .endian(Endian::parse(&tree.get_child_elem("endian")?, config)?)
37 .mpu_present(has_mpu_present)
38 .fpu_present(has_fpu_present)
39 .fpu_double_precision(optional::<BoolParse>("fpuDP", tree, &())?)
40 .dsp_present(optional::<BoolParse>("dspPresent", tree, &())?)
41 .icache_present(optional::<BoolParse>("icachePresent", tree, &())?)
42 .dcache_present(optional::<BoolParse>("dcachePresent", tree, &())?)
43 .itcm_present(optional::<BoolParse>("itcmPresent", tree, &())?)
44 .dtcm_present(optional::<BoolParse>("dtcmPresent", tree, &())?)
45 .vtor_present(optional::<BoolParse>("vtorPresent", tree, &())?)
46 .nvic_priority_bits(tree.get_child_u32("nvicPrioBits")?)
47 .has_vendor_systick(has_vendor_systick)
48 .device_num_interrupts(optional::<u32>("deviceNumInterrupts", tree, &())?)
49 .sau_num_regions(optional::<u32>("sauNumRegions", tree, &())?)
50 .build(config.validate_level)
51 .map_err(|e| SVDError::from(e).at(tree.id()))
52 }
53}