def _parse_register(self, register_node): fields = [] for field_node in register_node.findall('.//field'): node = self._parse_field(field_node) if self.remove_reserved is 0 or 'reserved' not in node.name.lower(): fields.append(node) dim = _get_int(register_node, 'dim') dim_index_text = _get_text(register_node, 'dimIndex') if dim is not None: if dim_index_text is None: dim_index = range(0,dim) #some files omit dimIndex elif ',' in dim_index_text: dim_index = dim_index_text.split(',') elif '-' in dim_index_text: #some files use <dimIndex>0-3</dimIndex> as an inclusive inclusive range m=re.search('([0-9]+)-([0-9]+)', dim_index_text) dim_index = range(int(m.group(1)),int(m.group(2))+1) else: dim_index = None return SVDRegister( name=_get_text(register_node, 'name'), description=_get_text(register_node, 'description'), address_offset=_get_int(register_node, 'addressOffset'), size=_get_int(register_node, 'size'), access=_get_text(register_node, 'access'), reset_value=_get_int(register_node, 'resetValue'), reset_mask=_get_int(register_node, 'resetMask'), fields=fields, dim=dim, dim_increment=_get_int(register_node, 'dimIncrement'), dim_index=dim_index )
def process_peripheral(raw_peripheral, device): if (raw_peripheral.derived_from != None): base_peripheral = raw_peripheral.get_derived_from() result = Peripheral( raw_peripheral.name, raw_peripheral._base_address if (raw_peripheral._base_address != None) else base_peripheral._base_address, raw_peripheral._access if (raw_peripheral._access != None) else base_peripheral._access, raw_peripheral._size if (raw_peripheral._size != None) else base_peripheral._size, raw_peripheral._description if (raw_peripheral._description != None) else base_peripheral._description) if (raw_peripheral._registers != None): for raw_register in raw_peripheral._registers: result.registers.append(process_register(raw_register, result)) else: if (base_peripheral._registers != None): for raw_register in base_peripheral._registers: result.registers.append(process_register(raw_register, result)) else: result = Peripheral( raw_peripheral.name, raw_peripheral._base_address, raw_peripheral._access if (raw_peripheral._access != None) else device.access, raw_peripheral._size if (raw_peripheral._size != None) else device.size, raw_peripheral._description) if (raw_peripheral._registers != None): for raw_register in raw_peripheral._registers: result.registers.append(process_register(raw_register, result)) if(raw_peripheral._register_arrays != None): for raw_register in raw_peripheral._register_arrays: for i in range(raw_register.dim): _name = raw_register.name % raw_register.dim_indices[i] _name = _name.replace('[','') _name = _name.replace(']','') reg = SVDRegister( name = _name, fields = raw_register._fields, fields_array = raw_register._fields_array, derived_from = raw_register.derived_from, description = raw_register.description, address_offset = raw_register.address_offset + raw_register.dim_increment * i, size = raw_register._size, access = raw_register._access, protection = raw_register._protection, reset_value = raw_register._reset_value, reset_mask = raw_register._reset_mask, display_name = raw_register._display_name, alternate_group = raw_register._alternate_group, modified_write_values = raw_register._modified_write_values, read_action = raw_register._read_action, ) result.registers.append(process_register(reg, result)) return result
def duplicate_array_of_registers(input): #expects a SVDRegister which is an array of registers output = [] assert(input.dim == len(input.dim_index)) for i in range(input.dim): output.append(SVDRegister( name=input.name % input.dim_index[i], description=input.description, address_offset=input.address_offset+input.dim_increment*i, size=input.size, access=input.access, reset_value=input.reset_value, reset_mask=input.reset_mask, fields=input.fields, dim=None, dim_increment=None, dim_index=None ) ) return output
def _parse_registers(self, register_node): fields = [] for field_node in register_node.findall('.//field'): node = self._parse_field(field_node) if self.remove_reserved or 'reserved' not in node.name.lower(): fields.append(node) dim = _get_int(register_node, 'dim') name = _get_text(register_node, 'name') derived_from = _get_text(register_node, 'derivedFrom') description = _get_text(register_node, 'description') address_offset = _get_int(register_node, 'addressOffset') size = _get_int(register_node, 'size') access = _get_text(register_node, 'access') protection = _get_text(register_node, 'protection') reset_value = _get_int(register_node, 'resetValue') reset_mask = _get_int(register_node, 'resetMask') dim_increment = _get_int(register_node, 'dimIncrement') dim_index_text = _get_text(register_node, 'dimIndex') display_name = _get_text(register_node, 'displayName') alternate_group = _get_text(register_node, 'alternateGroup') modified_write_values = _get_text(register_node, 'modifiedWriteValues') read_action = _get_text(register_node, 'readAction') if dim is None: return SVDRegister( name=name, fields=fields, derived_from=derived_from, description=description, address_offset=address_offset, size=size, access=access, protection=protection, reset_value=reset_value, reset_mask=reset_mask, display_name=display_name, alternate_group=alternate_group, modified_write_values=modified_write_values, read_action=read_action, ) else: # the node represents a register array if dim_index_text is None: dim_indices = range(0, dim) # some files omit dimIndex elif ',' in dim_index_text: dim_indices = dim_index_text.split(',') elif '-' in dim_index_text: # some files use <dimIndex>0-3</dimIndex> as an inclusive inclusive range m = re.search(r'([0-9]+)-([0-9]+)', dim_index_text) dim_indices = range(int(m.group(1)), int(m.group(2)) + 1) else: raise ValueError("Unexpected dim_index_text: %r" % dim_index_text) # yield `SVDRegisterArray` (caller will differentiate on type) return SVDRegisterArray( name=name, fields=fields, derived_from=derived_from, description=description, address_offset=address_offset, size=size, access=access, protection=protection, reset_value=reset_value, reset_mask=reset_mask, display_name=display_name, alternate_group=alternate_group, modified_write_values=modified_write_values, read_action=read_action, dim=dim, dim_indices=dim_indices, dim_increment=dim_increment, )