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/cpp
- from Rev 16 to Rev 18
- ↔ Reverse comparison
Rev 16 → Rev 18
/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 |
/helloworld.cpp
36,6 → 36,7
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <verilatedos.h> |
#include <stdio.h> |
#include <fcntl.h> |
#include <unistd.h> |
/linetest.cpp
44,6 → 44,7
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include <verilatedos.h> |
#include <stdio.h> |
#include <fcntl.h> |
#include <unistd.h> |
/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. |
|
|
/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 |
/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) { |
/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. |