// feedforward.v
// Feedforward table and related accounting
// $Id$
// Larry Doolittle, LBNL
// llc-suite Copyright (c) 2004, The Regents of the University of
// California, through Lawrence Berkeley National Laboratory (subject
// to receipt of any required approvals from the U.S. Dept. of Energy).
// All rights reserved.
// Your use of this software is pursuant to a "BSD-style" open
// source license agreement, the text of which is in license.txt
// (md5sum a1e0e81c78f6eba050b0e96996f49fd5) that should accompany
// this file. If the license agreement is not there, or if you
// have questions about the license, please contact Berkeley Lab's
// Technology Transfer Department at TTD@lbl.gov referring to
// "llc-suite (LBNL Ref CR-1988)"
// Initial coding: January 2003, modularized from code in adctest.v
`timescale 1ns / 1ns
// Number of ignored bits in address word.
// Use 2 normally, so each I/Q pair is used for 8 clock cycles.
// 5 is the hack value for SRF
`define FSHIFT 2
module feedforward
(
input host_clk, // interconnect
input [13:0] host_addr, // interconnect
input host_we, // interconnect
input [15:0] host_data, // interconnect
output [15:0] host_dout, // register FEEDFORWARD
input select, // select FEEDFORWARD
input clk40, // interconnect
input feedforward_start, // interconnect
output [12:0] feedforward_data // interconnect
);
reg [8+`FSHIFT:0] counter;
reg run;
`ifdef SIMULATE
initial counter = 11'b11111110000;
initial run=0;
`endif
wire local_host_we = host_we & select;
wire [7:0] feedforward_raw;
RAMB4_S8_S8 feedforward_table(
.ENA(1'b1),
.DIA(8'b0), // not used
.ADDRA({counter[8+`FSHIFT:1+`FSHIFT], counter[0]}),
.WEA(1'b0), // read only port
.RSTA(1'b0),
.CLKA(clk40),
.DOA(feedforward_raw), // sent to 40 MS/s processing chain
.ENB(1'b1),
.DIB(host_data[7:0]),
.ADDRB(host_addr[8:0]),
.WEB(local_host_we),
.RSTB(1'b0),
.CLKB(host_clk),
.DOB(host_dout[7:0]));
assign host_dout[15:8] = 0;
// 11 bit counter that is used to generate the feedforward address.
// ignore bits 1 and 2 to generate the address for the 512 element
// feedforward table. Host needs to make sure the value at the
// first address is zero, since we sit there when the system is idle.
always @(posedge clk40) begin
run <= feedforward_start |
(run & (counter != {(9+`FSHIFT){1'b1}}));
counter <= run ? (counter + 1'b1) : {(9+`FSHIFT){1'b0}};
end
wire [12:0] ff_prep = {
{(`FSHIFT){feedforward_raw[7]}},
feedforward_raw,
{(5-`FSHIFT){1'b0}}
};
assign feedforward_data = counter[1] ? (~ff_prep + 1) : ff_prep;
`ifdef SIMULATE
initial counter = 0;
`endif
endmodule