https://mp.weixin.qq.com/s/yJx_dV6ScUStJtPWVuD38w

 

原理图

 

参考链接

https://github.com/wjcdx/jchdl/blob/master/src/org/jchdl/model/gsl/example/Mux4.java

 

 

1.创建Mux4.java, 并生成构造方法和logic()方法

 

根据逻辑原理图,添加输入输出线

需要注意的是,这里使用了WireVec,而不是Wire来声明输入线,以便统一处理一排线。

 

 

3. 在构造方法中搜集输入输出线并调用construct()方法

这里一次性的把dat, sel中的所有线都加到输入线中。

 

4. 在logic()方法中创建子节点并连线

创建WireVec时可以直接与input/output相连;使用时从WireVec中取出某一条线使用即可。

 

这里更通用的做法,是记录输入WireVec dat的位数,这样在logic()取的时候,就不需要把数字写死了:

 

 

5. 创建inst静态方法方便后续使用

 

6. 创建main方法执行验证

 

运行结果为:

 

四种组合逐个选择i0~i3中的值。

 

7. 生成Verilog

 

执行结果如下:

 

vec;

 

org.jchdl.model.gsl.core.datatype.helper.WireVec;

org.jchdl.model.gsl.core.datatype.net.Wire;

org.jchdl.model.gsl.core.meta.Node;

org.jchdl.model.gsl.core.meta.PropagateManager;

org.jchdl.model.gsl.core.value.Value;

org.jchdl.model.gsl.operator.conditional.Mux;

 

Node {

;

;

;

;

 

Wire();

Wire();

 

Mux4(Wire out, WireVec dat, WireVec sel) {

= dat.nBits();

in(dat.wires());

in(sel.wires());

out(out);

construct();

}

 

@Override

logic() {

));

));

));

 

));

));

));

}

 

Mux4 inst(Wire out, WireVec dat, WireVec sel) {

Mux4(out, dat, sel);

}

 

main(String[] args) {

);

);

Wire();

(out, dat, sel);

 

});

});

(dat, sel);

+ out.getValue().toString());

 

});

(sel);

+ out.getValue().toString());

 

});

(sel);

+ out.getValue().toString());

 

});

(sel);

+ out.getValue().toString());

 

mux4.toVerilog();

}

}

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案