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

Commit

Permalink
add mux 4 to 1 one hot
Browse files Browse the repository at this point in the history
  • Loading branch information
SinaKarvandi committed May 5, 2024
1 parent 2e0a055 commit 686d514
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions src/main/scala/hwdbg/libs/mux/mux_4_to_1_onehot.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @file
* mux_4_to_1_onehot.scala
* @author
* Sina Karvandi ([email protected])
* @brief
* Implementation of MUX 4 to 1 (One Hot)
* @details
* @version 0.1
* @date
* 2024-05-05
*
* @copyright
* This project is released under the GNU Public License v3.
*/
package hwdbg.libs.mux

import chisel3._
import chisel3.util._

import hwdbg.configs._

class Mux4To1OneHot(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
width: Int = 32
) extends Module {

val io = IO(new Bundle {

val in0 = Input(UInt(width.W))
val in1 = Input(UInt(width.W))
val in2 = Input(UInt(width.W))
val in3 = Input(UInt(width.W))
val sel = Input(UInt(log2Ceil(width).W))
val out = Output(UInt(width.W))

})

io.out := Mux1H(io.sel, Seq(io.in0, io.in1, io.in2, io.in3))

}

object Mux4To1OneHot {

def apply(
debug: Boolean = DebuggerConfigurations.ENABLE_DEBUG,
width: Int = 32
)(
in0: UInt,
in1: UInt,
in2: UInt,
in3: UInt,
sel: UInt
): (UInt) = {

val mux4To1OneHot = Module(
new Mux4To1OneHot(
debug
)
)

val out = Wire(UInt(width.W))

//
// Configure the input signals
//
mux4To1OneHot.io.in0 := in0
mux4To1OneHot.io.in1 := in1
mux4To1OneHot.io.in2 := in2
mux4To1OneHot.io.in3 := in3
mux4To1OneHot.io.sel := sel

//
// Configure the output signals
//
out := mux4To1OneHot.io.out

//
// Return the output result
//
out
}
}

0 comments on commit 686d514

Please sign in to comment.