Ejemplo n.º 1
0
def addRegisters(peripheral_blk_struct, peripheral, min_size):
    for register in peripheral.registers:
        if (register._size >= min_size):
            print("register {:s} {:02X}".format(register.name, register._size))
            # check if the register is a member of the current addressBlock
            if ((register.address_offset >= adrBlock.offset) and
                (register.address_offset < adrBlock.offset + adrBlock.size)):
                register_size = 32 if not register._size else register._size
                r_type = UnsignedIntegerDataType()
                rs = register_size // 8
                if rs == 1:
                    r_type = ByteDataType()
                elif rs == 2:
                    r_type = UnsignedShortDataType()
                elif rs == 8:
                    r_type = UnsignedLongLongDataType()

                # please note: The address for registering here must be relative to the addressBlock address/offset
                peripheral_blk_struct.replaceAtOffset(
                    register.address_offset - adrBlock.offset, r_type,
                    register_size // 8, register.name, register.description)
Ejemplo n.º 2
0
    peripheral_struct = StructureDataType(peripheral.name, length)

    peripheral_start = peripheral.base_address
    peripheral_end = peripheral_start + length

    for register in peripheral.registers:
        register_size = default_register_size if not register._size else register._size

        r_type = UnsignedIntegerDataType()
        rs = register_size / 8
        if rs == 1:
            r_type = ByteDataType()
        elif rs == 2:
            r_type = UnsignedShortDataType()
        elif rs == 8:
            r_type = UnsignedLongLongDataType()

        peripheral_struct.replaceAtOffset(register.address_offset, r_type,
                                          register_size / 8, register.name,
                                          register.description)

    addr = space.getAddress(peripheral_start)

    dtm.addDataType(peripheral_struct, DataTypeConflictHandler.REPLACE_HANDLER)
    try:
        listing.createData(addr, peripheral_struct, False)

        symtbl.createLabel(addr, peripheral.name, namespace,
                           SourceType.USER_DEFINED)
    except:
        print("\t\tFailed to generate peripheral " + peripheral.name)