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

}

}

相关推荐
WorkAgent4 小时前
windows下本地部署安装hadoop+scala+spark-【不需要虚拟机】
hadoop·spark·scala
JoneMaster7 天前
[读书日志]从零开始学习Chisel 第十二篇:Scala的抽象成员(敏捷硬件开发语言Chisel与数字系统设计)
开发语言·学习·scala
wlyang6669 天前
4. scala高阶之隐式转换与泛型
大数据·开发语言·后端·spark·scala
一杯拿铁go11 天前
[sparkstreaming]java.lang.NoSuchMethodError:错误以及更改
scala·noclassdeffound
百流11 天前
scala基础学习(数据类型)-集合
开发语言·学习·scala
JoneMaster11 天前
[读书日志]从零开始学习Chisel 第十篇:Scala的模式匹配(敏捷硬件开发语言Chisel与数字系统设计)
开发语言·学习·scala
JoneMaster12 天前
[读书日志]从零开始学习Chisel 第十一篇:Scala的类型参数化(敏捷硬件开发语言Chisel与数字系统设计)
开发语言·学习·scala
小白学大数据12 天前
如何使用Scala和Selenium爬取知乎视频并保存到本地
chrome·python·selenium·scala
小_太_阳12 天前
scala_【JVM】概述
开发语言·jvm·scala
wlyang66612 天前
2. Scala 高阶语法之集合与元组
开发语言·后端·scala