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

}

}

相关推荐
啊喜拔牙5 小时前
1. hadoop 集群的常用命令
java·大数据·开发语言·python·scala
企鹅不耐热.11 小时前
Scala基础知识6
开发语言·后端·scala
一元钱面包11 小时前
scala课后总结(6)
scala
凉白开3382 天前
Scala基础知识
开发语言·后端·scala
不要不开心了2 天前
Scala内容
开发语言·pytorch·flask·scala·dash
2401_824256862 天前
Scala的函数式编程
开发语言·后端·scala
sho_re2 天前
第 3 章 运算符Scala 运算符的使用
scala
Gvemis⁹3 天前
Scala总结(三)
开发语言·后端·scala
星辰瑞云3 天前
Scala(2)
开发语言·后端·scala
苏小夕夕3 天前
Scala(二)
scala