https://github.com/jc-ll/rtl
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/jc-ll/rtl
- Owner: JC-LL
- Created: 2021-02-13T09:58:32.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-16T20:52:53.000Z (over 4 years ago)
- Last Synced: 2025-03-09T13:46:57.367Z (3 months ago)
- Language: Ruby
- Size: 41 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# RTL Circuit
## What is it ?
**rtl_circuit** is a simple Ruby gem that helps me manipulate simple digital circuits. It is used essentially as a _library_ and as such, used by other tools of my own (like my experimental [Synchrony DSL](https://github.com/JC-LL/synchrony))### features :
- basic library components (logic gates, DFF, mux,...)
- port-based interconnect
- hierarchical composition (building a circuit based on existing )
- json serialization
- viewing : graphviz
- ambryonic SVG place & route## How to use
Here the programmatic construction of a Half Adder, followed by a Full-adder.
This can be seen as a 'hello world' of digital circuits.```(ruby)
require 'rtl' # note that the library is named 'rtl' while the gem is _rtl_circuit_include RTL # module loaded
ha=Circuit.new("ha")
ha.add a =Port.new(:in,"a")
ha.add b =Port.new(:in,"b")
ha.add s =Port.new(:out,"s")
ha.add co=Port.new(:out,"co")
ha.add and_=And.new
ha.add xor_=Xor.newa.connect and_.port("i1")
b.connect and_.port("i2")
a.connect xor_.port("i1")
b.connect xor_.port("i2")
xor_.port("f").connect s
and_.port("f").connect coprinter=Printer.new
printer.print ha
```.
Now, let's try a Full-adder (made of two Half-adders).
```
fa=Circuit.new("fa")
fa.add a =Port.new(:in,"a")
fa.add b =Port.new(:in,"b")
fa.add ci=Port.new(:in,"ci")
fa.add s= Port.new(:out,"s")
fa.add co=Port.new(:out,"co")fa.add ha_1=ha.new_instance
fa.add ha_2=ha.new_instancefa.add or_=Or.new
a.connect ha_2.port('a')
b.connect ha_1.port('a')
ci.connect ha_1.port('b')
ha_1.port('s').connect ha_2.port('b')
ha_2.port('co').connect or_.port('i1')
ha_1.port('co').connect or_.port('i2')
or_.port('f').connect fa.port('co')
ha_2.port('s').connect fa.port('s')printer.print fa
```
.
## How to install ?```
gem install rtl_circuit
```## Contact
email : jean-christophe.le_lann at ensta-bretagne dot fr.