Method: HDLRuby::High::Std#before
- Defined in:
- lib/HDLRuby/std/counters.rb
#before(init, rst = $rst, clk = $clk, &code) ⇒ Object
Sets a counter to +init+ when +rst+ is 1 that is decreased according to +clk+. As long as this counter does not reach 0, +code+ is executed. When not within a block, a behavior will be created which is activated on the rising edge of +clk+.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/HDLRuby/std/counters.rb', line 45 def before(init, rst = $rst, clk = $clk, &code) with_counter(init,rst,clk) do |counter| seq do hif(rst.to_expr == 1) do counter.to_ref <= init.to_expr end helsif(counter.to_expr != 0) do counter.to_ref <= counter.to_expr - 1 # code.call instance_eval(&code) end end end end |