OpenCores
URL https://opencores.org/ocsvn/qaz_libs/qaz_libs/trunk

Subversion Repositories qaz_libs

[/] [qaz_libs/] [trunk/] [BFM/] [src/] [SPI/] [spi_sequence_item.svh] - Rev 50

Compare with Previous | Blame | View Log

//////////////////////////////////////////////////////////////////////
////                                                              ////
//// Copyright (C) 2018 Authors and OPENCORES.ORG                 ////
////                                                              ////
//// This source file may be used and distributed without         ////
//// restriction provided that this copyright statement is not    ////
//// removed from the file and that any derivative work contains  ////
//// the original copyright notice and the associated disclaimer. ////
////                                                              ////
//// This source file is free software; you can redistribute it   ////
//// and/or modify it under the terms of the GNU Lesser General   ////
//// Public License as published by the Free Software Foundation; ////
//// either version 2.1 of the License, or (at your option) any   ////
//// later version.                                               ////
////                                                              ////
//// This source is distributed in the hope that it will be       ////
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
//// PURPOSE.  See the GNU Lesser General Public License for more ////
//// details.                                                     ////
////                                                              ////
//// You should have received a copy of the GNU Lesser General    ////
//// Public License along with this source; if not, download it   ////
//// from http://www.opencores.org/lgpl.shtml                     ////
////                                                              ////
//////////////////////////////////////////////////////////////////////

class spi_sequence_item
  extends uvm_sequence_item;
  `uvm_object_utils(spi_sequence_item)

  // --------------------------------------------------------------------
  rand int data_width; // data size in bits

  // --------------------------------------------------------------------
  logic miso_data[]; // data from slave to master
  logic mosi_data[]; // data from master to slave
  int ss_index = 0;
  bit read;
  bit write;

  // --------------------------------------------------------------------
  function new(string name = "");
    super.new(name);
  endfunction : new

  // --------------------------------------------------------------------
  function void init(bit read, bit write, int data_width);
    this.read = read;
    this.write = write;
    this.data_width = data_width;
    this.miso_data = new[data_width];
    this.mosi_data = new[data_width];

    if(write)
      foreach(this.mosi_data[i])
        mosi_data[i] = 0;
  endfunction : init

  // --------------------------------------------------------------------
  function void load_mosi_from_file(string file_name);
    byte buffer;
    integer fd;
    integer code;
    integer size;

    fd = $fopen(file_name, "rb");
    code = $fseek(fd, 0, 2); // SEEK_END
    size = $ftell(fd);
    code = $rewind(fd);
    data_width = size*8;
    mosi_data = new[data_width];
    write = 1;

    for(int i = 0; i < size; i++) begin
      code = $fread(buffer, fd);
      mosi_data[i*8 +: 8] = {>>{buffer}};
    end

    $fclose(fd);
  endfunction

  // --------------------------------------------------------------------
  function void load_mosi_from_byte_array(byte byte_array[]);
    foreach(byte_array[i])
      mosi_data[i*8 +: 8] = {>>{byte_array[i]}};
  endfunction

  // --------------------------------------------------------------------
  function string convert2string();
    string s0, s1, s2, s3;
    byte data[];

    s0 = $sformatf( "\n| %m | rd | wr | data width |\n");
    s1 = $sformatf( "| %m | %1h  | %1h  | %d |\n"
                  , read
                  , write
                  , data_width
                  );
    s0 = {s0, s1};

    if(read) begin
      data = {>>{miso_data}};

      foreach(data[i])
        s2 = {s2, $sformatf("%2h|", data[i])};

      s2 = $sformatf("| %m | miso_data: |%s\n" , s2);
      s0 = {s0, s2};
    end

    if(write) begin
      data = {>>{mosi_data}};

      foreach(data[i])
        s3 = {s3, $sformatf("%2h|", data[i])};

      s3 = $sformatf("| %m | mosi_data: |%s\n" , s3);
      s0 = {s0, s3};
    end

    return s0;
  endfunction : convert2string

// --------------------------------------------------------------------
endclass

Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.