Advertisement
vrangan

Untitled

Jan 7th, 2024
2,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 3.52 KB | None | 0 0
  1. package vexriscv.demo
  2.  
  3.  
  4. import spinal.core._
  5. import spinal.lib._
  6. import spinal.lib.bus.amba3.apb._
  7. import spinal.lib.bus.amba4.axi._
  8. import spinal.lib.io.{TriStateArray, TriState}
  9.  
  10. import spinal.lib.misc.HexTools
  11.  
  12. import scala.collection.mutable.ArrayBuffer
  13. import scala.collection.Seq
  14.  
  15. case class USB23_IO() extends Bundle with IMasterSlave {
  16.   val VBUS         = Analog(Bits(1 bits))
  17.   val DM            = Analog(Bits(1 bits))
  18.   val DP            = Analog(Bits(1 bits))
  19.   val REFINCLKEXTP = Analog(Bits(1 bits))
  20.   val REFINCLKEXTM = Analog(Bits(1 bits))
  21.   val RESEXTUSB2     = Analog(Bits(1 bits))
  22.   val RXP         = Analog(Bits(1 bits))
  23.   val RXM         = Analog(Bits(1 bits))
  24.   val TXP         = Analog(Bits(1 bits))
  25.   val TXM         = Analog(Bits(1 bits))
  26.   val clkIn = Bool
  27.   val dOut = Bool
  28.  
  29.   override def asMaster() : Unit = {
  30.     out(dOut)
  31.     in(clkIn)
  32.     inout(VBUS, DM, DP, REFINCLKEXTM, REFINCLKEXTP, RESEXTUSB2, RXM, RXP,
  33.           TXM, TXP)
  34.   }
  35. }
  36.  
  37. case class USB23() extends BlackBox {
  38.   val io = new Bundle {
  39.     val clkIn = in Bool()
  40.     val io    = master(USB23_IO())
  41.   }
  42.   noIoPrefix()
  43. }
  44.  
  45. class TinyClunx(
  46.                 onChipRamSize : BigInt
  47.                 ) extends Component{
  48.  
  49.     val axiMConfig = Axi4Config(
  50.     addressWidth = 17,
  51.     dataWidth    = 64,
  52.     idWidth      = 3,
  53.     useRegion    = false,
  54.     useLock      = false,
  55.     useQos      = false,
  56.     useResp = false,
  57.     useProt=false,
  58.     useStrb=false
  59.         )
  60.  
  61.     val axiSConfig = Axi4Config(
  62.     addressWidth = 17,
  63.     dataWidth    = 64,
  64.     idWidth      = 4,
  65.     useRegion    = false,
  66.     useLock      = false,
  67.     useQos      = false,
  68.     useResp = false,
  69.     useProt=false,
  70.     useStrb=false
  71.     )
  72.  
  73.   val io = new Bundle{
  74.     //Clocks / reset
  75.     val axiReset = in Bool()
  76.     val axiClk   = in Bool()
  77.     val axiM1    = slave(Axi4(axiMConfig))
  78.     //val usbIO    = master(USB23_IO())
  79.     val axiM2    = slave(Axi4Shared(axiMConfig))
  80.     val axiS1    = master(Axi4Shared(axiSConfig))
  81.   }
  82.   noIoPrefix()
  83.  
  84.   val axiClockDomain = ClockDomain(
  85.     clock = io.axiClk,
  86.     reset = io.axiReset
  87.     )
  88.  
  89.   val axi1 = new ClockingArea(axiClockDomain) {
  90.     val ram1 = Axi4SharedOnChipRam(
  91.       dataWidth = 64,
  92.       byteCount = onChipRamSize,
  93.       idWidth = axiMConfig.idWidth+1
  94.     )
  95.  
  96. /*
  97.     val ram2 = Axi4SharedOnChipRam(
  98.       dataWidth = 64,
  99.       byteCount = onChipRamSize,
  100.       idWidth = axiConfig.idWidth+1
  101.     )
  102. */
  103.     //val axiM2 = Axi4(axiConfig)
  104.  
  105.  
  106.     //val usbCore = new USB23
  107.  
  108.     val axiCrossbar = Axi4CrossbarFactory()
  109.  
  110.     axiCrossbar.addSlaves(
  111.       ram1.io.axi       -> (0x00000000L,   onChipRamSize),
  112.       io.axiS1          -> (0x00010000L,   onChipRamSize)
  113.     )
  114.  
  115.     axiCrossbar.addConnections(
  116.       io.axiM2        -> List(ram1.io.axi, io.axiS1),
  117.       io.axiM1        -> List(ram1.io.axi, io.axiS1)
  118.     )
  119.  
  120.     axiCrossbar.build()
  121.   }
  122.  
  123.     //usbCore.io.clkIn := io.axiClk
  124.     //io.usbIO := usbCore.io.io
  125. }
  126.  
  127. object TinyClunx{
  128.   def main(args: Array[String]) {
  129.     val config = SpinalConfig()
  130.     config.generateVerilog({
  131.       val toplevel = new TinyClunx(onChipRamSize = 8 kB)
  132.       toplevel
  133.     })
  134.   }
  135. }
  136.  
  137. // With memory init
  138. object TinyCClunxWithMemoryInit{
  139.   def main(args: Array[String]) {
  140.     val config = SpinalConfig()
  141.     config.generateVerilog({
  142.       val toplevel = new TinyClunx(onChipRamSize = 8 kB)
  143.       HexTools.initRam(toplevel.axi1.ram1.ram, "src/main/ressource/hex/muraxDemo.hex", 0x80000000l)
  144.       toplevel
  145.     })
  146.   }
  147. }
  148.  
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement