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

}

}

相关推荐
6.9417 小时前
Scala——身份证号码查询籍贯
学习·scala
无奈ieq1 天前
Scala快速入门+示例
开发语言·后端·scala
yzj2311282 天前
BorrowRecordDAO
scala
yzj2311282 天前
图书展示功能2
scala
百流2 天前
Intellij配置scala运行环境
开发语言·scala·intellij-idea
lisacumt2 天前
[java] 简单的熔断器scala语言案例
java·开发语言·scala
百流2 天前
scala基础学习(数据类型)-字符串
开发语言·学习·scala
Ekine2 天前
【Flink-scala】DataStream编程模型之状态编程
大数据·flink·scala
麻芝汤圆2 天前
Scala的惰性求值:深入理解与实践
开发语言·后端·scala
炒空心菜菜2 天前
scala中模式匹配的应用
开发语言·后端·scala