Ejemplo n.º 1
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())
Ejemplo n.º 2
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")
Ejemplo n.º 3
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")
Ejemplo n.º 4
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)
Ejemplo n.º 5
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()
Ejemplo n.º 6
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)
Ejemplo n.º 7
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())
Ejemplo n.º 8
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())
Ejemplo n.º 9
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
Ejemplo n.º 10
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))
Ejemplo n.º 11
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.drv = None
            return
        n = plat[2]
        urn = n.find_device(DRIVER)[0]
        self.drv = DRIVER(n, urn)
        self.s.set_level("verbose")
        self.s.Important("Using Platform: %s" % plat[0])
        self.s.Important("Instantiated a DRIVER Device: %s" % urn)

    def test_sata(self):
        if self.drv is None:
            self.s.Fatal("Cannot Run Test when no device is found!")
            return
        self.drv.enable_sata_reset(True)
        self.s.Info("Reseting Hard Drive, sleeping for a half second...")
        time.sleep(0.5)
        self.drv.enable_sata_reset(False)
        self.s.Info("Hard Drive Reset, sleeping for a half second...")
        time.sleep(0.75)

        self.s.Info("Sata in reset: %s" % self.drv.is_sata_reset())
        #self.s.Info("Is reset in progress: %s" % self.drv.is_sata_reset_active())
        #self.s.Info("Command Layer Reset: %s" % self.drv.is_sata_command_layer_reset())
        self.s.Info("Is platform ready: %s" % self.drv.is_platform_ready())
        #self.s.Info("Is platform error: %s" % self.drv.is_platform_error())
        self.s.Important("linkup: %s" % self.drv.is_linkup())
        #self.s.Info("phy layer ready: %s" % self.drv.is_phy_ready())
        #self.s.Info("link layer ready: %s" % self.drv.is_link_layer_ready())
        #self.s.Info("sata busy: %s" % self.drv.is_sata_busy())
        #self.s.Info("is hard drive error: %s" % self.drv.is_hard_drive_error())
        #self.s.Info("PIO data ready: %s" % self.drv.is_pio_data_ready())
        #self.s.Info("RX COMM Init Detect: %s" % self.drv.get_rx_comm_init_detect())
        #self.s.Info("RX COMM Wake Detect: %s" % self.drv.get_rx_comm_wake_detect())
        #self.s.Info("TX OOB Complete: %s" % self.drv.get_tx_oob_complete())

        #self.s.Info("TX Comm Reset Detect: %s" % self.drv.get_tx_comm_reset())
        #self.s.Info("TX Comm Wake Detect: %s" % self.drv.get_tx_comm_wake())
        #self.s.Debug("OOB State: 0x%04X" % self.drv.get_oob_state())
        #self.s.Debug("Reset Count: 0x%08X" % self.drv.get_reset_count())
        #self.s.Debug("Debug Linkup Data: 0x%08X" % self.drv.get_debug_linkup_data())

        #self.s.Debug("Write to local buffer")
        self.s.Info("Local Buffer Test")
        values = Array('B')
        for i in range(2048 * 4):
            values.append(i % 256)

        self.drv.write_local_buffer(values)
        buf = self.drv.read_local_buffer()
        length_error = False
        if len(values) != len(buf):
            length_error = True
            self.s.Error(
                "Length of write does not match length of read! %d != %d" %
                (len(values), len(buf)))

        error_count = 0
        for i in range(len(values)):
            if error_count > 16:
                break
            if values[i] != buf[i]:
                error_count += 1
                self.s.Error("Error at Address 0x%04X: 0x%02X != 0x%02X" %
                             (i, values[i], buf[i]))

        if error_count > 0 or length_error:
            self.s.Error("Failed local buffer test")
        else:
            self.s.Important("Passed local buffer test!")

        #self.drv.get_hard_drive_size()
        ''' 
        rok_count = self.drv.get_r_ok_count()
        rok_count_before = rok_count
        rerr_count = self.drv.get_r_err_count()
        rerr_count_before = rerr_count

        print "ROK Test"
        self.s.Warning("ROK Count Before: %d" % rok_count)
        self.s.Warning("RERR Count Before: %d" % rerr_count)
        self.drv.hard_drive_idle()
        
        rok_count = self.drv.get_r_ok_count()
        rerr_count = self.drv.get_r_err_count()
        self.s.Warning("ROK Count After: %d" % rok_count)
        self.s.Warning("ROK Count Delta: %d" % (rok_count - rok_count_before))
        self.s.Warning("RERR Count After: %d" % rerr_count)
        self.s.Warning("RERR Count Delta: %d" % (rerr_count - rerr_count_before))
        '''
        self.s.Info("\tInitial Status of hard drive (Status): 0x%02X" %
                    self.drv.get_d2h_status())

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

            self.s.Info("\tInitial (Status): 0x%02X" %
                        self.drv.get_d2h_status())
            for i in range(32):
                self.drv.send_hard_drive_command(0xEC)
                if (self.drv.get_d2h_status() & 0x040) == 0:
                    print "Not Found..."
                else:
                    print "Found!"
            if (self.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.drv.enable_sata_command_layer_reset(True)
                time.sleep(0.1)
                self.drv.enable_sata_command_layer_reset(False)

        self.s.Info("Put Hard Drive in IDLE state")
        self.drv.hard_drive_idle()
        #self.s.Info("\tIdle Result (Status): 0x%02X" % self.drv.get_d2h_status())
        if (self.drv.get_d2h_status() & 0x040) == 0:
            self.s.Error(
                "Did not get a normal status response from the hard drive")
            return

        native_size = self.drv.get_hard_drive_native_size()
        max_lba = self.drv.get_hard_drive_max_native_lba()
        print "Max Native LBA: %d" % max_lba
        self.s.Important("Native Size in gigabytes: %f" %
                         ((native_size * 1.0) * 0.000000001))

        print "Identify Device:"
        data = self.drv.identify_hard_drive()[0:512]
        #print "\tLength of read: %d" % len(data)
        #print "\tdata from hard drive: %s" % str(data)

        config = self.drv.get_config()
        print "Serial Number: %s" % config.serial_number()
        print "Max User Sectors: %d" % config.max_user_sectors()
        print "Max User Size (GB): %f" % (
            (config.max_user_sectors() * 512.0) * 0.000000001)
        #print "Max Sector Capacity: %d" % config.capacity_in_sectors()
        #print "Max Sector Capacity (GB): %f" % ((config.capacity_in_sectors() * 512.0) * 0.000000001)
        #print "Buffer size (bytes): %d" % config.hard_drive_buffer_size()
        #print "DMA Transfer Mode..."
        #config.dma_transfer_mode()
        #config.sata_enabled_features()

        values = Array('B')
        clear_values = Array('B')
        for i in range(2048 * 4):
            values.append(i % 256)
            clear_values.append(0)

        self.drv.set_local_buffer_write_size(128)
        self.drv.write_local_buffer(values)
        #self.drv.write_local_buffer(clear_values)
        #print "Ready Status (Before):0x%02X" % self.drv.get_din_fifo_status()
        #print "Sata Ready: %s" % self.drv.is_command_layer_ready()
        #print "Sata Busy: %s" % self.drv.is_sata_busy()

        self.drv.load_local_buffer()
        self.drv.load_local_buffer()
        self.s.Important("Before Write Start DMA Activate: %s" %
                         self.drv.is_dma_activate_en())
        #self.drv.hard_drive_write(0x0101, 16)
        #self.drv.hard_drive_write(0x0101, 1)
        self.drv.hard_drive_write(0x0000, 2)
        time.sleep(0.5)
        self.s.Important("After Write Start DMA Activate: %s" %
                         self.drv.is_dma_activate_en())
        #self.drv.load_local_buffer()
        #self.drv.load_local_buffer()
        self.drv.set_local_buffer_write_size(2048)
        #self.drv.load_local_buffer()

        #print "Ready Status (Before):0x%02X" % self.drv.get_din_fifo_status()
        #print "command state: %d" % self.drv.get_cmd_wr_state()
        #print "transport state: %d" % self.drv.get_transport_state()
        #print "link layer write state: %d" % self.drv.get_link_layer_write_state()

        #print ""
        #print "Ready Status (Before Read):0x%02X" % self.drv.get_din_fifo_status()
        #print "Sata Ready: %s" % self.drv.is_command_layer_ready()
        #print "Sata Busy: %s" % self.drv.is_sata_busy()
        #print "phy layer ready: %s" % self.drv.is_phy_ready()
        #print ""

        #if self.drv.is_command_layer_ready():
        #print "*** CAN READ NOW! ***"
        self.s.Info("Reading from Hard Drive...")
        self.drv.write_local_buffer(clear_values)

        #self.drv.hard_drive_read(0x0101, 2)
        self.drv.hard_drive_read(0x0400, 2)

        print "Read Result:"
        print "\tstatus: 0x%02X" % self.drv.get_d2h_status()
        print "\terror : 0x%02X" % self.drv.get_d2h_error()
        print "\tLBA: 0x%012X" % self.drv.get_hard_drive_lba()
        print "\tSector Count: 0x%04X" % self.drv.get_sector_count()

        data = self.drv.read_local_buffer()
        #print "\tdata from hard drive: %s" % str(data[0:1024])
        print "\tLength of read: %d" % len(data)
        print "\tdata from hard drive: %s" % str(data[0:1024])
        print "\tReady Status :0x%02X" % self.drv.get_din_fifo_status()

        self.drv.hard_drive_sleep()
Ejemplo n.º 12
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())