jchdl - GSL实例 - Mux4(使用WireVec简化输入线声明)
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()方法
2. 根据逻辑原理图,添加输入输出线
需要注意的是,这里使用了WireVec,而不是Wire来声明输入线,以便统一处理一排线。
3. 在构造方法中搜集输入输出线并调用construct()方法
这里一次性的把dat, sel中的所有线都加到输入线中。
4. 在logic()方法中创建子节点并连线
创建WireVec时可以直接与input/output相连;使用时从WireVec中取出某一条线使用即可。
这里更通用的做法,是记录输入WireVec dat的位数,这样在logic()取的时候,就不需要把数字写死了:
5. 创建inst静态方法方便后续使用
6. 创建main方法执行验证
运行结果为:
四种组合逐个选择i0~i3中的值。
7. 生成Verilog
执行结果如下:
package vec;
import org.jchdl.model.gsl.core.datatype.helper.WireVec;
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 int nDatBits = 0;
private WireVec dat;
private WireVec sel;
private Wire out;
private Wire o0 = new Wire();
private Wire o1 = new Wire();
public Mux4(Wire out, WireVec dat, WireVec sel) {
nDatBits = dat.nBits();
in(dat.wires());
in(sel.wires());
out(out);
construct();
}
@Override
public void logic() {
dat = new WireVec(inputs(0, nDatBits));
sel = new WireVec(inputs(nDatBits));
out = new Wire(out(0));
Mux.inst(o0, dat.wire(0), dat.wire(1), sel.wire(0));
Mux.inst(o1, dat.wire(2), dat.wire(3), sel.wire(0));
Mux.inst(out, o0, o1, sel.wire(1));
}
public static Mux4 inst(Wire out, WireVec dat, WireVec sel) {
return new Mux4(out, dat, sel);
}
public static void main(String[] args) {
WireVec dat = new WireVec(4);
WireVec sel = new WireVec(2);
Wire out = new Wire();
Mux4 mux4 = Mux4.inst(out, dat, sel);
dat.assign(new Value[]{Value.V0, Value.V1, Value.V0, Value.V1});
sel.assign(new Value[]{Value.V0, Value.V0});
PropagateManager.propagateParallel(dat, sel);
System.out.println("out: " + out.getValue().toString());
sel.assign(new Value[]{Value.V1, Value.V0});
PropagateManager.propagateParallel(sel);
System.out.println("out: " + out.getValue().toString());
sel.assign(new Value[]{Value.V0, Value.V1});
PropagateManager.propagateParallel(sel);
System.out.println("out: " + out.getValue().toString());
sel.assign(new Value[]{Value.V1, Value.V1});
PropagateManager.propagateParallel(sel);
System.out.println("out: " + out.getValue().toString());
mux4.toVerilog();
}
}
jchdl - GSL实例 - Mux4(使用WireVec简化输入线声明)的更多相关文章
- jchdl - GSL实例 - Mux4
https://mp.weixin.qq.com/s/hh0eExVFC6cxzpvNI1cA9A 使用门实现四选一选择器. 原理图 参考链接 https://github.com/wjcdx/ ...
- jchdl - GSL实例 - Mux4(使用Mux)
https://mp.weixin.qq.com/s/GrYJ4KXEFRoLLmLnAGoMSA 原理图 参考链接 https://github.com/wjcdx/jchdl/blob/ma ...
- jchdl - GSL实例 - Concat
https://mp.weixin.qq.com/s/oJY6Xj9_oM1gSmvH_dHkJg Concat节点把多根输入线线组合成一排线输出. 参考链接 https://github.c ...
- jchdl - GSL实例 - Add
https://mp.weixin.qq.com/s/6xcYYdYZTBPTf25xFluzBQ 使用FullAdder级联实现加法器 参考链接: https://github.com/wj ...
- jchdl - GSL实例 - Assign
https://mp.weixin.qq.com/s/MtHR3iolPd5VQq6AUE-JPg Assign是一个节点,把输入线直接赋值给输出线.在转换成Verilog时,这种类型的节点会直接 ...
- jchdl - GSL实例 - LogicalLeft
https://mp.weixin.qq.com/s/WNm4bLWzZ0oWHWa7HQ6Y6w 逻辑左移,继承自Shifter类.只需要实现shift方法即可. 参考链接 https:// ...
- jchdl - GSL实例 - Shifter
https://mp.weixin.qq.com/s/ngQji-xi4FCCbL_2ihUi_A Shifter是移位节点的父类,定义了输入输出线,但是没有定义具体的移位方式,这个留给子类去实现 ...
- jchdl - GSL实例 - Sub(二的补码实现)
https://mp.weixin.qq.com/s/10fgjqPt2pRvIJzjDGYgBg 概念辨析 <IC-二进制, 自然数, 有符号数>:https://mp.weix ...
- jchdl - GSL实例:HalfAdder
https://mp.weixin.qq.com/s/Y97bIro7UlPPFCoPlzgmOQ 半加器电路是指对两个输入相加,输出一个结果位和,没有进位输入的电路. 是实现两个一位二进制数的加法运 ...
随机推荐
- java读源码 之 list源码分析(LinkedList)
文章目录 LinkedList: 继承关系分析: 字段分析: 构造函数分析: 方法分析: LinkedList: 继承关系分析: public class LinkedList<E> ex ...
- gulp基本使用
一.gulp是什么 gulp强调的是前端开发的工作流程,我们可以通过定义task事件定义事件的执行顺序,gulp去执行这些事件,构建整个前端开发的工作流程 gulp常见定义事件,例如: 变更静态资源 ...
- 王颖奇 201771010129《面向对象程序设计(java)》第六周学习总结
实验六 继承定义与使用 实验时间 2018-9-28 1.目的与要求 理论部分: 继承(inheritance): 继承的特点:具有结构层次:子类继承了父类的域和方法. 主要内容: (1)类.子类.超 ...
- 变分深度嵌入(Variational Deep Embedding, VaDE)
变分深度嵌入(Variational Deep Embedding, VaDE) 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 这篇博文主要是对论文“ ...
- CF#214 C. Dima and Salad 01背包变形
C. Dima and Salad 题意 有n种水果,第i个水果有一个美味度ai和能量值bi,现在要选择部分水果做沙拉,假如此时选择了m个水果,要保证\(\frac{\sum_{i=1}^ma_i}{ ...
- [csu/coj 1080]划分树求区间前k大数和
题意:从某个区间内最多选择k个数,使得和最大 思路:首先题目给定的数有负数,如果区间前k大出现负数,那么负数不选和更大,于是对于所有最优选择,负数不会出现,所以用0取代负数,问题便转化为区间的前k大数 ...
- Struts2-Tiles 2.5.2 升级指南和通配符拓展
最近工程从Struts2.3.18升级Struts2.5.2导致相关联的插件都需要升级到相同版本,其中tiles的变化最大. 1.web.xml上 listener org.apache.struts ...
- jquery监听input
$(function(){ //输入框正在输入时 $("#ipt").on('input',function(){ if(!($('#ipt').val()=='')){ $(&q ...
- 初识Page Object
PageObject是UI自动化测试项目开发实践的最佳设计模式之一,它的主要特点体现在对界面交互细节的封装上,使测试用例更加专注于业务的操作,从而提高测试用例的可维护性. 1.认识Page Objec ...
- DOM的使用
1. 修改: 3样: 1. 内容: 3个属性: 1. 获取或修改原始HTML片段: 元素.innerHTML 2. 获取或修改纯文本内容: 元素.textContent vs innerHTML 1. ...