Hi,
Please find the code that I am using to read the data from DUT and send the i2c data & addr to predictor through uvm analysis port.
virtual protected task i2c_data_transmition(REQ trans);
if(m_i2c_trans_type == READ) begin
m_i2c_data = new [m_trans_data_len];
//Receive Data Buffer
for(int i2c_trans_data_idx=0; i2c_trans_data_idx < m_trans_data_len;
i2c_trans_data_idx++)
begin : RCV_READ_BYTE
i2c_byte_read((i2c_trans_data_idx+1 == m_trans_data_len),
m_i2c_data[i2c_trans_data_idx]);
end
end
endtask
virtual protected task i2c_byte_read(bit ack, output bit[7:0] dataOut);
for(int i2c_data_idx=7; i2c_data_idx >=0; i2c_data_idx--)
begin : RCV_READ_BIT
@(negedge m_i2c_if.filtered_scl)
m_i2c_if.io_sda_l <= 1'bz;
@(posedge m_i2c_if.filtered_scl)
dataOut = {dataOut[6:0], m_i2c_if.io_sda};
end
//for debug purpose
m_i2c_if.read_bytes_debug <= dataOut;
uvm_info(this.get_name(),"=============================================", UVM_LOW); uvm_info(this.get_name(), $psprintf(“Data Read from Slave :0x%0h”, dataOut), UVM_LOW);
`uvm_info(this.get_name(),“=============================================”, UVM_LOW);
//Send Acknowledgement to Slave once Read Data is received.
@(negedge m_i2c_if.filtered_scl)
m_i2c_if.io_sda_l <= ack;
endtask
virtual protected task gen_stop_condition(REQ rsp);
if(cfg.send_tr_at_stop == 1’b1 && send_tr_at_stop == 1) begin
//Copying Read Data into Transaction, to send it to Scoreboard
if (rsp.m_i2c_trans_type == READ || rsp.m_i2c_trans_type == RD_WITH_RE_START) begin
for (int idx = 0; idx < (m_i2c_data.size()); idx++) begin
//rsp.m_i2c_data[idx] = {m_i2c_data[idx],m_i2c_data[idx+1]};
{rsp.m_i2c_data[idx],rsp.m_i2c_data[idx+1]} = {m_i2c_data[idx],m_i2c_data[idx+1]};
end
end
//Adding information about number of ACKs and NACKs in the transaction.
rsp.m_no_of_acks = m_no_of_acks;
rsp.m_no_of_nacks = m_no_of_nacks;
//Record transaction Start and End times
rsp.m_trans_start_time = m_trans_start_time;
rsp.m_trans_end_time = m_trans_end_time;
`uvm_info(this.get_name(),$psprintf("Transaction before Sent_gen \n%s",rsp.sprint()), UVM_LOW) -- 1St Display Statement
//Send transaction out on analysis port.
send_transaction_to_analysis_export(rsp);
`uvm_info(this.get_name(),$psprintf("Transaction Sent_gen \n%s",rsp.sprint()), UVM_LOW) --2nd display statement
end
endtask