Skip to content

Commit ff876fa

Browse files
author
Oron Port
committed
adjust slew rate to slowest/fastest global setting
1 parent 5f3baae commit ff876fa

File tree

7 files changed

+42
-10
lines changed

7 files changed

+42
-10
lines changed

compiler/ir/src/main/scala/dfhdl/compiler/ir/annotation.scala

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ object constraints:
8585
).filter(_.nonEmpty).mkString(", ")
8686
s"""@deviceID($params)"""
8787
end DeviceID
88+
final case class DeviceInfo(
89+
slewRateSlowest: ConfigN[Int],
90+
slewRateFastest: ConfigN[Int]
91+
) extends GlobalConstraint
92+
derives CanEqual, ReadWriter:
93+
protected def `prot_=~`(that: HWAnnotation)(using MemberGetSet): Boolean = this == that
94+
lazy val getRefs: List[DFRef.TwoWayAny] = Nil
95+
def copyWithNewRefs(using RefGen): this.type = this
96+
def codeString(using Printer): String =
97+
val params = List(
98+
csParam("slewRateSlowest", slewRateSlowest),
99+
csParam("slewRateFastest", slewRateFastest)
100+
).filter(_.nonEmpty).mkString(", ")
101+
s"""@deviceInfo($params)"""
102+
end DeviceInfo
88103
final case class DeviceProperties(properties: Map[String, String]) extends GlobalConstraint
89104
derives ReadWriter:
90105
protected def `prot_=~`(that: HWAnnotation)(using MemberGetSet): Boolean = this == that
@@ -264,7 +279,8 @@ object constraints:
264279
case SchmittTrigger =>
265280
throw new IllegalArgumentException("Found unexpected use of SchmittTrigger.")
266281
enum SlewRate extends StableEnum, HasCodeString derives CanEqual, ReadWriter:
267-
case SLOW, FAST
282+
case SLOWEST, FASTEST
283+
case CUSTOM(value: Int)
268284
def codeString(using Printer): String = "io.SlewRate." + this.toString
269285
enum PullMode extends StableEnum, HasCodeString derives CanEqual, ReadWriter:
270286
case UP, DOWN

core/src/main/scala/dfhdl/hw/annotation.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ object constraints:
7878
ir.constraints.DeviceID(vendor, deviceName, partName, deviceVersion)
7979
object deviceID:
8080
export ir.constraints.DeviceID.Vendor
81+
final case class deviceInfo(
82+
slewRateSlowest: ir.ConfigN[Int] = None,
83+
slewRateFastest: ir.ConfigN[Int] = None
84+
) extends GlobalConstraint:
85+
val asIR: ir.constraints.DeviceInfo =
86+
ir.constraints.DeviceInfo(slewRateSlowest, slewRateFastest)
8187
final case class deviceProperties(properties: (String, String)*) extends GlobalConstraint:
8288
val asIR: ir.constraints.DeviceProperties = ir.constraints.DeviceProperties(properties.toMap)
8389
final case class toolOptions(options: (String, String)*) extends GlobalConstraint:

lib/src/main/scala/dfhdl/platforms/resources/Led.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ object Led:
1111
private val pullMode = if (activeState == Led.On) IO.PullMode.DOWN else IO.PullMode.UP
1212
injectConstraint(IO(
1313
standard = IO.Standard.LVCMOS,
14-
slewRate = IO.SlewRate.SLOW,
14+
slewRate = IO.SlewRate.SLOWEST,
1515
unusedPullMode = pullMode
1616
))
1717
injectConstraint(Timing.Ignore(maxFreqMinPeriod = 100.Hz))

lib/src/main/scala/dfhdl/platforms/resources/SevenSegDisplay.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object SevenSegDisplay:
2424
enum Segment extends Encoded.Toggle:
2525
case Off, On
2626
object Segment:
27-
@io(standard = io.Standard.LVCMOS, slewRate = io.SlewRate.SLOW)
27+
@io(standard = io.Standard.LVCMOS, slewRate = io.SlewRate.SLOWEST)
2828
@timing.ignore(maxFreqMinPeriod = 200.us)
2929
protected[SevenSegDisplay] class Resource private[Segment] (val activeState: Segment)
3030
extends ToggleIO[Segment]
@@ -38,7 +38,7 @@ object SevenSegDisplay:
3838
private val pullMode = if (activeState == Select.Enabled) IO.PullMode.DOWN else IO.PullMode.UP
3939
injectConstraint(IO(
4040
standard = IO.Standard.LVCMOS,
41-
slewRate = IO.SlewRate.SLOW,
41+
slewRate = IO.SlewRate.SLOWEST,
4242
unusedPullMode = pullMode
4343
))
4444
injectConstraint(Timing.Ignore(maxFreqMinPeriod = 200.us))

lib/src/main/scala/dfhdl/tools/toolsCore/QuartusPrime.scala

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ class QuartusPrimeProjectPhysicalConstraintsPrinter(using
154154
val pro: Boolean = designDB.top.dclMeta.annotations.collectFirst {
155155
case constraints.DeviceID(vendor = constraints.DeviceID.Vendor.AlteraIntel(pro)) => pro
156156
}.get
157+
val deviceInfo: constraints.DeviceInfo = designDB.top.dclMeta.annotations.collectFirst {
158+
case constraint: constraints.DeviceInfo => constraint
159+
}.getOrElse(throw new IllegalArgumentException("No device info found"))
157160

158161
def qsf_get_ports(port: DFVal.Dcl, constraint: constraints.SigConstraint): String =
159162
val portName = port.getName
@@ -201,9 +204,14 @@ class QuartusPrimeProjectPhysicalConstraintsPrinter(using
201204
portConstraint.slewRate.foreach { slewRate =>
202205
// TODO: what about other slew rate values?
203206
val slewRateStr = slewRate match
204-
case constraints.IO.SlewRate.SLOW => "0"
205-
case constraints.IO.SlewRate.FAST => "2"
206-
addInstanceAssignment("SLEW_RATE", "2")
207+
case constraints.IO.SlewRate.SLOWEST => deviceInfo.slewRateSlowest.getOrElse(
208+
throw new IllegalArgumentException("Slowest slew rate not found in device info")
209+
).toString
210+
case constraints.IO.SlewRate.FASTEST => deviceInfo.slewRateFastest.getOrElse(
211+
throw new IllegalArgumentException("Fastest slew rate not found in device info")
212+
).toString
213+
case constraints.IO.SlewRate.CUSTOM(value) => value.toString
214+
addInstanceAssignment("SLEW_RATE", slewRateStr)
207215
}
208216

209217
// Drive strength constraint

lib/src/main/scala/dfhdl/tools/toolsCore/Vivado.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,10 @@ class VivadoProjectConstraintsPrinter(using
225225
// Slew rate constraint
226226
portConstraint.slewRate.foreach { slewRate =>
227227
val slewRateStr = slewRate match
228-
case constraints.IO.SlewRate.SLOW => "SLOW"
229-
case constraints.IO.SlewRate.FAST => "FAST"
228+
case constraints.IO.SlewRate.SLOWEST => "SLOW"
229+
case constraints.IO.SlewRate.FASTEST => "FAST"
230+
case constraints.IO.SlewRate.CUSTOM(value) =>
231+
throw new IllegalArgumentException(s"Custom slew rate is not supported in Vivado.")
230232
addToDict("SLEW", slewRateStr)
231233
}
232234

0 commit comments

Comments
 (0)