circuits 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/lib/circuits/component/d.rb +80 -0
- data/lib/circuits/version.rb +1 -1
- data/spec/unit/circuits/component/d_spec.rb +114 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NzVmMmEyOWQyYmM4Zjg5ZDNjNzYzNDM1OTQyZTU1ZjhlNmUxMzJmNA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NDI2YzNkYWNjYjQ5NzA0YTAwNTY3NzViM2FlNmZmOTVmNWI3YTBmMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZGU0MDZiMDRlN2NiZjM3MDFkNjA1ZTJkNTI0YTQxODNjMmEyNDAxODIwZTNj
|
10
|
+
YjdiNjViMGRhZGZhNDI1Njg4NzNmNWM4YzM5MzAzYmJlZWQ4ZjQ0YWUxYzBj
|
11
|
+
YTNlNWJkYzViZGUwZGIwNjhmYWFlZWMxOGUyMWFmZDE4MzlhNTI=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OGVkYmYxZDE0YzY0NDExYmZlM2EwNGQ5NzNiMThkNjQ1NzExMTRlZmM4MWI1
|
14
|
+
ZTE0YTdlOGM2NDFlYzRkMzljYjUxOTlmYmVkZTg0YjQ4ZTRmMmFhNzJiM2Iz
|
15
|
+
MzQ3OTFiZmQxY2U0ZGE2YjgyNjA4Y2JkYjRjMzViY2ZjZjFkNWM=
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'circuits/component/base'
|
2
|
+
require 'circuits/component/nand'
|
3
|
+
|
4
|
+
module Circuits
|
5
|
+
module Component
|
6
|
+
# Positive edge triggered flip flop
|
7
|
+
class D < Base
|
8
|
+
def initialize
|
9
|
+
super(port_mappings: { d: { type: :input, number: 0 },
|
10
|
+
clk: { type: :input, number: 1 },
|
11
|
+
q: { type: :output, number: 0 },
|
12
|
+
not_q: { type: :output, number: 1 } })
|
13
|
+
create_sub_components
|
14
|
+
link_sub_components
|
15
|
+
end
|
16
|
+
|
17
|
+
# Computes the outputs based on the inputs and previous state
|
18
|
+
def tick
|
19
|
+
3.times.each do
|
20
|
+
sub_components.each(&:tick)
|
21
|
+
sub_components.each(&:tock)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :and_gate, :sr_nand_clk, :sr_nand_d, :sr_nand_out,
|
28
|
+
:sub_components
|
29
|
+
|
30
|
+
def create_sub_components
|
31
|
+
@and_gate = Circuits::Component::And.new
|
32
|
+
@sr_nand_clk = Circuits::Component::SrNand.new
|
33
|
+
@sr_nand_d = Circuits::Component::SrNand.new
|
34
|
+
@sr_nand_out = Circuits::Component::SrNand.new
|
35
|
+
@sub_components = [@and_gate, @sr_nand_clk, @sr_nand_d, @sr_nand_out]
|
36
|
+
end
|
37
|
+
|
38
|
+
def default_input_count
|
39
|
+
2
|
40
|
+
end
|
41
|
+
|
42
|
+
def default_output_count
|
43
|
+
2
|
44
|
+
end
|
45
|
+
|
46
|
+
def link_and_gate
|
47
|
+
and_gate[:a].set sr_nand_clk[:not_q]
|
48
|
+
and_gate[:b].set self[:clk]
|
49
|
+
end
|
50
|
+
|
51
|
+
def link_outputs
|
52
|
+
self[:q].set sr_nand_out[:q]
|
53
|
+
self[:not_q].set sr_nand_out[:not_q]
|
54
|
+
end
|
55
|
+
|
56
|
+
def link_sr_nand_d
|
57
|
+
sr_nand_d[:not_s].set and_gate[:out]
|
58
|
+
sr_nand_d[:not_r].set self[:d]
|
59
|
+
end
|
60
|
+
|
61
|
+
def link_sr_nand_clk
|
62
|
+
sr_nand_clk[:not_s].set sr_nand_d[:not_q]
|
63
|
+
sr_nand_clk[:not_r].set self[:clk]
|
64
|
+
end
|
65
|
+
|
66
|
+
def link_sr_nand_out
|
67
|
+
sr_nand_out[:not_s].set sr_nand_clk[:not_q]
|
68
|
+
sr_nand_out[:not_r].set sr_nand_d[:q]
|
69
|
+
end
|
70
|
+
|
71
|
+
def link_sub_components
|
72
|
+
link_outputs
|
73
|
+
link_and_gate
|
74
|
+
link_sr_nand_d
|
75
|
+
link_sr_nand_clk
|
76
|
+
link_sr_nand_out
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
data/lib/circuits/version.rb
CHANGED
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'circuits/component/d'
|
3
|
+
|
4
|
+
describe Circuits::Component::D do
|
5
|
+
describe '#tick' do
|
6
|
+
subject { Circuits::Component::D.new }
|
7
|
+
|
8
|
+
context 'has just been set' do
|
9
|
+
before do
|
10
|
+
subject[:clk].set false
|
11
|
+
subject.tick
|
12
|
+
subject.tock
|
13
|
+
subject[:d].set true
|
14
|
+
subject[:clk].set true
|
15
|
+
subject.tick
|
16
|
+
subject.tock
|
17
|
+
subject[:d].set false
|
18
|
+
subject[:clk].set false
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'is set' do
|
22
|
+
expect(subject[:q].get).to eq(true)
|
23
|
+
expect(subject[:not_q].get).to eq(false)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'is stable' do
|
27
|
+
subject.tick
|
28
|
+
subject.tock
|
29
|
+
expect(subject[:q].get).to eq(true)
|
30
|
+
expect(subject[:not_q].get).to eq(false)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'd high has no effect' do
|
34
|
+
subject[:d].set true
|
35
|
+
subject.tick
|
36
|
+
subject.tock
|
37
|
+
expect(subject[:q].get).to eq(true)
|
38
|
+
expect(subject[:not_q].get).to eq(false)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'clock has to be positive edge' do
|
42
|
+
subject[:d].set false
|
43
|
+
subject[:clk].set true
|
44
|
+
subject.tick
|
45
|
+
subject.tock
|
46
|
+
expect(subject[:q].get).to eq(true)
|
47
|
+
expect(subject[:not_q].get).to eq(false)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'can be reset' do
|
51
|
+
subject.tick
|
52
|
+
subject.tock
|
53
|
+
subject[:clk].set true
|
54
|
+
subject.tick
|
55
|
+
subject.tock
|
56
|
+
expect(subject[:q].get).to eq(false)
|
57
|
+
expect(subject[:not_q].get).to eq(true)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'has just been reset' do
|
62
|
+
before do
|
63
|
+
subject[:clk].set false
|
64
|
+
subject.tick
|
65
|
+
subject.tock
|
66
|
+
subject[:d].set false
|
67
|
+
subject[:clk].set true
|
68
|
+
subject.tick
|
69
|
+
subject.tock
|
70
|
+
subject[:clk].set false
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'is reset' do
|
74
|
+
expect(subject[:q].get).to eq(false)
|
75
|
+
expect(subject[:not_q].get).to eq(true)
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'is stable' do
|
79
|
+
subject.tick
|
80
|
+
subject.tock
|
81
|
+
expect(subject[:q].get).to eq(false)
|
82
|
+
expect(subject[:not_q].get).to eq(true)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'd high has no effect' do
|
86
|
+
subject[:d].set true
|
87
|
+
subject.tick
|
88
|
+
subject.tock
|
89
|
+
expect(subject[:q].get).to eq(false)
|
90
|
+
expect(subject[:not_q].get).to eq(true)
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'clock has to be positive edge' do
|
94
|
+
subject[:d].set true
|
95
|
+
subject[:clk].set true
|
96
|
+
subject.tick
|
97
|
+
subject.tock
|
98
|
+
expect(subject[:q].get).to eq(false)
|
99
|
+
expect(subject[:not_q].get).to eq(true)
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'can be set' do
|
103
|
+
subject.tick
|
104
|
+
subject.tock
|
105
|
+
subject[:d].set true
|
106
|
+
subject[:clk].set true
|
107
|
+
subject.tick
|
108
|
+
subject.tock
|
109
|
+
expect(subject[:q].get).to eq(true)
|
110
|
+
expect(subject[:not_q].get).to eq(false)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: circuits
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henry Muru Paenga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/circuits.rb
|
127
127
|
- lib/circuits/component/and.rb
|
128
128
|
- lib/circuits/component/base.rb
|
129
|
+
- lib/circuits/component/d.rb
|
129
130
|
- lib/circuits/component/nand.rb
|
130
131
|
- lib/circuits/component/nor.rb
|
131
132
|
- lib/circuits/component/not.rb
|
@@ -140,6 +141,7 @@ files:
|
|
140
141
|
- spec/spec_helper.rb
|
141
142
|
- spec/unit/circuits/component/and_spec.rb
|
142
143
|
- spec/unit/circuits/component/base_spec.rb
|
144
|
+
- spec/unit/circuits/component/d_spec.rb
|
143
145
|
- spec/unit/circuits/component/nand_spec.rb
|
144
146
|
- spec/unit/circuits/component/nor_spec.rb
|
145
147
|
- spec/unit/circuits/component/not_spec.rb
|
@@ -178,6 +180,7 @@ test_files:
|
|
178
180
|
- spec/spec_helper.rb
|
179
181
|
- spec/unit/circuits/component/and_spec.rb
|
180
182
|
- spec/unit/circuits/component/base_spec.rb
|
183
|
+
- spec/unit/circuits/component/d_spec.rb
|
181
184
|
- spec/unit/circuits/component/nand_spec.rb
|
182
185
|
- spec/unit/circuits/component/nor_spec.rb
|
183
186
|
- spec/unit/circuits/component/not_spec.rb
|