예제 #1
0
    def get_value(self, addr, size, offset, **kwargs):
        '''Reading a value of any arbitrary size (max. unsigned int 64) and offset from a register

        Parameters
        ----------
        addr : int
            The register address.
        size : int
            Bit size/length of the value.
        offset : int
            Offset of the value to be written to the register (in number of bits).

        Returns
        -------
        reg : int
            Register value.
        '''
        div_offset, mod_offset = divmod(offset, 8)
        div_size, mod_size = divmod(size + mod_offset, 8)
        if mod_size:
            div_size += 1
        ret = self._intf.read(self._base_addr + addr + div_offset,
                              size=div_size)
        reg = BitLogic()
        reg.frombytes(tobytes(ret))
        return reg[size + mod_offset - 1:mod_offset].tovalue()
예제 #2
0
    def set_value(self, value, addr, size, offset, **kwargs):
        '''Writing a value of any arbitrary size (max. unsigned int 64) and offset to a register

        Parameters
        ----------
        value : int, str
            The register value (int, long, bit string) to be written.
        addr : int
            The register address.
        size : int
            Bit size/length of the value to be written to the register.
        offset : int
            Offset of the value to be written to the register (in number of bits).

        Returns
        -------
        nothing
        '''
        div_offset, mod_offset = divmod(offset, 8)
        div_size, mod_size = divmod(size + mod_offset, 8)
        if mod_size:
            div_size += 1
        if mod_offset == 0 and mod_size == 0:
            reg = BitLogic.from_value(0, size=div_size * 8)
        else:
            ret = self._intf.read(self._base_addr + addr + div_offset,
                                  size=div_size)
            reg = BitLogic()
            reg.frombytes(tobytes(ret))
        reg[size + mod_offset - 1:mod_offset] = value
        self._intf.write(self._base_addr + addr + div_offset,
                         data=array.array('B', reg.tobytes()))
예제 #3
0
 def frombytes(self, value):
     bl_value = BitLogic()
     bl_value.frombytes(utils.tobytes(array.array('B', value)[::-1]))
     self._deconstruct_reg(bl_value[self._conf['size']:])