Learning BSV‎ > ‎Attributes‎ > ‎

fire_when_enabled Attribute

Overview

This attribute asserts that this rule must fire whenever its predicate and its implicit conditions are true. When the rule conditions are true, the attribute checks that there are no scheduling conflicts with other rules that will prevent it from firing. This is statically verified by the compiler. If the rule won't fire, or may not fire, the compiler reports an error. Without the attribute, the compiler would generate a warning about conflicting rules.

Attribute Syntax

(* fire_when_enabled *)
rule rulename conditions ;
...
endrule

The fire_when_enabled scheduling attribute immediately precedes a rule (just before the rule keyword) and governs the rule.

BSV Example

In this example, the rule resetCounter conflicts with the rule updateCounter because both try to modify the counter register when all bits are set to one. Because resetCounter may not always fire when its conditions are true, the assertion is violated and an error is generated.

// IfcCounter with read method
interface IfcCounter#(type t);
method t readCounter;
endinterface

typedef Bit#(16) CounterType;

(* synthesize *)
module counter (IfcCounter#(CounterType));
Reg#(CounterType) counter <- mkRegA(1);

// Next rule resets the counter to 1 when it reaches its limit.
// The attribute fire_when_enabled will check that this rule will fire
// if counter == '1
(* fire_when_enabled *)
rule resetCounter (counter == '1);
counter <= 1;
endrule

// Next rule updates the counter.
rule updateCounter;
counter <= counter + 1;
endrule

// Method to output the counter's value
method CounterType readCounter;
return counter;
endmethod
endmodule

Compiler Output

Warning: "counter.bsv", line 15, column 8: (G0010)
Rule "updateCounter" was treated as more urgent than
"resetCounter". Conflicts:
"updateCounter" cannot fire before "resetCounter":
calls to counter.write vs. counter.read
"resetCounter" cannot fire before "updateCounter":
calls to counter.write vs. counter.read
Error: "counter.bsv", line 23, column 9: (G0005)
The assertion `fire_when_enabled' failed for rule `RL_resetCounter'
because it is blocked by rule
RL_updateCounter
in the scheduler
esposito: [readCounter -> [],
RL_updateCounter -> [],
RL_resetCounter -> [RL_updateCounter]]
Comments