Class: Logic
- Inherits:
-
SignalElm
show all
- Includes:
- BaseModule, ClassHDL::AssignDefOpertor, ClassHDL::RandomNum
- Defined in:
- lib/tdl/elements/logic.rb,
lib/tdl/elements/logic.rb,
lib/tdl/Logic/logic_edge.rb,
lib/tdl/Logic/logic_main.rb,
lib/tdl/Logic/logic_latency.rb,
lib/tdl/class_hdl/hdl_random.rb,
lib/tdl/bfm/logic_initial_block.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb
Overview
Constant Summary
collapse
- INPUT =
"INPUT"
- OUTPUT =
"OUTPUT"
- INOUT =
"INOUT"
- Synth_REP =
parse text for autogen method and constant ###
/\(\*\s+logic\s*=\s*"true"\s+\*\)/i
- OP_SYMBOLS =
%w{+ - * / % > < >= <= << | &}
Instance Attribute Summary collapse
Attributes inherited from BaseElm
#belong_to_module
Class Method Summary
collapse
Instance Method Summary
collapse
-
#[](a, b = nil) ⇒ Object
-
#[]=(a, b = nil, c) ⇒ Object
-
#active ⇒ Object
-
#broaden_and_cross_clk(phase: "POSITIVE", len: 4, lat: 2, wclk: nil, rreset: "1'b1".to_nq, rclk: nil, wreset: "1'b1".to_nq, name: nil) ⇒ Object
-
#copy(name: @name.to_s, dsize: @dsize, port: @port, default: @default, msb_high: @msb_high, dimension: @dimension, type: @type, belong_to_module: @belong_to_module) ⇒ Object
-
#cross_clock(clock: nil, name: false) ⇒ Object
-
#destruct_to(*args) ⇒ Object
-
#exp_element(b) ⇒ Object
def signal_proc(a) if a.is_a? Proc a.call else a.to_s end end.
-
#falling(cnt: 1, clock: nil, reset: nil) ⇒ Object
-
#force_nege_index(bool = true) ⇒ Object
-
#init_assign(value) ⇒ Object
-
#init_exec(str) ⇒ Object
-
#Initial {|_self| ... } ⇒ Object
-
#initialize(name: "tmp", dsize: 1, port: false, default: nil, msb_high: true, dimension: [], type: "logic") ⇒ Logic
constructor
-
#inst ⇒ Object
-
#inst_port ⇒ Object
-
#latency(count: 1, clock: nil, reset: nil) ⇒ Object
-
#merge_from(*args) ⇒ Object
def self.clear @@id = 1 @@inst_stack = [] @@ports = [] @@nc = self.new BaseElm.recfg_nc(@@nc) end.
-
#port_length ⇒ Object
-
#raising(cnt: 1, clock: nil, reset: nil) ⇒ Object
-
#repeat(num = 0, &block) ⇒ Object
-
#signal(h: nil, l: 0, square: true) ⇒ Object
-
#to_s ⇒ Object
curr_assign_block, curr_assign_block=, curr_assign_block_stack, curr_opertor_stack, included, init_op_methods, use_new_yield_opertors, use_old_cond_opertors, with_new_assign_block, with_new_opertor, with_normal_opertor, with_rollback_opertors
#precent_false, #precent_true
Methods included from BaseModule
#length
Methods inherited from SignalElm
inherited, subclass
Methods inherited from BaseElm
#matrix, #name_copy, #path_refs, recfg_nc, #s
#create_tp, #root_ref
Constructor Details
#initialize(name: "tmp", dsize: 1, port: false, default: nil, msb_high: true, dimension: [], type: "logic") ⇒ Logic
Returns a new instance of Logic.
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/tdl/elements/logic.rb', line 24
def initialize(name:"tmp",dsize:1,port: false,default: nil,msb_high: true,dimension: [],type: "logic")
@name = name
@dsize = dsize
@port = port
@default = default
@dimension = dimension
@type = type
name_legal?(name)
if block_given?
yield
end
end
|
Instance Attribute Details
#clock ⇒ Object
@@logic_expression = [] @@logic_expression_def = [] @@logic_expression_record = []
@@condition_expression = []
14
15
16
|
# File 'lib/tdl/Logic/logic_main.rb', line 14
def clock
@clock
end
|
#dimension ⇒ Object
Returns the value of attribute dimension.
23
24
25
|
# File 'lib/tdl/elements/logic.rb', line 23
def dimension
@dimension
end
|
#dsize ⇒ Object
22
23
24
|
# File 'lib/tdl/elements/logic.rb', line 22
def dsize
@dsize
end
|
#ghost ⇒ Object
22
23
24
|
# File 'lib/tdl/elements/logic.rb', line 22
def ghost
@ghost
end
|
#id ⇒ Object
22
23
24
|
# File 'lib/tdl/elements/logic.rb', line 22
def id
@id
end
|
#name ⇒ Object
22
23
24
|
# File 'lib/tdl/elements/logic.rb', line 22
def name
@name
end
|
#port ⇒ Object
Returns the value of attribute port.
23
24
25
|
# File 'lib/tdl/elements/logic.rb', line 23
def port
@port
end
|
#reset ⇒ Object
@@logic_expression = [] @@logic_expression_def = [] @@logic_expression_record = []
@@condition_expression = []
14
15
16
|
# File 'lib/tdl/Logic/logic_main.rb', line 14
def reset
@reset
end
|
#type ⇒ Object
22
23
24
|
# File 'lib/tdl/elements/logic.rb', line 22
def type
@type
end
|
Class Method Details
.exp_element(b) ⇒ Object
165
166
167
168
169
170
171
|
# File 'lib/tdl/Logic/logic_main.rb', line 165
def self.exp_element(b)
if b.is_a? Proc
b.call
else
b.to_s
end
end
|
.parse_ports(port_str) ⇒ Object
308
309
310
311
312
|
# File 'lib/tdl/elements/logic.rb', line 308
def self.parse_ports(port_str)
rh = super.parse_ports(port_str)
rh[:type] = Logic
return rh
end
|
Instance Method Details
#[]=(a, b = nil, c) ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/tdl/elements/logic.rb', line 110
def []=(a,b=nil,c)
if a.is_a? ClassHDL::OpertorChain
a.slaver = true
end
if b.is_a? ClassHDL::OpertorChain
b.slaver = true
end
if c.is_a? Logic
cstr = c.signal
elsif c.is_a? String
cstr = c
else
""
end
lbd = "assign #{self.[](a,b)} = #{cstr};"
belong_to_module.Logic_draw << lbd
return lbd
end
|
#active ⇒ Object
72
73
74
|
# File 'lib/tdl/elements/logic.rb', line 72
def active
"low"
end
|
#broaden_and_cross_clk(phase: "POSITIVE", len: 4, lat: 2, wclk: nil, rreset: "1'b1".to_nq, rclk: nil, wreset: "1'b1".to_nq, name: nil) ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/tdl/Logic/logic_latency.rb', line 80
def broaden_and_cross_clk(phase: "POSITIVE",len:4,lat:2,wclk: nil,rreset: "1'b1".to_nq,rclk: nil,wreset: "1'b1".to_nq,name: nil)
if wclk.nil? || rclk.nil?
raise TdlError.new("\n #{self.to_s} BROADEN_AND_CROSS_CLK <clock = nil> \n")
end
new_l = belong_to_module.Def().logic(name:name || "broaden_and_cross_clk_#{globle_random_name_flag()}",dsize:1)
large_name_len(phase,len,wclk,wreset,rclk,rreset)
body =
"
broaden_and_cross_clk #(
.PHASE (#{align_signal(phase)}), //POSITIVE NEGATIVE
.LEN (#{align_signal(len)}),
.LAT (#{align_signal(lat)})
)#{new_l.signal}_inst_#{globle_random_name_flag()}(
/* input */ .rclk (#{align_signal(rclk,q_mark=false)}),
/* input */ .rd_rst_n (#{align_signal(rreset,q_mark=false)}),
/* input */ .wclk (#{align_signal(wclk,q_mark=false)}),
/* input */ .wr_rst_n (#{align_signal(wreset,q_mark=false)}),
/* input */ .d (#{align_signal(self,q_mark=false)}),
/* output */ .q (#{align_signal(new_l,q_mark=false)})
);
"
belong_to_module.Logic_draw << page(tag:"BROADEN_AND_CROSS_CLK",body:body)
return new_l
end
|
#copy(name: @name.to_s, dsize: @dsize, port: @port, default: @default, msb_high: @msb_high, dimension: @dimension, type: @type, belong_to_module: @belong_to_module) ⇒ Object
67
68
69
70
|
# File 'lib/tdl/elements/logic.rb', line 67
def copy(name:@name.to_s,dsize:@dsize,port:@port,default:@default,msb_high:@msb_high,dimension:@dimension,type:@type,belong_to_module:@belong_to_module)
append_name = name_copy(name)
belong_to_module.Def.logic(name:append_name,dsize:dsize,port:port,default:default,msb_high:msb_high,dimension:dimension,type:type)
end
|
#cross_clock(clock: nil, name: false) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/tdl/Logic/logic_latency.rb', line 48
def cross_clock(clock:nil,name: false)
raise TdlError.new("\n #{signal} CROSS CLOCK <clock = nil> \n") unless clock
new_l = nil
ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
unless name
new_l = belong_to_module.Def.logic(name:"#{signal(square:false)}_cc",dsize:self.dsize)
else
new_l = belong_to_module.Def.logic(name: name.to_s ,dsize:self.dsize)
end
str = %Q{
//----->> #{signal} cross clock <<------------------
cross_clk_sync #(
.LAT (2 ),
.DSIZE (#{dsize})
)#{signal(square:false)}_cross_clk_#{name ? name.to_s : '' }inst(
/* input */ .clk (#{align_signal(clock)}),
/* input */ .rst_n (#{align_signal("1'b1")}),
/* input [DSIZE-1:0] */ .d (#{align_signal(self)}),
/* output[DSIZE-1:0] */ .q (#{align_signal(new_l)})
);
//-----<< #{signal} cross clock >>------------------
}
belong_to_module.Logic_draw << str
end
return new_l
end
|
#destruct_to(*args) ⇒ Object
270
271
272
273
274
275
276
|
# File 'lib/tdl/elements/logic.rb', line 270
def destruct_to(*args)
m = args.map do |e|
align_signal(e)
end
belong_to_module.Logic_draw << "\nassign {#{m.join(',')}} = #{signal};\n"
end
|
#exp_element(b) ⇒ Object
def signal_proc(a)
if a.is_a? Proc
a.call
else
a.to_s
end
end
157
158
159
160
161
162
163
|
# File 'lib/tdl/Logic/logic_main.rb', line 157
def exp_element(b)
if b.is_a? Proc
b.call
else
b.to_s
end
end
|
#falling(cnt: 1, clock: nil, reset: nil) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/tdl/Logic/logic_edge.rb', line 47
def falling(cnt:1,clock:nil,reset:nil)
@logic_expression_record ||= Hash.new
@clock = clock if clock
@reset = reset if reset
head_str = ""
end_str = ""
str = ""
ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
head_str =
"\n//====>>>> #{signal} FEDGE <<<<#{"="*(60-6-signal.length)}\n"
end_str =
"//----<<<< #{signal} FEDGE >>>>#{"-"*(60-6-signal.length)}\n"
belong_to_module.Logic_draw << head_str
inst_edge(@clock,@reset)
if cnt>1
inst_fall_edge_cnt(cnt-1)
str = inst_cnt_edge_signal(cnt-1,:fall)
else
str = "#{signal}_falling"
end
belong_to_module.Logic_draw << end_str
end
return str.to_nq
end
|
#force_nege_index(bool = true) ⇒ Object
165
166
167
|
# File 'lib/tdl/elements/logic.rb', line 165
def force_nege_index(bool=true)
@nege_index = bool
end
|
#init_assign(value) ⇒ Object
#init_exec(str) ⇒ Object
22
23
24
|
# File 'lib/tdl/bfm/logic_initial_block.rb', line 22
def init_exec(str)
@_init_exec_stack << "#{logic_init_tap}#{str};\n"
end
|
#Initial {|_self| ... } ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/tdl/bfm/logic_initial_block.rb', line 4
def Initial(&block)
@_lg_init_tap_cnt_ = 1
@_init_exec_stack = []
yield(self)
str = initial_block(@_init_exec_stack.join())
belong_to_module.Logic_draw << str
end
|
#inst ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/tdl/elements/logic.rb', line 169
def inst
lname = @name.to_s
unless @ghost
if dsize.eql?(1) && dimension.empty?
str = "#{@type} #{lname}#{@default ? " = #{align_signal(@default)};" : ";"}"
else
if (@dsize.is_a? Numeric) && @dsize < 0
str = "#{@type} [0:#{(-@dsize-1)}] #{lname}#{array_inst} #{@default ? " = #{align_signal(@default)};" : ";"}"
elsif @nege_index
str = "#{@type} [0:#{@dsize}-1] #{lname}#{array_inst} #{@default ? " = #{align_signal(@default)};" : ";"}"
else
str = "#{@type} [#{@dsize}-1:0] #{lname}#{array_inst} #{@default ? " = #{align_signal(@default)};" : ";"}"
end
end
else
str = ""
end
str
end
|
#inst_port ⇒ Object
209
210
211
212
213
214
215
216
217
218
|
# File 'lib/tdl/elements/logic.rb', line 209
def inst_port
if dsize.eql? 1
n = " #{@type}"
else
n = " #{@type}[#{(@dsize-1)}:0]"
end
return [@port.to_s + n, @name.to_s,array_inst]
end
|
#latency(count: 1, clock: nil, reset: nil) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/tdl/Logic/logic_latency.rb', line 3
def latency(count:1,clock:nil,reset:nil)
unless clock
sclk = @__clock__
else
sclk = clock
end
unless reset
srst = @__reset__
else
srst = reset
end
unless sclk
raise TdlError.new("latency clock is nil")
end
unless srst
raise TdlError.new('latency reset is nil')
end
new_l = belong_to_module.Def.logic(name:"#{signal(square:false)}_lat",dsize:self.dsize)
str = %Q{
//----->> #{signal} LAST DELAY <<------------------
latency #(
.LAT (#{count}),
.DSIZE (#{dsize})
)#{signal(square:false)}_lat#{count}_inst(
#{sclk},
#{srst},
#{signal},
#{new_l.signal}
);
//-----<< #{signal} LAST DELAY >>------------------
}
belong_to_module.Logic_draw << str
return new_l
end
|
#merge_from(*args) ⇒ Object
def self.clear
@@id = 1
@@inst_stack = []
@@ports = []
@@nc = self.new
BaseElm.recfg_nc(@@nc)
end
262
263
264
265
266
267
268
|
# File 'lib/tdl/elements/logic.rb', line 262
def merge_from(*args)
m = args.map do |e|
align_signal(e)
end
belong_to_module.Logic_draw << "\nassign #{signal} = {#{m.join(',')}};\n"
end
|
#port_length ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
|
# File 'lib/tdl/elements/logic.rb', line 195
def port_length
if dsize.eql? 1
n = ""
else
if @dsize.is_a? Numeric
n = "[#{(@dsize.abs-1)}:0]"
else
n = "[#{(@dsize.to_s-1)}:0]"
end
end
(@port.to_s + n + " ").length
end
|
#raising(cnt: 1, clock: nil, reset: nil) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/tdl/Logic/logic_edge.rb', line 4
def raising(cnt:1,clock:nil,reset:nil)
@logic_expression_record ||= Hash.new
str = ""
@clock = clock if clock
@reset = reset if reset
head_str = ""
end_str = ""
ClassHDL::AssignDefOpertor.with_rollback_opertors(:old) do
head_str =
"\n//====>>>> #{signal} RAISING EDGE <<<<#{"="*(60-6-signal.length)}\n"
end_str =
"\n//----<<<< #{signal} RAISING EDGE >>>>#{"-"*(60-6-signal.length)}\n"
belong_to_module.Logic_draw << head_str
inst_edge(@clock,@reset)
if cnt>1
inst_raise_edge_cnt(cnt-1)
str = inst_cnt_edge_signal(cnt-1,:raise)
else
str = "#{signal}_raising"
end
belong_to_module.Logic_draw << end_str
end
return str.to_nq
end
|
#repeat(num = 0, &block) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/tdl/bfm/logic_initial_block.rb', line 26
def repeat(num=0,&block)
if num > 0
@_init_exec_stack << "#{logic_init_tap}repeat(#{num.to_s}) begin\n"
else
@_init_exec_stack << "#{logic_init_tap}forever begin\n"
end
@_lg_init_tap_cnt_ += 1
yield
@_lg_init_tap_cnt_ -= 1
@_init_exec_stack << "#{logic_init_tap}end\n"
end
|
#signal(h: nil, l: 0, square: true) ⇒ Object
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
# File 'lib/tdl/elements/logic.rb', line 136
def signal(h:nil,l:0,square:true)
if h.is_a? Numeric
if @dsize.is_a?(Numeric) && (h > @dsize-1)
h = @dsize - 1
end
h = h
elsif @dsize.is_a? Numeric
h = (@dsize.abs-1)
else
h = "#{@dsize}-1"
end
if @port
NqString.new (@name.to_s)
elsif !square || @dimension.any?
NqString.new("#{name}")
elsif dsize.eql? 1
NqString.new("#{name}")
else
NqString.new("#{name}[#{h}:#{l}]")
end
end
|