Add custom csr gpio example
This commit is contained in:
parent
b7d8ed8a81
commit
f13dba847c
|
@ -1,6 +1,8 @@
|
|||
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}
|
||||
|
||||
|
@ -32,3 +34,30 @@ class CustomCsrDemoPlugin extends Plugin[VexRiscv]{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ object GenCustomCsr extends App{
|
|||
plugins = List(
|
||||
new CustomCsrDemoPlugin,
|
||||
new CsrPlugin(CsrPluginConfig.small),
|
||||
new CustomCsrDemoGpioPlugin,
|
||||
new PcManagerSimplePlugin(
|
||||
resetVector = 0x00000000l,
|
||||
relaxedPcCalculation = false
|
||||
|
|
|
@ -55,7 +55,11 @@ case class CsrPluginConfig(
|
|||
}
|
||||
|
||||
object CsrPluginConfig{
|
||||
val all = CsrPluginConfig(
|
||||
def all : CsrPluginConfig = all(0x00000020l)
|
||||
def small : CsrPluginConfig = small(0x00000020l)
|
||||
def smallest : CsrPluginConfig = smallest(0x00000020l)
|
||||
|
||||
def all(mtvecInit : BigInt) : CsrPluginConfig = CsrPluginConfig(
|
||||
catchIllegalAccess = true,
|
||||
mvendorid = 11,
|
||||
marchid = 22,
|
||||
|
@ -64,7 +68,7 @@ object CsrPluginConfig{
|
|||
misaExtensionsInit = 66,
|
||||
misaAccess = CsrAccess.READ_WRITE,
|
||||
mtvecAccess = CsrAccess.READ_WRITE,
|
||||
mtvecInit = 0x00000020l,
|
||||
mtvecInit = mtvecInit,
|
||||
mepcAccess = CsrAccess.READ_WRITE,
|
||||
mscratchGen = true,
|
||||
mcauseAccess = CsrAccess.READ_WRITE,
|
||||
|
@ -76,7 +80,7 @@ object CsrPluginConfig{
|
|||
ucycleAccess = CsrAccess.READ_ONLY
|
||||
)
|
||||
|
||||
val small = CsrPluginConfig(
|
||||
def small(mtvecInit : BigInt) = CsrPluginConfig(
|
||||
catchIllegalAccess = false,
|
||||
mvendorid = null,
|
||||
marchid = null,
|
||||
|
@ -85,7 +89,7 @@ object CsrPluginConfig{
|
|||
misaExtensionsInit = 66,
|
||||
misaAccess = CsrAccess.NONE,
|
||||
mtvecAccess = CsrAccess.NONE,
|
||||
mtvecInit = 0x00000020l,
|
||||
mtvecInit = mtvecInit,
|
||||
mepcAccess = CsrAccess.READ_WRITE,
|
||||
mscratchGen = false,
|
||||
mcauseAccess = CsrAccess.READ_ONLY,
|
||||
|
@ -97,7 +101,7 @@ object CsrPluginConfig{
|
|||
ucycleAccess = CsrAccess.NONE
|
||||
)
|
||||
|
||||
val smallest = CsrPluginConfig(
|
||||
def smallest(mtvecInit : BigInt) = CsrPluginConfig(
|
||||
catchIllegalAccess = false,
|
||||
mvendorid = null,
|
||||
marchid = null,
|
||||
|
@ -106,7 +110,7 @@ object CsrPluginConfig{
|
|||
misaExtensionsInit = 66,
|
||||
misaAccess = CsrAccess.NONE,
|
||||
mtvecAccess = CsrAccess.NONE,
|
||||
mtvecInit = 0x00000020l,
|
||||
mtvecInit = mtvecInit,
|
||||
mepcAccess = CsrAccess.NONE,
|
||||
mscratchGen = false,
|
||||
mcauseAccess = CsrAccess.READ_ONLY,
|
||||
|
@ -146,6 +150,7 @@ trait CsrInterface{
|
|||
def rw(csrAddress : Int, thats : (Int, Data)*) : Unit = for(that <- thats) rw(csrAddress,that._1, that._2)
|
||||
def r [T <: Data](csrAddress : Int, thats : (Int, Data)*) : Unit = for(that <- thats) r(csrAddress,that._1, that._2)
|
||||
def rw[T <: Data](csrAddress : Int, that : T): Unit = rw(csrAddress,0,that)
|
||||
def w[T <: Data](csrAddress : Int, that : T): Unit = w(csrAddress,0,that)
|
||||
def r [T <: Data](csrAddress : Int, that : T): Unit = r(csrAddress,0,that)
|
||||
def isWriting(csrAddress : Int) : Bool = {
|
||||
val ret = False
|
||||
|
|
Loading…
Reference in New Issue