Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Explanation of systemveilog code snippet for SPI

Status
Not open for further replies.

verif.ier

Newbie level 4
Joined
Jun 13, 2016
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
41
The following is a working code snippet for read/write operation using spi protocol to a slave with addr address. Could anyone explain what is the function of the part marked in bold?

Code:
task TmspiCmd(bit [13:0] addr, bit rwb=0,inout bit [15:0] data,input bit reg_size=0, input int check =0,input bit[15:0] expData = 0, int tlead =0 );

//..

if(rwb)
      begin
      [B]spiw.data[0] = {2'b00,addr};
      spiw.data[1] = 16'b0;[/B]
      end
    else
      begin
      [B]spiw.data[0] = {2'b10,addr}; 
      spiw.data[1] = data;[/B]
      end

//...

if(rwb)
    begin
      TempData = 0;
      TempData = spiw.resp_data;
      for(int index=0; index <16; index++)
          TempData[index]  =  spiw.resp_data[15-index];
      if (reg_size)
      begin
[B]          if (addr %2)
             data = TempData[15:8];
          else 
             data = TempData[7:0];[/B]
      end
      else 
         [B] data = TempData;[/B]

      `uvm_info("TMSPI:Response=> ",$sformatf("Addr %h  [%h = %h ] [%h]", addr,data,TempData,spiw.resp_data), UVM_LOW);

// ..
 

Modulo 2 of the address separates the even and odd addresses, so the bytes can be accessed individually. It would have been easier to understand if they had just done if (addr[0]) instead.
 

Thanks for your reply. Yes, I understood odd/even address part but what does it have to do with spi communication?

Also, the following part is confusing to me. How can a 16-bit value be assigned to 1 bit location? Or I am misinterpreting!!!
Again why is it required for spi communication?
Code:
spiw.data[0] = {2'b00,addr};
spiw.data[1] = 16'b0;
 

spiw is declared as follows.

Code:
class myBaseTest extends uvm_test;
   SpiCRM spiw

virtual function void build_phase(uvm_phase phase);
   spiw = SpiCRM::type_id::create("slv_wr",this);

I could find defintion of SpiCRM anywhere. May be it is from uvm_test
 

You probably need to post the majority of the code as this has a lot of stuff buried in classes, funcitons, etc that will be needed to interpret what the code does.

My thought on your original question about
Code:
spiw.data[0] = {2'b00,addr};
spiw.data[1] = 16'b0;
is that the 0 and 1 are not bits but are array indices.
 

I could find defintion of SpiCRM anywhere. May be it is from uvm_test
I think learning how to read code should be your first educational objective. Without knowing the definition of SpiCRM, the discussion is mostly pointless.

It's easy to guess that data is an array of bit vectors, but you should really review the original definition yourself.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top