Sha256: 9eba25dc09752023b809a25fc15bb5c9e861242c595f34d3782bc0dd67382252

Contents?: true

Size: 1.3 KB

Versions: 5

Compression:

Stored size: 1.3 KB

Contents

# A factorial with default stack depth.
sdef(:fact) do |n|
    hprint("n=",n,"\n")
    sif(n > 1) { sreturn(n*fact(n-1,20)) } #Recurse setting the stack depth to 20
    selse      { sreturn(1) }
end

# A factiorial with very low stack depth for checking overflow.
sdef(:fact_over,2,proc { stack_overflow_error <= 1 }) do |n|
    hprint("n2=",n,"\n")
    sif(n > 1) { sreturn(n*fact_over(n-1)) }
    selse      { sreturn(1) }
end

# Checking the usage of sequencers functions.
system :my_seqencer do

    inner :clk,:rst

    [16].inner :val
    [16].inner :res

    inner stack_overflow_error: 0

    sequencer(clk.posedge,rst) do
        5.stimes do |i|
            val <= i
            res <= fact(val)
            hprint("res=",res,"\n")
        end
        hprint("Going to overflow...\n")
        4.stimes do |i|
            val <= i
            res <= fact_over(val)
            hprint("res=",res,"\n")
        end
        hprint("stack_overflow_error=",stack_overflow_error,"\n")
    end

    timed do
        clk <= 0
        rst <= 0
        !10.ns
        clk <= 1
        !10.ns
        clk <= 0
        rst <= 1
        !10.ns
        clk <= 1
        !10.ns
        clk <= 0
        rst <= 0
        !10.ns
        clk <= 1
        repeat(500) do
            !10.ns
            clk <= ~clk
        end
    end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
HDLRuby-3.4.0 lib/HDLRuby/hdr_samples/with_sequencer_func.rb
HDLRuby-3.3.4 lib/HDLRuby/hdr_samples/with_sequencer_func.rb
HDLRuby-3.3.3 lib/HDLRuby/hdr_samples/with_sequencer_func.rb
HDLRuby-3.3.1 lib/HDLRuby/hdr_samples/with_sequencer_func.rb
HDLRuby-3.3.0 lib/HDLRuby/hdr_samples/with_sequencer_func.rb