2016-04-11 12:01:59 -04:00
|
|
|
//#############################################################################
|
|
|
|
//# Function: "ONE HOT" N:1 MUX #
|
|
|
|
//#############################################################################
|
|
|
|
//# Author: Andreas Olofsson #
|
|
|
|
//# License: MIT (see LICENSE file in OH! repository) #
|
|
|
|
//#############################################################################
|
2016-01-20 17:22:05 -05:00
|
|
|
|
2016-04-11 12:01:59 -04:00
|
|
|
module oh_mux #( parameter DW = 1, // width of data inputs
|
|
|
|
parameter N = 1 // number of inputs
|
|
|
|
)
|
|
|
|
(
|
|
|
|
input [N-1:0] sel, // select vector
|
|
|
|
input [N*DW-1:0] in, // concatenated input {..,in1[DW-1:0],in0[DW-1:0]
|
|
|
|
output [DW-1:0] out // output
|
|
|
|
);
|
2016-01-20 17:22:05 -05:00
|
|
|
|
2020-08-17 16:11:42 -04:00
|
|
|
//local variable
|
|
|
|
reg [DW-1:0] mux;
|
2016-01-20 17:22:05 -05:00
|
|
|
|
|
|
|
integer i;
|
|
|
|
always @*
|
|
|
|
begin
|
2020-08-17 16:11:42 -04:00
|
|
|
mux[DW-1:0] = 'b0;
|
2016-01-20 17:22:05 -05:00
|
|
|
for(i=0;i<N;i=i+1)
|
2020-08-17 16:11:42 -04:00
|
|
|
mux[DW-1:0] = mux[DW-1:0] | {(DW){sel[i]}} & in[((i+1)*DW-1)-:DW];
|
2016-01-20 17:22:05 -05:00
|
|
|
end
|
|
|
|
|
2020-08-17 16:11:42 -04:00
|
|
|
assign out[DW-1:0] = mux;
|
|
|
|
|
2016-01-20 17:22:05 -05:00
|
|
|
endmodule // oh_mux
|
|
|
|
|
|
|
|
|
2016-04-11 12:01:59 -04:00
|
|
|
|