Method: HDLRuby::High::Std#delay

Defined in:
lib/HDLRuby/std/delays.rb

#delayObject

Module describing a simple delay using handshake for working. @param num the number of clock cycles to delay.



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
47
48
49
# File 'lib/HDLRuby/std/delays.rb', line 11

system :delay do |num|
    # Checks and process the number of clock to wait.
    num = num.to_i
    raise "The delay generic argument must be positive: #{num}" if (num < 0)

    input  :clk     # The clock to make the delay on.
    input  :req     # The handshake request.
    output :ack     # The handshake acknoledgment.

    # The process of the delay.
    if (num == 0) then
        # No delay case.
        ack <= req
    else
        # The is a delay.
        inner run: 0               # Tell if the deayl is running.
        [num.width+1].inner :count # The counter for computing the delay.
        par(clk.posedge) do
            # Is there a request to treat?
            hif(req & ~run) do
                # Yes, intialize the delay.
                run <= 1
                count <= 0
                ack <= 0
            end
            # No, maybe there is a request in processing.
            helsif(run) do
                # Yes, increase the counter.
                count <= count + 1
                # Check if the delay is reached.
                hif(count == num-1) do
                    # Yes, tells it and stop the count.
                    ack <= 1
                    run <= 0
                end
            end
        end
    end
end