Пример #1
0
    def test_1(self):
        sys = py4hw.HWSystem()

        a = sys.wire("a", 32)
        b = sys.wire("b", 32)
        c = sys.wire("c", 32)
        r1 = sys.wire("r1", 32)
        r2 = sys.wire("r2", 32)
        r3 = sys.wire("r3", 32)

        py4hw.And2(sys, "and1", a, b, r1)
        py4hw.And2(sys, "and2", a, c, r2)
        py4hw.And2(sys, "and3", b, c, r3)

        py4hw.Constant(sys, "a", 0xF, a)
        py4hw.Constant(sys, "b", 0xA, b)
        py4hw.Constant(sys, "c", 0x5, c)

        py4hw.Scope(sys, "r1 (0xF & 0xA)", r1)
        py4hw.Scope(sys, "r2 (0xF & 0x5)", r2)
        py4hw.Scope(sys, "r3 (0xA & 0x5)", r3)

        sys.getSimulator().clk(1)

        assert (r1.get() == 10)
        assert (r2.get() == 5)
        assert (r3.get() == 0)
Пример #2
0
    def test_integrity(self):
        sys = py4hw.HWSystem()

        a = sys.wire("a", 2)

        bits = sys.wires('b', 2, 1)
        minterm = sys.wire('minterm', 1)

        py4hw.BitsLSBF(sys, 'bits', a, bits)
        py4hw.Minterm(sys, 'minterm', bits, 0, minterm)
        py4hw.Constant(sys, "a", 0, a)

        for i in range(len(bits)):
            py4hw.Scope(sys, 'b{}'.format(i), bits[i])

        py4hw.Scope(sys, 'minterm_5', minterm)

        py4hw.debug.checkIntegrity(sys)
Пример #3
0
    def test_printHierarchy(self):
        sys = py4hw.HWSystem()

        a = sys.wire("a", 32)
        b = sys.wire("b", 32)
        c = sys.wire("c", 32)
        r1 = sys.wire("r1", 32)
        r2 = sys.wire("r2", 32)
        r3 = sys.wire("r3", 32)

        py4hw.And2(sys, "and1", a, b, r1)
        py4hw.And2(sys, "and2", a, c, r2)
        py4hw.And2(sys, "and3", b, c, r3)

        py4hw.Constant(sys, "a", 0xF, a)
        py4hw.Constant(sys, "b", 0xA, b)
        py4hw.Constant(sys, "c", 0x5, c)

        py4hw.Scope(sys, "r1 (0xF & 0xA)", r1)
        py4hw.Scope(sys, "r2 (0xF & 0x5)", r2)
        py4hw.Scope(sys, "r3 (0xA & 0x5)", r3)

        py4hw.debug.printHierarchy(sys)
Пример #4
0
    def test_Integrity(self):
        sys = py4hw.HWSystem()

        a = sys.wire("a", 32)
        b = sys.wire("b", 32)
        c = sys.wire("c", 32)
        r1 = sys.wire("r", 32)
        r2 = sys.wire("r2", 32)

        py4hw.Add(sys, "add1", a, b, r1)
        py4hw.Add(sys, "add2", r1, c, r2)

        py4hw.Constant(sys, "a", 10, a)
        py4hw.Constant(sys, "b", 20, b)
        py4hw.Constant(sys, "c", 5, c)
        py4hw.Scope(sys, "r2", r2)

        py4hw.debug.checkIntegrity(sys)
Пример #5
0
import py4hw


class Circuit(py4hw.Logic):
    def __init__(self, parent, name, a, b, r):
        super().__init__(parent, name)

        self.addIn('a', a)
        self.addIn('b', b)
        self.addOut('r', r)

        aux = self.wire('aux')
        py4hw.Add(self, 'add', a, b, aux)
        py4hw.Buf(self, 'buf', aux, r)


sys = py4hw.HWSystem()

a = sys.wire('a', 8)
b = sys.wire('b', 8)
r = sys.wire('r', 8)

c = Circuit(sys, 'c', a, b, r)
py4hw.Constant(sys, 'a', 3, a)
py4hw.Constant(sys, 'b', 3, b)
py4hw.Scope(sys, 'r', r)

py4hw.debug.checkIntegrity(sys)

sch = py4hw.Schematic(c)