jchdl - GSL实例 - Mux4(使用Mux)

Posted wjcdx

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jchdl - GSL实例 - Mux4(使用Mux)相关的知识,希望对你有一定的参考价值。

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

 

原理图

?技术分享图片?

 

参考链接

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

 

 

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

?技术分享图片?

 

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

?技术分享图片?

 

 

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

?技术分享图片?

 

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

?技术分享图片?

 

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

?技术分享图片?

 

6. 创建main方法执行验证

?技术分享图片?

 

运行结果为:

?技术分享图片?

 

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

 

7. 生成Verilog

?技术分享图片?

 

执行结果如下:

?技术分享图片?

 

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

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

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

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

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

 

public class Mux4 extends Node {

private Wire i0;

private Wire i1;

private Wire i2;

private Wire i3;

private Wire s1;

private Wire s0;

private Wire out;

 

private Wire o0 = new Wire();

private Wire o1 = new Wire();

 

public Mux4(Wire out, Wire i0, Wire i1, Wire i2, Wire i3, Wire s1, Wire s0) {

in(Wire.array(i0, i1, i2, i3, s1, s0));

out(out);

construct();

}

 

@Override

public void logic() {

i0 = new Wire(in(0));

i1 = new Wire(in(1));

i2 = new Wire(in(2));

i3 = new Wire(in(3));

s1 = new Wire(in(4));

s0 = new Wire(in(5));

out = new Wire(out(0));

 

Mux.inst(o0, i0, i1, s0);

Mux.inst(o1, i2, i3, s0);

Mux.inst(out, o0, o1, s1);

}

 

public static Mux4 inst(Wire out, Wire i0, Wire i1, Wire i2, Wire i3, Wire s1, Wire s0) {

return new Mux4(out, i0, i1, i2, i3, s1, s0);

}

 

public static void main(String[] args) {

Wire i0 = new Wire(Value.V0);

Wire i1 = new Wire(Value.V1);

Wire i2 = new Wire(Value.V0);

Wire i3 = new Wire(Value.V1);

Wire s1 = new Wire(Value.V0);

Wire s0 = new Wire(Value.V0);

Wire out = new Wire();

Mux4 mux4 = Mux4.inst(out, i0, i1, i2, i3, s1, s0);

 

PropagateManager.propagateParallel(i0, i1, i2, i3, s1, s0);

System.out.println("out: " + out.getValue().toString());

 

s1.assign(Value.V0);

s0.assign(Value.V1);

PropagateManager.propagateParallel(s1, s0);

System.out.println("out: " + out.getValue().toString());

 

s1.assign(Value.V1);

s0.assign(Value.V0);

PropagateManager.propagateParallel(s1, s0);

System.out.println("out: " + out.getValue().toString());

 

s1.assign(Value.V1);

s0.assign(Value.V1);

PropagateManager.propagateParallel(s1, s0);

System.out.println("out: " + out.getValue().toString());

 

mux4.toVerilog();

}

}

 

 

 


以上是关于jchdl - GSL实例 - Mux4(使用Mux)的主要内容,如果未能解决你的问题,请参考以下文章

jchdl - GSL实例 - Mux4(使用WireVec简化输入线声明)

jchdl-GSL-实例 - 使用Intellij IDEA创建Mux

jchdl - GSL实例 - Add

jchdl - GSL实例 - Div

jchdl-GSL-实例 - 使用Intellij IDEA创建Mux

jchdl - GSL实例 - Counter