Class: Clock

Inherits:
SignalElm show all
Includes:
BaseModule, ClassHDL::AssignDefOpertor
Defined in:
lib/tdl/elements/clock.rb,
lib/tdl/elements/clock.rb,
lib/tdl/class_hdl/hdl_redefine_opertor.rb

Overview

require_relative “./tdlerror” require_relative “./basefunc”

Constant Summary

Constants included from ClassHDL::AssignDefOpertor

ClassHDL::AssignDefOpertor::OP_SYMBOLS

Instance Attribute Summary collapse

Attributes inherited from BaseElm

#belong_to_module

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ClassHDL::AssignDefOpertor

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

Methods included from BaseModule

#length, #to_s

Methods inherited from SignalElm

#[], inherited, #inst, subclass

Methods inherited from BaseElm

#matrix, #name_copy, #path_refs, recfg_nc, #s, #signal

Methods included from TdlSpace::ExCreateTP

#create_tp, #root_ref

Constructor Details

#initialize(name: "system_clock", freqM: 100.0, port: false, dsize: 1, jitter: 0.01) ⇒ Clock

Returns a new instance of Clock.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/tdl/elements/clock.rb', line 8

def initialize(name:"system_clock",freqM:100.0,port:false,dsize:1,jitter: 0.01)
    name_legal?(name)
    # @id = GlobalParam.CurrTdlModule.BindEleClassVars.Clock.id
    @name = name
    @freqM = freqM
    @port = port
    @dsize = dsize
    @jitter = jitter
    # if @port
    #     GlobalParam.CurrTdlModule.BindEleClassVars.Clock.ports << self if @id != 0
    # else
    #     GlobalParam.CurrTdlModule.BindEleClassVars.Clock.inst_stack << method(:inst).to_proc
    # end
    # if @id == 0
    #     raise TdlError.new(" ID ")
    # end
end

Instance Attribute Details

#dsizeObject

Returns the value of attribute dsize.



6
7
8
# File 'lib/tdl/elements/clock.rb', line 6

def dsize
  @dsize
end

#freqMObject

Returns the value of attribute freqM.



6
7
8
# File 'lib/tdl/elements/clock.rb', line 6

def freqM
  @freqM
end

#ghostObject

Returns the value of attribute ghost.



6
7
8
# File 'lib/tdl/elements/clock.rb', line 6

def ghost
  @ghost
end

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/tdl/elements/clock.rb', line 6

def id
  @id
end

#jitterObject

Returns the value of attribute jitter.



6
7
8
# File 'lib/tdl/elements/clock.rb', line 6

def jitter
  @jitter
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/tdl/elements/clock.rb', line 5

def name
  @name
end

#portObject

Returns the value of attribute port.



6
7
8
# File 'lib/tdl/elements/clock.rb', line 6

def port
  @port
end

Class Method Details

.checkpclock(aclk, bclk, blm) ⇒ Object



154
155
156
# File 'lib/tdl/elements/clock.rb', line 154

def self.checkpclock(aclk,bclk,blm)
    blm.Clock_draw << self.checkpclockdraw(aclk,bclk,blm)
end

.checkpclockdraw(aclk, bclk, blm) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/tdl/elements/clock.rb', line 158

def self.checkpclockdraw(aclk,bclk,blm)
    @@_cpc_id ||= 0
    cc_done = "cc_done_#{@@_cpc_id}"
    cc_same = "cc_same_#{@@_cpc_id}"
    cc_afreq = "cc_afreq_#{@@_cpc_id}"
    cc_bfreq = "cc_bfreq_#{@@_cpc_id}"
    str =
"//--->> CheckClock <<----------------
logic #{cc_done},#{cc_same};
integer #{cc_afreq},#{cc_bfreq};
ClockSameDomain CheckPClock_inst_#{@@_cpc_id}(
/*  input         */      .aclk     (#{align_signal(aclk,q_mark=false)}),
/*  input         */      .bclk     (#{align_signal(bclk,q_mark=false)}),
/*  output logic  */      .done     (#{cc_done}),
/*  output logic  */      .same     (#{cc_same}),
/*  output integer */     .aFreqK   (#{cc_afreq}),
/*  output integer */     .bFreqK   (#{cc_bfreq})
);

initial begin
wait(#{cc_done});
assert(#{cc_same})
else begin
    $error(\"--- Error : `#{blm.module_name}` clock is not same, #{aclk}< %0f M> != #{bclk}<%0f M>\",1000000.0/#{cc_afreq}, 1000000.0/#{cc_bfreq});
    repeat(10)begin 
        @(posedge #{aclk});
    end
    $stop;
end
end
//---<< CheckClock >>----------------
"
    @@_cpc_id += 1
    str
end

.parse_ports(port_str) ⇒ Object

parse text for autogen method and constant ###



135
136
137
138
139
# File 'lib/tdl/elements/clock.rb', line 135

def self.parse_ports(port_str)
    rh = super.parse_ports(port_str)
    rh[:type]   = Clock
    return rh
end

.same_clock(blm, *clks) ⇒ Object



146
147
148
149
150
151
152
# File 'lib/tdl/elements/clock.rb', line 146

def self.same_clock(blm,*clks)
    blm.Clock_draw << "//-------- CLOCKs Total #{clks.size} ----------------------"
    clks[1,clks.size].each do |c|
        self.checkpclock(clks[0],c,blm)
    end
    blm.Clock_draw << "//======== CLOCKs Total #{clks.size} ======================"
end

Instance Method Details

#inst_port(align_len = 7) ⇒ Object

def port_length

(@port.to_s + " ").length

end



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/tdl/elements/clock.rb', line 30

def inst_port(align_len = 7)
    # if align_len >=  port_length
    #     sub_len = align_len - port_length
    # else
    #     sub_len = 0
    # end
    #
    # if @port
    #     (@port.to_s + " " + " "*sub_len + @name.to_s)
    # end

    if dsize.eql? 1
        n = ""
    else
        n = "[#{(@dsize-1)}:0]"
    end

    return [@port.to_s+n, @name.to_s,""]
end