Skip to content

Commit 5126464

Browse files
author
Your Name
committed
Adding a basic verification env and few corrections.
1 parent 895920a commit 5126464

15 files changed

+552
-3
lines changed

LICENSE

100644100755
File mode changed.

README.md

100644100755
File mode changed.

doc/general_Diagram_i2c_master_slave.pdf

100644100755
File mode changed.

doc/general_i2c_write_read_operation.pdf

100644100755
File mode changed.

pli/i2c_bfm_handler_type_test.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
static int i2c_bfm_handler_type_test_calltf(char*user_data)
2+
{
3+
4+
vpiHandle PRESETn = vpi_handle_by_name("I2C_GLADIC_tb.PRESETn", NULL);
5+
vpiHandle i = vpi_handle_by_name("I2C_GLADIC_tb.i", NULL);
6+
7+
v_generate.format=vpiIntVal;
8+
vpi_get_value(PRESETn, &v_generate);
9+
10+
if(RESET_GENERATED >= MAX_RESET_TIMES)
11+
{
12+
type_bfm = SIMPLE_READ_AFTER_RESET;
13+
14+
if(PACKETS_GENERATED == MAX_ITERATIONS)
15+
{
16+
v_generate.value.integer = 1;
17+
vpi_put_value(i, &v_generate, NULL, vpiNoDelay);
18+
}
19+
}
20+
else
21+
{
22+
type_bfm = -1;
23+
}
24+
25+
return 0;
26+
}

pli/i2c_bfm_reset.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
static int i2c_reset_calltf(char*user_data)
2+
{
3+
4+
vpiHandle PRESETn = vpi_handle_by_name("I2C_GLADIC_tb.PRESETn", NULL);
5+
6+
std::mt19937 rd_counter{std::random_device{}()};
7+
std::uniform_int_distribution<int> counter(1,50);
8+
9+
std::mt19937 rd{std::random_device{}()};
10+
std::uniform_real_distribution<> time(0,50);
11+
12+
13+
v_reset.format=vpiIntVal;
14+
15+
//printf("STATE_RESET : %i\n",STATE_RESET);
16+
//printf("MAX_RESET_TIMES : %i\n",MAX_RESET_TIMES);
17+
//printf("RESET_GENERATED : %i\n",RESET_GENERATED);
18+
19+
switch(STATE_RESET)
20+
{
21+
22+
case IDLE_RESET:
23+
24+
if(RESET_GENERATED > MAX_RESET_TIMES)
25+
{
26+
STATE_RESET = IDLE_RESET;
27+
}else
28+
{
29+
30+
STATE_RESET = ENTER_RESET;
31+
32+
v_reset.value.integer = 0;
33+
t_reset.type = vpiScaledRealTime;
34+
t_reset.real = time(rd);
35+
v_wr.format=vpiIntVal;
36+
v_reset.value.integer = 0;
37+
vpi_put_value(PRESETn, &v_reset, &t_reset, vpiTransportDelay);
38+
counter_reset_wait = counter(rd_counter);
39+
40+
}
41+
42+
counter_reset_enter=0;
43+
counter_reset_wait=0;
44+
45+
46+
break;
47+
48+
case ENTER_RESET:
49+
50+
if(counter_reset_enter >= counter_reset_wait)
51+
{
52+
v_reset.value.integer = 0;
53+
t_reset.type = vpiScaledRealTime;
54+
t_reset.real = time(rd);
55+
v_wr.format=vpiIntVal;
56+
v_reset.value.integer = 1;
57+
vpi_put_value(PRESETn,&v_reset, &t_reset, vpiTransportDelay);
58+
STATE_RESET = GET_OUT_RESET;
59+
}
60+
61+
counter_reset_enter++;
62+
63+
break;
64+
65+
case GET_OUT_RESET:
66+
67+
counter_reset_wait=0;
68+
counter_reset_enter=0;
69+
70+
STATE_RESET = WAIT_RESET;
71+
72+
counter_reset_wait = counter(rd_counter);
73+
74+
break;
75+
76+
case WAIT_RESET:
77+
78+
if(counter_reset_enter >= counter_reset_wait)
79+
{
80+
STATE_RESET = IDLE_RESET;
81+
counter_reset_wait=0;
82+
counter_reset_enter=0;
83+
RESET_GENERATED++;
84+
}
85+
counter_reset_enter++;
86+
87+
break;
88+
89+
}
90+
91+
92+
return 0;
93+
}
94+

pli/i2c_env.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
Design name : Felipe Fernandes da Costa
3+
Description:
4+
5+
A verification environment used to be a basic one.
6+
7+
Brazil -- 21/03/2023 --
8+
*/
9+
10+
#include "/usr/local/include/iverilog/vpi_user.h"
11+
//#include <vpi_user.h>
12+
#include <iostream>
13+
#include <random>
14+
#include<string.h>
15+
16+
s_vpi_value v_generate;
17+
18+
s_vpi_value v_initial;
19+
s_vpi_time t_initial;
20+
21+
s_vpi_value v_reset;
22+
s_vpi_time t_reset;
23+
24+
s_vpi_value v_wr;
25+
s_vpi_time t_wr;
26+
27+
/*GENERAL USE */
28+
29+
int STATE_PENABLE;
30+
int READ_REGISTER;
31+
32+
/*THIS SPECIFY the BFMS we need to make sure we choose right tests*/
33+
int type_bfm;
34+
35+
// GLOBAL PACKETS
36+
int PACKETS_GENERATED;
37+
38+
//This is to be used on BFM
39+
int STATE;
40+
41+
// RESET BFM ONLY
42+
int reset_counter;
43+
int counter_reset_enter;
44+
int counter_reset_wait;
45+
46+
int STATE_RESET;
47+
int RESET_GENERATED;
48+
49+
50+
#define ADDR_I2C_WRITE_TX_FIFO 0
51+
#define ADDR_I2C_READ_RX_FIFO 4
52+
53+
#define ADDR_I2C_CONFIG 8
54+
#define ADDR_I2C_TIMEOUT 12
55+
#define ADDR_I2C_READ_ACTUAL_DATA 16
56+
57+
58+
/*DEFINE A BFM RESET PROPER DEFINE*/
59+
#define IDLE_RESET 0
60+
#define ENTER_RESET 1
61+
#define WAIT_RESET 2
62+
#define GET_OUT_RESET 3
63+
64+
65+
#define IDLE 0
66+
#define WRITE 1
67+
#define READ 2
68+
#define WAIT 3
69+
#define READ_RESULTS 4
70+
71+
/*BFM ACT TO PERFORM SIMPLE TASKS*/
72+
#define SIMPLE_READ_AFTER_RESET 0
73+
#define SIMPLE_WRITE_AFTER_RESET 1
74+
#define SIMPLE_WRITE_READ_AFTER_RESET 2
75+
76+
/*MAX RESET GENERATION */
77+
#define MAX_RESET_TIMES 4
78+
79+
/*MAX PACKETS GENERATION*/
80+
#define MAX_ITERATIONS 8
81+
82+
//INITIAL ENV CONFIGURE
83+
#include "i2c_init.h"
84+
#include "i2c_bfm_handler_type_test.h"
85+
#include "i2c_bfm_reset.h"
86+
#include "i2c_init_reset.h"
87+
88+
89+
#include "read/i2c_test_read_registers_bfm_r.h"
90+
91+
92+
void I2C_GLADIC_register()
93+
{
94+
s_vpi_systf_data tf_data;
95+
96+
//i2c_test_read_registers_bfm_r
97+
tf_data.type = vpiSysTask;
98+
tf_data.sysfunctype = 0;
99+
tf_data.tfname = "$i2c_test_read_registers";
100+
tf_data.calltf = i2c_test_read_registers_bfm_r_calltf;
101+
tf_data.compiletf = 0;
102+
tf_data.sizetf = 0;
103+
tf_data.user_data = 0;
104+
vpi_register_systf(&tf_data);
105+
106+
//MAIN DEFINE BFM TYPE
107+
tf_data.type = vpiSysTask;
108+
tf_data.sysfunctype = 0;
109+
tf_data.tfname = "$bfm_generate_type";
110+
tf_data.calltf = i2c_bfm_handler_type_test_calltf;
111+
tf_data.compiletf = 0;
112+
tf_data.sizetf = 0;
113+
tf_data.user_data = 0;
114+
vpi_register_systf(&tf_data);
115+
116+
// RESET BFM
117+
tf_data.type = vpiSysTask;
118+
tf_data.sysfunctype = 0;
119+
tf_data.tfname = "$reset_i2c_master";
120+
tf_data.calltf = i2c_reset_calltf;
121+
tf_data.compiletf = 0;
122+
tf_data.sizetf = 0;
123+
tf_data.user_data = 0;
124+
vpi_register_systf(&tf_data);
125+
126+
127+
//ENV CONFIGURATION
128+
tf_data.type = vpiSysTask;
129+
tf_data.sysfunctype = 0;
130+
tf_data.tfname = "$init";
131+
tf_data.calltf = init_calltf;
132+
tf_data.compiletf = 0;
133+
tf_data.sizetf = 0;
134+
tf_data.user_data = 0;
135+
vpi_register_systf(&tf_data);
136+
137+
tf_data.type = vpiSysTask;
138+
tf_data.sysfunctype = 0;
139+
tf_data.tfname = "$init_reset";
140+
tf_data.calltf = init_reset_calltf;
141+
tf_data.compiletf = 0;
142+
tf_data.sizetf = 0;
143+
tf_data.user_data = 0;
144+
vpi_register_systf(&tf_data);
145+
146+
}
147+
148+
149+
void (*vlog_startup_routines[])() = {
150+
I2C_GLADIC_register,
151+
0
152+
};

pli/i2c_init.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
static int init_calltf(char*user_data)
2+
{
3+
vpiHandle PRESETn = vpi_handle_by_name("I2C_GLADIC_tb.PRESETn", NULL);
4+
vpiHandle PWDATA = vpi_handle_by_name("I2C_GLADIC_tb.PWDATA", NULL);
5+
vpiHandle PENABLE = vpi_handle_by_name("I2C_GLADIC_tb.PENABLE", NULL);
6+
vpiHandle PSELx = vpi_handle_by_name("I2C_GLADIC_tb.PSELx", NULL);
7+
vpiHandle PWRITE = vpi_handle_by_name("I2C_GLADIC_tb.PWRITE", NULL);
8+
vpiHandle PADDR = vpi_handle_by_name("I2C_GLADIC_tb.PADDR", NULL);
9+
vpiHandle PRDATA = vpi_handle_by_name("I2C_GLADIC_tb.PRDATA", NULL);
10+
vpiHandle PREADY = vpi_handle_by_name("I2C_GLADIC_tb.PREADY", NULL);
11+
vpiHandle PSLVERR = vpi_handle_by_name("I2C_GLADIC_tb.PSLVERR", NULL);
12+
vpiHandle i = vpi_handle_by_name("I2C_GLADIC_tb.i", NULL);
13+
14+
15+
if(RESET_GENERATED >= MAX_RESET_TIMES)
16+
{}
17+
else
18+
{
19+
20+
/**/
21+
PACKETS_GENERATED = 0;
22+
reset_counter = 0;
23+
STATE_RESET = IDLE_RESET;
24+
25+
v_initial.format=vpiIntVal;
26+
27+
v_initial.value.integer = 0;
28+
vpi_put_value(PENABLE, &v_initial, NULL, vpiNoDelay);
29+
vpi_put_value(PSELx , &v_initial, NULL, vpiNoDelay);
30+
vpi_put_value(PADDR, &v_initial, NULL, vpiNoDelay);
31+
vpi_put_value(i, &v_initial, NULL, vpiNoDelay);
32+
vpi_put_value(PWRITE, &v_initial, NULL, vpiNoDelay);
33+
vpi_put_value(PWDATA, &v_initial, NULL, vpiNoDelay);
34+
}
35+
36+
return 0;
37+
}

pli/i2c_init_reset.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
static int init_reset_calltf(char*user_data)
2+
{
3+
STATE_RESET = IDLE_RESET;
4+
RESET_GENERATED= 0;
5+
6+
reset_counter = 0;
7+
counter_reset_enter = 0;
8+
counter_reset_wait = 0;
9+
10+
return 0;
11+
}

0 commit comments

Comments
 (0)