Chisel3 - Tutorial - VendingMachine
https://mp.weixin.qq.com/s/tDpUe9yhwC-2c1VqisFzMw
import chisel3._
import chisel3.util._ // Problem:
//
// Implement a vending machine using 'when' states.
// 'nickel' is a 5 cent coin
// 'dime' is 10 cent coin
// 'sOk' is reached when there are coins totalling 20 cents or more in the machine.
// The vending machine should return to the 'sIdle' state from the 'sOk' state.
//
class VendingMachine extends Module {
val io = IO(new Bundle {
val nickel = Input(Bool())
val dime = Input(Bool())
val valid = Output(Bool())
})
val sIdle :: s5 :: s10 :: s15 :: sOk :: Nil = Enum(5)
val state = RegInit(sIdle)
when (state === sIdle) {
when (io.nickel) { state := s5 }
when (io.dime) { state := s10 }
}
when (state === s5) {
when (io.nickel) { state := s10 }
when (io.dime) { state := s15 }
}
when (state === s10) {
when (io.nickel) { state := s15 }
when (io.dime) { state := sOk }
}
when (state === s15) {
when (io.nickel) { state := sOk }
when (io.dime) { state := sOk }
}
when (state === sOk) {
state := sIdle
}
io.valid := (state === sOk)
} object VendingMachineMain {
def main(args: Array[String]): Unit = {
chisel3.Driver.execute(Array("--target-dir", "generated/VendingMachine"), () => new VendingMachine)
}
}
Chisel3 - Tutorial - VendingMachine的更多相关文章
- Chisel3 - Tutorial - VendingMachineSwitch
https://mp.weixin.qq.com/s/5lcMkenM2zTy-pYOXfRjyA 演示如何使用switch/is来实现状态机. 参考链接: https://github.co ...
- Chisel3 - Tutorial - Tbl
https://mp.weixin.qq.com/s/e8vJ8claauBtiuedxYYaJw 实现可以动态索引的表. 参考链接: https://github.com/ucb-bar/c ...
- Chisel3 - Tutorial - Stack
https://mp.weixin.qq.com/s/-AVJD1IfvNIJhmZM40DemA 实现后入先出(last in, first out)的栈. 参考链接: https://gi ...
- Chisel3 - Tutorial - Functionality
https://mp.weixin.qq.com/s/3hDzpJiANdwp07hO03psyA 演示使用函数进行代码复用的方法. 参考链接: https://github.com/ucb- ...
- Chisel3 - Tutorial - Parity
https://mp.weixin.qq.com/s/OtiQnE52PwdCpvmzJ6VFnA 奇偶发生器.统计输入中1的个数,如果为偶数则输出0,奇数则输出1. 参考链接: https: ...
- Chisel3 - Tutorial - ByteSelector
https://mp.weixin.qq.com/s/RQg2ca1rwfVHx_QG-IOV-w 字节选择器. 参考链接: https://github.com/ucb-bar/chisel ...
- Chisel3 - Tutorial - ShiftRegister
https://mp.weixin.qq.com/s/LKiXUgSnt3DzgFLa9zLCmQ 简单的寄存器在时钟的驱动下,逐个往下传值. 参考链接: https://github.com ...
- Chisel3 - Tutorial - Adder
https://mp.weixin.qq.com/s/SEcVjGRL1YloGlEPSoHr3A 位数为参数的加法器.通过FullAdder级联实现. 参考链接: https://githu ...
- Chisel3 - Tutorial - Adder4
https://mp.weixin.qq.com/s/X5EStKor2DU0-vS_wIO-fg 四位加法器.通过FullAdder级联实现. 参考链接: https://github.co ...
随机推荐
- C#并发编程之初识并行编程
写在前面 之前微信公众号里有一位叫sara的朋友建议我写一下Parallel的相关内容,因为手中商城的重构工作量较大,一时之间无法抽出时间.近日,这套系统已有阶段性成果,所以准备写一下Parallel ...
- 前端【JS】,深入理解原型和原型链
对于原型和原型链,相信有很多伙伴都说的上来一些,但有具体讲不清楚.但面试的时候又经常会碰到面试官的死亡的追问,我们慢慢来梳理这方面的知识! 要理解原型和原型链的关系,我们首先需要了解几个概念:1.什么 ...
- GroupJoin()各参数的意义及用法
EF Core中GroupJoin的注释比较复杂: public static IEnumerable<TResult> GroupJoin<TOuter, TInner, TKey ...
- Coursera课程笔记----计算导论与C语言基础----Week 11
C程序中的字符串(Week 11) 字符数组 所有的字符串,都是以\0结尾的 只能在数组定义并初始化的时候:char c[6] = "China"; 不能用赋值语句将一个字符串常量 ...
- LRU 的C# 实现
首先 先写点儿感悟吧: 本来计划是 晚上回家写的 后来发现还是没坚持的了 上午花了一个多小时 做了一下这个题目 应该还有提高的空间 的,这个题目是在力扣里面看到的 为什么看到这个题目 是因为 ...
- numpy数组的分割与合并
合并 np.newaxis import numpy as np a=np.array([1,2,3])[:,np.newaxis]#变成列向量 b=np.array([4,5,6])[:,np.ne ...
- python是如何进行参数传递的?
在分析python的参数传递是如何进行的之前,我们需要先来了解一下,python变量和赋值的基本原理,这样有助于我们更好的理解参数传递. python变量以及赋值 数值 从几行代码开始 In [1]: ...
- 【SPOJ – SUBST1】New Distinct Substrings 后缀数组
New Distinct Substrings 题意 给出T个字符串,问每个字符串有多少个不同的子串. 思路 字符串所有子串,可以看做由所有后缀的前缀组成. 按照后缀排序,遍历后缀,每次新增的前缀就是 ...
- jquery遍历数组、对象
1,for循环: var arr = new Array(13.5,3,4,5,6); for(var i=0;i<arr.length;i++){ arr[i] = arr[i]/2.0; } ...
- 《学习笔记》Layui-WPF窗体美化
一睹为快: 1.创建自定义控件,并取名为LayuiWPFStyle 2.在当前目录中创建Fonts和WindowStyle文件加用来存放字体文件和自定义窗体,字体用fontawesome字体当然你们可 ...