Files
b210-k7-fpga/sim/rfnoc/PkgRfnocItemUtils.sv
T
+18 6b67702ad7 Merge FPGA repository back into UHD repository
The FPGA codebase was removed from the UHD repository in 2014 to reduce
the size of the repository. However, over the last half-decade, the
split between the repositories has proven more burdensome than it has
been helpful. By merging the FPGA code back, it will be possible to
create atomic commits that touch both FPGA and UHD codebases. Continuous
integration testing is also simplified by merging the repositories,
because it was previously difficult to automatically derive the correct
UHD branch when testing a feature branch on the FPGA repository.

This commit also updates the license files and paths therein.

We are therefore merging the repositories again. Future development for
FPGA code will happen in the same repository as the UHD host code and
MPM code.

== Original Codebase and Rebasing ==

The original FPGA repository will be hosted for the foreseeable future
at its original local location: https://github.com/EttusResearch/fpga/

It can be used for bisecting, reference, and a more detailed history.

The final commit from said repository to be merged here is
05003794e2da61cabf64dd278c45685a7abad7ec. This commit is tagged as
v4.0.0.0-pre-uhd-merge.

If you have changes in the FPGA repository that you want to rebase onto
the UHD repository, simply run the following commands:

- Create a directory to store patches (this should be an empty
  directory):

    mkdir ~/patches

- Now make sure that your FPGA codebase is based on the same state as
  the code that was merged:

    cd src/fpga # Or wherever your FPGA code is stored
    git rebase v4.0.0.0-pre-uhd-merge

  Note: The rebase command may look slightly different depending on what
  exactly you're trying to rebase.

- Create a patch set for your changes versus v4.0.0.0-pre-uhd-merge:

    git format-patch v4.0.0.0-pre-uhd-merge -o ~/patches

  Note: Make sure that only patches are stored in your output directory.
  It should otherwise be empty. Make sure that you picked the correct
  range of commits, and only commits you wanted to rebase were exported
  as patch files.

- Go to the UHD repository and apply the patches:

    cd src/uhd # Or wherever your UHD repository is stored
    git am --directory fpga ~/patches/*
    rm -rf ~/patches # This is for cleanup

== Contributors ==

The following people have contributed mainly to these files (this list
is not complete):

Co-authored-by: Alex Williams <alex.williams@ni.com>
Co-authored-by: Andrej Rode <andrej.rode@ettus.com>
Co-authored-by: Ashish Chaudhari <ashish@ettus.com>
Co-authored-by: Ben Hilburn <ben.hilburn@ettus.com>
Co-authored-by: Ciro Nishiguchi <ciro.nishiguchi@ni.com>
Co-authored-by: Daniel Jepson <daniel.jepson@ni.com>
Co-authored-by: Derek Kozel <derek.kozel@ettus.com>
Co-authored-by: EJ Kreinar <ej@he360.com>
Co-authored-by: Humberto Jimenez <humberto.jimenez@ni.com>
Co-authored-by: Ian Buckley <ian.buckley@gmail.com>
Co-authored-by: Jörg Hofrichter <joerg.hofrichter@ni.com>
Co-authored-by: Jon Kiser <jon.kiser@ni.com>
Co-authored-by: Josh Blum <josh@joshknows.com>
Co-authored-by: Jonathon Pendlum <jonathan.pendlum@ettus.com>
Co-authored-by: Martin Braun <martin.braun@ettus.com>
Co-authored-by: Matt Ettus <matt@ettus.com>
Co-authored-by: Michael West <michael.west@ettus.com>
Co-authored-by: Moritz Fischer <moritz.fischer@ettus.com>
Co-authored-by: Nick Foster <nick@ettus.com>
Co-authored-by: Nicolas Cuervo <nicolas.cuervo@ettus.com>
Co-authored-by: Paul Butler <paul.butler@ni.com>
Co-authored-by: Paul David <paul.david@ettus.com>
Co-authored-by: Ryan Marlow <ryan.marlow@ettus.com>
Co-authored-by: Sugandha Gupta <sugandha.gupta@ettus.com>
Co-authored-by: Sylvain Munaut <tnt@246tNt.com>
Co-authored-by: Trung Tran <trung.tran@ettus.com>
Co-authored-by: Vidush Vishwanath <vidush.vishwanath@ettus.com>
Co-authored-by: Wade Fife <wade.fife@ettus.com>


Original-commit: bafa9d95453387814ef25e6b6256ba8db2df612f
2020-01-28 09:35:36 -08:00

216 lines
6.5 KiB
Systemverilog

//
// Copyright 2019 Ettus Research, A National Instruments Company
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// Module: PkgRfnocItemUtils
//
// Description: This package contains utilities to handle and process items.
//
// - ItemDataBuff: A class that holds a collection of items of arbitrary width
// To can convert to and from a CHDR vector
// - ItemDataBuffQueue: A queue of ItemDataBuff buffers
//
package PkgRfnocItemUtils;
import PkgChdrUtils::*;
//---------------------------------------------------------------------------
// Item Data Buffer
//---------------------------------------------------------------------------
//
// This class items of an arbitrary type
//
//---------------------------------------------------------------------------
class ItemDataBuff #(type data_t);
typedef ItemDataBuff #(data_t) ItemDataBuffQueue[$];
// Store data in the user-specified format
local data_t buff[$];
// Create a new empty buffer
function new();
buff.delete();
endfunction : new
// Get the bitwidth of a item in this buffer
function int item_w();
return $size(data_t);
endfunction : item_w
// Delete the contents of this buffer
function void delete();
buff.delete();
endfunction : delete
// Get the size (in number of words) of this buffer
function int size();
return buff.size();
endfunction : size
// Get the size (in number of bytes) of this buffer
function int get_bytes();
return size() * (item_w() / 8);
endfunction : get_bytes
// Get the i'th element in this buffer
function data_t get(int i);
return buff[i];
endfunction : get
// Put and element in this buffer. If i is negative
// then put it at the end
function void put(data_t d, int i = -1);
if (i < 0)
buff.push_back(d);
else
buff.insert(i, d);
endfunction : put
// Convert the contents of this buffer to a CHDR payload
// A CHDR payload can be transmitted using the block controller
// BFM.
function chdr_word_queue_t to_chdr_payload();
int samps_per_word = $size(chdr_word_t) / $size(data_t);
int num_chdr_lines = ((buff.size() + samps_per_word - 1) / samps_per_word);
chdr_word_t chdr_w_vtr[$];
for (int i = 0; i < num_chdr_lines; i++) begin
chdr_word_t tmp = 'x;
for (int j = 0; j < samps_per_word; j++) begin
tmp[j*$size(data_t) +: $size(data_t)] = buff[i*samps_per_word + j];
end
chdr_w_vtr.push_back(tmp);
end
return chdr_w_vtr;
endfunction : to_chdr_payload
// Populate this buffer using a CHDR payload
// A CHDR payload can be received using the block controller
// BFM.
function void from_chdr_payload(chdr_word_queue_t chdr_w_vtr, int bytes);
int samps_per_word = $size(chdr_word_t) / $size(data_t);
int bytes_left = bytes;
buff.delete();
foreach (chdr_w_vtr[i]) begin
for (int j = 0; j < samps_per_word; j++) begin
if (bytes_left > 0) begin
buff.push_back(chdr_w_vtr[i][j*$size(data_t) +: $size(data_t)]);
bytes_left -= ($size(data_t)/8);
end
end
end
endfunction : from_chdr_payload
// Output a string representation of the contents of the buffer
function string sprint(string format = "%X", bit as_chdr = 0);
if (as_chdr) begin
string str = $sformatf("ItemDataBuff (64-bit CHDR, %0d bytes)\n", get_bytes());
chdr_word_queue_t chdr_q = this.to_chdr_payload();
foreach (chdr_q[i]) begin
str = { str, $sformatf({"%5d> ", format, "\n"}, i, chdr_q[i]) };
end
return str;
end else begin
string str = $sformatf("ItemDataBuff (%0d-bit)\n", $size(data_t));
foreach (buff[i]) begin
str = { str, $sformatf({"%5d> ", format, "\n"}, i, buff[i]) };
end
return str;
end
endfunction : sprint
// Print a string representation of the contents of the buffer
function void print(string format = "%X", bit as_chdr = 0);
$display(sprint(format, as_chdr));
endfunction : print
// Check if the contents of two buffers is equal
function bit equal(
ItemDataBuff #(data_t) rhs
);
if (this.size() != rhs.size()) return 0;
for (int i = 0; i < this.size(); i++) begin
if (this.get(i) != rhs.get(i)) return 0;
end
return 1;
endfunction : equal
endclass
class ItemDataBuffQueue #(type data_t);
local ItemDataBuff #(data_t) queue[$];
// Create a new empty queue
function new();
queue.delete();
endfunction : new
// Delete the contents of this queue
function void delete();
queue.delete();
endfunction : delete
// Get the size (in number of buffers) of this queue
function int size();
return queue.size();
endfunction : size
// Get the i'th element in this buffer
function ItemDataBuff #(data_t) get(int i);
return queue[i];
endfunction : get
// Put an element in this buffer. If i is negative
// then put it at the end
function void put(ItemDataBuff #(data_t) buff, int i = -1);
if (i < 0)
queue.push_back(buff);
else
queue.insert(i, buff);
endfunction : put
// Create a queue of buffers and fill them using the contents of the specified file.
function void from_hex_file(
int max_buff_size,
string filename
);
string line;
int word_i = 0;
int handle = $fopen(filename, "r");
queue.delete();
while ($fgets(line, handle) > 0) begin
data_t word = 'x;
int buff_i = word_i++ / max_buff_size;
if (queue.size() < buff_i + 1) begin
ItemDataBuff #(data_t) buff = new;
queue.push_back(buff);
end
if ($sscanf(line, "%x", word) > 0) begin
queue[buff_i].put(word);
end else begin
$error("File parse error");
end
end
$fclose(handle);
handle = 0;
endfunction : from_hex_file
// Write the contents of the queue of buffers to the specified file.
function void to_hex_file(
string filename
);
int handle = $fopen(filename, "w");
foreach (queue[i]) begin
for (int j = 0; j < queue[i].size(); j++) begin
$fdisplay(handle, $sformatf("%x", queue[i].get(j)));
end
end
$fclose(handle);
handle = 0;
endfunction : to_hex_file
endclass
endpackage : PkgRfnocItemUtils