实用工具
一些实用工具也在 spinal.core 中
免状态工具
语法 |
返回类型 |
描述 |
---|---|---|
toGray(x : UInt) |
位 |
返回从 |
fromGray(x : Bits) |
UInt |
返回从 |
Reverse(x : T) |
T |
翻转所有位(lsb + n -> msb - n) |
OHToUInt(x : Seq[Bool])
OHToUInt(x : BitVector)
|
UInt |
返回 |
CountOne(x : Seq[Bool])
CountOne(x : BitVector)
|
UInt |
返回 |
CountLeadingZeroes(x : Bits)
|
UInt |
返回从最显著位 (MSB) 开始连续零位的个数 |
MajorityVote(x : Seq[Bool])
MajorityVote(x : BitVector)
|
Bool |
如果设置为1的位数 > x.size / 2,则返回 True |
EndiannessSwap(that: T[, base:BitCount]) |
T |
大端 <-> 小端 |
OHMasking.first(x : Bits) |
位 |
对x应用掩码以仅保留第一个设为1的位 |
OHMasking.last(x : Bits) |
位 |
对x应用掩码以仅保留最后一个设为1的位 |
OHMasking.roundRobin(
requests : Bits,
ohPriority : Bits
)
|
位 |
对x应用掩码以仅保留
requests 中设置1的位。它从
ohPriority 位置开始访问 requests 。例如,如果
requests 为“1001”且 ohPriority 为“0010”,则 roundRobin 函数将从第二位开始访问 requests 并返回“1000”。 |
MuxOH (
oneHot : IndexedSeq[Bool],
inputs : Iterable[T]
)
|
T |
根据 |
PriorityMux (
sel: Seq[Bool],
in: Seq[T]
)
|
T |
返回第一个其 |
PriorityMux (
in: Seq[(Bool, T)]
)
|
T |
返回第一个其 |
全状态工具
语法 |
返回类型 |
描述 |
---|---|---|
Delay(that: T, cycleCount: Int) |
T |
返回延迟了 |
History (
that: T, length: Int
[, when : Bool][, init : T]
)
|
Vec[T] |
返回长度为
length 的Vec其第一个元素是
that ,最后一个元素是延迟了 length -1的 that 内部移位寄存器会在
when 有效时采样 |
History (
that: T, range: Range
[, when : Bool][, init : T]
)
|
Vec[T] |
和
History(that, length) 相同但返回长度为
range.length 的Vec其中第一个元素延迟了
range.low 个周期且最后一个是延迟了
range.high 个周期的元素 |
BufferCC(input : T) |
T |
返回利用两个触发器同步到当前时钟域的同步输入信号 |
计数器
计数器工具可用于轻松实例化硬件计数器。
实例化语法 |
备注 |
---|---|
|
|
|
与 |
|
从 0 开始,到 |
|
从0开始到 |
计数器可以通过方法控制,并且可以连线可以被读取:
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
当 Counter
溢出(达到最终值)时,它会重新启动下一个周期并设置为起始值。
备注
目前仅支持向上计数器。
CounterFreeRun
构建一个始终运行的计数器: CounterFreeRun(stateCount: BigInt)
。
超时
超时工具可用于方便地实例化一个硬件超时。
实例化语法 |
备注 |
---|---|
Timeout(cycles : BigInt) |
在 |
Timeout(time : TimeNumber) |
在持续 |
Timeout(frequency : HertzNumber) |
以 |
下方是可以与Counter工具一起使用的不同语法句式的示例
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
}
备注
如果您使用时间或频率设置实例化 Timeout
,则隐含地 ClockDomain
应该具有频率设置。
复位控制
复位控制(ResetCtrl)提供了一些实用工具来管理复位。
asyncAssertSyncDeassert
您可以使用“异步有效同步无效”的逻辑来构造异步复位。为此,可以使用 ResetCtrl.asyncAssertSyncDeassert
函数返回构造的复位信号。
参数名称 |
类型 |
描述 |
---|---|---|
input |
Bool |
输入的异步信号,用于触发复位 |
clockDomain |
ClockDomain |
返回的新复位信号对齐的时钟域(ClockDomain) |
inputPolarity |
Polarity |
HIGH/LOW (default=HIGH) |
outputPolarity |
Polarity |
HIGH/LOW (default=clockDomain.config.resetActiveLevel) |
bufferDepth |
Int |
防止亚稳态所需的寄存器级数(默认为2) |
另外还有一个 ResetCtrl.asyncAssertSyncDeassertDrive
版本的工具,它直接使用新构造的复位信号作为 clockDomain
这个时钟域的复位。
特殊工具
语法 |
返回类型 |
描述 |
---|---|---|
LatencyAnalysis(paths : Node*) |
Int |
以周期为单位返回经过所有节点的最短路径,
从第一个节点到最后一个节点
|