Advertisement
vrangan

SpinalHDL AXI crossbar with 2 SRAM's

Jan 5th, 2024
1,591
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 2.26 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.  
  9. import spinal.lib.misc.HexTools
  10.  
  11. import scala.collection.mutable.ArrayBuffer
  12. import scala.collection.Seq
  13.  
  14. class TinyClunx(
  15.                 onChipRamSize : BigInt
  16.                 ) extends Component{
  17.  
  18.     val axiConfig = Axi4Config(
  19.     addressWidth = 17,
  20.     dataWidth    = 64,
  21.     idWidth      = 3,
  22.     useRegion    = false,
  23.     useLock      = false,
  24.     useQos      = false,
  25.     useResp = false,
  26.     useProt=false,
  27.     useStrb=false
  28.         )
  29.  
  30.   val debug = true
  31.  
  32.   val io = new Bundle{
  33.     //Clocks / reset
  34.     val axiReset = in Bool()
  35.     val axiClk   = in Bool()
  36.     val axiM1    = slave(Axi4(axiConfig))
  37.     val axiM2    = slave(Axi4(axiConfig))
  38.     //val axiM1    = slave(Axi4Shared(axiConfig))
  39.     //val axiM2    = slave(Axi4Shared(axiConfig))
  40.   }
  41.  
  42.   val axiClockDomain = ClockDomain(
  43.     clock = io.axiClk,
  44.     reset = io.axiReset
  45.     )
  46.  
  47.   val axi1 = new ClockingArea(axiClockDomain) {
  48.     val ram1 = Axi4SharedOnChipRam(
  49.       dataWidth = 64,
  50.       byteCount = onChipRamSize,
  51.       idWidth = axiConfig.idWidth+1
  52.     )
  53.  
  54.     val ram2 = Axi4SharedOnChipRam(
  55.       dataWidth = 64,
  56.       byteCount = onChipRamSize,
  57.       idWidth = axiConfig.idWidth+1
  58.     )
  59.  
  60.     val axiCrossbar = Axi4CrossbarFactory()
  61.  
  62.     axiCrossbar.addSlaves(
  63.       ram1.io.axi       -> (0x00000000L,   onChipRamSize),
  64.       ram2.io.axi       -> (0x00010000L,   onChipRamSize)
  65.     )
  66.  
  67.     axiCrossbar.addConnections(
  68.       io.axiM2        -> List(ram1.io.axi, ram2.io.axi),
  69.       io.axiM1        -> List(ram1.io.axi, ram2.io.axi)
  70.     )
  71.  
  72.  
  73.     axiCrossbar.build()
  74.  
  75.   }
  76.  
  77. }
  78.  
  79. object TinyClunx{
  80.   def main(args: Array[String]) {
  81.     val config = SpinalConfig()
  82.     config.generateVerilog({
  83.       val toplevel = new TinyClunx(onChipRamSize = 8 kB)
  84.       toplevel
  85.     })
  86.   }
  87. }
  88.  
  89. // With memory init
  90. object TinyCClunxWithMemoryInit{
  91.   def main(args: Array[String]) {
  92.     val config = SpinalConfig()
  93.     config.generateVerilog({
  94.       val toplevel = new TinyClunx(onChipRamSize = 8 kB)
  95.       HexTools.initRam(toplevel.axi1.ram1.ram, "src/main/ressource/hex/muraxDemo.hex", 0x80000000l)
  96.       toplevel
  97.     })
  98.   }
  99. }
  100.  
  101.  
Tags: spinalhdl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement