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

Commit

Permalink
add switch case statements for functions of script eval
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaKarvandi committed May 28, 2024
1 parent fd4f259 commit bbd87ce
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

23 changes: 18 additions & 5 deletions src/main/scala/hwdbg/configs/configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ object DebuggerConfigurations {
//
val NUMBER_OF_PINS: Int = 32

//
// Maximum number of stages
//
val MAXIMUM_NUMBER_OF_STAGES: Int = 10

//
// Address width of the Block RAM (BRAM)
//
Expand All @@ -68,6 +63,24 @@ object DebuggerConfigurations {

}

/**
* @brief
* Design constants for script engine
*/
object ScriptEngineConfigurations {

//
// Maximum number of stages
//
val MAXIMUM_NUMBER_OF_STAGES: Int = 10

//
// Maximum number of stages
//
val MAXIMUM_NUMBER_OF_SUPPORTED_OPERATORS: Int = 2

}

/**
* @brief
* The constants for memory communication
Expand Down
38 changes: 38 additions & 0 deletions src/main/scala/hwdbg/globals/global_stages.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file
* global_stages.scala
* @author
* Sina Karvandi ([email protected])
* @brief
* Data types related to stage registers
* @details
* @version 0.1
* @date
* 2024-05-17
*
* @copyright
* This project is released under the GNU Public License v3.
*/
package hwdbg.stage

import chisel3._

import hwdbg.configs._

object GlobalStages {

//
// Stage registers
//
val stageRegs = Reg(
Vec(
ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
new StageRegisters(
DebuggerConfigurations.ENABLE_DEBUG,
DebuggerConfigurations.NUMBER_OF_PINS,
ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES
)
)
)

}
4 changes: 2 additions & 2 deletions src/main/scala/hwdbg/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import hwdbg.communication.interpreter._
class DebuggerMain(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
bramAddrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
bramDataWidth: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
Expand Down Expand Up @@ -191,7 +191,7 @@ object DebuggerMain {
def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
bramAddrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
bramDataWidth: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
Expand Down
57 changes: 49 additions & 8 deletions src/main/scala/hwdbg/script/eval.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,28 @@ import chisel3._
import chisel3.util._

import hwdbg.configs._
import hwdbg.utils._
import hwdbg.stage._

object ScriptEvalFunc {
object ScriptOperators extends ChiselEnum {
val sFuncInc, sFuncDec, sFuncDec2, sFuncDec3, sFuncDec4, sFuncDec5, sFuncDec6, sFuncDec7 = Value
}
}

class ScriptEngineEval(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
) extends Module {

//
// Import state enum
//
import ScriptEvalFunc.ScriptOperators
import ScriptEvalFunc.ScriptOperators._

val io = IO(new Bundle {

//
Expand All @@ -36,9 +49,9 @@ class ScriptEngineEval(
val en = Input(Bool()) // chip enable signal

//
// Evaluation symbol
// Evaluation operator symbol
//
val symbol = Input(new SYMBOL)
val operator = Input(new SYMBOL)

val currentStage = Input(UInt(log2Ceil(maximumNumberOfStages).W))
val nextStage = Output(UInt(log2Ceil(maximumNumberOfStages).W))
Expand All @@ -54,12 +67,40 @@ class ScriptEngineEval(
// Output pins
//
// val outputPin = Wire(Vec(numberOfPins, UInt(1.W)))
val nextStage = Wire(UInt(log2Ceil(maximumNumberOfStages).W))
val nextStage = WireInit(0.U(log2Ceil(maximumNumberOfStages).W))

//
// Assign operator value (split the signal into only usable part)
//
LogInfo(debug)("Usable size of Value in the SYMBOL: " + ScriptOperators().getWidth)
val operatorValue = io.operator.Value(ScriptOperators().getWidth - 1, 0).asTypeOf(ScriptOperators())

//
// *** Implementing the evaluation engine ***
//

//
// Apply the chip enable signal
//
when(io.en === true.B) {

switch(operatorValue) {

is(sFuncInc) {
nextStage := io.currentStage + 1.U
}
is(sFuncDec) {
nextStage := io.currentStage + 2.U
}
}
}

// ---------------------------------------------------------------------

//
// Increment the stage
//
nextStage := io.currentStage + 1.U
// nextStage := io.currentStage + 1.U

//
// Connect the output signals
Expand All @@ -75,11 +116,11 @@ object ScriptEngineEval {
def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
)(
en: Bool,
symbol: SYMBOL,
operator: SYMBOL,
currentStage: UInt,
inputPin: Vec[UInt]
): (UInt, Vec[UInt]) = {
Expand All @@ -100,7 +141,7 @@ object ScriptEngineEval {
// Configure the input signals
//
scriptEngineEvalModule.io.en := en
scriptEngineEvalModule.io.symbol := symbol
scriptEngineEvalModule.io.operator := operator
scriptEngineEvalModule.io.currentStage := currentStage
scriptEngineEvalModule.io.inputPin := inputPin

Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/hwdbg/script/exec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import hwdbg.stage._
class ScriptExecutionEngine(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
bramAddrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
bramDataWidth: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
Expand Down Expand Up @@ -151,7 +151,7 @@ object ScriptExecutionEngine {
def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
bramAddrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
bramDataWidth: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/hwdbg/types/stage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class SYMBOL extends Bundle {
class StageRegisters(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES
) extends Bundle {
val pinValues = Vec(numberOfPins, UInt(1.W)) // The value of each pin in each stage (should be passed to the next stage)
val scriptSymbol = new SYMBOL // Interpreted script symbol for the target stage (should NOT be passed to the next stage)
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import hwdbg.configs._
class DebuggerModule(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
bramAddrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
bramDataWidth: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
Expand Down Expand Up @@ -94,7 +94,7 @@ object Main extends App {
new DebuggerModule(
DebuggerConfigurations.ENABLE_DEBUG,
DebuggerConfigurations.NUMBER_OF_PINS,
DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
DebuggerPorts.PORT_PINS_MAP
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/top_test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import hwdbg.libs.mem._
class DebuggerModuleTestingBRAM(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
maximumNumberOfStages: Int = ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
bramAddrWidth: Int = DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
bramDataWidth: Int = DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
portsConfiguration: Map[Int, Int] = DebuggerPorts.PORT_PINS_MAP
Expand Down Expand Up @@ -126,7 +126,7 @@ object MainWithInitializedBRAM extends App {
new DebuggerModuleTestingBRAM(
DebuggerConfigurations.ENABLE_DEBUG,
DebuggerConfigurations.NUMBER_OF_PINS,
DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
ScriptEngineConfigurations.MAXIMUM_NUMBER_OF_STAGES,
DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
DebuggerPorts.PORT_PINS_MAP
Expand Down

0 comments on commit bbd87ce

Please sign in to comment.