2012-02-26 02:09:26 +01:00
|
|
|
package rocket
|
2011-10-26 08:02:47 +02:00
|
|
|
|
|
|
|
import Chisel._
|
|
|
|
import Node._;
|
|
|
|
|
2012-02-09 02:55:05 +01:00
|
|
|
class ioQueue[T <: Data](flushable: Boolean)(data: => T) extends Bundle
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
2012-02-09 02:55:05 +01:00
|
|
|
val flush = if (flushable) Bool(INPUT) else null
|
|
|
|
val enq = new ioDecoupled()(data)
|
|
|
|
val deq = new ioDecoupled()(data).flip
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
|
|
|
|
2012-02-29 12:08:04 +01:00
|
|
|
class queue[T <: Data](entries: Int, pipe: Boolean = false, flushable: Boolean = false)(data: => T) extends Component
|
2011-10-26 08:02:47 +02:00
|
|
|
{
|
2012-02-09 02:55:05 +01:00
|
|
|
val io = new ioQueue(flushable)(data)
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-09 02:55:05 +01:00
|
|
|
val do_enq = io.enq.ready && io.enq.valid
|
|
|
|
val do_deq = io.deq.ready && io.deq.valid
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-25 04:22:35 +01:00
|
|
|
var enq_ptr = UFix(0)
|
|
|
|
var deq_ptr = UFix(0)
|
|
|
|
|
|
|
|
if (entries > 1)
|
|
|
|
{
|
|
|
|
enq_ptr = Reg(resetVal = UFix(0, log2up(entries)))
|
|
|
|
deq_ptr = Reg(resetVal = UFix(0, log2up(entries)))
|
|
|
|
|
|
|
|
when (do_deq) {
|
|
|
|
deq_ptr := deq_ptr + UFix(1)
|
|
|
|
}
|
|
|
|
when (do_enq) {
|
|
|
|
enq_ptr := enq_ptr + UFix(1)
|
|
|
|
}
|
|
|
|
if (flushable) {
|
|
|
|
when (io.flush) {
|
|
|
|
deq_ptr := UFix(0)
|
|
|
|
enq_ptr := UFix(0)
|
|
|
|
}
|
|
|
|
}
|
2012-02-09 02:55:05 +01:00
|
|
|
}
|
2012-02-25 04:22:35 +01:00
|
|
|
|
|
|
|
val maybe_full = Reg(resetVal = Bool(false))
|
2012-02-09 02:55:05 +01:00
|
|
|
when (do_enq != do_deq) {
|
2012-02-12 02:20:33 +01:00
|
|
|
maybe_full := do_enq
|
|
|
|
}
|
|
|
|
if (flushable) {
|
|
|
|
when (io.flush) {
|
|
|
|
maybe_full := Bool(false)
|
|
|
|
}
|
2012-01-22 05:13:15 +01:00
|
|
|
}
|
2011-10-26 08:02:47 +02:00
|
|
|
|
2012-02-25 04:22:35 +01:00
|
|
|
io.deq.valid := maybe_full || enq_ptr != deq_ptr
|
2012-02-29 12:08:04 +01:00
|
|
|
io.enq.ready := !maybe_full || enq_ptr != deq_ptr || (if (pipe) io.deq.ready else Bool(false))
|
2012-02-12 02:20:33 +01:00
|
|
|
io.deq.bits <> Mem(entries, do_enq, enq_ptr, io.enq.bits).read(deq_ptr)
|
2011-10-26 08:02:47 +02:00
|
|
|
}
|
2012-02-29 23:21:42 +01:00
|
|
|
|
|
|
|
object Queue
|
|
|
|
{
|
|
|
|
def apply[T <: Data](enq: ioDecoupled[T], entries: Int = 2, pipe: Boolean = false) = {
|
|
|
|
val q = (new queue(entries, pipe)) { enq.bits.clone }
|
|
|
|
q.io.enq <> enq
|
|
|
|
q.io.deq
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class pipereg[T <: Data]()(data: => T) extends Component
|
|
|
|
{
|
|
|
|
val io = new Bundle {
|
|
|
|
val enq = new ioValid()(data)
|
|
|
|
val deq = new ioValid()(data).flip
|
|
|
|
}
|
|
|
|
|
|
|
|
//val bits = Reg() { io.enq.bits.clone }
|
|
|
|
//when (io.enq.valid) {
|
|
|
|
// bits := io.enq.bits
|
|
|
|
//}
|
|
|
|
|
|
|
|
io.deq.valid := Reg(io.enq.valid, resetVal = Bool(false))
|
|
|
|
io.deq.bits <> Mem(1, io.enq.valid, UFix(0), io.enq.bits).read(UFix(0))
|
|
|
|
}
|
|
|
|
|
2012-03-02 03:49:00 +01:00
|
|
|
object Pipe
|
2012-02-29 23:21:42 +01:00
|
|
|
{
|
2012-03-02 03:49:00 +01:00
|
|
|
def apply[T <: Data](enq: ioValid[T], latency: Int = 1): ioValid[T] = {
|
2012-02-29 23:21:42 +01:00
|
|
|
val q = (new pipereg) { enq.bits.clone }
|
|
|
|
q.io.enq <> enq
|
|
|
|
q.io.deq
|
2012-03-02 03:49:00 +01:00
|
|
|
|
|
|
|
if (latency > 1)
|
|
|
|
Pipe(q.io.deq, latency-1)
|
|
|
|
else
|
|
|
|
q.io.deq
|
2012-02-29 23:21:42 +01:00
|
|
|
}
|
|
|
|
}
|