AXI4BurstMaster.scala 1.6 KB
Newer Older
L
linjiawei 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
package device

import chipsalliance.rocketchip.config._
import chisel3._
import chisel3.util._
import chiseltest._
import freechips.rocketchip.amba.axi4.{AXI4Deinterleaver, AXI4MasterNode, AXI4MasterParameters, AXI4MasterPortParameters, AXI4Parameters, AXI4UserYanker}
import freechips.rocketchip.diplomacy._

class AXI4BurstMaster
(
  startAddr: Long = 0,
  nOp: Int = 1,
  beatBytes: Int = 8,
  burstLen: Int = 16,
  idRange: IdRange = IdRange(0, 1)
)(implicit p: Parameters) extends LazyModule {

  val node = AXI4MasterNode(Seq(AXI4MasterPortParameters(
    Seq(AXI4MasterParameters("burst master", idRange))
  )))

  lazy val module = new LazyModuleImp(this){

    val io = IO(new Bundle{
      val finished = Output(Bool())
    })

    val (out, edge) = node.out.head
    val cnt = RegInit(nOp.U)
    val addr = RegInit(startAddr.U)
    val s_idle :: s_addr :: s_data :: Nil = Enum(3)
    val state = RegInit(s_idle)
    val ar = out.ar
    val r = out.r
    switch(state){
      is(s_idle){
        when(cnt =/= 0.U){
          state := s_addr
        }
      }
      is(s_addr){
        when(ar.ready){
          state := s_data
        }
      }
      is(s_data){
        when(r.valid){
          addr := addr + beatBytes.U
        }
        when(r.valid && r.bits.last){
          state := s_idle
          cnt := cnt - 1.U
        }
      }
    }

    io.finished := cnt === 0.U

    ar.valid := state === s_addr
    ar.bits.addr := addr
    ar.bits.size := log2Up(beatBytes).U
    ar.bits.len := (burstLen-1).U
    ar.bits.burst := AXI4Parameters.BURST_INCR

    r.ready := state === s_data
  }
}