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

Commit

Permalink
add register stage transitions
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaKarvandi committed May 7, 2024
1 parent 78e8ae5 commit 77c136d
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 37 deletions.
38 changes: 2 additions & 36 deletions src/main/scala/hwdbg/communication/interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ class DebuggerPacketInterpreter(

val regRequestedActionOfThePacketOutput = RegInit(0.U(new DebuggerRemotePacket().RequestedActionOfThePacket.getWidth.W))

//////////////////// Test Signals (Should be remove) ////////////////////

val regRecvScriptSize = RegInit(0.U(new DebuggerRemotePacket().RequestedActionOfThePacket.getWidth.W))

/////////////////////////////////////////////////////////////////////////

//
// Apply the chip enable signal
//
Expand Down Expand Up @@ -181,27 +175,9 @@ class DebuggerPacketInterpreter(
regRequestedActionOfThePacketOutput := HwdbgResponseEnums.hwdbgResponseScriptBufferConfigurationResult.id.U

//
// Get next buffer
// This action needs a response
//
readNextData := true.B

when(io.dataValidInput === false.B) {

//
// Still the configuration is not done, so receiving the data
// stay at the same state
//
state := sNewActionReceived

}.otherwise {

regRecvScriptSize := io.receivingData

//
// Configuration was done, send the response (result)
//
state := sSendResponse
}
state := sSendResponse

}.otherwise {

Expand Down Expand Up @@ -334,16 +310,6 @@ class DebuggerPacketInterpreter(
// *** Send result of applying script ***
//

//
// Set the test data
//
sendingData := regRecvScriptSize

//
// Data is valid to send
//
dataValidOutput := true.B

//
// TODO: To be implemented
//
Expand Down
5 changes: 5 additions & 0 deletions src/main/scala/hwdbg/configs/configs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ 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 Down
3 changes: 3 additions & 0 deletions src/main/scala/hwdbg/main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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,
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 @@ -174,6 +175,7 @@ object DebuggerMain {
def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.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 All @@ -188,6 +190,7 @@ object DebuggerMain {
new DebuggerMain(
debug,
numberOfPins,
maximumNumberOfStages,
bramAddrWidth,
bramDataWidth,
portsConfiguration
Expand Down
139 changes: 139 additions & 0 deletions src/main/scala/hwdbg/script/exec.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/**
* @file
* exec.scala
* @author
* Sina Karvandi (sina@hyperdbg.org)
* @brief
* Script execution engine
* @details
* @version 0.1
* @date
* 2024-05-07
*
* @copyright
* This project is released under the GNU Public License v3.
*/
package hwdbg.exec

import chisel3._
import chisel3.util._

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

class ScriptExec(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.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
) extends Module {

val io = IO(new Bundle {

//
// Chip signals
//
val en = Input(Bool()) // chip enable signal

//
// Input/Output signals
//
val inputPin = Input(Vec(numberOfPins, UInt((1.W)))) // input pins
val outputPin = Output(Vec(numberOfPins, UInt((1.W)))) // output pins
})

//
// Output pins
//
val outputPin = Wire(Vec(numberOfPins, UInt((1.W))))

//
// Stage registers
//
val stageRegs = Reg(new StageRegisters(debug, numberOfPins, maximumNumberOfStages))

// -----------------------------------------------------------------------
//
// *** Move each register (input vector) to the next stage at each clock ***
//
for (i <- 0 until maximumNumberOfStages) {

if (i == 0) {

//
// At the first stage, the input registers should be passed to the
// first registers set of the stage registers
//
stageRegs.pinValues(i) := io.inputPin

} else if (i == (maximumNumberOfStages - 1)) {

//
// At the last stage, the state registers should be passed to the output
//
outputPin := stageRegs.pinValues(i)

} else {

//
// At the normal (middle) stage, the state registers should be passed to
// the next level of stage registers
//
stageRegs.pinValues(i + 1) := stageRegs.pinValues(i)
}
}
// -----------------------------------------------------------------------

//
// Connect the output signals
//
io.outputPin := outputPin

}

object ScriptExec {

def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.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
)(
en: Bool,
inputPin: Vec[UInt]
): (Vec[UInt]) = {

val scriptExecModule = Module(
new ScriptExec(
debug,
numberOfPins,
maximumNumberOfStages,
bramAddrWidth,
bramDataWidth,
portsConfiguration
)
)

val outputPin = Wire(Vec(numberOfPins, UInt((1.W))))

//
// Configure the input signals
//
scriptExecModule.io.en := en
scriptExecModule.io.inputPin := inputPin

//
// Configure the output signals
//
outputPin := scriptExecModule.io.outputPin

//
// Return the output result
//
outputPin
}
}
2 changes: 1 addition & 1 deletion src/main/scala/hwdbg/types/communication.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ object HwdbgResponseEnums extends Enumeration {

val hwdbgResponseInvalidPacketOrError = Value(1)
val hwdbgResponseVersion = Value(2)
val hwdbgResponsePinInformation = Value(0x8595)
val hwdbgResponsePinInformation = Value(3)
val hwdbgResponseScriptBufferConfigurationResult = Value(4)

}
Expand Down
28 changes: 28 additions & 0 deletions src/main/scala/hwdbg/types/stage.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @file
* stage.scala
* @author
* Sina Karvandi (sina@hyperdbg.org)
* @brief
* Data types related to stage registers
* @details
* @version 0.1
* @date
* 2024-05-07
*
* @copyright
* This project is released under the GNU Public License v3.
*/
package hwdbg.stage

import chisel3._

import hwdbg.configs._

class StageRegisters(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
numberOfPins: Int = DebuggerConfigurations.NUMBER_OF_PINS,
maximumNumberOfStages: Int = DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES
) extends Bundle {
val pinValues = Vec(maximumNumberOfStages, UInt(numberOfPins.W))
}
3 changes: 3 additions & 0 deletions src/main/scala/top.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +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,
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 @@ -64,6 +65,7 @@ class DebuggerModule(
DebuggerMain(
debug,
numberOfPins,
maximumNumberOfStages,
bramAddrWidth,
bramDataWidth,
portsConfiguration
Expand Down Expand Up @@ -92,6 +94,7 @@ object Main extends App {
new DebuggerModule(
DebuggerConfigurations.ENABLE_DEBUG,
DebuggerConfigurations.NUMBER_OF_PINS,
DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
DebuggerPorts.PORT_PINS_MAP
Expand Down
3 changes: 3 additions & 0 deletions src/main/scala/top_test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +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,
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 @@ -88,6 +89,7 @@ class DebuggerModuleTestingBRAM(
DebuggerMain(
debug,
numberOfPins,
maximumNumberOfStages,
bramAddrWidth,
bramDataWidth,
portsConfiguration
Expand Down Expand Up @@ -124,6 +126,7 @@ object MainWithInitializedBRAM extends App {
new DebuggerModuleTestingBRAM(
DebuggerConfigurations.ENABLE_DEBUG,
DebuggerConfigurations.NUMBER_OF_PINS,
DebuggerConfigurations.MAXIMUM_NUMBER_OF_STAGES,
DebuggerConfigurations.BLOCK_RAM_ADDR_WIDTH,
DebuggerConfigurations.BLOCK_RAM_DATA_WIDTH,
DebuggerPorts.PORT_PINS_MAP
Expand Down

0 comments on commit 77c136d

Please sign in to comment.