util_adc_pack: Added parameters for configuring data width and number of channels

Valid values for the number of channels is 4 or 8
Valid values for datawidth is 16 or 32
main
Adrian Costina 2014-08-27 14:47:57 +03:00
parent a49eb5853b
commit 31002c404c
2 changed files with 236 additions and 128 deletions

View File

@ -81,43 +81,45 @@ module util_adc_pack (
);
parameter CHANNELS = 8 ; // valid values are 4 and 8
parameter DATA_WIDTH = 16; // valid values are 16 and 32
// common clock
input clk;
input chan_enable_0;
input chan_valid_0;
input [15:0] chan_data_0;
input [(DATA_WIDTH-1):0] chan_data_0;
input chan_enable_1;
input chan_valid_1;
input [15:0] chan_data_1;
input [(DATA_WIDTH-1):0] chan_data_1;
input chan_enable_2;
input chan_valid_2;
input [15:0] chan_data_2;
input [(DATA_WIDTH-1):0] chan_data_2;
input chan_enable_3;
input chan_valid_3;
input [15:0] chan_data_3;
input [(DATA_WIDTH-1):0] chan_data_3;
input chan_enable_4;
input chan_valid_4;
input [15:0] chan_data_4;
input [(DATA_WIDTH-1):0] chan_data_4;
input chan_enable_5;
input chan_valid_5;
input [15:0] chan_data_5;
input [(DATA_WIDTH-1):0] chan_data_5;
input chan_enable_6;
input chan_valid_6;
input [15:0] chan_data_6;
input [(DATA_WIDTH-1):0] chan_data_6;
input chan_valid_7;
input chan_enable_7;
input [15:0] chan_data_7;
input [(DATA_WIDTH-1):0] chan_data_7;
output [127:0] ddata;
output [(DATA_WIDTH * CHANNELS - 1):0] ddata;
output dvalid;
output dsync;
@ -125,7 +127,7 @@ module util_adc_pack (
reg [2:0] enable_cnt_0;
reg [2:0] enable_cnt_1;
reg [127:0] packed_data = 0;
reg [(DATA_WIDTH * CHANNELS - 1):0] packed_data = 0;
reg [63:0] temp_data_0 = 0;
reg [63:0] temp_data_1 = 0;
reg [7:0] path_enabled = 0;
@ -134,18 +136,18 @@ module util_adc_pack (
reg [7:0] en1 = 0;
reg [7:0] en2 = 0;
reg [7:0] en4 = 0;
reg [127:0] ddata = 0;
reg [(DATA_WIDTH * CHANNELS - 1):0] ddata = 0;
reg dvalid = 0;
reg chan_valid = 0;
reg chan_valid_d1 = 0;
reg [15:0] chan_data_0_r;
reg [15:0] chan_data_1_r;
reg [15:0] chan_data_2_r;
reg [15:0] chan_data_3_r;
reg [15:0] chan_data_4_r;
reg [15:0] chan_data_5_r;
reg [15:0] chan_data_6_r;
reg [15:0] chan_data_7_r;
reg [(DATA_WIDTH-1):0] chan_data_0_r;
reg [(DATA_WIDTH-1):0] chan_data_1_r;
reg [(DATA_WIDTH-1):0] chan_data_2_r;
reg [(DATA_WIDTH-1):0] chan_data_3_r;
reg [(DATA_WIDTH-1):0] chan_data_4_r;
reg [(DATA_WIDTH-1):0] chan_data_5_r;
reg [(DATA_WIDTH-1):0] chan_data_6_r;
reg [(DATA_WIDTH-1):0] chan_data_7_r;
assign dsync = dvalid;
@ -174,39 +176,39 @@ module util_adc_pack (
if(chan_valid == 1'b1)
begin
casex ({chan_enable_3,chan_enable_2,chan_enable_1,chan_enable_0})
4'bxxx1: temp_data_0[15:0] = chan_data_0_r;
4'bxx10: temp_data_0[15:0] = chan_data_1_r;
4'bx100: temp_data_0[15:0] = chan_data_2_r;
4'b1000: temp_data_0[15:0] = chan_data_3_r;
default: temp_data_0 [15:0] = 16'h0000;
4'bxxx1: temp_data_0[(DATA_WIDTH-1):0] = chan_data_0_r;
4'bxx10: temp_data_0[(DATA_WIDTH-1):0] = chan_data_1_r;
4'bx100: temp_data_0[(DATA_WIDTH-1):0] = chan_data_2_r;
4'b1000: temp_data_0[(DATA_WIDTH-1):0] = chan_data_3_r;
default: temp_data_0 [(DATA_WIDTH-1):0] = 0;
endcase
casex ({chan_enable_3,chan_enable_2,chan_enable_1,chan_enable_0})
4'bxx11: temp_data_0[31:16] = chan_data_1_r;
4'bx110: temp_data_0[31:16] = chan_data_2_r;
4'bx101: temp_data_0[31:16] = chan_data_2_r;
4'b1001: temp_data_0[31:16] = chan_data_3_r;
4'b1010: temp_data_0[31:16] = chan_data_3_r;
4'b1100: temp_data_0[31:16] = chan_data_3_r;
default: temp_data_0[31:16] = 16'h0000;
4'bxx11: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_1_r;
4'bx110: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_2_r;
4'bx101: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_2_r;
4'b1001: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_3_r;
4'b1010: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_3_r;
4'b1100: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_3_r;
default: temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH] = 0;
endcase
casex ({chan_enable_3,chan_enable_2,chan_enable_1,chan_enable_0})
4'bx111: temp_data_0[47:32] = chan_data_2_r;
4'b1011: temp_data_0[47:32] = chan_data_3_r;
4'b1101: temp_data_0[47:32] = chan_data_3_r;
4'b1110: temp_data_0[47:32] = chan_data_3_r;
default: temp_data_0[47:32] = 16'h0000;
4'bx111: temp_data_0[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_2_r;
4'b1011: temp_data_0[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_3_r;
4'b1101: temp_data_0[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_3_r;
4'b1110: temp_data_0[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_3_r;
default: temp_data_0[3*DATA_WIDTH-1:2*DATA_WIDTH] = 0;
endcase
case ({chan_enable_3,chan_enable_2,chan_enable_1,chan_enable_0})
4'b1111: temp_data_0[63:48] = chan_data_3_r;
default: temp_data_0[63:48] = 16'h0000;
4'b1111: temp_data_0[4*DATA_WIDTH-1:3*DATA_WIDTH] = chan_data_3_r;
default: temp_data_0[4*DATA_WIDTH-1:3*DATA_WIDTH] = 0;
endcase
end
else
begin
temp_data_0 = 64'h0;
temp_data_0 = 0;
end
end
@ -215,45 +217,45 @@ module util_adc_pack (
if(chan_valid == 1'b1)
begin
casex ({chan_enable_7,chan_enable_6,chan_enable_5,chan_enable_4})
4'bxxx1: temp_data_1[15:0] = chan_data_4_r;
4'bxx10: temp_data_1[15:0] = chan_data_5_r;
4'bx100: temp_data_1[15:0] = chan_data_6_r;
4'b1000: temp_data_1[15:0] = chan_data_7_r;
default: temp_data_1 [15:0] = 16'h0000;
4'bxxx1: temp_data_1[(DATA_WIDTH-1):0] = chan_data_4_r;
4'bxx10: temp_data_1[(DATA_WIDTH-1):0] = chan_data_5_r;
4'bx100: temp_data_1[(DATA_WIDTH-1):0] = chan_data_6_r;
4'b1000: temp_data_1[(DATA_WIDTH-1):0] = chan_data_7_r;
default: temp_data_1[(DATA_WIDTH-1):0] = 0;
endcase
casex ({chan_enable_7,chan_enable_6,chan_enable_5,chan_enable_4})
4'bxx11: temp_data_1[31:16] = chan_data_5_r;
4'bx110: temp_data_1[31:16] = chan_data_6_r;
4'bx101: temp_data_1[31:16] = chan_data_6_r;
4'b1001: temp_data_1[31:16] = chan_data_7_r;
4'b1010: temp_data_1[31:16] = chan_data_7_r;
4'b1100: temp_data_1[31:16] = chan_data_7_r;
default: temp_data_1[31:16] = 16'h0000;
4'bxx11: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_5_r;
4'bx110: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_6_r;
4'bx101: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_6_r;
4'b1001: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_7_r;
4'b1010: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_7_r;
4'b1100: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = chan_data_7_r;
default: temp_data_1[2*DATA_WIDTH-1:DATA_WIDTH] = 0;
endcase
casex ({chan_enable_7,chan_enable_6,chan_enable_5,chan_enable_4})
4'bx111: temp_data_1[47:32] = chan_data_6_r;
4'b1011: temp_data_1[47:32] = chan_data_7_r;
4'b1101: temp_data_1[47:32] = chan_data_7_r;
4'b1110: temp_data_1[47:32] = chan_data_7_r;
default: temp_data_1[47:32] = 16'h0000;
4'bx111: temp_data_1[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_6_r;
4'b1011: temp_data_1[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_7_r;
4'b1101: temp_data_1[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_7_r;
4'b1110: temp_data_1[3*DATA_WIDTH-1:2*DATA_WIDTH] = chan_data_7_r;
default: temp_data_1[3*DATA_WIDTH-1:2*DATA_WIDTH] = 0;
endcase
case ({chan_enable_7,chan_enable_6,chan_enable_5,chan_enable_4})
4'b1111: temp_data_1[63:48] = chan_data_7_r;
default: temp_data_1[63:48] = 16'h0000;
4'b1111: temp_data_1[4*DATA_WIDTH-1:3*DATA_WIDTH] = chan_data_7_r;
default: temp_data_1[4*DATA_WIDTH-1:3*DATA_WIDTH] = 0;
endcase
end
else
begin
temp_data_1 = 64'h0;
temp_data_1 = 0;
end
end
always @(temp_data_0, temp_data_1, enable_cnt_0)
begin
packed_data = temp_data_0 | temp_data_1 << enable_cnt_0 * 16;
packed_data = temp_data_0 | temp_data_1 << enable_cnt_0 * DATA_WIDTH;
end
always @(enable_cnt)
@ -368,106 +370,122 @@ module util_adc_pack (
endcase
end
// FOUR CHANNELS
always @(posedge clk)
begin
// ddata[15:0]
// ddata 0
if ((en1[0] | en2[0] | en4[0] | path_enabled[7]) == 1'b1)
begin
ddata[15:0] <= packed_data[15:0];
ddata[(DATA_WIDTH-1):0] <= temp_data_0[(DATA_WIDTH-1):0];
end
// ddata[31:16]
// ddata 1
if( en1[1] == 1'b1)
begin
ddata[31:16] <= packed_data[15:0];
ddata[2*DATA_WIDTH-1:DATA_WIDTH] <= temp_data_0[(DATA_WIDTH-1):0];
end
if ( (en2[1] | en4[1] | path_enabled[7]) == 1'b1)
begin
ddata[31:16] <= packed_data[31:16];
ddata[2*DATA_WIDTH-1:DATA_WIDTH] <= temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH];
end
// ddata[47:32]
// ddata 2
if ((en1[2] | en2[2]) == 1'b1)
begin
ddata[47:32] <= packed_data[15:0];
ddata[3*DATA_WIDTH-1:2*DATA_WIDTH] <= temp_data_0[(DATA_WIDTH-1):0];
end
if ((en4[2] | path_enabled[7]) == 1'b1)
begin
ddata[47:32] <= packed_data[47:32];
ddata[3*DATA_WIDTH-1:2*DATA_WIDTH] <= temp_data_0[3*DATA_WIDTH-1:2*DATA_WIDTH];
end
// ddata[63:48]
// ddata 3
if (en1[3] == 1'b1)
begin
ddata[63:48] <= packed_data[15:0];
ddata[4*DATA_WIDTH-1:3*DATA_WIDTH] <= temp_data_0[(DATA_WIDTH-1):0];
end
if (en2[3] == 1'b1)
begin
ddata[63:48] <= packed_data[31:16];
ddata[4*DATA_WIDTH-1:3*DATA_WIDTH] <= temp_data_0[2*DATA_WIDTH-1:DATA_WIDTH];
end
if ((en4[3] | path_enabled[7]) == 1'b1)
begin
ddata[63:48] <= packed_data[63:48];
end
// ddata[79:64]
if ((en1[4] | en2[4] | en4[4]) == 1'b1)
begin
ddata[79:64] <= packed_data[15:0];
end
if (path_enabled[7] == 1'b1)
begin
ddata[79:64] <= packed_data[79:64];
end
// ddata[95:80]
if (en1[5] == 1'b1)
begin
ddata[95:80] <= packed_data[15:0];
end
if ((en2[5] | en4[5]) == 1'b1)
begin
ddata[95:80] <= packed_data[31:16];
end
if (path_enabled[7] == 1'b1)
begin
ddata[95:80] <= packed_data[95:80];
end
// ddata[111:96]
if ((en1[6] | en2[6]) == 1'b1)
begin
ddata[111:96] <= packed_data[15:0];
end
if (en4[6] == 1'b1)
begin
ddata[111:96] <= packed_data[47:32];
end
if (path_enabled[7] == 1'b1)
begin
ddata[111:96] <= packed_data[111:96];
end
// ddata[127:112]
if (en1[7] == 1'b1)
begin
ddata[127:112] <= packed_data[15:0];
end
if (en2[7] == 1'b1)
begin
ddata[127:112] <= packed_data[31:16];
end
if (en4[7] == 1'b1)
begin
ddata[127:112] <= packed_data[63:48];
end
if (path_enabled[7] == 1'b1)
begin
ddata[127:112] <= packed_data[127:112];
ddata[4*DATA_WIDTH-1:3*DATA_WIDTH] <= temp_data_0[4*DATA_WIDTH-1:3*DATA_WIDTH];
end
end
// EIGHT CHANNELS
generate
if ( CHANNELS == 8)
begin
always @(posedge clk)
begin
// ddata 4
if ((en1[4] | en2[4] | en4[4]) == 1'b1)
begin
ddata[5*DATA_WIDTH-1:4*DATA_WIDTH] <= packed_data[(DATA_WIDTH-1):0];
end
if (path_enabled[7] == 1'b1)
begin
ddata[5*DATA_WIDTH-1:4*DATA_WIDTH] <= packed_data[5*DATA_WIDTH-1:4*DATA_WIDTH];
end
// ddata 5
if (en1[5] == 1'b1)
begin
ddata[6*DATA_WIDTH-1:5*DATA_WIDTH] <= packed_data[(DATA_WIDTH-1):0];
end
if ((en2[5] | en4[5]) == 1'b1)
begin
ddata[6*DATA_WIDTH-1:5*DATA_WIDTH] <= packed_data[2*DATA_WIDTH-1:DATA_WIDTH];
end
if (path_enabled[7] == 1'b1)
begin
ddata[6*DATA_WIDTH-1:5*DATA_WIDTH] <= packed_data[6*DATA_WIDTH-1:5*DATA_WIDTH];
end
// ddata 6
if ((en1[6] | en2[6]) == 1'b1)
begin
ddata[7*DATA_WIDTH-1:6*DATA_WIDTH] <= packed_data[(DATA_WIDTH-1):0];
end
if (en4[6] == 1'b1)
begin
ddata[7*DATA_WIDTH-1:6*DATA_WIDTH] <= packed_data[3*DATA_WIDTH-1:2*DATA_WIDTH];
end
if (path_enabled[7] == 1'b1)
begin
ddata[7*DATA_WIDTH-1:6*DATA_WIDTH] <= packed_data[7*DATA_WIDTH-1:6*DATA_WIDTH];
end
// ddata 7
if (en1[7] == 1'b1)
begin
ddata[8*DATA_WIDTH-1:7*DATA_WIDTH] <= packed_data[(DATA_WIDTH-1):0];
end
if (en2[7] == 1'b1)
begin
ddata[8*DATA_WIDTH-1:7*DATA_WIDTH] <= packed_data[2*DATA_WIDTH-1:DATA_WIDTH];
end
if (en4[7] == 1'b1)
begin
ddata[8*DATA_WIDTH-1:7*DATA_WIDTH] <= packed_data[4*DATA_WIDTH-1:3*DATA_WIDTH];
end
if (path_enabled[7] == 1'b1)
begin
ddata[8*DATA_WIDTH-1:7*DATA_WIDTH] <= packed_data[127:7*DATA_WIDTH];
end
end
always @(temp_data_0, temp_data_1, enable_cnt_0)
begin
packed_data = temp_data_0 | temp_data_1 << enable_cnt_0 * DATA_WIDTH;
end
end
endgenerate
endmodule
// ***************************************************************************

View File

@ -0,0 +1,90 @@
package require -exact qsys 13.0
source ../scripts/adi_env.tcl
set_module_property NAME util_adc_pack
set_module_property DESCRIPTION "Util ADC data packager"
set_module_property VERSION 1.0
set_module_property DISPLAY_NAME util_adc_pack
set_module_property ELABORATION_CALLBACK util_adc_pack_elaborate
# files
add_fileset quartus_synth QUARTUS_SYNTH "" "Quartus Synthesis"
set_fileset_property quartus_synth TOP_LEVEL util_adc_pack
add_fileset_file util_adc_pack.v VERILOG PATH util_adc_pack.v
# parameters
add_parameter CHANNELS INTEGER 0
set_parameter_property CHANNELS DEFAULT_VALUE 8
set_parameter_property CHANNELS ALLOWED_RANGES {4 8}
set_parameter_property CHANNELS DESCRIPTION "Valid values are 4 and 8"
set_parameter_property CHANNELS DISPLAY_NAME CHANNELS
set_parameter_property CHANNELS TYPE INTEGER
set_parameter_property CHANNELS UNITS None
set_parameter_property CHANNELS HDL_PARAMETER true
add_parameter DATA_WIDTH INTEGER 0
set_parameter_property DATA_WIDTH DEFAULT_VALUE 16
set_parameter_property DATA_WIDTH ALLOWED_RANGES {16 32}
set_parameter_property DATA_WIDTH DESCRIPTION "Valid values are 16 and 32"
set_parameter_property DATA_WIDTH DISPLAY_NAME DATA_WIDTH
set_parameter_property DATA_WIDTH TYPE INTEGER
set_parameter_property DATA_WIDTH UNITS None
set_parameter_property DATA_WIDTH HDL_PARAMETER true
add_interface data_clock clock end
add_interface_port data_clock clk clk Input 1
add_interface channels_data conduit end
set_interface_property channels_data associatedClock data_clock
add_interface_port channels_data chan_enable_0 chan_enable_0 Input 1
add_interface_port channels_data chan_valid_0 chan_valid_0 Input 1
add_interface_port channels_data chan_data_0 chan_data_0 Input DATA_WIDTH
add_interface_port channels_data chan_enable_1 chan_enable_1 Input 1
add_interface_port channels_data chan_valid_1 chan_valid_1 Input 1
add_interface_port channels_data chan_data_1 chan_data_1 Input DATA_WIDTH
add_interface_port channels_data chan_enable_2 chan_enable_2 Input 1
add_interface_port channels_data chan_valid_2 chan_valid_2 Input 1
add_interface_port channels_data chan_data_2 chan_data_2 Input DATA_WIDTH
add_interface_port channels_data chan_enable_3 chan_enable_3 Input 1
add_interface_port channels_data chan_valid_3 chan_valid_3 Input 1
add_interface_port channels_data chan_data_3 chan_data_3 Input DATA_WIDTH
proc util_adc_pack_elaborate {} {
set DW [ get_parameter_value DATA_WIDTH ]
set CHAN [ get_parameter_value CHANNELS ]
add_interface_port channels_data dvalid dvalid Output 1
add_interface_port channels_data dsync dsync Output 1
add_interface_port channels_data ddata ddata Output [expr {$DW * $CHAN}]
if {[get_parameter_value CHANNELS] == 8} {
add_interface_port channels_data chan_enable_4 chan_enable_4 Input 1
add_interface_port channels_data chan_valid_4 chan_valid_4 Input 1
add_interface_port channels_data chan_data_4 chan_data_4 Input DATA_WIDTH
add_interface_port channels_data chan_enable_5 chan_enable_5 Input 1
add_interface_port channels_data chan_valid_5 chan_valid_5 Input 1
add_interface_port channels_data chan_data_5 chan_data_5 Input DATA_WIDTH
add_interface_port channels_data chan_enable_6 chan_enable_6 Input 1
add_interface_port channels_data chan_valid_6 chan_valid_6 Input 1
add_interface_port channels_data chan_data_6 chan_data_6 Input DATA_WIDTH
add_interface_port channels_data chan_enable_7 chan_enable_7 Input 1
add_interface_port channels_data chan_valid_7 chan_valid_7 Input 1
add_interface_port channels_data chan_data_7 chan_data_7 Input DATA_WIDTH
}
}