Add custom csr gpio example

This commit is contained in:
Dolu1990 2018-02-02 11:14:55 +01:00
parent b7d8ed8a81
commit f13dba847c
3 changed files with 41 additions and 6 deletions

View file

@ -1,6 +1,8 @@
package vexriscv.demo package vexriscv.demo
import spinal.core._ import spinal.core._
import spinal.lib.io.TriStateArray
import spinal.lib.{Flow, master}
import vexriscv.plugin.{CsrInterface, Plugin} import vexriscv.plugin.{CsrInterface, Plugin}
import vexriscv.{DecoderService, Stageable, VexRiscv} 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
}
}
}

View file

@ -15,6 +15,7 @@ object GenCustomCsr extends App{
plugins = List( plugins = List(
new CustomCsrDemoPlugin, new CustomCsrDemoPlugin,
new CsrPlugin(CsrPluginConfig.small), new CsrPlugin(CsrPluginConfig.small),
new CustomCsrDemoGpioPlugin,
new PcManagerSimplePlugin( new PcManagerSimplePlugin(
resetVector = 0x00000000l, resetVector = 0x00000000l,
relaxedPcCalculation = false relaxedPcCalculation = false

View file

@ -55,7 +55,11 @@ case class CsrPluginConfig(
} }
object 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, catchIllegalAccess = true,
mvendorid = 11, mvendorid = 11,
marchid = 22, marchid = 22,
@ -64,7 +68,7 @@ object CsrPluginConfig{
misaExtensionsInit = 66, misaExtensionsInit = 66,
misaAccess = CsrAccess.READ_WRITE, misaAccess = CsrAccess.READ_WRITE,
mtvecAccess = CsrAccess.READ_WRITE, mtvecAccess = CsrAccess.READ_WRITE,
mtvecInit = 0x00000020l, mtvecInit = mtvecInit,
mepcAccess = CsrAccess.READ_WRITE, mepcAccess = CsrAccess.READ_WRITE,
mscratchGen = true, mscratchGen = true,
mcauseAccess = CsrAccess.READ_WRITE, mcauseAccess = CsrAccess.READ_WRITE,
@ -76,7 +80,7 @@ object CsrPluginConfig{
ucycleAccess = CsrAccess.READ_ONLY ucycleAccess = CsrAccess.READ_ONLY
) )
val small = CsrPluginConfig( def small(mtvecInit : BigInt) = CsrPluginConfig(
catchIllegalAccess = false, catchIllegalAccess = false,
mvendorid = null, mvendorid = null,
marchid = null, marchid = null,
@ -85,7 +89,7 @@ object CsrPluginConfig{
misaExtensionsInit = 66, misaExtensionsInit = 66,
misaAccess = CsrAccess.NONE, misaAccess = CsrAccess.NONE,
mtvecAccess = CsrAccess.NONE, mtvecAccess = CsrAccess.NONE,
mtvecInit = 0x00000020l, mtvecInit = mtvecInit,
mepcAccess = CsrAccess.READ_WRITE, mepcAccess = CsrAccess.READ_WRITE,
mscratchGen = false, mscratchGen = false,
mcauseAccess = CsrAccess.READ_ONLY, mcauseAccess = CsrAccess.READ_ONLY,
@ -97,7 +101,7 @@ object CsrPluginConfig{
ucycleAccess = CsrAccess.NONE ucycleAccess = CsrAccess.NONE
) )
val smallest = CsrPluginConfig( def smallest(mtvecInit : BigInt) = CsrPluginConfig(
catchIllegalAccess = false, catchIllegalAccess = false,
mvendorid = null, mvendorid = null,
marchid = null, marchid = null,
@ -106,7 +110,7 @@ object CsrPluginConfig{
misaExtensionsInit = 66, misaExtensionsInit = 66,
misaAccess = CsrAccess.NONE, misaAccess = CsrAccess.NONE,
mtvecAccess = CsrAccess.NONE, mtvecAccess = CsrAccess.NONE,
mtvecInit = 0x00000020l, mtvecInit = mtvecInit,
mepcAccess = CsrAccess.NONE, mepcAccess = CsrAccess.NONE,
mscratchGen = false, mscratchGen = false,
mcauseAccess = CsrAccess.READ_ONLY, 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 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 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 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 r [T <: Data](csrAddress : Int, that : T): Unit = r(csrAddress,0,that)
def isWriting(csrAddress : Int) : Bool = { def isWriting(csrAddress : Int) : Bool = {
val ret = False val ret = False