Skip to content

Commit 602ef71

Browse files
committed
Initial Release
All the files for the initial release of the DESim software tool.
1 parent f91d6f3 commit 602ef71

File tree

141 files changed

+9486
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

141 files changed

+9486
-2
lines changed

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,37 @@
3030
*.exe
3131
*.out
3232
*.app
33+
34+
# Compiled class file
35+
*.class
36+
37+
# Log file
38+
*.log
39+
40+
# BlueJ files
41+
*.ctxt
42+
43+
# Mobile Tools for Java (J2ME)
44+
.mtj.tmp/
45+
46+
# Package Files #
47+
*.jar
48+
*.war
49+
*.nar
50+
*.ear
51+
*.zip
52+
*.tar.gz
53+
*.rar
54+
55+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
56+
hs_err_pid*
57+
58+
# VI Swap Files
59+
*.swp
60+
61+
# ModelSim VPI
62+
*.vpi
63+
64+
# Software Build/Release Paths
65+
dist/
66+
out/

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 fpgacademy
3+
Copyright (c) 2020 fpgacademy
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1-
# DESim
1+
# DESim
2+
3+
The DESim tool is an interactive graphical user interface showing features of a DE-Series board, such as switches, lights, and displays. The tool interfaces with the ModelSim simulation software. The simulation results affect the lights and displays in the GUI, as opposed to showing the waveforms corresponding to the signals being simulated.
4+
5+
The DESim tool has three parts:
6+
1) The frontend graphical user interface
7+
2) The backend simulator interface
8+
3) Various demos showcasing the different capabilities of the tool
9+
10+
The DESim tool requires the ModelSim HDL simuator. Preferably, one of the ModelSim-Intel FPGA editions, which has the Intel FPGA IP Core simulation models built-in.

backend/Makefile

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Copyright (c) 2020 FPGAcademy
2+
# Please see license at https://github.com/fpgacademy/DESim
3+
4+
MODELSIM_DIR = C:\intelFPGA\19.1\modelsim_ae
5+
6+
CFLAGS = -m32 -static -c -Wall -g -fno-diagnostics-show-caret -fpic -Iinclude -I$(MODELSIM_DIR)/include
7+
LDFLAGS = -m32 -static -g -shared -lmtipli
8+
9+
ifeq ($(OS),Windows_NT)
10+
LDFLAGS += -lws2_32
11+
LDFLAGS += -L$(MODELSIM_DIR)/win32aloem
12+
endif
13+
14+
all: dist/simfpga.vpi
15+
16+
utils.o: utils.c include/utils.h
17+
gcc utils.c $(CFLAGS)
18+
19+
fpga_output_device.o: fpga_output_device.cpp include/fpga_output_device.h
20+
g++ fpga_output_device.cpp $(CFLAGS)
21+
22+
fpga_input_device.o: fpga_input_device.cpp include/fpga_input_device.h
23+
g++ fpga_input_device.cpp $(CFLAGS)
24+
25+
fpga_inout_device.o: fpga_inout_device.cpp include/fpga_inout_device.h
26+
g++ fpga_inout_device.cpp $(CFLAGS)
27+
28+
keyboard_input.o: keyboard_input.cpp include/keyboard_input.h
29+
g++ keyboard_input.cpp $(CFLAGS)
30+
31+
fpga.o: fpga.cpp include/fpga*.h include/keyboard_input.h include/utils.h include/helper.h
32+
g++ fpga.cpp $(CFLAGS)
33+
34+
sim_task.o: sim_task.cpp include/sim_task.h include/fpga.h include/utils.h include/helper.h
35+
g++ sim_task.cpp $(CFLAGS)
36+
37+
dist/simfpga.vpi: sim_task.o utils.o fpga.o fpga_output_device.o fpga_input_device.o keyboard_input.o fpga_inout_device.o
38+
g++ -o dist/simfpga.vpi fpga_inout_device.o keyboard_input.o fpga_input_device.o fpga_output_device.o fpga.o sim_task.o utils.o $(LDFLAGS)
39+
40+
update_demos: dist/simfpga.vpi
41+
cp dist/simfpga.vpi ../demos/Accumulate/sim/.
42+
cp dist/simfpga.vpi ../demos/Addern/sim/.
43+
cp dist/simfpga.vpi ../demos/Counter/sim/.
44+
cp dist/simfpga.vpi ../demos/Counter_LPM/sim/.
45+
cp dist/simfpga.vpi ../demos/Display/sim/.
46+
cp dist/simfpga.vpi ../demos/GPIO/gpio_bidir_demo/sim/.
47+
cp dist/simfpga.vpi ../demos/GPIO/gpio_in_demo/sim/.
48+
cp dist/simfpga.vpi ../demos/GPIO/gpio_out_demo/sim/.
49+
cp dist/simfpga.vpi ../demos/LED_HEX/sim/.
50+
cp dist/simfpga.vpi ../demos/ps2_demo/sim/.
51+
cp dist/simfpga.vpi ../demos/vga_demo/sim/.
52+
53+
clean:
54+
rm -rf *.o
55+
rm -rf dist/*.vpi
56+

backend/fpga.cpp

Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
// Copyright (c) 2020 FPGAcademy
2+
// Please see license at https://github.com/fpgacademy/DESim
3+
4+
#include "fpga.h"
5+
#include "helper.h"
6+
7+
fpga::fpga(vpiHandle clk_handle, vpiHandle switch_handle, vpiHandle key_handle,
8+
vpiHandle led_handle, vpiHandle hex_handle, vpiHandle key_action_handle,
9+
vpiHandle scan_code_handle, vpiHandle ps2_lock_handle,
10+
vpiHandle x_handle, vpiHandle y_handle, vpiHandle color_handle, vpiHandle plot_handle,
11+
vpiHandle gpio_handle) {
12+
// basic I/O
13+
this->leds = new fpga_output_device(NUM_LEDS, vpiBinStrVal, 'l', led_handle);
14+
this->hex_displays = new fpga_output_device(HEX_SIG_LENGTH, vpiHexStrVal, 'h', hex_handle);
15+
16+
this->switches = new fpga_input_device(NUM_SW, vpiBinStrVal, "0000000000", switch_handle);
17+
this->keys = new fpga_input_device(NUM_KEYS, vpiBinStrVal, "1111", key_handle);
18+
19+
// gpio
20+
this->gpio = new fpga_inout_device(NUM_GPIO, vpiBinStrVal, 'g', gpio_handle);
21+
22+
// ps2
23+
this->ps2_locks = new fpga_output_device(NUM_PS2_LOCKS, vpiBinStrVal, 'p', ps2_lock_handle);
24+
this->keyboard = new keyboard_input(key_action_handle, scan_code_handle);
25+
26+
// vga
27+
this->clk_handle = clk_handle;
28+
this->vga_x_handle = x_handle;
29+
this->vga_y_handle = y_handle;
30+
this->vga_color_handle = color_handle;
31+
this->vga_plot_handle = plot_handle;
32+
33+
this->rwsync_cb_reg = 0;
34+
this->rosync_cb_reg = 0;
35+
36+
this->keep_alive_cb_handle = NULL;
37+
}
38+
39+
40+
void fpga::UpdateOutputValue(char device_type, s_vpi_value *value) {
41+
if (device_type == 'l') {
42+
if(this->leds->UpdateValue(value)){
43+
vpi_printf_helper("Error: incorrect led value format\n");
44+
vpi_control(vpiFinish, 1);
45+
}
46+
} else if(device_type == 'h') {
47+
if(this->hex_displays->UpdateValue(value)){
48+
vpi_printf_helper("Error: incorrect hex display value format\n");
49+
vpi_control(vpiFinish, 1);
50+
}
51+
} else if(device_type == 'p') {
52+
if(this->ps2_locks->UpdateValue(value)){
53+
vpi_printf_helper("Error: incorrect ps2 lock value format\n");
54+
vpi_control(vpiFinish, 1);
55+
}
56+
}else if(device_type == 'g'){
57+
if(this->gpio->UpdateOutputValue(value)){
58+
vpi_printf_helper("Error: incorrect gpio value format\n");
59+
vpi_control(vpiFinish, 1);
60+
}
61+
}
62+
}
63+
64+
// Send output signals to GUI
65+
void fpga::SendOutputValue(sockfd server) {
66+
this->leds->SendValue(server);
67+
this->hex_displays->SendValue(server);
68+
this->ps2_locks->SendValue(server);
69+
this->gpio->SendValue(server);
70+
}
71+
72+
73+
void fpga::SetInitialSimInput() {
74+
this->switches->SetInitialValue();
75+
this->keys->SetInitialValue();
76+
this->keyboard->SetInitialValue();
77+
}
78+
79+
// Process input signals from GUI
80+
int fpga::HandleInput(char *msg) {
81+
82+
char *tokens = strpbrk(msg, " \t\r\n\v");
83+
if (tokens) {
84+
// truncate msg in order to compare the first word of msg
85+
*tokens = 0;
86+
tokens++;
87+
}
88+
89+
if (!tokens) {
90+
vpi_printf_helper("Warning: malformed command. Ignoring...\n");
91+
vpi_mcd_flush(1);
92+
return 0;
93+
}
94+
if (!strcmp(msg, "SW")) {
95+
if(this->switches->UpdateValue(tokens)){
96+
vpi_printf_helper("Warning: malformed switch command. Ignoring...\n");
97+
vpi_mcd_flush(1);
98+
}
99+
100+
} else if (!strcmp(msg, "KEY")) {
101+
if(this->keys->UpdateValue(tokens)){
102+
vpi_printf_helper("Warning: malformed push button command. Ignoring...\n");
103+
vpi_mcd_flush(1);
104+
}
105+
106+
} else if (!strcmp(msg, "KB")) {
107+
if(this->keyboard->UpdateValue(tokens)){
108+
vpi_printf_helper("Warning: malformed keyboard scan code. Ignoring...\n");
109+
vpi_mcd_flush(1);
110+
}
111+
112+
} else if (!strcmp(msg, "GPIO")) {
113+
if(this->gpio->UpdateInputValue(tokens)){
114+
vpi_printf_helper("Warning: malformed gpio command. Ignoring...\n");
115+
vpi_mcd_flush(1);
116+
}
117+
}else if (!strcmp(msg, "end")) {
118+
vpi_control(vpiFinish, 1);
119+
return 0;
120+
}
121+
122+
return 0;
123+
}
124+
125+
126+
void fpga::SendVGAPixelValue(sockfd server){
127+
128+
s_vpi_value val = {.format = vpiIntVal};
129+
vpi_get_value(this->vga_plot_handle, &val);
130+
131+
// first check if plot is 1, then send pixel value
132+
if(val.value.integer != 0){
133+
int x, y, color;
134+
135+
vpi_get_value(this->vga_x_handle, &val);
136+
x = val.value.integer;
137+
vpi_get_value(this->vga_y_handle, &val);
138+
y = val.value.integer;
139+
vpi_get_value(this->vga_color_handle, &val);
140+
color = val.value.integer;
141+
142+
char line[80];
143+
//write at most size bytes (including '\0')
144+
snprintf(line, 80, "c %03d %03d %d\n", x, y, color);
145+
146+
int rc = send(server, line, 12, 0);
147+
if (rc <= 0) {
148+
vpi_printf_helper("Could not send VGA signal to GUI\n");
149+
vpi_mcd_flush(1);
150+
vpi_control(vpiFinish, 1);
151+
}
152+
}
153+
}
154+
155+
156+
157+
fpga::~fpga(){
158+
delete this->leds;
159+
delete this->hex_displays;
160+
delete this->switches;
161+
delete this->keys;
162+
delete this->gpio;
163+
delete this->ps2_locks;
164+
delete this->keyboard;
165+
166+
}
167+
168+
bool fpga::operator = (fpga const &other){
169+
// devices should be the same
170+
if(this->leds != other.leds) return false;
171+
if(this->hex_displays != other.hex_displays) return false;
172+
if(this->switches != other.switches) return false;
173+
if(this->keys != other.keys) return false;
174+
if(this->ps2_locks != other.ps2_locks) return false;
175+
if(this->keyboard != other.keyboard) return false;
176+
if(this->gpio != other.gpio) return false;
177+
178+
// device handles
179+
if(this->clk_handle != other.clk_handle) return false;
180+
if(this->vga_x_handle != other.vga_x_handle) return false;
181+
if(this->vga_y_handle != other.vga_y_handle) return false;
182+
if(this->vga_color_handle != other.vga_y_handle) return false;
183+
if(this->vga_plot_handle != other.vga_plot_handle) return false;
184+
185+
// read/write/keep alive callback can be either registered or not
186+
return true;
187+
}
188+
189+
190+
fpga::fpga(fpga const &other){
191+
this->leds = new fpga_output_device(*(other.leds));
192+
this->hex_displays = new fpga_output_device(*(other.hex_displays));
193+
this->switches = new fpga_input_device(*(other.switches));
194+
this->keys = new fpga_input_device(*(other.keys));
195+
this->ps2_locks = new fpga_output_device(*(other.ps2_locks));
196+
this->keyboard = new keyboard_input(*(other.keyboard));
197+
this->gpio = new fpga_inout_device(*(other.gpio));
198+
199+
this->clk_handle = other.clk_handle;
200+
this->vga_x_handle = other.vga_x_handle;
201+
this->vga_y_handle = other.vga_y_handle;
202+
this->vga_color_handle = other.vga_color_handle;
203+
this->vga_plot_handle = other.vga_plot_handle;
204+
205+
this->rwsync_cb_reg = 0;
206+
this->rosync_cb_reg = 0;
207+
this->keep_alive_cb_handle = NULL;
208+
}
209+
210+
211+

0 commit comments

Comments
 (0)