Skip to content

Commit

Permalink
feat: VPL guide, VPL test 1 (#24)
Browse files Browse the repository at this point in the history
This PR adds the guide for VPL on Moodle, VPL scripts and files for the VPL test 1.
  • Loading branch information
sdcioc authored Oct 23, 2024
1 parent 7b745b9 commit f454e8b
Show file tree
Hide file tree
Showing 52 changed files with 1,403 additions and 7 deletions.
6 changes: 3 additions & 3 deletions chapters/grading/grading.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
- Când: la începutul laboratorului 4
- Strcutură: 3 exerciții practice de implementat în verilog
- Locație: sala de laborator
- Platformă: Calculator Laborator - Safe Exam Browser - Moodle - VPL
- Platformă: Calculator Laborator - Moodle - VPL

### Test circuite secvențiale
- Materia necesară: laboratoarele 4,5 și 6
- Durată: 60 de minute
- Când: la începutul laboratorului 7
- Strcutură: 3 exerciții practice de implementat în verilog
- Locație: sala de laborator
- Platformă: Calculator Laborator - Safe Exam Browser - Moodle - VPL
- Platformă: Calculator Laborator - Moodle - VPL

### Colocviu final calculator didactic
- Materia necesară: toate laboratoarele
Expand All @@ -35,7 +35,7 @@
- 3 exerciții practice de implementat în verilog
- 20 întrebări teoretice
- Locație: sala de laborator
- Platformă: Calculator Laborator - Safe Exam Browser - Moodle - VPL/Quiz
- Platformă: Calculator Laborator - Moodle - VPL/Quiz

### Tema
- Durată: Întreg semestrul cu termen limită începutul ultimii săptămâni de laborator
Expand Down
Binary file added chapters/guides/media/VPL1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL10.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added chapters/guides/media/VPL9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions chapters/guides/vpl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Moodle VPL

1. Din cadrul cursului vom selecta "SIMULARE VPL"

![VPL1](../media/VPL1.png)

2. Veți avea următoarea fereastră care va conține descrierea exercițiului și fișierele pe care le puteți modifica. Pentru a le edita apăsați butonul "EDIT".

![VPL2](../media/VPL2.png)

3. În cadrul IDE-ului VPL veți avea un tab cu fiecare fișier (mux.v, test_mux.v), punctajul în dreapta, rezultatele compilării sau evaluării.

![VPL3](../media/VPL3.png)

4. Puteți modifica fișierul "mux.v". Atât timp cât fișierele nu sunt salvate veți avea o stea în dreptul numelui fișierului. Pentru a salva apăsați butonul "Save".

![VPL4](../media/VPL4.png)

5. O dată salvat fișierul steaua va dispărea. Acum puteți apăsa pe butonul "Run" pentru a vedea enunțul.

![VPL5](../media/VPL5.png)

6. Se va porni o consolă ca în imaginea următoare. Veți avea detalii despre implementarea pe care o aveți de făcut și rezultatele rulării modului nostru de test/simulare.

![VPL6](../media/VPL6.png)

7. Pentru a evalua soluția voastră puteți apăsa butonul "Evaluate". Nota va fi modificată în dreapta și vom avea descrierea implementării și primul test eșuat.

![VPL7](../media/VPL7.png)

8. Pentru a vedea mai bine detaliile testului puteți modifica mărimea ferestrelor.

![VPL8](../media/VPL8.png)

9. Daca doriți să rulați testele voastre pentru a face debug, puteți modifica fișierul "test_mux.v".

![VPL9](../media/VPL9.png)

10. Folosim butonul "Run" și vom vedea rezultatele simulării.

![VPL10](../media/VPL10.png)
3 changes: 3 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.vvp
*.vcd
vpl_execution
46 changes: 46 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
COMPILER=iverilog
INTERPRETER=vvp
SIMULATOR=gtkwave
FLAGS=-Wall -Winfloop
SOLUTION_FLAGS=-DDIGIT1=1 -DDIGIT2=2 -DDIGIT3=3 -DDIGIT4=4
TOP_MODULE=alu
TOP_SIM_MODULE=test_${TOP_MODULE}
TOP_EVALUATE_MODULE=evaluate_${TOP_MODULE}
SOLUTION_MODULE=sol
SOLUTION_SIM_MODULE=test_${SOLUTION_MODULE}
OTHER_SOURCES=bigalu.v
DUMP_VCD_FILE=test.vcd
EVALUATE_FILE=evaluate.out
GRADE_SCRIPT=grade.sh

all: build

build:
$(COMPILER) $(FLAGS) $(TOP_MODULE).v $(TOP_SIM_MODULE).v $(OTHER_SOURCES) -o $(TOP_MODULE).vvp

build_solution:
$(COMPILER) $(FLAGS) ${SOLUTION_FLAGS} ${SOLUTION_SIM_MODULE}.v ${SOLUTION_MODULE}.v $(OTHER_SOURCES) -o $(SOLUTION_MODULE).vvp

build_evaluate:
$(COMPILER) $(FLAGS) ${SOLUTION_FLAGS} ${TOP_MODULE}.v ${SOLUTION_MODULE}.v ${TOP_EVALUATE_MODULE}.v $(OTHER_SOURCES) -o $(TOP_EVALUATE_MODULE).vvp

run: build
$(INTERPRETER) $(TOP_MODULE).vvp

run_solution: build_solution
$(INTERPRETER) $(SOLUTION_MODULE).vvp

run_evaluate: build_evaluate
$(INTERPRETER) $(TOP_EVALUATE_MODULE).vvp > $(EVALUATE_FILE) 2>&1

simulate: run
$(SIMULATOR) $(DUMP_VCD_FILE)

simulate_solution: run_solution
$(SIMULATOR) $(DUMP_VCD_FILE)

evaluate: run_evaluate
./${GRADE_SCRIPT} $(EVALUATE_FILE)

clean:
rm *.vvp $(DUMP_VCD_FILE) $(EVALUATE_FILE)
2 changes: 2 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implmentați modulul verilog pentru un ALU (arithmetic logic unit) cu 2 operanzi i_w_op1 și i_w_op2 pe 4 biți fiecare, cu rezultatul pe 4 biți o_w_out și o linie de selecție pe 2 biți a operație i_w_sel.
Apăsați butonul run din VPL pentru a afla operațile pe care trebuie sa le implementați pentru fiecare selecție.
10 changes: 10 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/alu.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module alu(
output wire [3:0] o_w_out,
input wire [3:0] i_w_op1,
input wire [3:0] i_w_op2,
input wire [1:0 ] i_w_sel
);

//TODO: Implement the digital logic for the 7-segment display

endmodule
33 changes: 33 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/bigalu.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
module bigalu(
output wire [3:0] o_w_out,
input wire [3:0] i_w_op1,
input wire [3:0] i_w_op2,
input wire [3:0 ] i_w_sel
);

reg [3:0] l_r_out;

always @(*) begin
case(i_w_sel)
4'b0000: l_r_out = i_w_op1 + i_w_op2; // add
4'b0001: l_r_out = i_w_op1 - i_w_op2; // sub
4'b0010: l_r_out = i_w_op1 & i_w_op2; // and
4'b0011: l_r_out = i_w_op1 | i_w_op2; // or
4'b0100: l_r_out = i_w_op1 ^ i_w_op2; // xor
4'b0101: l_r_out = i_w_op1 << i_w_op2; // shift left
4'b0110: l_r_out = i_w_op1 >> i_w_op2; // shift right
4'b0111: l_r_out = i_w_op1 >>> i_w_op2; // shift right arithmetic
4'b1000: l_r_out = i_w_op1 * i_w_op2; // multiply
4'b1001: l_r_out = i_w_op1 / i_w_op2; // divide
4'b1010: l_r_out = i_w_op1 % i_w_op2; // modulo
4'b1011: l_r_out = i_w_op1 == i_w_op2; // equal
4'b1100: l_r_out = i_w_op1 < i_w_op2; // less than
4'b1101: l_r_out = i_w_op1 > i_w_op2; // greater than
4'b1110: l_r_out = ~(i_w_op1 & i_w_op2); // NAND
4'b1111: l_r_out = ~(i_w_op1 | i_w_op2); // NOR
endcase
end

assign o_w_out = l_r_out;

endmodule
55 changes: 55 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/evaluate_alu.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
`timescale 1ns / 1ps
module evaluate_alu;
//Inputs
reg[3:0] l_r_op1;
reg[3:0] l_r_op2;
reg[1:0] l_r_sel;

//Outputs
wire[3:0] l_w_out;

//Expected outputs
wire[3:0] l_w_sout;

//local variables for loop
integer i, j, k;

//Module initialization
alu uut (
.o_w_out(l_w_out),
.i_w_op1(l_r_op1),
.i_w_op2(l_r_op2),
.i_w_sel(l_r_sel)
);

//Expected module initialization
sol l_m_sol (
.o_w_out(l_w_sout),
.i_w_op1(l_r_op1),
.i_w_op2(l_r_op2),
.i_w_sel(l_r_sel)
);

//Simulation tests
initial begin
for(i=0;i<4;i=i+1) begin
l_r_sel = i;
for(j=0;j<16;j=j+1) begin
l_r_op1 = j;
for(k=0;k<16;k=k+1) begin
l_r_op2 = k;
#5;
if (l_w_out !== l_w_sout) begin
$display("Error: (hex_values) l_w_out = %0h correct %0h, op1 = %0h, op2 = %0h, sel = %0h", l_w_out, l_w_sout, l_r_op1, l_r_op2, l_r_sel);
end else begin
$display("OK");
end
#5;
end
end
end

//finish the simulation
$finish;
end
endmodule
21 changes: 21 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/grade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo 'Too many/few arguments, expecting one' >&2
exit 1
fi

EVALUATE_FILE=$1
#--- remove multiple spaces ---
cat $EVALUATE_FILE | sed 's/ */ /g' > dummy.out
mv dummy.out $EVALUATE_FILE

#--- remove blank lines ---
cat $EVALUATE_FILE | sed '/^\s*$/d' > dummy.out
mv dummy.out $EVALUATE_FILE

# Calculate number of correct test versus wrong test
correct_test_no=$(awk '$1=="OK" { print $0 }' $EVALUATE_FILE | wc -l | awk '{ print $1 }')
test_no=$(wc -l $EVALUATE_FILE| awk '{ print $1 }')
grade=$( expr $correct_test_no \* 100 / $test_no)

echo $grade
58 changes: 58 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/sol.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
module sol(
output wire [3:0] o_w_out,
input wire [3:0] i_w_op1,
input wire [3:0] i_w_op2,
input wire [1:0 ] i_w_sel
);

reg [3:0] l_r_sop0;
reg [3:0] l_r_sop1;
reg [3:0] l_r_sop2;
reg [3:0] l_r_sop3;

wire [3:0] l_w_res0_out;
wire [3:0] l_w_res1_out;
wire [3:0] l_w_res2_out;
wire [3:0] l_w_res3_out;

initial begin
l_r_sop0 <= 4'd`OP0;
l_r_sop1 <= 4'd`OP1;
l_r_sop2 <= 4'd`OP2;
l_r_sop3 <= 4'd`OP3;
end

bigalu l_m_res0(
.o_w_out(l_w_res0_out),
.i_w_op1(i_w_op1),
.i_w_op2(i_w_op2),
.i_w_sel(l_r_sop0)
);

bigalu l_m_res1(
.o_w_out(l_w_res1_out),
.i_w_op1(i_w_op1),
.i_w_op2(i_w_op2),
.i_w_sel(l_r_sop1)
);

bigalu l_m_res2(
.o_w_out(l_w_res2_out),
.i_w_op1(i_w_op1),
.i_w_op2(i_w_op2),
.i_w_sel(l_r_sop2)
);

bigalu l_m_res3(
.o_w_out(l_w_res3_out),
.i_w_op1(i_w_op1),
.i_w_op2(i_w_op2),
.i_w_sel(l_r_sop3)
);

assign o_w_out = (i_w_sel == 2'b00) ? l_w_res0_out :
(i_w_sel == 2'b01) ? l_w_res1_out :
(i_w_sel == 2'b10) ? l_w_res2_out :
l_w_res3_out;

endmodule
45 changes: 45 additions & 0 deletions chapters/verilog/behavioral/assigments/alu/test_alu.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
`timescale 1ns / 1ps
module test_alu;
//Inputs
reg[3:0] l_r_op1;
reg[3:0] l_r_op2;
reg[1:0] l_r_sel;

//Outputs
wire[3:0] l_w_out;

//local variables for loop

//Module initialization
alu uut (
.o_w_out(l_w_out),
.i_w_op1(l_r_op1),
.i_w_op2(l_r_op2),
.i_w_sel(l_r_sel)
);

//Simulation tests
initial begin
// monitor varibles changes in values
$monitor(
"Time = %0t, ", $time,
"l_w_out = %0h, ", l_w_out,
"l_r_op1 = %0h, ", l_r_op1,
"l_r_op2 = %0h, ", l_r_op2,
"l_r_sel = %0h, ", l_r_sel
);

l_r_op1 = 4'b0010;
l_r_op2 = 4'b0100;
l_r_sel = 2'b00;
#10;
l_r_sel = 2'b01;
#10;
l_r_sel = 2'b10;
#10;
l_r_sel = 2'b11;
#10;
//finish the simulation
$finish;
end
endmodule
Loading

0 comments on commit f454e8b

Please sign in to comment.