Utils
Some utils are also present in spinal.core
State less utilities
Syntax |
Return |
Description |
---|---|---|
toGray(x : UInt) |
Bits |
Return the gray value converted from |
fromGray(x : Bits) |
UInt |
Return the UInt value converted value from |
Reverse(x : T) |
T |
Flip all bits (lsb + n -> msb - n) |
OHToUInt(x : Seq[Bool])
OHToUInt(x : BitVector)
|
UInt |
Return the index of the single bit set (one hot) in |
CountOne(x : Seq[Bool])
CountOne(x : BitVector)
|
UInt |
Return the number of bit set in |
CountLeadingZeroes(x : Bits)
|
UInt |
Return the number of consecutive zero bits starting from the MSB |
MajorityVote(x : Seq[Bool])
MajorityVote(x : BitVector)
|
Bool |
Return True if the number of bit set is > x.size / 2 |
EndiannessSwap(that: T[, base:BitCount]) |
T |
Big-Endian <-> Little-Endian |
OHMasking.first(x : Bits) |
Bits |
Apply a mask on x to only keep the first bit set |
OHMasking.last(x : Bits) |
Bits |
Apply a mask on x to only keep the last bit set |
OHMasking.roundRobin(
requests : Bits,
ohPriority : Bits
)
|
Bits |
Apply a mask on x to only keep the bit set from
requests .it start looking in
requests from the ohPriority position.For example if
requests is “1001” and ohPriority is “0010”, the roundRobin function will start looking in requests from its second bit and will return “1000”. |
MuxOH (
oneHot : IndexedSeq[Bool],
inputs : Iterable[T]
)
|
T |
Returns the muxed |
PriorityMux (
sel: Seq[Bool],
in: Seq[T]
)
|
T |
Return the first |
PriorityMux (
in: Seq[(Bool, T)]
)
|
T |
Return the first |
State full utilities
Syntax |
Return |
Description |
---|---|---|
Delay(that: T, cycleCount: Int) |
T |
Return |
History (
that: T, length: Int
[, when : Bool][, init : T]
)
|
Vec[T] |
Return a Vec of
length elementsThe first element is
that , the last one is that delayed by length - 1The internal shift register sample when
when is asserted |
History (
that: T, range: Range
[, when : Bool][, init : T]
)
|
Vec[T] |
Same as
History(that, length) but return a Vec of size
range.length where the first element is delayed by
range.low and the last by
range.high |
BufferCC(input : T) |
T |
Return the input signal synchronized with the current clock domain by using 2 flip flop |
Counter
The Counter tool can be used to easily instantiate a hardware counter.
Instantiation syntax |
Notes |
---|---|
|
|
|
Compatible with the |
|
Starts at zero and ends at |
|
Starts at zero and ends at |
A counter can be controlled by methods, and wires can be read:
val counter = Counter(2 to 9) // Creates a counter of 8 states (2 to 9)
// Methods
counter.clear() // Resets the counter
counter.increment() // Increments the counter
// Wires
counter.value // Current value
counter.valueNext // Next value
counter.willOverflow // True if the counter overflows this cycle
counter.willOverflowIfInc // True if the counter would overflow this cycle if an increment was done
// Cast
when(counter === 5){ ... } // counter is implicitly casted to its current value
When a Counter
overflows (reached end value), it restarts the next cycle to its start value.
Note
Currently, only up counter are supported.
CounterFreeRun
builds an always running counter: CounterFreeRun(stateCount: BigInt)
.
Timeout
The Timeout tool can be used to easily instantiate an hardware timeout.
Instantiation syntax |
Notes |
---|---|
Timeout(cycles : BigInt) |
Tick after |
Timeout(time : TimeNumber) |
Tick after a |
Timeout(frequency : HertzNumber) |
Tick at an |
There is an example of different syntaxes which could be used with the Counter tool
val timeout = Timeout(10 ms) // Timeout who tick after 10 ms
when(timeout) { // Check if the timeout has tick
timeout.clear() // Ask the timeout to clear its flag
}
Note
If you instantiate an Timeout
with an time or frequency setup, the implicit ClockDomain
should have an frequency setting.
ResetCtrl
The ResetCtrl provide some utilities to manage resets.
asyncAssertSyncDeassert
You can filter an asynchronous reset by using an asynchronously asserted synchronously deasserted logic. To do it you can use the ResetCtrl.asyncAssertSyncDeassert
function which will return you the filtered value.
Argument name |
Type |
Description |
---|---|---|
input |
Bool |
Signal that should be filtered |
clockDomain |
ClockDomain |
ClockDomain which will use the filtered value |
inputPolarity |
Polarity |
HIGH/LOW (default=HIGH) |
outputPolarity |
Polarity |
HIGH/LOW (default=clockDomain.config.resetActiveLevel) |
bufferDepth |
Int |
Number of register stages used to avoid metastability (default=2) |
There is also an ResetCtrl.asyncAssertSyncDeassertDrive
version of tool which directly assign the clockDomain
reset with the filtered value.
Special utilities
Syntax |
Return |
Description |
---|---|---|
LatencyAnalysis(paths : Node*) |
Int |
Return the shortest path, in terms of cycles, that travel through all nodes,
from the first one to the last one
|