1 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
2 |
2 |
HanySalah |
//
|
3 |
3 |
HanySalah |
//
|
4 |
2 |
HanySalah |
// UART2BUS VERIFICATION
|
5 |
|
|
//
|
6 |
3 |
HanySalah |
//
|
7 |
|
|
//-------------------------------------------------------------------------------------------------
|
8 |
2 |
HanySalah |
// CREATOR : HANY SALAH
|
9 |
|
|
// PROJECT : UART2BUS UVM TEST BENCH
|
10 |
|
|
// UNIT : INTERFACE
|
11 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
12 |
|
|
// TITLE : REGISTER FILE BFM
|
13 |
|
|
// DESCRIPTION: THIS BUS FUNCTIONAL MODEL (BFM) ACTS AS ACTUAL REGISTER FILE CONNECTED TO THE DUT
|
14 |
|
|
// ACROSS THE NON-STANDARD INTERFACE. IT IS IMPLEMENTED IN THE MANNER THAT APPLY THE
|
15 |
|
|
// COMMUNICATION PROTOCOL DESCRIPED IN THE DUT MICROARCHITECTURE SPECIFICATIONS
|
16 |
|
|
//-------------------------------------------------------------------------------------------------
|
17 |
2 |
HanySalah |
// LOG DETAILS
|
18 |
|
|
//-------------
|
19 |
|
|
// VERSION NAME DATE DESCRIPTION
|
20 |
|
|
// 1 HANY SALAH 25122015 FILE CREATION
|
21 |
3 |
HanySalah |
// 2 HANY SALAH 20012016 ADD READ BLOCK ROUTINE
|
22 |
|
|
// 3 HANY SALAH 11022016 IMPROVE BLOCK DESCRIPTION & ADD BLOCK COMMENTS
|
23 |
|
|
//-------------------------------------------------------------------------------------------------
|
24 |
|
|
// ALL COPYRIGHTS ARE RESERVED FOR THE PRODUCER ONLY .THIS FILE IS PRODUCED FOR OPENCORES MEMBERS
|
25 |
|
|
// ONLY AND IT IS PROHIBTED TO USE THIS MATERIAL WITHOUT THE CREATOR'S PERMISSION
|
26 |
|
|
//-------------------------------------------------------------------------------------------------
|
27 |
2 |
HanySalah |
`include "defin_lib.svh"
|
28 |
|
|
interface rf_interface (input bit clock, // Global Clock Signal
|
29 |
|
|
input bit reset); // Global Asynchronous Reset Signal
|
30 |
|
|
|
31 |
|
|
|
32 |
|
|
|
33 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
34 |
2 |
HanySalah |
//
|
35 |
3 |
HanySalah |
// Register File Side Signals
|
36 |
2 |
HanySalah |
//
|
37 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
38 |
2 |
HanySalah |
|
39 |
3 |
HanySalah |
logic [15:0] int_address; // Address Bus To Register File
|
40 |
2 |
HanySalah |
|
41 |
|
|
logic [7:0] int_wr_data; // Write Data To Register File
|
42 |
|
|
logic int_write; // Write Contorl To Register File
|
43 |
|
|
|
44 |
|
|
logic [7:0] int_rd_data; // Read Data From Register File
|
45 |
|
|
logic int_read; // Read Control To Register File
|
46 |
|
|
|
47 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
48 |
2 |
HanySalah |
//
|
49 |
3 |
HanySalah |
// CONTROL SIGNALS
|
50 |
2 |
HanySalah |
//
|
51 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
52 |
2 |
HanySalah |
|
53 |
3 |
HanySalah |
// This output is set when the testbench gives the bus access to the UART DUT
|
54 |
2 |
HanySalah |
logic int_gnt;
|
55 |
3 |
HanySalah |
|
56 |
|
|
// This input is activated whenever the UART DUT request to grant the bus access
|
57 |
2 |
HanySalah |
logic int_req;
|
58 |
3 |
HanySalah |
|
59 |
|
|
//-------------------------------------------------------------------------------------------------
|
60 |
2 |
HanySalah |
//
|
61 |
3 |
HanySalah |
// Internal Variables
|
62 |
2 |
HanySalah |
//
|
63 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
64 |
2 |
HanySalah |
|
65 |
|
|
// Memory of 64K bytes as Register File
|
66 |
|
|
byte register_file [`mem_size-1:0];
|
67 |
|
|
|
68 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
69 |
2 |
HanySalah |
//
|
70 |
3 |
HanySalah |
// Operation Blocks
|
71 |
2 |
HanySalah |
//
|
72 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
73 |
|
|
|
74 |
|
|
// This is the main operation always block that responds to the asynchronous reset. Every clock
|
75 |
|
|
// positive edge, it check for both int_read & int_write inputs. if the int_write is activated,
|
76 |
|
|
// it store the data forced on the int_wr_data into the memory location defined by the address
|
77 |
|
|
// applied on the int_address port. if the int_read is activated, it load the data stored in the
|
78 |
|
|
// memory location defined by the address applied on the int_address port.
|
79 |
|
|
// It's forbidden to assert both the int_write & int_read signal in the same time.
|
80 |
2 |
HanySalah |
always
|
81 |
|
|
begin
|
82 |
|
|
@(posedge clock or posedge reset);
|
83 |
|
|
begin
|
84 |
|
|
if (reset)
|
85 |
|
|
begin
|
86 |
|
|
reset_mem();
|
87 |
|
|
end
|
88 |
|
|
else if (int_write)
|
89 |
|
|
begin
|
90 |
|
|
fill_byte(int_address,int_wr_data);
|
91 |
|
|
end
|
92 |
|
|
else if (int_read)
|
93 |
|
|
begin
|
94 |
|
|
int_rd_data = read_mem_data(int_address);
|
95 |
|
|
end
|
96 |
|
|
end
|
97 |
|
|
end
|
98 |
|
|
|
99 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
100 |
2 |
HanySalah |
//
|
101 |
3 |
HanySalah |
// Non Standard Routines
|
102 |
2 |
HanySalah |
//
|
103 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
104 |
2 |
HanySalah |
|
105 |
3 |
HanySalah |
// fill_byte routine is a function that fill only a single byte in the register file defined by
|
106 |
|
|
// the input address with the single byte identified by data.
|
107 |
|
|
function void fill_byte (bit [`size-1:0] address,
|
108 |
|
|
byte data);
|
109 |
|
|
register_file[address] = data;
|
110 |
|
|
endfunction:fill_byte
|
111 |
2 |
HanySalah |
|
112 |
3 |
HanySalah |
// fill_block routine is a function that fill continuous block of locations in the register file.
|
113 |
|
|
// The starting address identified by the address input and the data is defined by the dynamic
|
114 |
|
|
// array data with length equal to block_length input.
|
115 |
|
|
// In case that the block of memory locations includes the top memory location which meant that
|
116 |
|
|
// the memory pointer(address) will reach its highest possible value and roll to zero. The imp-
|
117 |
|
|
// lemented function has put this point in the concern
|
118 |
|
|
function automatic void fill_block(bit [`size-1:0] address,
|
119 |
|
|
ref byte data [],
|
120 |
|
|
int unsigned block_length);
|
121 |
2 |
HanySalah |
|
122 |
3 |
HanySalah |
for (int unsigned index = 0; index < block_length; index++)
|
123 |
|
|
begin
|
124 |
|
|
// in case that the memory pointer has rolled over. the new address will be calculated from
|
125 |
|
|
// the following relationship
|
126 |
|
|
// The new address = the actual address - the whole memory size.
|
127 |
|
|
if(address+index > `mem_size-1)
|
128 |
|
|
begin
|
129 |
|
|
register_file[address+index-`mem_size] = data [index];
|
130 |
|
|
end
|
131 |
|
|
else
|
132 |
|
|
begin
|
133 |
|
|
register_file[address+index] = data [index];
|
134 |
|
|
end
|
135 |
|
|
end
|
136 |
|
|
endfunction:fill_block
|
137 |
|
|
|
138 |
|
|
// reset_mem routine is a function that fill reset the register file contents to zero
|
139 |
|
|
function void reset_mem();
|
140 |
|
|
for (int unsigned index = 0; index < `mem_size; index++)
|
141 |
2 |
HanySalah |
begin
|
142 |
3 |
HanySalah |
register_file[index] = 8'b0;
|
143 |
2 |
HanySalah |
end
|
144 |
3 |
HanySalah |
endfunction:reset_mem
|
145 |
2 |
HanySalah |
|
146 |
|
|
// read_mem_data routine is a function that load bus with the data content
|
147 |
|
|
function byte read_mem_data(bit [`size-1:0] address);
|
148 |
|
|
return register_file[address];
|
149 |
|
|
endfunction: read_mem_data
|
150 |
|
|
|
151 |
3 |
HanySalah |
// This routine read adjacent block of memory location into dynamic array of data and the
|
152 |
|
|
// starting address defined by the address input.
|
153 |
|
|
// The point of memory pointer rolling over has been put in the consideration
|
154 |
2 |
HanySalah |
task automatic read_block(input int unsigned data_length,
|
155 |
|
|
input bit [15:0] address,
|
156 |
|
|
ref byte data []);
|
157 |
|
|
data = new [data_length];
|
158 |
|
|
for (int unsigned index=0;index
|
159 |
|
|
begin
|
160 |
3 |
HanySalah |
if (address+index > `mem_size-1)
|
161 |
|
|
begin
|
162 |
|
|
data[index] = read_mem_data(address+index-`mem_size);
|
163 |
|
|
end
|
164 |
|
|
else
|
165 |
|
|
begin
|
166 |
|
|
data[index] = read_mem_data(address+index);
|
167 |
|
|
end
|
168 |
2 |
HanySalah |
end
|
169 |
|
|
endtask:read_block
|
170 |
|
|
|
171 |
3 |
HanySalah |
//-------------------------------------------------------------------------------------------------
|
172 |
|
|
//
|
173 |
|
|
// MONITOR ROUTINES
|
174 |
|
|
//
|
175 |
|
|
//-------------------------------------------------------------------------------------------------
|
176 |
|
|
|
177 |
|
|
// This routine capture both the data and the address of the current transaction across the non-
|
178 |
|
|
// standard interface side.
|
179 |
|
|
// When it is called, it is blocked till the raising edge of int_gnt input. And during the high
|
180 |
|
|
// level of int_gnt input. This routine samples both int_read and int_write inputs every positive
|
181 |
|
|
// edge of the clock signal. If int_read is active, it realizes that the current transaction is
|
182 |
|
|
// read and sample the int_rd_data bus at the current clock tick.
|
183 |
|
|
// If the int_write is active, it realizes that the current transaction is write and sample the
|
184 |
|
|
// int_wr_data bus at the current clock tick.
|
185 |
|
|
// Note : - The transaction address is the address of the first affected memory location.
|
186 |
|
|
// - It's obvious that one of the signals int_read or int_write at least should be active
|
187 |
|
|
// when the int_gnt is active. which is implemented through the error alarm below.
|
188 |
|
|
task automatic capture_transaction (output bit [`size-1:0] address,
|
189 |
|
|
ref byte data [],
|
190 |
|
|
output int unsigned data_length);
|
191 |
|
|
int unsigned index;
|
192 |
2 |
HanySalah |
index = 0;
|
193 |
|
|
@(posedge int_gnt);
|
194 |
|
|
while (int_gnt)
|
195 |
|
|
begin
|
196 |
|
|
@(posedge clock);
|
197 |
|
|
if(index == 0)
|
198 |
|
|
begin
|
199 |
|
|
address = int_address;
|
200 |
|
|
end
|
201 |
|
|
if(int_read)
|
202 |
|
|
begin
|
203 |
|
|
data [index] = int_rd_data;
|
204 |
|
|
end
|
205 |
|
|
else if (int_write)
|
206 |
|
|
begin
|
207 |
|
|
data [index] = int_wr_data;
|
208 |
|
|
end
|
209 |
|
|
else
|
210 |
|
|
begin
|
211 |
3 |
HanySalah |
$error("Both int_read and int_write is inactive while int_gnt is active");
|
212 |
2 |
HanySalah |
end
|
213 |
|
|
index++;
|
214 |
3 |
HanySalah |
data_length = index;
|
215 |
2 |
HanySalah |
end
|
216 |
|
|
endtask:capture_transaction
|
217 |
|
|
endinterface:rf_interface
|