Example #1
0
def replace_in_memory_block(data, startaddr, replace_dict):
    """
    Replace memory cells in memory write commands in an XML profile
    This function won't be applied to EEPROM write commands!
    """
    cell_len = Adau145x.cell_len(startaddr)

    assert len(data) % cell_len == 0

    endaddr = startaddr + len(data) / cell_len

    for repl_addr in replace_dict.keys():
        if repl_addr >= startaddr and repl_addr <= endaddr:
            content = replace_dict[repl_addr]

            if len(content) != cell_len:
                logging.error(
                    "Cell %s: content len is %s but cell len is %s, ignoring",
                    repl_addr, len(content), cell_len)
                continue

            assert len(content) == cell_len

            address_offset = (repl_addr - startaddr) * cell_len
            logging.debug("replacing memory at address {} by {}", repl_addr,
                          content)

            data[address_offset:address_offset + len(content)] = content
Example #2
0
    def get_updates(self, xmlprofile):

        replace = {}

        for attribute in self.values:
            (addr, length) = xmlprofile.get_addr_length(attribute)

            if addr is None and attribute.startswith("0x"):
                # if it's not a setting form the profile, it might be
                # a memory address
                try:
                    addr = int(attribute, 16)
                    length = 1
                except:
                    logging.error("can't parse address %s", addr)
                    addr = None

            if addr is None:
                continue

            val = self.values[attribute]

            word_length = Adau145x.cell_len(addr)
            memory = self.param_to_bytes(val, length, word_length=word_length)

            if len(memory) <= self.dsp.cell_len(addr):
                replace[addr] = memory
            else:
                # Split long replaced into single words
                assert len(memory) % word_length == 0

                while len(memory) > 0:
                    cellvalue = memory[0:word_length]
                    replace[addr] = cellvalue
                    addr += 1
                    memory = memory[word_length:]

        return replace