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

Commit

Permalink
init.
Browse files Browse the repository at this point in the history
  • Loading branch information
kivikakk committed May 8, 2024
0 parents commit 10135c6
Show file tree
Hide file tree
Showing 14 changed files with 251 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/dependency-graph.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Update Dependency Graph
on:
push:
branches:
- main

permissions:
contents: write

jobs:
dependency-graph:
name: Update Dependency Graph
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: scalacenter/sbt-dependency-submission@v2
24 changes: 24 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Unit tests

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 22
uses: actions/setup-java@v4
with:
java-version: '22'
distribution: 'temurin'
cache: 'sbt'
- name: Run tests
run: sbt test
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
target/
test_run_dir/

.metals/
.bloop/
metals.sbt

.DS_Store
47 changes: 47 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
version = "3.7.15"
runner.dialect = scala213

maxColumn = 80

newlines.avoidForSimpleOverflow = [slc, tooLong]

assumeStandardLibraryStripMargin = true

align.preset = most
align.multiline = false
align.tokens."+" = [
{ code = ":=", owner = "Term.ApplyInfix" },
{ code = "+=", owner = "Term.ApplyInfix" },
{ code = "++=", owner = "Term.ApplyInfix" },
{ code = "--=", owner = "Term.ApplyInfix" },
{ code = "-=", owner = "Term.ApplyInfix" },
]

binPack.literalArgumentLists = true
binPack.literalsIncludeSimpleExpr = true
binPack.literalsExclude = [ "Term.Name" ]

# do I care about this?
docstrings.style = "SpaceAsterisk"
docstrings.wrap = yes
docstrings.oneline = fold

rewrite.rules = [
AvoidInfix, # do I want this?
RedundantBraces,
RedundantParens,
SortModifiers,
PreferCurlyFors,
Imports,
]

rewrite.redundantBraces.maxBreaks = 1
rewrite.redundantBraces.stringInterpolation = true

rewrite.trailingCommas.style = always

# unsure.
# includeCurlyBraceInSelectChains = false

project.includePaths = ["glob:**.scala", "glob:**.sbt", "glob:**.sc", "glob:**.md"]
project.excludePaths = ["glob:**metals.sbt"]
22 changes: 22 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
ThisBuild / scalaVersion := "2.13.12"
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / organization := "ee.hrzn"

val chiselVersion = "6.3.0"

lazy val root = (project in file("."))
.settings(
name := "chryse",
libraryDependencies ++= Seq(
"org.chipsalliance" %% "chisel" % chiselVersion,
"org.scalatest" %% "scalatest" % "3.2.18" % "test",
"edu.berkeley.cs" %% "chiseltest" % "6.0.0",
),
scalacOptions ++= Seq(
"-language:reflectiveCalls", "-deprecation", "-feature", "-Xcheckinit",
"-Ymacro-annotations",
),
addCompilerPlugin(
"org.chipsalliance" % "chisel-plugin" % chiselVersion cross CrossVersion.full,
),
)
1 change: 1 addition & 0 deletions project/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sbt.version = 1.9.7
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
logLevel := Level.Warn
11 changes: 11 additions & 0 deletions src/main/scala/ee/hrzn/chryse/HasIO.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ee.hrzn.chryse

import chisel3._

// This looks a lot like the FixedIO*Module stuff.

trait HasIO[ContainedIO <: Data] extends RawModule {
def createIo(): ContainedIO

val io = IO(createIo())
}
21 changes: 21 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/GenericTop.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ee.hrzn.chryse.platform

import chisel3._
import ee.hrzn.chryse.HasIO
import ee.hrzn.chryse.platform.Platform

class GenericTop[Top <: HasIO[_ <: Data]](genTop: => Top)(implicit
platform: Platform,
) extends Module {
override def desiredName = "top"

private val top = Module(genTop)
private val io = IO(top.createIo())
io :<>= top.io.as[Data]
}

object GenericTop {
def apply[Top <: HasIO[_ <: Data]](genTop: => Top)(implicit
platform: Platform,
) = new GenericTop(genTop)
}
17 changes: 17 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package ee.hrzn.chryse.platform

import chisel3._
import ee.hrzn.chryse.HasIO

// Similar to chisel3.choice.ModuleChoice.

trait Platform {
val id: String
val clockHz: Int
}

trait ElaboratablePlatform extends Platform {
def apply[Top <: HasIO[_ <: Data]](top: => Top)(implicit
platform: Platform,
): RawModule
}
16 changes: 16 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/cxxrtl/CXXRTLPlatform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ee.hrzn.chryse.platform.cxxrtl

import chisel3._
import ee.hrzn.chryse.HasIO
import ee.hrzn.chryse.platform.ElaboratablePlatform
import ee.hrzn.chryse.platform.GenericTop
import ee.hrzn.chryse.platform.Platform

case object CXXRTLPlatform extends ElaboratablePlatform {
val id = "cxxrtl"
val clockHz = 3_000_000

override def apply[Top <: HasIO[_ <: Data]](top: => Top)(implicit
platform: Platform,
) = GenericTop(top)
}
15 changes: 15 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Platform.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ee.hrzn.chryse.platform.ice40

import chisel3._
import ee.hrzn.chryse.HasIO
import ee.hrzn.chryse.platform.ElaboratablePlatform
import ee.hrzn.chryse.platform.Platform

case object ICE40Platform extends ElaboratablePlatform {
val id = "ice40"
val clockHz = 12_000_000

override def apply[Top <: HasIO[_ <: Data]](top: => Top)(implicit
platform: Platform,
) = ICE40Top(top)
}
43 changes: 43 additions & 0 deletions src/main/scala/ee/hrzn/chryse/platform/ice40/ICE40Top.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package ee.hrzn.chryse.platform.ice40

import chisel3._
import chisel3.util._
import ee.hrzn.chryse.HasIO
import ee.hrzn.chryse.platform.Platform
import ee.hrzn.chryse.sb.SB_GB

class ICE40Top[Top <: HasIO[_ <: Data]](genTop: => Top)(implicit
platform: Platform,
) extends RawModule {
override def desiredName = "top"

private val clki = IO(Input(Clock()))

private val clk_gb = Module(new SB_GB)
clk_gb.USER_SIGNAL_TO_GLOBAL_BUFFER := clki
private val clk = clk_gb.GLOBAL_BUFFER_OUTPUT

private val timerLimit = (15e-6 * platform.clockHz).toInt
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 io_ubtn = IO(Input(Bool()))

private val top =
withClockAndReset(clk, reset | ~io_ubtn)(Module(genTop))
private val io = IO(top.createIo())
io :<>= top.io.as[Data]
}

object ICE40Top {
def apply[Top <: HasIO[_ <: Data]](genTop: => Top)(implicit
platform: Platform,
) = new ICE40Top(genTop)
}
9 changes: 9 additions & 0 deletions src/main/scala/ee/hrzn/chryse/sb/SB_GB.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ee.hrzn.chryse.sb

import chisel3._
import chisel3.experimental.ExtModule

class SB_GB extends ExtModule {
val USER_SIGNAL_TO_GLOBAL_BUFFER = IO(Input(Clock()))
val GLOBAL_BUFFER_OUTPUT = IO(Output(Clock()))
}

0 comments on commit 10135c6

Please sign in to comment.