Skip to content
This repository has been archived by the owner on Jun 16, 2024. It is now read-only.

Commit

Permalink
ecp5: add buffers.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 29, 2024
1 parent cf6475e commit cdce3c8
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/ee/hrzn/chryse/ChryseApp.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import org.rogach.scallop._

import scala.collection.mutable

// TODO: Restore sbt plugin to attach rm of buildDir to clean.
// TODO: some platform may program in different ways (ULX3S: flash or SRAM).

abstract class ChryseApp {
val name: String
Expand Down
45 changes: 39 additions & 6 deletions src/main/scala/ee/hrzn/chryse/platform/ecp5/ECP5Top.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ee.hrzn.chryse.platform.ecp5

import chisel3._
import chisel3.util.unsignedBitLength
import ee.hrzn.chryse.chisel.directionOf
import ee.hrzn.chryse.platform.ChryseTop
import ee.hrzn.chryse.platform.Platform
import ee.hrzn.chryse.platform.PlatformBoard
Expand Down Expand Up @@ -28,30 +30,61 @@ class ECP5Top[Top <: Module](
PlatformConnectResultFallthrough
}

private val clki = Wire(Clock())
override protected def platformPort[HW <: Data](
res: ResourceData[HW],
topIo: Data,
portIo: Data,
) = {
directionOf(portIo) match {
case directionOf.Input =>
val ib = Module(new IB).suggestName(s"${res.name.get}_IB")
ib.I := portIo
topIo := ib.O
case directionOf.Output =>
val obz = Module(new OBZ).suggestName(s"${res.name.get}_OBZ")
obz.T := false.B // OE=1
obz.I := topIo
portIo := obz.O
}
}

private val clk = Wire(Clock())

private val gsr0 = Wire(Bool())
private val i0 = Module(new FD1S3AX)
i0.CK := clki
i0.CK := clk
i0.D := true.B
gsr0 := i0.Q

private val gsr1 = Wire(Bool())
private val i1 = Module(new FD1S3AX)
i1.CK := clki
i1.CK := clk
i1.D := gsr0
gsr1 := i1.Q

private val sgsr = Module(new SGSR)
sgsr.CLK := clki
sgsr.CLK := clk
sgsr.GSR := gsr1

// Provide a POR so RegNexts get their value.
private val timerLimit = 2
private val resetTimerReg =
withClock(clk)(Reg(UInt(unsignedBitLength(timerLimit).W)))
private val reset = Wire(Bool())

when(resetTimerReg === timerLimit.U) {
reset := false.B
}.otherwise {
reset := true.B
resetTimerReg := resetTimerReg + 1.U
}

private val top =
withClockAndReset(clki, false.B)(Module(genTop))
withClockAndReset(clk, reset)(Module(genTop))

// TODO (ECP5): allow clock source override.

val connectedResources = connectResources(platform, Some(clki))
val connectedResources = connectResources(platform, Some(clk))

val lpf = LPF(
connectedResources
Expand Down
9 changes: 9 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ecp5/IB.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ee.hrzn.chryse.platform.ecp5

import chisel3._
import chisel3.experimental.ExtModule

class IB extends ExtModule {
val I = IO(Input(Bool()))
val O = IO(Output(Bool()))
}
10 changes: 10 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ecp5/OBZ.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package ee.hrzn.chryse.platform.ecp5

import chisel3._
import chisel3.experimental.ExtModule

class OBZ extends ExtModule {
val T = IO(Input(Bool())) // inverted OE
val I = IO(Input(Bool()))
val O = IO(Output(Bool()))
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class ULX3SPlatformResources extends PlatformBoardResources {
)
.withAttributes("PULLMODE" -> "NONE", "DRIVE" -> "4")

val butt0 = Button().inverted.onPin("D6").withAttributes("PULLMODE" -> "UP")
// val buttons =
// DIP switches
// UART
Expand Down
1 change: 0 additions & 1 deletion src/main/scala/ee/hrzn/chryse/platform/ice40/SB_IO.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package ee.hrzn.chryse.platform.ice40

import chisel3._
import chisel3.experimental.Analog
import chisel3.experimental.ExtModule

class SB_IO(
Expand Down

0 comments on commit cdce3c8

Please sign in to comment.