Skip to content

Commit d8ef5b4

Browse files
committed
Add counter test
1 parent c57c4c4 commit d8ef5b4

File tree

7 files changed

+95
-1
lines changed

7 files changed

+95
-1
lines changed

verilog/dv/cocotb/cocotb_tests.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
from frigate_test.gpio_portA.gpio_portA import gpio_portA
1+
from frigate_test.gpio_portA.gpio_portA import gpio_portA
2+
from user_proj_tests.counter.counter import counter

verilog/dv/cocotb/user_counter.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef USER_COUNTER_H
2+
#define USER_COUNTER_H
3+
4+
typedef struct _EF_USER_COUNTER_TYPE_ {
5+
__RW COUNT;
6+
__RW CTRL;
7+
} EF_USER_COUNTER_TYPE;
8+
9+
typedef struct _EF_USER_COUNTER_TYPE_ *EF_USER_COUNTER_TYPE_PTR; // Pointer to the register structure
10+
#define USER_COUNTER ((EF_USER_COUNTER_TYPE_PTR)0x60000000)
11+
12+
13+
void EF_USER_COUNTER_enable(EF_USER_COUNTER_TYPE_PTR counter) {
14+
counter->CTRL = 1;
15+
};
16+
17+
void EF_USER_COUNTER_disable(EF_USER_COUNTER_TYPE_PTR counter) {
18+
counter->CTRL = 0;
19+
};
20+
21+
int read_count(EF_USER_COUNTER_TYPE_PTR counter) {
22+
return counter->COUNT;
23+
};
24+
25+
#endif // USER_COUNTER_H
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <frigate_regs.h>
2+
#include <EF_GPIO8.h>
3+
#include <EF_GPIO8.c>
4+
#include <clk_rst.h>
5+
#include "user_counter.h"
6+
#include <system_regs.h>
7+
8+
/*
9+
test sequence eable the counter
10+
read the counter value and write it at GPIOB (port3)
11+
*/
12+
void main(){
13+
CLK_RST_GCLK_EN(0b111); // enable pclk
14+
CLK_RST_USER_CLK_CTRL(1); // enable user clock
15+
SYSREG_setUserAHBEn(1); // enable user interface
16+
EF_GPIO8_setGclkEnable(PORT_H, 1); // required in design with clock gating.
17+
EF_GPIO8_setPinDirection(PORT_H, 7, GPIO8_OUTPUT); // use GPIOH 0 as indicator
18+
EF_GPIO8_writeAllDirection(PORT_B,0xFF); // configure port as output
19+
// enable counter
20+
EF_USER_COUNTER_enable(USER_COUNTER);
21+
while (1) {
22+
EF_GPIO8_writeData(PORT_H ,0);
23+
int count_val = read_count(USER_COUNTER);
24+
EF_GPIO8_writeData(PORT_B ,count_val);
25+
EF_GPIO8_writeData(PORT_H ,0xFF); // read data
26+
}
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from caravel_cocotb.caravel_interfaces import report_test
2+
import cocotb
3+
from common import test_configure_ml
4+
import random
5+
from frigate_test.gpio import GPIOsPortB, GPIOsPortA, GPIOsPortH
6+
7+
@cocotb.test()
8+
@report_test
9+
async def counter(dut):
10+
caravelEnv = await test_configure_ml(dut, timeout_cycles=78129)
11+
cocotb.log.info("[TEST] Start counter test")
12+
counter_gpio = GPIOsPortA(caravelEnv) # RTL connects user counter value to GPIOA
13+
gpio_port_b = GPIOsPortB(caravelEnv) # for monitoring value read from software
14+
gpio_port_h = GPIOsPortH(caravelEnv) # new value indicator
15+
shift = 0
16+
old_counter_val = 0
17+
old_software_val = 0
18+
for i in range(10):
19+
await gpio_port_h.wait_gpio_pin(7, 1)
20+
counter_val = counter_gpio.monitor_gpio(7, 0).integer
21+
software_val = gpio_port_b.monitor_gpio(7, 0).integer
22+
cocotb.log.info(f"[TEST] counter_val: {counter_val}, software_val: {software_val} shift {counter_val - software_val}")
23+
if i == 0:
24+
shift = counter_val - software_val
25+
old_counter_val = counter_val
26+
old_software_val = software_val
27+
else:
28+
if counter_val - software_val != shift:
29+
cocotb.log.error(f"[TEST] shift error shift = {counter_val - software_val} expected shift = {shift}")
30+
if counter_val <= old_counter_val:
31+
cocotb.log.error(f"[TEST] counting direction error counter_val: {counter_val} <= old_counter_val: {old_counter_val}")
32+
if software_val <= old_software_val:
33+
cocotb.log.error(f"[TEST] counting direction error software_val: {software_val} <= old_software_val: {old_software_val}")
34+
await gpio_port_h.wait_gpio_pin(7, 0)
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Tests:
22
- {name: gpio_portA, sim: RTL}
3+
- {name: counter, sim: RTL}

verilog/dv/cocotb/user_run_test.py

+4
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ def _iverilog_docker_command_str(self, command=""):
186186

187187
def iverilog_compile(self):
188188
macros = " -D" + " -D".join(self.test.macros)
189+
if os.path.isfile(f"{self.test.compilation_dir}/sim.vvp"):
190+
os.remove(f"{self.test.compilation_dir}/sim.vvp")
189191
compile_command = (
190192
f"cd {self.test.compilation_dir} &&"
191193
f"iverilog -g2012 -Ttyp {macros} {self.iverilog_dirs} -o {self.test.compilation_dir}/sim.vvp -s caravel_top"
@@ -201,6 +203,8 @@ def iverilog_compile(self):
201203

202204

203205
def vcs_compile(self):
206+
if os.path.isfile(f"{self.test.compilation_dir}/simv"):
207+
os.remove(f"{self.test.compilation_dir}/simv")
204208
macros = " +define+" + " +define+".join(self.test.macros)
205209
vlogan_cmd = f"cd {self.test.compilation_dir}; vlogan -full64 -negdelay -sverilog +error+30 {self.paths.FRIGATE_ROOT}/verilog/vip/toplevel_cocotb.v {self.vcs_dirs} {macros} -l {self.test.compilation_dir}/analysis.log -o {self.test.compilation_dir} "
206210
self.run_command_write_to_file(vlogan_cmd, self.test.compilation_log, self.logger, quiet=False if self.args.verbosity == "debug" else True)

verilog/includes/includes.rtl.frigate_user_project

+2
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@
1616

1717
# defines
1818
-v $(USER_PROJECT_VERILOG)/rtl/user_defines.v
19+
-v $(USER_PROJECT_VERILOG)/rtl/user_project_wrapper.v
20+
-v $(USER_PROJECT_VERILOG)/rtl/ahb_counter.v

0 commit comments

Comments
 (0)