Files
+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

149 lines
4.1 KiB
Verilog

//
// Copyright 2016 Ettus Research
// Copyright 2018 Ettus Research, a National Instruments Company
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
module cic_decimate #(
parameter WIDTH = 16,
parameter N = 4,
parameter MAX_RATE = 256
)(
input clk,
input reset,
input rate_stb,
input [$clog2(MAX_RATE+1)-1:0] rate, // +1 due to $clog2() rounding
input strobe_in,
output reg strobe_out,
input last_in,
output reg last_out,
input [WIDTH-1:0] signal_in,
output reg [WIDTH-1:0] signal_out
);
wire [WIDTH+(N*$clog2(MAX_RATE+1))-1:0] signal_in_ext;
reg [WIDTH+(N*$clog2(MAX_RATE+1))-1:0] integrator [0:N-1];
reg [WIDTH+(N*$clog2(MAX_RATE+1))-1:0] differentiator [0:N-1];
reg [WIDTH+(N*$clog2(MAX_RATE+1))-1:0] pipeline [0:N-1];
reg [WIDTH+(N*$clog2(MAX_RATE+1))-1:0] sampler;
reg [N-1:0] last_integ;
reg last_integ_hold;
reg [N-1:0] last_diff;
reg last_sampler;
reg [N-1:0] strobe_integ;
reg strobe_sampler;
reg [N-1:0] strobe_diff;
integer i;
sign_extend #(WIDTH,WIDTH+(N*$clog2(MAX_RATE+1))) ext_input (.in(signal_in),.out(signal_in_ext));
// Integrate
always @(posedge clk) begin
if (reset) begin
last_integ <= 0;
last_integ_hold <= 0;
for (i = 0; i < N; i = i + 1) begin
integrator[i] <= 0;
strobe_integ[i] <= 0;
end
end else begin
strobe_integ <= {strobe_integ[N-2:0],strobe_in};
if (strobe_in) begin
last_integ[0] <= last_in;
integrator[0] <= integrator[0] + signal_in_ext;
end
for (i = 1; i < N; i = i + 1) begin
if (strobe_integ[i-1]) begin
last_integ[i] <= last_integ[i-1];
integrator[i] <= integrator[i] + integrator[i-1];
end
end
if (last_integ[N-1] & ~strobe_sampler) begin
last_integ_hold <= 1'b1;
end else if (strobe_sampler) begin
last_integ_hold <= 1'b0;
end
end
end
// Sampler strobe
reg [$clog2(MAX_RATE+1)-1:0] counter;
always @(posedge clk) begin
if (reset) begin
counter <= rate;
strobe_sampler <= 1'b0;
last_sampler <= 1'b0;
sampler <= 'd0;
end else begin
strobe_sampler <= 1'b0;
last_sampler <= 1'b0;
if (rate_stb) begin
counter <= rate;
end else if (strobe_integ[N-1]) begin
if (counter <= 1) begin
counter <= rate;
strobe_sampler <= 1'b1;
last_sampler <= last_integ[N-1] | last_integ_hold;
sampler <= integrator[N-1];
end else begin
counter <= counter - 1;
end
end
end
end
// Differentiate
always @(posedge clk) begin
if (reset) begin
last_diff <= 0;
for (i = 0; i < N; i = i + 1) begin
pipeline[i] <= 0;
differentiator[i] <= 0;
strobe_diff <= 0;
end
end else begin
strobe_diff <= {strobe_diff[N-2:0], strobe_sampler};
if (strobe_sampler) begin
last_diff[0] <= last_sampler;
differentiator[0] <= sampler;
pipeline[0] <= sampler - differentiator[0];
end
for (i = 1; i < N; i = i + 1) begin
if (strobe_diff[i-1]) begin
last_diff[i] <= last_diff[i-1];
differentiator[i] <= pipeline[i-1];
pipeline[i] <= pipeline[i-1] - differentiator[i];
end
end
end
end
genvar l;
wire [WIDTH-1:0] signal_out_shifted[0:MAX_RATE];
generate
for (l = 1; l <= MAX_RATE; l = l + 1) begin
// N*log2(rate), $clog2(rate) = ceil(log2(rate)) which rounds to nearest shift without overflow
assign signal_out_shifted[l] = pipeline[N-1][$clog2(l**N)+WIDTH-1:$clog2(l**N)];
end
endgenerate
assign signal_out_shifted[0] = pipeline[N-1][WIDTH-1:0];
// Output register
always @(posedge clk) begin
if (reset) begin
last_out <= 1'b0;
strobe_out <= 1'b0;
signal_out <= 'd0;
end else begin
strobe_out <= strobe_diff[N-1];
if (strobe_diff[N-1]) begin
last_out <= last_diff[N-1];
signal_out <= signal_out_shifted[rate];
end
end
end
endmodule