Exemple #1
0
    def __init__(self, dut, period=CLK_PERIOD):
        self.status = Status()
        self.status.set_level('verbose')
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut = dut
        dev_dict = json.load(open('test_dict.json'))
        super(NysaSim, self).__init__(dev_dict, self.status)

        self.timeout = 1000
        self.response = Array('B')

        self.dut.rst <= 0
        self.dut.ih_reset <= 0

        self.dut.in_ready <= 0
        self.dut.in_command <= 0
        self.dut.in_address <= 0
        self.dut.in_data <= 0
        self.dut.in_data_count <= 0
        gd = GenSDB()
        self.rom = gd.gen_rom(self.dev_dict, debug=False)

        #yield ClockCycles(self.dut.clk, 10)

        cocotb.fork(Clock(dut.clk, period).start())
Exemple #2
0
    def setUp(self):
        s = Status()
        s.set_level("fatal")

        print "Unit test!"
        pass
        '''
def uninstall_board(name, debug):
    from nysa.ibuilder.lib import utils
    from nysa.common.status import Status
    status = Status()
    if debug:
        status.set_level("Verbose")
    utils.uninstall_local_board_package(name, status)
Exemple #4
0
def uninstall_board(name, debug):
    from nysa.ibuilder.lib import utils
    from nysa.common.status import Status
    status = Status()
    if debug:
        status.set_level("Verbose")
    utils.uninstall_local_board_package(name, status)
Exemple #5
0
def install_board(name, path, setup_platform, debug):
    from nysa.ibuilder.lib import utils
    from nysa.common.status import Status
    status = Status()
    if debug:
        status.set_level("Verbose")
    utils.install_local_board_package(name, path, setup_platform, status)
Exemple #6
0
    def __init__(self, dut, sim_config, period=CLK_PERIOD, user_paths=[]):
        self.status = Status()
        self.status.set_level('verbose')
        self.user_paths = user_paths
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut = dut
        dev_dict = json.load(open(sim_config), object_pairs_hook=OrderedDict)
        super(NysaSim, self).__init__(dev_dict, self.status)

        self.timeout = 1000
        self.response = Array('B')

        self.dut.rst <= 0
        self.dut.ih_reset <= 0

        self.dut.in_ready <= 0
        self.dut.in_command <= 0
        self.dut.in_address <= 0
        self.dut.in_data <= 0
        self.dut.in_data_count <= 0
        gd = GenSDB()
        self.callbacks = {}
        self.rom = gd.gen_rom(self.dev_dict,
                              user_paths=self.user_paths,
                              debug=False)

        cocotb.fork(Clock(dut.clk, period).start())
        cocotb.fork(self.interrupt_interface())
def install_board(name, path, setup_platform, debug):
    from nysa.ibuilder.lib import utils
    from nysa.common.status import Status
    status = Status()
    if debug:
        status.set_level("Verbose")
    utils.install_local_board_package(name, path, setup_platform, status)
Exemple #8
0
    def setUp(self):
        s = Status()
        s.set_level("fatal")

        print "Unit test!"
        pass
        '''
Exemple #9
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break
            self.s.Debug("Platform: %s" % str(platform_name))
            platform_instance = platform_dict[platform_name](self.s)
            instances_dict = platform_instance.scan()
            for name in instances_dict:
                n = instances_dict[name]
                plat = ["", None, None]
                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

        if plat[1] is None:
            self.sdio_drv = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sdio = DRIVER(n, sdio_urn)
        self.s.set_level("verbose")
        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SDIO Device Device: %s" % sdio_urn)

    def test_sdio_device(self):
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.s.Info("Enable Interrupt: %s" % self.sdio.is_interrupt_enable())
        self.sdio.enable_interrupt(True)
        self.s.Info("Enable Interrupt: %s" % self.sdio.is_interrupt_enable())
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.sdio.enable_sdio_device(True)
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.sdio.set_control(0x01)
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.sdio.write_local_buffer(0, [0, 1, 2, 3, 4, 5, 6, 7, 8])
        data = self.sdio.read_local_buffer(0, 2)
        self.s.Info("Buffer Out: %s" % str(data))
        self.s.Info("Status: 0x%08X" % self.sdio.get_status())
        self.s.Info("Clock Count: 0x%08X" % self.sdio.get_clock_count())
        self.s.Info("SD Command: 0x%08X" % self.sdio.get_sd_cmd())
        self.s.Info("SD Command Arg: 0x%08X" % self.sdio.get_sd_cmd_arg())
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.sata_drv = None
            return
        n = plat[2]
        self.n = n
        sata_urn = n.find_device(DRIVER)[0]
        dma_urn = n.find_device(DMA)[0]
        self.memory_urn = self.n.find_device(Memory)[0]

        self.sata_drv = DRIVER(n, sata_urn)
        self.dma = DMA(n, dma_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SATA Device: %s" % sata_urn)
        self.s.Info("Instantiated a DMA Device: %s" % dma_urn)
Exemple #11
0
 def setUp(self):
     name = "sim"
     serial = "dionysus_uart_pmod"
     s = Status()
     s.set_level("fatal")
     try:
         self.n = find_board(name, serial, s)
     except PlatformScannerException as ex:
         print "Could not find platform :%s" % str(ex)
         sys.exit(1)
     self.n.read_sdb()
Exemple #12
0
 def setUp(self):
     self.dbg = False
     name = "sim"
     serial = "dionysus_uart_pmod"
     s = Status()
     s.set_level(StatusLevel.FATAL)
     try:
         self.board = find_board(name, serial, s)
     except PlatformScannerException as ex:
         print "Could not find platform :%s" % str(ex)
         sys.exit(1)
     self.board.read_sdb()
     self.nsm = self.board.nsm
Exemple #13
0
    def setUp(self):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(SFCamera):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.camera = None
            return
        n = plat[2]
        urn = n.find_device(SFCamera)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a SFCamera Device: %s" % urn)
        self.camera = SFCamera(n, urn)
        self.received_callback = False
Exemple #14
0
    def __init__(self, dut, sim_config, period = CLK_PERIOD, user_paths = []):
        self.status = Status()
        self.status.set_level('verbose')
        self.user_paths = user_paths
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut                              = dut
        dev_dict                              = json.load(open(sim_config), object_pairs_hook = OrderedDict)
        super (NysaSim, self).__init__(dev_dict, self.status)

        self.timeout                          = 1000
        self.response                         = Array('B')

        self.dut.rst                          <= 0
        self.dut.ih_reset                     <= 0

        self.dut.in_ready                     <= 0
        self.dut.in_command                   <= 0
        self.dut.in_address                   <= 0
        self.dut.in_data                      <= 0
        self.dut.in_data_count                <= 0
        gd = GenSDB()
        self.callbacks = {}
        self.rom = gd.gen_rom(self.dev_dict, user_paths = self.user_paths, debug = False)

        cocotb.fork(Clock(dut.clk, period).start())
        cocotb.fork(self.interrupt_interface())
Exemple #15
0
    def __init__(self, status=None):
        self.d = {}
        self.s = status
        if status is None:
            self.s = Status()

        for e in self.ELEMENTS:
            self.d[e] = ""
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                try:
                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]
                    
                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        try:
                            n.read_sdb()
                        except IndexError:
                            self.s.Warning("%s is not responding..." % name)
                            continue
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(DRIVER):
                            plat = [platform_name, name, n]
                            break
                        continue
                    
                    #self.s.Verbose("\t%s" % psi)
                except NysaCommError:
                    continue

        if plat[1] is None:
            self.driver = None
            return
        n = plat[2]
        self.n = n
        pcie_urn = n.find_device(DRIVER)[0]
        self.driver = DRIVER(n, pcie_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a PCIE Device Device: %s" % pcie_urn)
Exemple #17
0
    def test_full_dionysus_read(self):
        from nysa.host.platform_scanner import PlatformScanner
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()
        if "dionysus" not in platform_names:
            return

        s = Status()
        platform_instance = platform_dict["dionysus"](s)
        platforms = platform_instance.scan()
        if len(platforms) == 0:
            return
        dionysus = platforms[platforms.keys()[0]]
        #print "Found Dionysus"
        s.set_level("fatal")
        s.Verbose("Read SDB")
        dionysus.read_sdb()
    def test_full_dionysus_read(self):
        from nysa.host.platform_scanner import PlatformScanner
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()
        if "dionysus" not in platform_names:
            return

        s = Status()
        platform_instance = platform_dict["dionysus"](s)
        platforms = platform_instance.scan()
        if len(platforms) == 0:
            return
        dionysus = platforms[platforms.keys()[0]]
        #print "Found Dionysus"
        s.set_level("fatal")
        s.Verbose("Read SDB")
        dionysus.read_sdb()
Exemple #19
0
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.sata_drv = None
            return
        n = plat[2]
        self.n = n
        sata_urn = n.find_device(DRIVER)[0]
        dma_urn = n.find_device(DMA)[0]
        self.memory_urn = self.n.find_device(Memory)[0]

        self.sata_drv = DRIVER(n, sata_urn)
        self.dma = DMA(n, dma_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SATA Device: %s" % sata_urn)
        self.s.Info("Instantiated a DMA Device: %s" % dma_urn)
Exemple #20
0
    def setUp(self):
        name = "sim"
        serial = "dionysus_dma_test"
        s = Status()
        s.set_level("fatal")
        try:
            self.n = find_board(name, serial, s)
        except PlatformScannerException as ex:
            print "Could not find platform :%s" % str(ex)
            sys.exit(1)
        self.n.read_sdb()
        urns = self.n.find_device(MockGPIODriver)
        #self.simple_dev = MockGPIODriver(self.n, urns[0], True)
        self.simple_dev = MockGPIODriver(self.n, urns[0], False)
        urns = self.n.find_device(MockDMAReaderDriver)
        self.dmar = MockDMAReaderDriver(self.n, urns[0], False)

        urns = self.n.find_device(MockDMAWriterDriver)
        self.dmaw = MockDMAWriterDriver(self.n, urns[0], False)
        s.set_level("error")
Exemple #21
0
    def setUp(self):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(SFCamera):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.camera = None
            return
        n = plat[2]
        urn = n.find_device(SFCamera)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a SFCamera Device: %s" % urn)
        self.camera = SFCamera(n, urn)
        self.received_callback = False
Exemple #22
0
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break
            self.s.Debug("Platform: %s" % str(platform_name))
            platform_instance = platform_dict[platform_name](self.s)
            instances_dict = platform_instance.scan()
            for name in instances_dict:
                n = instances_dict[name]
                plat = ["", None, None]
                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

        if plat[1] is None:
            self.sdio_drv = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sdio = DRIVER(n, sdio_urn)
        self.s.set_level("verbose")
        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SDIO Device Device: %s" % sdio_urn)
Exemple #23
0
    def __init__(self, dut, sim_config, period = CLK_PERIOD, user_paths = []):
        self.status = Status()
        self.status.set_level('verbose')
        self.user_paths = user_paths
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut                              = dut
        dev_dict                              = json.load(open(sim_config), object_pairs_hook = OrderedDict)
        super (NysaSim, self).__init__(dev_dict, self.status)

        self.timeout                          = 1000
        self.response                         = Array('B')

        self.dut.rst                          <= 0
        #self.ft245  =   FT245(dut, "ft245", dut.ft245_clk, buffer_size = 0x10)
        self.ft245  =   FT245(dut, "ft245", dut.ft245_clk, buffer_size = 0x11)
        #self.ft245  =   FT245(dut, "ft245", dut.ft245_clk, buffer_size = 0x200)
        gd = GenSDB()
        self.callbacks = {}
        self.rom = gd.gen_rom(self.dev_dict, user_paths = self.user_paths, debug = False)

        cocotb.fork(Clock(dut.clk, period).start())
        setup_ft245_clk(dut)
        cocotb.fork(self.interrupt_interface())
    def __init__(self,
                 dut,
                 uart_if,
                 sim_config,
                 period=CLK_PERIOD,
                 user_paths=[],
                 status=None):
        self.dev_dict = json.load(open(sim_config),
                                  object_pairs_hook=OrderedDict)
        Nysa.__init__(self, Status())
        self.s.set_level('verbose')
        self.user_paths = user_paths
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut = dut
        cocotb.fork(Clock(dut.clk, period).start())
        gd = GenSDB()
        self.rom = gd.gen_rom(self.dev_dict,
                              user_paths=self.user_paths,
                              debug=False)

        self.uart = uart_if
        self.response = Array('B')
Exemple #25
0
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break
            self.s.Debug("Platform: %s" % str(platform_name))
            platform_instance = platform_dict[platform_name](self.s)
            instances_dict = platform_instance.scan()
            for name in instances_dict:
                n = instances_dict[name]
                plat = ["", None, None]
                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

        if plat[1] is None:
            self.sdio_drv = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sdio = DRIVER(n, sdio_urn)
        self.s.set_level("verbose")
        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SDIO Device Device: %s" % sdio_urn)
    def setUp(self):
        name = "sim"
        serial = "dionysus_dma_test"
        s = Status()
        s.set_level("fatal")
        try:
            self.n = find_board(name, serial, s)
        except PlatformScannerException as ex:
            print "Could not find platform :%s" % str(ex)
            sys.exit(1)
        self.n.read_sdb()
        urns = self.n.find_device(MockGPIODriver)
        #self.simple_dev = MockGPIODriver(self.n, urns[0], True)
        self.simple_dev = MockGPIODriver(self.n, urns[0], False)
        urns = self.n.find_device(MockDMAReaderDriver)
        self.dmar = MockDMAReaderDriver(self.n, urns[0], False)

        urns = self.n.find_device(MockDMAWriterDriver)
        self.dmaw = MockDMAWriterDriver(self.n, urns[0], False)
        s.set_level("error")
Exemple #27
0
class Test(unittest.TestCase):
    def setUp(self):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(SFCamera):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.camera = None
            return
        n = plat[2]
        urn = n.find_device(SFCamera)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a SFCamera Device: %s" % urn)
        self.camera = SFCamera(n, urn)
        self.received_callback = False

    def read_image_callback(self):
        self.received_callback = True
        self.s.Debug("Image callback")

    def test_camera(self):
        if self.camera is None:
            self.s.Fatal("Cannot Run Test when no device is found!")
            return
        #Setup the camera
        self.camera.unregister_interrupt_callback(None)
        self.s.Debug("Image Height: %d" % self.camera.get_height())
        self.s.Debug("Image Width : %d" % self.camera.get_width())

        self.s.Debug("Initialize the camera")
        self.camera.set_control(0x00)
        self.camera.reset_camera()
        self.camera.set_rgb_mode()
        self.camera.reset_counts()
        time.sleep(0.1)
        row_count = self.camera.read_row_count()
        pixel_count = self.camera.read_pixel_count()
        height = row_count
        width = pixel_count / 2
        self.s.Debug("Height: %d" % height)
        self.s.Debug("Width : %d" % width)

        self.camera.enable_camera(True)
        time.sleep(0.1)
        #self.s.Important("Wait for a callback from the camera...")
        self.camera.start_async_reader(self.read_image_callback)
        #self.s.Important("Sleep for a moment...")
        time.sleep(0.4)
        '''
        data = self.camera.read_raw_image()
        print "Length of data: %d" % len(data)
        shape = (self.camera.get_width(), self.camera.get_height())
        img = Image.frombuffer('RGB', shape, data)
        img.save("/home/cospan/foo.png")
        '''
        if self.received_callback:
            data = self.camera.dma_reader.async_read()
            #Expand Image
            rgb_image = Array('B')
            for i in range(0, height * width * 2, 2):
                #top = data[i]
                #bot = data[i + 1]

                #red = ((top >> 3) & 0x1F) << 3
                #green = (((top & 0x7) << 3) | ((bot >> 5) & 0x7)) << 2
                #blue = (top & 0x1F) << 3

                value = (data[i + 1] << 8) + data[i]
                red = ((value >> 11) & 0x1F) << 3
                green = ((value >> 5) & 0x3F) << 2
                blue = (value & 0x1F) << 3

                rgb_image.append(red)
                rgb_image.append(green)
                rgb_image.append(blue)

            self.s.Debug("RGB Image Size: %d" % len(rgb_image))

            self.s.Important("Received callback from camera")
            self.s.Debug("Length of data: %d" % len(data))
            shape = (self.camera.get_width(), self.camera.get_height())
            img = Image.frombuffer('RGB', shape, rgb_image)
            img.save("camera_image.png")
        else:
            self.s.Error("Did not receive callback")
Exemple #28
0
class Test(unittest.TestCase):
    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(i2s.I2S)

    def configure_device(self, driver):
        self.s.Debug("type of driver: %s" % str(driver))
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(driver):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.d = None
            return
        n = plat[2]
        self.n = n
        urn = n.find_device(driver)[0]
        self.d = driver(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a driver Device: %s" % urn)

    def test_device(self):
        if self.d is None:
            return
        '''
        if self.n.get_board_name() == "sim":
            self.s.Warning("Unable to run Device test with simulator")
            return
        '''

        self.d.register_dump()
        self.s.Debug("Is self.d enabled: %s" % str(self.d.is_i2s_enabled()))
        self.s.Debug("Control: 0x%08X" % self.d.get_control())

        self.s.Debug("Enabling I2S...")
        self.d.enable_i2s(True)
        self.s.Debug("Control: 0x%08X" % self.d.get_control())

        self.s.Debug("Is self.d enabled: %s" % str(self.d.is_i2s_enabled()))
        self.s.Debug("Disable self.d...")
        self.d.enable_i2s(False)
        self.s.Debug("Is self.d enabled: %s" % str(self.d.is_i2s_enabled()))

        self.s.Debug("Sample Rate: %d" % self.d.get_sample_rate())
        self.s.Debug("Set custom sample rate to 44.1Khz")
        self.d.set_custom_sample_rate(44100)
        self.s.Debug("Sample Rate (may not match exactly): %d" %
                     self.d.get_sample_rate())

        self.d.enable_i2s(True)
        self.s.Debug("Enable post sine wave test")
        self.d.enable_post_fifo_test(True)
        time.sleep(4)
        self.d.enable_post_fifo_test(False)

        self.s.Debug("Enable pre sine wave test")
Exemple #29
0
    def __init__(self, name = None):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        if name is not None and name in platform_names:
            self.s.Debug("Platform: %s" % str(name))
 
            platform_instance = platform_dict[name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))
 
            instances_dict = platform_instance.scan()
 
            for iname in instances_dict:
 
                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[iname]
                plat = ["", None, None]
 
                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % iname)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(Memory):
                        plat = [name, iname, n]
                        break
                    continue
 
                #self.s.Verbose("\t%s" % psi)


        else:           
            for platform_name in platform_names:
                if plat[1] is not None:
                    break
         
                self.s.Debug("Platform: %s" % str(platform_name))
         
                platform_instance = platform_dict[platform_name](self.s)
                #self.s.Verbose("Platform Instance: %s" % str(platform_instance))
         
                instances_dict = platform_instance.scan()
         
                for name in instances_dict:
         
                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]
         
                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        n.read_sdb()
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(Memory):
                            plat = [platform_name, name, n]
                            break
                        continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            return
        self.n = plat[2]
        self.urn = self.n.find_device(Memory)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a Memory Device: %s" % self.urn)
        self.memory = Memory(self.n, self.urn)
Exemple #30
0
class Test(unittest.TestCase):
    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(i2c.I2C)

    def configure_device(self, driver):
        self.s.Debug("type of driver: %s" % str(driver))
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(driver):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.d = None
            return
        n = plat[2]
        self.n = n
        urn = n.find_device(driver)[0]
        self.d = driver(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a driver Device: %s" % urn)

    def test_device(self):
        if self.d is None:
            return
        if self.n.get_board_name() == "sim":
            self.s.Warning("Unable to run Device test with simulator")
            return

        self.d.reset_i2c_core()
        '''
        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())


        print "Disable core"
        self.d.enable_i2c(False)

        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())
        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())

        print "Check if interrupt is enabled"
        print "enabled: " + str(self.d.is_interrupt_enabled())

        print "Enable interrupt"
        self.d.enable_interrupt(True)
        print "Check if interrupt is enabled"
        print "enabled: " + str(self.d.is_interrupt_enabled())

        clock_rate = self.d.get_clock_rate()
        print "Clock Rate: %d" % clock_rate

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Set clock divider to generate 100kHz clock"
        self.d.set_speed_to_100khz()

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Set clock divider to generate 400kHz clock"
        self.d.set_speed_to_400khz()

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Set a custom clock divider to get 1MHz I2C clock"
        self.d.set_custom_speed(1000000)

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Setting clock rate back to 100kHz"
        '''
        print "Enable core"
        self.d.enable_i2c(True)
        self.d.enable_interrupt(True)
        self.d.get_status()
        self.d.set_speed_to_100khz()

        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())

        print "Check if interrupt is enabled"
        print "enabled: " + str(self.d.is_interrupt_enabled())

        #PMOD AD2 (this is used on PMODA with config file:
        #dionysus_i2c_pmod.json file
        #The following reads ADC Channel 0
        i2c_id = 0x28
        data = Array('B', [0x15])

        self.d.write_to_i2c(i2c_id, data)

        #reading from I2C device
        #print "Reading from register"
        #data  = Array('B', [0x02])
        read_data = self.d.read_from_i2c(i2c_id, None, 2)
        print "Read Data: %s" % str(read_data)
Exemple #31
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        self.s.set_level("verbose")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(GPIO):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.gpio = None
            return
        n = plat[2]
        urn = n.find_device(GPIO)[0]
        self.gpio = GPIO(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a GPIO Device: %s" % urn)

    def test_gpio(self):
        if self.gpio is None:
            self.s.Fatal("Cannot Run Test when no device is found!")
            return
        self.s.Info ("Testing output ports (like LEDs)")

        self.s.Info ("Flashing all the outputs for one second")

        self.s.Info ("Set all the ports to outputs")
        self.gpio.set_port_direction(0xFFFFFFFF)

        self.s.Info ("Set all the values to 1s")
        self.gpio.set_port_raw(0xFFFFFFFF)
        time.sleep(1)
        self.s.Info ("Set all the values to 0s")
        self.gpio.set_port_raw(0x00000000)

        self.s.Info ("Reading inputs (Like buttons) in 2 second")
        self.gpio.set_port_direction(0x00000000)

        time.sleep(2)
        self.s.Info ("Read value: 0x%08X" % self.gpio.get_port_raw())
        self.s.Info ("Reading inputs (Like buttons) in 2 second")
        time.sleep(2)
        self.s.Info ("Read value: 0x%08X" % self.gpio.get_port_raw())

        self.s.Info ("Interrupts: 0x%08X" % self.gpio.get_interrupts())

        self.s.Info ("Testing Interrupts, setting interrupts up for positive edge detect")
        self.s.Info ("Interrupts: 0x%08X" % self.gpio.get_interrupts())
        self.gpio.set_interrupt_edge(0xFFFFFFFF)
        self.gpio.set_interrupt_enable(0xFFFFFFFF)

        self.s.Info ("Waiting for 5 seconds for the interrupts to fire")
        if self.gpio.wait_for_interrupts(5):
            self.s.Info ("Interrupt detected!\n")
            #if self.gpio.is_interrupt_for_slave():
            self.s.Info ("Interrupt for GPIO detected!")
            self.s.Info ("Interrupts: 0x%08X" % self.gpio.get_interrupts())
            self.s.Info ("Read value: 0x%08X" % self.gpio.get_port_raw())

        self.s.Info ("Interrupts: 0x%08X" % self.gpio.get_interrupts())
Exemple #32
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.driver = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.driver = DRIVER(n, sdio_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SDIO Device Device: %s" % sdio_urn)

    def test_device(self):

        TX_DIFF_CTRL = 0x09
        TX_PRE_EMPTH = 0x00
        RX_EQUALIZER = 0x3


        self.s.Info("Attempting to set voltage range")
        self.s.Info("Enable PCIE")
        self.driver.enable(False)
        self.driver.enable_pcie_read_block(True)
        self.driver.enable_external_reset(True)
        #self.driver.enable_manual_reset(True)
        #self.driver.enable_manual_reset(False)

        self.s.Info("Is external reset enabled: %s" % str(self.driver.is_external_reset_enabled()))
        self.s.Info("Driver Control: 0x%08X" % self.driver.get_control())
        self.driver.set_tx_diff_swing(TX_DIFF_CTRL)
        self.driver.set_rx_equalizer(RX_EQUALIZER)
        self.s.Important("Tx Diff Swing: %d" % self.driver.get_tx_diff_swing())
        self.s.Important("RX Equalizer: %d" % self.driver.get_rx_equalizer())
        time.sleep(0.5)
        self.driver.enable(True)
        time.sleep(0.5)
        self.s.Info("Driver Control: 0x%08X" % self.driver.get_control())

        self.s.Verbose("Is GTP PLL Locked: %s" % self.driver.is_gtp_pll_locked())
        self.s.Verbose("Is GTP Reset Done: %s" % self.driver.is_gtp_reset_done())
        self.s.Verbose("Is GTP RX Electrical Idle: %s" % self.driver.is_gtp_rx_elec_idle())
        self.s.Verbose("Is PLL Locked: %s" % self.driver.is_pll_locked())
        self.s.Verbose("Is Host Holding Reset: %s" % self.driver.is_host_set_reset())

        if self.driver.is_pcie_reset():
            self.s.Error("PCIE_A1 Core is in reset!")

        if self.driver.is_linkup():
            self.s.Important("PCIE Linked up!")
        else:
            self.s.Error("PCIE Core is not linked up!")

        self.s.Important("LTSSM State: %s" % self.driver.get_ltssm_state())

        if self.driver.is_correctable_error():
            self.s.Error("Correctable Error Detected")

        if self.driver.is_fatal_error():
            self.s.Error("Fatal Error Detected")

        if self.driver.is_non_fatal_error():
            self.s.Error("Non Fatal Error Detected")

        if self.driver.is_unsupported_error():
            self.s.Error("Unsupported Error Detected")


        self.s.Info("Link State: %s" % self.driver.get_link_state_string())
        self.s.Info("Get Bus Number: 0x%08X" % self.driver.get_bus_num())
        self.s.Info("Get Device Number: 0x%08X" % self.driver.get_dev_num())
        self.s.Info("Get Function Number: 0x%08X" % self.driver.get_func_num())
        self.s.Info("Clock: %d" % self.driver.get_pcie_clock_count())
        self.s.Info("Debug Clock Data: %d" % self.driver.get_debug_pcie_clock_count())

        self.s.Info("Hot Reset: %s" % self.driver.is_hot_reset())
        self.s.Info("Config Turnoff Request: %s" % self.driver.is_turnoff_request())

        self.s.Info("Config Command:    0x%04X" % self.driver.get_cfg_command())
        self.s.Info("Config Status:     0x%04X" % self.driver.get_cfg_status())
        self.s.Info("Config DCommand:   0x%04X" % self.driver.get_cfg_dcommand())
        self.s.Info("Config DStatus:    0x%04X" % self.driver.get_cfg_dstatus())
        self.s.Info("Config LCommand:   0x%04X" % self.driver.get_cfg_lcommand())
        self.s.Info("Config LStatus:    0x%04X" % self.driver.get_cfg_lstatus())

        #self.s.Info("Debug Flags: 0x%08X" % self.driver.get_debug_flags())
        self.driver.read_debug_flags()

        print "Buffer:"
        print "%s" % list_to_hex_string(self.driver.read_local_buffer())
Exemple #33
0
    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(i2c.I2C)
Exemple #34
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(i2c.I2C)

    def configure_device(self, driver):
        self.s.Debug("type of driver: %s" % str(driver))
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(driver):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.d = None
            return
        n = plat[2]
        self.n = n
        urn = n.find_device(driver)[0]
        self.d = driver(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a driver Device: %s" % urn)


    def test_device(self):
        if self.d is None:
            return
        if self.n.get_board_name() == "sim":
            self.s.Warning("Unable to run Device test with simulator")
            return


        self.d.reset_i2c_core()

        '''
        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())


        print "Disable core"
        self.d.enable_i2c(False)

        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())
        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())

        print "Check if interrupt is enabled"
        print "enabled: " + str(self.d.is_interrupt_enabled())

        print "Enable interrupt"
        self.d.enable_interrupt(True)
        print "Check if interrupt is enabled"
        print "enabled: " + str(self.d.is_interrupt_enabled())

        clock_rate = self.d.get_clock_rate()
        print "Clock Rate: %d" % clock_rate

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Set clock divider to generate 100kHz clock"
        self.d.set_speed_to_100khz()

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Set clock divider to generate 400kHz clock"
        self.d.set_speed_to_400khz()

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Set a custom clock divider to get 1MHz I2C clock"
        self.d.set_custom_speed(1000000)

        print "Get clock divider"
        clock_divider = self.d.get_clock_divider()
        print "Clock Divider: %d" % clock_divider

        print "Setting clock rate back to 100kHz"
        '''
        print "Enable core"
        self.d.enable_i2c(True)
        self.d.enable_interrupt(True)
        self.d.get_status()
        self.d.set_speed_to_100khz()

        print "Check if core is enabled"
        print "enabled: " + str(self.d.is_i2c_enabled())

        print "Check if interrupt is enabled"
        print "enabled: " + str(self.d.is_interrupt_enabled())



        #PMOD AD2 (this is used on PMODA with config file:
        #dionysus_i2c_pmod.json file
        #The following reads ADC Channel 0
        i2c_id = 0x28
        data   = Array('B', [0x15])

        self.d.write_to_i2c(i2c_id, data)

        #reading from I2C device
        #print "Reading from register"
        #data  = Array('B', [0x02])
        read_data = self.d.read_from_i2c(i2c_id, None, 2)
        print "Read Data: %s" % str(read_data)
Exemple #35
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.sata_drv = None
            return
        n = plat[2]
        self.n = n
        sata_urn = n.find_device(DRIVER)[0]
        dma_urn = n.find_device(DMA)[0]
        self.memory_urn = self.n.find_device(Memory)[0]

        self.sata_drv = DRIVER(n, sata_urn)
        self.dma = DMA(n, dma_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SATA Device: %s" % sata_urn)
        self.s.Info("Instantiated a DMA Device: %s" % dma_urn)

    def test_dma_sata(self):
        if self.sata_drv is None:
            self.s.Fatal("Cannot Run Test when no device is found!")
            return

        self.s.Info("Reseting Hard Drive...")
        self.sata_drv.enable_sata_reset(True)
        time.sleep(0.5)
        self.sata_drv.enable_sata_reset(False)
        time.sleep(0.75)
        self.s.Info("Reset Complete")

        if self.sata_drv.is_linkup():
            self.s.Important("Linked up with Hard Drive!")

        self.s.Info("\tInitial Status of hard drive (Status): 0x%02X" % self.sata_drv.get_d2h_status())

        if (self.sata_drv.get_d2h_status() & 0x040) == 0:
            self.s.Warning("\tReceived 0 for status of hard drive, sending reset!")
            self.s.Warning ("Sending reset command to hard drive")
            self.sata_drv.send_hard_drive_command(0x08)

            if (self.sata_drv.get_d2h_status() & 0x040) == 0:
                self.s.Warning("Still Received 0x00 after reset, send a sequence of identify commands to get hard drive into known state")
                for i in range (32):
                    self.sata_drv.send_hard_drive_command(0xEC)
                    if (self.sata_drv.get_d2h_status() & 0x040) > 0:
                        print "Found!"
                        break

                if (self.sata_drv.get_d2h_status() & 0x040) == 0:
                    self.s.Warning("Did not get a normal status response from the hard drive attempting soft reset")
                    time.sleep(0.1)
                    self.sata_drv.enable_sata_command_layer_reset(True)
                    time.sleep(0.1)
                    self.sata_drv.enable_sata_command_layer_reset(False)
                    self.sata_drv.send_hard_drive_command(0x00)
                    if (self.sata_drv.get_d2h_status() & 0x040) == 0:
                        self.s.Error("After Soft Reset Still Did not get a good response")
                        sys.exit(1)



        self.sata_drv.identify_hard_drive()
        config = self.sata_drv.get_config()
        self.s.Verbose("Hard Drive Serial Number: %s" % config.serial_number())
        max_user_lba = config.max_user_sectors()
        self.s.Verbose("Max User Sectors: %d" % config.max_user_sectors())
        self.s.Verbose("Max User Size (GB): %f" % ((config.max_user_sectors() * 512.0) * 0.000000001))

        #Clear out a block of memory
        values = Array('B')
        clear_values = Array('B')
        for i in range (2048 * 4):
            values.append(i % 256)
            clear_values.append(0)

        self.sata_drv.set_local_buffer_write_size(128)
        self.sata_drv.write_local_buffer(clear_values)
        self.sata_drv.load_local_buffer()
        self.sata_drv.hard_drive_write(0x0000, 1)
        print "\tSATA Status:                       0x%08X" % self.sata_drv.get_d2h_status()
        print "\tSATA Sector Count:                 0x%08X" % self.sata_drv.get_sector_count()
        print "\tSATA Current Address:              0x%08X" % self.sata_drv.get_hard_drive_lba()


        self.sata_drv.hard_drive_read(0x0000, 1)

        data = self.sata_drv.read_local_buffer()
        #self.s.Verbose("Data from Hard Drive Before DMA Transfer (Should be all zeros):")
        #print str(data[0:128])

        self.sata_drv.enable_dma_control(True)

        self.s.Info("Setup DMA")
        self.dma.setup()
        self.dma.enable_dma(True)

        #DMA Configuration
        CHANNEL_ADDR        = 2
        SINK_ADDR           = 0
        INST_ADDR           = 0
        DDR3_ADDRESS        = 0x0000000000000000
        SATA_ADDRESS        = 0x0000000000000000
        #WORD_TRANSFER_COUNT = 0x1000
        #WORD_TRANSFER_COUNT = 0x800
        #WORD_TRANSFER_COUNT = 2048

        #Rarely Failed:
        #WORD_TRANSFER_COUNT = 0x2000
        #WORD_TRANSFER_COUNT = 0x16000
        WORD_TRANSFER_COUNT = 0x0A00000
        #WORD_TRANSFER_COUNT = 0x100000
        #WORD_TRANSFER_COUNT = 0xF00000
        #WORD_TRANSFER_COUNT = 0x800000
        #WORD_TRANSFER_COUNT = 0x900000
        #WORD_TRANSFER_COUNT = 0xB00000
        MEGABYTES = (WORD_TRANSFER_COUNT * 4.0) / 1000000.0
        self.s.Info ("Transfer Size: 0x%08X" % WORD_TRANSFER_COUNT)


        #Clear SATA
        self.clear_memory()
        #Fill Memory With Data
        self.s.Important("Fill memory with zeros")
        self.s.Important("Configure DMA to transfer %f MB from DDR3 to Hard Drive" % MEGABYTES)
        #self.fill_memory_with_pattern()

        self.dma.enable_channel                     (CHANNEL_ADDR, False                )
        #Configure DMA to transfer 100MB of data from DDR3 to hard drive
        self.dma.set_channel_sink_addr              (CHANNEL_ADDR, SINK_ADDR            )
        self.dma.set_channel_instruction_pointer    (CHANNEL_ADDR, INST_ADDR            )
        self.dma.enable_source_address_increment    (CHANNEL_ADDR, True                 )

        self.dma.enable_dest_address_increment      (SINK_ADDR,    True                 )
        self.dma.enable_dest_respect_quantum        (SINK_ADDR,    True                 )

        self.dma.set_instruction_source_address     (INST_ADDR,    DDR3_ADDRESS         )
        self.dma.set_instruction_dest_address       (INST_ADDR,    SATA_ADDRESS         )
        self.dma.set_instruction_data_count         (INST_ADDR,    WORD_TRANSFER_COUNT  )
        #This is only needed if we are going to another instruction after this
        self.dma.set_instruction_next_instruction   (INST_ADDR,    INST_ADDR            )
        self.dma.enable_instruction_continue        (INST_ADDR,    False                )

        #Initate DMA Transaction
        self.s.Important("Intiate a DMA Transaction")
        self.dma.enable_interrupt_when_command_finished(True)
        self.dma.enable_channel                     (CHANNEL_ADDR, True                 )

        #Transaction Complete
        self.s.Important("DMA Transaction is complete")
        #self.dma.wait_for_interrupts(wait_time = 10)
        self.s.Info ("Wait for transaction to finish")
        fail = False
        timeout = time.time() + TIMEOUT

        self.sata_drv.hard_drive_read(0x0000, 1)
        data = self.sata_drv.read_local_buffer()
        self.s.Verbose("Data from first sector of hard drive (Should be all zeros):")
        print str(data[0:128])
        self.sata_drv.enable_dma_control(True)
        print ("")


        #Fill Memory With Data
        self.s.Important("Fill memory with pattern")
        self.s.Important("Configure DMA to transfer %f MB from DDR3 to Hard Drive" % MEGABYTES)
        self.fill_memory_with_pattern()

        self.dma.enable_channel                     (CHANNEL_ADDR, False                )
        #Configure DMA to transfer 100MB of data from DDR3 to hard drive
        self.dma.set_channel_sink_addr              (CHANNEL_ADDR, SINK_ADDR            )
        self.dma.set_channel_instruction_pointer    (CHANNEL_ADDR, INST_ADDR            )
        self.dma.enable_source_address_increment    (CHANNEL_ADDR, True                 )

        self.dma.enable_dest_address_increment      (SINK_ADDR,    True                 )
        self.dma.enable_dest_respect_quantum        (SINK_ADDR,    True                 )

        self.dma.set_instruction_source_address     (INST_ADDR,    DDR3_ADDRESS         )
        self.dma.set_instruction_dest_address       (INST_ADDR,    SATA_ADDRESS         )
        self.dma.set_instruction_data_count         (INST_ADDR,    WORD_TRANSFER_COUNT  )
        #This is only needed if we are going to another instruction after this
        self.dma.set_instruction_next_instruction   (INST_ADDR,    INST_ADDR            )
        self.dma.enable_instruction_continue        (INST_ADDR,    False                )

        #Initate DMA Transaction
        self.s.Important("Intiate a DMA Transaction")
        self.dma.enable_interrupt_when_command_finished(True)
        self.dma.enable_channel                     (CHANNEL_ADDR, True                 )

        #Transaction Complete
        self.s.Important("DMA Transaction is complete")
        #self.dma.wait_for_interrupts(wait_time = 10)
        self.s.Info ("Wait for transaction to finish")
        fail = False
        timeout = time.time() + TIMEOUT


        '''
        self.fail_analysis(CHANNEL_ADDR, SINK_ADDR, INST_ADDR)
        print "\tCurrent SATA DMA Address:          0x%08X" % self.dma.get_current_sink_address(SINK_ADDR)
        print "\tSATA Status:                       0x%08X" % self.sata_drv.get_d2h_status()
        print "\tSATA Sector Count:                 0x%08X" % self.sata_drv.get_sector_count()


        status          = self.dma.get_channel_status(CHANNEL_ADDR)
        print "\tFinished:              %s" % str(((status & 0x04) > 0))
        print "\tStatus:                0x%08X" % status
        '''
        while not self.dma.is_channel_finished(CHANNEL_ADDR):
        #while (self.dma.get_current_sink_address(SINK_ADDR)  - SATA_ADDRESS) >= WORD_TRANSFER_COUNT:
            print ".",
            if time.time() > timeout:
                print ""
                self.s.Error("Timeout Occured!")
                fail = True
                break
        if fail:
            self.fail_analysis(CHANNEL_ADDR, SINK_ADDR, INST_ADDR)
            return

        self.s.Info ("Transaction Finished!")
        print "\tCurrent SATA DMA Address:          0x%08X" % self.dma.get_current_sink_address(SINK_ADDR)
        print "\tSATA Status:                       0x%08X" % self.sata_drv.get_d2h_status()
        print "\tSATA Sector Count:                 0x%08X" % self.sata_drv.get_sector_count()

        #self.fail_analysis(CHANNEL_ADDR, SINK_ADDR, INST_ADDR)
        self.dma.enable_channel                     (CHANNEL_ADDR, False                )
        self.sata_drv.enable_dma_control            (False)


        self.sata_drv.hard_drive_read(0x0000, 1)
        data = self.sata_drv.read_local_buffer()
        self.s.Verbose("Data from first sector of the hard drive (Should be incrementing number patter):")
        print str(data[0:128])
        self.sata_drv.enable_dma_control(True)


        #Clear DDR3 Memory
        self.s.Important("Clear DDR3 Memory")
        self.clear_memory()
        data = self.n.read_memory(0x00, 128)
        self.s.Verbose("Data read from memory after clear (Should be all zeros):")
        print str(data[0:128])

        #Configure DMA to transfer 100MB of data from hard drive to DDR3
        CHANNEL_ADDR        = 0
        SINK_ADDR           = 2
        self.s.Important("Configure DMA to transfer %f MB from Hard Drive to DDR3" % MEGABYTES)
        self.dma.set_channel_sink_addr              (CHANNEL_ADDR, SINK_ADDR            )
        self.dma.set_channel_instruction_pointer    (CHANNEL_ADDR, INST_ADDR            )
        self.dma.enable_source_address_increment    (CHANNEL_ADDR, True                 )

        self.dma.enable_dest_address_increment      (SINK_ADDR,    True                 )
        #self.dma.enable_dest_respect_quantum        (SINK_ADDR,    True                 )
        self.dma.enable_dest_respect_quantum        (SINK_ADDR,    False                )

        self.dma.set_instruction_source_address     (INST_ADDR,    SATA_ADDRESS         )
        self.dma.set_instruction_dest_address       (INST_ADDR,    SATA_ADDRESS         )
        self.dma.set_instruction_data_count         (INST_ADDR,    WORD_TRANSFER_COUNT  )
        #This is only needed if we are going to another instruction after this
        self.dma.set_instruction_next_instruction   (INST_ADDR,    INST_ADDR            )
        self.dma.enable_instruction_continue        (INST_ADDR,    False                )

        #Initate DMA Transaction
        self.s.Important("Intiate a DMA Transaction")
        self.dma.enable_interrupt_when_command_finished(True)
        self.dma.enable_channel                     (CHANNEL_ADDR, True                 )

        #Transaction Complete
        self.s.Important("DMA Transaction is complete")
        #self.dma.wait_for_interrupts(wait_time = 10)
        self.s.Info ("Wait for transaction to finish (Timeout: %d)" % TIMEOUT)
        timeout = time.time() + TIMEOUT
        fail = False
        while not self.dma.is_channel_finished(CHANNEL_ADDR):
            print ".",
            if time.time() > timeout:
                print ""
                self.s.Error("Timeout Occured!")
                fail = True
                break

        if fail:
            self.fail_analysis(CHANNEL_ADDR, SINK_ADDR, INST_ADDR)
            return

        self.s.Info ("Transaction Finished!")
        print "\tSATA Sector Count:                 0x%08X" % self.sata_drv.get_sector_count()


        #Transaction Complete
        self.s.Important("DMA Transaction is complete")

        #Verify values of memory are correct
        self.s.Important("Verify values of DDR3 are correct")
        data = self.n.read_memory(0x00, 128)
        self.s.Verbose("Data read from memory after clear (Should be all incrementing number pattern):")
        print str(data[0:128])
        #self.verify_memory_pattern()

        self.s.Verbose("Put Hard Drive to Sleep")
        self.sata_drv.hard_drive_sleep()

    def fail_analysis(self, channel, sink, instruction_addr):
        status          = self.dma.get_channel_status(channel)
        source_ready    = ((status & 0x200) >> 9)
        source_activate = ((status & 0x100) >> 8)
        sink_ready      = ((status & 0xC0) >> 6)
        sink_activate   = ((status & 0x30) >> 4)

        if channel == 0:
            self.s.Warning("Hard Drive -> DDR3")
            if ((source_ready == 0) and (source_activate == 0)):
                self.s.Error("*** HARD DRIVE STALL! ****")
            elif ((sink_ready == 0) and (sink_activate == 0)):
                self.s.Error("***DMA STALL! *****")

        elif channel == 2:
            self.s.Warning("DDR3 -> Hard Drive")
            if ((source_ready == 0) and (source_activate == 0)):
                self.s.Error("***DMA STALL! *****")
            elif ((sink_ready == 0) and (sink_activate == 0)):
                self.s.Error("*** HARD DRIVE STALL! ****")



        print "Channel Status: 0x%08X" % status
        print "\tDMA Enabled:           %s" % str(((status & 0x01) > 0))
        print "\tBusy:                  %s" % str(((status & 0x02) > 0))
        print "\tFinished:              %s" % str(((status & 0x04) > 0))
        print "\tSink Error Conflict:   %s" % str(((status & 0x08) > 0))
        print "\tSink Activate:         0x%02X" % sink_activate
        print "\tSink Ready:            0x%02X" % sink_ready
        print "\tSource Activate:       0x%02X" % source_activate
        print "\tSource Ready:          0x%02X" % source_ready
        print "\tInstruction Count:     0x%08X" % self.dma.get_instruction_data_count(instruction_addr)
        print "\tInstruction Dest Addr  0x%016X" % self.dma.get_instruction_dest_address(instruction_addr)
        print "\tInstruction Source Addr0x%016X" % self.dma.get_instruction_source_address(instruction_addr)
        print""
        print "\tDMA Request Ingress Address:       0x%08X" % self.dma.get_channel_sink_addr(channel)
        print "\tSATA Current Address:              0x%08X" % self.sata_drv.get_hard_drive_lba()
        print "\tDMA Request Egress Address:        0x%08X" % self.dma.get_instruction_dest_address(instruction_addr)
        print "\tCurrent SATA DMA Address:          0x%08X" % self.dma.get_current_sink_address(sink)
        print ""
        print "\tSATA Command Layer Write State:    %d" % self.sata_drv.get_cmd_wr_state()
        print "\tSATA Transport State:              %d" % self.sata_drv.get_transport_state()
        print "\tSATA Link Layer State:             %d" % self.sata_drv.get_link_layer_write_state()
        print ""
        print "\tSATA Status:                       0x%08X" % self.sata_drv.get_d2h_status()
        print "\tSATA Current Address:              0x%08X" % self.sata_drv.get_hard_drive_lba()
        print "\tSATA Sector Count:                 0x%08X" % self.sata_drv.get_sector_count()
        print "\tDMA Channel State:                 %s" % self.dma.get_debug_channel_state(channel)

    def fill_memory_with_pattern(self):
        position = 0
        #self.clear_memory()
        total_size = self.n.get_device_size(self.memory_urn)

        size = 0
        if total_size > MAX_LONG_SIZE:
            self.s.Verbose("Memory Size: 0x%08X is larger than write size" % total_size)
            self.s.Verbose("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        #Write Data Out
        data_out = Array('B')
        for i in range (0, size):
            data_out.append((i % 0x100))


        while position < total_size:
            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
            self.s.Verbose("Wrote: 0x%08X - 0x%08X" % (prev_pos, position))

    def verify_memory_pattern(self):
        #Read
        status = "Passed"
        fail = False
        fail_count = 0
        total_size = self.n.get_device_size(self.memory_urn)
        position = 0
        size = 0

        data_out = Array('B')
        for i in range (0, size):
            data_out.append((i % 0x100))

        if total_size > MAX_LONG_SIZE:
            self.s.Verbose("Memory Size: 0x%08X is larger than write size" % total_size)
            self.s.Verbose("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        while (position < total_size) and fail_count < 257:

            data_in = self.n.read_memory(position, size / 4)
            if size != len(data_in):
                self.s.Error("Data in length not equal to data_out length")
                self.s.Error("\toutgoing: %d" % size)
                self.s.Error("\tincomming: %d" % len(data_in))

            dout = data_out.tolist()
            din = data_in.tolist()

            for i in range(len(data_out)):
                out_val = dout[i]
                in_val = din[i]
                if out_val != in_val:
                    fail = True
                    status = "Failed"
                    self.s.Error("Mismatch @ 0x%08X: Write: (Hex): 0x%08X Read (Hex): 0x%08X" % (position + i, data_out[i], data_in[i]))
                    if fail_count >= 16:
                        break
                    fail_count += 1

            prev_pos = position
            if (position + size) > total_size:
                size = total_size - position
            position += size

            self.s.Verbose("Read: 0x%08X - 0x%08X" % (prev_pos, position))

        return status

    def clear_memory(self):
        total_size = self.n.get_device_size(self.memory_urn)
        position = 0
        size = 0
        self.s.Verbose("Clearing Memory")
        self.s.Verbose("Memory Size: 0x%08X" % size)

        if total_size > MAX_LONG_SIZE:
            self.s.Verbose("Memory Size: 0x%08X is larger than read/write size" % total_size)
            self.s.Verbose("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        while position < total_size:
            data_out = Array('B')
            for i in range(0, ((size / 4) - 1)):
                num = 0x00
                data_out.append(num)

            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size

            self.s.Verbose ("Cleared: 0x%08X - 0x%08X" % (prev_pos, position))
Exemple #36
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(i2s.I2S)

    def configure_device(self, driver):
        self.s.Debug("type of driver: %s" % str(driver))
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(driver):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.d = None
            return
        n = plat[2]
        self.n = n
        urn = n.find_device(driver)[0]
        self.d = driver(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a driver Device: %s" % urn)


    def test_device(self):
        if self.d is None:
            return
        '''
        if self.n.get_board_name() == "sim":
            self.s.Warning("Unable to run Device test with simulator")
            return
        '''


        self.d.register_dump()
        self.s.Debug("Is self.d enabled: %s" % str(self.d.is_i2s_enabled()))
        self.s.Debug("Control: 0x%08X" % self.d.get_control())

        self.s.Debug("Enabling I2S...")
        self.d.enable_i2s(True)
        self.s.Debug("Control: 0x%08X" % self.d.get_control())

        self.s.Debug("Is self.d enabled: %s" % str(self.d.is_i2s_enabled()))
        self.s.Debug("Disable self.d...")
        self.d.enable_i2s(False)
        self.s.Debug("Is self.d enabled: %s" % str(self.d.is_i2s_enabled()))

        self.s.Debug("Sample Rate: %d" % self.d.get_sample_rate())
        self.s.Debug("Set custom sample rate to 44.1Khz")
        self.d.set_custom_sample_rate(44100)
        self.s.Debug("Sample Rate (may not match exactly): %d" % self.d.get_sample_rate())

        self.d.enable_i2s(True)
        self.s.Debug("Enable post sine wave test")
        self.d.enable_post_fifo_test(True)
        time.sleep(4)
        self.d.enable_post_fifo_test(False)

        self.s.Debug("Enable pre sine wave test")
Exemple #37
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                try:
                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]
                 
                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        n.read_sdb()
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(DRIVER):
                            plat = [platform_name, name, n]
                            break
                        continue
                 
                    #self.s.Verbose("\t%s" % psi)
                except NysaCommError:
                    continue

        if plat[1] is None:
            self.driver = None
            return
        n = plat[2]
        self.n = n
        pcie_urn = n.find_device(DRIVER)[0]
        self.driver = DRIVER(n, pcie_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a PCIE Device Device: %s" % pcie_urn)

    def test_device(self):
        #print "Is enabled: %s" % self.driver.is_enabled()
        self.driver.enable(False)
        #self.driver.set_trigger         (0x00000020)
        #self.driver.set_trigger_mask    (0x00000020)
        #self.driver.set_trigger_edge    (0xFFFFFFFF)

        #self.driver.set_trigger         (0x00200000)
        #self.driver.set_trigger_mask    (0x01E00000)
        #self.driver.set_trigger_edge    (0xFFFFFFFF)
 
        #self.driver.set_trigger_after   (0x00000100)
        #self.driver.set_trigger_after   (0x00000000)
        self.driver.enable(True)
        self.driver.force_trigger()
        while not self.driver.is_finished():
            print "Waiting..."
            time.sleep(0.5)
            
        print "Is Finished: %s" % self.driver.is_finished()
        data = self.driver.read_data()
        clock_rate = self.driver.get_clock_rate()
        buf = create_vcd_buffer(data, count = 32, clock_count = clock_rate, add_clock = True)
        f = open('f.vcd', 'wb')
        f.write(buf)
        f.close()
Exemple #38
0
class NysaSim(FauxNysa):
    def __init__(self, dut, period=CLK_PERIOD):
        self.status = Status()
        self.status.set_level('verbose')
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut = dut
        dev_dict = json.load(open('test_dict.json'))
        super(NysaSim, self).__init__(dev_dict, self.status)

        self.timeout = 1000
        self.response = Array('B')

        self.dut.rst <= 0
        self.dut.ih_reset <= 0

        self.dut.in_ready <= 0
        self.dut.in_command <= 0
        self.dut.in_address <= 0
        self.dut.in_data <= 0
        self.dut.in_data_count <= 0
        gd = GenSDB()
        self.rom = gd.gen_rom(self.dev_dict, debug=False)

        #yield ClockCycles(self.dut.clk, 10)

        cocotb.fork(Clock(dut.clk, period).start())
        #self.dut.log.info("Clock Started")

    @cocotb.coroutine
    def wait_clocks(self, num_clks):
        for i in range(num_clks):
            yield RisingEdge(self.dut.clk)

    def read_sdb(self):
        """read_sdb

        Read the contents of the DRT

        Args:
          Nothing

        Returns (Array of bytes):
          the raw DRT data, this can be ignored for normal operation

        Raises:
          Nothing
        """
        self.s.Verbose("entered")
        gd = GenSDB()
        self.rom = gd.gen_rom(self.dev_dict, debug=False)

        return self.nsm.read_sdb(self)

    def read(self, address, length=1, mem_device=False):
        if (address * 4) + (length * 4) <= len(self.rom):
            length *= 4
            address *= 4

            ra = Array('B')
            for count in range(0, length, 4):
                ra.extend(self.rom[address + count:address + count + 4])
            #print "ra: %s" % str(ra)
            return ra

        self._read(address, length, mem_device)
        return self.response

    @cocotb.function
    def _read(self, address, length=1, mem_device=False):
        yield (self.comm_lock.acquire())
        #print "_Read Acquire Lock"
        data_index = 0
        self.dut.in_ready <= 0
        self.dut.out_ready <= 0

        self.response = Array('B')
        yield (self.wait_clocks(10))

        if (mem_device):
            self.dut.in_command <= 0x00010002
        else:
            self.dut.in_command <= 0x00000002

        self.dut.in_data_count <= length
        self.dut.in_address <= address
        self.dut.in_data <= 0

        yield (self.wait_clocks(1))
        self.dut.in_ready <= 1
        yield FallingEdge(self.dut.master_ready)
        yield (self.wait_clocks(1))
        self.dut.in_ready <= 0
        yield (self.wait_clocks(1))
        self.dut.out_ready <= 1

        while data_index < length:
            #self.dut.log.info("Waiting for master to assert out enable")
            yield RisingEdge(self.dut.out_en)
            yield (self.wait_clocks(1))
            self.dut.out_ready <= 0
            timeout_count = 0
            data_index += 1
            value = self.dut.out_data.value.get_value()
            self.response.append(0xFF & (value >> 24))
            self.response.append(0xFF & (value >> 16))
            self.response.append(0xFF & (value >> 8))
            self.response.append(0xFF & value)
            yield (self.wait_clocks(1))
            self.dut.out_ready <= 1

        if self.dut.master_ready.value.get_value() == 0:
            yield RisingEdge(self.dut.master_ready)

        yield (self.wait_clocks(10))
        self.comm_lock.release()
        raise ReturnValue(self.response)

    @cocotb.function
    def write(self, address, data=None, mem_device=False):
        yield (self.comm_lock.acquire())
        # print "Write Acquired Lock"
        data_count = len(data) / 4
        #print "data count: %d" % data_count
        yield (self.wait_clocks(1))

        if data_count == 0:
            raise NysaCommError("Length of data to write is 0!")
        data_index = 0
        timeout_count = 0

        #self.dut.log.info("Writing data")
        self.dut.in_address <= address
        if (mem_device):
            self.dut.in_command <= 0x00010001
        else:
            self.dut.in_command <= 0x00000001

        self.dut.in_data_count <= data_count

        while data_index < data_count:
            self.dut.in_data        <=  (data[data_index    ] << 24) | \
                                        (data[data_index + 1] << 16) | \
                                        (data[data_index + 2] << 8 ) | \
                                        (data[data_index + 3]      )
            self.dut.in_ready <= 1
            #self.dut.log.info("Waiting for master to deassert ready")
            yield FallingEdge(self.dut.master_ready)
            yield (self.wait_clocks(1))
            data_index += 1
            timeout_count = 0
            #self.dut.log.info("Waiting for master to be ready")
            self.dut.in_ready <= 0
            yield RisingEdge(self.dut.master_ready)
            yield (self.wait_clocks(1))

        self.response = Array('B')
        value = self.dut.out_data.value.get_value()
        self.response.append(0xFF & (value >> 24))
        self.response.append(0xFF & (value >> 16))
        self.response.append(0xFF & (value >> 8))
        self.response.append(0xFF & value)

        yield (self.wait_clocks(10))
        self.comm_lock.release()

    @cocotb.coroutine
    def wait_for_interrupts(self, wait_time=1):
        pass

    @cocotb.coroutine
    def dump_core(self):
        pass

    @cocotb.coroutine
    def reset(self):
        yield (self.comm_lock.acquire())
        #print "Reset Acquired Lock"
        yield (self.wait_clocks(RESET_PERIOD / 2))

        self.dut.rst <= 1
        #self.dut.log.info("Sending Reset to the bus")
        self.dut.in_ready <= 0
        self.dut.out_ready <= 0

        self.dut.in_command <= 0
        self.dut.in_address <= 0
        self.dut.in_data <= 0
        self.dut.in_data_count <= 0
        yield (self.wait_clocks(RESET_PERIOD / 2))
        self.dut.rst <= 0
        yield (self.wait_clocks(RESET_PERIOD / 2))
        yield (self.wait_clocks(10))
        self.comm_lock.release()
        #print "Reset Release Lock"

    @cocotb.coroutine
    def ping(self):
        timeout_count = 0

        while timeout_count < self.timeout:
            yield RisingEdge(self.dut.clk)
            timeout_count += 1
            yield ReadOnly()
            if self.master_ready.value.get_value() == 0:
                continue
            else:
                break

        if timeout_count == self.timeout:
            self.dut.log.error(
                "Timed out while waiting for master to be ready")
            return

        yield ReadWrite()
        self.dut.in_ready <= 1
        self.dut.in_command <= 0
        self.dut.in_data <= 0
        self.dut.in_address <= 0
        self.dut.in_data_count <= 0
        self.dut.out_ready <= 1

        timeout_count = 0

        while timeout_count < self.timeout:
            yield RisingEdge(self.dut.clk)
            timeout_count += 1
            yield ReadOnly()
            if self.dut.out_en.value.get_value() == 0:
                continue
            else:
                break

        if timeout_count == self.timeout:
            self.dut.log.error("Timed out while waiting for master to respond")
            return
        self.dut.in_ready <= 0

        self.dut.log.info("Master Responded to ping")
        self.dut.log.info("\t0x%08X" % self.out_status.value.get_value())

    def register_interrupt_callback(self, index, callback):
        pass

    def unregister_interrupt_callback(self, index, callback=None):
        pass

    def get_sdb_base_address(self):
        return 0x0

    def get_board_name(self):
        return "Cocotb"

    def upload(self, filepath):
        pass

    def program(self):
        pass
Exemple #39
0
class Test(unittest.TestCase):
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break
            self.s.Debug("Platform: %s" % str(platform_name))
            platform_instance = platform_dict[platform_name](self.s)
            instances_dict = platform_instance.scan()
            for name in instances_dict:
                n = instances_dict[name]
                plat = ["", None, None]
                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

        if plat[1] is None:
            self.sdio_drv = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sdio = DRIVER(n, sdio_urn)
        self.s.set_level("verbose")
        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SDIO Device Device: %s" % sdio_urn)

    def test_sdio_device(self):
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.s.Info("Enable Interrupt: %s" % self.sdio.is_interrupt_enable())
        self.sdio.enable_interrupt(True)
        self.s.Info("Enable Interrupt: %s" % self.sdio.is_interrupt_enable())
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.sdio.enable_sdio_device(True)
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.sdio.set_control(0x01)
        self.s.Info("Control: 0x%08X" % self.sdio.get_control())
        self.sdio.write_local_buffer(0, [0, 1, 2, 3, 4, 5, 6, 7, 8])
        data = self.sdio.read_local_buffer(0, 2)
        self.s.Info("Buffer Out: %s" % str(data))
        self.s.Info("Status: 0x%08X" % self.sdio.get_status())
        self.s.Info("Clock Count: 0x%08X" % self.sdio.get_clock_count())
        self.s.Info("SD Command: 0x%08X" % self.sdio.get_sd_cmd())
        self.s.Info("SD Command Arg: 0x%08X" % self.sdio.get_sd_cmd_arg())
Exemple #40
0
    def __init__(self, name=None):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        if name is not None and name in platform_names:
            self.s.Debug("Platform: %s" % str(name))

            platform_instance = platform_dict[name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for iname in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[iname]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % iname)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(Memory):
                        plat = [name, iname, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        else:
            for platform_name in platform_names:
                if plat[1] is not None:
                    break

                self.s.Debug("Platform: %s" % str(platform_name))

                platform_instance = platform_dict[platform_name](self.s)
                #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

                instances_dict = platform_instance.scan()

                for name in instances_dict:

                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]

                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        n.read_sdb()
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(Memory):
                            plat = [platform_name, name, n]
                            break
                        continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            return
        self.n = plat[2]
        self.urn = self.n.find_device(Memory)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a Memory Device: %s" % self.urn)
        self.memory = Memory(self.n, self.urn)
Exemple #41
0
class Test(object):
    def __init__(self, name=None):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        if name is not None and name in platform_names:
            self.s.Debug("Platform: %s" % str(name))

            platform_instance = platform_dict[name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for iname in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[iname]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % iname)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(Memory):
                        plat = [name, iname, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        else:
            for platform_name in platform_names:
                if plat[1] is not None:
                    break

                self.s.Debug("Platform: %s" % str(platform_name))

                platform_instance = platform_dict[platform_name](self.s)
                #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

                instances_dict = platform_instance.scan()

                for name in instances_dict:

                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]

                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        n.read_sdb()
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(Memory):
                            plat = [platform_name, name, n]
                            break
                        continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            return
        self.n = plat[2]
        self.urn = self.n.find_device(Memory)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a Memory Device: %s" % self.urn)
        self.memory = Memory(self.n, self.urn)

    def _test_small_memory_rw_at_beginning(self):
        if self.single_rw_start() == "Failed":
            print "Failed memory write and read at beginning"

    def _test_small_memory_rw_at_end(self):
        if self.single_rw_end() == "Failed":
            print "Failed memory write and read at end"

    def single_rw_start(self):
        status = "Passed"
        #self.clear_memory()
        size = self.n.get_device_size(self.urn)
        print "size: 0x%08X" % size
        print("Test Single Read/Write at Beginning")
        data_out = Array('B', [0xAA, 0xBB, 0xCC, 0xDD, 0x55, 0x66, 0x77, 0x88])
        self.n.write_memory(0, data_out)
        print "Wrote second part!"
        data_in = self.n.read_memory(0, len(data_out) / 4)
        print "length: data_out: %d, data_in: %d" % (len(data_out),
                                                     len(data_in))
        print "data out: %s" % str(data_out)
        print "data_in: %s" % str(data_in)
        for i in range(len(data_out)):
            if data_in[i] != data_out[i]:
                status = "Failed"
                print "Error at: 0x%02X OUT: 0x%02X IN: 0x%02X" % (
                    i, data_out[i], data_in[i])
                #print "ERROR at: [{0:>2}] OUT: {1:>8} IN: {2:>8}".format(str(i), hex(data_out[i]), hex(data_in[i]))
        return status

    def single_rw_end(self):
        status = "Passed"
        #self.clear_memory()
        size = self.n.get_device_size(self.urn)
        print("Test Single Read/Write at End")
        data_out = Array('B', [0xAA, 0xBB, 0xCC, 0xDD, 0x55, 0x66, 0x77, 0x88])
        self.n.write_memory((size - 16), data_out)
        print "Reading from location: 0x%08X" % (size - 16)
        data_in = self.n.read_memory((size - 16), 2)
        print "data out: %s" % str(data_out)
        print "data_in: %s" % str(data_in)

        for i in range(len(data_out)):
            if data_in[i] != data_out[i]:
                print "Error at: 0x%02X OUT: 0x%02X IN: 0x%02X" % (
                    i, data_out[i], data_in[i])
                status = "Failed"

        return status

    def test_long_burst(self):
        status = "Passed"
        fail = False
        fail_count = 0
        position = 0
        #self.clear_memory()
        total_size = self.n.get_device_size(self.urn)
        total_size = MAX_LONG_SIZE * 2

        size = 0
        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" %
                  total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        #Write Data Out
        while position < total_size:
            data_out = Array('B')
            for i in range(0, size):
                data_out.append((i % 0x100))

            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
            print("Wrote: 0x%08X - 0x%08X" % (prev_pos, position))
            #time.sleep(0.1)

        position = 0
        size = total_size

        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" %
                  total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)

            size = MAX_LONG_SIZE

        while (position < total_size) and fail_count < 257:

            data_in = self.n.read_memory(position, size / 4)
            if size != len(data_in):
                print("Data in length not equal to data_out length")
                print("\toutgoing: %d" % size)
                print("\tincomming: %d" % len(data_in))

            dout = data_out.tolist()
            din = data_in.tolist()

            for i in range(len(data_out)):
                out_val = dout[i]
                in_val = din[i]
                if out_val != in_val:
                    fail = True
                    status = "Failed"
                    print(
                        "Mismatch @ 0x%08X: Write: (Hex): 0x%08X Read (Hex): 0x%08X"
                        % (position + i, data_out[i], data_in[i]))
                    if fail_count >= 16:
                        break
                    fail_count += 1

            prev_pos = position
            if (position + size) > total_size:
                size = total_size - position
            position += size

            print("Read: 0x%08X - 0x%08X" % (prev_pos, position))

        return status

    def clear_memory(self):
        total_size = self.n.get_device_size(self.urn)
        position = 0
        size = 0
        print("Clearing Memory")
        print("Memory Size: 0x%08X" % size)

        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" %
                  total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        while position < total_size:
            data_out = Array('B')
            for i in range(0, size):
                data_out.append(0x00)

            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
Exemple #42
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(uart.UART)

    def configure_device(self, driver):
        self.s.Debug("type of driver: %s" % str(driver))
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(driver):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.d = None
            return
        n = plat[2]
        self.n = n
        urn = n.find_device(driver)[0]
        self.d = driver(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a driver Device: %s" % urn)

    def test_uart(self):
        """Unit test for UART
        """
        if self.d is None:
            return
        if self.n.get_board_name() == "sim":
            self.s.Warning("Unable to run UART test with simulator")
            return

        self.d.set_control(0)
        self.s.Debug ("Testing UART config")
        baudrate = self.d.get_baudrate()
        self.s.Debug ("Initial baudrate = %d" % baudrate)
        self.s.Debug ("Setting baudrate to 115200")
        self.d.set_baudrate(115200)
        '''
        self.d.set_baudrate(57600)
        if self.d.get_baudrate() > (57600 - (57600 * .01)) and self.d.get_baudrate() < (57600 + (57600 * .01)) :
            self.s.Debug ("Baudrate is within 1% of target")
        else:
            self.s.Debug ("Baudrate is not correct!")

        self.s.Debug ("Reverting back to initial baudrate")
        self.d.set_baudrate(baudrate)

        self.s.Debug ("\tXXX: Cannot test hardware flow control!")
        '''
        self.s.Debug ("\tControl: 0x%08X" % self.d.get_control())

        self.s.Debug ("Writing a string")
        self.d.write_string("STEAM ROXORS THE BIG ONE!1!!\r\n")


        self.s.Debug ("disable all interrupts")
        self.d.disable_interrupts()
        self.s.Debug ("Testing receive interrupt")
        self.d.enable_read_interrupt()
        self.s.Debug ("\tControl: 0x%08X" % self.d.get_control())

        self.s.Debug ("Read: %s " % self.d.read_string(-1))
        self.d.get_status()

        self.s.Debug ("Waiting 5 second for receive interrupts")
        if self.d.wait_for_interrupts(10) > 0:
            #if self.d.is_interrupt_for_slave():
            self.s.Debug ("Found a read interrupt")

            self.s.Debug ("Read: %s" % self.d.read_string(-1))

        self.s.Debug ("After waiting for interupt")

        self.s.Debug ("\tControl: 0x%08X" % self.d.get_control())

        #self.d.disable_read_interrupt()

        self.s.Debug ("Testing write interrupt")
        self.d.enable_write_interrupt()
        self.s.Debug ("Waiting 1 second for write interrupts")
        #if self.d.wait_for_interrupts(1) > 0:
        #    if self.d.is_interrupt_for_slave():
        #        print "Found a write interrupt!"

        #self.d.disable_write_interrupt()

        #print "Testing write"

        '''
Exemple #43
0
    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(uart.UART)
Exemple #44
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.sd = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sd = DRIVER(n, sdio_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a SDIO Device Device: %s" % sdio_urn)

    def test_sd_host(self):
        self.s.Info("Control: 0x%08X" % self.sd.get_control())
        self.s.Info("Status: 0x%08X" % self.sd.get_status())
        self.s.Info("Attempting to set voltage range")
        self.sd.set_voltage_range(2.0, 3.6)
        self.s.Info("Enable SD Host")
        self.sd.enable_sd_host(True)
        #self.s.Info("Control: 0x%08X" % self.sd.get_control())
        #self.sd.cmd_phy_sel()
        self.s.Info("Control: 0x%08X" % self.sd.get_control())
        self.sd.cmd_io_send_op_cond(enable_1p8v = True)
        self.s.Info("Control: 0x%08X" % self.sd.get_control())
        self.s.Info("Status: 0x%08X" % self.sd.get_status())
Exemple #45
0
class Test (object):

    def __init__(self, name = None):
        self.s = Status()
        self.s.set_level("fatal")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        if name is not None and name in platform_names:
            self.s.Debug("Platform: %s" % str(name))
 
            platform_instance = platform_dict[name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))
 
            instances_dict = platform_instance.scan()
 
            for iname in instances_dict:
 
                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[iname]
                plat = ["", None, None]
 
                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % iname)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(Memory):
                        plat = [name, iname, n]
                        break
                    continue
 
                #self.s.Verbose("\t%s" % psi)


        else:           
            for platform_name in platform_names:
                if plat[1] is not None:
                    break
         
                self.s.Debug("Platform: %s" % str(platform_name))
         
                platform_instance = platform_dict[platform_name](self.s)
                #self.s.Verbose("Platform Instance: %s" % str(platform_instance))
         
                instances_dict = platform_instance.scan()
         
                for name in instances_dict:
         
                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]
         
                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        n.read_sdb()
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(Memory):
                            plat = [platform_name, name, n]
                            break
                        continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            return
        self.n = plat[2]
        self.urn = self.n.find_device(Memory)[0]
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a Memory Device: %s" % self.urn)
        self.memory = Memory(self.n, self.urn)

    def _test_small_memory_rw_at_beginning(self):
        if self.single_rw_start() == "Failed":
            print "Failed memory write and read at beginning"

    def _test_small_memory_rw_at_end(self):
        if self.single_rw_end() == "Failed":
            print "Failed memory write and read at end"

    def single_rw_start(self):
        status = "Passed"
        #self.clear_memory()
        size = self.n.get_device_size(self.urn)
        print "size: 0x%08X" % size
        print ( "Test Single Read/Write at Beginning")
        data_out = Array('B', [0xAA, 0xBB, 0xCC, 0xDD, 0x55, 0x66, 0x77, 0x88])
        self.n.write_memory(0, data_out)
        print "Wrote second part!"
        data_in = self.n.read_memory(0, len(data_out)/4)
        print "length: data_out: %d, data_in: %d" % (len(data_out), len(data_in))
        print "data out: %s" % str(data_out)
        print "data_in: %s" % str(data_in)
        for i in range (len(data_out)):
            if data_in[i] != data_out[i]:
                status = "Failed"
                print "Error at: 0x%02X OUT: 0x%02X IN: 0x%02X" % (i, data_out[i], data_in[i])
                #print "ERROR at: [{0:>2}] OUT: {1:>8} IN: {2:>8}".format(str(i), hex(data_out[i]), hex(data_in[i]))
        return status

    def single_rw_end(self):
        status = "Passed"
        #self.clear_memory()
        size = self.n.get_device_size(self.urn)
        print ( "Test Single Read/Write at End")
        data_out = Array('B', [0xAA, 0xBB, 0xCC, 0xDD, 0x55, 0x66, 0x77, 0x88])
        self.n.write_memory((size - 16), data_out)
        print "Reading from location: 0x%08X" % (size - 16)
        data_in = self.n.read_memory((size - 16), 2)
        print "data out: %s" % str(data_out)
        print "data_in: %s" % str(data_in)

        for i in range (len(data_out)):
            if data_in[i] != data_out[i]:
                print "Error at: 0x%02X OUT: 0x%02X IN: 0x%02X" % (i, data_out[i], data_in[i])
                status = "Failed"

        return status

    def test_long_burst(self):
        status = "Passed"
        fail = False
        fail_count = 0
        position = 0
        #self.clear_memory()
        total_size = self.n.get_device_size(self.urn)
        total_size = MAX_LONG_SIZE * 2

        size = 0
        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" % total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        #Write Data Out
        while position < total_size:
            data_out = Array('B')
            for i in range (0, size):
                data_out.append((i % 0x100))

            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
            print("Wrote: 0x%08X - 0x%08X" % (prev_pos, position))
            #time.sleep(0.1)


        position = 0
        size = total_size

        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" % total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)

            size = MAX_LONG_SIZE
 
        while (position < total_size) and fail_count < 257:

            data_in = self.n.read_memory(position, size / 4)
            if size != len(data_in):
                print( "Data in length not equal to data_out length")
                print( "\toutgoing: %d" % size)
                print( "\tincomming: %d" % len(data_in))

            dout = data_out.tolist()
            din = data_in.tolist()

            for i in range(len(data_out)):
                out_val = dout[i]
                in_val = din[i]
                if out_val != in_val:
                    fail = True
                    status = "Failed"
                    print("Mismatch @ 0x%08X: Write: (Hex): 0x%08X Read (Hex): 0x%08X" % (position + i, data_out[i], data_in[i]))
                    if fail_count >= 16:
                        break
                    fail_count += 1

            prev_pos = position
            if (position + size) > total_size:
                size = total_size - position
            position += size

            print("Read: 0x%08X - 0x%08X" % (prev_pos, position))

        return status

    def clear_memory(self):
        total_size = self.n.get_device_size(self.urn)
        position = 0
        size = 0
        print ( "Clearing Memory")
        print ( "Memory Size: 0x%08X" % size)

        if total_size > MAX_LONG_SIZE:
            print("Memory Size: 0x%08X is larger than read/write size" % total_size)
            print("\tBreaking transaction into 0x%08X chunks" % MAX_LONG_SIZE)
            size = MAX_LONG_SIZE
        else:
            size = total_size

        while position < total_size:
            data_out = Array('B')
            for i in range (0, size):
                data_out.append(0x00)

            self.n.write_memory(position, data_out)

            #Increment the position
            prev_pos = position

            if position + size > total_size:
                size = total_size - position
            position += size
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                try:
                    #s.Verbose("Found Platform Item: %s" % str(platform_item))
                    n = instances_dict[name]
                    plat = ["", None, None]
                    
                    if n is not None:
                        self.s.Important("Found a nysa instance: %s" % name)
                        try:
                            n.read_sdb()
                        except IndexError:
                            self.s.Warning("%s is not responding..." % name)
                            continue
                        #import pdb; pdb.set_trace()
                        if n.is_device_in_platform(DRIVER):
                            plat = [platform_name, name, n]
                            break
                        continue
                    
                    #self.s.Verbose("\t%s" % psi)
                except NysaCommError:
                    continue

        if plat[1] is None:
            self.driver = None
            return
        n = plat[2]
        self.n = n
        pcie_urn = n.find_device(DRIVER)[0]
        self.driver = DRIVER(n, pcie_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])
        self.s.Info("Instantiated a PCIE Device Device: %s" % pcie_urn)

    def test_device(self):
        self.s.Info("Getting clock rate")
        self.driver.set_tx_diff(0x0C)
        print ""
        self.s.Info("TX Diff Control:        0x%04X" % self.driver.get_tx_diff())
        self.s.Info("Link Up:                %s" % self.driver.is_linkup())
        self.s.Info("PCIE USR Reset:         %s" % self.driver.is_pcie_usr_rst())
        self.s.Info("PCIE PHY Reset:         %s" % self.driver.is_pcie_phy_rst())
        self.s.Info("PCIE PHY Ready          %s" % self.driver.is_pcie_phy_ready())
        self.s.Info("PCIE Elect Idle:        0x%02X" % self.driver.get_elec_idle())
        self.s.Info("LTSSM:                  %s" % self.driver.get_ltssm_state())
        self.s.Info("Input Clocked Stopped:  %s" % self.driver.is_clk_in_stopped())
        self.s.Info("PLL Locked:             %s" % self.driver.is_pll_locked())
        print ""
        self.s.Info("Config Command:         0x%04X" % self.driver.get_cfg_command())
        self.s.Info("Config Status:          0x%04X" % self.driver.get_cfg_status())
        self.s.Info("Config DCommand:        0x%04X" % self.driver.get_cfg_dcommand())
        self.s.Info("Config DCommand2:       0x%04X" % self.driver.get_cfg_dcommand2())
        self.s.Info("Config DStatus:         0x%04X" % self.driver.get_cfg_dstatus())
        self.s.Info("Config LCommand:        0x%04X" % self.driver.get_cfg_lcommand())
        self.s.Info("Config LStatus:         0x%04X" % self.driver.get_cfg_lstatus())
        self.s.Info("State:                  0x%04X" % self.driver.get_link_state())
        self.s.Info("GTX PLL Locked:         0x%04X" % self.driver.get_gtx_pll_lock_reg())
        print ""
Exemple #47
0
class NysaSim (FauxNysa):

    @cocotb.coroutine
    def interrupt_interface(self):
        while(1):
            yield RisingEdge(self.dut.device_interrupt)
            #print "got interrupt... looking for callback"
            for key in self.callbacks:
                if self.callbacks[key] is not None:
                    #print "Found callback for: %s" % str(key)
                    for c in self.callbacks[key]:
                        c()

    def __init__(self, dut, sim_config, period = CLK_PERIOD, user_paths = []):
        self.status = Status()
        self.status.set_level('verbose')
        self.user_paths = user_paths
        self.comm_lock = cocotb.triggers.Lock('comm')
        self.dut                              = dut
        dev_dict                              = json.load(open(sim_config), object_pairs_hook = OrderedDict)
        super (NysaSim, self).__init__(dev_dict, self.status)

        self.timeout                          = 1000
        self.response                         = Array('B')

        self.dut.rst                          <= 0
        #self.ft245  =   FT245(dut, "ft245", dut.ft245_clk, buffer_size = 0x10)
        self.ft245  =   FT245(dut, "ft245", dut.ft245_clk, buffer_size = 0x11)
        #self.ft245  =   FT245(dut, "ft245", dut.ft245_clk, buffer_size = 0x200)
        gd = GenSDB()
        self.callbacks = {}
        self.rom = gd.gen_rom(self.dev_dict, user_paths = self.user_paths, debug = False)

        cocotb.fork(Clock(dut.clk, period).start())
        setup_ft245_clk(dut)
        cocotb.fork(self.interrupt_interface())

    @cocotb.coroutine
    def wait_clocks(self, num_clks):
        for i in range(num_clks):
            yield RisingEdge(self.dut.clk)

    def read_sdb(self):
        """read_sdb

        Read the contents of the DRT

        Args:
          Nothing

        Returns (Array of bytes):
          the raw DRT data, this can be ignored for normal operation

        Raises:
          Nothing
        """
        self.s.Verbose("entered")
        gd = GenSDB()
        self.rom = gd.gen_rom(self.dev_dict, user_paths = self.user_paths, debug = False)

        return self.nsm.read_sdb(self)

    def read(self, address, length = 1, flags = []):
        if NYSA_FLAGS.MASTER_ADDRESS not in flags:
            if (address * 4) + (length * 4) <= len(self.rom):
                length *= 4
                address *= 4
            
                ra = Array('B')
                for count in range (0, length, 4):
                    ra.extend(self.rom[address + count :address + count + 4])
                #print "ra: %s" % str(ra)
                return ra

        mem_device = False
        if self.mem_addr is None:
            self.mem_addr = self.nsm.get_address_of_memory_bus()

        if address >= self.mem_addr:
            address = address - self.mem_addr
            mem_device = True

        self._read(address, length, mem_device, flags)
        return self.response

    @cocotb.function
    def _read(self, address, length = 1, mem_device = False, flags = []):
        yield(self.comm_lock.acquire())

        data_index = 0
        self.response = Array('B')
        yield( self.wait_clocks(10))

        data = Array('B')

        command = 0x00000002

        if mem_device:
            command |= FLAG_MEM_BUS

        if NYSA_FLAGS.DISABLE_AUTO_INC in flags:
            command |= FLAG_DISABLE_AUTO_INC

        if NYSA_FLAGS.MASTER_ADDRESS in flags:
            command |= FLAG_MASTER_CONFIG

        data.extend(create_byte_array_from_dword(command))

        data.extend(create_byte_array_from_dword(length))
        data.extend(create_byte_array_from_dword(address))
        yield(self.ft245.write(data))
        yield(self.ft245.read(length * 4))
        self.response = self.ft245.get_data()
        self.comm_lock.release()
        raise ReturnValue(self.response)

    @cocotb.function
    def write(self, address, data = None, flags = []):
        #print "Writing"
        mem_device = False
        write_data = Array('B')

        if self.mem_addr is None:
            self.mem_addr = self.nsm.get_address_of_memory_bus()

        command = 0x00000001

        if address >= self.mem_addr:
            address = address - self.mem_addr
            command |= FLAG_MEM_BUS

        if NYSA_FLAGS.DISABLE_AUTO_INC in flags:
            command |= FLAG_DISABLE_AUTO_INC

        if NYSA_FLAGS.MASTER_ADDRESS in flags:
            command |= FLAG_MASTER_CONFIG

        write_data.extend(create_byte_array_from_dword(command))

        while (len(data) % 4) != 0:
            data.append(0)

        data_count = len(data) / 4

        write_data.extend(create_byte_array_from_dword(data_count))
        write_data.extend(create_byte_array_from_dword(address))
        write_data.extend(data)

        if data_count == 0:
            raise NysaCommError("Length of data to write is 0!")
        data_index          = 0
        timeout_count       = 0

        yield(self.comm_lock.acquire())
        yield(self.ft245.write(write_data))
        self.comm_lock.release()

    def wait_for_interrupts(self, wait_time = 1):
        self._wait_for_interrupts(wait_time)
        return False

    @cocotb.function
    def _wait_for_interrupts(self, wait_time = 1):
        wait_time = wait_time * 100
        count = 0
        self.interrupt_good = False
        while count < wait_time:
            #print "wait...",
            yield (self.wait_clocks(10))
            #print ".",
            count += 1
            if self.dut.device_interrupt.value.get_value():
                self.interrupt_good = True
                break

        #print "good? %s" % str(self.interrupt_good)

    @cocotb.coroutine
    def dump_core(self):
        pass

    @cocotb.coroutine
    def reset(self):
        yield(self.comm_lock.acquire())
        #print "Reset Acquired Lock"
        yield(self.wait_clocks(RESET_PERIOD / 2))

        self.dut.rst            <= 1
        yield(self.wait_clocks(RESET_PERIOD / 2))
        self.dut.rst            <= 0
        yield(self.wait_clocks(RESET_PERIOD / 2))
        yield( self.wait_clocks(10))
        self.comm_lock.release()
        #print "Reset Release Lock"

    @cocotb.coroutine
    def ping(self):
        timeout_count       =  0

        while timeout_count < self.timeout:
            yield RisingEdge(self.dut.clk)
            timeout_count   += 1
            yield ReadOnly()
            if self.master_ready.value.get_value() == 0:
                continue
            else:
                break

        if timeout_count == self.timeout:
            self.dut.log.error("Timed out while waiting for master to be ready")
            return

        yield ReadWrite()

        timeout_count       =  0

        while timeout_count < self.timeout:
            yield RisingEdge(self.dut.clk)
            timeout_count   += 1
            yield ReadOnly()
            #if self.dut.out_en.value.get_value() == 0:
            #   continue
            #else:
            #    break
            break

        if timeout_count == self.timeout:
            self.dut.log.error("Timed out while waiting for master to respond")
            return
        self.dut.log.info("Master Responded to ping")
        self.dut.log.info("\t0x%08X" % self.out_status.value.get_value())

    def register_interrupt_callback(self, index, callback):
        if index not in self.callbacks:
            self.callbacks[index] = []
        self.callbacks[index].append(callback)

    def unregister_interrupt_callback(self, index, callback = None):
        if callback is None:
            self.callbacks[index] = None
        elif index in self.callbacks:
            i = self.callbacks[index].index(callback)
            del self.callbacks[index][i]

    def get_sdb_base_address(self):
        return 0x0

    def get_board_name(self):
        return "Cocotb"

    def upload(self, filepath):
        pass

    def program(self):
        pass
Exemple #48
0
class Test(unittest.TestCase):
    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.sd = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sd = DRIVER(n, sdio_urn)
        sdio_urn = n.find_device(SDIODeviceDriver)[0]
        self.sdio = SDIODeviceDriver(n, sdio_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])

    def test_sd_host_sdio(self):
        #self.s.Info("Host Control:\t\t0x%08X" % self.sd.get_control())
        self.sd.display_control()
        self.s.Info("Device Control:\t\t0x%08X" % self.sdio.get_control())
        self.s.Info("Delay: 0x%02X" % self.sd.get_input_delay())
        sd_host_input_delay_value = 63
        self.s.Info("Set host input delay to %d ( 0x%02X )" %
                    (sd_host_input_delay_value, sd_host_input_delay_value))
        self.sd.set_input_delay(sd_host_input_delay_value)
        self.s.Info("Delay: 0x%02X" % self.sd.get_input_delay())

        self.sdio.enable_sdio_device(False)
        self.sdio.reset_core()

        sdio_input_delay_value = 0
        self.s.Info("Delay: 0x%02X" % self.sdio.get_input_delay())
        self.s.Info("Set Input delay to %d ( 0x%02X )" %
                    (sdio_input_delay_value, sdio_input_delay_value))
        self.sdio.set_input_delay(sdio_input_delay_value)
        self.s.Info("Delay: 0x%02X" % self.sdio.get_input_delay())

        self.sdio.enable_sdio_device(True)
        #self.s.Info("Host Status:\t\t0x%08X" % self.sd.get_status())
        self.sd.display_status()
        self.s.Info("Device Control:\t\t0x%08X" % self.sdio.get_control())
        self.s.Info("Device Status:\t\t0x%08X" % self.sdio.get_status())
        self.s.Info("Host Attempting to set voltage range")
        self.sd.set_voltage_range(2.0, 3.6)
        self.s.Info("Host Enable SD Host")
        self.sd.enable_sd_host(True)

        self.s.Verbose("Setting Phy Select... should be no response")
        self.sdio.display_control()
        self.sdio.display_status()
        self.sd.cmd_phy_sel()
        self.sd.display_crcs()
        self.sdio.display_crcs()

        self.s.Verbose("Phy State should be 0x00")
        self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
        self.s.Info("Host Control:\t\t0x%08X" % self.sd.get_control())

        try:
            self.s.Verbose("Send Command 5")
            self.sd.cmd_io_send_op_cond(enable_1p8v=True)
            #self.sd.display_crcs()
            #self.sdio.display_crcs()
            #self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
            #self.s.Info("SD Command Arg:\t\t0x%08X" % self.sdio.get_sd_cmd_arg())
            #self.s.Info("Response Value:\t\t0x%0X" % self.sd.read_response())

            self.s.Verbose("Get Relative Address")
            self.sd.cmd_get_relative_card_address()
            #self.sd.display_crcs()
            #self.sdio.display_crcs()
            #self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
            #self.s.Info("SD Command Arg:\t\t0x%08X" % self.sdio.get_sd_cmd_arg())
            #self.s.Info("Response Value:\t\t0x%0X" % self.sd.read_response())

            self.s.Verbose("Enable Card")
            self.sd.cmd_enable_card(True)
            #self.sd.display_crcs()
            #self.sdio.display_crcs()

            self.s.Verbose("Read a configuration byte")
            value = self.sd.read_config_byte(0x00)
            # self.sd.display_crcs()
            # self.sdio.display_crcs()
            self.s.Important("Read Value: 0x%02X" % value)

        except SDHostException as e:
            self.s.Error("Failed data transfer!: %s" % str(e))
        '''
        self.sd.display_control()
        self.sd.display_status()
        self.sdio.display_status()
        self.s.Info("Clock Count:\t\t0x%08X" % self.sdio.get_clock_count())
        '''
        self.s.Info("Read data from CCCR")
        value = self.sd.read_sd_data(function_id=0,
                                     address=0x00,
                                     byte_count=0x08,
                                     fifo_mode=False)
        self.s.Info("Data from CCCR: %s" % print_hex_array(value))

        self.s.Info("Attempting to write data")
        #data_out = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
        data_out = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]
        self.sdio.write_local_buffer(0, data_out)
        #data_out = [0xAA, 0x33, 0x22, 0x55, 0x0B, 0x00, 0x11, 0x44]
        #data_out = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]
        try:
            self.sd.write_sd_data(function_id=1, address=0x00, data=data_out)
            #self.sd.display_control()
        except SDHostException as e:
            self.s.Error("Failed data transfer!: %s" % str(e))

        self.s.Important("Write data from host to SDIO Device")
        print "Sending data to SDIO:\t\t\t%s" % print_hex_array(data_out)
        #mem_data = self.sdio.read_memory(0x00, 2)
        #print "Data in Memory:\t\t\t\t%s" % print_hex_array(mem_data)
        data = self.sdio.read_local_buffer(0, len(data_out) / 4)
        print "SDIO Local Data:\t\t\t%s" % print_hex_array(data)
        print ""

        #self.s.Important("Put Data in SDIO Device, read this data from SD Host")
        #print "Write Data to SDIO buffer:\t\t%s" % print_hex_array(data_out)
        #self.sdio.write_local_buffer(0, data_out)

        #data = self.sdio.read_local_buffer(0, 2)
        #print "Read back data from SDIO buffer:\t%s" % print_hex_array(data)

        #value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = len(data_out), fifo_mode = False)
        #value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = 0x20, fifo_mode = False)
        value = self.sd.read_sd_data(function_id=1,
                                     address=0x00,
                                     byte_count=0x08,
                                     fifo_mode=False)
        #self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
        #self.s.Info("SD Command Arg:\t\t0x%08X" % self.sdio.get_sd_cmd_arg())
        print "Data From SDIO:\t\t\t\t%s" % print_hex_array(value)
        self.sd.display_crcs()
        self.sdio.display_crcs()
        #data = self.sdio.read_local_buffer(0, 2)
        #print "Data: %s" % print_hex_array(data)

        #value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = 8, fifo_mode = False)
        #print "Value: %s" % str(value)

        SIZE = 256
        print "Long Write: %d" % SIZE
        data_out = []
        for i in range(SIZE):
            value = i % 256
            data_out.append(value)

        self.sd.write_sd_data(function_id=1, address=0x00, data=data_out)
        data = self.sd.read_sd_data(function_id=1,
                                    address=0x00,
                                    byte_count=len(data_out))
        print "Data From SDIO:\t\t\t\t%s" % print_hex_array(data)
Exemple #49
0
    def setUp(self):
        self.s = Status()
        self.s.set_level("debug")

        self.configure_device(i2s.I2S)
Exemple #50
0
class Test(unittest.TestCase):
    def setUp(self):
        self.s = Status()
        self.s.set_level("verbose")
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(GPIO):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.gpio = None
            return
        n = plat[2]
        urn = n.find_device(GPIO)[0]
        self.gpio = GPIO(n, urn)
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a GPIO Device: %s" % urn)

    def test_gpio(self):
        if self.gpio is None:
            self.s.Fatal("Cannot Run Test when no device is found!")
            return
        self.s.Info("Testing output ports (like LEDs)")

        self.s.Info("Flashing all the outputs for one second")

        self.s.Info("Set all the ports to outputs")
        self.gpio.set_port_direction(0xFFFFFFFF)

        self.s.Info("Set all the values to 1s")
        self.gpio.set_port_raw(0xFFFFFFFF)
        time.sleep(1)
        self.s.Info("Set all the values to 0s")
        self.gpio.set_port_raw(0x00000000)

        self.s.Info("Reading inputs (Like buttons) in 2 second")
        self.gpio.set_port_direction(0x00000000)

        time.sleep(2)
        self.s.Info("Read value: 0x%08X" % self.gpio.get_port_raw())
        self.s.Info("Reading inputs (Like buttons) in 2 second")
        time.sleep(2)
        self.s.Info("Read value: 0x%08X" % self.gpio.get_port_raw())

        self.s.Info("Interrupts: 0x%08X" % self.gpio.get_interrupts())

        self.s.Info(
            "Testing Interrupts, setting interrupts up for positive edge detect"
        )
        self.s.Info("Interrupts: 0x%08X" % self.gpio.get_interrupts())
        self.gpio.set_interrupt_edge(0xFFFFFFFF)
        self.gpio.set_interrupt_enable(0xFFFFFFFF)

        self.s.Info("Waiting for 5 seconds for the interrupts to fire")
        if self.gpio.wait_for_interrupts(5):
            self.s.Info("Interrupt detected!\n")
            #if self.gpio.is_interrupt_for_slave():
            self.s.Info("Interrupt for GPIO detected!")
            self.s.Info("Interrupts: 0x%08X" % self.gpio.get_interrupts())
            self.s.Info("Read value: 0x%08X" % self.gpio.get_port_raw())

        self.s.Info("Interrupts: 0x%08X" % self.gpio.get_interrupts())
class Test (unittest.TestCase):
    """Unit test SDB Tree"""

    def setUp(self):
        self.status = Status()
        self.status.set_level("error")
        self.som = som.SOM()

    def test_initialize_root(self):
        self.som.initialize_root()

    def test_initialize_root_with_good_params(self):
        self.som.initialize_root(
                          name = "test",
                          version = 1,
                          vendor_id = 0x800BEAF15DEADC03,
                          entity_id = 0x00000001,
                          bus_type = "wishbone")

    def test_initialize_root_with_version_error(self):
        self.assertRaises(SDBError,
                            self.som.initialize_root,
                            name = "test",
                            version = 2,
                            vendor_id = 0x800BEAF15DEADC03,
                            entity_id = 0x00000001,
                            bus_type = "wishbone")

    def test_initialize_root_with_bad_bus(self):
        self.assertRaises(SDBError,
                          self.som.initialize_root,
                          name = "test",
                          version = 1,
                          vendor_id = 0x800BEAF15DEADC03,
                          entity_id = 0x00000001,
                          bus_type = "bad bus")

    def test_insert_bus(self):
        self.som.initialize_root()
        self.som.insert_bus()
        self.assertTrue(self.som.is_entity_a_bus(root = None, index = 0))

    def test_insert_entity(self):
        self.som.initialize_root()
        c = sdbc.SDBComponent()
        c.parse_buffer(SDB_DATA)
        c.set_size(5)
        c.d["SDB_RECORD_TYPE"] = sdbc.SDB_RECORD_TYPE_DEVICE
        self.som.insert_component(component = c)
        self.assertFalse(self.som.is_entity_a_bus(root = None, index = 0))

    def test_get_child_count(self):
        self.som.initialize_root()
        c = sdbc.SDBComponent()
        c.parse_buffer(SDB_DATA)
        c.set_size(5)
        c.d["SDB_RECORD_TYPE"] = sdbc.SDB_RECORD_TYPE_DEVICE
        self.som.insert_component(component = c)
        self.assertEqual(self.som.get_child_count(), 1)

    def test_get_component(self):
        self.som.initialize_root()
        c = sdbc.SDBComponent()
        c.parse_buffer(SDB_DATA)
        c.set_size(5)
        c.d["SDB_RECORD_TYPE"] = sdbc.SDB_RECORD_TYPE_DEVICE
        self.som.insert_component(component = c)
        self.assertEqual(self.som.get_component(index = 0), c)

    def test_set_bus_name_for_root(self):
        self.som.initialize_root()
        root = self.som.get_root()
        self.som.set_bus_name(root, "Top")
        self.assertEqual(root.c.d["SDB_NAME"], "Top")

    def test_set_bus_name_for_not_root(self):
        self.som.initialize_root()
        root = self.som.get_root()
        self.som.insert_bus()
        bus = self.som.get_buses()[0]
        self.som.set_bus_name(bus, "peripherals")
        self.assertEqual(bus.c.d["SDB_NAME"], "peripherals")

    def test_set_spacing(self):
        self.som.initialize_root()
        root = self.som.get_root()
        spacing = 0x100
        root.set_child_spacing(spacing)
        bus = self.som.insert_bus()
        dev = sdbc.create_device_record(name = "test 1",
                                        size = 0x10)
        self.som.insert_component(bus, dev)

        self.som.insert_bus()

        #print "Number of components: %d" % self.som.get_child_count(root)
        bus = self.som.get_buses()[1]

        #self.som.set_bus_start_address(bus, start_address)
        #print "bus start address: 0x%08X" % bus.c.get_start_address_as_int()
        self.assertEqual(bus.c.get_start_address_as_int(), spacing)

    def test_remove_bus_root(self):
        self.som.initialize_root()
        root = self.som.get_root()
        self.assertRaises(SDBError,
                          self.som.remove_bus,
                          root)

    def test_remove_bus_bad_parent(self):
        self.som.initialize_root()
        class A (object):
            def get_parent(self):
                return None
        a = A()
        self.assertRaises(SDBError,
                          self.som.remove_bus,
                          a)

    def test_remove_bus(self):
        self.som.initialize_root()
        root = self.som.get_root()
        self.som.insert_bus()
        self.som.insert_bus()
        self.assertEqual(self.som.get_child_count(root), 2)
        self.som.remove_bus(self.som.get_buses()[0])
        self.assertEqual(self.som.get_child_count(root), 1)

    def test_insert_component_with_interconnect_fail(self):
        self.som.initialize_root()
        root = self.som.get_root()
        int_record = sdbc.create_interconnect_record()
        self.assertRaises(  SDBError,
                            self.som.insert_component,
                            root,
                            int_record)

    def test_insert_component(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din = sdbc.create_device_record()
        self.som.insert_component(root, din)
        dout = self.som.get_component(root, 0)
        self.assertEqual(din, dout)

    def test_update_method_at_root(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "Test 1", size = 0x10)
        din2 = sdbc.create_device_record(name = "Test 2", size = 0x20)
        self.som.insert_component(root, din1)
        self.som.insert_component(root, din2)
        dout = self.som.get_component(root, 0)
        self.assertEqual(din1, dout)

        dout = self.som.get_component(root, 1)
        self.assertEqual(dout.get_start_address_as_int(), 0x10)

    def test_update_method_at_subbus(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "Test 1", size = 0x10)
        din2 = sdbc.create_device_record(name = "Test 2", size = 0x20)

        bus = self.som.insert_bus()

        self.som.insert_component(root = bus, component = din1)
        self.som.insert_component(root = bus, component = din2)

        dout = self.som.get_component(bus, 0)
        self.assertEqual(din1, dout)

        dout = self.som.get_component(bus, 1)
        self.assertEqual(dout.get_start_address_as_int(), 0x10)

    def test_update_method_after_remove(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "Test 1", size = 0x10)
        din2 = sdbc.create_device_record(name = "Test 2", size = 0x20)
        din3 = sdbc.create_device_record(name = "Test 3", size = 0x30)

        bus = self.som.insert_bus()

        self.som.insert_component(root = bus, component = din1)
        self.som.insert_component(root = bus, component = din2)
        self.som.insert_component(root = bus, component = din3)

        self.som.remove_component_by_index(bus, 0)

        dout = self.som.get_component(bus, 0)
        self.assertEqual(din2, dout)

        dout = self.som.get_component(bus, 1)
        self.assertEqual(dout.get_start_address_as_int(), 0x20)

    def test_set_bus_name(self):
        test_name = "Renamed Bus"
        self.som.initialize_root()
        root = self.som.get_root()
        bus = self.som.insert_bus()
        self.som.set_bus_name(bus, test_name)
        name = self.som.get_bus_name(bus)
        self.assertEqual(test_name, name)

    def test_insert_component(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t", size = 0x10)
        self.som.insert_component(root = root, component = din1)

        comp = self.som.get_component(root, 0)
        self.assertEqual(din1, comp)

    def test_get_component_bad_index(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t", size = 0x10)
        self.som.insert_component(root = root, component = din1)

        self.assertRaises(  IndexError,
                            self.som.get_component,
                            root,
                            1)

    def test_remove_component(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t", size = 0x10)
        self.som.insert_component(root = root, component = din1)

        self.som.remove_component_by_index(root, 0)
        count = self.som.get_child_count(root)
        self.assertEqual(count, 0)

    def test_remove_component_bad_index(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t", size = 0x10)
        self.som.insert_component(root = root, component = din1)

        self.assertRaises(  IndexError,
                            self.som.remove_component_by_index,
                            root,
                            3)

    def test_insert_integration_record(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t0", size = 0x10)
        din2 = sdbc.create_device_record(name = "t1", size = 0x10)
        din3 = sdbc.create_device_record(name = "t3", size = 0x10)

        self.som.insert_component(root, din1)
        self.som.insert_component(root, din2)
        self.som.insert_component(root, din3)
        irec = sdbc.create_integration_record( "integration test",
                                                vendor_id = 0x00,
                                                device_id = 0x00)

        self.som.insert_component(root, irec, 0)
        record = self.som.get_component(root, 3)
        self.assertEqual(record, irec)

    def test_insert_url(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t0", size = 0x10)
        din2 = sdbc.create_device_record(name = "t1", size = 0x10)
        din3 = sdbc.create_device_record(name = "t3", size = 0x10)

        self.som.insert_component(root, din1)
        self.som.insert_component(root, din2)
        self.som.insert_component(root, din3)

        url = sdbc.create_repo_url_record(   "http://www.geocities.com")
        self.som.insert_component(root, url, 1)
        record = self.som.get_component(root, 3)
        self.assertEqual(record, url)

    def test_insert_synthesis_record(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t0", size = 0x10)
        din2 = sdbc.create_device_record(name = "t1", size = 0x10)
        din3 = sdbc.create_device_record(name = "t3", size = 0x10)

        self.som.insert_component(root, din1)
        self.som.insert_component(root, din2)
        self.som.insert_component(root, din3)

        synthesis = sdbc.create_synthesis_record(   synthesis_name = "image.bit",
                                                    commit_id = 01234567,
                                                    tool_name = "xilinx xst",
                                                    tool_version = 14.1,
                                                    user_name = "*****@*****.**")
        self.som.insert_component(root, synthesis, 1)
        record = self.som.get_component(root, 3)
        self.assertEqual(record, synthesis)

    def test_move_device(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "t0", size = 0x10)
        din2 = sdbc.create_device_record(name = "t1", size = 0x10)
        din3 = sdbc.create_device_record(name = "t3", size = 0x10)

        self.som.insert_component(root, din1)
        self.som.insert_component(root, din2)
        self.som.insert_component(root, din3)

        self.som.move_component(root, 2, root, 0)
        component = self.som.get_component(root, 0)
        self.assertEqual(din3, component)

    def test_iterate_bus(self):
        self.som.initialize_root()
        root = self.som.get_root()
        din1 = sdbc.create_device_record(name = "Sub Item 1", size = 0x10)
        din2 = sdbc.create_device_record(name = "Sub Item 2", size = 0x20)

        bus = self.som.insert_bus()
        bus.set_name("test bus")

        self.som.insert_component(root = bus, component = din1)
        self.som.insert_component(root = bus, component = din2)

        dout = self.som.get_component(bus, 0)
        self.assertEqual(din1, dout)
        #print "in bus: %s" % bus.get_name()
        #for entity in bus:
        #    print "\t%s" % entity.get_name()
        count = 0
        for entity in bus:
            count += 1

        self.assertEqual(count, 2)
Exemple #52
0
 def setUp(self):
     self.status = Status()
 def setUp(self):
     self.status = Status()
     self.status.set_level("error")
     self.som = som.SOM()
Exemple #54
0
class Test (unittest.TestCase):

    def setUp(self):
        self.s = Status()
        plat = ["", None, None]
        pscanner = PlatformScanner()
        platform_dict = pscanner.get_platforms()
        platform_names = platform_dict.keys()

        if "sim" in platform_names:
            #If sim is in the platforms, move it to the end
            platform_names.remove("sim")
            platform_names.append("sim")
        urn = None
        for platform_name in platform_names:
            if plat[1] is not None:
                break

            self.s.Debug("Platform: %s" % str(platform_name))

            platform_instance = platform_dict[platform_name](self.s)
            #self.s.Verbose("Platform Instance: %s" % str(platform_instance))

            instances_dict = platform_instance.scan()

            for name in instances_dict:

                #s.Verbose("Found Platform Item: %s" % str(platform_item))
                n = instances_dict[name]
                plat = ["", None, None]

                if n is not None:
                    self.s.Important("Found a nysa instance: %s" % name)
                    n.read_sdb()
                    #import pdb; pdb.set_trace()
                    if n.is_device_in_platform(DRIVER):
                        plat = [platform_name, name, n]
                        break
                    continue

                #self.s.Verbose("\t%s" % psi)

        if plat[1] is None:
            self.sd = None
            return
        n = plat[2]
        self.n = n
        sdio_urn = n.find_device(DRIVER)[0]
        self.sd = DRIVER(n, sdio_urn)
        sdio_urn = n.find_device(SDIODeviceDriver)[0]
        self.sdio = SDIODeviceDriver(n, sdio_urn)
        self.s.set_level("verbose")

        self.s.Info("Using Platform: %s" % plat[0])

    def test_sd_host_sdio(self):
        #self.s.Info("Host Control:\t\t0x%08X" % self.sd.get_control())
        self.sd.display_control()
        self.s.Info("Device Control:\t\t0x%08X" % self.sdio.get_control())
        self.s.Info("Delay: 0x%02X" % self.sd.get_input_delay())
        sd_host_input_delay_value = 63
        self.s.Info("Set host input delay to %d ( 0x%02X )" % (sd_host_input_delay_value, sd_host_input_delay_value))
        self.sd.set_input_delay(sd_host_input_delay_value)
        self.s.Info("Delay: 0x%02X" % self.sd.get_input_delay())

        self.sdio.enable_sdio_device(False)
        self.sdio.reset_core()

        sdio_input_delay_value = 0
        self.s.Info("Delay: 0x%02X" % self.sdio.get_input_delay())
        self.s.Info("Set Input delay to %d ( 0x%02X )" % (sdio_input_delay_value, sdio_input_delay_value))
        self.sdio.set_input_delay(sdio_input_delay_value)
        self.s.Info("Delay: 0x%02X" % self.sdio.get_input_delay())

        self.sdio.enable_sdio_device(True)
        #self.s.Info("Host Status:\t\t0x%08X" % self.sd.get_status())
        self.sd.display_status()
        self.s.Info("Device Control:\t\t0x%08X" % self.sdio.get_control())
        self.s.Info("Device Status:\t\t0x%08X" % self.sdio.get_status())
        self.s.Info("Host Attempting to set voltage range")
        self.sd.set_voltage_range(2.0, 3.6)
        self.s.Info("Host Enable SD Host")
        self.sd.enable_sd_host(True)

        self.s.Verbose("Setting Phy Select... should be no response")
        self.sdio.display_control()
        self.sdio.display_status()
        self.sd.cmd_phy_sel()
        self.sd.display_crcs()
        self.sdio.display_crcs()

        self.s.Verbose("Phy State should be 0x00")
        self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
        self.s.Info("Host Control:\t\t0x%08X" % self.sd.get_control())

        try:
            self.s.Verbose("Send Command 5")
            self.sd.cmd_io_send_op_cond(enable_1p8v = True)
            #self.sd.display_crcs()
            #self.sdio.display_crcs()
            #self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
            #self.s.Info("SD Command Arg:\t\t0x%08X" % self.sdio.get_sd_cmd_arg())
            #self.s.Info("Response Value:\t\t0x%0X" % self.sd.read_response())

            self.s.Verbose("Get Relative Address")
            self.sd.cmd_get_relative_card_address()
            #self.sd.display_crcs()
            #self.sdio.display_crcs()
            #self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
            #self.s.Info("SD Command Arg:\t\t0x%08X" % self.sdio.get_sd_cmd_arg())
            #self.s.Info("Response Value:\t\t0x%0X" % self.sd.read_response())

            self.s.Verbose("Enable Card")
            self.sd.cmd_enable_card(True)
            #self.sd.display_crcs()
            #self.sdio.display_crcs()

            self.s.Verbose("Read a configuration byte")
            value = self.sd.read_config_byte(0x00)
           # self.sd.display_crcs()
           # self.sdio.display_crcs()
            self.s.Important("Read Value: 0x%02X" % value)

        except SDHostException as e:
            self.s.Error("Failed data transfer!: %s" % str(e))

        '''
        self.sd.display_control()
        self.sd.display_status()
        self.sdio.display_status()
        self.s.Info("Clock Count:\t\t0x%08X" % self.sdio.get_clock_count())
        '''
        self.s.Info("Read data from CCCR")
        value = self.sd.read_sd_data(function_id = 0, address = 0x00, byte_count = 0x08, fifo_mode = False)
        self.s.Info("Data from CCCR: %s" % print_hex_array(value))

        self.s.Info ("Attempting to write data")
        #data_out = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
        data_out = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]
        self.sdio.write_local_buffer(0, data_out)
        #data_out = [0xAA, 0x33, 0x22, 0x55, 0x0B, 0x00, 0x11, 0x44]
        #data_out = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF]
        try:
            self.sd.write_sd_data(function_id = 1, address = 0x00, data = data_out)
            #self.sd.display_control()
        except SDHostException as e:
            self.s.Error("Failed data transfer!: %s" % str(e))

        self.s.Important("Write data from host to SDIO Device")
        print "Sending data to SDIO:\t\t\t%s" % print_hex_array(data_out)
        #mem_data = self.sdio.read_memory(0x00, 2)
        #print "Data in Memory:\t\t\t\t%s" % print_hex_array(mem_data)
        data = self.sdio.read_local_buffer(0, len(data_out) / 4)
        print "SDIO Local Data:\t\t\t%s" % print_hex_array(data)
        print ""



        #self.s.Important("Put Data in SDIO Device, read this data from SD Host")
        #print "Write Data to SDIO buffer:\t\t%s" % print_hex_array(data_out)
        #self.sdio.write_local_buffer(0, data_out)

        #data = self.sdio.read_local_buffer(0, 2)
        #print "Read back data from SDIO buffer:\t%s" % print_hex_array(data)

        #value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = len(data_out), fifo_mode = False)
        #value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = 0x20, fifo_mode = False)
        value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = 0x08, fifo_mode = False)
        #self.s.Info("SD Command:\t\t0x%08X" % self.sdio.get_sd_cmd())
        #self.s.Info("SD Command Arg:\t\t0x%08X" % self.sdio.get_sd_cmd_arg())
        print "Data From SDIO:\t\t\t\t%s" % print_hex_array(value)
        self.sd.display_crcs()
        self.sdio.display_crcs()
        #data = self.sdio.read_local_buffer(0, 2)
        #print "Data: %s" % print_hex_array(data)

        #value = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = 8, fifo_mode = False)
        #print "Value: %s" % str(value)

        SIZE = 256
        print "Long Write: %d" % SIZE
        data_out = []
        for i in range (SIZE):
            value = i % 256
            data_out.append(value)

        self.sd.write_sd_data(function_id = 1, address = 0x00, data = data_out)
        data = self.sd.read_sd_data(function_id = 1, address = 0x00, byte_count = len(data_out))
        print "Data From SDIO:\t\t\t\t%s" % print_hex_array(data)