Пример #1
0
class SiSim(SiTransferLayer):
    def __init__(self, conf):
        super(SiSim, self).__init__(conf)
        self._sock = None

    def init(self):
        super(SiSim, self).init()
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        host = 'localhost'
        if 'host' in self._init.keys():
            host = self._init['host']

        port = 12345
        if 'port' in self._init.keys():
            port = self._init['port']

        # try few times for simulator to setup
        try_cnt = 60
        if 'timeout' in self._init.keys():
            try_cnt = self._init['timeout']

        while (self._sock.connect_ex((host, port)) != 0):
            logger.debug("Trying to connect to simulator.")
            time.sleep(1)
            try_cnt -= 1
            if (try_cnt < 1):
                raise IOError("No connection to simulation server.")

        self._iface = PickleInterface(self._sock)  # exeption?

        self._lock = Lock()

    def write(self, addr, data):
        ad = array.array('B', data)
        req = WriteRequest(addr, ad)

        with self._lock:
            self._iface.send(req)

    def read(self, addr, size):
        req = ReadRequest(addr, size)

        with self._lock:
            self._iface.send(req)
            resp = self._iface.recv()

        if not isinstance(resp, ReadResponse):
            raise ValueError("Communication error with Simulation: got %s" %
                             repr(resp))
        return array.array('B', resp.data)

    def close(self):
        super(SiSim, self).close()
        self._sock.close()
Пример #2
0
class SiSim(SiTransferLayer):

    def __init__(self, conf):
        super(SiSim, self).__init__(conf)
        self._sock = None

    def init(self):
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        host = 'localhost'
        if 'host' in self._init.keys():
            host = self._init['host']

        port = 12345
        if 'port' in self._init.keys():
            port = self._init['port']

        # try few times for simulator to setup
        try_cnt = 60
        if 'timeout' in self._init.keys():
            try_cnt = self._init['timeout']

        while(self._sock.connect_ex((host, port)) != 0):
            logging.debug("Trying to connect to simulator.")
            time.sleep(1)
            try_cnt -= 1
            if(try_cnt < 1):
                raise IOError("No connection to simulation server.")

        self._iface = PickleInterface(self._sock)  # exeption?

        self._lock = Lock()

    def write(self, addr, data):
        ad = array.array('B', data)
        req = WriteRequest(addr, ad)

        with self._lock:
            self._iface.send(req)

    def read(self, addr, size):
        req = ReadRequest(addr, size)

        with self._lock:
            self._iface.send(req)
            resp = self._iface.recv()

        if not isinstance(resp, ReadResponse):
            raise ValueError("Communication error with Simulation: got %s" % repr(resp))
        return array.array('B', resp.data)

    def close(self):
        self._sock.close()
Пример #3
0
class SiUSBDevice(object):
    """Simulation library to emulate SiUSBDevices"""

    BASE_ADDRESS_I2C = 0x00000
    HIGH_ADDRESS_I2C = BASE_ADDRESS_I2C + 256

    BASE_ADDRESS_EXTERNAL = 0x10000
    HIGH_ADDRESS_EXTERNAL = 0x10000 + 0x10000

    BASE_ADDRESS_BLOCK = 0x0001000000000000
    HIGH_ADDRESS_BLOCK = 0xffffffffffffffff

    def __init__(self,
                 device=None,
                 simulation_host='localhost',
                 simulation_port=12345):
        self._sock = None
        self.simulation_host = simulation_host
        self.simulation_port = simulation_port

    def GetFWVersion(self):
        return __version__

    def GetName(self):
        return "Simulated Device"

    def GetBoardId(self):
        return "%s:%d" % (self.simulation_host, self.simulation_port)

    def DownloadXilinx(self, bitfile):
        """We hijack this call to perform the socket connect"""
        self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self._sock.connect((self.simulation_host, self.simulation_port))
        self._iface = PickleInterface(self._sock)
        return True

    def WriteExternal(self, address, data):
        req = WriteRequest(self.BASE_ADDRESS_EXTERNAL + address, data)
        self._iface.send(req)

    def ReadExternal(self, address, size):
        req = ReadRequest(self.BASE_ADDRESS_EXTERNAL + address, size)
        self._iface.send(req)
        resp = self._iface.recv()
        if not isinstance(resp, ReadResponse):
            raise ValueError("Communication error with Simulation: got %s" %
                             repr(resp))
        return array.array('B', resp.data)

    def FastBlockRead(self, size):
        req = ReadRequest(self.BASE_ADDRESS_BLOCK, size)
        self._iface.send(req)
        resp = self._iface.recv()
        if not isinstance(resp, ReadResponse):
            raise ValueError("Communication error with Simulation: got %s" %
                             repr(resp))
        return array.array('B', resp.data)

    def FastBlockWrite(self, data):
        req = WriteRequest(self.BASE_ADDRESS_BLOCK, data)
        self._iface.send(req)

    def WriteI2C(self, address, data):
        print('SiUSBDevice:WriteI2C', address,
              data)  # raise NotImplementedError("To be implemented.")

    def ReadI2C(self, address, size):
        print('SiUSBDevice:ReadI2C'
              )  # raise NotImplementedError("To be implemented.")
        return array.array('B', range(size))