diff options
author | Friedrich Beckmann <friedrich.beckmann@hs-augsburg.de> | 2022-07-25 17:55:39 +0200 |
---|---|---|
committer | Friedrich Beckmann <friedrich.beckmann@hs-augsburg.de> | 2022-07-25 17:55:39 +0200 |
commit | 3fff6023602822531efdae30bc8ebf862967f1ef (patch) | |
tree | 16028102b8d850f8ab3115d28a8539ca6bc5f51d /VexRiscv/src/main/scala/vexriscv/demo/CustomCsrDemoPlugin.scala |
Initial Commit
Diffstat (limited to 'VexRiscv/src/main/scala/vexriscv/demo/CustomCsrDemoPlugin.scala')
-rw-r--r-- | VexRiscv/src/main/scala/vexriscv/demo/CustomCsrDemoPlugin.scala | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/VexRiscv/src/main/scala/vexriscv/demo/CustomCsrDemoPlugin.scala b/VexRiscv/src/main/scala/vexriscv/demo/CustomCsrDemoPlugin.scala new file mode 100644 index 0000000..a763c83 --- /dev/null +++ b/VexRiscv/src/main/scala/vexriscv/demo/CustomCsrDemoPlugin.scala @@ -0,0 +1,63 @@ +package vexriscv.demo + +import spinal.core._ +import spinal.lib.io.TriStateArray +import spinal.lib.{Flow, master} +import vexriscv.plugin.{CsrInterface, Plugin} +import vexriscv.{DecoderService, Stageable, VexRiscv} + + + +class CustomCsrDemoPlugin extends Plugin[VexRiscv]{ + override def build(pipeline: VexRiscv): Unit = { + import pipeline._ + import pipeline.config._ + + pipeline plug new Area{ + val instructionCounter = Reg(UInt(32 bits)) + val cycleCounter = Reg(UInt(32 bits)) + + cycleCounter := cycleCounter + 1 + when(writeBack.arbitration.isFiring) { + instructionCounter := instructionCounter + 1 + } + + val csrService = pipeline.service(classOf[CsrInterface]) + csrService.rw(0xB04, instructionCounter) + csrService.r(0xB05, cycleCounter) + csrService.onWrite(0xB06){ + instructionCounter := 0 + } + csrService.onRead(0xB07){ + instructionCounter := 0x40000000 + } + } + } +} + + +class CustomCsrDemoGpioPlugin extends Plugin[VexRiscv]{ + var gpio : TriStateArray = null + + + override def setup(pipeline: VexRiscv): Unit = { + gpio = master(TriStateArray(32 bits)).setName("gpio") + } + + override def build(pipeline: VexRiscv): Unit = { + import pipeline._ + import pipeline.config._ + + pipeline plug new Area{ + val writeReg, writeEnableReg = Reg(Bits(32 bits)) + + val csrService = pipeline.service(classOf[CsrInterface]) + csrService.rw(0xB08, writeReg) + csrService.rw(0xB09, writeEnableReg) + csrService.r(0xB0A, gpio.read) + + gpio.writeEnable := writeEnableReg + gpio.write := writeReg + } + } +} |