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

}

}

相关推荐
哈哈很哈哈1 天前
Spark 核心 RDD详解
大数据·分布式·spark·scala
DTS小夏1 天前
Linux 系统 + IDEA+Scala 插件:新手进阶开发指南
linux·scala·intellij-idea
渣渣盟3 天前
Spark核心:单跳转换率计算全解析
大数据·spark·scala·apache
闯闯桑4 天前
Spark 中spark.implicits._ 中的 toDF和DataFrame 类本身的 toDF 方法
大数据·ajax·spark·scala
MOMO陌染6 天前
IDEA环境搭建与输出
scala
闯闯桑8 天前
toDF(columns: _*) 语法
开发语言·前端·spark·scala·apache
q567315239 天前
无需Python:Shell脚本如何成为你的自动化爬虫引擎?
开发语言·爬虫·python·自动化·scala
渣渣盟11 天前
Spark自定义累加器实现高效WordCount
大数据·spark·scala
IvanCodes12 天前
一、Scala 基础语法、变量与数据类型
大数据·开发语言·scala
q5673152313 天前
Nim轻量级爬虫:异步高效+代理轮换防封
开发语言·后端·爬虫·typescript·scala