2011-10-26 08:02:47 +02:00
|
|
|
package Top {
|
|
|
|
|
|
|
|
import Chisel._;
|
|
|
|
import Node._;
|
|
|
|
import Constants._;
|
|
|
|
|
|
|
|
class ioMem() extends Bundle
|
|
|
|
{
|
2012-01-18 19:28:48 +01:00
|
|
|
val req_val = Bool(OUTPUT);
|
|
|
|
val req_rdy = Bool(INPUT);
|
|
|
|
val req_rw = Bool(OUTPUT);
|
|
|
|
val req_addr = UFix(PADDR_BITS - OFFSET_BITS, OUTPUT);
|
|
|
|
val req_wdata = Bits(MEM_DATA_BITS, OUTPUT);
|
|
|
|
val req_tag = Bits(MEM_TAG_BITS, OUTPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-01-18 19:28:48 +01:00
|
|
|
val resp_val = Bool(INPUT);
|
|
|
|
val resp_tag = Bits(MEM_TAG_BITS, INPUT);
|
|
|
|
val resp_data = Bits(MEM_DATA_BITS, INPUT);
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2012-02-20 09:51:48 +01:00
|
|
|
class ioMemArbiter(n: Int) extends Bundle() {
|
2011-10-26 08:02:47 +02:00
|
|
|
val mem = new ioMem();
|
2012-02-20 09:51:48 +01:00
|
|
|
val requestor = Vec(n) { new ioDCache() }
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2012-02-20 09:51:48 +01:00
|
|
|
class rocketMemArbiter(n: Int) extends Component {
|
|
|
|
val io = new ioMemArbiter(n);
|
|
|
|
require(io.mem.req_tag.getWidth >= log2up(n) + io.requestor(0).req_tag.getWidth)
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-20 09:51:48 +01:00
|
|
|
var req_val = Bool(false)
|
|
|
|
var req_rdy = io.mem.req_rdy
|
|
|
|
for (i <- 0 until n)
|
|
|
|
{
|
|
|
|
io.requestor(i).req_rdy := req_rdy
|
|
|
|
req_val = req_val || io.requestor(i).req_val
|
|
|
|
req_rdy = req_rdy && !io.requestor(i).req_val
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-20 09:51:48 +01:00
|
|
|
var req_rw = io.requestor(n-1).req_rw
|
|
|
|
var req_addr = io.requestor(n-1).req_addr
|
|
|
|
var req_wdata = io.requestor(n-1).req_wdata
|
|
|
|
var req_tag = Cat(io.requestor(n-1).req_tag, UFix(n-1, log2up(n)))
|
|
|
|
for (i <- n-1 to 0 by -1)
|
|
|
|
{
|
|
|
|
req_rw = Mux(io.requestor(i).req_val, io.requestor(i).req_rw, req_rw)
|
|
|
|
req_addr = Mux(io.requestor(i).req_val, io.requestor(i).req_addr, req_addr)
|
|
|
|
req_wdata = Mux(io.requestor(i).req_val, io.requestor(i).req_wdata, req_wdata)
|
|
|
|
req_tag = Mux(io.requestor(i).req_val, Cat(io.requestor(i).req_tag, UFix(i, log2up(n))), req_tag)
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-20 09:51:48 +01:00
|
|
|
io.mem.req_val := req_val
|
|
|
|
io.mem.req_rw := req_rw
|
|
|
|
io.mem.req_addr := req_addr
|
|
|
|
io.mem.req_wdata := req_wdata
|
|
|
|
io.mem.req_tag := req_tag
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-20 09:51:48 +01:00
|
|
|
for (i <- 0 until n)
|
|
|
|
{
|
|
|
|
io.requestor(i).resp_val := io.mem.resp_val && io.mem.resp_tag(log2up(n)-1,0) === UFix(i)
|
|
|
|
io.requestor(i).resp_data := io.mem.resp_data
|
|
|
|
io.requestor(i).resp_tag := io.mem.resp_tag >> UFix(log2up(n))
|
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|