X
Xenon02
Guest
Hello !
I'm still struggeling how does the `include works. I know there is something about name space although I don't really much understand it and also about duplicating the same wires and parameters. I know I could accept the fact that modules cannot be included in other modules but I couldn't understand it and I want to understand it fully because accepting the fact doesn't ease my curiosity and worry of not understanding it and stucking in a situation like : Should I use include or not or why it doesn't work when I included something.
Here is my example code of na ALU :
and the include file :
So what if I add " 'include Komparator" which is a module visible also in alu as comparator#.......
And what will happen if I delete in ALU the line with "comparation #(.BITS(BITS)) Komparator (.in_arg_A(in_arg_A), .in_arg_B(in_arg_B), .out_result(out_result_1), .out_status(out_status_1)); " and leave the line " 'include Komparator" as it is.
Why I still cannot use include ?
My guess is that when the Komparator file is compiled it's output and input can be used anywhere without inclusion because it has been "constructed". Then if I want to use Komparator in ALU and it's inputs and outputs it doesn't know which Komparator it wants to use (if it's the one he included or the one in another .sv file). Something like that ? Because it isn't about the sv file but the content which is modules sv file can have any name but when the content of the file has duplicated module name it doesn't know which module should be used in the rest of the project when it used the same module name.
I guess something like that came to my mind. I thought that duplicating the same part of the code wouldn't make any difference.
It was confusing for me sometimes because I saw this post : https://electronics.stackexchange.c...ude-statement-error-in-verilog-testbench-code. His include files containd the modules which already made me confused.
I know that include removes the include line and replaces it with that the include file contained. But I somehow couldn't understand what was the problem that the modules just duplicated. It's like the number PI was duplicated in couple of modules. Or compiling the same module in both different modules that contained this one duplicated module how it can overwrite it or something ? The content is the same so it cannot be overwrited the module so what is the problem with duplication ? Like I wrote above ? Because now when I write this part I got again confused ;>
I'm still struggeling how does the `include works. I know there is something about name space although I don't really much understand it and also about duplicating the same wires and parameters. I know I could accept the fact that modules cannot be included in other modules but I couldn't understand it and I want to understand it fully because accepting the fact doesn't ease my curiosity and worry of not understanding it and stucking in a situation like : Should I use include or not or why it doesn't work when I included something.
Here is my example code of na ALU :
`include "alu_defines.vh"
module top_module(in_arg_A,in_arg_B,i_oper,in_clock,in_reset,out_result,in_carry,out_status);
parameter BITS = 10;
input logic signed [BITS-1:0] in_arg_A,in_arg_B;
input logic [1:0] i_oper;
input in_clock,in_reset;
output logic signed [BITS-1:0] out_result;
output logic [3:0] out_status;
input logic in_carry;
logic [BITS-1:0] out_mux;
logic [BITS-1:0] out_result_1;
logic [BITS-1:0] out_result_2;
logic [BITS-1:0] out_result_3;
logic [BITS-1:0] out_result_4;
logic [3:0] out_status_mux;
logic [3:0] out_status_1;
logic [3:0] out_status_2;
logic [3:0] out_status_3;
logic [3:0] out_status_4;
comparation #(.BITS(BITS)) Komparator (.in_arg_A(in_arg_A), .in_arg_B(in_arg_B), .out_result(out_result_1), .out_status(out_status_1));
right_shifter #(.BITS(BITS)) Shift (.in_arg_A(in_arg_A), .in_arg_B(in_arg_B), .out_result(out_result_2), .out_status(out_status_2));
subtractor #(.BITS(BITS)) Sub (.in_arg_A(in_arg_A),.in_arg_B(in_arg_B), .out_result(out_result_3), .out_status(out_status_3), .in_carry(in_carry));
//co należy podłączyć do wejścia out_carry
U2_changing #(.BITS(BITS)) Change (.in_arg_A(in_arg_A), .out_result(out_result_4), .out_status(out_status_4));
always@*
begin
{out_mux,out_status} = '0;
case(i_oper)
`ALU_COMPARATION: out_mux = out_result_1;
`ALU_RIGHT_SHIFFTER: out_mux = out_result_2;
`ALU_SUBTRACTOR: out_mux = out_result_3;
`ULU_U2_TO_ZM: out_mux = out_result_4;
default: out_mux = '0;
endcase
case(i_oper)
`ALU_COMPARATION: out_status_mux = out_status_1;
`ALU_RIGHT_SHIFFTER: out_status_mux = out_status_2;
`ALU_SUBTRACTOR: out_status_mux = out_status_3;
`ULU_U2_TO_ZM: out_status_mux = out_status_4;
default: out_status_mux = '0;
endcase
end
always_ff @(posedge in_clock)
begin
if (in_reset == 1 )
begin
out_result <= out_mux;
out_status <= out_status_mux;
end
else
begin
out_result = '0;
out_status = '0;
end
end
endmodule
and the include file :
`ifndef ALU_DEFINES
`define ALU_DEFINES
`define OPER_BITS 2
def∈eALUCOMPARATIONdef∈eALUCOMPARATIONOPER_BITS'd0
def∈eALURIGHTSHIFFTERdef∈eALURIGHTSHIFFTEROPER_BITS'd1
def∈eALUSUBTRACTORdef∈eALUSUBTRACTOROPER_BITS'd2
def∈eULUU2TOZMdef∈eULUU2TOZMOPER_BITS'd3
`endif
So what if I add " 'include Komparator" which is a module visible also in alu as comparator#.......
And what will happen if I delete in ALU the line with "comparation #(.BITS(BITS)) Komparator (.in_arg_A(in_arg_A), .in_arg_B(in_arg_B), .out_result(out_result_1), .out_status(out_status_1)); " and leave the line " 'include Komparator" as it is.
Why I still cannot use include ?
My guess is that when the Komparator file is compiled it's output and input can be used anywhere without inclusion because it has been "constructed". Then if I want to use Komparator in ALU and it's inputs and outputs it doesn't know which Komparator it wants to use (if it's the one he included or the one in another .sv file). Something like that ? Because it isn't about the sv file but the content which is modules sv file can have any name but when the content of the file has duplicated module name it doesn't know which module should be used in the rest of the project when it used the same module name.
I guess something like that came to my mind. I thought that duplicating the same part of the code wouldn't make any difference.
It was confusing for me sometimes because I saw this post : https://electronics.stackexchange.c...ude-statement-error-in-verilog-testbench-code. His include files containd the modules which already made me confused.
I know that include removes the include line and replaces it with that the include file contained. But I somehow couldn't understand what was the problem that the modules just duplicated. It's like the number PI was duplicated in couple of modules. Or compiling the same module in both different modules that contained this one duplicated module how it can overwrite it or something ? The content is the same so it cannot be overwrited the module so what is the problem with duplication ? Like I wrote above ? Because now when I write this part I got again confused ;>