def sync_header(): return [ PatternVector(['1', 'X', '0', 'X', 'X']), PatternVector(['1', 'X', '1', 'X', 'X'], opcode='repeat(5)', comment='Sync header') ]
def test_pattern_start(self): result = to_statements(sync_header()) expected = to_statements([ PatternVector(['1', 'X', '0', 'X', 'X']), PatternVector(['1', 'X', '1', 'X', 'X'], opcode='repeat(5)', comment='Sync header'), ]) self.assertEqual(result, expected)
def test_write_cmd(self): result = to_statements(write_cmd()) expected = to_statements([ PatternVector(['0', '0', 'X', '1'], comment='Write Command'), PatternVector(['0', '1', 'X', '1'], comment='Write Command'), PatternVector(['0', '0', 'X', '1'], comment='Write Command'), PatternVector(['0', '0', 'X', '1'], comment='Write Command'), PatternVector(['0', '0', 'X', '1'], comment='Write Command'), ]) self.assertEqual(result, expected)
def test_to_statements(self): vectors = [ PatternVector(['1', 'X'], 'this is a comment', 'opcode1'), PatternVector(['V', '0'], 'another comment', 'opcode2'), ] expected_statement = '\n'.join([ 'opcode1 - 1 X; // this is a comment', 'opcode2 - V 0; // another comment' ]) self.assertEqual(to_statements(vectors), expected_statement)
def test_read_value_cmd(self): result = to_statements(read_value_cmd()) expected = to_statements([ PatternVector(['0', '0', 'X', '1'], comment='Read Value Command'), PatternVector(['0', '1', 'X', '1'], comment='Read Value Command'), PatternVector(['0', '0', 'X', '1'], comment='Read Value Command'), PatternVector(['0', '0', 'X', '1'], comment='Read Value Command'), PatternVector(['0', '0', 'X', '1'], comment='Read Value Command'), ]) self.assertEqual(result, expected)
def generate(self, pattern_content): vectors = [PatternVector(['0', 'X', 'X'], comment='Pattern Start', timeset=self.timeset_name)] for row in pattern_content: cmd = row['Command'].lower() if cmd == 'write': vectors += self._write(row['Data']) elif cmd == 'read': vectors += self._read() else: raise Exception(f"Invalid command {cmd}") vectors += [PatternVector(['0', 'X', 'X'], comment='Pattern End', opcode='halt')] return vectors
def test_wait(self): result = to_statements(wait(3)) expected_result = PatternVector( ['1', 'X', '0', 'X', 'X'], opcode=f'repeat(3)', comment=f'Wait for 3 Timesets').get_statement() self.assertEqual(result, expected_result)
def frame_end(): return [PatternVector(['1', '0', 'X', '0'], comment='End of SPI 4W Frame', opcode='repeat(5)')]
def _expect_writing_bits(self, bits_str, comment): return to_statements([ PatternVector(['1', 'X', bit, 'X', 'X'], comment=comment) for bit in bits_str ])
def test_get_statement(self): vector = PatternVector(['1', 'X'], 'this is comment', 'opcode', 'timeset0') expected_statement = 'opcode timeset0 1 X; // this is comment' self.assertEqual(vector.get_statement(), expected_statement)
def _write(self, data): bit_str = int_to_bits_msb_first(data, 8) vectors = [] for i in range(0, 8): vectors.append(PatternVector(['1', bit_str[i], 'X'], comment=f'Write {data} (bit {i})')) return vectors
def _read(self): return ([PatternVector(['0', 'X', 'X'], opcode='capture_start(DATA_Read)')] # reading 8 bits + [PatternVector(['0', 'X', 'V'], comment='Read', opcode='capture')] * 8 + [PatternVector(['0', 'X', 'X'], opcode='capture_stop')] )
def pattern_end(): return [PatternVector(['X', 'X', 'X', 'X'], comment='End of the pattern', opcode='halt')]
def test_get_statement_default_params(self): vector = PatternVector(['1', 'X']) expected_statement = ' - 1 X;' self.assertEqual(vector.get_statement(), expected_statement)
def capture_stop(): return [PatternVector(['1', '0', 'X', '1'], opcode='capture_stop')]
def pattern_start(timeset_name): return [PatternVector(['1', '0', 'X', '0'], comment='Start of the pattern', timeset=timeset_name)]
def wait(num_timeset): return [PatternVector(['1', '0', 'X', '0'], comment=f'Wait for {num_timeset} Timeset', opcode=f'repeat({num_timeset})')]
def test_read_data(self): result = to_statements(read_data()) expected = to_statements([PatternVector(['0', 'X', 'V', '1'], comment='Read', opcode='capture')] * 16) self.assertEqual(result, expected)
def test_capture_stop(self): result = to_statements(capture_stop()) expected = PatternVector(['1', '0', 'X', '1'], opcode='capture_stop').get_statement() self.assertEqual(result, expected)
def test_frame_end(self): result = to_statements(frame_end()) expected = PatternVector(['1', '0', 'X', '0'], comment='End of SPI 4W Frame', opcode='repeat(5)').get_statement() self.assertEqual(result, expected)
def test_pattern_end(self): result = to_statements(pattern_end()) expected = PatternVector(['X', 'X', 'X', 'X'], comment='End of the pattern', opcode='halt').get_statement() self.assertEqual(result, expected)
def capture_start(): return [PatternVector(['1', '0', 'X', '0'], opcode='capture_start(DATA_Read)')]
def test_pattern_start(self): result = to_statements(pattern_start('Test_Timeset')) expected = PatternVector(['1', '0', 'X', '0'], comment='Start of the pattern', timeset='Test_Timeset').get_statement() self.assertEqual(result, expected)
def _write_bits(bits_str, comment): return [PatternVector(['0', bit, 'X', '1'], comment=comment) for bit in bits_str]
def test_write_address(self): result = to_statements(write_address('0x3cd')) # 0x3cd = 011 1100 1101 b expected = to_statements([ PatternVector(['0', '0', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '0', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '0', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '0', 'X', '1'], comment='Address 0x3cd'), PatternVector(['0', '1', 'X', '1'], comment='Address 0x3cd'), ]) self.assertEqual(result, expected)
def read_data(): # capture 16 bits of data return [PatternVector(['0', 'X', 'V', '1'], comment='Read', opcode='capture')] * 16
def test_write_data(self): result = to_statements(write_data('0xabcd')) # 0xabcd = 1010 1011 1100 1101 b expected = to_statements([ PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '0', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '0', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '0', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '0', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '0', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '0', 'X', '1'], comment='Data 0xabcd'), PatternVector(['0', '1', 'X', '1'], comment='Data 0xabcd'), ]) self.maxDiff = None self.assertEqual(result, expected)
def frame_start(): return [PatternVector(['1', '0', 'X', '0'], comment='Start of SPI 4W Frame', opcode='repeat(5)')]
def wait(num_timesets): return [ PatternVector(['1', 'X', '0', 'X', 'X'], opcode=f'repeat({num_timesets})', comment=f'Wait for {num_timesets} Timesets') ]