summaryrefslogtreecommitdiff
path: root/deprecated/hdl_lab/template.py
blob: 77eb18c099629631f2ce6ca5573b7d2a9699256a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from typing import Callable
from myhdl import *
from myhdl_wrap import Myhdl_Wrapper

import random
from random import randint

random.seed(63)

class Template(Myhdl_Wrapper):
    def __init__(self):
        super().__init__()

    # Main code, this is the actual logic
    @staticmethod
    @block
    def Template(args):  # this must be the same name as the class name

        @instance
        def logic():
            while True:
                ...

        return logic


    @block
    def tb(self, func: Callable):
        reset = Signal(False)
        clk = Signal(False)
        ...

        dut = func(..., clk=clk, reset=reset)

        @always(delay(...))
        def clock_gen():
            clk.next = not clk

        @instance
        def monitor():
            while True:
                ...

        @instance
        def stimulus():
            ...

            raise StopSimulation


        return dut, clock_gen, monitor, stimulus

    def export(self):
        reset = Signal(False)
        clk = Signal(False)
        ...

        # assigning signals, kargs only
        self._export(..., clk=clk, reset=reset)


def test_template_sim():
    hdl = Template()
    hdl.sim()

def test_template_cosim():
    hdl = Template()
    hdl.export()
    hdl.cosim()