interface_generic.sv 1.74 KB
Newer Older
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 70 71 72
interface InterfaceA;
    task hello;
        input integer inp;
        $display("Hello from InterfaceA %0d", inp);
    endtask
    logic [20:0] x = 21'b01011_00100000_01011110;
endinterface

interface InterfaceB;
    task hello;
        input integer inp;
        $display("Hello from InterfaceB %0d", inp);
    endtask
    logic [10:0] x = 11'b011_11110100;
endinterface

// could get bound to any of the interfaces or modports
module Module(interface i);
    initial #4 i.hello(1);
    initial #5 $display("Module got %b", i.x);
endmodule

interface InterfaceM;
    logic [4:0] x = 0;
    task hello;
        input integer inp;
        x = x + 1;
        $display("Hello from InterfaceM %0d %b", inp, x);
    endtask
    modport A(input .x(x[0]));
    modport B(input .x(x[2:1]));
endinterface

// could get bound to the entire interface bundle, or either modport
module ModuleM(InterfaceM i);
    initial i.hello(-1);
    initial $display("ModuleM got %b", i.x);
endmodule

module ModuleWrapperMA(InterfaceM.A i); Module m(i); endmodule
module ModuleWrapperMB(InterfaceM.B i); Module m(i); endmodule
module ModuleWrapperM (InterfaceM   i); Module m(i); endmodule

module ModuleMWrapperMA(InterfaceM.A i); ModuleM m(i); endmodule
module ModuleMWrapperMB(InterfaceM.B i); ModuleM m(i); endmodule
module ModuleMWrapperM (InterfaceM   i); ModuleM m(i); endmodule

module top;
    InterfaceM im();

    Module c(im.A);
    Module d(im.B);
    Module e(im);

    ModuleM x(im.A);
    ModuleM y(im.B);
    ModuleM z(im);

    InterfaceA ia();
    InterfaceB ib();

    Module a(ia);
    Module b(ib);

    ModuleWrapperMA cw(im);
    ModuleWrapperMB dw(im);
    ModuleWrapperM  ew(im);

    ModuleMWrapperMA xw(im);
    ModuleMWrapperMB yw(im);
    ModuleMWrapperM  zw(im);
endmodule