Livt packages
Livt.Base
Version 1.2.1
Foundational bit, array, string, conversion, formatting, and timing helpers for Livt hardware designs.
Published files (32)
src/PeriodicTickProvider.lvt
namespace Livt.Timing
/**
* Produces a one-context-tick pulse after each configured number of ticks.
* The configured interval must be at least one context tick.
*/
component PeriodicTickProvider
{
// Configured interval in cycles and current elapsed-cycle count.
periodTicks: uint
elapsedTicks: uint
// One-cycle output pulse when the configured interval elapses.
tick: logic
/**
* Creates a provider that pulses after every periodTicks context ticks.
* periodTicks must be at least one.
*/
new(periodTicks: uint, tick: out logic)
{
tick = this.tick
this.periodTicks = periodTicks
this.elapsedTicks = 0
this.tick = 0b0
}
/**
* Returns the configured interval in ticks of this component's context.
*/
public fn GetPeriodTicks() uint
{
return this.periodTicks
}
/**
* Advances the interval counter and emits a one-context-tick pulse.
*/
process Generate()
{
this.tick = 0b0
if ((this.elapsedTicks + 1) >= this.periodTicks) {
this.elapsedTicks = 0
this.tick = 0b1
} else {
this.elapsedTicks = this.elapsedTicks + 1
}
}
}