X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmain%2Fscala%2Fdevices%2Fpinctrl%2FPinCtrl.scala;fp=src%2Fmain%2Fscala%2Fdevices%2Fpinctrl%2FPinCtrl.scala;h=f487d390963d2e44d7261b27644466b42e97d7b0;hb=86010395adffd9ee4a42f5240b08bb0f243972ff;hp=0000000000000000000000000000000000000000;hpb=5e51e1e93172b5c5b6c436196f8dad68678eb93d;p=sifive-blocks.git diff --git a/src/main/scala/devices/pinctrl/PinCtrl.scala b/src/main/scala/devices/pinctrl/PinCtrl.scala new file mode 100644 index 0000000..f487d39 --- /dev/null +++ b/src/main/scala/devices/pinctrl/PinCtrl.scala @@ -0,0 +1,103 @@ +//See LICENSE for license details + +package sifive.blocks.devices.pinctrl + +import Chisel._ + +// This is the base class of things you "always" +// want to control from a HW block. +class PinCtrl extends Bundle { + val oval = Bool() + val oe = Bool() + val ie = Bool() +} + +// Package up the inputs and outputs +// for the Pin +abstract class Pin extends Bundle { + val i = new Bundle { + val ival = Bool(INPUT) + } + val o: PinCtrl + + // Must be defined by the subclasses + def default(): Unit + def inputPin(pue: Bool = Bool(false)): Bool + def outputPin(signal: Bool, + pue: Bool = Bool(false), + ds: Bool = Bool(false), + ie: Bool = Bool(false) + ): Unit + +} + + +//////////////////////////////////////////////////////////////////////////////////// + +class BasePin extends Pin() { + val o = new PinCtrl().asOutput + + def default(): Unit = { + this.o.oval := Bool(false) + this.o.oe := Bool(false) + this.o.ie := Bool(false) + } + + def inputPin(pue: Bool = Bool(false) /*ignored*/): Bool = { + this.o.oval := Bool(false) + this.o.oe := Bool(false) + this.o.ie := Bool(true) + this.i.ival + } + + def outputPin(signal: Bool, + pue: Bool = Bool(false), /*ignored*/ + ds: Bool = Bool(false), /*ignored*/ + ie: Bool = Bool(false) + ): Unit = { + this.o.oval := signal + this.o.oe := Bool(true) + this.o.ie := ie + } +} + +///////////////////////////////////////////////////////////////////////// +class EnhancedPinCtrl extends PinCtrl { + val pue = Bool() + val ds = Bool() +} + +class EnhancedPin extends Pin() { + + val o = new EnhancedPinCtrl().asOutput + + def default(): Unit = { + this.o.oval := Bool(false) + this.o.oe := Bool(false) + this.o.ie := Bool(false) + this.o.ds := Bool(false) + this.o.pue := Bool(false) + } + + def inputPin(pue: Bool = Bool(false)): Bool = { + this.o.oval := Bool(false) + this.o.oe := Bool(false) + this.o.pue := pue + this.o.ds := Bool(false) + this.o.ie := Bool(true) + + this.i.ival + } + + def outputPin(signal: Bool, + pue: Bool = Bool(false), + ds: Bool = Bool(false), + ie: Bool = Bool(false) + ): Unit = { + this.o.oval := signal + this.o.oe := Bool(true) + this.o.pue := pue + this.o.ds := ds + this.o.ie := ie + } +}