[1] | 1 | module MajorityVoter_bi2 (A, B, Zp, Z,status, fault1, fault0); |
---|
| 2 | //Z and Zp are bidirectional. |
---|
| 3 | //if forward =1, Zp is output and Z is input, the opposite otherwise. |
---|
| 4 | //note: forward can't change if not together with a status change. |
---|
| 5 | input [1:0] status; //status 00=relax, 01=switch, 10=hold, 11=release |
---|
| 6 | input A,B; |
---|
| 7 | input fault1, fault0; |
---|
| 8 | inout Z,Zp; |
---|
| 9 | wor wi1, wi2, wi3; |
---|
| 10 | wor wi1p, wi2p, wi3p; |
---|
| 11 | wor Z,Zp; |
---|
| 12 | reg latchZ, latchZp; |
---|
| 13 | // fault1=0 fault0=0 output fault free |
---|
| 14 | // fault1=1 fault0=0 output S a B |
---|
| 15 | // fault1=0(1) fault0=1 output Maj(A',B,C') |
---|
| 16 | |
---|
| 17 | assign forward = (Z===1'bz && Zp!==1'bz) ? 1: (Zp===1'bz && Z!==1'bz) ? 0 : 1'bz; |
---|
| 18 | assign latch_sig = ~status[0] & status[1]; |
---|
| 19 | assign wi1 = ((A & B) | (B & Z) | (A & Z)); |
---|
| 20 | assign wi1p= ((A & B) | (B & Zp) | (A & Zp)); |
---|
| 21 | assign wi3 = ((~A & B) | (B & ~Z) | (~A & ~Z)); |
---|
| 22 | assign wi3p= ((~A & B) | (B & ~Zp) | (~A & ~Zp)); |
---|
| 23 | assign wi2 = (fault1)? B : wi1; |
---|
| 24 | assign wi2p = (fault1)? B : wi1p; |
---|
| 25 | assign Zp = (status==2'b10) ? latchZp : |
---|
| 26 | (status==2'b01) ? (forward ? ((fault0) ? wi3: wi2) :1'bz) : |
---|
| 27 | 1'bz; |
---|
| 28 | assign Z = (status==2'b10 ) ? latchZ: |
---|
| 29 | (status==2'b01 ) ? ((forward===0) ? ((fault0) ? wi3p: wi2p) : 1'bz): |
---|
| 30 | 1'bz; |
---|
| 31 | initial |
---|
| 32 | begin |
---|
| 33 | latchZp =1'bZ; |
---|
| 34 | latchZ=1'bZ; |
---|
| 35 | end |
---|
| 36 | always@(posedge status[1]) |
---|
| 37 | begin |
---|
| 38 | if (status[0]==0) |
---|
| 39 | begin |
---|
| 40 | //latched <= ((fault0) ? wi3: wi2); |
---|
| 41 | latchZp <= Zp ; |
---|
| 42 | latchZ <= Z; |
---|
| 43 | end |
---|
| 44 | end |
---|
| 45 | endmodule |
---|