URL
https://opencores.org/ocsvn/wbuart32/wbuart32/trunk
Subversion Repositories wbuart32
Compare Revisions
- This comparison shows the changes necessary to convert path
/wbuart32/trunk/bench
- from Rev 16 to Rev 18
- ↔ Reverse comparison
Rev 16 → Rev 18
/cpp/Makefile
76,38 → 76,41
RTLD := ../verilog |
VERILATOR_ROOT ?= $(shell bash -c 'verilator -V|grep VERILATOR_ROOT | head -1 | sed -e " s/^.*=\s*//"') |
VROOT := $(VERILATOR_ROOT) |
INCS := -I$(RTLD)/obj_dir/ -I/usr/share/verilator/include |
INCS := -I$(RTLD)/obj_dir/ -I$(VROOT)/include |
SOURCES := helloworld.cpp linetest.cpp uartsim.cpp uartsim.h |
VOBJDR := $(RTLD)/obj_dir |
SYSVDR := /usr/share/verilator/include |
VLIB := $(SYSVDR)/verilated.cpp $(SYSVDR)/verilated_vcd_c.cpp |
SYSVDR := $(VROOT)/include |
VSRC := verilated.cpp verilated_vcd_c.cpp |
VLIB := $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(VSRC))) |
# Sources necessary to build the linetest program (rxuart-txuart test) |
LINSRCS := linetest.cpp uartsim.cpp |
LINOBJ := $(subst .cpp,.o,$(LINSRCS)) |
LINOBJS:= $(addprefix $(OBJDIR)/,$(LINOBJ)) |
LINOBJS:= $(addprefix $(OBJDIR)/,$(LINOBJ)) $(VLIB) |
# Sources necessary to build the helloworld test (txuart test) |
HLOSRCS := helloworld.cpp uartsim.cpp |
HLOOBJ := $(subst .cpp,.o,$(HLOSRCS)) |
HLOOBJS:= $(addprefix $(OBJDIR)/,$(HLOOBJ)) |
HLOOBJS:= $(addprefix $(OBJDIR)/,$(HLOOBJ)) $(VLIB) |
# Sources necessary to build the speech test (wbuart test) |
SPCHSRCS:= speechtest.cpp uartsim.cpp |
SPCHOBJ := $(subst .cpp,.o,$(SPCHSRCS)) |
SPCHOBJS:= $(addprefix $(OBJDIR)/,$(SPCHOBJ)) |
SPCHOBJS:= $(addprefix $(OBJDIR)/,$(SPCHOBJ)) $(VLIB) |
all: $(OBJDIR)/ linetest helloworld speechtest test |
|
$(OBJDIR)/: |
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi" |
|
$(OBJDIR)/uartsim.o: uartsim.cpp uartsim.h |
|
$(OBJDIR)/%.o: %.cpp |
$(mk-objdir) |
$(CXX) $(FLAGS) $(INCS) -c $< -o $@ |
|
$(OBJDIR)/%.o: $(SYSVDR)/%.cpp |
$(mk-objdir) |
$(CXX) $(FLAGS) $(INCS) -c $< -o $@ |
|
linetest: $(LINOBJS) $(VOBJDR)/Vlinetest__ALL.a |
$(CXX) $(FLAGS) $(INCS) $^ $(VLIB) -o $@ |
$(CXX) $(FLAGS) $(INCS) $^ -o $@ |
|
helloworld: $(HLOOBJS) $(VOBJDR)/Vhelloworld__ALL.a |
$(CXX) $(FLAGS) $(INCS) $^ $(VLIB) -o $@ |
$(CXX) $(FLAGS) $(INCS) $^ -o $@ |
|
# |
# The speech test program depends upon a copy of the Gettysburg Address, |
131,12 → 134,42
# Actually, we could've done this without the speech file being available, but |
# this works. |
speechtest: speech.hex $(SPCHOBJS) $(VOBJDR)/Vspeechfifo__ALL.a |
$(CXX) $(FLAGS) $(INCS) $(SPCHOBJS) $(VOBJDR)/Vspeechfifo__ALL.a $(VLIB) -o $@ |
$(CXX) $(FLAGS) $(INCS) $(SPCHOBJS) $(VOBJDR)/Vspeechfifo__ALL.a -o $@ |
|
test: linetest speechtest |
./linetest |
./speechtest |
|
# |
# The "depends" target, to know what files things depend upon. The depends |
# file itself is kept in $(OBJDIR)/depends.txt |
# |
define build-depends |
$(mk-objdir) |
@echo "Building dependency file" |
@$(CXX) $(CFLAGS) $(INCS) -MM $(SOURCES) > $(OBJDIR)/xdepends.txt |
@sed -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdepends.txt > $(OBJDIR)/depends.txt |
@rm $(OBJDIR)/xdepends.txt |
endef |
|
.PHONY: depends |
depends: tags |
$(build-depends) |
|
$(OBJDIR)/depends.txt: depends |
|
# |
define mk-objdir |
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi" |
endef |
|
# |
# The "tags" target |
# |
tags: $(SOURCES) $(HEADERS) |
@echo "Generating tags" |
@ctags $(SOURCES) $(HEADERS) |
|
.PHONY: clean |
clean: |
rm -f ./linetest ./helloworld ./speechtest |
143,3 → 176,4
rm -f ./mkspeech ./speech.hex |
rm -rf $(OBJDIR)/ |
|
-include $(OBJDIR)/depends.txt |
/cpp/helloworld.cpp
36,6 → 36,7
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <verilatedos.h> |
#include <stdio.h> |
#include <fcntl.h> |
#include <unistd.h> |
/cpp/linetest.cpp
44,6 → 44,7
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <verilatedos.h> |
#include <stdio.h> |
#include <fcntl.h> |
#include <unistd.h> |
/cpp/speech.txt
1,24 → 1,32
Four score and seven years ago our fathers brought forth on this continent, a |
new nation, conceived in Liberty, and dedicated to the proposition that all men |
are created equal. |
|===================================================================| |
| | |
| Four score and seven years ago our fathers brought forth on this | |
| continent, a new nation, conceived in Liberty, and dedicated to | |
| the proposition that all men are created equal. | |
| | |
| Now we are engaged in a great civil war, testing whether that | |
| nation, or any nation so conceived and so dedicated, can long | |
| endure. We are met on a great battle-field of that war. We have | |
| come to dedicate a portion of that field, as a final resting | |
| place for those who here gave their lives that that nation might | |
| live. It is altogether fitting and proper that we should do this. | |
| | |
| But, in a larger sense, we can not dedicate-we can not consecrate-| |
| we can not hallow-this ground. The brave men, living and dead, | |
| who struggled here, have consecrated it, far above our poor power | |
| to add or detract. The world will little note, nor long remember | |
| what we say here, but it can never forget what they did here. It | |
| is for us the living, rather, to be dedicated here to the | |
| unfinished work which they who fought here have thus far so nobly | |
| advanced. It is rather for us to be here dedicated to the great | |
| task remaining before us-that from these honored dead we take | |
| increased devotion to that cause for which they gave the last | |
| full measure of devotion-that we here highly resolve that these | |
| dead shall not have died in vain-that this nation, under God, | |
| shall have a new birth of freedom-and that government of the | |
| people, by the people, for the people, shall not perish from the | |
| earth. | |
| | |
| | |
|===================================================================| |
|
Now we are engaged in a great civil war, testing whether that nation, or any |
nation so conceived and so dedicated, can long endure. We are met on a great |
battle-field of that war. We have come to dedicate a portion of that field, as |
a final resting place for those who here gave their lives that that nation |
might live. It is altogether fitting and proper that we should do this. |
|
But, in a larger sense, we can not dedicate-we can not consecrate-we can not |
hallow-this ground. The brave men, living and dead, who struggled here, have |
consecrated it, far above our poor power to add or detract. The world will |
little note, nor long remember what we say here, but it can never forget what |
they did here. It is for us the living, rather, to be dedicated here to the |
unfinished work which they who fought here have thus far so nobly advanced. It |
is rather for us to be here dedicated to the great task remaining before |
us-that from these honored dead we take increased devotion to that cause for |
which they gave the last full measure of devotion-that we here highly resolve |
that these dead shall not have died in vain-that this nation, under God, shall |
have a new birth of freedom-and that government of the people, by the people, |
for the people, shall not perish from the earth. |
|
|
/cpp/speechtest.cpp
41,6 → 41,7
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <verilatedos.h> |
#include <stdio.h> |
#include <fcntl.h> |
#include <unistd.h> |
115,7 → 116,7
tfp->open("speechtrace.vcd"); |
|
testcount = 0; |
while(testcount < baudclocks * 16 * 2048) { |
while(testcount < baudclocks * 16 * 4096) { |
// Run one tick of the clock. |
|
tb.i_clk = 1; // Positive edge |
/cpp/uartsim.cpp
57,8 → 57,8
|
m_skt = socket(AF_INET, SOCK_STREAM, 0); |
if (m_skt < 0) { |
perror("Could not allocate socket: "); |
exit(-1); |
perror("ERR: Could not allocate socket: "); |
exit(EXIT_FAILURE); |
} |
|
// Set the reuse address option |
66,8 → 66,8
int optv = 1, er; |
er = setsockopt(m_skt, SOL_SOCKET, SO_REUSEADDR, &optv, sizeof(optv)); |
if (er != 0) { |
perror("SockOpt Err:"); |
exit(-1); |
perror("ERR: SockOpt Err:"); |
exit(EXIT_FAILURE); |
} |
} |
|
79,13 → 79,13
my_addr.sin_port = htons(port); |
|
if (bind(m_skt, (struct sockaddr *)&my_addr, sizeof(my_addr))!=0) { |
perror("BIND FAILED:"); |
exit(-1); |
perror("ERR: BIND FAILED:"); |
exit(EXIT_FAILURE); |
} |
|
if (listen(m_skt, 1) != 0) { |
perror("Listen failed:"); |
exit(-1); |
perror("ERR: Listen failed:"); |
exit(EXIT_FAILURE); |
} |
} |
|
131,9 → 131,7
} |
} |
|
int UARTSIM::nettick(int i_tx) { |
int o_rx = 1; |
|
void UARTSIM::check_for_new_connections(void) { |
if ((m_conrd < 0)&&(m_conwr<0)&&(m_skt>=0)) { |
// Can we accept a connection? |
struct pollfd pb; |
148,9 → 146,17
|
if (m_conrd < 0) |
perror("Accept failed:"); |
// else printf("New connection accepted!\n"); |
} |
} |
|
} |
|
int UARTSIM::nettick(int i_tx) { |
int o_rx = 1, nr = 0; |
|
check_for_new_connections(); |
|
if ((!i_tx)&&(m_last_tx)) |
m_rx_changectr = 0; |
else m_rx_changectr++; |
173,6 → 179,7
if (1 != send(m_conwr, buf, 1, 0)) { |
close(m_conwr); |
m_conrd = m_conwr = -1; |
fprintf(stderr, "Failed write, connection closed\n"); |
} |
} |
} else { |
201,7 → 208,7
perror("Polling error:"); |
if (pb.revents & POLLIN) { |
char buf[1]; |
if (1 == recv(m_conrd, buf, 1, MSG_DONTWAIT)) { |
if (1 == (nr = recv(m_conrd, buf, 1, MSG_DONTWAIT))) { |
m_tx_data = (-1<<(m_nbits+m_nparity+1)) |
// << nstart_bits |
|((buf[0]<<1)&0x01fe); |
226,6 → 233,14
m_tx_state = TXDATA; |
o_rx = 0; |
m_tx_baudcounter = m_baud_counts-1; |
} else if (nr == 0) { |
close(m_conrd); |
m_conrd = m_conwr = -1; |
// printf("Closing network connection\n"); |
} else if (nr < 0) { |
perror("O/S Read err:"); |
close(m_conrd); |
m_conrd = m_conwr = -1; |
} |
} |
} else if (m_tx_baudcounter <= 0) { |
/cpp/uartsim.h
79,6 → 79,10
// related setup stuff. |
void setup_listener(const int port); |
|
// Call check_for_new_connections() to see if we can accept a new |
// network socket connection to our device |
void check_for_new_connections(void); |
|
// nettick() gets called if we are connected to a network, and |
int nettick(const int i_tx); |
// fdtick() if we are not. |
/verilog/Makefile
18,7 → 18,7
## |
## // If we have a 100MHz clock, then we can set up for a 115,200 |
## // baud clock by setting i_setup to (100MHz / 115200) ~= 868. |
## // The upper bits of this number also set the protocol to |
## // The upper bits of this number also set the protocol to |
## // one stop bit, no parity, and 8 data bits. |
## assign i_setup = 30'd868; // 115,200 Baud 8N1 |
## |
58,7 → 58,7
## for more details. |
## |
## You should have received a copy of the GNU General Public License along |
## with this program. (It's in the $(ROOT)/doc directory, run make with no |
## with this program. (It's in the $(ROOT)/doc directory. Run make with no |
## target there if the PDF file isn't present.) If not, see |
## <http://www.gnu.org/licenses/> for a copy. |
## |
74,6 → 74,8
FBDIR := . |
VDIRFB:= $(FBDIR)/obj_dir |
RTLDR := ../../rtl |
VERILATOR := verilator |
VFLAGS := -Wall --MMD --trace -y ../../rtl -cc |
|
.PHONY: test testline testhello speechfifo |
test: testline testhello speechfifo |
99,7 → 101,7
$(SPEECHVFILES): speechfifo.v $(SPEECHSRCS) |
|
$(VDIRFB)/V%.cpp $(VDIRFB)/V%.h $(VDIRFB)/V%.mk: $(FBDIR)/%.v |
verilator --trace -cc -y ../../rtl $*.v |
$(VERILATOR) $(VFLAGS) $*.v |
|
$(VDIRFB)/V%__ALL.a: $(VDIRFB)/V%.mk |
cd $(VDIRFB); make -f V$*.mk |
111,3 → 113,7
rm -rf $(VDIRFB)/*.h |
rm -rf $(VDIRFB)/ |
|
DIRS := $(wildcard $(VDIRFB)/*.d) |
ifneq ($(DIRS),) |
-include $(DIRS) |
endif |
/verilog/linetest.v
91,7 → 91,7
reg pwr_reset; |
initial pwr_reset = 1'b1; |
always @(posedge i_clk) |
pwr_reset = 1'b0; |
pwr_reset <= 1'b0; |
|
|
|
102,7 → 102,10
// Data (rx_data) is present when rx_stb is true. Any parity or |
// frame errors will also be valid at that time. Finally, we'll ignore |
// errors, and even the clocked uart input distributed from here. |
wire rx_stb, rx_break, rx_perr, rx_ferr, rx_ignored; |
wire rx_stb, rx_break, rx_perr, rx_ferr; |
/* verilator lint_off UNUSED */ |
wire rx_ignored; |
/* verilator lint_on UNUSED */ |
wire [7:0] rx_data; |
|
`ifdef USE_LITE_UART |
/verilog/speechfifo.v
21,7 → 21,7
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// Copyright (C) 2015-2017, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): you can redistribute it and/or |
// modify it under the terms of the GNU General Public License as published |
72,6 → 72,10
// i_setup, but at least it gives us something to start with/from. |
parameter INITIAL_UART_SETUP = 31'd868; |
|
// Let's set our message length, in case we ever wish to change it in |
// the future |
localparam MSGLEN=2203; |
|
// The i_setup wires are input when run under Verilator, but need to |
// be set internally if this is going to run as a standalone top level |
// test configuration. |
87,11 → 91,22
reg [1:0] wb_addr; |
reg [31:0] wb_data; |
|
wire uart_stall, uart_ack; |
wire uart_stall; |
|
// We aren't using the receive interrupts, or the received data, or the |
// ready to send line, so we'll just mark them all here as ignored. |
|
/* verilator lint_off UNUSED */ |
wire uart_ack, tx_int; |
wire [31:0] uart_data; |
wire ignored_rx_int, ignored_rxfifo_int; |
wire rts_n_ignored; |
/* verilator lint_on UNUSED */ |
|
wire tx_int, txfifo_int; |
/* verilator lint_on UNUSED */ |
|
wire txfifo_int; |
|
// The next four lines create a strobe signal that is true on the first |
// clock, but never after. This makes for a decent power-on reset |
// signal. |
107,7 → 122,7
// element to a space so that if (for some reason) we broadcast past the |
// end of our message, we'll at least be sending something useful. |
integer i; |
reg [7:0] message [0:2047]; |
reg [7:0] message [0:4095]; |
initial begin |
// xx Verilator needs this file to be in the directory the file |
// is run from. For that reason, the project builds, makes, |
121,8 → 136,9
// synthesis tool can find it. |
// |
$readmemh("speech.hex", message); |
for(i=1481; i<2048; i=i+1) |
for(i=MSGLEN; i<4095; i=i+1) |
message[i] = 8'h20; |
|
// |
// The problem with the above approach is Xilinx's ISE program. |
// It's broken. It can't handle HEX files well (at all?) and |
164,8 → 180,8
// transmit next. Note, there's a clock delay between setting this |
// index and when the wb_data is valid. Hence, we set the index on |
// restart[0] to zero. |
reg [10:0] msg_index; |
initial msg_index = 11'd2040; |
reg [11:0] msg_index; |
initial msg_index = 12'h000 - 12'h8; |
always @(posedge i_clk) |
begin |
if (restart) |
220,7 → 236,7
if (restart) |
end_of_message <= 1'b0; |
else |
end_of_message <= (msg_index >= 1481); |
end_of_message <= (msg_index >= MSGLEN); |
|
// The wb_stb signal indicates that we wish to write, using the wishbone |
// to our peripheral. We have two separate types of writes. First, |
248,10 → 264,6
// But once the FIFO gets to half full, stop. |
wb_stb <= 1'b0; |
|
// We aren't using the receive interrupts, so we'll just mark them |
// here as ignored. |
wire ignored_rx_int, ignored_rxfifo_int; |
|
// The WBUART can handle hardware flow control signals. This test, |
// however, cannot. The reason? Simply just to keep things simple. |
// If you want to add hardware flow control to your design, simply |
259,7 → 271,7
// |
// Since this is an output only module demonstrator, what would be the |
// cts output is unused. |
wire cts_n, rts_n_ignored; |
wire cts_n; |
assign cts_n = 1'b0; |
|
// Finally--the unit under test--now that we've set up all the wires |