module DGate( // directions N, E, S, W, //output value, //clock status status //, // rotation //R ); function integer bintopol; // conversion function from binary to polarization input a; // input argument port case (a) 1'b0: bintopol = -1; 1'b1: bintopol = 1; 1'bz: bintopol = 0; 1'bx: bintopol = 0; endcase endfunction function Dcompute; // function definition input N, E, S, W; integer polarization; begin polarization = bintopol(N) + bintopol(S) - 2*(bintopol(E) + bintopol(W)); if ( polarization > 1) Dcompute = 1'b1; else if ( polarization < -1) Dcompute = 1'b0; else Dcompute =1'bz; end endfunction // Dcompute input N, E, S, W; input R; input [1:0] status; output value; reg value; parameter reset=2'b00; parameter switch=2'b01; parameter hold=2'b10; // //status 00=relax,01=switch, 10=hold, 11=release input N, E, S, W; input R; input [1:0] status; output value; reg value; always @(status,N,E,S,W) begin if (status == reset) //reset value <= 1'bz; else if (value === 1'bz) value<= #1 Dcompute(N,E,S,W); end endmodule