45Implementation
Make an action method always enabled
Situation
FreeRunningCounter.tick has no guard and calls no state-dependent method. The
design drives it on every cycle, but its interface currently describes an
ordinary action method with an Enable input. The implementation works in BSV;
the missing piece is the stronger generated-RTL protocol.
The editable area is the starter interface declaration. Keep the method bodies,
state, and supplied mkTop structure intact.
Read and predict before editing
Read in this order:
- Compare the
tickandcountdeclarations inFreeRunningCounter. - Follow
tickto the only register it updates. - Check whether
drivehas a predicate and whether any other rule can stop it. - Trace
cyclefrom reset untilshowbecomes enabled.
Predict the starter behavior before Run. Compilation and simulation can already
succeed because an ordinary Enable protocol is legal. The counter should advance
once for each cycle before show observes it. The problem is therefore not a
wrong arithmetic result; it is that generated RTL still permits an external
caller to omit tick.
Make the minimal change
Declare that tick is part of every cycle's module behavior. Change only the
method declaration in the interface. Do not add a guard, duplicate the call,
or alter the update expression to imitate the protocol in datapath logic.
The reasoning is short: tick is permanently ready, and drive requests it on
every cycle, so removing the request port accurately describes both callee and
caller behavior. Remember that this protocol also includes permanent readiness.
Observable completion
Run succeeds, and the displayed count reflects one increment for each completed
pre-display cycle. Independently synthesizing mkFreeRunningCounter no longer
requires an Enable input for tick; count remains a read-only value method.
The contract must continue to hold for every 8-bit delta, including zero and
wraparound values, rather than only for the supplied call with 1.
Progressive hints
Hint 1: classify the signal
An action method normally receives a caller request. This exercise removes that request because the action is mandatory each cycle; it does not rename the request.
Hint 2: narrow the location
Protocol attributes belong on the method prototype in
FreeRunningCounter, immediately before the declaration they govern. The
implementation body does not need another annotation.
Hint 3: choose the contract
Use the valueless method attribute whose name states that the method is always enabled. It also implies the always-ready property.
Transfer experiment
After completing the required change, temporarily guard drive so it runs only
while cycle < 2. Predict why the stronger interface contract is then false
even though the method body remains unguarded. Revert the experiment before
submitting; it is not part of grading.