AXI4Arbiter object scala code reading

object AXI4Arbiter

{

def applyT \<: Data(policy: TLArbiter.Policy)(sink: IrrevocableIOT, sources: IrrevocableIOT*): Unit = {

if (sources.isEmpty) {

sink.valid := false.B

} else {

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

}

}

def returnWinnerT \<: Data(policy: TLArbiter.Policy)(sink: IrrevocableIOT, sources: IrrevocableIOT*) = {

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

}

}

相关推荐
深兰科技3 天前
深兰科技受邀参与第二届中国(南宁)—东盟人工智能场景应用对接会,深化AI国际合作
人工智能·qt·r语言·scala·symfony·智能机器人·深兰科技
开开心心就好7 天前
低年级识字练笔顺工具,电脑和安卓端都能用
前端·javascript·网络·安全·scala·erlang·语音识别
开开心心就好8 天前
清理此电脑网盘图标工具,开源免费好用
网络·网络协议·tcp/ip·智能手机·电脑·scala·erlang
典典分享指南12 天前
用结构化数据管理产品知识库
scala·bash·batch·actionscript
Thomas214315 天前
scala 闭包
开发语言·后端·scala
江畔柳前堤15 天前
前台·中台·后台:2026年AI原生时代的架构全景图
开发语言·人工智能·算法·机器学习·架构·scala·ai-native
Thomas214323 天前
Java scala 数组 链表
java·链表·scala
江畔柳前堤25 天前
消息队列:从直觉到精通的完整认知地图
开发语言·人工智能·算法·机器学习·ruby on rails·scala
hopsky1 个月前
《Scala 学习手册》核心内容详解
人工智能·学习·scala
abcy0712132 个月前
scala playframework 搭建与新建controller教程
scala