circuits 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/circuits/component/d.rb +7 -1
- data/lib/circuits/component/sr_nand.rb +18 -6
- data/lib/circuits/component/sr_nor.rb +17 -5
- data/lib/circuits/version.rb +1 -1
- data/spec/unit/circuits/component/d_spec.rb +14 -0
- data/spec/unit/circuits/component/sr_nand_spec.rb +14 -0
- data/spec/unit/circuits/component/sr_nor_spec.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGUwZTZhZWY5NmMwMGM2MmEwMDJmNWU3YTgzZjAwMjFjOWRlODA2MA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MDNjMDhjODE2YjE5NWViNmMxMGE1OWQzNDlmZTk0MGQ5NWZlNjNhZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MjhiZWFiYzE1NGY0MGY1NjgxNjVlNWFkNjJlNjY0NzA1ZTgwYTFjZmU0Y2I2
|
10
|
+
OTJjNmI2MTAxYzE4MmMwNjJmMDExZmEzMjg3ZTU3YTM2NDg2MTA5OTRiMmUx
|
11
|
+
OGM3MDYwMTVmOTgwNjlkODI5ZTFlNDc5MDdlN2UyNWE5MTMwY2U=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YzBiODA1NWYyY2U4OGY0MTA4MTM5Y2MxZGZkYzk3YTE3N2M1ZTFlNzExM2Mx
|
14
|
+
YjY4Mjk4MTZjNWQxNzVmZjUyMDNiZTc3M2Y3NzRjZDZlY2ZhZDQ2NzZiYjBk
|
15
|
+
NTZmZjE1Y2YzOTY0MjU3Y2ZhOTllOWI5ODUwM2YwYTAwOGQ2MGU=
|
data/lib/circuits/component/d.rb
CHANGED
@@ -3,7 +3,7 @@ require 'circuits/component/nand'
|
|
3
3
|
|
4
4
|
module Circuits
|
5
5
|
module Component
|
6
|
-
# Positive edge triggered flip flop
|
6
|
+
# Positive edge triggered D-type flip flop
|
7
7
|
class D < Base
|
8
8
|
def initialize
|
9
9
|
super(port_mappings: { d: { type: :input, number: 0 },
|
@@ -12,6 +12,7 @@ module Circuits
|
|
12
12
|
not_q: { type: :output, number: 1 } })
|
13
13
|
create_sub_components
|
14
14
|
link_sub_components
|
15
|
+
reset
|
15
16
|
end
|
16
17
|
|
17
18
|
# Computes the outputs based on the inputs and previous state
|
@@ -75,6 +76,11 @@ module Circuits
|
|
75
76
|
link_sr_nand_clk
|
76
77
|
link_sr_nand_out
|
77
78
|
end
|
79
|
+
|
80
|
+
def reset
|
81
|
+
tick
|
82
|
+
tock
|
83
|
+
end
|
78
84
|
end
|
79
85
|
end
|
80
86
|
end
|
@@ -11,9 +11,8 @@ module Circuits
|
|
11
11
|
q: { type: :output, number: 0 },
|
12
12
|
not_q: { type: :output, number: 1 } })
|
13
13
|
create_sub_components
|
14
|
-
link_inputs
|
15
|
-
link_outputs
|
16
14
|
link_sub_components
|
15
|
+
reset
|
17
16
|
end
|
18
17
|
|
19
18
|
# Computes the outputs based on the inputs and previous state
|
@@ -42,9 +41,14 @@ module Circuits
|
|
42
41
|
2
|
43
42
|
end
|
44
43
|
|
45
|
-
def
|
46
|
-
nand_s[:a].set self[:not_s]
|
44
|
+
def link_nand_r
|
47
45
|
nand_r[:a].set self[:not_r]
|
46
|
+
nand_r[:b].set nand_s[:out]
|
47
|
+
end
|
48
|
+
|
49
|
+
def link_nand_s
|
50
|
+
nand_s[:a].set self[:not_s]
|
51
|
+
nand_s[:b].set nand_r[:out]
|
48
52
|
end
|
49
53
|
|
50
54
|
def link_outputs
|
@@ -53,8 +57,16 @@ module Circuits
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def link_sub_components
|
56
|
-
|
57
|
-
|
60
|
+
link_nand_s
|
61
|
+
link_nand_r
|
62
|
+
link_outputs
|
63
|
+
end
|
64
|
+
|
65
|
+
def reset
|
66
|
+
self[:not_s].set true
|
67
|
+
tick
|
68
|
+
tock
|
69
|
+
self[:not_r].set true
|
58
70
|
end
|
59
71
|
end
|
60
72
|
end
|
@@ -11,9 +11,8 @@ module Circuits
|
|
11
11
|
q: { type: :output, number: 0 },
|
12
12
|
not_q: { type: :output, number: 1 } })
|
13
13
|
create_sub_components
|
14
|
-
link_inputs
|
15
|
-
link_outputs
|
16
14
|
link_sub_components
|
15
|
+
reset
|
17
16
|
end
|
18
17
|
|
19
18
|
# Computes the outputs based on the inputs and previous state
|
@@ -42,9 +41,14 @@ module Circuits
|
|
42
41
|
2
|
43
42
|
end
|
44
43
|
|
45
|
-
def
|
44
|
+
def link_nor_r
|
46
45
|
nor_r[:a].set self[:r]
|
46
|
+
nor_r[:b].set nor_s[:out]
|
47
|
+
end
|
48
|
+
|
49
|
+
def link_nor_s
|
47
50
|
nor_s[:a].set self[:s]
|
51
|
+
nor_s[:b].set nor_r[:out]
|
48
52
|
end
|
49
53
|
|
50
54
|
def link_outputs
|
@@ -53,8 +57,16 @@ module Circuits
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def link_sub_components
|
56
|
-
|
57
|
-
|
60
|
+
link_nor_s
|
61
|
+
link_nor_r
|
62
|
+
link_outputs
|
63
|
+
end
|
64
|
+
|
65
|
+
def reset
|
66
|
+
self[:r].set true
|
67
|
+
tick
|
68
|
+
tock
|
69
|
+
self[:r].set false
|
58
70
|
end
|
59
71
|
end
|
60
72
|
end
|
data/lib/circuits/version.rb
CHANGED
@@ -5,6 +5,20 @@ describe Circuits::Component::D do
|
|
5
5
|
describe '#tick' do
|
6
6
|
subject { Circuits::Component::D.new }
|
7
7
|
|
8
|
+
context 'it has just been initialized' do
|
9
|
+
it 'is unset' do
|
10
|
+
expect(subject[:q].get).to eq(false)
|
11
|
+
expect(subject[:not_q].get).to eq(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is stable' do
|
15
|
+
subject.tick
|
16
|
+
subject.tock
|
17
|
+
expect(subject[:q].get).to eq(false)
|
18
|
+
expect(subject[:not_q].get).to eq(true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
8
22
|
context 'has just been set' do
|
9
23
|
before do
|
10
24
|
subject[:clk].set false
|
@@ -5,6 +5,20 @@ describe Circuits::Component::SrNand do
|
|
5
5
|
describe '#tick' do
|
6
6
|
subject { Circuits::Component::SrNand.new }
|
7
7
|
|
8
|
+
context 'it has just been initialized' do
|
9
|
+
it 'is unset' do
|
10
|
+
expect(subject[:q].get).to eq(false)
|
11
|
+
expect(subject[:not_q].get).to eq(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is stable' do
|
15
|
+
subject.tick
|
16
|
+
subject.tock
|
17
|
+
expect(subject[:q].get).to eq(false)
|
18
|
+
expect(subject[:not_q].get).to eq(true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
8
22
|
context 'is set' do
|
9
23
|
before do
|
10
24
|
subject[:not_s].set false
|
@@ -5,6 +5,20 @@ describe Circuits::Component::SrNor do
|
|
5
5
|
describe '#tick' do
|
6
6
|
subject { Circuits::Component::SrNor.new }
|
7
7
|
|
8
|
+
context 'it has just been initialized' do
|
9
|
+
it 'is unset' do
|
10
|
+
expect(subject[:q].get).to eq(false)
|
11
|
+
expect(subject[:not_q].get).to eq(true)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'is stable' do
|
15
|
+
subject.tick
|
16
|
+
subject.tock
|
17
|
+
expect(subject[:q].get).to eq(false)
|
18
|
+
expect(subject[:not_q].get).to eq(true)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
8
22
|
context 'is set' do
|
9
23
|
before do
|
10
24
|
subject[:r].set false
|