Ejemplo n.º 1
0
 def test_round_trip(self):
     with load_data('example-wide.mif') as f:
         mem = mif.load(f)
     memlist = [list(m) for m in mem]
     for a in RADIXES:
         for b in RADIXES:
             s = mif.dumps(mem, address_radix=a, data_radix=b)
             newmem = mif.loads(s)
             self.assertEqual(memlist, [list(m) for m in newmem])
Ejemplo n.º 2
0
 def test_parse(self):
     with load_data('example.mif') as f:
         mem = mif.load(f)
     for i, v in enumerate(mem):
         expected = '00000000'
         if i <= 12:
             expected = '{:08b}'.format(i)
         val = ''.join(str(b) for b in reversed(v))
         self.assertEqual(expected, val)
Ejemplo n.º 3
0
 def test_parse(self):
     with load_data('example-wide.mif') as f:
         mem = mif.load(f)
     expected_blob = [
         '1000000100111111001000000001000000001000000001000000001000000001',
         '0001000011111000111111001111111011111111111111110000000000000000',
         '1111000000001000000001000000001000000001000000010000000000000000',
         '1000000100111111001000000001000000001000000001000000001000000001',
     ]
     expected = list(int(i) for i in reversed(''.join(expected_blob)))
     self.assertEqual(list(mem[0]), expected)
Ejemplo n.º 4
0
    def read_mem(self, inst, delete_mif=False):

        fname = self.path + 'r' + self.name.format(inst)

        self.quartus.begin_memory_edit(hardware_name=self.hwname,\

            device_name=self.devname)

        self.quartus.save_content_from_memory_to_file(instance_index=inst,
                                                      mem_file_path=fname,
                                                      mem_file_type='mif')

        with open(fname, 'r') as f:
            data = mif.load(f)
            f.close()
        self.quartus.end_memory_edit()

        if delete_mif:
            os.remove(fname)

        return data
Ejemplo n.º 5
0
def read(q=None,
         inst=0,
         hw='DE-SoC [USB-1]',
         dev='@2: 5CSEBA6(.|ES)/5CSEMA6/.. (0x02D020DD)',
         begin=True,
         end=True,
         fname=None,
         delete_mif=True):
    '''Reads memory from an instance `inst` into an array `data`.
    Option `delete_mif` will delete temporary .mif file if set to `True`.'''
    if begin:
        begin_mem(q, hw=hw, dev=dev)
    fname = fname or 'read_inst{0}'.format(inst)
    q.save_content_from_memory_to_file(instance_index=inst,
                                       mem_file_path=fname,
                                       mem_file_type='mif')
    with open(fname, 'r') as f:
        data = mif.load(f)
        f.close()
    if delete_mif:
        os.remove(fname)
    if end:
        end_mem(q)
    return np.array(data).astype(float).astype(int)
Ejemplo n.º 6
0
import sys

import mif

for fname in sys.argv[1:]:
    with open(fname) as f:
        mem = mif.load(f)
        for m in mem:
            print(' '.join(str(b) for b in m))
Ejemplo n.º 7
0
def get_data(mif_file):
    with open(mif_file) as f:
        mem = mif.load(f)
    return mem