From 0badfdfa31df9220826f0862231234f22d214216 Mon Sep 17 00:00:00 2001 From: Laszlo Nagy Date: Fri, 29 May 2020 19:54:58 +0100 Subject: [PATCH] ad_mux: fix cases where channel number is not power of mux size --- library/common/ad_mux.v | 3 ++- library/common/tb/ad_mux_tb.v | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/library/common/ad_mux.v b/library/common/ad_mux.v index f6ece940e..017bae162 100644 --- a/library/common/ad_mux.v +++ b/library/common/ad_mux.v @@ -57,7 +57,8 @@ module ad_mux #( localparam MUX_SZ = CH_CNT < REQ_MUX_SZ ? CH_CNT : REQ_MUX_SZ; localparam CLOG2_CH_CNT = $clog2(CH_CNT); localparam CLOG2_MUX_SZ = $clog2(MUX_SZ); -localparam NUM_STAGES = $clog2(CH_CNT) / $clog2(MUX_SZ); +localparam NUM_STAGES = ($clog2(CH_CNT) / $clog2(MUX_SZ)) + // divide and round up + |($clog2(CH_CNT) % $clog2(MUX_SZ)); wire [NUM_STAGES*DW+CH_W-1:0] mux_in; wire [NUM_STAGES*CLOG2_CH_CNT-1:0] ch_sel_pln; diff --git a/library/common/tb/ad_mux_tb.v b/library/common/tb/ad_mux_tb.v index 410acdc55..c037fca6e 100644 --- a/library/common/tb/ad_mux_tb.v +++ b/library/common/tb/ad_mux_tb.v @@ -9,7 +9,7 @@ module ad_mux_tb; parameter EN_REG = 1; // Enable register at output of each mux localparam MUX_SZ = CH_CNT < REQ_MUX_SZ ? CH_CNT : REQ_MUX_SZ; - localparam NUM_STAGES = $clog2(CH_CNT) / $clog2(MUX_SZ); + localparam NUM_STAGES = $clog2(CH_CNT) / $clog2(MUX_SZ) + |($clog2(CH_CNT) % $clog2(MUX_SZ)); localparam DW = CH_W*CH_CNT; `include "tb_base.v"