示例#1
0
def test_idle():
    with pytest.raises(ValueError):
        jump_table.JumpEntry(64, 0, jump_table.IDLE(-1)).as_bytes()
    with pytest.raises(ValueError):
        jump_table.JumpEntry(64, 0, jump_table.IDLE(2**15)).as_bytes()
    data = jump_table.JumpEntry(64, 0, jump_table.IDLE(64)).as_bytes()
    assert data[6] >> 1 == 64
    assert data[7] == 0
示例#2
0
def test_table():
    cycle = jump_table.JumpEntry(64, 0, jump_table.CYCLE(0, 1))
    end = jump_table.JumpEntry(80, 0, jump_table.END())
    jt = jump_table.JumpTable(32, [cycle, end], [259, 0, 0, 0])
    data = np.fromstring(jt.toString(), dtype='u1')
    # counters
    assert data[0] == 3
    assert data[1] == 1
    for i in range(2, 16):
        assert data[i] == 0
    # start addr
    assert data[16] == data[19] == 32
    for i in [17, 18, 20, 21, 23]:
        assert data[i] == 0
    # first JT must always be NOP
    assert data[22] == 5
    assert np.array_equal(data[24:32], cycle.as_bytes())
    assert np.array_equal(data[32:40], end.as_bytes())
示例#3
0
 def test_jt_run_sram(self):
     PERIOD = 2000  # as in IQ mixer calibration
     dataIn = np.zeros(PERIOD)
     startAddr, endAddr = 0, len(dataIn)
     jt = self.dev.jt_run_sram(startAddr, endAddr, loop=True)
     jt_packet = np.fromstring(jt.toString(), dtype='u1')
     entry = jump_table.JumpEntry(
         PERIOD // 4 + _JUMP_TABLE_FROM_ADDR_OFFSET, 0, jump_table.JUMP(1))
     matching_jt = jump_table.JumpTable(start_addr=0, jumps=[entry])
     matching_jt_packet = np.fromstring(matching_jt.toString(), dtype='u1')
     assert np.array_equal(matching_jt_packet, jt_packet)
示例#4
0
    def test_basic_run(self):
        sram_data = np.array(np.linspace(0, 0x3FFF, 256), dtype='<u4')
        matching_jt = jump_table.JumpTable(
            start_addr=0,
            # from_addr offset of -3 for END for this version of the JT
            jumps=[
                jump_table.JumpEntry(256 // 4 + _JUMP_TABLE_END_ADDR_OFFSET, 0,
                                     jump_table.END())
            ],
            counters=[0, 0, 0, 0])
        matching_packet = np.fromstring(matching_jt.toString(), dtype='u1')

        s, c = self.server, self.ctx
        # do this board
        s.jump_table_clear(c)
        s.jump_table_add_entry(c, 'END', 256)
        s.dac_sram(c, sram_data)
        s.loop_delay(c, Value(50, 'us'))
        s.start_delay(c, 12)

        # global settings
        s.sequence_boards(
            c, [self.dev.name])  # actually the 'daisy_chain' setting
        s.sequence_timing_order(c, [])  # actually 'timing_order'

        self._fake_run_sequence()
        # check the run packet
        run_pkt = self.run_packets[0]
        assert run_pkt[0] == 1  # master mode
        assert run_pkt[1] == 0  # no readback
        assert run_pkt[13] == self.global_reps & 0xFF  # reps low byte
        assert run_pkt[14] == self.global_reps >> 8  # reps high byte
        assert run_pkt[15] == 50  # loop delay
        assert run_pkt[16] == 0
        delay = 12 + self.global_board_delay + dac.MASTER_SRAM_DELAY_US
        assert run_pkt[43] == delay & 0xFF  # delay
        assert run_pkt[44] == delay >> 8

        # check the SRAM and JT packets
        load_writes = self.load_writes[0]
        assert len(load_writes) == 2
        assert np.array_equal(load_writes[0], matching_packet)
        assert load_writes[1][0] == load_writes[1][1] == 0
        assert np.array_equal(load_writes[1][2:],
                              np.fromstring(sram_data.tostring(), dtype='u1'))
示例#5
0
    def test_multiple_boards(self):
        loop_delay = Value(250, 'us')
        start_delays = [(NUM_DACS - i) * 10 for i in range(NUM_DACS)]
        sram_data_1 = np.array(np.linspace(0, 0x3FFF, 512), dtype='<u4')
        sram_data_2 = np.array(np.ones_like(sram_data_1), dtype='<u4')
        matching_jt = jump_table.JumpTable(
            start_addr=0,
            jumps=[
                jump_table.JumpEntry(
                    256 // 4 + _JUMP_TABLE_FROM_ADDR_OFFSET, 0,
                    jump_table.IDLE(1000 // 4 + _JUMP_TABLE_IDLE_OFFSET)),
                jump_table.JumpEntry(512 // 4 + _JUMP_TABLE_END_ADDR_OFFSET, 0,
                                     jump_table.END())
            ],
            counters=[0, 0, 0, 0])
        matching_jt_packet = np.fromstring(matching_jt.toString(), dtype='u1')
        # set up the DACs
        s, c = self.server, self.ctx
        daisy_chain = []
        for i in range(1, NUM_DACS + 1):
            s.select_device(c, i)
            s.jump_table_clear(c)
            s.jump_table_add_entry(c, 'IDLE', [256, 1000])
            s.jump_table_add_entry(c, 'END', 512)
            if i == 1:
                s.dac_sram(c, sram_data_1)
            else:
                s.dac_sram(c, sram_data_2)
            s.loop_delay(c, loop_delay)
            s.start_delay(c, start_delays[i - 1])
            daisy_chain.append('Test DAC {}'.format(i))
        # global settings
        s.sequence_boards(c, daisy_chain)  # actually the 'daisy_chain' setting
        s.sequence_timing_order(c, [])  # actually 'timing_order'

        self._fake_run_sequence()

        for i in range(NUM_DACS):
            # check register packets
            p = self.run_packets[i]
            # first board is master
            if i == 0:
                assert p[0] == 1
            else:
                assert p[0] == 3
            packet_delay = p[43] + (p[44] >> 8)
            expected_delay = start_delays[i] + self.global_board_delay
            if i == 0:
                expected_delay += dac.MASTER_SRAM_DELAY_US
            assert packet_delay == expected_delay

            load_writes = self.load_writes[i]
            # check SRAM packets
            assert len(load_writes) == 3
            if i == 0:
                assert load_writes[1][2:].tostring(
                ) == sram_data_1[:256].tostring()
                assert load_writes[2][2:].tostring(
                ) == sram_data_1[256:].tostring()
            else:
                assert load_writes[1][2:].tostring(
                ) == sram_data_2[:256].tostring()
                assert load_writes[2][2:].tostring(
                ) == sram_data_2[256:].tostring()
            # check JT
            assert np.array_equal(matching_jt_packet, load_writes[0])
示例#6
0
def test_jump():
    data = jump_table.JumpEntry(64, 259, jump_table.JUMP(2)).as_bytes()
    assert list(data) == [64, 0, 0, 3, 1, 0, 13, 2]
示例#7
0
def test_cycle():
    data = jump_table.JumpEntry(64, 259, jump_table.CYCLE(2, 1)).as_bytes()
    assert list(data) == [64, 0, 0, 3, 1, 0, 35, 1]
示例#8
0
def test_nop():
    nop = jump_table.JumpEntry(259, 0, jump_table.NOP())
    data = nop.as_bytes()
    assert list(data) == [3, 1, 0, 0, 0, 0, 5, 0]
示例#9
0
def test_end():
    end = jump_table.JumpEntry(259, 0, jump_table.END())
    data = end.as_bytes()
    assert list(data) == [3, 1, 0, 0, 0, 0, 7, 0]