def small_multi_byte_data_read(dut): """ Description: Perform a small read on the data bus Test ID: 5 Expected Results: Multi byte data transfer, this will use the data bus, not CMC mode """ dut.test_id = 5 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) data = yield cocotb.external(sdhost.read_sd_data)(function_id=0, address=0x00, byte_count=8, fifo_mode=False) #print "data: %s" % print_hex_array(data) fail = False test_data = Array('B', [0x43, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) for i in range(len(data)): if data[i] != test_data[i]: fail = True break if fail: raise TestFailure("Multi-Byte Read incorrect: %s != %s" % (print_hex_array(test_data), print_hex_array(data))) yield (nysa.wait_clocks(1000))
def send_byte_test(dut): """ Description: Initiate an SD transaction Test ID: 2 Expected Results: Single Data Write """ dut.test_id = 2 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) if dut.s2.sdio_device.card_controller.v1p8_sel.value.get_value() == False: raise TestFailure("Failed to set 1.8V Switch Voltage Request") yield cocotb.external(sdhost.cmd_get_relative_card_address)() if dut.s2.sdio_device.card_controller.state.value.get_value() != 2: raise TestFailure("Card Should Be In Standby State Right Now") yield cocotb.external(sdhost.cmd_enable_card)(True) if dut.s2.sdio_device.card_controller.state.value.get_value() != 3: raise TestFailure("Card Should Be In Command State Right Now") yield cocotb.external(sdhost.write_config_byte)(0x02, 0x01) if dut.s2.sdio_device.cia.cccr.o_func_enable.value.get_value() != 1: raise TestFailure( "Failed to write configuration byte to CCCR Memory Space") yield (nysa.wait_clocks(1000))
def receive_byte_test(dut): """ Description: Initiate an SD transaction Test ID: 3 Expected Results: Single Data Read """ dut.test_id = 3 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) value = yield cocotb.external(sdhost.read_config_byte)(0x00) if value != 0x43: raise TestFailure("Failed to Read Configuration Byte at Address 0: bad value: 0x%02X" % value) dut.log.debug("Read value: 0x%02X" % value) value = yield cocotb.external(sdhost.read_config_byte)(0x01) if value != 0x03: raise TestFailure("Failed to Read Configuration Byte at Address 1: bad value: 0x%02X" % value) dut.log.debug("Read value: 0x%02X" % value) value = yield cocotb.external(sdhost.read_config_byte)(0x02) if value != 0x00: raise TestFailure("Failed to Read Configuration Byte at Address 2: bad value: 0x%02X" % value) dut.log.debug("Read value: 0x%02X" % value) yield (nysa.wait_clocks(1000))
def send_byte_test(dut): """ Description: Initiate an SD transaction Test ID: 2 Expected Results: Single Data Write """ dut.test_id = 2 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) if dut.s2.sdio_device.card_controller.v1p8_sel.value.get_value() == False: raise TestFailure ("Failed to set 1.8V Switch Voltage Request") yield cocotb.external(sdhost.cmd_get_relative_card_address)() if dut.s2.sdio_device.card_controller.state.value.get_value() != 2: raise TestFailure ("Card Should Be In Standby State Right Now") yield cocotb.external(sdhost.cmd_enable_card)(True) if dut.s2.sdio_device.card_controller.state.value.get_value() != 3: raise TestFailure ("Card Should Be In Command State Right Now") yield cocotb.external(sdhost.write_config_byte)(0x02, 0x01) if dut.s2.sdio_device.cia.cccr.o_func_enable.value.get_value() != 1: raise TestFailure ("Failed to write configuration byte to CCCR Memory Space") yield (nysa.wait_clocks(1000))
def small_multi_byte_data_write(dut): """ Description: Perform a small write on the data bus Test ID: 4 Expected Results: Multi byte data transfer, this will use the data bus, not FIFO mode """ dut.test_id = 4 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #data = Array ('B', [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]) data = Array ('B') for i in range (8): value = i % 256 data.append(value) yield cocotb.external(sdhost.write_sd_data)(0, 0x00, data, fifo_mode = False, read_after_write = False) value = dut.s2.sdio_device.cia.cccr.o_func_enable.value.get_value() if value != 0x02: raise TestFailure ("Failed to write configuration byte to CCCR Memory Space: Should be 0x02 is: 0x%02X" % value) value = dut.s2.sdio_device.cia.cccr.o_func_int_enable.value.get_value() if value != 0x04: raise TestFailure ("Failed to write configuration byte to CCCR Memory Space: Should be 0x04 is: 0x%02X" % value) yield (nysa.wait_clocks(1000))
def small_multi_byte_data_read(dut): """ Description: Perform a small read on the data bus Test ID: 5 Expected Results: Multi byte data transfer, this will use the data bus, not CMC mode """ dut.test_id = 5 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) data = yield cocotb.external(sdhost.read_sd_data)( function_id = 0, address = 0x00, byte_count = 8, fifo_mode = False) #print "data: %s" % print_hex_array(data) fail = False test_data = Array('B', [0x43, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]) for i in range (len(data)): if data[i] != test_data[i]: fail = True break if fail: raise TestFailure("Multi-Byte Read incorrect: %s != %s" % (print_hex_array(test_data), print_hex_array(data))) yield (nysa.wait_clocks(1000))
def small_multi_byte_data_write_to_func1(dut): """ Description: Perform a small write on the data bus Test ID: 12 Expected Results: Multi byte data transfer, this will use the data bus, not FIFO mode """ dut.test_id = 12 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #data = Array ('B', [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]) data = Array ('B') for i in range (16): value = i % 256 data.append(value) data = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF] yield cocotb.external(sdhost.write_sd_data)(1, 0x00, data, fifo_mode = False, read_after_write = False) yield (nysa.wait_clocks(100)) read_data = yield cocotb.external(sddev.read_local_buffer)(0, len(data) / 4) print "Read data: %s" % print_hex_array(read_data) yield (nysa.wait_clocks(1000))
def data_block_read(dut): """ Description: Perform a block read Test ID: 7 Expected Results: Block Transfer (Read) """ dut.test_id = 7 BLOCK_SIZE = 0x08 SIZE = 0x10 FUNCTION = 0 ADDRESS = 0x00 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) yield cocotb.external(sdhost.set_function_block_size)(FUNCTION, BLOCK_SIZE) data = yield cocotb.external(sdhost.read_sd_data)(FUNCTION, ADDRESS, SIZE, fifo_mode=False) print "Data: %s" % print_hex_array(data) yield (nysa.wait_clocks(2000))
def data_block_read(dut): """ Description: Perform a block read Test ID: 7 Expected Results: Block Transfer (Read) """ dut.test_id = 7 BLOCK_SIZE = 0x08 SIZE = 0x10 FUNCTION = 0 ADDRESS = 0x00 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) yield cocotb.external(sdhost.set_function_block_size)(FUNCTION, BLOCK_SIZE) data = yield cocotb.external(sdhost.read_sd_data)(FUNCTION, ADDRESS, SIZE, fifo_mode = False) print "Data: %s" % print_hex_array(data) yield (nysa.wait_clocks(2000))
def data_async_block_read_write_long_transfer(dut): """ Description: Perform a block read using asynchronous transfer Test ID: 11 Expected Results: Block Transfer (Read) """ dut.test_id = 11 ADDRESS = 0x00 FUNCTION = 1 BLOCK_SIZE = 0x08 SIZE = 0x18 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #Enable Function yield cocotb.external(sdhost.enable_function)(FUNCTION) yield cocotb.external(sdhost.set_function_block_size)(FUNCTION, BLOCK_SIZE) write_data = Array ('B') for i in range (SIZE): value = i % 256 write_data.append(value) yield cocotb.external(sdhost.write_sd_data)(FUNCTION, ADDRESS, write_data, fifo_mode = False, read_after_write = False) yield cocotb.external(sdhost.set_async_dma_reader_callback)(dma_read_callback) yield cocotb.external(sdhost.enable_async_dma_reader)(True) yield cocotb.external(sdhost.read_sd_data)(FUNCTION, ADDRESS, SIZE, fifo_mode = False) dut.log.debug("Waiting for function to finish...") yield (nysa.wait_clocks(4000)) if not data_is_ready: raise TestFailure("Async Read Never Finished!") read_data = sdhost.read_async_data() dut.log.debug("Async Data: %s" % print_hex_array(read_data)) fail = False for i in range(len(write_data)): if write_data[i] != read_data[i]: fail = True if fail: raise TestFailure("Async Block Read Transfer Failed, %s != %s" % (print_hex_array(write_data), print_hex_array(read_data)))
def detect_interrupt(dut): """ Description: Detect an interrupt Test ID: 10 Expected Results: Block Transfer (Read) """ dut.test_id = 10 FUNCTION = 1 BLOCK_SIZE = 0x08 READ_SIZE = 0x18 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #Configure an interrupt callback sdhost.set_interrupt_callback(interrupt_callback) #Enable Function yield cocotb.external(sdhost.enable_function)(FUNCTION) #Enable Interrupts on Device yield cocotb.external(sdhost.enable_function_interrupt)(FUNCTION) pending = yield cocotb.external(sdhost.is_interrupt_pending)(FUNCTION) dut.log.debug("Is Interrupt Pending? %s" % pending) #Enable Interrupt on controller yield cocotb.external(sdhost.enable_interrupt)(True) yield (nysa.wait_clocks(100)) #Generate an interrupt dut.request_interrupt = 1 #Detect an interrupt from the device pending = yield cocotb.external(sdhost.is_interrupt_pending)(FUNCTION) dut.log.debug("Is Interrupt Pending? %s" % pending) yield (nysa.wait_clocks(3000)) if not interrupt_called: raise TestFailure("Interrupt was not detected")
def data_block_write(dut): """ Description: Perform a block write Test ID: 6 Expected Results: Block Transfer (Write) """ dut.test_id = 6 FUNCTION = 1 ADDRESS = 0x00 BLOCK_SIZE = 0x08 SIZE = 0x10 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open (sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths = [MODULE_PATH]) setup_dut(dut) yield(nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)(nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)(nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v = True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #Enable Function yield cocotb.external(sdhost.enable_function)(FUNCTION) yield cocotb.external(sdhost.set_function_block_size)(FUNCTION, BLOCK_SIZE) write_data = Array ('B') for i in range (SIZE): value = i % 256 write_data.append(value) yield cocotb.external(sdhost.write_sd_data)(FUNCTION, ADDRESS, write_data, fifo_mode = False, read_after_write = False) yield (nysa.wait_clocks(2000)) read_data = yield cocotb.external(sdhost.read_sd_data)( function_id = FUNCTION, address = ADDRESS, byte_count = len(write_data), fifo_mode = False) yield (nysa.wait_clocks(2000)) fail = False for i in range(len(write_data)): if write_data[i] != read_data[i]: fail = True if fail: raise TestFailure("Block Write Transfer Failed, %s != %s" % (print_hex_array(write_data), print_hex_array(read_data)))
def small_multi_byte_data_write(dut): """ Description: Perform a small write on the data bus Test ID: 4 Expected Results: Multi byte data transfer, this will use the data bus, not FIFO mode """ dut.test_id = 4 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #data = Array ('B', [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]) data = Array('B') for i in range(8): value = i % 256 data.append(value) yield cocotb.external(sdhost.write_sd_data)(0, 0x00, data, fifo_mode=False, read_after_write=False) value = dut.s2.sdio_device.cia.cccr.o_func_enable.value.get_value() if value != 0x02: raise TestFailure( "Failed to write configuration byte to CCCR Memory Space: Should be 0x02 is: 0x%02X" % value) value = dut.s2.sdio_device.cia.cccr.o_func_int_enable.value.get_value() if value != 0x04: raise TestFailure( "Failed to write configuration byte to CCCR Memory Space: Should be 0x04 is: 0x%02X" % value) yield (nysa.wait_clocks(1000))
def receive_byte_test(dut): """ Description: Initiate an SD transaction Test ID: 3 Expected Results: Single Data Read """ dut.test_id = 3 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) value = yield cocotb.external(sdhost.read_config_byte)(0x00) if value != 0x43: raise TestFailure( "Failed to Read Configuration Byte at Address 0: bad value: 0x%02X" % value) dut.log.debug("Read value: 0x%02X" % value) value = yield cocotb.external(sdhost.read_config_byte)(0x01) if value != 0x03: raise TestFailure( "Failed to Read Configuration Byte at Address 1: bad value: 0x%02X" % value) dut.log.debug("Read value: 0x%02X" % value) value = yield cocotb.external(sdhost.read_config_byte)(0x02) if value != 0x00: raise TestFailure( "Failed to Read Configuration Byte at Address 2: bad value: 0x%02X" % value) dut.log.debug("Read value: 0x%02X" % value) yield (nysa.wait_clocks(1000))
def small_multi_byte_data_write_to_func1(dut): """ Description: Perform a small write on the data bus Test ID: 12 Expected Results: Multi byte data transfer, this will use the data bus, not FIFO mode """ dut.test_id = 12 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) #print "SDIO PATH: %s" % SDIO_PATH #print "module path: %s" % MODULE_PATH nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) #nysa.pretty_print_sdb() #sdhost = SDHostDriver(nysa, nysa.find_device(SDHostDriver)[0]) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #data = Array ('B', [0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07]) data = Array('B') for i in range(16): value = i % 256 data.append(value) data = [0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF] yield cocotb.external(sdhost.write_sd_data)(1, 0x00, data, fifo_mode=False, read_after_write=False) yield (nysa.wait_clocks(100)) read_data = yield cocotb.external(sddev.read_local_buffer)(0, len(data) / 4) print "Read data: %s" % print_hex_array(read_data) yield (nysa.wait_clocks(1000))
def data_async_block_read_write_long_transfer(dut): """ Description: Perform a block read using asynchronous transfer Test ID: 11 Expected Results: Block Transfer (Read) """ dut.test_id = 11 ADDRESS = 0x00 FUNCTION = 1 BLOCK_SIZE = 0x08 SIZE = 0x18 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #Enable Function yield cocotb.external(sdhost.enable_function)(FUNCTION) yield cocotb.external(sdhost.set_function_block_size)(FUNCTION, BLOCK_SIZE) write_data = Array('B') for i in range(SIZE): value = i % 256 write_data.append(value) yield cocotb.external(sdhost.write_sd_data)(FUNCTION, ADDRESS, write_data, fifo_mode=False, read_after_write=False) yield cocotb.external( sdhost.set_async_dma_reader_callback)(dma_read_callback) yield cocotb.external(sdhost.enable_async_dma_reader)(True) yield cocotb.external(sdhost.read_sd_data)(FUNCTION, ADDRESS, SIZE, fifo_mode=False) dut.log.debug("Waiting for function to finish...") yield (nysa.wait_clocks(4000)) if not data_is_ready: raise TestFailure("Async Read Never Finished!") read_data = sdhost.read_async_data() dut.log.debug("Async Data: %s" % print_hex_array(read_data)) fail = False for i in range(len(write_data)): if write_data[i] != read_data[i]: fail = True if fail: raise TestFailure( "Async Block Read Transfer Failed, %s != %s" % (print_hex_array(write_data), print_hex_array(read_data)))
def detect_interrupt(dut): """ Description: Detect an interrupt Test ID: 10 Expected Results: Block Transfer (Read) """ dut.test_id = 10 FUNCTION = 1 BLOCK_SIZE = 0x08 READ_SIZE = 0x18 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #Configure an interrupt callback sdhost.set_interrupt_callback(interrupt_callback) #Enable Function yield cocotb.external(sdhost.enable_function)(FUNCTION) #Enable Interrupts on Device yield cocotb.external(sdhost.enable_function_interrupt)(FUNCTION) pending = yield cocotb.external(sdhost.is_interrupt_pending)(FUNCTION) dut.log.debug("Is Interrupt Pending? %s" % pending) #Enable Interrupt on controller yield cocotb.external(sdhost.enable_interrupt)(True) yield (nysa.wait_clocks(100)) #Generate an interrupt dut.request_interrupt = 1 #Detect an interrupt from the device pending = yield cocotb.external(sdhost.is_interrupt_pending)(FUNCTION) dut.log.debug("Is Interrupt Pending? %s" % pending) yield (nysa.wait_clocks(3000)) if not interrupt_called: raise TestFailure("Interrupt was not detected")
def data_block_write(dut): """ Description: Perform a block write Test ID: 6 Expected Results: Block Transfer (Write) """ dut.test_id = 6 FUNCTION = 1 ADDRESS = 0x00 BLOCK_SIZE = 0x08 SIZE = 0x10 SDIO_PATH = get_verilog_path("sdio-device") sdio_config = os.path.join(SDIO_PATH, "sdio_configuration.json") config = None with open(sdio_config, "r") as f: dut.log.warning("Run %s before running this function" % os.path.join(SDIO_PATH, "tools", "generate_config.py")) config = json.load(f) nysa = NysaSim(dut, SIM_CONFIG, CLK_PERIOD, user_paths=[MODULE_PATH]) setup_dut(dut) yield (nysa.reset()) nysa.read_sdb() yield (nysa.wait_clocks(10)) sdhost = yield cocotb.external(SDHostDriver)( nysa, nysa.find_device(SDHostDriver)[0]) sddev = yield cocotb.external(SDIODeviceDriver)( nysa, nysa.find_device(SDIODeviceDriver)[0]) yield (nysa.wait_clocks(200)) yield cocotb.external(sddev.enable_sdio_device)(False) yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.reset_core)() yield (nysa.wait_clocks(100)) yield cocotb.external(sddev.enable_sdio_device)(True) yield (nysa.wait_clocks(100)) #Enable SDIO yield cocotb.external(sdhost.enable_sd_host)(True) yield cocotb.external(sdhost.cmd_io_send_op_cond)(enable_1p8v=True) yield cocotb.external(sdhost.cmd_get_relative_card_address)() yield cocotb.external(sdhost.cmd_enable_card)(True) #Enable Function yield cocotb.external(sdhost.enable_function)(FUNCTION) yield cocotb.external(sdhost.set_function_block_size)(FUNCTION, BLOCK_SIZE) write_data = Array('B') for i in range(SIZE): value = i % 256 write_data.append(value) yield cocotb.external(sdhost.write_sd_data)(FUNCTION, ADDRESS, write_data, fifo_mode=False, read_after_write=False) yield (nysa.wait_clocks(2000)) read_data = yield cocotb.external(sdhost.read_sd_data)( function_id=FUNCTION, address=ADDRESS, byte_count=len(write_data), fifo_mode=False) yield (nysa.wait_clocks(2000)) fail = False for i in range(len(write_data)): if write_data[i] != read_data[i]: fail = True if fail: raise TestFailure( "Block Write Transfer Failed, %s != %s" % (print_hex_array(write_data), print_hex_array(read_data)))