naps.soc.platform.jtag package

Submodules

naps.soc.platform.jtag.jtag_soc_platform module

class naps.soc.platform.jtag.jtag_soc_platform.JTAGSocPlatform(platform, *args, **kwargs)

Bases: naps.soc.soc_platform.SocPlatform

base_address = 0x00[0:34359738360]
csr_domain = 'jtag'
pack_bitstream_fatbitstream(builder)
pydriver_memory_accessor = 'class JTAGAccessor:\n    base = 0\n\n    def __init__(self, addr="127.0.0.1", port=4444, timeout=1024, debug=False, spawn_server=True, tap_name="dut.tap"):\n        import socket\n        import os\n        import time\n        from os.path import dirname, abspath\n\n        self.tap_name = tap_name\n\n        if spawn_server:\n            addr = "127.0.0.1"\n            port = 4444\n            os.system(\'cd {}; openocd -f openocd.cfg > /dev/null 2>&1 &\'.format(dirname(abspath(__file__))))\n            time.sleep(0.1)\n\n        self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n        self.s.connect((addr, port))\n        self.timeout = timeout\n        self.debug = debug\n        self.spawn_server = spawn_server\n\n        # skip some strange random shit\n        self._readline(decode=False)\n        self._irscan(0x32)\n        for i in range(3):\n            self._shift_word(0)\n\n    def __del__(self):\n        if hasattr(self, "spawn_server") and self.spawn_server:\n            self._writeline("shutdown")\n\n    def read(self, addr):\n        self._shift_bit(0)  # wakeup\n        self._shift_bit(1)  # wakeup\n        self._shift_word(addr)  # address\n        self._shift_bit(0)  # read\n\n        # read wait\n        timeout = self.timeout\n        for t in range(timeout):\n            if self._shift_bit(1) == 1:\n                break\n            if t == timeout - 1:\n                raise TimeoutError()\n\n        data = self._shift_word(0)\n        if self._shift_bit(0) != 0:  # read status\n            raise TransactionNotSuccessfulException()\n\n        return data\n\n    def write(self, addr, value):\n        self._shift_bit(0)  # wakeup\n        self._shift_bit(1)  # wakeup\n        self._shift_word(addr)  # address\n        self._shift_bit(1)  # write\n        self._shift_word(value)\n\n        # write wait\n        timeout = self.timeout\n        for t in range(timeout):\n            if self._shift_bit(1) == 1:\n                break\n            if t == timeout - 1:\n                raise TimeoutError()\n        if self._shift_bit(0) != 0:  # write status\n            raise TransactionNotSuccessfulException()\n\n    def _writeline(self, message):\n        message += "\\n"\n        self.s.send(message.encode(\'utf-8\'))\n\n    def _readline(self, decode=True):\n        buf = b""\n\n        while buf[-2:] != b\'> \':\n            buf += self.s.recv(1)\n\n        if decode and self.debug:\n            print(buf.decode(\'utf-8\'))\n\n        buf = buf.rsplit(b\'\\r\\n\', 2)[1][1:]\n\n        if decode:\n            buf = buf.decode(\'utf-8\')\n\n        return buf\n\n    def _writecmd(self, cmd):\n        self._writeline(cmd)\n        ret = self._readline()\n        if self.debug:\n            print(cmd, "->", ret)\n        return ret\n\n    def _shift_word(self, write):\n        return int(self._drscan(32, write), 16)\n\n    def _shift_bit(self, write):\n        return int(self._drscan(1, write), 16)\n\n    def _irscan(self, instruction):\n        return self._writecmd(\'irscan {} {}\'.format(self.tap_name, instruction))\n\n    def _drscan(self, len, value):\n        return self._writecmd(\'drscan {} {} {}\'.format(self.tap_name, len, value))\n\n\nMemoryAccessor = JTAGAccessor\n\n\nclass TransactionNotSuccessfulException(Exception):\n    pass\n'

naps.soc.platform.jtag.memory_accessor_openocd module

class naps.soc.platform.jtag.memory_accessor_openocd.JTAGAccessor(addr='127.0.0.1', port=4444, timeout=1024, debug=False, spawn_server=True, tap_name='dut.tap')

Bases: object

base = 0
read(addr)
write(addr, value)
naps.soc.platform.jtag.memory_accessor_openocd.MemoryAccessor

alias of naps.soc.platform.jtag.memory_accessor_openocd.JTAGAccessor

exception naps.soc.platform.jtag.memory_accessor_openocd.TransactionNotSuccessfulException

Bases: Exception

Module contents