Files
b210-k7-fpga/top/n3xx/dboards/rh/cpld/rhodium_gain_ctrl.v
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

204 lines
5.8 KiB
Verilog

///////////////////////////////////////////////////////////////////
//
// Copyright 2018 Ettus Research, A National Instruments Company
//
// SPDX-License-Identifier: LGPL-3.0-or-later
//
// Module: rhodium_gain_ctrl
// Description:
// Gain controller for Rhodium
// Provides 2 SPI slaves:
// The "load" slave is used to load the gain table with DSA settings for
// each index.
// The "ctrl" slave takes in a gain index and drives the DSAs with the
// setting found in the gain table.
// The SPI formats are provided below.
//////////////////////////////////////////////////////////////////////
`default_nettype none
/**
* SPI DATA FORMAT
* LOADER
* M {table_sel[1:0], gain_index[5:0], rsvd[1:0], dsa1[4:0], dsa2[4:0], wr_en, rsvd[2:0]}
* S {-------------------------------, rsvd[1:0], dsa1[4:0], dsa2[4:0], -------rsvd[3:0]}
* CTRL
* M {table_sel[1:0], gain_index[5:0], rsvd[1:0], wr_dsa1, -rsvd[5:0], wr_dsa2, rsvd[5:0]}
* S {-------------------------------, ---------rsvd[2:0], gain1[5:0], ---rsvd, gain2[5:0]}
*/
module rhodium_gain_ctrl
#(
parameter TABLE_NUM = 2'b01
) (
input wire load_table_sel,
input wire load_sck,
input wire load_csb,
input wire load_mosi,
output wire load_miso,
input wire ctrl_table_sel,
input wire ctrl_sck,
input wire ctrl_csb,
input wire ctrl_mosi,
output reg ctrl_miso,
output wire [4:0] dsa,
output reg dsa1_le,
output reg dsa2_le
);
localparam CNT_GAIN1_DRIVE = 10,
CNT_DSA1_LE_RISE = 11,
CNT_DSA1_LE_FALL = 14,
CNT_GAIN1_RELEASE = 17;
localparam CNT_GAIN2_DRIVE = 17,
CNT_DSA2_LE_RISE = 18,
CNT_DSA2_LE_FALL = 21,
CNT_GAIN2_RELEASE = 24;
/******************
* Gain table loader
*******************/
reg [4:0] load_bit_cnt;
reg [1:0] load_tbl;
reg [5:0] load_index;
reg [15:0] load_rd_data;
reg [4:0] load_dsa1;
reg [4:0] load_dsa2;
wire [4:0] load_dsa1_prev;
wire [4:0] load_dsa2_prev;
assign load_miso = load_rd_data[15]; // Shift out on neg edge
wire wr_en;
assign wr_en = (!load_csb) && (load_tbl == TABLE_NUM) && (load_bit_cnt == 20) && (load_mosi);
// Cycle counter for where we are in protocol and shift register for input
always @ (posedge load_sck or posedge load_csb)
begin
if (load_csb) begin
load_bit_cnt <= 5'd0;
end else if (!load_csb) begin
{load_dsa1, load_dsa2} <= {load_dsa1[3:0], load_dsa2, load_mosi};
if (load_bit_cnt < 23) begin
load_bit_cnt <= load_bit_cnt + 5'd1;
end
if (load_bit_cnt < 8) begin
{load_tbl, load_index} <= {load_tbl[0], load_index, load_mosi};
end
end
end
// Readback shift register
always @ (negedge load_sck)
begin
if (load_bit_cnt == 9) begin
load_rd_data <= {load_dsa1_prev, load_dsa2_prev, 5'b000};
end else begin
load_rd_data <= {load_rd_data[14:0], 1'b0};
end
end
/******************
* Gain table RAM
*******************/
wire [4:0] ctrl_dsa1;
wire [4:0] ctrl_dsa2;
/* Use half of table for low band, other half for high band
* Software decides address mapping
*/
rhodium_gain_table gain_table(
.wr_clk(load_sck),
.wr_en(wr_en),
.wr_addr({load_table_sel, load_index}),
.wr_data({load_dsa1, load_dsa2}),
.wr_data_prev({load_dsa1_prev, load_dsa2_prev}),
.rd_clk(ctrl_sck),
.rd_addr({ctrl_table_sel, ctrl_index}),
.rd_data({ctrl_dsa1, ctrl_dsa2})
);
/******************
* Gain control
*******************/
reg [4:0] ctrl_bit_cnt;
reg [1:0] ctrl_tbl;
reg [5:0] ctrl_index;
reg [5:0] gain1;
reg [5:0] gain2;
reg gain1_t;
reg gain2_t;
assign dsa = !gain1_t ? ctrl_dsa1 :
(!gain2_t ? ctrl_dsa2 :
5'b11111);
// Cycle counter for where we are in protocol and shift register for input
// Also controls timing of DSAs' latch enable signals
always @ (posedge ctrl_sck or posedge ctrl_csb)
begin
if (ctrl_csb) begin
ctrl_bit_cnt <= 5'd0;
dsa1_le <= 1'b0;
dsa2_le <= 1'b0;
gain1_t <= 1'b1;
gain2_t <= 1'b1;
end else if (!ctrl_csb) begin
if (ctrl_bit_cnt < 23) begin
ctrl_bit_cnt <= ctrl_bit_cnt + 5'd1;
end
if (ctrl_bit_cnt < 8) begin
{ctrl_tbl, ctrl_index} <= {ctrl_tbl[0], ctrl_index, ctrl_mosi};
end
if (ctrl_tbl == TABLE_NUM) begin
if ((ctrl_bit_cnt == CNT_GAIN1_DRIVE) && (ctrl_mosi)) begin
gain1 <= ctrl_index;
gain1_t <= 1'b0;
end else if ((gain1_t == 1'b0) && (ctrl_bit_cnt == CNT_DSA1_LE_RISE)) begin
dsa1_le <= 1'b1;
end else if ((gain1_t == 1'b0) && (ctrl_bit_cnt == CNT_DSA1_LE_FALL)) begin
dsa1_le <= 1'b0;
end else if ((gain1_t == 1'b0) && (ctrl_bit_cnt == CNT_GAIN1_RELEASE)) begin
gain1_t <= 1'b1;
end
if ((ctrl_bit_cnt == CNT_GAIN2_DRIVE) && (ctrl_mosi)) begin
gain2 <= ctrl_index;
gain2_t <= 1'b0;
end else if ((gain2_t == 1'b0) && (ctrl_bit_cnt == CNT_DSA2_LE_RISE)) begin
dsa2_le <= 1'b1;
end else if ((gain2_t == 1'b0) && (ctrl_bit_cnt == CNT_DSA2_LE_FALL)) begin
dsa2_le <= 1'b0;
end else if ((gain2_t == 1'b0) && (ctrl_bit_cnt == CNT_GAIN2_RELEASE)) begin
gain2_t <= 1'b1;
end
end
end
end
// SPI readback for ctrl bus, based on current bit count
always @ (negedge ctrl_sck)
begin
case (ctrl_bit_cnt) // Shift out on neg edge
11: ctrl_miso <= gain1[5];
12: ctrl_miso <= gain1[4];
13: ctrl_miso <= gain1[3];
14: ctrl_miso <= gain1[2];
15: ctrl_miso <= gain1[1];
16: ctrl_miso <= gain1[0];
18: ctrl_miso <= gain2[5];
19: ctrl_miso <= gain2[4];
20: ctrl_miso <= gain2[3];
21: ctrl_miso <= gain2[2];
22: ctrl_miso <= gain2[1];
23: ctrl_miso <= gain2[0];
default: ctrl_miso <= 1'b0;
endcase
end
endmodule // rhodium_gain_ctrl
`default_nettype wire