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] - Blame information for rev 50

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 47 qaztronic
//////////////////////////////////////////////////////////////////////
2
////                                                              ////
3
//// Copyright (C) 2018 Authors and OPENCORES.ORG                 ////
4
////                                                              ////
5
//// This source file may be used and distributed without         ////
6
//// restriction provided that this copyright statement is not    ////
7
//// removed from the file and that any derivative work contains  ////
8
//// the original copyright notice and the associated disclaimer. ////
9
////                                                              ////
10
//// This source file is free software; you can redistribute it   ////
11
//// and/or modify it under the terms of the GNU Lesser General   ////
12
//// Public License as published by the Free Software Foundation; ////
13
//// either version 2.1 of the License, or (at your option) any   ////
14
//// later version.                                               ////
15
////                                                              ////
16
//// This source is distributed in the hope that it will be       ////
17
//// useful, but WITHOUT ANY WARRANTY; without even the implied   ////
18
//// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      ////
19
//// PURPOSE.  See the GNU Lesser General Public License for more ////
20
//// details.                                                     ////
21
////                                                              ////
22
//// You should have received a copy of the GNU Lesser General    ////
23
//// Public License along with this source; if not, download it   ////
24
//// from http://www.opencores.org/lgpl.shtml                     ////
25
////                                                              ////
26
//////////////////////////////////////////////////////////////////////
27
 
28
class spi_sequence_item
29
  extends uvm_sequence_item;
30
  `uvm_object_utils(spi_sequence_item)
31
 
32
  // --------------------------------------------------------------------
33
  rand int data_width; // data size in bits
34
 
35
  // --------------------------------------------------------------------
36 48 qaztronic
  logic miso_data[]; // data from slave to master
37
  logic mosi_data[]; // data from master to slave
38 50 qaztronic
  int ss_index = 0;
39 48 qaztronic
  bit read;
40
  bit write;
41 47 qaztronic
 
42
  // --------------------------------------------------------------------
43
  function new(string name = "");
44
    super.new(name);
45
  endfunction : new
46
 
47
  // --------------------------------------------------------------------
48 48 qaztronic
  function void init(bit read, bit write, int data_width);
49
    this.read = read;
50
    this.write = write;
51 47 qaztronic
    this.data_width = data_width;
52 48 qaztronic
    this.miso_data = new[data_width];
53
    this.mosi_data = new[data_width];
54
 
55
    if(write)
56
      foreach(this.mosi_data[i])
57
        mosi_data[i] = 0;
58 47 qaztronic
  endfunction : init
59
 
60 50 qaztronic
  // --------------------------------------------------------------------
61
  function void load_mosi_from_file(string file_name);
62
    byte buffer;
63
    integer fd;
64
    integer code;
65
    integer size;
66 47 qaztronic
 
67 50 qaztronic
    fd = $fopen(file_name, "rb");
68
    code = $fseek(fd, 0, 2); // SEEK_END
69
    size = $ftell(fd);
70
    code = $rewind(fd);
71
    data_width = size*8;
72
    mosi_data = new[data_width];
73
    write = 1;
74 47 qaztronic
 
75 50 qaztronic
    for(int i = 0; i < size; i++) begin
76
      code = $fread(buffer, fd);
77
      mosi_data[i*8 +: 8] = {>>{buffer}};
78
    end
79 47 qaztronic
 
80 50 qaztronic
    $fclose(fd);
81
  endfunction
82 47 qaztronic
 
83 50 qaztronic
  // --------------------------------------------------------------------
84
  function void load_mosi_from_byte_array(byte byte_array[]);
85
    foreach(byte_array[i])
86
      mosi_data[i*8 +: 8] = {>>{byte_array[i]}};
87
  endfunction
88 47 qaztronic
 
89 48 qaztronic
  // --------------------------------------------------------------------
90
  function string convert2string();
91
    string s0, s1, s2, s3;
92
    byte data[];
93 47 qaztronic
 
94 48 qaztronic
    s0 = $sformatf( "\n| %m | rd | wr | data width |\n");
95
    s1 = $sformatf( "| %m | %1h  | %1h  | %d |\n"
96
                  , read
97
                  , write
98
                  , data_width
99
                  );
100
    s0 = {s0, s1};
101 47 qaztronic
 
102 50 qaztronic
    if(read) begin
103 48 qaztronic
      data = {>>{miso_data}};
104
 
105
      foreach(data[i])
106
        s2 = {s2, $sformatf("%2h|", data[i])};
107
 
108
      s2 = $sformatf("| %m | miso_data: |%s\n" , s2);
109
      s0 = {s0, s2};
110
    end
111
 
112 50 qaztronic
    if(write) begin
113 48 qaztronic
      data = {>>{mosi_data}};
114
 
115
      foreach(data[i])
116
        s3 = {s3, $sformatf("%2h|", data[i])};
117
 
118
      s3 = $sformatf("| %m | mosi_data: |%s\n" , s3);
119
      s0 = {s0, s3};
120
    end
121
 
122
    return s0;
123
  endfunction : convert2string
124
 
125 47 qaztronic
// --------------------------------------------------------------------
126 50 qaztronic
endclass

powered by: WebSVN 2.1.0

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