def save(self, reg_list): """ Converts the extracted data into register and bit field values, and loads the new data into the database. """ lookup = {'rw': BitField.TYPE_READ_WRITE, 'w': BitField.TYPE_WRITE_ONLY, 'r': BitField.TYPE_READ_ONLY} name_count = {} for reg in reg_list: for item in reg.field_list: if item.name in name_count: name_count[item.name] = name_count[item.name] + 1 else: name_count[item.name] = 1 duplicates = set([key for key in name_count if name_count[key] > 1]) current_duplicates = {} offset = self.dbase.data_bus_width / 8 for reg in reg_list: register = Register() register.address = reg.address register.register_name = reg.reg_name register.token = reg.token if not reg.description: register.description = reg.description else: register.description = reg.reg_name register.width = self.dbase.data_bus_width for item in reg.field_list: if item.name.startswith("OBSOLETE"): continue delta = (register.address % offset) * 8 if item.name in duplicates: if item.name in current_duplicates: index = current_duplicates[item.name] + 1 else: index = 1 current_duplicates[item.name] = index name = "%s_%d" % (item.name, index) else: name = item.name width = (item.stop - item.start) + 1 field = BitField() field.field_name = name field.field_type = lookup.get(item.software_access, BitField.READ_ONLY) field.start_position = item.start - delta field.stop_position = item.stop - delta field.reset_value = item.reset field.volatile = item.volatile field.description = item.description register.add_bit_field(field) self.dbase.add_register(register)
def save(self, reg_list): """ Converts the extracted data into register and bit field values, and loads the new data into the database. """ lookup = { '"rw"': BitField.TYPE_READ_WRITE, '"w"': BitField.TYPE_WRITE_ONLY, '"r"': BitField.TYPE_READ_ONLY } for (reg_name, addr_txt, width, field_list) in reg_list: register = Register() register.address = int(addr_txt, 16) register.register_name = reg_name register.width = width register.token = reg_name self.dbase.add_register(register) for item in field_list: field = BitField() field.field_name = item.name try: field.field_type = lookup[item.software_access] except IndexError: field.field_type = BitField.TYPE_READ_ONLY field.start_position = item.start field.stop_position = item.stop field.reset_value = item.reset field.description = item.description register.add_bit_field(field)
def save(self, reg_list): """ Converts the extracted data into register and bit field values, and loads the new data into the database. """ lookup = {'rw': BitField.READ_WRITE, 'w': BitField.WRITE_ONLY, 'r': BitField.READ_ONLY} for (reg_name, addr_txt, field_list) in reg_list: register = Register() register.address = int(addr_txt, 16) register.register_name = reg_name register.token = reg_name self.dbase.add_register(register) for item in field_list: field = BitField() field.field_name = item.name field.field_type = lookup.get(item.software_access, BitField.READ_ONLY) field.start_position = item.start field.stop_position = item.stop field.reset_value = item.reset field.description = item.description register.add_bit_field(field)
def import_data(self, filename): """ Opens, parses, and extracts data from the input file. """ next_addr = 0 field = None field_list = [] reg_list = [] col = {} name2addr = {} input_file = open(filename, "rU") titles = input_file.readline().split(",") for (i,name) in enumerate(titles): col[name] = i r_addr_col = col.get(REG_ADDR, -1) r_descr_col = col.get(REG_DESCR, -1) r_name_col = col.get(REG_NAME, -1) r_width_col = col.get(REG_WIDTH, -1) f_name_col = col.get(FIELD_NAME, -1) f_start_col = col.get(FIELD_OFFSET, -1) f_width_col = col.get(FIELD_WIDTH, -1) f_reset_col = col.get(FIELD_RESET, -1) f_type_col = col.get(FIELD_ACCESS, -1) f_descr_col = col.get(FIELD_DESCR, -1) for line in input_file: data = line.split(",") if is_blank(data): continue if r_name_col != -1: r_name = data[r_name_col].strip() else: r_name = "REG%04x" % r_addr r_token = r_name.upper().replace(" ", "_") if r_width_col != -1: r_width = parse_hex_value(data[r_width_col]) else: r_width = 32 if r_descr_col == -1: r_descr = "" else: r_descr = data[r_descr_col].strip() if data[r_addr_col].strip() == "": r_addr = name2addr.get(r_name, next_addr) else: r_addr = parse_hex_value(data[r_addr_col]) next_addr = r_addr + r_width/8 name2addr[r_name] = r_addr if f_start_col != -1: f_start = parse_hex_value(data[f_start_col]) if f_width_col != -1: width = parse_hex_value(data[col[FIELD_WIDTH]]) if width == 0: f_stop = f_start else: f_stop = f_start + width - 1 else: f_stop = f_start if f_descr_col != -1: f_descr = data[f_descr_col] else: f_descr = "" if f_name_col != -1: f_name = data[f_name_col].strip() elif f_stop == f_start: f_name = "BIT%d" % f_stop else: f_name = "BITS_%d_%d" % (f_stop, f_start) if f_reset_col != -1: f_reset = parse_hex_value(data[col[FIELD_RESET]]) else: f_reset = 0 if f_type_col == -1: if data[f_type_col] == "RW": f_type = BitField.READ_WRITE else: f_type = BItField.READ_ONLY else: f_type = BitField.READ_ONLY if r_addr in self.dbase.get_keys(): reg = self.dbase.get_register(r_addr) else: reg = Register() reg.address = r_addr reg.description = r_descr reg.token = r_token reg.width = r_width reg.register_name = r_name self.dbase.add_register(reg) field = BitField() field.field_name = f_name field.description = f_descr field.start_position = f_start field.stop_position = f_stop field.field_type = f_type reg.add_bit_field(field) input_file.close()