R
RL
Guest
Hi,
I am working on my first project in Verilog, currently in ModelSIM. The
target will most likely be a Xilinx FPGA.
This part of my project is very simple. It simply listens for commands
sent via a serial connection, decodes the packet, and responds
appropriately. I am trying to use multiple modules, one for each type of
packet that needs to be constructed, and send using a common 'serialtx'
module.
What I am unsure about is how to get the data from one location to
another when multiple modules need to write to a common buffer.
In my simplified example below, 'cmd_one' and 'cmd_two', both construct
packets to be sent by 'serialtx'. What I see when I run this in
simulation is that the local packets 'lpkt' get populated, but the value
is not reflected in 'opkt' for 'serialtx'.
I may be going about this completely the wrong way, or just missing
something simple. Your assistance is really appreciated.
Example below...
Thanks,
RL
`timescale 1ns / 100ps
module cmd_one (clk,opkt,opktready);
output [0:95] opkt;
inout opktready;
input clk;
reg [0:95] lpkt;
reg lpktready;
serialtx u0(.opkt(opkt),.opktready(opktready),.serialclk());
clk u1(.clk(clk));
assign opktready = lpktready;
assign opkt = lpkt;
always @(posedge clk) begin
lpkt = 95'd 1;
lpktready = 1;
end
endmodule
module cmd_two (clk,opkt,opktready);
output [0:95] opkt;
inout opktready;
input clk;
reg [0:95] lpkt;
reg lpktready;
serialtx u0(.opkt(opkt),.opktready(opktready),.serialclk());
clk u1(.clk(clk));
assign opktready = lpktready;
assign opkt = lpkt;
always @(negedge clk) begin
lpkt = 95'd 2;
lpktready = 1;
end
endmodule
module serialtx (opkt,opktready,serialclk);
input[0:95] opkt;
inout opktready;
input serialclk;
reg lpktready;
serialclk u0(.clk(),.serialclk(serialclk));
initial begin
lpktready = 0;
end
assign opktready = lpktready;
always @(posedge opktready) begin
// Send the packet...
lpktready = 0;
end
endmodule
module serialclk (clk,serialclk);
input clk;
output serialclk;
reg serialclk;
reg[0:15] cnt;
reg[0:15] clocks;
clk u0(.clk(clk));
initial begin
serialclk = 1'b 0;
cnt = 16'd 0;
clocks = 16'd 5;
end
always @(posedge clk) begin
if(cnt == clocks) begin
cnt=1;
serialclk = ~serialclk;
end
else begin
cnt = cnt + 1;
end
end
endmodule
module clk(clk);
output clk;
reg clk;
always
#1 clk = ~clk;
initial begin
clk = 1'b 0;
end
endmodule
I am working on my first project in Verilog, currently in ModelSIM. The
target will most likely be a Xilinx FPGA.
This part of my project is very simple. It simply listens for commands
sent via a serial connection, decodes the packet, and responds
appropriately. I am trying to use multiple modules, one for each type of
packet that needs to be constructed, and send using a common 'serialtx'
module.
What I am unsure about is how to get the data from one location to
another when multiple modules need to write to a common buffer.
In my simplified example below, 'cmd_one' and 'cmd_two', both construct
packets to be sent by 'serialtx'. What I see when I run this in
simulation is that the local packets 'lpkt' get populated, but the value
is not reflected in 'opkt' for 'serialtx'.
I may be going about this completely the wrong way, or just missing
something simple. Your assistance is really appreciated.
Example below...
Thanks,
RL
`timescale 1ns / 100ps
module cmd_one (clk,opkt,opktready);
output [0:95] opkt;
inout opktready;
input clk;
reg [0:95] lpkt;
reg lpktready;
serialtx u0(.opkt(opkt),.opktready(opktready),.serialclk());
clk u1(.clk(clk));
assign opktready = lpktready;
assign opkt = lpkt;
always @(posedge clk) begin
lpkt = 95'd 1;
lpktready = 1;
end
endmodule
module cmd_two (clk,opkt,opktready);
output [0:95] opkt;
inout opktready;
input clk;
reg [0:95] lpkt;
reg lpktready;
serialtx u0(.opkt(opkt),.opktready(opktready),.serialclk());
clk u1(.clk(clk));
assign opktready = lpktready;
assign opkt = lpkt;
always @(negedge clk) begin
lpkt = 95'd 2;
lpktready = 1;
end
endmodule
module serialtx (opkt,opktready,serialclk);
input[0:95] opkt;
inout opktready;
input serialclk;
reg lpktready;
serialclk u0(.clk(),.serialclk(serialclk));
initial begin
lpktready = 0;
end
assign opktready = lpktready;
always @(posedge opktready) begin
// Send the packet...
lpktready = 0;
end
endmodule
module serialclk (clk,serialclk);
input clk;
output serialclk;
reg serialclk;
reg[0:15] cnt;
reg[0:15] clocks;
clk u0(.clk(clk));
initial begin
serialclk = 1'b 0;
cnt = 16'd 0;
clocks = 16'd 5;
end
always @(posedge clk) begin
if(cnt == clocks) begin
cnt=1;
serialclk = ~serialclk;
end
else begin
cnt = cnt + 1;
end
end
endmodule
module clk(clk);
output clk;
reg clk;
always
#1 clk = ~clk;
initial begin
clk = 1'b 0;
end
endmodule