AXI4Arbiter object scala code reading

object AXI4Arbiter

{

def apply[T <: Data](policy: TLArbiter.Policy)(sink: IrrevocableIO[T], sources: IrrevocableIO[T]*): Unit = {

if (sources.isEmpty) {

sink.valid := false.B

} else {

returnWinner(policy)(sink, sources:_*)

}

}

def returnWinner[T <: Data](policy: TLArbiter.Policy)(sink: IrrevocableIO[T], sources: IrrevocableIO[T]*) = {

require (!sources.isEmpty)

// The arbiter is irrevocable; when !idle, repeat last request

val idle = RegInit(true.B)

// Who wants access to the sink?

val valids = sources.map(_.valid)

val anyValid = valids.reduce(_ || _)

// Arbitrate amongst the requests

val readys = VecInit(policy(valids.size, Cat(valids.reverse), idle).asBools)

// Which request wins arbitration?

val winner = VecInit((readys zip valids) map { case (r,v) => r&&v })

// Confirm the policy works properly

require (readys.size == valids.size)

// Never two winners

val prefixOR = winner.scanLeft(false.B)(||).init

assert((prefixOR zip winner) map { case (p,w) => !p || !w } reduce {_ && _})

// If there was any request, there is a winner

assert (!anyValid || winner.reduce(||))

// The one-hot source granted access in the previous cycle

val state = RegInit(VecInit.fill(sources.size)(false.B))

val muxState = Mux(idle, winner, state)

state := muxState

// Determine when we go idle

when (anyValid) { idle := false.B }

when (sink.fire) { idle := true.B }

if (sources.size > 1) {

val allowed = Mux(idle, readys, state)

(sources zip allowed) foreach { case (s, r) =>

s.ready := sink.ready && r

}

} else {

sources(0).ready := sink.ready

}

sink.valid := Mux(idle, anyValid, Mux1H(state, valids))

sink.bits :<= Mux1H(muxState, sources.map(_.bits))

muxState

}

}

相关推荐
今天我又学废了9 小时前
scala学习记录,Set,Map
开发语言·学习·scala
富能量爆棚2 天前
scala的属性访问权限
scala
富能量爆棚2 天前
Scala的包及其导入
开发语言·后端·scala
睎zyl2 天前
Scala的访问权限。
开发语言·后端·scala
富能量爆棚3 天前
Scala的属性访问权限(一)默认访问权限
开发语言·后端·scala
富能量爆棚3 天前
scala的控制方法作用域
scala
2401_871290583 天前
Scala 的例题:银行账户钱存取功能
scala
白总Server5 天前
Ribbon解说
后端·spring cloud·微服务·云原生·ribbon·架构·scala
白总Server6 天前
Ribbon的轮询策略实现方法
开发语言·后端·spring cloud·ribbon·架构·scala·1024程序员节
anqi276 天前
Scala 的trait
开发语言·后端·scala